nir: use nir_shader_instructions_pass in nir_lower_clip_halfz
authorMarcin Ślusarz <marcin.slusarz@intel.com>
Mon, 9 Aug 2021 13:12:48 +0000 (15:12 +0200)
committerMarge Bot <emma+marge@anholt.net>
Mon, 26 Sep 2022 11:13:03 +0000 (11:13 +0000)
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>

src/compiler/nir/nir_lower_clip_halfz.c

index 254c498..48c4818 100644 (file)
 
 #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);
 }