LPE AOV's now use the RenderVar name rather than the LPE
authorblevin <blevin@users.noreply.github.com>
Sat, 3 Feb 2024 04:04:24 +0000 (20:04 -0800)
committerpixar-oss <pixar-oss@users.noreply.github.com>
Mon, 5 Feb 2024 20:21:06 +0000 (12:21 -0800)
expression as the channel name.  This both gives expected
outputs in EXR channels and fixes name collisions when the
same LPE is used with multiple summary statistics, such
as variance and mse.

Strip ri:displayChannel namespace from params dictionary
keys, so e.g. ri:displayChannel:statistics -> statistics,
as expected by RenderMan API.

(Internal change: 2314430)

third_party/renderman-25/plugin/hdPrman/renderDelegate.h
third_party/renderman-25/plugin/hdPrman/renderParam.cpp
third_party/renderman-25/plugin/hdPrman/testenv/testHdPrman.cpp

index 1d978089fd57a8d8cc95ebf4ac42b6acb49659fd..76e5caf76bd4286e0953411a327bfc760d8d7127 100644 (file)
@@ -61,6 +61,8 @@ TF_DECLARE_PUBLIC_TOKENS(HdPrmanRenderSettingsTokens, HDPRMAN_API,
     (renderVars)                   \
     (renderVarIndices)             \
     (name)                         \
+    (sourceName)                   \
+    (sourceType)                   \
     (type)                         \
     (params)                       \
     (camera)
index 24e5cd50550c9033196103be8917b85fd8f9d098..fa63daed0e92ed9fa68e11a03dbbd9ae4b675b32 100644 (file)
@@ -69,6 +69,9 @@ TF_DEFINE_PRIVATE_TOKENS(
     (sourceName)
     (sourceType)
     (lpe)
+
+    // See PxrDisplayChannelAPI
+    ((riDisplayChannelNamespace,    "ri:displayChannel:"))
 );
 
 TF_DEFINE_PRIVATE_TOKENS(
@@ -1365,14 +1368,19 @@ _ToRenderOutputType(const TfToken &t)
     }
 }
 
-// Helper to convert a dictionary of Hydra settings to Riley params.
+// Helper to convert a dictionary of Hydra settings to Riley params,
+// stripping the namespace prefix if provided.
 static
 RtParamList
-_ToRtParamList(VtDictionary const& dict)
+_ToRtParamList(VtDictionary const& dict, TfToken prefix=TfToken())
 {
     RtParamList params;
     for (auto const& entry: dict) {
-        RtUString riName(entry.first.c_str());
+        std::string key = entry.first;
+        if (TfStringStartsWith(key, prefix.GetString())) {
+            key = key.substr(prefix.size());
+        }
+        RtUString riName(key.c_str());
         HdPrman_Utils::SetParamFromVtValue(riName, entry.second,
                                            /* role = */ TfToken(), &params);
     }
@@ -1422,26 +1430,45 @@ _ComputeRenderViewDesc(
     
     for (const VtValue &renderVarVal : renderVars) {
         const VtDictionary renderVar = renderVarVal.Get<VtDictionary>();
+
         const std::string &nameStr =
             VtDictionaryGet<std::string>(
                 renderVar,
                 HdPrmanExperimentalRenderSpecTokens->name);
-        const RtUString name(nameStr.c_str());
+        const std::string &sourceNameStr =
+            VtDictionaryGet<std::string>(
+                renderVar,
+                HdPrmanExperimentalRenderSpecTokens->sourceName);
+        const TfToken sourceType =
+            VtDictionaryGet<TfToken>(
+                renderVar,
+                HdPrmanExperimentalRenderSpecTokens->sourceType);
+
+        // Map renderVar to RenderMan AOV name and source.
+        // For LPE's, we use the name of the prim rather than the LPE,
+        // and include an "lpe:" prefix on the source.
+        const RtUString aovName( (sourceType == _tokens->lpe)
+            ? nameStr.c_str()
+            : sourceNameStr.c_str());
+        const RtUString sourceName( (sourceType == _tokens->lpe)
+            ? ("lpe:" + sourceNameStr).c_str()
+            : sourceNameStr.c_str());
 
         HdPrman_RenderViewDesc::RenderOutputDesc renderOutputDesc;
-        renderOutputDesc.name = name;
+        renderOutputDesc.name = aovName;
         renderOutputDesc.type = _ToRenderOutputType(
             TfToken(
                 VtDictionaryGet<std::string>(
                     renderVar,
                     HdPrmanExperimentalRenderSpecTokens->type)));
-        renderOutputDesc.sourceName = name;
+        renderOutputDesc.sourceName = sourceName;
         renderOutputDesc.rule = RixStr.k_filter;
         renderOutputDesc.params = _ToRtParamList(
             VtDictionaryGet<VtDictionary>(
                 renderVar,
                 HdPrmanExperimentalRenderSpecTokens->params,
-                VtDefault = VtDictionary()));
+                VtDefault = VtDictionary()),
+            _tokens->riDisplayChannelNamespace);
         renderViewDesc.renderOutputDescs.push_back(renderOutputDesc);
     }
     
@@ -1532,22 +1559,29 @@ _ComputeRenderViewDesc(
         displayDesc.renderOutputIndices.push_back(renderVarIndex);
         renderVarIndex++;
 
-        // Map renderVar sourceName to Ri name.
-        std::string varSourceName = (renderVar.sourceType == _tokens->lpe) 
-            ? _tokens->lpe.GetString() + ":" + renderVar.sourceName
+        // Map renderVar to RenderMan AOV name and source.
+        // For LPE's, we use the name of the prim rather than the LPE,
+        // and include an "lpe:" prefix on the source.
+        std::string aovNameStr = (renderVar.sourceType == _tokens->lpe)
+            ? renderVar.varPath.GetName()
+            : renderVar.sourceName;
+        std::string sourceNameStr = (renderVar.sourceType == _tokens->lpe) 
+            ? "lpe:" + renderVar.sourceName
             : renderVar.sourceName;
-        const RtUString sourceName(varSourceName.c_str());
+        const RtUString aovName(aovNameStr.c_str());
+        const RtUString sourceName(sourceNameStr.c_str());
 
         // Create a RenderOutputDesc for this RenderVar and add it to the 
         // renderViewDesc.
         // Note that we are not using the renderOutputIndices passed into 
         // this function, we are instead relying on the indices stored above
         std::vector<size_t> renderOutputIndices;
-        _AddRenderOutput(sourceName, 
+        _AddRenderOutput(aovName, 
                         renderVar.dataType, 
                         HdFormatInvalid, // using renderVar.dataType
                         sourceName, 
-                        _ToRtParamList(renderVar.namespacedSettings),
+                        _ToRtParamList(renderVar.namespacedSettings,
+                                       _tokens->riDisplayChannelNamespace),
                         &renderViewDesc.renderOutputDescs,
                         &renderOutputIndices);
     }
index 741d3896525c9ff9e2b7cc38386221af036968cd..9ec216254c508e6f1cc95548aaf12511f2d3ef81 100644 (file)
@@ -566,15 +566,13 @@ CreateRenderSpecDict(
         for (size_t index: product.renderVarIndices) {
             auto const& renderVar = renderSpec.renderVars[index];
 
-            // Map source to Ri name.
-            std::string name = renderVar.sourceName;
-            if (renderVar.sourceType == UsdRenderTokens->lpe) {
-                name = "lpe:" + name;
-            }
-
             VtDictionary renderVarDict;
             renderVarDict[HdPrmanExperimentalRenderSpecTokens->name] =
-                name;
+                renderVar.renderVarPath.GetName();
+            renderVarDict[HdPrmanExperimentalRenderSpecTokens->sourceName] =
+                renderVar.sourceName;
+            renderVarDict[HdPrmanExperimentalRenderSpecTokens->sourceType] =
+                renderVar.sourceType;
             renderVarDict[HdPrmanExperimentalRenderSpecTokens->type] =
                 renderVar.dataType.GetString();
             renderVarDict[HdPrmanExperimentalRenderSpecTokens->params] =