nir: use nir_shader_instructions_pass in nir_lower_clip_halfz

Changes:
- nir_metadata_preserve(..., nir_metadata_block_index | nir_metadata_dominance)
  is called only when pass makes progress
- nir_metadata_preserve(..., nir_metadata_all) is called when pass doesn't
  make progress

Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12282>
This commit is contained in:
Marcin Ślusarz
2021-08-09 15:12:48 +02:00
committed by Marge Bot
parent c6e4641a21
commit 00b0de5c83

View File

@@ -23,20 +23,20 @@
#include "nir_builder.h"
static void
lower_pos_write(nir_builder *b, struct nir_instr *instr)
static bool
lower_pos_write(nir_builder *b, nir_instr *instr, UNUSED void *cb_data)
{
if (instr->type != nir_instr_type_intrinsic)
return;
return false;
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
if (intr->intrinsic != nir_intrinsic_store_deref)
return;
return false;
nir_variable *var = nir_intrinsic_get_var(intr, 0);
if (var->data.mode != nir_var_shader_out ||
var->data.location != VARYING_SLOT_POS)
return;
return false;
b->cursor = nir_before_instr(&intr->instr);
@@ -51,6 +51,7 @@ lower_pos_write(nir_builder *b, struct nir_instr *instr)
0.5),
nir_channel(b, pos, 3));
nir_instr_rewrite_src(&intr->instr, intr->src + 1, nir_src_for_ssa(def));
return true;
}
void
@@ -61,19 +62,8 @@ nir_lower_clip_halfz(nir_shader *shader)
shader->info.stage != MESA_SHADER_TESS_EVAL)
return;
nir_foreach_function(function, shader) {
if (function->impl) {
nir_builder b;
nir_builder_init(&b, function->impl);
nir_foreach_block(block, function->impl) {
nir_foreach_instr_safe(instr, block) {
lower_pos_write(&b, instr);
}
}
nir_metadata_preserve(function->impl, nir_metadata_block_index |
nir_metadata_dominance);
}
}
nir_shader_instructions_pass(shader, lower_pos_write,
nir_metadata_block_index |
nir_metadata_dominance,
NULL);
}