Skip to content

[HLSL] Add codegen for accessing resource members of a struct (2nd merge attempt)#193584

Merged
hekota merged 17 commits into
llvm:mainfrom
hekota:res-in-structs-codegen-member-access
Apr 23, 2026
Merged

[HLSL] Add codegen for accessing resource members of a struct (2nd merge attempt)#193584
hekota merged 17 commits into
llvm:mainfrom
hekota:res-in-structs-codegen-member-access

Conversation

@hekota

@hekota hekota commented Apr 22, 2026

Copy link
Copy Markdown
Member

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 #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.

hekota added 16 commits March 2, 2026 18:07
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
Also prevent crash when accessing a resource member inside a member function. This will be implemented later.
@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 115765 tests passed
  • 4655 tests skipped

✅ The build succeeded and all tests passed.

@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 55327 tests passed
  • 2464 tests skipped

✅ The build succeeded and all tests passed.

@hekota hekota merged commit 87a8d40 into llvm:main Apr 23, 2026
10 of 11 checks passed
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.
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.

[HLSL] Codegen for accessing resource members of a struct

4 participants