From 9d043e138d9d6bed9eaf1e6e5bc54550ad684777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 31 Oct 2024 21:34:50 -0400 Subject: [PATCH] nir: add nir_clear_divergence_info, use it in nir_opt_varyings nir_opt_varyings computes vertex divergence, which isn't exactly expected by any other passes. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_divergence_analysis.c | 20 ++++++++++++++++++++ src/compiler/nir/nir_opt_varyings.c | 9 +++++++++ 3 files changed, 30 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index f1f520c1550..84c11062945 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -6715,6 +6715,7 @@ void nir_divergence_analysis_impl(nir_function_impl *impl, nir_divergence_option void nir_divergence_analysis(nir_shader *shader); void nir_vertex_divergence_analysis(nir_shader *shader); bool nir_has_divergent_loop(nir_shader *shader); +void nir_clear_divergence_info(nir_shader *nir); void nir_rewrite_uses_to_load_reg(struct nir_builder *b, nir_def *old, diff --git a/src/compiler/nir/nir_divergence_analysis.c b/src/compiler/nir/nir_divergence_analysis.c index b773d21e7ac..a8fc33bc98e 100644 --- a/src/compiler/nir/nir_divergence_analysis.c +++ b/src/compiler/nir/nir_divergence_analysis.c @@ -1469,3 +1469,23 @@ nir_has_divergent_loop(nir_shader *shader) return false; } + +/* Recommended when computing divergence information in shared code such + * as the GLSL linker. + */ +void +nir_clear_divergence_info(nir_shader *nir) +{ + nir_foreach_function_impl(impl, nir) { + nir_foreach_block(block, impl) { + /* true is the safer value. */ + block->divergent = true; + + nir_foreach_instr(instr, block) { + nir_def *def = nir_instr_def(instr); + if (def) + def->divergent = true; + } + } + } +} diff --git a/src/compiler/nir/nir_opt_varyings.c b/src/compiler/nir/nir_opt_varyings.c index c21b0e157bf..6e101b42f2b 100644 --- a/src/compiler/nir/nir_opt_varyings.c +++ b/src/compiler/nir/nir_opt_varyings.c @@ -4402,5 +4402,14 @@ nir_opt_varyings(nir_shader *producer, nir_shader *consumer, bool spirv, if (progress & nir_progress_consumer) nir_validate_shader(consumer, "nir_opt_varyings"); + if (consumer->info.stage == MESA_SHADER_FRAGMENT) { + /* We have called nir_vertex_divergence_analysis on the producer here. + * We need to reset the divergent field to true, otherwise it will be + * garbage after some other passes are run, and then we end up failing + * assertions in some passes because src is divergent and dst isn't. + */ + nir_clear_divergence_info(producer); + } + return progress; }