Skip to content

[SPIR-V] Static const declarations inside cbuffer can corrupt member indices and generate invalid OpAccessChain. #8537

Description

@fall2019

Description

Static const declarations inside cbuffer can corrupt member indices and generate invalid OpAccessChain.

Steps to Reproduce

cbuffer MetadataCB
{
    uint m0; static const int c0 = 0;
    uint m1; static const int c1 = 0;
    uint m2; static const int c2 = 0;
    uint m3; static const int c3 = 0;
    uint m4; static const int c4 = 0;
    uint m5; static const int c5 = 0;
    uint m6; static const int c6 = 0;
    uint m7; static const int c7 = 0;
    uint m8; static const int c8 = 0;
    uint m9; static const int c9 = 0;
}

float4 main() : SV_Target
{
    return float4(asfloat(m9), 0, 0, 0);
}

https://godbolt.org/z/MsPTcsb5d

Actual Behavior

The compile fails during SPIR-V validation:
fatal error: generated SPIR-V is invalid: Index '6[%int_18]' is out of bounds: OpAccessChain cannot find index 18 into the structure '3[%type_MetadataCB]'. This structure has 10 members. Largest valid index is 9.
%17 = OpAccessChain %_ptr_Uniform_uint %MetadataCB %int_18

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