From cfee9e1d9f60a51b426e0d01c3e4618839a5f5ba Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Mon, 17 Feb 2025 21:39:26 +0100 Subject: [PATCH] nir/peephole_select: add option to allow discard without ~0 limit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Daniel Schürmann Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_opt_peephole_select.c | 12 +++++++++--- src/gallium/frontends/rusticl/core/kernel.rs | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index bfecbe54c8f..4a0dd80c3c5 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -6062,6 +6062,7 @@ typedef struct nir_opt_peephole_select_options { unsigned limit; /* Set to max to flatten all control flow. */ bool indirect_load_ok; bool expensive_alu_ok; + bool discard_ok; } nir_opt_peephole_select_options; bool nir_opt_peephole_select(nir_shader *shader, diff --git a/src/compiler/nir/nir_opt_peephole_select.c b/src/compiler/nir/nir_opt_peephole_select.c index f67d6351905..700456d1fa6 100644 --- a/src/compiler/nir/nir_opt_peephole_select.c +++ b/src/compiler/nir/nir_opt_peephole_select.c @@ -195,6 +195,14 @@ block_check_for_allowed_instrs(nir_block *block, unsigned *count, return false; break; + case nir_intrinsic_terminate: + case nir_intrinsic_terminate_if: + case nir_intrinsic_demote: + case nir_intrinsic_demote_if: + if (!options->discard_ok) + return false; + break; + default: return false; } @@ -296,9 +304,7 @@ get_options_for_if(nir_if *if_stmt, return if_options; } -/* If we're moving discards out of the if for non-CF hardware, we need to add - * the if's condition to it - */ +/* If we're moving discards out of the if we need to add the if's condition to it */ static void rewrite_discard_conds(nir_instr *instr, nir_def *if_cond, bool is_else) { diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index f2f8510ce46..8bbd822390d 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -592,6 +592,7 @@ fn opt_nir(nir: &mut NirShader, dev: &Device, has_explicit_types: bool) { limit: 8, indirect_load_ok: true, expensive_alu_ok: true, + discard_ok: false, }; progress |= nir_pass!(nir, nir_opt_peephole_select, &peephole_select_options); progress |= nir_pass!(