From e966c1bdec69791e8c03c10bc274a18b4e827267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 27 Apr 2026 22:12:27 -0400 Subject: [PATCH] nir/opt_varyings: use workgroup divergence to identify convergent mesh outputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It turns out we do have workgroup divergence, hidden behind nir_divergence_across_subgroups, if I understand it correctly. Reviewed-by: Timur Kristóf Part-of: --- src/compiler/nir/nir_opt_varyings.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler/nir/nir_opt_varyings.c b/src/compiler/nir/nir_opt_varyings.c index 18387eb3997..f52efccf87c 100644 --- a/src/compiler/nir/nir_opt_varyings.c +++ b/src/compiler/nir/nir_opt_varyings.c @@ -1625,17 +1625,13 @@ gather_outputs(struct nir_builder *builder, nir_intrinsic_instr *intr, void *cb_ if (is_store) { nir_scalar value = nir_scalar_resolved(intr->src[0].ssa, 0); - const bool constant = nir_scalar_is_const(value); - /* If the store instruction is executed in a divergent block, the value * that's stored in the output becomes divergent. * - * Mesh shaders get special treatment because we can't follow their topology, - * so we only propagate constants. - * TODO: revisit this when workgroup divergence analysis is merged. + * For all shaders except mesh shaders, "divergent" is vertex divergence. + * For mesh shaders, it's workgroup divergence. */ - const bool divergent = (!constant && linkage->producer_stage == MESA_SHADER_MESH) || - intr->instr.block->divergent || + const bool divergent = intr->instr.block->divergent || nir_src_is_divergent(&intr->src[0]); if (!out->producer.value.def) { @@ -5426,7 +5422,11 @@ nir_opt_varyings(nir_shader *producer, nir_shader *consumer, bool spirv, * divergence information. */ if (consumer->info.stage == MESA_SHADER_FRAGMENT) { - nir_custom_divergence_analysis(producer, nir_divergence_vertex); + nir_divergence_options divergence_options = + producer->info.stage == MESA_SHADER_MESH ? + nir_divergence_across_subgroups : nir_divergence_vertex; + + nir_custom_divergence_analysis(producer, divergence_options); } /* This also removes dead varyings. */