spirv: use Loop Continue Construct to emit SPIR-V loops and lower after parsing

Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13962>
This commit is contained in:
Daniel Schürmann 2021-11-23 17:06:36 +01:00 committed by Marge Bot
parent c20751d61d
commit f42eb71df9
2 changed files with 3 additions and 27 deletions

View file

@ -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.

View file

@ -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