[HLSL] Add codegen for accessing resource members of a struct (2nd merge attempt)#193584
Merged
Conversation
For each resource or resource array member of a struct declared at global scope or inside a cbuffer, create an implicit global variable of the same resource type. The variable name will be derived from the struct instance name and the member name. The new global is associated with the struct declaration using a new attribute HLSLAssociatedResourceDeclAttr. Closes llvm#182988
Add binding attributes to global variables that were created for resources embedded in structs. The binding values are based on `register` annotations and `[[vk::binding]]` attribute on the struct instance. Depends on llvm#184281 Fixes llvm#182992
…in-structs-sema
…ithub.com/llvm/llvm-project into res-in-structs-sema-with-binding
…in-structs-codegen-member-access
Also prevent crash when accessing a resource member inside a member function. This will be implemented later.
…in-structs-codegen-member-access
…in-structs-codegen-member-access
inbelic
approved these changes
Apr 22, 2026
bob80905
approved these changes
Apr 22, 2026
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
bogner
approved these changes
Apr 22, 2026
yingopq
pushed a commit
to yingopq/llvm-project
that referenced
this pull request
Apr 29, 2026
…rge attempt) (llvm#193584) Any expression that accesses a resource or resource array member of a global struct instance must be during codegen replaced by an access of the corresponding implicit global resource variable. When codegen encounters a `MemberExpr` of a resource type, it traverses the AST to locate the parent struct declaration, building the expected global resource variable name along the way. If the parent declaration is a non-static global struct instance, codegen searches its `HLSLAssociatedResourceDeclAttr` attributes to locate the matching global resource variable and then generates IR code to access the resource global in place of the member access. Fixes llvm#182989 This is the second try to land this. The [first one](llvm#187127 with llvm#188792 and both PRs had to be reverted. No updates needed to this change. I synced with @inbelic and we agreed that this one should go in first.
KHicketts
pushed a commit
to KHicketts/llvm-project
that referenced
this pull request
Apr 30, 2026
…rge attempt) (llvm#193584) Any expression that accesses a resource or resource array member of a global struct instance must be during codegen replaced by an access of the corresponding implicit global resource variable. When codegen encounters a `MemberExpr` of a resource type, it traverses the AST to locate the parent struct declaration, building the expected global resource variable name along the way. If the parent declaration is a non-static global struct instance, codegen searches its `HLSLAssociatedResourceDeclAttr` attributes to locate the matching global resource variable and then generates IR code to access the resource global in place of the member access. Fixes llvm#182989 This is the second try to land this. The [first one](llvm#187127 with llvm#188792 and both PRs had to be reverted. No updates needed to this change. I synced with @inbelic and we agreed that this one should go in first.
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.
Any expression that accesses a resource or resource array member of a global struct instance must be during codegen replaced by an access of the corresponding implicit global resource variable.
When codegen encounters a
MemberExprof a resource type, it traverses the AST to locate the parent struct declaration, building the expected global resource variable name along the way. If the parent declaration is a non-static global struct instance, codegen searches itsHLSLAssociatedResourceDeclAttrattributes to locate the matching global resource variable and then generates IR code to access the resource global in place of the member access.Fixes #182989
This is the second try to land this. The first one collided with #188792 and both PRs had to be reverted.
No updates needed to this change. I synced with @inbelic and we agreed that this one should go in first.