-
Notifications
You must be signed in to change notification settings - Fork 664
Segfault in CopyPropagateArrays #2869
Copy link
Copy link
Closed
Description
HLSL shader originally posted in microsoft/DirectXShaderCompiler#2423. May be related to legalization.
struct MyConstantBuffer {
float4 myParam1[8];
};
cbuffer myCBuffer : register(b0) {
MyConstantBuffer myConstantBuffer;
}
struct MyConstantBufferWrapper {
MyConstantBuffer constants;
float4 GetParam1(uint index) { return constants.myParam1[index]; }
};
MyConstantBufferWrapper CreateWrapper() {
MyConstantBufferWrapper wrapper;
wrapper.constants = myConstantBuffer;
return wrapper;
};
struct VS_OUTPUT {
float4 m_ScreenPos : VS_OUT_POSITION;
};
struct MyStruct {
uint myIndex;
};
static MyConstantBufferWrapper myWrapper = CreateWrapper();
float4 main(VS_OUTPUT In) : SV_Target {
MyStruct myStruct = (MyStruct)0;
// Causes the issue:
float4 myParam = myWrapper.GetParam1(myStruct.myIndex);
// Works fine:
//float4 myParam = myConstantBuffer.myParam1[myStruct.myIndex];
return myParam;
}
What I see is that AsIntConstant() returns nullptr:
SPIRV-Tools/source/opt/copy_prop_arrays.cpp
Line 516 in 9325619
| access_chain.push_back(index_const->AsIntConstant()->GetU32()); |
The attached test.spv.txt is the result of -spirv -fcgl -O0 from DXC.
test.spv.txt
If I run spirv-opt.exe test.spv.txt -o test.optimized.spv, however, I get the following error rather than the segfault (not sure why):
error: line 101: OpFunctionCall Argument <id> '21[%myWrapper]'s type does not match Function <id> '52[%_ptr_Function_MyConstantBufferWrapper]'s parameter type.
%47 = OpFunctionCall %v4float %MyConstantBufferWrapper_GetParam1 %myWrapper %param_var_index
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels