From 70f17142de907bc03ab0b7ddfa7522eb7e237481 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 30 Jun 2020 12:02:24 +0200 Subject: [PATCH] GLSL: Fix nested legacy switch workarounds. --- .../legacy/fragment/switch.legacy.frag | 4 +- .../legacy/vert/switch-nested.legacy.vert | 43 +++++++++++++++++++ ...gle-case-multiple-exit-cfg.legacy.asm.frag | 2 +- .../legacy/fragment/switch.legacy.frag | 4 +- .../legacy/vert/switch-nested.legacy.vert | 41 ++++++++++++++++++ shaders/legacy/vert/switch-nested.legacy.vert | 28 ++++++++++++ spirv_glsl.cpp | 6 ++- 7 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 reference/opt/shaders/legacy/vert/switch-nested.legacy.vert create mode 100644 reference/shaders/legacy/vert/switch-nested.legacy.vert create mode 100644 shaders/legacy/vert/switch-nested.legacy.vert diff --git a/reference/opt/shaders/legacy/fragment/switch.legacy.frag b/reference/opt/shaders/legacy/fragment/switch.legacy.frag index 21a4d673..1920958d 100644 --- a/reference/opt/shaders/legacy/fragment/switch.legacy.frag +++ b/reference/opt/shaders/legacy/fragment/switch.legacy.frag @@ -10,7 +10,7 @@ void main() highp vec4 _65; highp vec4 _66; highp vec4 _68; - for (int SPIRV_Cross_Dummy = 0; SPIRV_Cross_Dummy < 1; SPIRV_Cross_Dummy++) + for (int SPIRV_Cross_Dummy25 = 0; SPIRV_Cross_Dummy25 < 1; SPIRV_Cross_Dummy25++) { if (_13 == 2) { @@ -59,7 +59,7 @@ void main() } } highp vec4 _70; - for (int SPIRV_Cross_Dummy = 0; SPIRV_Cross_Dummy < 1; SPIRV_Cross_Dummy++) + for (int SPIRV_Cross_Dummy146 = 0; SPIRV_Cross_Dummy146 < 1; SPIRV_Cross_Dummy146++) { if ((_13 == 10) || (_13 == 20)) { diff --git a/reference/opt/shaders/legacy/vert/switch-nested.legacy.vert b/reference/opt/shaders/legacy/vert/switch-nested.legacy.vert new file mode 100644 index 00000000..fb8d46ec --- /dev/null +++ b/reference/opt/shaders/legacy/vert/switch-nested.legacy.vert @@ -0,0 +1,43 @@ +#version 100 + +struct UBO +{ + int func_arg; + int inner_func_arg; +}; + +uniform UBO _34; + +void main() +{ + vec4 _102; + for (int SPIRV_Cross_Dummy30 = 0; SPIRV_Cross_Dummy30 < 1; SPIRV_Cross_Dummy30++) + { + if (_34.func_arg != 0) + { + vec4 _101; + for (int SPIRV_Cross_Dummy45 = 0; SPIRV_Cross_Dummy45 < 1; SPIRV_Cross_Dummy45++) + { + if (_34.inner_func_arg != 0) + { + _101 = vec4(1.0); + break; + } + else + { + _101 = vec4(0.0); + break; + } + } + _102 = _101; + break; + } + else + { + _102 = vec4(0.0); + break; + } + } + gl_Position = _102; +} + diff --git a/reference/shaders-no-opt/legacy/frag/switch-single-case-multiple-exit-cfg.legacy.asm.frag b/reference/shaders-no-opt/legacy/frag/switch-single-case-multiple-exit-cfg.legacy.asm.frag index d36e7827..cc5cb716 100644 --- a/reference/shaders-no-opt/legacy/frag/switch-single-case-multiple-exit-cfg.legacy.asm.frag +++ b/reference/shaders-no-opt/legacy/frag/switch-single-case-multiple-exit-cfg.legacy.asm.frag @@ -7,7 +7,7 @@ vec2 _19; void main() { highp vec2 _30; - for (int SPIRV_Cross_Dummy = 0; SPIRV_Cross_Dummy < 1; SPIRV_Cross_Dummy++) + for (int SPIRV_Cross_Dummy15 = 0; SPIRV_Cross_Dummy15 < 1; SPIRV_Cross_Dummy15++) { if (gl_FragCoord.x != gl_FragCoord.x) { diff --git a/reference/shaders/legacy/fragment/switch.legacy.frag b/reference/shaders/legacy/fragment/switch.legacy.frag index 9960ce7e..a70168e6 100644 --- a/reference/shaders/legacy/fragment/switch.legacy.frag +++ b/reference/shaders/legacy/fragment/switch.legacy.frag @@ -8,7 +8,7 @@ void main() { int vIndex = int(vIndexF); highp vec4 v = vec4(0.0); - for (int SPIRV_Cross_Dummy = 0; SPIRV_Cross_Dummy < 1; SPIRV_Cross_Dummy++) + for (int SPIRV_Cross_Dummy21 = 0; SPIRV_Cross_Dummy21 < 1; SPIRV_Cross_Dummy21++) { if (vIndex == 2) { @@ -65,7 +65,7 @@ void main() } } highp vec4 w = vec4(20.0); - for (int SPIRV_Cross_Dummy = 0; SPIRV_Cross_Dummy < 1; SPIRV_Cross_Dummy++) + for (int SPIRV_Cross_Dummy165 = 0; SPIRV_Cross_Dummy165 < 1; SPIRV_Cross_Dummy165++) { if ((vIndex == 10) || (vIndex == 20)) { diff --git a/reference/shaders/legacy/vert/switch-nested.legacy.vert b/reference/shaders/legacy/vert/switch-nested.legacy.vert new file mode 100644 index 00000000..3ec027b4 --- /dev/null +++ b/reference/shaders/legacy/vert/switch-nested.legacy.vert @@ -0,0 +1,41 @@ +#version 100 + +struct UBO +{ + int func_arg; + int inner_func_arg; +}; + +uniform UBO _34; + +vec4 test_inner_func(bool b) +{ + if (b) + { + return vec4(1.0); + } + else + { + return vec4(0.0); + } +} + +vec4 test_func(bool b) +{ + if (b) + { + bool param = _34.inner_func_arg != 0; + return test_inner_func(param); + } + else + { + return vec4(0.0); + } +} + +void main() +{ + bool param = _34.func_arg != 0; + gl_Position = test_func(param); +} + diff --git a/shaders/legacy/vert/switch-nested.legacy.vert b/shaders/legacy/vert/switch-nested.legacy.vert new file mode 100644 index 00000000..6726c1c6 --- /dev/null +++ b/shaders/legacy/vert/switch-nested.legacy.vert @@ -0,0 +1,28 @@ +#version 450 + +layout(set = 0, binding = 0) uniform UBO +{ + int func_arg; + int inner_func_arg; +}; + +vec4 test_inner_func(bool b) +{ + if (b) + return vec4(1.0); + else + return vec4(0.0); +} + +vec4 test_func(bool b) +{ + if (b) + return test_inner_func(inner_func_arg != 0); + else + return vec4(0.0); +} + +void main() +{ + gl_Position = test_func(func_arg != 0); +} diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 5f2a48f0..f6a42a4e 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -13386,7 +13386,11 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block) { // ESSL 1.0 is not guaranteed to support do/while. if (is_legacy_es()) - statement("for (int SPIRV_Cross_Dummy = 0; SPIRV_Cross_Dummy < 1; SPIRV_Cross_Dummy++)"); + { + uint32_t counter = statement_count; + statement("for (int SPIRV_Cross_Dummy", counter, + " = 0; SPIRV_Cross_Dummy", counter, " < 1; SPIRV_Cross_Dummy", counter, "++)"); + } else statement("do"); }