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 <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31968>
This commit is contained in:
Marek Olšák
2024-10-31 21:34:50 -04:00
committed by Marge Bot
parent b71edce77a
commit 9d043e138d
3 changed files with 30 additions and 0 deletions
+1
View File
@@ -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,
@@ -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;
}
}
}
}
+9
View File
@@ -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;
}