SPIRV-Cross/reference/shaders-msl/frag/switch-unreachable-break.frag
Hans-Kristian Arntzen d08ce828f4 Promote Unreachable cases into break to avoid fallthrough.
HLSL is very fussy about fallthrough in switch blocks, so promote
Unreachable blocks to breaks if they are inside a switch construct.

Some false positives are possible in weird multi-break scenarios, but
this is benign.
2022-05-18 18:36:32 +02:00

44 lines
690 B
GLSL

#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct UBO
{
int cond;
int cond2;
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(constant UBO& _15 [[buffer(0)]])
{
main0_out out = {};
out.FragColor = float4(10.0);
switch (_15.cond)
{
case 1:
{
if (_15.cond2 < 50)
{
break;
}
else
{
discard_fragment();
}
break; // unreachable workaround
}
default:
{
out.FragColor = float4(20.0);
break;
}
}
return out;
}