OpenShadingLanguage icon indicating copy to clipboard operation
OpenShadingLanguage copied to clipboard

Writing color user data doesn't work in OptiX mode

Open DeclanRussell opened this issue 5 years ago • 2 comments

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

  1. 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.

  2. Notice that by running the test the background is black, when the expected result should be white. optix_out

  3. Interestingly, if the user data callback returns zero, the default value of the parameter is correctly retrieved. ret_zero

Versions

  • OSL branch/version: 1.11.0 -> master
  • OS: windows
  • C++ compiler: MSVC++ 14.0
  • LLVM version: 8
  • OIIO version: 2.1.0

DeclanRussell avatar May 31 '19 12:05 DeclanRussell

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.

timgrant avatar Jun 13 '19 17:06 timgrant

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!

DeclanRussell avatar Jun 20 '19 11:06 DeclanRussell