Compare commits

...
Author SHA1 Message Date
Larry Gritz 6b7e81fd43 Stage v1.13.2.4-dev 2023-04-14 10:24:57 -07:00
Larry Gritz edf079ce6d Temp fix for 1670 to be backported to this branch 2023-04-14 10:24:57 -07:00
cmstein 2754fa2a08 fix for ReParameterization corner case (#1670)
Take into account whether a parameter can change due to interactivity
when comparing parameters for "mergeability".

This proposed patch fixes a corner case we were seeing during live rendering with ReParameterization.

We were experiencing a problem when ss->ReParameterize() wasn't successfully applying parameter changes for us.

In our situation, a shader's parameter, "A", was marked with lockgeom=0 (ie. "live" or "editable") and was set via ss->Parameter(). This parameter was connected (through a series of copies and network links) to another shader's parameter, "B", downstream whose initialized value (ie. the one specified in the .osl/.oso file) matched A's set value. When this happened, A's shading layer was getting marked as "mergeable" and deleted, and we wouldn't see any updates to A via "reparameterization" take effect.

Signed-off-by: Clifford Stein <cstein@imageworks.com>
2023-04-14 10:05:05 -07:00
Chris Hellmuth 56a6099de1 Apply recent run layer call optimization to batched execution (#1669)
Copy-paste the run layer call checks from #1665 into the batched execution mode.

Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
2023-04-14 10:04:48 -07:00
Larry Gritz 86050991c4 Clean up OptiX comments (#1666)
Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-04-14 10:04:33 -07:00
Chris Hellmuth 4478b290d1 Don't insert redundant run layer calls inside a basic block (#1665)
This patch is a very simple part one of work to optimize the number of conditional run layer calls that OSL makes, which take the form:

    if (!groupdata->run[parentlayer])
        parent_layer([...]);

After examining our slowest JIT’ing shaders on gpu, @tgrant-nv showed us that these run layer calls were significantly bloating our ptx and slowing down their compilation. Many of them are unnecessary because static analysis can show we are guaranteed to have already run the layer in question.

For example, reading different fields from a connected struct like below will often generate multiple conditional run layer calls:

```
struct Pair {
    float x;
    float y;
};

shader example_shader(Pair p = {})
{
    if ([…]) {
        float xx = p.x;
        float yy = p.y;
        […]
    }
}
```

Since this is not really a performance issue on cpu (runtime overhead is just checking the conditional bit), OSL doesn’t make a huge effort to optimize away these redundant cases. Each useparam op will be careful not to insert more than one per layer, and code that is called unconditionally in the main section of the shader will also not have redundant checks, but there are plenty of examples like above that are not currently removed.

This patch takes a basic first step, adding metrics to track run layer call counts and removing duplicate run layer calls inside a basic block, covering cases like the example above.

On my set of production test scenes, this alone removes anywhere from 20-50% of total run layer calls, with our biggest shaders seeing the most improvement. Total ptx line reduction varies between 3-20%, and optix module compilation (jit time) is reduced between 1-15%.

Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
2023-04-14 10:04:09 -07:00
Larry Gritz 26868c8493 Build: verify that OSL can build with clang16 (#1664)
But note: OSL does not yet work with LLVM 16.

Because homebrew recently upgraded its default llvm to 16.0, there may
be users for whom builds now break. The solution is:

    brew install llvm@14
    cmake ... -DLLVM_ROOT=/usr/local/opt/llvm@14

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-04-14 10:03:57 -07:00
Larry Gritz 786e943b61 Build: Fix cuda compilation flags for LLVM 15 (#1659)
For LLVM 15+, we need to disable opaque pointers. We did this for
regular bitcode generation in llvm_macros.cmake, but neglected to make
the corresponding change for copmiling to ptx in cuda_macros.cmake.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-04-14 10:03:24 -07:00
Larry Gritz a12f99bf5a build: proper warnings about LLVM 16 (#1658)
LLVM 16 was just released. I'm pretty sure we won't build properly
against it because of the phase-out of typed pointers in LLVM IR, so
warn prominently so that anybody building against it who has problems
will know why.

Also, LLVM itself has bumped their toolchain requirements with the
release of 16. Technically, I'm not sure if that extends to projects
using the LLVM APIs, but warn anyway and hope for the best. If it
fails, at least the warning will supply an explanation.

At a later time, we'll need to upgrade the code on our side to have the
option of using opaque pointers so we can run with LLVM 16+.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-04-14 10:03:05 -07:00
Chris Hellmuth 3a59480628 Enable userdata derivatives for interpolated params on GPU (#1657)
When generating calls to osl_bind_interpolated_param in llvm_instance.cpp, the userdata_has_derivs field is set to true if the parameter's derivatives are needed, but the code does not take into account that on gpu there is no space allocated for these derivatives.

This leads to an incorrect derivatives pointer getting passed into the renderer, which the renderer will use to write into unrelated groupdata fields.

For our renders, getting the correct image was worth the 1-2% inflation of groupdata struct size that we observed by simply re-enabling gpu userdata derivatives. If desired, adding an option to turn them on/off is straightforward, but I didn't want to preemptively bloat the code if it's not necessary.

Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
2023-04-14 10:02:25 -07:00
Larry Gritz 74be126d44 Be more careful about paths to look for llvm (1656)
In particular, `${LLVM_ROOT}/bin` will end up being (incorrectly!)
`/bin` if LLVM_ROOT is empty. That is bad if some other llvm-config
happens to be in /bin.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-16 15:35:51 -07:00
Larry Gritz d27b57e5b1 Stage for v1.13.2.3 2023-03-16 09:21:30 -07:00
Larry Gritz 9a2b49d81e oslc: simple constant folding of binary expressions on the oslc side (#1653)
The runtime optimization does a great job of constant folding, and
we'd pushed it there because, with instance parameter values and
shader network connections known, it can find so much more opportunity
to optimize than we could in oslc.

However, there is one pesky problem, which is that shader parameters
that are initialized to even simple expressions such as 3+1 end up
with "init ops", which although later constant folded by the time the
shader is JITed, make it impossible to know the value via OSLQuery.

So this patch just takes the simplest cases -- certain `int OP int`
and `float OP float` expressions involving literal constants, and
performs the operation as it's parsing the code. So

         int val = 3 + 1;

actually just immediately is turned into `val = 4` instead of making
an "add".

To reiterate, the add would never have happened while executing the
shader -- at runtime in the renderer, when it's time to optimize and
JIT the shader, it would know it's a constant 4 value. This is
strictly about making oslc directly output an .oso file that knows
that parameter `val` has default value 4 instead of throwing up its
hands and saying "it's math code that will be evaluated later."

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-16 00:34:42 -07:00
Larry Gritz 1d17ae944a ci: update runners (#1651)
* Stop using the deprecated, soon to be removed, ubuntu-18.04 runners
  and switch to 20.04.
* Bump the "latest" test openexr to 3.1.6
* Update INSTALL.md to document some things we're already testing and
  are known to work.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-16 00:34:24 -07:00
Larry Gritz 6012b09777 Fix missing // clang-format on in oslc.c (#1652)
We had turned it off in one function to preserve formatting, but
failed to turn it on at the end of the function. This led to several
small functions not being clang-formatted, now fixed.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-16 00:34:02 -07:00
Larry Gritz b43ec5546a Make compile_report attribute an int instead of just 0/1 (#1654)
In particular, 1 prints a short version of the compile report (just
the fact that it happened and the time), >1 prints more verbose info.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-16 00:33:04 -07:00
Larry Gritz 4d9ef03d76 ci: Fix broken Mac CI (#1647)
Make sure LLVM_ROOT/bin (either as a cmake var or as an env var) end
up in the hints list when searching for llvm-config.

Without this, one of our Mac CI jobs was ending up with clang 14 and
llvm 15, and that was causing problems. The particular test was
supposed to be using 14 for both.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-15 23:08:07 -07:00
Larry Gritz 3e2689db51 docs: Update credits
Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-15 23:07:56 -07:00
Larry Gritz 9673b6faa2 Typo in test shaders (#1644)
Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-15 23:07:41 -07:00
Larry Gritz 9644456f0d fix: add missing fmod variants (#1643)
Apparently some varieties of fmod(triple,float) -- which were not
documented in the spec but were intended to work and did allow that
combination in oslc -- were not fully implemented in the runtime.

* Add all these tests to the arithmetic-reg test, to fully test all
  possible argument type and unif/vary/const combinations once and for
  all for fmod. Also add some more rudimentary testing to miscmath.

* Implement the missing bits and/or avoid the code paths that rely
  on the unimplemented parts.

The implementation of fmod for funny -- both for batch and non-batch,
it's got one code path that just directly generates code and doesn't
need any functional implementation in llvm_ops at all, and a second
code path that uses the functional implementations to work around
(different, in each case!) what appears to be bugs or limitations in
long-ago LLVM versions we don't need any more.  I'm trying to assess
whether those are still needed at all in the oldest versions of LLVM
we are using, and if not, I may amend even more simplification to this
whole thing.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-15 23:07:03 -07:00
Larry Gritz dccf7a3360 Fix mismatched strides when calling OCIO for transformc with derivs (#1646)
We were getting an exception thrown on the OCIO side, because we were
passing 0 for the y stride (which, us humans know, should have been fine
since there was only one row, so the stride shouldn't have mattered).
Now pass the right stride even though we don't need to step from row
to row.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
2023-03-15 23:06:36 -07:00
Larry Gritz 959b0c1330 Stage developer preview 1.13.2.2 2023-02-07 17:59:07 -08:00
43 changed files with 492 additions and 163 deletions
+5 -5
View File
@@ -47,7 +47,7 @@ jobs:
pybind11_ver: v2.4.2
- desc: clang9/C++14 llvm9 oiio-release boost1.66 avx2 exr2.3 py2.7
nametag: linux-clang9-llvm9
os: ubuntu-18.04
os: ubuntu-20.04
vfxyear: 2019
vfxsuffix: -clang9
cc_compiler: clang
@@ -290,7 +290,7 @@ jobs:
include:
- desc: Debug gcc7/C++14 llvm9 py2.7 oiio2.3 exr2.4 sse4 boost1.65 exr2.4
nametag: linux-debug-gcc7-llvm9
os: ubuntu-18.04
os: ubuntu-20.04
cxx_compiler: g++-7
cxx_std: 14
openexr_ver: v2.4.3
@@ -304,7 +304,7 @@ jobs:
CTEST_TEST_TIMEOUT=240
- desc: gcc10/C++17 llvm10 oiio-release boost1.65 exr2.5 avx2
nametag: linux-2021ish-gcc10-llvm10
os: ubuntu-18.04
os: ubuntu-20.04
cxx_compiler: g++-10
cxx_std: 17
fmt_ver: 7.0.1
@@ -322,7 +322,7 @@ jobs:
cxx_compiler: g++-11
cxx_std: 17
fmt_ver: 9.1.0
openexr_ver: v3.1.5
openexr_ver: v3.1.6
openimageio_ver: master
pybind11_ver: v2.10.0
python_ver: 3.9
@@ -331,7 +331,7 @@ jobs:
setenvs: export LLVM_VERSION=13.0.0
LLVM_DISTRO_NAME=ubuntu-20.04
OPENCOLORIO_VERSION=v2.2.0
PUGIXML_VERSION=v1.11.4
PUGIXML_VERSION=v1.13
- desc: bleeding edge gcc12/C++17 llvm14 oiio/ocio/exr/pybind-master boost1.71 py3.10 avx2 batch-b16avx512
nametag: linux-bleeding-edge
os: ubuntu-22.04
+1 -1
View File
@@ -4,7 +4,7 @@
cmake_minimum_required (VERSION 3.12)
set (OSL_VERSION "1.13.2.1")
set (OSL_VERSION "1.13.2.4")
set (OSL_VERSION_OVERRIDE "" CACHE STRING
"Version override (use with caution)!")
mark_as_advanced (OSL_VERSION_OVERRIDE)
+6 -5
View File
@@ -12,11 +12,11 @@ Dependencies
OSL requires the following dependencies or tools.
NEW or CHANGED dependencies since the last major release are **bold**.
* Build system: [CMake](https://cmake.org/) 3.12 or newer (tested through 3.24)
* Build system: [CMake](https://cmake.org/) 3.12 or newer (tested through 3.26)
* A suitable C++14 or C++17 compiler to build OSL itself, which may be any of:
- GCC 6.1 or newer (tested through gcc 12.1)
- Clang 3.4 or newer (tested through clang 15)
- Clang 3.4 or newer (tested through clang 16)
- Microsoft Visual Studio 2017 or newer
- Intel C++ compiler icc version 17 or newer or LLVM-based icx compiler
version 2022 or newer.
@@ -41,13 +41,14 @@ NEW or CHANGED dependencies since the last major release are **bold**.
DYLD_LIBRARY_PATH on OS X).
* [LLVM](http://www.llvm.org) 9, 10, 11, 12, 13, 14, or 15, including
clang libraries.
clang libraries. LLVM 16 doesn't work yet, we need to make changes
on the OSL side to be compatible.
* (optional) For GPU rendering on NVIDIA GPUs:
* [OptiX](https://developer.nvidia.com/rtx/ray-tracing/optix) 7.0 or higher.
* [Cuda](https://developer.nvidia.com/cuda-downloads) 8.0 or higher.
* [Boost](https://www.boost.org) 1.55 or newer (tested through boost 1.80)
* [Boost](https://www.boost.org) 1.55 or newer (tested through boost 1.81)
* [Ilmbase or Imath](https://github.com/AcademySoftwareFoundation/openexr) 2.3
or newer (recommended: 2.4 or higher; tested through 3.1)
* [Flex](https://github.com/westes/flex) 2.5.35 or newer and
@@ -55,7 +56,7 @@ NEW or CHANGED dependencies since the last major release are **bold**.
Note that on some MacOS/xcode releases, the system-installed Bison is too
old, and it's better to install a newer Bison (via Homebrew is one way to
do this easily).
* [PugiXML](http://pugixml.org/)
* [PugiXML](http://pugixml.org/) >= 1.8 (we have tested through 1.13).
* (optional) [Partio](https://www.disneyanimation.com/technology/partio.html)
If it is not found at build time, the OSL `pointcloud` functions will not
be operative.
+21 -14
View File
@@ -389,8 +389,9 @@ Films using OSL (grouped by year of release date):
Last Night in Soho,
Ghostbusters: Afterlife,
Spider-Man 3: No Way Home,
Matrix Resurrections
* **(2022 / upcoming)**
Matrix Resurrections,
Sing 2
* **(2022)**
Hotel Transylvania 4: Transformania,
Death on the Nile,
Uncharted,
@@ -403,11 +404,15 @@ Films using OSL (grouped by year of release date):
Thor: Love and Thunder,
The Sea Beast,
DC League of Super Pets,
Minions: Rise of Gru,
Bullet Train,
Slumberland,
Glass Onion
* **(2023 / upcoming)**
Ant-Man and the Wasp: Quantumania,
...
Building and Installation
-------------------------
@@ -480,18 +485,20 @@ The current project leadership is documented in the
Many people have contributed features, bug fixes, and other changes to OSL
over the years: Steve Agland, Shane Ambler, Martijn Berger, Farchad
Bidgolirad, Nicholas Bishop, Solomon Boulos, Stefan Bruens, Stefan Büttner,
Matthaus G. Chajdas, Clark Chen, Alejandro Conty, Dieter De Baets, Thomas
Dinges, Mads Drøschler, Luke Emrose, Louis Feng, Mark Final, Henri Fousse,
Stephen Friedman, Syoyo Fujita, Tim Grant, Larry Gritz, Nicolas Guiard, Euan
Haahr, Derek Haase, Sven-Hendrik Haase, John Haddon, Niklas Harrysson, Daniel
Heckenberg, Adrien Herubel, Thiago Ize, Matt Johnson, Ronan Keryell, Chris
Matthaus G. Chajdas, Clark Chen, Alejandro Conty, Damien Courtois, Dieter De
Baets, Thomas Dinges, Daniel Dresser, Mads Drøschler, Peter Ellerington, Luke
Emrose, Louis Feng, Mark Final, Henri Fousse, Stephen Friedman, Syoyo Fujita,
Tim Grant, Larry Gritz, Nicolas Guiard, Euan Haahr, Derek Haase, Sven-Hendrik
Haase, John Haddon, Niklas Harrysson, Daniel Heckenberg, Chris Hellmuth,
Adrien Herubel, Dan Horák, Thiago Ize, Matt Johnson, Ronan Keryell, Chris
Kulla, Elvic Liang, Max Liani, Adam Martinez, John Mertic, Bastien Montagne,
Steena Monteiro, Alexis Oblet, Erich Ocean, Mikko Ohtamaa, Jino Park, Alexei
Pawlow, Jay Reynolds, Declan Russell, Benoit Ruiz, Patrick Scheibe, Alex
Schworer, Jonathan Scruggs, Sergey Sharybin, Sandip Shukla, Cliff Stein,
Stephan Steinbach, Luya Tshimbalanga, Esteban Tovagliari, Brecht Van Lommel,
Alexander von Knorring, Alex Wells, Roman Zulak. (Listed alphabetically; if
we've left anybody out, it is inadvertent, please let us know.)
Steena Monteiro, Patrick Mours, Alexis Oblet, Erich Ocean, Mikko Ohtamaa, Jino
Park, Alexei Pawlow, Jay Reynolds, Declan Russell, Benoit Ruiz, Patrick
Scheibe, Alex Schworer, Jonathan Scruggs, Sergey Sharybin, Mark Sisson, Sandip
Shukla, Cliff Stein, Stephan Steinbach, Luya Tshimbalanga, Esteban Tovagliari,
Brecht Van Lommel, Alexander von Knorring, Alex Wells, Roman Zulak. (Listed
alphabetically; if we've left anybody out, it is inadvertent, please let us
know.)
We cannot possibly express sufficient gratitude to the managers at Sony
Pictures Imageworks who allowed this project to proceed, supported it
+8 -4
View File
@@ -189,6 +189,10 @@ else ifeq (${platform}, macosx)
MY_CMAKE_FLAGS += \
-DCMAKE_C_COMPILER=/usr/local/opt/llvm@15/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@15/bin/clang++
else ifeq (${COMPILER},clang16)
MY_CMAKE_FLAGS += \
-DCMAKE_C_COMPILER=/usr/local/opt/llvm@16/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@16/bin/clang++
else ifeq (${COMPILER},clang)
MY_CMAKE_FLAGS += -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
else ifeq (${COMPILER},gcc)
@@ -196,13 +200,13 @@ else ifeq (${platform}, macosx)
else ifeq (${COMPILER},)
# default compiler is clang, taken from the LLVM directory
MY_CMAKE_FLAGS += \
-DCMAKE_C_COMPILER=${LLVM_DIRECTORY}/bin/clang \
-DCMAKE_CXX_COMPILER=${LLVM_DIRECTORY}/bin/clang++
-DCMAKE_C_COMPILER=${LLVM_ROOT}/bin/clang \
-DCMAKE_CXX_COMPILER=${LLVM_ROOT}/bin/clang++
else ifeq (${COMPILER},llvm)
# "llvm" means "use the clang from our llvm"
MY_CMAKE_FLAGS += \
-DCMAKE_C_COMPILER=${LLVM_DIRECTORY}/bin/clang \
-DCMAKE_CXX_COMPILER=${LLVM_DIRECTORY}/bin/clang++
-DCMAKE_C_COMPILER=${LLVM_ROOT}/bin/clang \
-DCMAKE_CXX_COMPILER=${LLVM_ROOT}/bin/clang++
endif
# end generic OSX
+1 -1
View File
@@ -14,7 +14,7 @@ uname
if [[ `uname` == "Linux" ]] ; then
LLVM_VERSION=${LLVM_VERSION:=13.0.0}
LLVM_VERSION=${LLVM_VERSION:=14.0.0}
LLVM_INSTALL_DIR=${LLVM_INSTALL_DIR:=${PWD}/llvm-install}
if [[ "$GITHUB_WORKFLOW" != "" ]] ; then
LLVM_DISTRO_NAME=${LLVM_DISTRO_NAME:=ubuntu-18.04}
+6
View File
@@ -21,6 +21,12 @@ function ( NVCC_COMPILE cuda_src extra_headers ptx_generated extra_nvcc_args )
list (TRANSFORM OpenImageIO_INCLUDES PREPEND -I
OUTPUT_VARIABLE ALL_OpenImageIO_INCLUDES)
if (${LLVM_VERSION} VERSION_GREATER_EQUAL 15.0)
# Until we fully support opaque pointers, we need to disable
# them when using LLVM 15.
list (APPEND LLVM_COMPILE_FLAGS -Xclang -no-opaque-pointers)
endif ()
add_custom_command ( OUTPUT ${cuda_ptx}
COMMAND ${CUDA_NVCC_EXECUTABLE}
"-I${OPTIX_INCLUDES}"
+14
View File
@@ -115,6 +115,7 @@ checked_find_package (pugixml REQUIRED
# LLVM library setup
checked_find_package (LLVM REQUIRED
VERSION_MIN 9.0
VERSION_MAX 15.9
PRINT LLVM_SYSTEM_LIBRARIES CLANG_LIBRARIES)
# ensure include directory is added (in case of non-standard locations
include_directories (BEFORE SYSTEM "${LLVM_INCLUDES}")
@@ -144,6 +145,19 @@ if (LLVM_VERSION VERSION_GREATER_EQUAL 15.0
"If you are using LLVM 15 or higher, you should also use clang version "
"15 or higher, or you may get build errors.${ColorReset}\n")
endif ()
if (LLVM_VERSION VERSION_GREATER_EQUAL 16.0)
message (ERROR "${ColorYellow}OSL is not yet compatible with LLVM 16.${ColorReset}\n")
if (CMAKE_CXX_STANDARD VERSION_LESS 17)
message (WARNING "${ColorYellow}LLVM 16+ requires C++17 or higher. "
"Please set CMAKE_CXX_STANDARD to 17 or higher.${ColorReset}\n")
endif ()
if (CMAKE_COMPILER_IS_GNUCC AND (GCC_VERSION VERSION_LESS 7.0))
message (WARNING "${ColorYellow}LLVM 16+ requires gcc 7.0 or higher.${ColorReset}\n")
endif ()
if (CMAKE_COMPILER_IS_CLANG AND (CLANG_VERSION_STRING VERSION_LESS 5.0))
message (WARNING "${ColorYellow}LLVM 16+ requires clang 5.0 or higher.${ColorReset}\n")
endif ()
endif ()
checked_find_package (partio)
+7 -1
View File
@@ -23,7 +23,13 @@
# try to find llvm-config, with a specific version if specified
if (LLVM_DIRECTORY)
set (LLVM_CONFIG_PATH_HINTS "${LLVM_DIRECTORY}/bin")
list (APPEND LLVM_CONFIG_PATH_HINTS "${LLVM_DIRECTORY}/bin")
endif ()
if (LLVM_ROOT)
list (APPEND LLVM_CONFIG_PATH_HINTS "${LLVM_ROOT}/bin")
endif ()
if (DEFINED ENV{LLVM_ROOT})
list (APPEND LLVM_CONFIG_PATH_HINTS "$ENV{LLVM_ROOT}/bin")
endif ()
list (APPEND LLVM_CONFIG_PATH_HINTS
"/usr/local/opt/llvm/${LLVM_VERSION}/bin/"
+1
View File
@@ -298,6 +298,7 @@ macro (osl_add_all_tests)
oslc-err-struct-dup oslc-err-struct-print
oslc-err-type-as-variable
oslc-err-unknown-ctr
oslc-literalfold
oslc-pragma-warnerr
oslc-warn-commainit
oslc-variadic-macro
-11
View File
@@ -15,21 +15,10 @@
OSL_NAMESPACE_ENTER
// Strings are handled differently in OptiX 6 vs OptiX 7.
//
// In OptiX 7+:
// Strings are not stored on the GPU at all. Strings are represented by
// their hash values which are computed at compile-time. Because of this,
// we have no access to either the strings' contents or their lengths.
//
// In OptiX 6:
// Strings are stored in a block of CUDA device memory. String variables hold a
// pointer to the start of the char array for each string. Each canonical string
// has a unique entry in the table, so two strings can be tested for equality by
// comparing their addresses.
//
// As a convenience, the ustring hash and the length of the string are also
// stored in the table, in the 16 bytes preceding the characters.
struct DeviceString {
#ifdef __CUDA_ARCH__
+97 -36
View File
@@ -1116,90 +1116,151 @@ ASTassign_expression::opword() const
OSL_ASSERT (0 && "unknown assignment expression");
return "assign"; // punt
}
// clang-format on
}
ASTunary_expression::ASTunary_expression (OSLCompilerImpl *comp, int op,
ASTNode *expr)
: ASTNode (unary_expression_node, comp, op, expr)
ASTunary_expression::ASTunary_expression(OSLCompilerImpl* comp, int op,
ASTNode* expr)
: ASTNode(unary_expression_node, comp, op, expr)
{
// Check for a user-overloaded function for this operator
Symbol *sym = comp->symtab().find(ustring::fmtformat("__operator__{}__", opword()));
Symbol* sym = comp->symtab().find(
ustring::fmtformat("__operator__{}__", opword()));
if (sym && sym->symtype() == SymTypeFunction)
m_function_overload = (FunctionSymbol *)sym;
m_function_overload = (FunctionSymbol*)sym;
}
const char *
ASTunary_expression::childname (size_t i) const
const char*
ASTunary_expression::childname(size_t i) const
{
static const char *name[] = { "expression" };
static const char* name[] = { "expression" };
return name[i];
}
const char *
ASTunary_expression::opname () const
const char*
ASTunary_expression::opname() const
{
switch (m_op) {
case Add : return "+";
case Sub : return "-";
case Not : return "!";
case Compl : return "~";
default:
OSL_ASSERT (0 && "unknown unary expression");
return "unknown";
case Add: return "+";
case Sub: return "-";
case Not: return "!";
case Compl: return "~";
default: OSL_ASSERT(0 && "unknown unary expression"); return "unknown";
}
}
const char *
ASTunary_expression::opword () const
const char*
ASTunary_expression::opword() const
{
switch (m_op) {
case Add : return "add";
case Sub : return "neg";
case Not : return "not";
case Compl : return "compl";
default:
OSL_ASSERT (0 && "unknown unary expression");
return "unknown";
case Add: return "add";
case Sub: return "neg";
case Not: return "not";
case Compl: return "compl";
default: OSL_ASSERT(0 && "unknown unary expression"); return "unknown";
}
}
ASTbinary_expression::ASTbinary_expression (OSLCompilerImpl *comp, Operator op,
ASTNode *left, ASTNode *right)
: ASTNode (binary_expression_node, comp, op, left, right)
ASTbinary_expression::ASTbinary_expression(OSLCompilerImpl* comp, Operator op,
ASTNode* left, ASTNode* right)
: ASTNode(binary_expression_node, comp, op, left, right)
{
// Check for a user-overloaded function for this operator.
// Disallow a few ops from overloading.
if (op != And && op != Or) {
ustring funcname = ustring::fmtformat("__operator__{}__", opword());
Symbol *sym = comp->symtab().find (funcname);
Symbol* sym = comp->symtab().find(funcname);
if (sym && sym->symtype() == SymTypeFunction)
m_function_overload = (FunctionSymbol *)sym;
m_function_overload = (FunctionSymbol*)sym;
}
}
const char *
ASTbinary_expression::childname (size_t i) const
ASTNode*
ASTbinary_expression::make(OSLCompilerImpl* comp, Operator op, ASTNode* left,
ASTNode* right)
{
static const char *name[] = { "left", "right" };
// If the left and right are both literal constants, fold the expression
if (left->nodetype() == literal_node && right->nodetype() == literal_node) {
ASTNode* cf = nullptr; // constant-folded result
if (left->typespec().is_int() && right->typespec().is_int()) {
int lv = dynamic_cast<ASTliteral*>(left)->intval();
int rv = dynamic_cast<ASTliteral*>(right)->intval();
switch (op) {
case Mul: cf = new ASTliteral(comp, lv * rv); break;
case Div: cf = new ASTliteral(comp, rv ? lv / rv : 0); break;
case Add: cf = new ASTliteral(comp, lv + rv); break;
case Sub: cf = new ASTliteral(comp, lv - rv); break;
case Mod: cf = new ASTliteral(comp, rv ? lv % rv : 0); break;
case Equal: cf = new ASTliteral(comp, lv == rv ? 1 : 0); break;
case NotEqual: cf = new ASTliteral(comp, lv != rv ? 1 : 0); break;
case Greater: cf = new ASTliteral(comp, lv > rv ? 1 : 0); break;
case Less: cf = new ASTliteral(comp, lv < rv ? 1 : 0); break;
case GreaterEqual:
cf = new ASTliteral(comp, lv >= rv ? 1 : 0);
break;
case LessEqual: cf = new ASTliteral(comp, lv <= rv ? 1 : 0); break;
case BitAnd: cf = new ASTliteral(comp, lv & rv); break;
case BitOr: cf = new ASTliteral(comp, lv | rv); break;
case Xor: cf = new ASTliteral(comp, lv ^ rv); break;
case ShiftLeft: cf = new ASTliteral(comp, lv << rv); break;
case ShiftRight: cf = new ASTliteral(comp, lv >> rv); break;
default: break;
}
} else if (left->typespec().is_float()
&& right->typespec().is_float()) {
float lv = dynamic_cast<ASTliteral*>(left)->floatval();
float rv = dynamic_cast<ASTliteral*>(right)->floatval();
switch (op) {
case Mul: cf = new ASTliteral(comp, lv * rv); break;
case Div: cf = new ASTliteral(comp, rv ? lv / rv : 0.0f); break;
case Add: cf = new ASTliteral(comp, lv + rv); break;
case Sub: cf = new ASTliteral(comp, lv - rv); break;
case Equal: cf = new ASTliteral(comp, lv == rv ? 1 : 0); break;
case NotEqual: cf = new ASTliteral(comp, lv != rv ? 1 : 0); break;
case Greater: cf = new ASTliteral(comp, lv > rv ? 1 : 0); break;
case Less: cf = new ASTliteral(comp, lv < rv ? 1 : 0); break;
case GreaterEqual:
cf = new ASTliteral(comp, lv >= rv ? 1 : 0);
break;
case LessEqual: cf = new ASTliteral(comp, lv <= rv ? 1 : 0); break;
default: break;
}
}
if (cf) {
delete left;
delete right;
return cf;
}
}
return new ASTbinary_expression(comp, op, left, right);
}
const char*
ASTbinary_expression::childname(size_t i) const
{
static const char* name[] = { "left", "right" };
return name[i];
}
const char *
ASTbinary_expression::opname () const
const char*
ASTbinary_expression::opname() const
{
// clang-format off
switch (m_op) {
+4
View File
@@ -832,6 +832,10 @@ public:
ASTbinary_expression(OSLCompilerImpl* comp, Operator op, ASTNode* left,
ASTNode* right);
// Special consructor wrapper that can collapse ops between literals
static ASTNode* make(OSLCompilerImpl* comp, Operator op, ASTNode* left,
ASTNode* right);
const char* nodetypename() const { return "binary_expression"; }
const char* childname(size_t i) const;
const char* opname() const;
+18 -18
View File
@@ -858,109 +858,109 @@ variable_ref
binary_expression
: expression OR_OP expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Or, $1, $3);
$$->sourceline (@2.first_line);
}
| expression AND_OP expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::And, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '|' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::BitOr, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '^' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Xor, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '&' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::BitAnd, $1, $3);
$$->sourceline (@2.first_line);
}
| expression EQ_OP expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Equal, $1, $3);
$$->sourceline (@2.first_line);
}
| expression NE_OP expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::NotEqual, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '>' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Greater, $1, $3);
$$->sourceline (@2.first_line);
}
| expression GE_OP expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::GreaterEqual, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '<' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Less, $1, $3);
$$->sourceline (@2.first_line);
}
| expression LE_OP expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::LessEqual, $1, $3);
$$->sourceline (@2.first_line);
}
| expression SHL_OP expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::ShiftLeft, $1, $3);
$$->sourceline (@2.first_line);
}
| expression SHR_OP expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::ShiftRight, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '+' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Add, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '-' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Sub, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '*' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Mul, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '/' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Div, $1, $3);
$$->sourceline (@2.first_line);
}
| expression '%' expression
{
$$ = new ASTbinary_expression (oslcompiler,
$$ = ASTbinary_expression::make(oslcompiler,
ASTNode::Mod, $1, $3);
$$->sourceline (@2.first_line);
}
+7 -6
View File
@@ -398,12 +398,8 @@ public:
/// Execute the upstream connection (if any, and if not yet run) that
/// establishes the value of symbol sym, which has index 'symindex'
/// within the current layer rop.inst(). If already_run is not NULL,
/// it points to a vector of layer indices that are known to have been
/// run -- those can be skipped without dynamically checking their
/// execution status.
void llvm_run_connected_layers(Symbol& sym, int symindex, int opnum = -1,
std::set<int>* already_run = NULL);
/// within the current layer rop.inst().
void llvm_run_connected_layers(Symbol& sym, int symindex, int opnum = -1);
/// Generate code for a call to the named function with the given
/// arg list as symbols -- float & ints will be passed by value,
@@ -501,6 +497,11 @@ public:
shadingsys().m_stat_tex_calls_as_handles += 1;
}
void increment_useparam_ops()
{
shadingsys().m_stat_useparam_ops++;
}
/// Return the mapping from symbol names to GlobalVariables.
std::map<std::string, llvm::GlobalVariable*>& get_const_map()
{
+4 -6
View File
@@ -477,13 +477,9 @@ public:
/// Execute the upstream connection (if any, and if not yet run) that
/// establishes the value of symbol sym, which has index 'symindex'
/// within the current layer rop.inst(). If already_run is not NULL,
/// it points to a vector of layer indices that are known to have been
/// run -- those can be skipped without dynamically checking their
/// execution status.
/// within the current layer rop.inst().
void llvm_run_connected_layers(const Symbol& sym, int symindex,
int opnum = -1,
std::set<int>* already_run = NULL);
int opnum = -1);
@@ -705,6 +701,8 @@ public:
shadingsys().m_stat_tex_calls_as_handles += 1;
}
void increment_useparam_ops() { shadingsys().m_stat_useparam_ops++; }
void llvm_print_mask(const char* title, llvm::Value* mask = nullptr);
/// Return the userdata index for the given Symbol. Return -1 if the Symbol
+21 -18
View File
@@ -149,14 +149,15 @@ BatchedBackendLLVM::llvm_call_layer(int layer, bool unconditional)
if (!unconditional)
ll.op_branch(after_block); // also moves insert point
shadingsys().m_stat_call_layers_inserted++;
}
void
BatchedBackendLLVM::llvm_run_connected_layers(const Symbol& sym, int symindex,
int opnum,
std::set<int>* already_run)
int opnum)
{
if (sym.valuesource() != Symbol::ConnectedVal)
return; // Nothing to do
@@ -171,16 +172,6 @@ BatchedBackendLLVM::llvm_run_connected_layers(const Symbol& sym, int symindex,
const Connection& con(inst()->connection(c));
// If the connection gives a value to this param
if (con.dst.param == symindex) {
// already_run is a set of layers run for this particular op.
// Just so we don't stupidly do several consecutive checks on
// whether we ran this same layer. It's JUST for this op.
if (already_run) {
if (already_run->count(con.srclayer))
continue; // already ran that one on this op
else
already_run->insert(con.srclayer); // mark it
}
if (inmain) {
// There is an instance-wide m_layers_already_run that tries
// to remember which earlier layers have unconditionally
@@ -199,6 +190,16 @@ BatchedBackendLLVM::llvm_run_connected_layers(const Symbol& sym, int symindex,
}
}
// m_call_layers_inserted tracks if we've already run this layer either:
// * inside the current basic block (opnum >= 0)
// * while writing output parameters (opnum == -1)
const CallLayerKey key = { opnum >= 0 ? m_bblockids[opnum] : opnum,
con.srclayer };
if (m_call_layers_inserted.count(key)) {
continue;
}
m_call_layers_inserted.insert(key);
// If the earlier layer it comes from has not yet been
// executed, do so now.
llvm_call_layer(con.srclayer);
@@ -223,15 +224,11 @@ LLVMGEN(llvm_gen_useparam)
std::cout << ">>>>>>>>>>>>>>>>>>>>>llvm_gen_useparam <<<<<<<<<<<<<<<<<<<"
<< std::endl);
// If we have multiple params needed on this statement, don't waste
// time checking the same upstream layer more than once.
std::set<int> already_run;
Opcode& op(rop.inst()->ops()[opnum]);
for (int i = 0; i < op.nargs(); ++i) {
Symbol& sym = *rop.opargsym(op, i);
int symindex = rop.inst()->arg(op.firstarg() + i);
rop.llvm_run_connected_layers(sym, symindex, opnum, &already_run);
rop.llvm_run_connected_layers(sym, symindex, opnum);
// If it's an interpolated (userdata) parameter and we're
// initializing them lazily, now we have to do it.
if ((sym.symtype() == SymTypeParam
@@ -243,6 +240,9 @@ LLVMGEN(llvm_gen_useparam)
rop.ll.current_mask()));
}
}
rop.increment_useparam_ops();
return true;
}
@@ -1677,6 +1677,7 @@ LLVMGEN(llvm_gen_modulus)
int num_components = type.aggregate;
#if 0
if (is_float && !op_is_uniform) {
// llvm 5.0.1 did not do a good job with op_mod when its
// parameters were <16xf32>. So we will go ahead
@@ -1703,7 +1704,9 @@ LLVMGEN(llvm_gen_modulus)
}
rop.ll.call_function(rop.build_name(func_spec), call_args);
} else {
} else
#endif
{
for (int i = 0; i < num_components; i++) {
llvm::Value* a = rop.loadLLVMValue(A, i, 0, type, op_is_uniform);
llvm::Value* b = rop.loadLLVMValue(B, i, 0, type, op_is_uniform);
+1
View File
@@ -2096,6 +2096,7 @@ BatchedBackendLLVM::build_llvm_instance(bool groupentry)
// records for each.
find_basic_blocks();
find_conditionals();
m_call_layers_inserted.clear();
build_llvm_code(inst()->maincodebegin(), inst()->maincodeend());
+6 -1
View File
@@ -248,10 +248,10 @@ UNARY_OP_IMPL(log10)
UNARY_OP_IMPL(exp)
UNARY_OP_IMPL(exp2)
UNARY_OP_IMPL(expm1)
BINARY_OP_IMPL(pow)
UNARY_OP_IMPL(erf)
UNARY_OP_IMPL(erfc)
BINARY_OP_IMPL(pow)
DECL(osl_pow_vvf, "xXXf")
DECL(osl_pow_dvdvdf, "xXXX")
DECL(osl_pow_dvvdf, "xXXX")
@@ -285,7 +285,12 @@ DECL(osl_fabs_ii, "ii")
UNARY_OP_IMPL(abs)
UNARY_OP_IMPL(fabs)
BINARY_OP_IMPL(fmod)
DECL(osl_fmod_vvf, "xXXf")
DECL(osl_fmod_dvdvdf, "xXXX")
DECL(osl_fmod_dvvdf, "xXXX")
DECL(osl_fmod_dvdvf, "xXXf")
DECL(osl_smoothstep_ffff, "ffff")
DECL(osl_smoothstep_dfffdf, "xXffX")
+8 -2
View File
@@ -653,10 +653,16 @@ ShaderInstance::mergeable(const ShaderInstance& b,
continue;
if (sym->typespec().is_closure())
continue; // Closures can't have instance override values
// Even if the symbols' values match now, they might not in the
// future with 'interactive' parameters.
const Symbol* b_sym = optimized ? b.symbol(i) : b.mastersymbol(i);
if ((sym->valuesource() == Symbol::InstanceVal
|| sym->valuesource() == Symbol::DefaultVal)
&& memcmp(param_storage(i), b.param_storage(i),
sym->typespec().simpletype().size())) {
&& (memcmp(param_storage(i), b.param_storage(i),
sym->typespec().simpletype().size())
// || b_sym->interactive())
|| !b_sym->lockgeom())
) {
return false;
}
}
+17 -17
View File
@@ -142,13 +142,14 @@ BackendLLVM::llvm_call_layer(int layer, bool unconditional)
if (!unconditional)
ll.op_branch(after_block); // also moves insert point
shadingsys().m_stat_call_layers_inserted++;
}
void
BackendLLVM::llvm_run_connected_layers(Symbol& sym, int symindex, int opnum,
std::set<int>* already_run)
BackendLLVM::llvm_run_connected_layers(Symbol& sym, int symindex, int opnum)
{
if (sym.valuesource() != Symbol::ConnectedVal)
return; // Nothing to do
@@ -160,16 +161,6 @@ BackendLLVM::llvm_run_connected_layers(Symbol& sym, int symindex, int opnum,
const Connection& con(inst()->connection(c));
// If the connection gives a value to this param
if (con.dst.param == symindex) {
// already_run is a set of layers run for this particular op.
// Just so we don't stupidly do several consecutive checks on
// whether we ran this same layer. It's JUST for this op.
if (already_run) {
if (already_run->count(con.srclayer))
continue; // already ran that one on this op
else
already_run->insert(con.srclayer); // mark it
}
if (inmain) {
// There is an instance-wide m_layers_already_run that tries
// to remember which earlier layers have unconditionally
@@ -188,6 +179,16 @@ BackendLLVM::llvm_run_connected_layers(Symbol& sym, int symindex, int opnum,
}
}
// m_call_layers_inserted tracks if we've already run this layer either:
// * inside the current basic block (opnum >= 0)
// * while writing output parameters (opnum == -1)
const CallLayerKey key = { opnum >= 0 ? m_bblockids[opnum] : opnum,
con.srclayer };
if (m_call_layers_inserted.count(key)) {
continue;
}
m_call_layers_inserted.insert(key);
// If the earlier layer it comes from has not yet been
// executed, do so now.
llvm_call_layer(con.srclayer);
@@ -214,15 +215,11 @@ LLVMGEN(llvm_gen_useparam)
OSL_DASSERT(!rop.inst()->unused()
&& "oops, thought this layer was unused, why do we call it?");
// If we have multiple params needed on this statement, don't waste
// time checking the same upstream layer more than once.
std::set<int> already_run;
Opcode& op(rop.inst()->ops()[opnum]);
for (int i = 0; i < op.nargs(); ++i) {
Symbol& sym = *rop.opargsym(op, i);
int symindex = rop.inst()->arg(op.firstarg() + i);
rop.llvm_run_connected_layers(sym, symindex, opnum, &already_run);
rop.llvm_run_connected_layers(sym, symindex, opnum);
// If it's an interpolated (userdata) parameter and we're
// initializing them lazily, now we have to do it.
if ((sym.symtype() == SymTypeParam
@@ -233,6 +230,9 @@ LLVMGEN(llvm_gen_useparam)
rop.llvm_assign_initial_value(sym);
}
}
rop.increment_useparam_ops();
return true;
}
+5 -8
View File
@@ -279,14 +279,10 @@ BackendLLVM::llvm_type_groupdata()
++order;
for (int i = 0; i < nuserdata; ++i) {
TypeDesc type = types[i];
// NB: Userdata derivs are not currently supported in OptiX, since
// making room for them in the GroupData struct can result in a
// large per-thread memory allocation, which could negatively
// impact performance.
int n = (!use_optix()) ? type.numelements()
* 3 // make room for derivs by default
: type.numelements();
type.arraylen = n;
// make room for float derivs only
type.arraylen = type.basetype == TypeDesc::FLOAT
? type.numelements() * 3
: type.numelements();
fields.push_back(llvm_type(type));
m_groupdata_field_names.emplace_back(
fmtformat("userdata{}_{}_", i, names[i]));
@@ -1102,6 +1098,7 @@ BackendLLVM::build_llvm_instance(bool groupentry)
// records for each.
find_basic_blocks();
find_conditionals();
m_call_layers_inserted.clear();
build_llvm_code(inst()->maincodebegin(), inst()->maincodeend());
+16 -1
View File
@@ -909,7 +909,7 @@ private:
std::vector<ustring> m_renderer_outputs; ///< Names of renderer outputs
std::vector<SymLocationDesc> m_symlocs;
int m_max_local_mem_KB; ///< Local storage can a shader use
bool m_compile_report; ///< Print compilation report?
int m_compile_report; ///< Print compilation report?
bool m_buffer_printf; ///< Buffer/batch printf output?
bool m_no_noise; ///< Substitute trivial noise calls
bool m_no_pointcloud; ///< Substitute trivial pointcloud calls
@@ -955,6 +955,8 @@ private:
atomic_int m_stat_global_connections; ///< Stat: global connections elim'd
atomic_int m_stat_tex_calls_codegened; ///< Stat: total texture calls
atomic_int m_stat_tex_calls_as_handles; ///< Stat: texture calls with handles
atomic_int m_stat_useparam_ops; ///< Stat: pre-optimization useparam ops
atomic_int m_stat_call_layers_inserted; ///< Stat: post-opt layer calls
double m_stat_master_load_time; ///< Stat: time loading masters
double m_stat_optimization_time; ///< Stat: time spent optimizing
double m_stat_opt_locking_time; ///< locking time
@@ -2606,6 +2608,19 @@ protected:
std::vector<char> m_in_conditional; ///< Whether each op is in a cond
std::vector<char> m_in_loop; ///< Whether each op is in a loop
int m_first_return; ///< Op number of first return or exit
struct CallLayerKey {
int bblockid;
int layerid;
bool operator<(const CallLayerKey& other) const
{
return bblockid < other.bblockid
|| (bblockid == other.bblockid && layerid < other.layerid);
}
};
std::set<CallLayerKey>
m_call_layers_inserted; ///< Lookup used during llvm gen
};
}; // namespace pvt
+2
View File
@@ -3384,6 +3384,8 @@ RuntimeOptimizer::run()
new_nops, old_nops,
100.0 * double((long long)new_nops - (long long)old_nops)
/ double(old_nops));
}
if (shadingsys().m_compile_report > 1) {
if (does_nothing)
shadingcontext()->infofmt("Group does nothing");
if (m_textures_needed.size()) {
+9 -2
View File
@@ -1049,7 +1049,7 @@ ShadingSystemImpl::ShadingSystemImpl(RendererServices* renderer,
, m_llvm_output_bitcode(0)
, m_llvm_dumpasm(0)
, m_max_local_mem_KB(2048)
, m_compile_report(false)
, m_compile_report(0)
, m_buffer_printf(true)
, m_no_noise(false)
, m_no_pointcloud(false)
@@ -1093,6 +1093,8 @@ ShadingSystemImpl::ShadingSystemImpl(RendererServices* renderer,
m_stat_global_connections = 0;
m_stat_tex_calls_codegened = 0;
m_stat_tex_calls_as_handles = 0;
m_stat_useparam_ops = 0;
m_stat_call_layers_inserted = 0;
m_stat_master_load_time = 0;
m_stat_optimization_time = 0;
m_stat_getattribute_time = 0;
@@ -1768,6 +1770,8 @@ ShadingSystemImpl::getattribute(string_view name, TypeDesc type, void* val)
ATTR_DECODE("stat:global_connections", int, m_stat_global_connections);
ATTR_DECODE("stat:tex_calls_codegened", int, m_stat_tex_calls_codegened);
ATTR_DECODE("stat:tex_calls_as_handles", int, m_stat_tex_calls_as_handles);
ATTR_DECODE("stat:useparam_ops", int, m_stat_useparam_ops);
ATTR_DECODE("stat:call_layers_inserted", int, m_stat_call_layers_inserted);
ATTR_DECODE("stat:master_load_time", float, m_stat_master_load_time);
ATTR_DECODE("stat:optimization_time", float, m_stat_optimization_time);
ATTR_DECODE("stat:opt_locking_time", float, m_stat_opt_locking_time);
@@ -2402,6 +2406,8 @@ ShadingSystemImpl::getstats(int level) const
* (double(m_stat_postopt_syms)
/ (std::max(1, (int)m_stat_preopt_syms))
- 1.0));
print(out, " Optimized {} useparam ops into {} llvm run layer calls\n",
m_stat_useparam_ops, m_stat_call_layers_inserted);
}
print(out, " Constant connections eliminated: {}\n",
(int)m_stat_const_connections);
@@ -4165,7 +4171,8 @@ ShadingContext::ocio_transform(StringParam fromspace, StringParam tospace,
const float eps = 0.001f;
Color3 CC[3] = { C.val(), C.val() + eps * C.dx(),
C.val() + eps * C.dy() };
cp->apply((float*)&CC, 3, 1, 3, sizeof(float), sizeof(Color3), 0);
cp->apply((float*)&CC, 3, 1, 3, sizeof(float), sizeof(Color3),
3 * sizeof(Color3));
Cout.set(CC[0], (CC[1] - CC[0]) * (1.0f / eps),
(CC[2] - CC[0]) * (1.0f / eps));
return true;
+4 -2
View File
@@ -90,8 +90,10 @@ abs(const Dual2<float>& x)
#define __OSL_XMACRO_ARGS (fabs, std::abs)
#include "wide_opunary_int_xmacro.h"
#define __OSL_XMACRO_ARGS (fmod, OIIO::safe_fmod)
#include "wide_opbinary_per_component_float_or_vector_xmacro.h"
#define __OSL_XMACRO_ARGS (fmod, OIIO::safe_fmod, safe_fmod)
#include "wide_opbinary_per_component_xmacro.h"
#define __OSL_XMACRO_ARGS (fmod, OIIO::safe_fmod, safe_fmod)
#include "wide_opbinary_per_component_mixed_vector_float_xmacro.h"
static OSL_FORCEINLINE float
+10 -1
View File
@@ -71,7 +71,7 @@ def run_binary_tests (opname) :
return
# Run binary tests with mixing combinations of varying(v), uniform(u), and constant(c) parameters.
# Test with constants to pass non-deriviative parameters to functions
# Test with constants to pass non-derivative parameters to functions
# Choose not to test variation of 2 constant argument, as that should be constant folded
run_binary_tests ("fmod")
run_binary_tests ("fmod_u_u")
@@ -82,6 +82,15 @@ run_binary_tests ("fmod_c_v")
run_binary_tests ("fmod_u_c")
run_binary_tests ("fmod_c_u")
run_binary_tests ("fmod_u_u_float")
run_binary_tests ("fmod_v_u_float")
run_binary_tests ("fmod_u_v_float")
run_binary_tests ("fmod_v_v_float")
run_binary_tests ("fmod_v_c_float")
run_binary_tests ("fmod_c_v_float")
run_binary_tests ("fmod_u_c_float")
run_binary_tests ("fmod_c_u_float")
run_binary_tests ("step")
run_binary_tests ("step_u_u")
run_binary_tests ("step_v_u")
@@ -0,0 +1,10 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#define __OSL_XMACRO_OPNAME fmod_c_u_float
#define __OSL_XMACRO_OP fmod
#define __OSL_XMACRO_CONSTANT_IN
#define __OSL_XMACRO_UNIFORM_IN2
#include "../common/shaders/test_binary_mixed_triple_float_xmacro.h"
@@ -0,0 +1,9 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#define __OSL_XMACRO_OPNAME fmod_c_v_float
#define __OSL_XMACRO_OP fmod
#define __OSL_XMACRO_CONSTANT_IN
#include "../common/shaders/test_binary_mixed_triple_float_xmacro.h"
@@ -0,0 +1,10 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#define __OSL_XMACRO_OPNAME fmod_u_c_float
#define __OSL_XMACRO_OP fmod
#define __OSL_XMACRO_UNIFORM_IN
#define __OSL_XMACRO_CONSTANT_IN2
#include "../common/shaders/test_binary_mixed_triple_float_xmacro.h"
@@ -0,0 +1,10 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#define __OSL_XMACRO_OPNAME fmod_u_u_float
#define __OSL_XMACRO_OP fmod
#define __OSL_XMACRO_UNIFORM_IN
#define __OSL_XMACRO_UNIFORM_IN2
#include "../common/shaders/test_binary_mixed_triple_float_xmacro.h"
@@ -0,0 +1,9 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#define __OSL_XMACRO_OPNAME fmod_u_v_float
#define __OSL_XMACRO_OP fmod
#define __OSL_XMACRO_UNIFORM_IN
#include "../common/shaders/test_binary_mixed_triple_float_xmacro.h"
@@ -0,0 +1,9 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#define __OSL_XMACRO_OPNAME fmod_v_c_float
#define __OSL_XMACRO_OP fmod
#define __OSL_XMACRO_CONSTANT_IN2
#include "../common/shaders/test_binary_mixed_triple_float_xmacro.h"
@@ -0,0 +1,9 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#define __OSL_XMACRO_OPNAME fmod_v_u_float
#define __OSL_XMACRO_OP fmod
#define __OSL_XMACRO_UNIFORM_IN2
#include "../common/shaders/test_binary_mixed_triple_float_xmacro.h"
@@ -0,0 +1,8 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#define __OSL_XMACRO_OPNAME fmod_v_v_float
#define __OSL_XMACRO_OP fmod
#include "../common/shaders/test_binary_mixed_triple_float_xmacro.h"
+4
View File
@@ -71,6 +71,7 @@ Compiled test.osl -> test.oso
cbrt (0 0 0) = 0 0 0
fmod (0 0 0, 0 0 0) = 0 0 0
mod (0 0 0, 0 0 0) = 0 0 0
fmod (0 0 0, 0.75) = 0 0 0, derivs 1 1 1, 0 0 0
abs (137) = 137
fabs (137) = 137
abs (-137) = 137
@@ -143,6 +144,7 @@ Compiled test.osl -> test.oso
cbrt (1 1 1) = 1 1 1
fmod (1 1 1, 1.5 1.5 1.5) = 1 1 1
mod (1 1 1, 1.5 1.5 1.5) = 1 1 1
fmod (1 1 1, 0.75) = 0.25 0.25 0.25, derivs 1 1 1, 0 0 0
abs (137) = 137
fabs (137) = 137
abs (-137) = 137
@@ -215,6 +217,7 @@ Compiled test.osl -> test.oso
cbrt (0 0 0) = 0 0 0
fmod (0 0 0, 0 0 0) = 0 0 0
mod (0 0 0, 0 0 0) = 0 0 0
fmod (0 0 0, 0.75) = 0 0 0, derivs 1 1 1, 0 0 0
abs (137) = 137
fabs (137) = 137
abs (-137) = 137
@@ -287,4 +290,5 @@ Compiled test.osl -> test.oso
cbrt (1 1 1) = 1 1 1
fmod (1 1 1, 1.5 1.5 1.5) = 1 1 1
mod (1 1 1, 1.5 1.5 1.5) = 1 1 1
fmod (1 1 1, 0.75) = 0.25 0.25 0.25, derivs 1 1 1, 0 0 0
+8
View File
@@ -113,4 +113,12 @@ test ()
printf (" fmod (%g, %g) = %g\n", a, b, fmod(a, b));
printf (" mod (%g, %g) = %g\n", a, b, mod(a, b));
}
{
// Special regression test: fmod with derivs
vector vec = u;
float f = 0.75;
vector r = fmod(vec, f);
printf (" fmod (%g, %g) = %g, derivs %g, %g\n", vec, f, r, Dx(r), Dy(r));
}
}
+28
View File
@@ -0,0 +1,28 @@
Compiled test.osl -> test.oso
int add_i = 8
int sub_i = 2
int mul_i = 15
int div_i = 1
int mod_i = 2
int eq_i = 0
int ne_i = 1
int gt_i = 1
int ge_i = 1
int lt_i = 0
int le_i = 0
int and_i = 1
int or_i = 7
int xor_i = 6
int shl_i = 40
int shr_i = 0
float add_f = 8.000000
float sub_f = 2.000000
float mul_f = 15.000000
float div_f = 1.666667
float eq_f = 0
float ne_f = 1
float gt_f = 1
float ge_f = 1
float lt_f = 0
float le_f = 0
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env python
# Copyright Contributors to the Open Shading Language project.
# SPDX-License-Identifier: BSD-3-Clause
# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
command = testshade("test")
+69
View File
@@ -0,0 +1,69 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
// Test oslc-side constant folding of simple binary operators on literal
// values
#define three 3
#define five 5
shader test(
int add_i = five + three,
int sub_i = five - three,
int mul_i = five * three,
int div_i = five / three,
int mod_i = five % three,
int eq_i = five == three,
int ne_i = five != three,
int gt_i = five > three,
int ge_i = five >= three,
int lt_i = five < three,
int le_i = five <= three,
int and_i = five & three,
int or_i = five | three,
int xor_i = five ^ three,
int shl_i = five << three,
int shr_i = five >> three,
float add_f = float(five) + float(three),
float sub_f = float(five) - float(three),
float mul_f = float(five) * float(three),
float div_f = float(five) / float(three),
int eq_f = float(five) == float(three),
int ne_f = float(five) != float(three),
int gt_f = float(five) > float(three),
int ge_f = float(five) >= float(three),
int lt_f = float(five) < float(three),
int le_f = float(five) <= float(three),
)
{
printf("int add_i = %d\n", add_i);
printf("int sub_i = %d\n", sub_i);
printf("int mul_i = %d\n", mul_i);
printf("int div_i = %d\n", div_i);
printf("int mod_i = %d\n", mod_i);
printf("int eq_i = %d\n", eq_i);
printf("int ne_i = %d\n", ne_i);
printf("int gt_i = %d\n", gt_i);
printf("int ge_i = %d\n", ge_i);
printf("int lt_i = %d\n", lt_i);
printf("int le_i = %d\n", le_i);
printf("int and_i = %d\n", and_i);
printf("int or_i = %d\n", or_i);
printf("int xor_i = %d\n", xor_i);
printf("int shl_i = %d\n", shl_i);
printf("int shr_i = %d\n", shr_i);
printf("float add_f = %f\n", add_f);
printf("float sub_f = %f\n", sub_f);
printf("float mul_f = %f\n", mul_f);
printf("float div_f = %f\n", div_f);
printf("float eq_f = %d\n", eq_f);
printf("float ne_f = %d\n", ne_f);
printf("float gt_f = %d\n", gt_f);
printf("float ge_f = %d\n", ge_f);
printf("float lt_f = %d\n", lt_f);
printf("float le_f = %d\n", le_f);
}
+1 -1
View File
@@ -26,7 +26,7 @@ def run_ternary_tests (opname) :
return
# Run ternary tests with mixing combinations of varying(v), uniform(u), and constant(c) parameters.
# Test with constants to pass non-deriviative parameters to functions
# Test with constants to pass non-derivative parameters to functions
# Choose not to test variation of 3 constant argument2, as that should be constant folded
# Choose not to test variation of constant and uniform arguments, assuming
# testing of varying and uniform arguments provided enough coverage.
+1 -1
View File
@@ -75,7 +75,7 @@ def run_binary_tests (opname) :
return
# Run binary tests with mixing combinations of varying(v), uniform(u), and constant(c) parameters.
# Test with constants to pass non-deriviative parameters to functions
# Test with constants to pass non-derivative parameters to functions
# Choose not to test variation of 2 constant argument, as that should be constant folded
run_binary_tests ("pow")
run_binary_tests ("pow_u_u")
+1 -1
View File
@@ -56,7 +56,7 @@ def run_binary_tests (opname) :
return
# Run binary tests with mixing combinations of varying(v), uniform(u), and constant(c) parameters.
# Test with constants to pass non-deriviative parameters to functions
# Test with constants to pass non-derivative parameters to functions
# Choose not to test variation of 2 constant argument, as that should be constant folded
run_binary_tests ("atan2")
run_binary_tests ("atan2_u_u")