Extended tracing instrumentation for shader codegen and rendering#2820
Open
ppenenko wants to merge 21 commits intoAcademySoftwareFoundation:mainfrom
Open
Extended tracing instrumentation for shader codegen and rendering#2820ppenenko wants to merge 21 commits intoAcademySoftwareFoundation:mainfrom
ppenenko wants to merge 21 commits intoAcademySoftwareFoundation:mainfrom
Conversation
Add configurable environment radiance sample count to test suite options, allowing game-representative performance testing (1-16 samples) vs reference quality (1024+ samples). Lower sample counts make shader complexity a larger fraction of GPU time, enabling meaningful runtime performance comparisons.
Python package (MaterialXTest.diff_test_runs) with three comparison
scripts and shared reporting utilities:
diff_images.py -- perceptual image comparison via NVIDIA FLIP,
with HTML side-by-side reports
diff_traces.py -- Perfetto trace comparison with per-material
CPU slice and GPU render time analysis,
multiple --slice filters, --warmup-frames
burn-in, inline SVG charts
diff_shaders.py -- offline shader analysis (LOC, SPIR-V size,
compile time, spirv-opt time); auto-discovers
Vulkan SDK tools in PATH
_report.py -- shared comparison tables, SVG chart generation,
and HTML report builder
Declare the new test suite options so the C++ test runner can read them from the options file. Also reset enableTracing default to false (opt-in for profiling runs).
Added MX_TRACE markers to key codegen functions for profiling: - ShaderGraph: createConnectedNodes, addUpstreamDependencies, createNode - ShaderGenerator: getImplementation, emitFunctionDefinitions, emitFunctionCalls - CompoundNode: initialize, emitFunctionDefinition, emitFunctionCall
- Add GpuTimerQuery helper class and getCurrentTimeNs() for GPU timing via GL_TIME_ELAPSED queries (guarded by MATERIALX_BUILD_TRACING) - Add multi-frame render loop using framesPerMaterial for statistical validity, emitting MX_TRACE_ASYNC events on the GPU track - Replace stale Cat:: alias with mx::Tracing::Category:: (the alias was removed in PR AcademySoftwareFoundation#2742)
Shader codegen source files (ShaderGraph.cpp, ShaderGenerator.cpp, etc.) include MaterialXTrace/Tracing.h and use MX_TRACE macros. When Perfetto tracing is enabled, MaterialXGenShader needs to link against MaterialXTrace for the trace event symbols.
The CMake flag was renamed from MATERIALX_BUILD_TRACING to MATERIALX_BUILD_PERFETTO_TRACING in PR AcademySoftwareFoundation#2742. Update all #ifdef guards in RenderGlsl.cpp to match.
Port AsyncTrack enum, Sink::asyncEvent(), and MX_TRACE_ASYNC macro from the pre-merge proto2 branch. This enables GPU timer query results to be emitted as events on a dedicated "GPU" track in Perfetto traces. Use std::numeric_limits<uint64_t>::max() for the GPU track ID to guarantee no collision with OS thread IDs.
The previous commit accidentally set enableTracing to false, which would prevent CI from producing Perfetto traces. Restore to true to match the behavior established in PR AcademySoftwareFoundation#2742.
Without matplotlib, the HTML reports are generated with no charts, making them essentially empty. Fail early with a clear install message, consistent with how perfetto and pandas are handled.
Derive display labels from the actual directory names passed on the command line, matching the convention already used by diff_traces.py. Affects console output, HTML report title, and per-image labels. Assisted-by: Claude (Anthropic) via Cursor IDE Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>
Use the shared openReport() from _report.py, matching the behavior already present in diff_traces.py and diff_shaders.py. Assisted-by: Claude (Anthropic) via Cursor IDE Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>
Use the same relative/fallback import pattern as diff_traces.py and diff_shaders.py so the script works both as a package and standalone. Assisted-by: Claude (Anthropic) via Cursor IDE Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>
Remove the diff_test_runs package to keep this PR focused on C++ tracing instrumentation only. The Python tooling will be proposed in a separate follow-up PR.
Remove framesPerMaterial and envSampleCount options to keep this PR focused on C++ tracing instrumentation. The options will be proposed in a separate follow-up PR. Also reset UiNode.h/cpp to main (unrelated Graph Editor fix that crept into the branch).
4 tasks
Move MX_TRACE_ASYNC macro, AsyncTrack enum, GpuTimerQuery, and GPU timer query usage to a follow-up PR, keeping this branch focused on CPU trace markers only.
3 tasks
ppenenko
commented
Mar 13, 2026
| <input name="outputDirectory" type="string" value="" /> | ||
|
|
||
| <!-- Enable Perfetto tracing during render tests (requires MATERIALX_BUILD_TRACING). | ||
| <!-- Enable Perfetto tracing during render tests (requires MATERIALX_BUILD_PERFETTO_TRACING). |
Contributor
Author
There was a problem hiding this comment.
This is just fixing an oversight from #2774: we renamed this setting as part of the code review.
ppenenko
commented
Mar 13, 2026
Comment on lines
+4
to
+7
| set(GENSHADER_MTLX_MODULES MaterialXFormat MaterialXCore) | ||
| if(MATERIALX_BUILD_PERFETTO_TRACING) | ||
| list(APPEND GENSHADER_MTLX_MODULES MaterialXTrace) | ||
| endif() |
Contributor
Author
There was a problem hiding this comment.
The optional dependency on tracing - zero overhead if disabled. If enabled, this wouldn't create any additional linking dependencies for MaterialX's consumers because Perfetto is compiled into MaterialXTrace.
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
Building on the Perfetto tracing from #2742, this PR adds CPU trace markers to additional codegen and rendering hot paths. This also required conditionally linking
MaterialXTracetoMaterialXGenShader, which was not needed by #2742 (tracing was only in test code) but is now required for the new codegen instrumentation.Shader codegen:
ShaderGraphtraversal (createConnectedNodes,addUpstreamDependencies,createNode),ShaderGeneratoremit functions (emitFunctionDefinitions,emitFunctionCalls,getImplementation), andCompoundNodeoperationsGLSL build:
GlslProgram::build(),DumpGeneratedCode,DumpUniformsAndAttributes,CaptureAndSaveImageMotivation
This instrumentation was developed to measure and validate shader generation optimizations (early lobe pruning, dead code elimination) in a companion branch. The infrastructure is generally useful for identifying bottlenecks in shader generation and compilation.
Test plan
MATERIALX_BUILD_PERFETTO_TRACING=ONon Windows (MSVC)MATERIALX_BUILD_PERFETTO_TRACING=OFF(no-op macros, no link dependencies)Related