From 537c0029ddece2bb0f5c56947ff7e92258077a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Thu, 8 Feb 2024 11:14:21 +0100 Subject: [PATCH] nir: Fix divergence of reductions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By accident, the function would return without setting the divergence information. Cc: mesa-stable Signed-off-by: Timur Kristóf Reviewed-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_divergence_analysis.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir_divergence_analysis.c b/src/compiler/nir/nir_divergence_analysis.c index 1f35d122bdb..6db01231475 100644 --- a/src/compiler/nir/nir_divergence_analysis.c +++ b/src/compiler/nir/nir_divergence_analysis.c @@ -371,14 +371,19 @@ visit_intrinsic(nir_shader *shader, nir_intrinsic_instr *instr, * the source is uniform and the operation is invariant */ case nir_intrinsic_reduce: - if (vertex_divergence) - return true; - if (nir_intrinsic_cluster_size(instr) == 0) - return false; + if (nir_intrinsic_cluster_size(instr) == 0) { + /* Cluster size of 0 means the subgroup size. + * This is uniform within a subgroup, but divergent between + * vertices of the same primitive because they may be in + * different subgroups. + */ + is_divergent = vertex_divergence; + break; + } FALLTHROUGH; case nir_intrinsic_inclusive_scan: { nir_op op = nir_intrinsic_reduction_op(instr); - is_divergent = instr->src[0].ssa->divergent; + is_divergent = instr->src[0].ssa->divergent || vertex_divergence; if (op != nir_op_umin && op != nir_op_imin && op != nir_op_fmin && op != nir_op_umax && op != nir_op_imax && op != nir_op_fmax && op != nir_op_iand && op != nir_op_ior)