Skip to content

Commit 45db9e4

Browse files
committed
USD ShaderAlgo : Emit warning for unsupported parameter types
In conjunction with the previous commit, this means that we now gracefully print a warning message for any parameter types we can't write to USD. Prior to this we were throwing a not very helpful exception and not writing anything at all. This came up in production with a GLSL shader with an ImagePlug input in Gaffer, where we pack an entire image into a CompoundData value.
1 parent 8b3385f commit 45db9e4

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Fixes
1111

1212
- ShaderNetworkAlgo : Fixed crash caused by cyclic connections in `removeUnusedShaders()`.
1313
- ShaderStateComponent : Fixed GL rendering failures caused by unsupported values for texture parameters.
14+
- USDScene : Fixed exceptions caused by attempt to write shader parameters with unsupported value types.
1415
- IECoreUSD::DataAlgo : Fixed exceptions thrown by `toUSD()` and `valueTypeName()` when passed datatypes not supported by `dispatch()`. An empty VtValue or SdfValueTypeName is now returned instead.
1516

1617
Build

contrib/IECoreUSD/src/IECoreUSD/ShaderAlgo.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,16 @@ void writeShaderParameterValues( const IECoreScene::Shader *shader, pxr::UsdShad
322322
pxr::UsdShadeInput input = usdShader.GetInput( usdParameterName );
323323
if( !input )
324324
{
325-
input = usdShader.CreateInput(
326-
toUSDParameterName( p.first ),
327-
IECoreUSD::DataAlgo::valueTypeName( p.second.get() )
328-
);
325+
pxr::SdfValueTypeName typeName = IECoreUSD::DataAlgo::valueTypeName( p.second.get() );
326+
if( !typeName )
327+
{
328+
IECore::msg( IECore::Msg::Warning, "ShaderAlgo",
329+
boost::format( "Shader parameter `%1%.%2%` has unsupported type `%3%`" )
330+
% shader->getName() % p.first % p.second->typeName()
331+
);
332+
continue;
333+
}
334+
input = usdShader.CreateInput( toUSDParameterName( p.first ), typeName );
329335
}
330336
if( auto *s = IECore::runTimeCast<IECore::StringData>( p.second.get() ) )
331337
{

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,42 @@ def testShadersAcrossDifferentScopes( self ):
31813181
) ]
31823182
)
31833183

3184+
def testUnsupportedShaderParameterTypes( self ) :
3185+
3186+
sourceNetwork = IECoreScene.ShaderNetwork(
3187+
shaders = {
3188+
"test" : IECoreScene.Shader(
3189+
"test",
3190+
parameters = {
3191+
"unsupported1" : IECore.CompoundData(),
3192+
"unsupported2" : IECore.PathMatcherData(),
3193+
"supported" : "abc"
3194+
}
3195+
)
3196+
},
3197+
output = "test"
3198+
)
3199+
3200+
fileName = os.path.join( self.temporaryDirectory(), "test.usda" )
3201+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
3202+
3203+
with IECore.CapturingMessageHandler() as mh :
3204+
root.createChild( "test" ).writeAttribute( "surface", sourceNetwork, 0 )
3205+
3206+
self.assertEqual(
3207+
{ m.message for m in mh.messages },
3208+
{
3209+
"Shader parameter `test.unsupported1` has unsupported type `CompoundData`",
3210+
"Shader parameter `test.unsupported2` has unsupported type `PathMatcherData`",
3211+
}
3212+
)
3213+
3214+
del root
3215+
3216+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
3217+
network = root.child( "test" ).readAttribute( "surface", 0 )
3218+
self.assertEqual( network.outputShader().parameters, IECore.CompoundData( { "supported" : "abc" } ) )
3219+
31843220
def testHoudiniVaryingLengthArrayPrimVar( self ) :
31853221

31863222
root = IECoreScene.SceneInterface.create(

0 commit comments

Comments
 (0)