DirectXShaderCompiler
DirectXShaderCompiler copied to clipboard
[SPIR-V] fatal error: generated SPIR-V is invalid: The <id> passed to OpAccessChain to index into a structure must be an OpConstant
Hi,
As instructed by the compiler, I'm creating a ticket:
Command:
dxc.exe test.hlsl -spirv -T vs_6_6 -E main -fvk-use-dx-layout -fspv-target-env=vulkan1.1 -Fo ps.out
Output:
fatal error: generated SPIR-V is invalid: The <id> passed to OpAccessChain to index into a structure must be an OpConstant.
%16 = OpLoad %uint %gl_VertexIndex
Used latest build artifact at time of writing. Git commit: 3082ec4a0fa2c4988ba7ee6e3040760850ede98c
Repro Code:
cbuffer TestPositions : register(b3)
{
float4 Vertex0;
float4 Vertex1;
float4 Vertex2;
};
struct VS_OUT
{
float4 Position : SV_Position;
};
VS_OUT main(uint vertexId : SV_VertexID)
{
const float4 positions[] = {
Vertex0,
Vertex1,
Vertex2
};
VS_OUT RetVal;
RetVal.Position = positions[vertexId];
return RetVal;
}
Got the same using
struct Rectangle
{
float2 extent;
float2 rotation; // complex
float3 center; // last is depth
float4 colour;
float2 uv_min;
float2 uv_max;
};
ConstantBuffer<Rectangle> g_rectangles[] : register(b2, space1);
float4 main(uint vertex_index : SV_VertexID, uint instance_index : SV_InstanceID)
{
return CreateRectangleVertex(vertex_index, g_rectangles[instance_index]);
}
command line options: -HV 2021 -WX -spirv -fspv-extension=SPV_EXT_descriptor_indexing -E main -I./ -T vs_6_0
error message:
1>CUSTOMBUILD : 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).
1> %51 = OpAccessChain %_ptr_Uniform_ConstantBuffer %g_rectangles %50
1>
1>note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible
1>
Hello all!
Can reproduce at 7a45cbbf8bab340d212d72c3cfe9f8c5f5837ccf on linux. Will investigate.
This issue is caused by SPIRV-Tools optimizer. Root cause found and fix found. However I need to solve another bug before being able to submit this fix.