From 577a3f5e0b86f216389eef7d0d9e0fcd439e0819 Mon Sep 17 00:00:00 2001 From: Joachim Reichel <43646584+jreichel-nvidia@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:37:15 +0100 Subject: [PATCH 1/2] Fix missing closing scope in MDL compound output functions. Mixed-output compound graphs emit separate functions for material and non-material outputs. Close the function body after returning a non-material output. --- .../pbrlib/multioutput/mixedoutput.mtlx | 29 +++++++++++++++++++ .../Nodes/ClosureCompoundNodeMdl.cpp | 1 + 2 files changed, 30 insertions(+) create mode 100644 resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput.mtlx diff --git a/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput.mtlx b/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput.mtlx new file mode 100644 index 0000000000..07909137e4 --- /dev/null +++ b/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput.mtlx @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp index 822fd5406a..9a65e6c3bf 100644 --- a/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp +++ b/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp @@ -101,6 +101,7 @@ void ClosureCompoundNodeMdl::emitFunctionDefinition(const ShaderNode& node, GenC { const string result = shadergen.getUpstreamResult(outputSocket, context); shadergen.emitLine("return " + result, stage); + shadergen.emitScopeEnd(stage); } shadergen.emitLineBreak(stage); From c10fa801aa95df18f2d094669e716b7847f172c1 Mon Sep 17 00:00:00 2001 From: Joachim Reichel <43646584+jreichel-nvidia@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:25:14 +0100 Subject: [PATCH 2/2] Fix MDL compound implementation selection for mixed output types. Check all nodegraph outputs for closure types instead of only the first. Add a scalar-first mixed-output test alongside the existing shader-first test. --- .../pbrlib/multioutput/mixedoutput2.mtlx | 30 +++++++++++++++++++ source/MaterialXGenMdl/MdlShaderGenerator.cpp | 10 +++---- 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput2.mtlx diff --git a/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput2.mtlx b/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput2.mtlx new file mode 100644 index 0000000000..c57d502dfd --- /dev/null +++ b/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput2.mtlx @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/MaterialXGenMdl/MdlShaderGenerator.cpp b/source/MaterialXGenMdl/MdlShaderGenerator.cpp index d0987aea35..36a6430d14 100644 --- a/source/MaterialXGenMdl/MdlShaderGenerator.cpp +++ b/source/MaterialXGenMdl/MdlShaderGenerator.cpp @@ -379,13 +379,11 @@ ShaderNodeImplPtr MdlShaderGenerator::createShaderNodeImplForNodeGraph(const Nod throw ExceptionShaderGenError("NodeGraph '" + nodegraph.getName() + "' has no outputs defined"); } - const TypeDesc outputType = _typeSystem->getType(outputs[0]->getType()); - - ShaderNodeImplPtr impl; - // Use a compound implementation. - if (outputType.isClosure()) + // Any closure output requires the emitter that handles mixed output types. + for (OutputPtr output : outputs) { - return ClosureCompoundNodeMdl::create(); + if (_typeSystem->getType(output->getType()).isClosure()) + return ClosureCompoundNodeMdl::create(); } return CompoundNodeMdl::create(); }