DirectXShaderCompiler
DirectXShaderCompiler copied to clipboard
[SPIR-V] Error with switch statement with constant input
If I try to create a switch statement with a literal value as the input, I get an error like the following when compiling with spirv:
file.hlsl:5:7: error: non-32bit integer case value in switch statement unimplemented
case 0:
^
This link should reproduce the issue: https://shader-playground.timjones.io/6fd31f9898afb861d22de36c0f989a85
Shader code, in case that link goes stale:
float PSMain() : SV_TARGET
{
switch (0)
{
case 0:
return 1;
}
return 0;
}
(Obviously you generally would not hand-write code like that, but in our case the code is generated).
The issue can be worked-around by assigning the value to a dummy variable, or introducing an (identity) cast, e.g. switch ((int)0)
Thanks for reporting, @simontaylor81.
@sudonatalie or @jaebaek, could you take a look?