OCIOv2 with OSL native support, part III


Patrick Hodoul <patrick.hodoul@...>
 

HI,

That's again the OCIOv2 generating an OSL shader code related topic. Now I currently implement the corresponding OSL unit test framework in OCIO, and unfortunately I face some execution problems.

To have some context, the OSL shader declaration is:
shader OSL_OCIOMain(color4 inColor = {color(0), 1}, output color4 outColor = {color(0), 1})

And my framework mainly copies & pastes the [osl]/testsuite/example-deformer/osldeformer.cpp unit test.

The output parameter declaration is causing some trouble. The code snippet is:
<...>
OSL::SymLocationDesc outputs("layer1.outColor", OIIO::TypeFloat4, false,
                                 OSL::SymArena::Outputs,
                                 0 /* output arena offset of "out" */,
                                 sizeof(OSL::Vec4) /* point to point stride */);
    shadsys->add_symlocs(mygroup.get(), outputs);
<...>
    shadsys->optimize_group(mygroup.get(), ctx);
    const OSL::ShaderSymbol * outsym
        = shadsys->find_symbol(*mygroup.get(), OSL::ustring("layer1"), OSL::ustring("outColor"));
When the unit test runs, "shadsys->optimize_group()" generates the following outputs (from llvm_instance.cpp:1138):

No output copy for struct vector4 outColor because of type mismatch vs symloc=float4

There is a mismatch between the OSL C++ declaration and the OSL shader declaration (structure vs. type). As I used the 'color4' for the input and output variables of the shader, I found nothing equivalent in OSL C++ & OIIO C++ types so, I switched to OIIO::TypeFloat4 and OSL::Vec4. But that's clearly not the right choice.

What should be the declared types (for C++ OSL & OIIO) to match the shader 'color4' type (which is a structure containing a color and a float) ?

Thanks,
Patrick


Larry Gritz
 

First, please note that the SymLocation stuff is very hot off the presses, and only is present in OSL master, not yet in any officially supported release.

It may be better to use the older find_symbol/symbol_address approach -- which you can see commented out in master's osldeformer example. That will work for released versions of OSL.

But anyway, a color4 is not a real type (yet), it's a struct, so the implementation underneath is that there are two variables: "color4 mycolor" really just gets turned into "color mycolor.rgb" and "float mycolor.a". You can from the C++ side treat them as the two individual variables.


On Aug 31, 2021, at 6:48 AM, Patrick Hodoul <patrick.hodoul@...> wrote:

HI,

That's again the OCIOv2 generating an OSL shader code related topic. Now I currently implement the corresponding OSL unit test framework in OCIO, and unfortunately I face some execution problems.

To have some context, the OSL shader declaration is:
shader OSL_OCIOMain(color4 inColor = {color(0), 1}, output color4 outColor = {color(0), 1})

And my framework mainly copies & pastes the [osl]/testsuite/example-deformer/osldeformer.cpp unit test.

The output parameter declaration is causing some trouble. The code snippet is:
<...>
OSL::SymLocationDesc outputs("layer1.outColor", OIIO::TypeFloat4, false,
                                 OSL::SymArena::Outputs,
                                 0 /* output arena offset of "out" */,
                                 sizeof(OSL::Vec4) /* point to point stride */);
    shadsys->add_symlocs(mygroup.get(), outputs);
<...>
    shadsys->optimize_group(mygroup.get(), ctx);
    const OSL::ShaderSymbol * outsym
        = shadsys->find_symbol(*mygroup.get(), OSL::ustring("layer1"), OSL::ustring("outColor"));
When the unit test runs, "shadsys->optimize_group()" generates the following outputs (from llvm_instance.cpp:1138):

No output copy for struct vector4 outColor because of type mismatch vs symloc=float4

There is a mismatch between the OSL C++ declaration and the OSL shader declaration (structure vs. type). As I used the 'color4' for the input and output variables of the shader, I found nothing equivalent in OSL C++ & OIIO C++ types so, I switched to OIIO::TypeFloat4 and OSL::Vec4. But that's clearly not the right choice.

What should be the declared types (for C++ OSL & OIIO) to match the shader 'color4' type (which is a structure containing a color and a float) ?

Thanks,
Patrick <UnitTestOSL.cpp>

--
Larry Gritz





Patrick Hodoul <patrick.hodoul@...>
 

Thanks for the fast answers.

First, please note that the SymLocation stuff is very hot off the presses, and only is present in OSL master, not yet in any officially supported release.
Does the tag 'v1.11.14.2' represent the last official version?

But anyway, a color4 is not a real type (yet), it's a struct, so the implementation underneath is that there are two variables: "color4 mycolor" really just gets turned into "color mycolor.rgb" and "float mycolor.a". You can from the C++ side treat them as the two individual variables.
What about the input parameter which is also a color4 ?
Should I have two input parameters (like for the output parameter)?

--
Patrick


Larry Gritz
 

On Aug 31, 2021, at 10:29 AM, Patrick Hodoul <patrick.hodoul@...> wrote:

Does the tag 'v1.11.14.2' represent the last official version?

Yes, and also there is a branch called "release" that at all times points to the latest supported release. (We move the branch marker whenever we tag releases.)


What about the input parameter which is also a color4 ?
Should I have two input parameters (like for the output parameter)?

Yes, exactly. From the point of view of a program using the ShadingSystem API), a struct is really just one variable for each field of the struct.

--
Larry Gritz