Philip Rebohle : vkd3d-shader/spirv: Omit the "endloop" branch to the loop start if the loop block was previously ended.

Alexandre Julliard julliard at winehq.org
Mon Nov 8 15:44:34 CST 2021


Module: vkd3d
Branch: master
Commit: 4e398459b1e467377d68f73a49612bb49a09c9c8
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=4e398459b1e467377d68f73a49612bb49a09c9c8

Author: Philip Rebohle <philip.rebohle at tu-dortmund.de>
Date:   Mon Nov  8 14:50:17 2021 +0100

vkd3d-shader/spirv: Omit the "endloop" branch to the loop start if the loop block was previously ended.

Avoiding generation of invalid SPIR-V.

Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d-shader/spirv.c             | 6 +++++-
 libs/vkd3d-shader/vkd3d_shader_main.c | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c
index 9f6eb88..e5b9ef0 100644
--- a/libs/vkd3d-shader/spirv.c
+++ b/libs/vkd3d-shader/spirv.c
@@ -7661,6 +7661,7 @@ static int vkd3d_dxbc_compiler_emit_control_flow_instruction(struct vkd3d_dxbc_c
             cf_info->u.loop.continue_block_id = continue_block_id;
             cf_info->u.loop.merge_block_id = merge_block_id;
             cf_info->current_block = VKD3D_BLOCK_LOOP;
+            cf_info->inside_block = true;
 
             vkd3d_spirv_build_op_name(builder, loop_header_block_id, "loop%u_header", compiler->loop_id);
             vkd3d_spirv_build_op_name(builder, loop_body_block_id, "loop%u_body", compiler->loop_id);
@@ -7673,7 +7674,10 @@ static int vkd3d_dxbc_compiler_emit_control_flow_instruction(struct vkd3d_dxbc_c
             assert(compiler->control_flow_depth);
             assert(cf_info->current_block == VKD3D_BLOCK_LOOP);
 
-            vkd3d_spirv_build_op_branch(builder, cf_info->u.loop.continue_block_id);
+            /* The loop block may have already been ended by an unconditional
+             * break instruction right before the end of the loop. */
+            if (cf_info->inside_block)
+                vkd3d_spirv_build_op_branch(builder, cf_info->u.loop.continue_block_id);
 
             vkd3d_spirv_build_op_label(builder, cf_info->u.loop.continue_block_id);
             vkd3d_spirv_build_op_branch(builder, cf_info->u.loop.header_block_id);
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c
index d204533..3982d07 100644
--- a/libs/vkd3d-shader/vkd3d_shader_main.c
+++ b/libs/vkd3d-shader/vkd3d_shader_main.c
@@ -814,6 +814,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte
         case VKD3DSIH_LOOP:
             cf_info = vkd3d_shader_scan_push_cf_info(context);
             cf_info->type = VKD3D_SHADER_BLOCK_LOOP;
+            cf_info->inside_block = true;
             break;
         case VKD3DSIH_ENDLOOP:
             if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_LOOP)




More information about the wine-cvs mailing list