Module: Mesa Branch: main Commit: f42eb71df9a7b301176683af309511a8fd767e8f URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=f42eb71df9a7b301176683af309511a8fd767e8f
Author: Daniel Schürmann <[email protected]> Date: Tue Nov 23 17:06:36 2021 +0100 spirv: use Loop Continue Construct to emit SPIR-V loops and lower after parsing Reviewed-by: Faith Ekstrand <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13962> --- src/compiler/spirv/spirv_to_nir.c | 1 + src/compiler/spirv/vtn_cfg.c | 29 ++--------------------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 802936fd6ce..2c9c75b4c8a 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -6694,6 +6694,7 @@ spirv_to_nir(const uint32_t *words, size_t word_count, /* structurize the CFG */ nir_lower_goto_ifs(b->shader); + nir_lower_continue_constructs(b->shader); /* A SPIR-V module can have multiple shaders stages and also multiple * shaders of the same stage. Global variables are declared per-module. diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c index cdf3587ed95..b02c11b8d7c 100644 --- a/src/compiler/spirv/vtn_cfg.c +++ b/src/compiler/spirv/vtn_cfg.c @@ -1230,32 +1230,10 @@ vtn_emit_cf_list_structured(struct vtn_builder *b, struct list_head *cf_list, nir_loop *loop = nir_push_loop(&b->nb); loop->control = vtn_loop_control(b, vtn_loop); - vtn_emit_cf_list_structured(b, &vtn_loop->body, NULL, NULL, handler); - if (!list_is_empty(&vtn_loop->cont_body)) { - /* If we have a non-trivial continue body then we need to put - * it at the beginning of the loop with a flag to ensure that - * it doesn't get executed in the first iteration. - */ - nir_variable *do_cont = - nir_local_variable_create(b->nb.impl, glsl_bool_type(), "cont"); - - b->nb.cursor = nir_before_cf_node(&loop->cf_node); - nir_store_var(&b->nb, do_cont, nir_imm_false(&b->nb), 1); - - b->nb.cursor = nir_before_cf_list(&loop->body); - - nir_if *cont_if = - nir_push_if(&b->nb, nir_load_var(&b->nb, do_cont)); - - vtn_emit_cf_list_structured(b, &vtn_loop->cont_body, NULL, NULL, - handler); - - nir_pop_if(&b->nb, cont_if); - - nir_store_var(&b->nb, do_cont, nir_imm_true(&b->nb), 1); - } + nir_push_continue(&b->nb, loop); + vtn_emit_cf_list_structured(b, &vtn_loop->cont_body, NULL, NULL, handler); nir_pop_loop(&b->nb, loop); break; @@ -1481,9 +1459,6 @@ vtn_function_emit(struct vtn_builder *b, struct vtn_function *func, * There are some cases where we need to repair SSA to insert * the needed phi nodes: * - * - Continue blocks for loops get inserted before the body of the loop - * but instructions in the continue may use SSA defs in the loop body. - * * - Early termination instructions `OpKill` and `OpTerminateInvocation`, * in NIR. They're represented by regular intrinsics with no control-flow * semantics. This means that the SSA form from the SPIR-V may not
