Skip to content

[SPIR-V] Passing a constant buffer as an argument and then loading from it into a local variable and then accessing nested fields causes ICE. #7954

@zopsicle

Description

@zopsicle

Description

Pass a constant buffer as an argument to a function.
In the function, load from the constant buffer into a local variable.
Then, access a field of a field of the loaded value.
The compiler crashes with:

fatal error: generated SPIR-V is invalid: Result type (OpTypeStruct) does not match the type that results from indexing into the composite (OpTypeStruct).
  %18 = OpCompositeExtract %A_0 %17 0

Bug does not happen if the constant buffer is loaded from into a local variable inside the entry point (inline e into j in the below example).
Bug does not happen if the nested field is accessed directly from the constant buffer (f.d.b instead of h.d.b in the below example).
Bug does not happen if structs aren't nested (inline A into C in the below example).

Steps to Reproduce

struct A
{
    float3 b;
};

struct C
{
    A d;
};

void e(ConstantBuffer<C> f, out float4 g)
{
    C h = f;
    g = float4(h.d.b, 1.);
}

ConstantBuffer<C> i;

void j(out float4 k : SV_Position)
{
    e(i, k);
}
dxc -T vs_6_8 -E j -spirv example.hlsl

https://godbolt.org/z/fjrbY98hT

Actual Behavior

Environment

  • DXC version 1.8.2502
  • Host Operating System Linux 6.12.51, NixOS 25.05

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