Fix MDL codegen for inline sourcecode implementations#2988
Open
ppenenko wants to merge 3 commits into
Open
Conversation
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).
Contributor
Author
|
Found while investigating autodesk-forks#1488 |
Contributor
Author
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
Fix three issues in the MDL shader generator that cause
mdlccompilation failures when processingImplementationelements with bare inlinesourcecodeattributes (no{{markers, nofile+function):Dangling expression bug —
CustomCodeNodeMdl::emitFunctionDefinitionemitted the inline sourcecode as a bare expression statement, which MDL discards. For single-output nodes, the expression is now assigned to the output variable.Namespace in function names — When a
NodeDefuses a MaterialX namespace (e.g.namespace="adsk"),getName()returnsadsk:ND_foo, and the colon is not a valid MDL identifier character. ApplymakeValidName()to sanitize, consistent with other codegen paths.Unused variable warning suppression — Add
-W "181=off"to themdlctest 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.
CustomCodeNodeMdlis instantiated when an implementation has asourcecodeattribute with no{{markers. Every upstream MDL sourcecode implementation either uses{{markers (routed toSourceCodeNodeMdl) or hasfile+functionattributes (early return inCustomCodeNodeMdl). The bare-expression path was never exercised until downstream libraries introduced simple placeholder implementations likesourcecode="0.5".Test plan
mxp_out = <expression>;assignmentmdlccompilation passes for all affected nodedefs