DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIR-V] Internal compiler error with bit-field

Open MaxwellGengYF opened this issue 2 months ago • 1 comments

With this simple HLSL code:

struct Test {
    bool a: 1;
    int b;
};
RWStructuredBuffer<Test> buffer;

[numthreads(1, 1, 1)]
void main(){
    Test t;
    t.a = true;
    t.b = 1;
    buffer[0] = t;
}

While compiling with command dxc.exe -T cs_6_5 -spirv test_ice.hlsl, we have error Internal compiler error: access violation. Attempted to read from address 0x0000000000000030, remove -spirv by compiling to dxil is ok.

MaxwellGengYF avatar Sep 27 '25 04:09 MaxwellGengYF

This is complicated to fix because it touches an a pervasive design issue in DXC. We prepresent the hlsl bool type with OpTypeBool when the bool is not externally visible. In SPIR-V this is an abstract type, so we cannot using it as a container for a bitfield. They need to get converted to int, but this creates many special cases in the code.

Any solution to this have to be carefully tested, and could be error prone.

For now, I will get DXC to issue an error when a bool is used in a bit field. A workaround is to use int for the bitfied.

s-perron avatar Oct 14 '25 16:10 s-perron