[hdSt] Make converted GLSL identifier tokens immortal
authortgvarik <tgvarik@users.noreply.github.com>
Tue, 19 Dec 2023 20:50:36 +0000 (12:50 -0800)
committerpixar-oss <pixar-oss@users.noreply.github.com>
Tue, 19 Dec 2023 20:50:36 +0000 (12:50 -0800)
GLSL has strict identifier requirements. During codegen, we turn primvar (and other) names into GLSL identifiers. When the primvar name is not a legal GLSL identifier, we convert it into one using HdStGLConversions::GetGLSLIdentifier(). However, the TfTokens thus generated were short-lived, so on subsequent frames, primvars (&c.) with GL-illegal names would produce new TfTokens at new memory addresses, giving them different hash values. The hash value differences caused the program's overall hash value to change from frame to frame, triggering unnecessary recompilation.

To fix this, all TfTokens generated by GetGLSLIdentifier() will be instantiated as immortal, so that even if they go out of scope, later calls to GetGLSLIdentifier() for a given input name will produce TfTokens with the same hash value as those from earlier calls.

(Internal change: 2309306)

pxr/imaging/hdSt/glConversions.cpp

index 492681f9d7537463fc09ef10c1156c9c66315d1f..9d6092dedd064328358bf5f2c221a5d9cc1596e0 100644 (file)
@@ -402,7 +402,7 @@ HdStGLConversions::GetGLSLIdentifier(TfToken const& identifier)
         return identifier;
     }
 
-    return TfToken(result);
+    return TfToken(result, TfToken::Immortal);
 }
 
 PXR_NAMESPACE_CLOSE_SCOPE