From 581ed0fd59cf628d583a695faaefb412bcfcffe2 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 27 Jun 2019 15:10:17 +0200 Subject: [PATCH] HLSL: Does not support case-fallthrough. Disable any fallthrough on HLSL. Risky business if fallthrough blocks had a barrier(), but can't do anything about that ... --- .../asm/frag/switch-block-case-fallthrough.asm.frag | 9 +++++++++ spirv_glsl.cpp | 2 +- spirv_glsl.hpp | 1 + spirv_hlsl.cpp | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/reference/shaders-hlsl-no-opt/asm/frag/switch-block-case-fallthrough.asm.frag b/reference/shaders-hlsl-no-opt/asm/frag/switch-block-case-fallthrough.asm.frag index fa4953fd..ba66ccf6 100644 --- a/reference/shaders-hlsl-no-opt/asm/frag/switch-block-case-fallthrough.asm.frag +++ b/reference/shaders-hlsl-no-opt/asm/frag/switch-block-case-fallthrough.asm.frag @@ -30,16 +30,23 @@ void frag_main() case 0: { _30 = 3; + j = _30; + _31 = 0; + j = _31; + break; } default: { j = _30; _31 = 0; + j = _31; + break; } case 1: case 11: { j = _31; + break; } case 2: { @@ -59,6 +66,8 @@ void frag_main() } case 4: { + i = 0; + break; } case 5: { diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 3aeedf0e..78eacb9f 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -11702,7 +11702,7 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block) } auto &case_block = get(target_block); - if (i + 1 < num_blocks && + if (backend.support_case_fallthrough && i + 1 < num_blocks && execution_is_direct_branch(case_block, get(block_declaration_order[i + 1]))) { // We will fall through here, so just terminate the block chain early. diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index f486d271..9759671f 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -405,6 +405,7 @@ protected: bool comparison_image_samples_scalar = false; bool native_pointers = false; bool support_small_type_sampling_result = false; + bool support_case_fallthrough = true; } backend; void emit_struct(SPIRType &type); diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index c129966f..4d9ade2c 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -4700,6 +4700,7 @@ string CompilerHLSL::compile() backend.can_declare_arrays_inline = false; backend.can_return_array = false; backend.nonuniform_qualifier = "NonUniformResourceIndex"; + backend.support_case_fallthrough = false; fixup_type_alias(); reorder_type_alias();