diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index f9cb78b6137..1d851a79b31 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -5342,9 +5342,10 @@ static bool emit_loop(struct ntd_context *ctx, nir_loop *loop) { nir_block *first_block = nir_loop_first_block(loop); + nir_block *last_block = nir_loop_last_block(loop); - assert(nir_loop_last_block(loop)->successors[0]); - assert(!nir_loop_last_block(loop)->successors[1]); + assert(last_block->successors[0]); + assert(!last_block->successors[1]); if (!emit_branch(ctx, first_block->index)) return false; @@ -5352,7 +5353,12 @@ emit_loop(struct ntd_context *ctx, nir_loop *loop) if (!emit_cf_list(ctx, &loop->body)) return false; - if (!emit_branch(ctx, first_block->index)) + /* If the loop's last block doesn't explicitly jump somewhere, then there's + * an implicit continue that should take it back to the first loop block + */ + nir_instr *last_instr = nir_block_last_instr(last_block); + if ((!last_instr || last_instr->type != nir_instr_type_jump) && + !emit_branch(ctx, first_block->index)) return false; return true;