Skip to content

[SPIR-V] Bitfields can cause wrong struct member access #8526

Closed

Description

@vntec

Description
Accessing data in a constant buffer via a local struct variable can cause wrong elements to be accessed if bitfield members precede them. In the example below, watch how the %uint_1 offset in the last OpAccessChain changes to %uint_0 if the second approach is used.
I noticed this while using my workaround for #8373, meaning I cannot always use a variable of ConstantBuffer<...> type directly, which would avoid this issue...

Steps to Reproduce
https://godbolt.org/z/ohd9eafGP

// -E main -T ps_6_7 -spirv -fspv-target-env=vulkan1.3 -HV 2021
struct MyData {
    uint a : 16;
    uint b : 16;
    uint c; 
}; 

uint main() : SV_Target {
    ConstantBuffer<MyData> md = ResourceDescriptorHeap[123]; // Works
    //MyData md = (ConstantBuffer<MyData>)ResourceDescriptorHeap[123]; // Word 0 instead of 1 is accessed!
    return md.c;
}

Actual Behavior
Word 0 instead of 1 of the struct is accessed, if the second approach is used.

Environment

  • DXC trunk

Activity

  1. added
    bug
    spirv
    needs-triage
    on Jun 7, 2026
  2. added a commit that references this issue on Oct 10, 2026
    6e0fab3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triagespirv

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions