DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIR-V] OpAccessChain result type (OpTypeStruct) does not match the type that results from indexing into the base <id> (OpTypeStruct)

Open Narvin-Chana opened this issue 4 months ago • 1 comments

Description When compiling my shader I get an error, the error originates from a struct I pass in as a constant buffer: The uniform struct:

struct View
{
    row_major matrix view;
    row_major matrix projection;
    row_major matrix viewProjection;
    row_major matrix invView;
    row_major matrix invProjection;
    row_major matrix invViewProjection;
    float3 cameraPosition;
    float time;
    uint2 screenSize;
    uint punctualLightsCount; // Number of punctual lights
    uint padding;
    DirectionalLight dirLight;
};

With:

struct DirectionalLight
{
    float3 color;
    float intensity;
    float3 direction;
};

I've tried with various spv options but have had no real success. The same shader code works when compiling to DXIL.

Steps to Reproduce Compile out.txt with this command line: dxc -spirv -T cs_6_8 -E DeferredShadingCS out.txt

Actual Behavior

Error: fatal error: generated SPIR-V is invalid: OpAccessChain result type (OpTypeStruct) does not match the type that results from indexing into the base <id> (OpTypeStruct).
  %169 = OpAccessChain %_ptr_Uniform_DirectionalLight_0 %160 %uint_11

note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Environment

  • DXC version: dxcompiler.dll: 1.9 - 1.8.0.4973 (8f5595872)
  • Host Operating System:
Edition	Windows 11 Pro
Version	24H2
Installed on	‎2025-‎03-‎18
OS build	26100.6899
Experience	Windows Feature Experience Pack 1000.26100.253.0

out.txt

Narvin-Chana avatar Oct 28 '25 17:10 Narvin-Chana

Short repro for this issue:

// RUN: %dxc %s -T cs_6_8 -spirv -fspv-target-env=vulkan1.3 -E main

struct B
{
    float c;
};

struct A
{
    B b;
};

float EvaluateLighting(A a)
{
    return a.b.c;
}

static RWStructuredBuffer<float> output;

[numthreads(1, 1, 1)]
void main()
{
    ConstantBuffer<A> cb = ResourceDescriptorHeap[1];
    output[0] = 1.5f * EvaluateLighting(cb);
}

The struct B is duplicated B_0 and B, something is wrong in the SpirvContext or parent code

Keenuts avatar Oct 31 '25 14:10 Keenuts