Re: OCIOv2 with OSL native support, part III


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




Join osl-dev@lists.aswf.io to automatically receive all group messages.