diff --git a/Changes b/Changes index c0108861cc..18df9e2db6 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,15 @@ 10.6.x.x (relative to 10.6.1.0) ======== +Improvements +------------ + +- ShaderNetwork : Optimised applySubstitutions() for cases where not all shaders need them. + +Fixes +----- + - ShaderNetwork::hashSubstitutions : Fixed shader string substitutions that are escaped with backslashes ( ie. `myText\` ). 10.6.1.0 (relative to 10.6.0.2) ======== diff --git a/include/IECoreScene/ShaderNetwork.h b/include/IECoreScene/ShaderNetwork.h index 9af9418ab1..e1aedef495 100644 --- a/include/IECoreScene/ShaderNetwork.h +++ b/include/IECoreScene/ShaderNetwork.h @@ -197,7 +197,7 @@ class IECORESCENE_API ShaderNetwork : public IECore::BlindDataHolder /// /// We support special syntax that allows you to substitute string attributes /// into the values of string parameters on shaders. - /// + /// /// If a string parameter, or string vector parameter, contains the token /// , then it will be subsituted with the value of a /// string attribute named PARAMETER_NAME. If there is no attribute named @@ -208,7 +208,7 @@ class IECORESCENE_API ShaderNetwork : public IECore::BlindDataHolder /// you can escape the angle brackets with backslashes, like /// "\" - /// Appends all attributes used by `applySubstitutions()` into the hash. + /// Appends to the hash to reflect all changes made by applySubstitutions( attributes ). void hashSubstitutions( const IECore::CompoundObject *attributes, IECore::MurmurHash &h ) const; /// Apply substitutions to all string and string vector parameters in the network, diff --git a/src/IECoreScene/ShaderNetwork.cpp b/src/IECoreScene/ShaderNetwork.cpp index eb98abc39f..ae3f97b4af 100644 --- a/src/IECoreScene/ShaderNetwork.cpp +++ b/src/IECoreScene/ShaderNetwork.cpp @@ -447,6 +447,13 @@ class ShaderNetwork::Implementation h.append( 0 ); } } + + if( m_parmsNeedingSubstitution.size() && !m_neededSubstitutions.size() ) + { + // We don't depend on any attributes, but some parameters have escaped substitutions. + // Modify hash to reflect the fact that applySubstitutions() will remove the escaping. + h.append( true ); + } } void applySubstitutions( const CompoundObject *attributes ) @@ -745,7 +752,10 @@ class ShaderNetwork::Implementation } } - m_parmsNeedingSubstitution[ node.handle ] = parmsNeedingSub; + if( parmsNeedingSub.size() ) + { + m_parmsNeedingSubstitution[ node.handle ] = parmsNeedingSub; + } } m_hash.append( m_output.shader ); diff --git a/test/IECoreScene/ShaderNetworkTest.py b/test/IECoreScene/ShaderNetworkTest.py index 1f7f5373e6..7f693eb30f 100644 --- a/test/IECoreScene/ShaderNetworkTest.py +++ b/test/IECoreScene/ShaderNetworkTest.py @@ -591,6 +591,8 @@ def testSubstitutions( self ) : } ) ) ( h6, sSubst6 ) = self.__hashAndSubstitution( s, {} ) ( h7, sSubst7 ) = self.__hashAndSubstitution( s, allAttributes ) + self.assertNotEqual( h6, IECore.MurmurHash() ) + self.assertNotEqual( h7, IECore.MurmurHash() ) self.assertEqual( h6, h7 ) self.assertEqual( sSubst6, sSubst7 ) self.assertEqual( sSubst6.parameters["a"].value, "prepost" )