Skip to content

Add an option to toggle eliding constant nodes - #2521

Merged
jstone-lucasfilm merged 5 commits into
AcademySoftwareFoundation:mainfrom
autodesk-forks:gamaj/allow_keeping_constant_nodes_unelided
Oct 10, 2025
Merged

Add an option to toggle eliding constant nodes#2521
jstone-lucasfilm merged 5 commits into
AcademySoftwareFoundation:mainfrom
autodesk-forks:gamaj/allow_keeping_constant_nodes_unelided

Conversation

@JGamache-autodesk

Copy link
Copy Markdown
Contributor

Editing this node in a real time MaterialX editing software leads to constant shader recompilation because the value gets burned inside the shader text. On complex shading models, this has a noticeable perfomance impact.

Add an option to keep these as regular nodes that do not require recompiling the shader.

JGamache-autodesk and others added 2 commits August 13, 2025 14:40
Editing this node in a real time MaterialX editing software leads to
constant shader recompilation because the value gets burned inside the
shader text. On complex shading models, this has a noticeable perfomance
impact.

Add an option to keep these as regular nodes that do not require
recompiling the shader.
}
// Second, check for specific nodes types
else if (nodeDef.getNodeString() == CONSTANT)
else if (nodeDef.getNodeString() == CONSTANT && context.getOptions().elideConstantNodes)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking the option here - I think it's clearer to apply the same logic inside ShaderGraph::optimize() when the constant nodes are actually being elided here.

I know we only use the CONSTANT classification for this at the moment, but if we ever used it for something else this would need to be refactored.

@JGamache-autodesk JGamache-autodesk Aug 29, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say it was a matter of taste, but you are actually correct since non-elided ND_constant_filename nodes will become an issue in GLSL, which means we need to change the condition in ShaderGraph::optimize() from

else if (node->hasClassification(ShaderNode::Classification::DOT))

to

else if (node->hasClassification(ShaderNode::Classification::DOT) || 
         node->hasClassification(ShaderNode::Classification::CONSTANT))

Mentioning this also opens another can of worms, because that is a vital elision only when the filename is replaced by a sampler, and only if the shading language does not allow passing samplers as function parameters. But that is a discussion for another time.

So my recommendation is to wait until I have completed @ld-kerley 's request and added proper elision at least for GLSL.

@ld-kerley ld-kerley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - thanks @JGamache-autodesk

@jstone-lucasfilm jstone-lucasfilm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a great proposal to me, @JGamache-autodesk, and I had just one note about mixed code styles that should be resolved.

bypass(node, 0);
++numEdits;
bool canElide = context.getOptions().elideConstantNodes;
if (!canElide) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some mixing of code styles here, and make sure to align all of your new code to the Allman-style braces of MaterialX before we merge this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jstone-lucasfilm
jstone-lucasfilm merged commit 44932c1 into AcademySoftwareFoundation:main Oct 10, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants