From 3f26e9ca1971e5d602770b03f371ded5d69657a9 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Mon, 25 Nov 2024 14:19:39 +0100 Subject: [PATCH] nir/opt_intrinsic: fix sample mask opt with demote MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák Fixes: d3ce8a7f6b9 ("nir: optimize gl_SampleMaskIn to gl_HelperInvocation for radeonsi when possible") Part-of: --- src/compiler/nir/nir_opt_intrinsics.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/compiler/nir/nir_opt_intrinsics.c b/src/compiler/nir/nir_opt_intrinsics.c index f20a7ac6e0c..c73dd40d1a3 100644 --- a/src/compiler/nir/nir_opt_intrinsics.c +++ b/src/compiler/nir/nir_opt_intrinsics.c @@ -329,6 +329,20 @@ opt_intrinsics_intrin(nir_builder *b, nir_intrinsic_instr *intrin, if (!nir_scalar_is_const(other) || nir_scalar_as_uint(other)) continue; + nir_cf_node *cf_node = &intrin->instr.block->cf_node; + while (cf_node->parent) + cf_node = cf_node->parent; + + nir_function_impl *func_impl = nir_cf_node_as_function(cf_node); + + /* We need to insert load_helper before any demote, + * which is only possible in the entry point function + */ + if (func_impl != nir_shader_get_entrypoint(b->shader)) + break; + + b->cursor = nir_before_impl(func_impl); + nir_def *new_expr = nir_load_helper_invocation(b, 1); if (alu->op == nir_op_ine)