Skip to content

Commit

Permalink
Plumb material id into material network conversion
Browse files Browse the repository at this point in the history
so that diagnostic warnings can provide helpful context
about which material has issues.

(Internal change: 2348775)
  • Loading branch information
blevin authored and pixar-oss committed Nov 26, 2024
1 parent c5cd266 commit 4ce480f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion third_party/renderman-26/plugin/hdPrman/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ _PopulateNodesFromMaterialResource(HdSceneDelegate *sceneDelegate,

result->reserve(matNetwork2.nodes.size());
if (!HdPrman_ConvertHdMaterialNetwork2ToRmanNodes(
matNetwork2, nodePath, result)) {
id, matNetwork2, nodePath, result)) {
TF_WARN("Failed to convert HdMaterialNetwork to Renderman shading "
"nodes for '%s'", id.GetText());
return false;
Expand Down
61 changes: 36 additions & 25 deletions third_party/renderman-26/plugin/hdPrman/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ _IsWriteAsset(const TfToken& nodeName, const RtUString& paramName)
// of multi-path dependencies.
static bool
_ConvertNodes(
SdfPath const& id,
HdMaterialNetwork2 const& network,
SdfPath const& nodePath,
std::vector<riley::ShadingNode> *result,
Expand All @@ -301,7 +302,8 @@ _ConvertNodes(
auto iter = network.nodes.find(nodePath);
if (iter == network.nodes.end()) {
// This could be caused by a bad connection to a non-existent node.
TF_WARN("Unknown material node '%s'", nodePath.GetText());
TF_WARN("Unknown material node '%s' in <%s>", nodePath.GetText(),
id.GetText());
return false;
}
HdMaterialNode2 const& node = iter->second;
Expand All @@ -311,7 +313,7 @@ _ConvertNodes(
for (auto const& e: connEntry.second) {
// This method will just return if we've visited this upstream node
// before
_ConvertNodes(network, e.upstreamNode, result, visitedNodes,
_ConvertNodes(id, network, e.upstreamNode, result, visitedNodes,
elideDefaults);
}
}
Expand All @@ -337,8 +339,8 @@ _ConvertNodes(
sdrRegistry.GetShaderNodeByIdentifier(node.nodeTypeId,
_GetShaderSourceTypes());
if (!sdrEntry) {
TF_WARN("Unknown shader ID %s for node <%s>\n",
node.nodeTypeId.GetText(), nodePath.GetText());
TF_WARN("Unknown shader ID %s for node <%s> in <%s>\n",
node.nodeTypeId.GetText(), nodePath.GetText(), id.GetText());
return false;
}
// Create equivalent Riley shading node.
Expand Down Expand Up @@ -373,15 +375,16 @@ _ConvertNodes(
} else if (sdrEntry->GetContext() == SdrNodeContext->LightFilter) {
sn.type = riley::ShadingNode::Type::k_LightFilter;
} else {
TF_WARN("Unknown shader entry type '%s' for shader '%s'",
sdrEntry->GetContext().GetText(), sdrEntry->GetName().c_str());
TF_WARN("Unknown shader entry type '%s' for shader '%s' in <%s>",
sdrEntry->GetContext().GetText(), sdrEntry->GetName().c_str(),
id.GetText());
return false;
}
sn.handle = RtUString(nodePath.GetText());
std::string shaderPath = sdrEntry->GetResolvedImplementationURI();
if (shaderPath.empty()){
TF_WARN("Shader '%s' did not provide a valid implementation path.",
sdrEntry->GetName().c_str());
TF_WARN("Shader '%s' did not provide a valid implementation "
"path in <%s>.", sdrEntry->GetName().c_str(), id.GetText());
return false;
}
if (sn.type == riley::ShadingNode::Type::k_Displacement ||
Expand All @@ -402,10 +405,11 @@ _ConvertNodes(
if (!prop) {
TF_DEBUG(HDPRMAN_MATERIALS)
.Msg("Unknown shader property '%s' for "
"shader '%s' at '%s'; ignoring.\n",
"shader '%s' at '%s' in <%s>; ignoring.\n",
param.first.GetText(),
sdrEntry->GetName().c_str(),
nodePath.GetText());
nodePath.GetText(),
id.GetText());
continue;
}
// Skip parameter values that match schema-defined defaults
Expand All @@ -431,10 +435,11 @@ _ConvertNodes(
}
TF_DEBUG(HDPRMAN_MATERIALS)
.Msg("Unknown shader entry field type for "
"field '%s' on shader '%s' at '%s'; ignoring.\n",
"field '%s' on shader '%s' at '%s' in <%s>; ignoring.\n",
param.first.GetText(),
sdrEntry->GetName().c_str(),
nodePath.GetText());
nodePath.GetText(),
id.GetText());
continue;
}

Expand Down Expand Up @@ -650,11 +655,12 @@ _ConvertNodes(
if (!ok) {
TF_DEBUG(HDPRMAN_MATERIALS)
.Msg("Unknown shading parameter type '%s'; skipping "
"parameter '%s' on node '%s'; "
"parameter '%s' on node '%s' in <%s>; "
"expected type '%s'\n",
param.second.GetTypeName().c_str(),
param.first.GetText(),
nodePath.GetText(),
id.GetText(),
propType.GetText());
}
}
Expand All @@ -665,7 +671,8 @@ _ConvertNodes(
SdrShaderPropertyConstPtr downstreamProp =
sdrEntry->GetShaderInput(connEntry.first);
if (!downstreamProp) {
TF_WARN("Unknown downstream property %s", connEntry.first.data());
TF_WARN("Unknown downstream property %s in <%s>",
connEntry.first.data(), id.GetText());
continue;
}
RtUString name(downstreamProp->GetImplementationName().c_str());
Expand All @@ -680,7 +687,8 @@ _ConvertNodes(
HdMaterialNode2 const* upstreamNode =
TfMapLookupPtr(network.nodes, e.upstreamNode);
if (!upstreamNode) {
TF_WARN("Unknown upstream node %s", e.upstreamNode.GetText());
TF_WARN("Unknown upstream node %s in <%s>",
e.upstreamNode.GetText(), id.GetText());
continue;
}
// Ignore nodes of id "PrimvarPass". This node is a workaround for
Expand All @@ -693,17 +701,17 @@ _ConvertNodes(
sdrRegistry.GetShaderNodeByIdentifier(
upstreamNode->nodeTypeId, _GetShaderSourceTypes());
if (!upstreamSdrEntry) {
TF_WARN("Unknown shader for upstream node %s",
e.upstreamNode.GetText());
TF_WARN("Unknown shader for upstream node %s in <%s>",
e.upstreamNode.GetText(), id.GetText());
continue;
}
SdrShaderPropertyConstPtr upstreamProp =
upstreamSdrEntry->GetShaderOutput(e.upstreamOutputName);
// In the case of terminals there is no upstream output name
// since the whole node is referenced as a whole
if (!upstreamProp && propType != SdrPropertyTypes->Terminal) {
TF_WARN("Unknown upstream property %s",
e.upstreamOutputName.data());
TF_WARN("Unknown upstream property %s in <%s>",
e.upstreamOutputName.data(), id.GetText());
continue;
}
// Prman syntax for parameter references is "handle:param".
Expand Down Expand Up @@ -776,10 +784,11 @@ _ConvertNodes(
sn.params.SetStructReference(name, inputRefs[0]);
} else {
TF_WARN("Unsupported type struct array for property '%s' "
"on shader '%s' at '%s'; ignoring.",
"on shader '%s' at '%s' in <%s>; ignoring.",
connEntry.first.data(),
sdrEntry->GetName().c_str(),
nodePath.GetText());
nodePath.GetText(),
id.GetText());
}
} else if (propType == SdrPropertyTypes->Terminal) {
if (numInputRefs == 1) {
Expand All @@ -797,11 +806,12 @@ _ConvertNodes(
}
} else {
TF_WARN("Unknown type '%s' for property '%s' "
"on shader '%s' at %s; ignoring.",
"on shader '%s' at %s in <%s>; ignoring.",
propType.GetText(),
connEntry.first.data(),
sdrEntry->GetName().c_str(),
nodePath.GetText());
nodePath.GetText(),
id.GetText());
}
}
}
Expand All @@ -813,6 +823,7 @@ _ConvertNodes(

bool
HdPrman_ConvertHdMaterialNetwork2ToRmanNodes(
SdfPath const& id,
HdMaterialNetwork2 const& network,
SdfPath const& nodePath,
std::vector<riley::ShadingNode> *result)
Expand All @@ -824,7 +835,7 @@ HdPrman_ConvertHdMaterialNetwork2ToRmanNodes(

_PathSet visitedNodes;
return _ConvertNodes(
network, nodePath, result, &visitedNodes, elideDefaults);
id, network, nodePath, result, &visitedNodes, elideDefaults);
}

// Debug helper
Expand Down Expand Up @@ -878,7 +889,7 @@ _ConvertHdMaterialNetwork2ToRman(

for (auto const& terminal: network.terminals) {
if (HdPrman_ConvertHdMaterialNetwork2ToRmanNodes(
network, terminal.second.upstreamNode, &nodes)) {
id, network, terminal.second.upstreamNode, &nodes)) {
if (nodes.empty()) {
// Already emitted a specific warning.
continue;
Expand Down
1 change: 1 addition & 0 deletions third_party/renderman-26/plugin/hdPrman/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class HdPrmanMaterial final : public HdMaterial
/// to perform this conversion.
bool
HdPrman_ConvertHdMaterialNetwork2ToRmanNodes(
SdfPath const& id,
HdMaterialNetwork2 const& network,
SdfPath const& nodePath,
std::vector<riley::ShadingNode> *result);
Expand Down
6 changes: 3 additions & 3 deletions third_party/renderman-26/plugin/hdPrman/renderParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2723,15 +2723,15 @@ HdPrman_RenderParam::_CreateFallbackMaterials()
{
// Default material
{
SdfPath id("/_FallbackMaterial");
std::vector<riley::ShadingNode> materialNodes;
HdPrman_ConvertHdMaterialNetwork2ToRmanNodes(
HdPrmanMaterial_GetFallbackSurfaceMaterialNetwork(),
id, HdPrmanMaterial_GetFallbackSurfaceMaterialNetwork(),
SdfPath("/PxrSurface"), // We assume this terminal name here
&materialNodes
);
_fallbackMaterialId = _riley->CreateMaterial(
riley::UserId(stats::AddDataLocation("/_FallbackMaterial").
GetValue()),
riley::UserId(stats::AddDataLocation(id.GetText()).GetValue()),
{static_cast<uint32_t>(materialNodes.size()), materialNodes.data()},
RtParamList());
}
Expand Down

0 comments on commit 4ce480f

Please sign in to comment.