[clang] [HLSL] Diagnose dynamic indexing of struct arrays for resource access (PR #187132)
Joshua Batista via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 3 10:29:12 PDT 2026
================
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -finclude-default-header -verify %s
+
+struct A {
+ RWBuffer<float> Buf;
+ RWBuffer<float> ManyBufs[5];
+};
+
+A array[10] : register(u10);
+
+[numthreads(4,1,1)]
+void main(uint GI : SV_GroupThreadID) {
+
+ // expected-error at +1 {{index for struct array inside cbuffer that contains resources must be a literal expression}}
+ array[GI].Buf[0] = 1.0f;
+
+ array[2].Buf[GI] = 2.0f; // ok
+
+ // expected-error at +1 {{index for struct array inside cbuffer that contains resources must be a literal expression}}
+ array[GI].ManyBufs[3][0] = 3.0f;
+
+ array[1].ManyBufs[GI][0] = 4.0f; // ok
----------------
bob80905 wrote:
I disagree, if you look at the godbolt link, DXC emits an error when GI is used as an index (since its value depends on the lane that is running, and isnt knowable at compile time), while x is a variable, but is known at compile time.
This is why DXC disallows the former but allows the latter. I don't think the GI case covers the x case.
https://github.com/llvm/llvm-project/pull/187132
More information about the cfe-commits
mailing list