DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIR-V] Error with switch statement with constant input

Open simontaylor81 opened this issue 3 years ago • 1 comments

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)

simontaylor81 avatar Mar 18 '22 15:03 simontaylor81

Thanks for reporting, @simontaylor81.

@sudonatalie or @jaebaek, could you take a look?

kuhar avatar Mar 18 '22 18:03 kuhar