From 092106d7429efef695dba91cb4367a03f37b7104 Mon Sep 17 00:00:00 2001 From: Caius-Moldovan-img Date: Wed, 4 Mar 2026 10:56:33 +0200 Subject: [PATCH] pco: Move DITR and DITRP fencing from translation to legalization Signed-off-by: Caius Moldovan Reviewed-by: Simon Perretta Part-of: --- src/imagination/pco/pco_internal.h | 1 + src/imagination/pco/pco_ir.c | 1 + src/imagination/pco/pco_legalize.c | 40 +++++++++++++++++++++++++++++ src/imagination/pco/pco_trans_nir.c | 13 ---------- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/imagination/pco/pco_internal.h b/src/imagination/pco/pco_internal.h index 86a325cf276..874a8236cd1 100644 --- a/src/imagination/pco/pco_internal.h +++ b/src/imagination/pco/pco_internal.h @@ -1781,6 +1781,7 @@ bool pco_const_imms(pco_shader *shader); bool pco_bool(pco_shader *shader); bool pco_cf(pco_shader *shader); bool pco_dce(pco_shader *shader); +bool pco_post_ra_legalize(pco_shader *shader); bool pco_end(pco_shader *shader); bool pco_group_instrs(pco_shader *shader); bool pco_index(pco_shader *shader, bool skip_ssa); diff --git a/src/imagination/pco/pco_ir.c b/src/imagination/pco/pco_ir.c index fbeb844efad..7660cfe5224 100644 --- a/src/imagination/pco/pco_ir.c +++ b/src/imagination/pco/pco_ir.c @@ -55,6 +55,7 @@ void pco_process_ir(pco_ctx *ctx, pco_shader *shader) PCO_PASS(_, shader, pco_schedule); PCO_PASS(_, shader, pco_legalize); PCO_PASS(_, shader, pco_ra); + PCO_PASS(_, shader, pco_post_ra_legalize); PCO_PASS(_, shader, pco_end); PCO_PASS(_, shader, pco_group_instrs); diff --git a/src/imagination/pco/pco_legalize.c b/src/imagination/pco/pco_legalize.c index 430aafeae34..8d644a78245 100644 --- a/src/imagination/pco/pco_legalize.c +++ b/src/imagination/pco/pco_legalize.c @@ -396,6 +396,25 @@ static bool try_legalize_large_hwreg_offsets(pco_instr *instr, return true; } +static bool try_legalize_ditr_fence(pco_instr *instr) +{ + if (instr->op != PCO_OP_DITR && instr->op != PCO_OP_DITRP) + return false; + + pco_builder b = + pco_builder_create(instr->parent_func, pco_cursor_before_instr(instr)); + pco_flush_p0(&b); + pco_br_next(&b, .exec_cnd = PCO_EXEC_CND_E1_Z1); + pco_br_next(&b, .exec_cnd = PCO_EXEC_CND_E1_Z0); + + b.cursor = pco_cursor_after_instr(instr); + pco_flush_p0(&b); + pco_br_next(&b, .exec_cnd = PCO_EXEC_CND_E1_Z1); + pco_br_next(&b, .exec_cnd = PCO_EXEC_CND_E1_Z0); + + return true; +} + /** * \brief Try to legalizes an instruction. * @@ -441,3 +460,24 @@ bool pco_legalize(pco_shader *shader) shader->is_legalized = true; return progress; } + +/** + * \brief Post-RA legalization pass. + * + * \param[in,out] shader PCO shader. + * \return True if the pass made progress. + */ +bool pco_post_ra_legalize(pco_shader *shader) +{ + bool progress = false; + + assert(!shader->is_grouped); + + pco_foreach_func_in_shader (func, shader) { + pco_foreach_instr_in_func_safe (instr, func) { + progress |= try_legalize_ditr_fence(instr); + } + } + + return progress; +} diff --git a/src/imagination/pco/pco_trans_nir.c b/src/imagination/pco/pco_trans_nir.c index 6c5dabea9cd..985a6f78a67 100644 --- a/src/imagination/pco/pco_trans_nir.c +++ b/src/imagination/pco/pco_trans_nir.c @@ -44,13 +44,6 @@ static pco_block *trans_cf_nodes(trans_ctx *tctx, struct list_head *cf_node_list, struct exec_list *nir_cf_node_list); -static inline void pco_fence(pco_builder *b) -{ - pco_flush_p0(b); - pco_br_next(b, .exec_cnd = PCO_EXEC_CND_E1_Z1); - pco_br_next(b, .exec_cnd = PCO_EXEC_CND_E1_Z0); -} - /** * \brief Splits a vector destination into scalar components. * @@ -325,14 +318,8 @@ static inline pco_instr *build_itr(pco_builder *b, pco_instr_set_itr_mode(instr, itr_mode); - if (d) - pco_fence(b); - pco_builder_insert_instr(b, instr); - if (d) - pco_fence(b); - return instr; }