Repository navigation
HLSL: avoid name collisions for flattened varying array elements - #17
Merged
bkaradzic-microsoft merged 1 commit intoOct 13, 2026
Conversation
Name flattened narrow varying array elements name__i instead of name_i. SPIRV-Cross sanitizes source identifiers so they never contain "__", so the generated members cannot collide with a user varying such as pairs_0. Extend the fixture with a colliding pairs_0 varying. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
bghgary
approved these changes
Oct 13, 2026
| // cannot collide with a user varying such as `name_0`. | ||
| string CompilerHLSL::flattened_varying_element_name(const string &name, uint32_t index) | ||
| { | ||
| return join(name, "__", index); |
There was a problem hiding this comment.
Please also avoid collisions with generated interface-block member names. out B { vec2 x[2]; } first; plus out B_x { vec2 _0; } second; emits two B_x__0 members with this change, and FXC rejects the shader. Both identifiers are valid after sanitization; the double underscore in the second name comes from joining the block and member names.
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.
#16 flattens narrow inter-stage varying arrays into
name_imembers, which collides with a user varying of the same name (e.g.vec2 bridge[2]plusvec2 bridge_0produced twobridge_0members). Raised in review of BabylonJS/BabylonNative#1926.Flattened elements are now named
name__i. SPIRV-Cross sanitizes source identifiers so they never contain__(ParsedIR::is_valid_identifier/sanitize_underscores), so the generated names cannot collide.Testing: the
spirv-cross-hlsl-narrow-varying-testfixture adds apairs_0varying next topairs[3]; the generated vertex and pixel shaders compile with fxc (vs_5_0/ps_5_0).