zink: handle ntv case of nested loop instructions more permissively
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 10 Jun 2020 15:09:47 +0000 (11:09 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 13 Jul 2020 21:13:45 +0000 (21:13 +0000)
if the last instruction in a loop's body terminates a block, e.g., from
a nested loop with a jump as its final instruction, then no block will
have been started when returning to the original loop, and there's no need
to emit a branch

fixes shaders@glsl-vs-continue-in-switch-in-do-while

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5852>

src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c

index 095b8e08fcf7aa5edbeb8ee9b079fa3f23f18bf2..b80f09ccccd75b603a8c880f439c402bc54b66b9 100644 (file)
@@ -2119,7 +2119,9 @@ emit_loop(struct ntv_context *ctx, nir_loop *loop)
    ctx->loop_break = save_break;
    ctx->loop_cont = save_cont;
 
-   branch(ctx, cont_id);
+   /* loop->body may have already ended our block */
+   if (ctx->block_started)
+      branch(ctx, cont_id);
    start_block(ctx, cont_id);
    branch(ctx, header_id);