Description
Attempting to compile HLSL to SPIR-V with the SPIR-V target environment set as Vulkan 1.1 and optimizations enabled (-O3) will produce invalid SPIR-V with a incorrect OpSelect instruction under certain circumstances.
The following code produces the aforementioned error:
float3 tileColor = { 0.005f, 0.005f, 0.005f };
float tileBorder = (horizontal == 0) || (vertical == 0) ? 8.0f : 0.0f;
debugRW[pixelCoord.xy].rgba = float4(tileColor.rgb * tileBorder, 0.5f);
With the specific error output in one such test case appearing as:
fatal error: generated SPIR-V is invalid: Expected vector sizes of Result Type and the condition to be equal: Select
%80 = OpSelect %v3float %79 %33 %34
This may be due to a bugged optimization around the ternary operation when assigning to 'tileBorder' followed by the multiplication of 'tileBorder' with a 3-component vector 'tileColor.rgb'. Judging by the error, the 'OpSelect' op's result type is a float3, whilst 'tileBorder' is a scalar float. The resultant type in this case should be a scalar float, or the arguments for 'OpSelect' should all be 3-component float vectors.
Steps to Reproduce
- Checkout and build DXC at SHA:
99400dc80ffa0eb6aef56fc6e482f5eff40185e4 ('main' branch)
- Run the built dxc.exe on the following provided HLSL source file in:
problemhlsl.zip
with arguments:
-T cs_6_0 -E csScreenSpaceRaytraceDebug problemhlsl.hlsl -Fo problemshader.spv -spirv -O3 -fspv-target-env=vulkan1.1
- Observe output for the aforementioned error.
Actual Behavior
Compilation to SPIR-V will fail with a SPIR-V validation failure.
The error output when running dxc.exe with the above reproduction steps is:
fatal error: generated SPIR-V is invalid: Expected vector sizes of Result Type and the condition to be equal: Select
%80 = OpSelect %v3float %79 %33 %34
Environment
- DXC version:
dxcompiler.dll: 1.10(5371-99400dc8)(1.10.2605.0) - 1.10.2605.0
- Host Operating System: Windows 11 24H2 Build 26100.7462
- Commit SHA:
99400dc80ffa0eb6aef56fc6e482f5eff40185e4
Description
Attempting to compile HLSL to SPIR-V with the SPIR-V target environment set as Vulkan 1.1 and optimizations enabled (-O3) will produce invalid SPIR-V with a incorrect OpSelect instruction under certain circumstances.
The following code produces the aforementioned error:
With the specific error output in one such test case appearing as:
This may be due to a bugged optimization around the ternary operation when assigning to 'tileBorder' followed by the multiplication of 'tileBorder' with a 3-component vector 'tileColor.rgb'. Judging by the error, the 'OpSelect' op's result type is a float3, whilst 'tileBorder' is a scalar float. The resultant type in this case should be a scalar float, or the arguments for 'OpSelect' should all be 3-component float vectors.
Steps to Reproduce
99400dc80ffa0eb6aef56fc6e482f5eff40185e4('main' branch)problemhlsl.zip
with arguments:
-T cs_6_0 -E csScreenSpaceRaytraceDebug problemhlsl.hlsl -Fo problemshader.spv -spirv -O3 -fspv-target-env=vulkan1.1Actual Behavior
Compilation to SPIR-V will fail with a SPIR-V validation failure.
The error output when running dxc.exe with the above reproduction steps is:
Environment
dxcompiler.dll: 1.10(5371-99400dc8)(1.10.2605.0) - 1.10.2605.099400dc80ffa0eb6aef56fc6e482f5eff40185e4