Skip to content

Commit adef8cd

Browse files
authored
Stricter check for eliding for Shader Optimization (#2754)
This is a follow up to the PR #2746. Me and @rasmustilljander continued to look into issues related to upgrading our MaterialX 1.38 materials to MaterialX 1.39. The PR #2746 solved an issue for custom nodes getting classified as CONSTANTS but without inputs. However, we discover some more appearances having shaders generated with syntax errors not fixed by last PR. This PR tightens the check to make sure only constant/dot nodes are elided.
1 parent 2e64ebb commit adef8cd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

source/MaterialXGenShader/ShaderGraph.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void ShaderGraph::createConnectedNodes(const ElementPtr& downstreamElement,
9797
{
9898
continue;
9999
}
100-
100+
101101
InputPtr graphInput = activeInput->getInterfaceInput();
102102
if (graphInput && graphInput->hasDefaultGeomPropString())
103103
{
@@ -978,9 +978,9 @@ void ShaderGraph::optimize(GenContext& context)
978978
{
979979
if (node->hasClassification(ShaderNode::Classification::CONSTANT))
980980
{
981-
if (node->numInputs() == 0)
981+
if (node->numInputs() != 1 || node->numOutputs() != 1)
982982
{
983-
// Cannot elide a constant node with no inputs.
983+
// Constant node doesn't follow expected interface, cannot elide.
984984
continue;
985985
}
986986
// Constant nodes can be elided by moving their value downstream.
@@ -1003,9 +1003,9 @@ void ShaderGraph::optimize(GenContext& context)
10031003
}
10041004
else if (node->hasClassification(ShaderNode::Classification::DOT))
10051005
{
1006-
if (node->numInputs() == 0)
1006+
if (node->numOutputs() != 1)
10071007
{
1008-
// Cannot elide a dot node with no inputs.
1008+
// Dot node dosen't follow expected interface, cannot elide.
10091009
continue;
10101010
}
10111011
// Filename dot nodes must be elided so they do not create extra samplers.

0 commit comments

Comments
 (0)