OpenShadingLanguage
OpenShadingLanguage copied to clipboard
Writing color user data doesn't work in OptiX mode
Problem
The way the OptiX run time exposes user data is by directly implementing the osl_bind_interpolated_param()
function. There is already an example implementation of the callback in testrender for strings. However, it seems that if you try to use the callback for retrieving colors (and maybe other data types) the result does not get correctly passed along.
Steps to Reproduce
-
Here is a patch that hard codes the user data callback so that if color user data is requested, it returns white. The patch also modifies the testoptix test so that you can simply reproduce the results with the command: testrender.exe -optix -res 320 240 scene.xml out.exr. Notice that the checkerboard.osl shader which is used for the background of the test now should simply return a color provided by user data.
-
Notice that by running the test the background is black, when the expected result should be white.
-
Interestingly, if the user data callback returns zero, the default value of the parameter is correctly retrieved.
Versions
- OSL branch/version: 1.11.0 -> master
- OS: windows
- C++ compiler: MSVC++ 14.0
- LLVM version: 8
- OIIO version: 2.1.0
I'd have to dig a bit more to figure out exactly why the userdata lookup is failing, but in the meantime here is a patch that should unblock you: userdata-fix.txt. It makes the userdata lookup behave more like the CPU version. Lookup by name, type, etc., is possible, but requires a bit of setup.
I could maybe roll this change into #1029, or if we encounter more userdata wrinkles we can do a new PR.
Thanks Tim, I just got around to trying this patch out. Looks like its solved the issue as far as I can tell, nice one!