microsoft / microsoft/DirectXShaderCompiler
[SPIR-V] GetAttributeAtVertex generates invalid SPIR-V with `-O0` and a shared type between nointerpolation and normal.
Open
Nobody has claimed this yet.
bug
spirv
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Repro:
struct S {
float a;
float b;
};
float4 main(nointerpolation S s1 : A, S s2 : B) : SV_Target
{
return float4(GetAttributeAtVertex(s1.a, 1) + s2.a, 0, 0, 0);
}
./build/bin/dxc -E main -T ps_6_1 ./test.hlsl -spirv -O0
Error:
fatal error: generated SPIR-V is invalid: Expected Constituent type to be equal to the corresponding member type of Result Type struct
%32 = OpCompositeConstruct %S %30 %31
note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible
The reason is -O0 doesn't force inlining, hence the bug shows up.
The bug is around the definition of the struct S:
%S = OpTypeStruct %_arr_float_uint_3 %_arr_float_uint_3
Because the first param is markednointerpolation, the struct becomes an array of structs.
Then, in the wrapper function that creates the struct to pass them to main, the same type is used twice: once to create the array of structs (good), and once to create a simple struct (bad)
%27 = OpLoad %_arr_float_uint_3 %in_var_A
%28 = OpLoad %_arr_float_uint_3 %in_var_A1
%29 = OpCompositeConstruct %S %27 %28
OpStore %param_var_s1 %29
%30 = OpLoad %float %in_var_B
%31 = OpLoad %float %in_var_B1
%32 = OpCompositeConstruct %S %30 %31
OpStore %param_var_s2 %32
%33 = OpFunctionCall %v4float %src_main %param_var_s1 %param_var_s2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with build/bin/dxc using the provided test.hlsl source and -spirv -O0. Inspect the SPIR-V wrapper generation around the %S struct and the OpCompositeConstruct instructions; done means the command no longer produces invalid SPIR-V for the repro.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100