Skip to content

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

@bogner

Description

@bogner

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 025ca7b "[SPIRV] Handle associated counters for RWStructuredBuffer in base classes (#7880)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug, regression, crashneeds-triageAwaiting triagespirvWork related to SPIR-V

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions