[clang] [HLSL] Add globals for resources embedded in structs (PR #184281)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 10 18:03:00 PDT 2026
================
@@ -0,0 +1,167 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -ast-dump %s | FileCheck %s
+
+// Single resource field in struct
+
+// CHECK: CXXRecordDecl {{.*}} struct A
+// CHECK: FieldDecl {{.*}} Buf 'RWBuffer<float>':'hlsl::RWBuffer<float>'
+struct A {
+ RWBuffer<float> Buf;
+};
+
+// CHECK: VarDecl {{.*}} implicit a1.Buf 'hlsl::RWBuffer<float>' callinit
+// CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
+
+// CHECK: VarDecl {{.*}} a1 'hlsl_constant A'
+// CHECK: HLSLResourceBindingAttr {{.*}} "u0" "space0"
+// CHECK-NEXT: HLSLAssociatedResourceDeclAttr {{.*}} 'a1.Buf' 'hlsl::RWBuffer<float>'
+A a1 : register(u0);
+
+// Resource array in struct
+
+// CHECK: CXXRecordDecl {{.*}} struct B
+// CHECK: FieldDecl {{.*}} Bufs 'RWBuffer<float>[10]'
+struct B {
+ RWBuffer<float> Bufs[10];
+};
+
+// CHECK: VarDecl {{.*}} implicit b1.Bufs 'hlsl::RWBuffer<float>[10]'
+// CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
+
+// CHECK: VarDecl {{.*}} b1 'hlsl_constant B'
+// CHECK: HLSLResourceBindingAttr {{.*}} "u2" "space0"
+// CHECK-NEXT: HLSLAssociatedResourceDeclAttr {{.*}} 'b1.Bufs' 'hlsl::RWBuffer<float>[10]'
+B b1 : register(u2);
+
+// Inheritance
+
+// CHECK: CXXRecordDecl {{.*}} struct C
+// CHECK: FieldDecl {{.*}} Buf2 'RWBuffer<float>':'hlsl::RWBuffer<float>'
+struct C : A {
+ RWBuffer<float> Buf2;
+};
+
+// CHECK: VarDecl {{.*}} implicit c1.A::Buf 'hlsl::RWBuffer<float>' callinit
+// CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
+
+// CHECK: VarDecl {{.*}} implicit c1.Buf2 'hlsl::RWBuffer<float>' callinit
+// CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
+
+// CHECK: VarDecl {{.*}} c1 'hlsl_constant C'
+// CHECK: HLSLResourceBindingAttr {{.*}} "u3" "space0"
+// CHECK: HLSLAssociatedResourceDeclAttr {{.*}} 'c1.A::Buf' 'hlsl::RWBuffer<float>'
+// CHECK: HLSLAssociatedResourceDeclAttr {{.*}} 'c1.Buf2' 'hlsl::RWBuffer<float>'
+C c1 : register(u3);
+
+// Inheritance with same named field
+// CHECK: CXXRecordDecl {{.*}} struct D
+// CHECK: FieldDecl {{.*}} A 'A'
+struct D : A {
+ A A;
+};
+
+// CHECK: VarDecl {{.*}} implicit d1.A::Buf 'hlsl::RWBuffer<float>' callinit
+// CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
+
+// CHECK: VarDecl {{.*}} implicit d1.A.Buf 'hlsl::RWBuffer<float>' callinit
+// CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
+
+// CHECK: VarDecl {{.*}} d1 'hlsl_constant D'
+// CHECK: HLSLAssociatedResourceDeclAttr {{.*}} 'd1.A::Buf' 'hlsl::RWBuffer<float>'
+// CHECK: HLSLAssociatedResourceDeclAttr {{.*}} 'd1.A.Buf' 'hlsl::RWBuffer<float>'
----------------
hekota wrote:
No, these attributes are different. One points to `d1.A::Buf`, which is the `Buf` resource that comes from the base class `A`, and the other `d1.A.Buf` points to the `Buf` that comes from the `A` member of the `D` struct.
https://github.com/llvm/llvm-project/pull/184281
More information about the cfe-commits
mailing list