DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIR-V] Incorrect indexing into cbuffer involving base classes

Open bogner opened this issue 3 months ago • 0 comments

Description CBuffer/structs.test in the offload test suite is failing: https://github.com/llvm/offload-test-suite/actions/runs/19900325563/job/57042033289#step:12:205

This boils down to us indexing into a struct in a cbuffer incorrectly, and can be reduced a bit to the following:

struct X { int a1; };
struct Y : X { int2 a2; };
struct Z {
  X xs[2];
  Y y;
};

cbuffer CBStructs : register(b0) {
  Z z;
};
RWStructuredBuffer<int> Out : register(u1);

[numthreads(1,1,1)]
void main() {
 Out[0] = z.y.a1;
}

https://hlsl.godbolt.org/z/sh1q338fE

In main, the access to z.y.a1 is:

OpAccessChain %_ptr_Uniform_int %CBStructs %int_0 %int_0 %int_1 %int_0

But this is incorrect and indexes into z.xs[1] instead. For comparison, dxc 1.8.2505 gives us

OpAccessChain %_ptr_Uniform_int %CBStructs %int_0 %int_1 %uint_0 %int_0

From what I can tell, this started happening as of 025ca7b04 "[SPIRV] Handle associated counters for RWStructuredBuffer in base classes (#7880)"

bogner avatar Dec 03 '25 19:12 bogner