From b44492f5feaeff9391122cb1d5ae0b26298746f0 Mon Sep 17 00:00:00 2001 From: Daniel Dresser Date: Wed, 22 Oct 2025 09:39:57 -0700 Subject: [PATCH 1/2] ShaderNetwork : Fix bug causing extra shader copying when substituting --- Changes | 3 +++ src/IECoreScene/ShaderNetwork.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index c0108861cc..dc83e6ef1b 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,10 @@ 10.6.x.x (relative to 10.6.1.0) ======== +Improvements +------------ +- ShaderNetwork : Optimised applySubstitutions() for cases where not all shaders need them. 10.6.1.0 (relative to 10.6.0.2) ======== diff --git a/src/IECoreScene/ShaderNetwork.cpp b/src/IECoreScene/ShaderNetwork.cpp index eb98abc39f..0d2325f691 100644 --- a/src/IECoreScene/ShaderNetwork.cpp +++ b/src/IECoreScene/ShaderNetwork.cpp @@ -745,7 +745,10 @@ class ShaderNetwork::Implementation } } - m_parmsNeedingSubstitution[ node.handle ] = parmsNeedingSub; + if( parmsNeedingSub.size() ) + { + m_parmsNeedingSubstitution[ node.handle ] = parmsNeedingSub; + } } m_hash.append( m_output.shader ); From aead08014de4924b9f9a630eedb774372554b10f Mon Sep 17 00:00:00 2001 From: Daniel Dresser Date: Wed, 22 Oct 2025 09:41:40 -0700 Subject: [PATCH 2/2] ShaderNetwork : Allow escaped string substitutions to work correctly --- Changes | 5 +++++ include/IECoreScene/ShaderNetwork.h | 4 ++-- src/IECoreScene/ShaderNetwork.cpp | 7 +++++++ test/IECoreScene/ShaderNetworkTest.py | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index dc83e6ef1b..18df9e2db6 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,11 @@ 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 0d2325f691..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 ) 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" )