nir/lower_discard_to_demote: Use nir_shader_instructions_pass().
authorEric Anholt <eric@anholt.net>
Thu, 20 Aug 2020 19:32:20 +0000 (12:32 -0700)
committerMarge Bot <eric+marge@anholt.net>
Thu, 27 Aug 2020 23:01:52 +0000 (23:01 +0000)
Cleans up indentation, and clears the metadata tracking flag that would
break if this pass was used in in NIR_PASS().

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6412>

src/compiler/nir/nir_lower_discard_to_demote.c

index eb13796d952926e16607f654835a8f3d0185bbe9..88bc9c940a22a483c30ed51f6d16e5d999254579 100644 (file)
  */
 
 #include "nir.h"
+#include "nir_builder.h"
+
+static bool
+nir_lower_discard_to_demote_instr(nir_builder *b, nir_instr *instr, void *data)
+{
+   if (instr->type != nir_instr_type_intrinsic)
+      return false;
+
+   nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
+   switch (intrin->intrinsic) {
+   case nir_intrinsic_discard:
+      intrin->intrinsic = nir_intrinsic_demote;
+      b->shader->info.fs.uses_demote = true;
+      return true;
+   case nir_intrinsic_discard_if:
+      intrin->intrinsic = nir_intrinsic_demote_if;
+      b->shader->info.fs.uses_demote = true;
+      return true;
+   case nir_intrinsic_load_helper_invocation:
+      intrin->intrinsic = nir_intrinsic_is_helper_invocation;
+      return true;
+   default:
+      return false;
+   }
+}
 
 /**
  * This pass is intended as workaround for game bugs to force correct
@@ -38,34 +63,8 @@ nir_lower_discard_to_demote(nir_shader *shader)
    if (shader->info.stage != MESA_SHADER_FRAGMENT)
       return false;
 
-   bool progress = false;
-
-   nir_foreach_function(function, shader) {
-      nir_foreach_block(block, function->impl) {
-         nir_foreach_instr(instr, block) {
-            if (instr->type != nir_instr_type_intrinsic)
-               continue;
-
-            nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
-            switch (intrin->intrinsic) {
-            case nir_intrinsic_discard:
-               intrin->intrinsic = nir_intrinsic_demote;
-               shader->info.fs.uses_demote = true;
-               break;
-            case nir_intrinsic_discard_if:
-               intrin->intrinsic = nir_intrinsic_demote_if;
-               shader->info.fs.uses_demote = true;
-               break;
-            case nir_intrinsic_load_helper_invocation:
-               intrin->intrinsic = nir_intrinsic_is_helper_invocation;
-               break;
-            default:
-               continue;
-            }
-            progress = true;
-         }
-      }
-   }
-
-   return progress;
+   return nir_shader_instructions_pass(shader,
+                                       nir_lower_discard_to_demote_instr,
+                                       nir_metadata_all,
+                                       NULL);
 }