Mesa (main): nir/lower_packing: use shader_instructions_pass

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 29 22:33:04 UTC 2021


Module: Mesa
Branch: main
Commit: b4369de27fc63222a024287af4a2ac58ee949953
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b4369de27fc63222a024287af4a2ac58ee949953

Author: Thomas H.P. Andersen <phomes at gmail.com>
Date:   Mon Jun 28 01:00:31 2021 +0200

nir/lower_packing: use shader_instructions_pass

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11615>

---

 src/compiler/nir/nir_lower_packing.c | 114 ++++++++++++++---------------------
 1 file changed, 46 insertions(+), 68 deletions(-)

diff --git a/src/compiler/nir/nir_lower_packing.c b/src/compiler/nir/nir_lower_packing.c
index b162b84b31c..57bbeac49a8 100644
--- a/src/compiler/nir/nir_lower_packing.c
+++ b/src/compiler/nir/nir_lower_packing.c
@@ -87,80 +87,58 @@ lower_unpack_64_to_16(nir_builder *b, nir_ssa_def *src)
 }
 
 static bool
-lower_pack_impl(nir_function_impl *impl)
+lower_pack_instr(nir_builder *b, nir_instr *instr, void *data)
 {
-   nir_builder b;
-   nir_builder_init(&b, impl);
-   bool progress = false;
-
-   nir_foreach_block(block, impl) {
-      nir_foreach_instr_safe(instr, block) {
-         if (instr->type != nir_instr_type_alu)
-            continue;
-
-         nir_alu_instr *alu_instr = (nir_alu_instr *) instr;
-
-         if (alu_instr->op != nir_op_pack_64_2x32 &&
-             alu_instr->op != nir_op_unpack_64_2x32 &&
-             alu_instr->op != nir_op_pack_64_4x16 &&
-             alu_instr->op != nir_op_unpack_64_4x16 &&
-             alu_instr->op != nir_op_pack_32_2x16 &&
-             alu_instr->op != nir_op_unpack_32_2x16)
-            continue;
-
-         b.cursor = nir_before_instr(&alu_instr->instr);
-
-         nir_ssa_def *src = nir_ssa_for_alu_src(&b, alu_instr, 0);
-         nir_ssa_def *dest;
-
-         switch (alu_instr->op) {
-         case nir_op_pack_64_2x32:
-            dest = lower_pack_64_from_32(&b, src);
-            break;
-         case nir_op_unpack_64_2x32:
-            dest = lower_unpack_64_to_32(&b, src);
-            break;
-         case nir_op_pack_64_4x16:
-            dest = lower_pack_64_from_16(&b, src);
-            break;
-         case nir_op_unpack_64_4x16:
-            dest = lower_unpack_64_to_16(&b, src);
-            break;
-         case nir_op_pack_32_2x16:
-            dest = lower_pack_32_from_16(&b, src);
-            break;
-         case nir_op_unpack_32_2x16:
-            dest = lower_unpack_32_to_16(&b, src);
-            break;
-         default:
-            unreachable("Impossible opcode");
-         }
-
-         nir_ssa_def_rewrite_uses(&alu_instr->dest.dest.ssa, dest);
-         nir_instr_remove(&alu_instr->instr);
-         progress = true;
-      }
+   if (instr->type != nir_instr_type_alu)
+      return false;
+
+   nir_alu_instr *alu_instr = (nir_alu_instr *) instr;
+
+   if (alu_instr->op != nir_op_pack_64_2x32 &&
+       alu_instr->op != nir_op_unpack_64_2x32 &&
+       alu_instr->op != nir_op_pack_64_4x16 &&
+       alu_instr->op != nir_op_unpack_64_4x16 &&
+       alu_instr->op != nir_op_pack_32_2x16 &&
+       alu_instr->op != nir_op_unpack_32_2x16)
+
+      return false;
+
+   b->cursor = nir_before_instr(&alu_instr->instr);
+
+   nir_ssa_def *src = nir_ssa_for_alu_src(b, alu_instr, 0);
+   nir_ssa_def *dest;
+
+   switch (alu_instr->op) {
+   case nir_op_pack_64_2x32:
+      dest = lower_pack_64_from_32(b, src);
+      break;
+   case nir_op_unpack_64_2x32:
+      dest = lower_unpack_64_to_32(b, src);
+      break;
+   case nir_op_pack_64_4x16:
+      dest = lower_pack_64_from_16(b, src);
+      break;
+   case nir_op_unpack_64_4x16:
+      dest = lower_unpack_64_to_16(b, src);
+      break;
+   case nir_op_pack_32_2x16:
+      dest = lower_pack_32_from_16(b, src);
+      break;
+   case nir_op_unpack_32_2x16:
+      dest = lower_unpack_32_to_16(b, src);
+      break;
+   default:
+      unreachable("Impossible opcode");
    }
+   nir_ssa_def_rewrite_uses(&alu_instr->dest.dest.ssa, dest);
+   nir_instr_remove(&alu_instr->instr);
 
-   if (progress) {
-      nir_metadata_preserve(impl, nir_metadata_block_index |
-                                  nir_metadata_dominance);
-   } else {
-      nir_metadata_preserve(impl, nir_metadata_all);
-   }
-
-   return progress;
+   return true;
 }
 
 bool
 nir_lower_pack(nir_shader *shader)
 {
-   bool progress = false;
-
-   nir_foreach_function(function, shader) {
-      if (function->impl)
-         progress |= lower_pack_impl(function->impl);
-   }
-
-   return progress;
+   return nir_shader_instructions_pass(shader, lower_pack_instr,
+         nir_metadata_block_index | nir_metadata_dominance, NULL);
 }



More information about the mesa-commit mailing list