From 0173308bb0950f2ce0b290fe68aa08efc082342f Mon Sep 17 00:00:00 2001 From: Pavlo Penenko Date: Tue, 16 Jun 2026 12:10:39 -0400 Subject: [PATCH 1/3] Fix MDL codegen: assign inline sourcecode to output variable CustomCodeNodeMdl::emitFunctionDefinition was emitting the inline sourcecode attribute as a bare expression statement in the generated MDL function body. This produced invalid MDL: the expression was discarded and the output variable retained its default value, causing mdlc errors C100 (syntax), C181 (unused variable), and C201 (function must return a value). For single-output nodes, assign the expression to the output variable so the generated function correctly returns the sourcecode value. --- source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp index edda7368e5..f7bae1240a 100644 --- a/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp +++ b/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp @@ -248,7 +248,14 @@ void CustomCodeNodeMdl::emitFunctionDefinition(const ShaderNode& node, GenContex // User defined code shadergen.emitComment("inlined shader source code:", stage); - shadergen.emitLine(_inlineSourceCode, stage, false); + if (numOutputs == 1) + { + shadergen.emitLine(outputs.back().name + " = " + _inlineSourceCode, stage); + } + else + { + shadergen.emitLine(_inlineSourceCode, stage, false); + } // Output packing shadergen.emitComment("pack (in case of multiple outputs) and return outputs:", stage); From 0a5c7ebd68571b40de400a178cfd647158d4c41b Mon Sep 17 00:00:00 2001 From: Pavlo Penenko Date: Tue, 16 Jun 2026 14:09:44 -0400 Subject: [PATCH 2/3] Sanitize inline function names for namespaced nodedefs in MDL codegen When a nodedef uses a MaterialX namespace (e.g. namespace="adsk"), getName() returns the qualified name with a colon separator (adsk:ND_backface_util) after library import. The colon is not a valid MDL identifier character, causing mdlc error C100. Apply makeValidName() to replace invalid characters with underscores, consistent with how all other MaterialX codegen paths sanitize names. --- source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp index f7bae1240a..882186c527 100644 --- a/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp +++ b/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp @@ -72,10 +72,11 @@ void CustomCodeNodeMdl::initializeForInlineSourceCode(const InterfaceElement& el NodeDefPtr nodeDef = impl.getNodeDef(); _inlineFunctionName = nodeDef->getName(); - _hash = std::hash{}(_inlineFunctionName); // make sure we emit the function definition only once const ShaderGenerator& shadergen = context.getShaderGenerator(); const MdlSyntax& syntax = static_cast(shadergen.getSyntax()); + syntax.makeValidName(_inlineFunctionName); + _hash = std::hash{}(_inlineFunctionName); // make sure we emit the function definition only once // Construct the function call template string initializeFunctionCallTemplateString(syntax, *nodeDef); // Collect information about output names and defaults From e4df8cb1309261a0e2f49975507070d2488a1957 Mon Sep 17 00:00:00 2001 From: Pavlo Penenko Date: Tue, 16 Jun 2026 14:26:13 -0400 Subject: [PATCH 3/3] Suppress mdlc C181 (unused variable) warning in MDL generate test The MDL codegen emits geometry property and image output variables that may be unreferenced in the generated shader. This is a known limitation of the codegen's dead variable elimination, consistent with the existing suppressions for C183 (unused parameter) and C350 (unused let temporary). --- source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp b/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp index 2353703e7a..fadfdf84b4 100644 --- a/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp +++ b/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp @@ -242,6 +242,9 @@ void MdlShaderGeneratorTester::compileSource(const std::vector& so // avoid warning "C350: unused let temporary '...'" mdlcCommand += " -W \"350=off\""; + // avoid warning "C181: unused variable '...'" + mdlcCommand += " -W \"181=off\""; + // but treat all other warnings as errors mdlcCommand += " -W err";