Early lobe pruning during ShaderGraph construction#2844
Open
ppenenko wants to merge 1 commit intoAcademySoftwareFoundation:mainfrom
Open
Early lobe pruning during ShaderGraph construction#2844ppenenko wants to merge 1 commit intoAcademySoftwareFoundation:mainfrom
ppenenko wants to merge 1 commit intoAcademySoftwareFoundation:mainfrom
Conversation
Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>
1f86c5d to
27d07e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR partially implements #2680 - an optional early pruning optimization to MaterialX shader generation. The implementation is heavily inspired by the OpenUSD PR PixarAnimationStudios/OpenUSD#3525
When
GenOptions::enableLobePruningis enabled, the system analyzes NodeGraph topology to identify topological ("permutation-defining") inputs (mix weights, multiply factors) that, when hardcoded to 0 or 1 at a call site, allow entire dead branches to be pruned. In contrast to #2499 and #2832 which rely on rewriting the already-constructed ShaderGraph in theoptimizecall, this PR applies pruning at an earlier stage - during ShaderGraph construction, during the NodeGraph traversal. If a sub-node is found to be prunable, the traversal skips it entirely. This allows us to save time even at the codegen stage.Key components
NodeGraphTopology(new): Statically analyzes a NodeGraph to identify topological inputs and which internal nodes each can eliminate. Results are cached per NodeGraph inGenContextviaNodeGraphTopologyCache.NodeGraphPermutation(new): Lightweight object representing a specific pruning configuration for a call site, produced byNodeGraphTopology::createPermutation().CompoundNode/ ShaderGenerator changes: Thread the permutation throughcreateShaderNodeImplForNodeGraph()→ShaderGraph::create()→createConnectedNodes(), whereshouldPrune()skips dead nodes before they are instantiated.GenOptions::enableLobePruning: Runtime flag (default off) to enable the optimization. Wired through test suite options.Measurement infrastructure
The optimization was measured with a set of companion PRs that add profiling and comparison tooling to the MaterialX test suite:
envSampleCountandframesPerMaterialtest suite optionsdiff_test_runs)MX_TRACE_ASYNCResults
Measured on the MaterialX test suite (baseline vs.
enableLobePruning=true).GPU frame time has not improved noticeably.
Shader compilation time shows clear improvement for materials with prunable lobes:
The lines of code metric also shows a clear reduction, reflecting the decreased shader complexity:

Further work
This PR performs what is effectively early dead code elimination (DCE) based on input values that are known to be hardcoded for all possible instances of the material - for example, unconnected subnode inputs assuming default values. This is the same optimization that the downstream shader compiler (e.g.
glslang+spirv-optor the video driver compiler) would eventually perform, resulting in an equally optimized final shader binary, which explains the lack of improvement in GPU frame time. However, DCE performed earlier, during MaterialX codegen is cheaper and saves the more expensive time overhead of DCE in the compiler.A natural follow-up is to proactively generate more optimal shader permutations by specializing on the topological input values encountered at run time, similar to Jerry's approach in PixarAnimationStudios/OpenUSD#3525.