diff --git a/reference/opt/shaders-hlsl/frag/for-loop-continue-control-flow.frag b/reference/opt/shaders-hlsl/frag/for-loop-continue-control-flow.frag new file mode 100644 index 00000000..f37c1fcc --- /dev/null +++ b/reference/opt/shaders-hlsl/frag/for-loop-continue-control-flow.frag @@ -0,0 +1,25 @@ +static float4 FragColor; + +struct SPIRV_Cross_Output +{ + float4 FragColor : SV_Target0; +}; + +void frag_main() +{ + FragColor = 0.0f.xxxx; + for (int _43 = 0; _43 < 3; ) + { + FragColor[_43] += float(_43); + _43++; + continue; + } +} + +SPIRV_Cross_Output main() +{ + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.FragColor = FragColor; + return stage_output; +} diff --git a/reference/opt/shaders-msl/frag/for-loop-continue-control-flow.frag b/reference/opt/shaders-msl/frag/for-loop-continue-control-flow.frag new file mode 100644 index 00000000..b4cd2085 --- /dev/null +++ b/reference/opt/shaders-msl/frag/for-loop-continue-control-flow.frag @@ -0,0 +1,23 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 FragColor [[color(0)]]; +}; + +fragment main0_out main0() +{ + main0_out out = {}; + out.FragColor = float4(0.0); + for (int _43 = 0; _43 < 3; ) + { + out.FragColor[_43] += float(_43); + _43++; + continue; + } + return out; +} + diff --git a/reference/opt/shaders/frag/for-loop-continue-control-flow.frag b/reference/opt/shaders/frag/for-loop-continue-control-flow.frag new file mode 100644 index 00000000..f49b9060 --- /dev/null +++ b/reference/opt/shaders/frag/for-loop-continue-control-flow.frag @@ -0,0 +1,15 @@ +#version 450 + +layout(location = 0) out vec4 FragColor; + +void main() +{ + FragColor = vec4(0.0); + for (int _43 = 0; _43 < 3; ) + { + FragColor[_43] += float(_43); + _43++; + continue; + } +} + diff --git a/reference/shaders-hlsl/frag/for-loop-continue-control-flow.frag b/reference/shaders-hlsl/frag/for-loop-continue-control-flow.frag new file mode 100644 index 00000000..12e1e7f5 --- /dev/null +++ b/reference/shaders-hlsl/frag/for-loop-continue-control-flow.frag @@ -0,0 +1,44 @@ +static float4 FragColor; + +struct SPIRV_Cross_Output +{ + float4 FragColor : SV_Target0; +}; + +void frag_main() +{ + FragColor = 0.0f.xxxx; + int i = 0; + int _36; + for (;;) + { + if (i < 3) + { + int a = i; + FragColor[a] += float(i); + if (false) + { + _36 = 1; + } + else + { + int _41 = i; + i = _41 + 1; + _36 = _41; + } + continue; + } + else + { + break; + } + } +} + +SPIRV_Cross_Output main() +{ + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.FragColor = FragColor; + return stage_output; +} diff --git a/reference/shaders-msl/frag/for-loop-continue-control-flow.frag b/reference/shaders-msl/frag/for-loop-continue-control-flow.frag new file mode 100644 index 00000000..847ec653 --- /dev/null +++ b/reference/shaders-msl/frag/for-loop-continue-control-flow.frag @@ -0,0 +1,42 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 FragColor [[color(0)]]; +}; + +fragment main0_out main0() +{ + main0_out out = {}; + out.FragColor = float4(0.0); + int i = 0; + int _36; + for (;;) + { + if (i < 3) + { + int a = i; + out.FragColor[a] += float(i); + if (false) + { + _36 = 1; + } + else + { + int _41 = i; + i = _41 + 1; + _36 = _41; + } + continue; + } + else + { + break; + } + } + return out; +} + diff --git a/reference/shaders/frag/for-loop-continue-control-flow.frag b/reference/shaders/frag/for-loop-continue-control-flow.frag new file mode 100644 index 00000000..638d89be --- /dev/null +++ b/reference/shaders/frag/for-loop-continue-control-flow.frag @@ -0,0 +1,34 @@ +#version 450 + +layout(location = 0) out vec4 FragColor; + +void main() +{ + FragColor = vec4(0.0); + int i = 0; + int _36; + for (;;) + { + if (i < 3) + { + int a = i; + FragColor[a] += float(i); + if (false) + { + _36 = 1; + } + else + { + int _41 = i; + i = _41 + 1; + _36 = _41; + } + continue; + } + else + { + break; + } + } +} + diff --git a/shaders-hlsl/frag/for-loop-continue-control-flow.frag b/shaders-hlsl/frag/for-loop-continue-control-flow.frag new file mode 100644 index 00000000..1f91cca2 --- /dev/null +++ b/shaders-hlsl/frag/for-loop-continue-control-flow.frag @@ -0,0 +1,11 @@ +#version 450 +layout(location = 0) out vec4 FragColor; +void main() +{ + FragColor = vec4(0.0); + for (int i = 0; i < 3; (0 > 1) ? 1 : i ++) + { + int a = i; + FragColor[a] += float(i); + } +} diff --git a/shaders-msl/frag/for-loop-continue-control-flow.frag b/shaders-msl/frag/for-loop-continue-control-flow.frag new file mode 100644 index 00000000..1f91cca2 --- /dev/null +++ b/shaders-msl/frag/for-loop-continue-control-flow.frag @@ -0,0 +1,11 @@ +#version 450 +layout(location = 0) out vec4 FragColor; +void main() +{ + FragColor = vec4(0.0); + for (int i = 0; i < 3; (0 > 1) ? 1 : i ++) + { + int a = i; + FragColor[a] += float(i); + } +} diff --git a/shaders/frag/for-loop-continue-control-flow.frag b/shaders/frag/for-loop-continue-control-flow.frag new file mode 100644 index 00000000..1f91cca2 --- /dev/null +++ b/shaders/frag/for-loop-continue-control-flow.frag @@ -0,0 +1,11 @@ +#version 450 +layout(location = 0) out vec4 FragColor; +void main() +{ + FragColor = vec4(0.0); + for (int i = 0; i < 3; (0 > 1) ? 1 : i ++) + { + int a = i; + FragColor[a] += float(i); + } +} diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index c09c87de..c207eebf 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -11250,7 +11250,10 @@ bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method } default: - SPIRV_CROSS_THROW("For/while loop detected, but need while/for loop semantics."); + block.disable_block_optimization = true; + force_recompile(); + begin_scope(); // We'll see an end_scope() later. + return false; } begin_scope(); @@ -11324,7 +11327,10 @@ bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method } default: - SPIRV_CROSS_THROW("For/while loop detected, but need while/for loop semantics."); + block.disable_block_optimization = true; + force_recompile(); + begin_scope(); // We'll see an end_scope() later. + return false; } begin_scope();