Skip to content

Fix MDL codegen for inline sourcecode implementations#2988

Open
ppenenko wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
autodesk-forks:ppenenko/fix-mdl-inline-sourcecode
Open

Fix MDL codegen for inline sourcecode implementations#2988
ppenenko wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
autodesk-forks:ppenenko/fix-mdl-inline-sourcecode

Conversation

@ppenenko

Copy link
Copy Markdown
Contributor

Summary

Fix three issues in the MDL shader generator that cause mdlc compilation failures when processing Implementation elements with bare inline sourcecode attributes (no {{ markers, no file+function):

  1. Dangling expression bugCustomCodeNodeMdl::emitFunctionDefinition emitted the inline sourcecode as a bare expression statement, which MDL discards. For single-output nodes, the expression is now assigned to the output variable.

  2. Namespace in function names — When a NodeDef uses a MaterialX namespace (e.g. namespace="adsk"), getName() returns adsk:ND_foo, and the colon is not a valid MDL identifier character. Apply makeValidName() to sanitize, consistent with other codegen paths.

  3. Unused variable warning suppression — Add -W "181=off" to the mdlc test command, consistent with existing suppressions for C183 and C350. The MDL codegen may emit geometry property and image output variables that are unreferenced in the generated shader.

Context

These bugs are latent defects in untested code. CustomCodeNodeMdl is instantiated when an implementation has a sourcecode attribute with no {{ markers. Every upstream MDL sourcecode implementation either uses {{ markers (routed to SourceCodeNodeMdl) or has file+function attributes (early return in CustomCodeNodeMdl). The bare-expression path was never exercised until downstream libraries introduced simple placeholder implementations like sourcecode="0.5".

Test plan

  • Verified locally that MDL generation produces correct mxp_out = <expression>; assignment
  • Verified mdlc compilation passes for all affected nodedefs
  • CI should pass the existing MDL generate and compile tests

ppenenko added 3 commits June 23, 2026 15:35
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.
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.
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).
@ppenenko

Copy link
Copy Markdown
Contributor Author

Found while investigating autodesk-forks#1488

@ppenenko

Copy link
Copy Markdown
Contributor Author

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.

1 participant