Mesa (main): intel/compiler: use nir_shader_instructions_pass in brw_nir_clamp_image_1d_2d_array_sizes

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 5 10:29:39 UTC 2021


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

Author: Marcin Ślusarz <marcin.slusarz at intel.com>
Date:   Fri Aug  6 13:20:53 2021 +0200

intel/compiler: use nir_shader_instructions_pass in brw_nir_clamp_image_1d_2d_array_sizes

No functional changes.

Signed-off-by: Marcin Ślusarz <marcin.slusarz at intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13189>

---

 .../brw_nir_clamp_image_1d_2d_array_sizes.c        | 210 ++++++++++-----------
 1 file changed, 98 insertions(+), 112 deletions(-)

diff --git a/src/intel/compiler/brw_nir_clamp_image_1d_2d_array_sizes.c b/src/intel/compiler/brw_nir_clamp_image_1d_2d_array_sizes.c
index 0daae1d6e7a..a4bac2315ec 100644
--- a/src/intel/compiler/brw_nir_clamp_image_1d_2d_array_sizes.c
+++ b/src/intel/compiler/brw_nir_clamp_image_1d_2d_array_sizes.c
@@ -36,123 +36,109 @@
  * MAX(array_size, 1) for array textures.
  */
 
-bool
-brw_nir_clamp_image_1d_2d_array_sizes(nir_shader *shader)
+static bool
+brw_nir_clamp_image_1d_2d_array_sizes_instr(nir_builder *b,
+                                            nir_instr *instr,
+                                            UNUSED void *cb_data)
 {
-   bool progress = false;
-   nir_builder b;
-
-   nir_foreach_function(func, shader) {
-      bool function_progress = false;
-
-      if (!func->impl)
-         continue;
-
-      nir_builder_init(&b, func->impl);
-
-      nir_foreach_block(block, func->impl) {
-         nir_foreach_instr_safe(instr, block) {
-            nir_ssa_def *image_size = NULL;
-
-            switch (instr->type) {
-            case nir_instr_type_intrinsic: {
-               nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
-
-               switch (intr->intrinsic) {
-               case nir_intrinsic_image_size:
-               case nir_intrinsic_bindless_image_size:
-                  if (!nir_intrinsic_image_array(intr))
-                     break;
-
-                  image_size = &intr->dest.ssa;
-                  break;
-
-               case nir_intrinsic_image_deref_size: {
-                  nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
-
-                  assert(glsl_type_is_image(deref->type));
-
-                  if (!glsl_sampler_type_is_array(deref->type))
-                     break;
-
-                  image_size = &intr->dest.ssa;
-                  break;
-               }
-
-               default:
-                  break;
-               }
-               break;
-            }
-
-            case nir_instr_type_tex: {
-               nir_tex_instr *tex_instr = nir_instr_as_tex(instr);
-               if (tex_instr->op != nir_texop_txs)
-                  break;
-
-               if (!tex_instr->is_array)
-                  break;
-
-               image_size = &tex_instr->dest.ssa;
-               break;
-            }
-
-            default:
-               break;
-            }
-
-            if (!image_size)
-               continue;
-
-            b.cursor = nir_after_instr(instr);
-
-            nir_ssa_def *components[4];
-            /* OR all the sizes for all components but the last. */
-            nir_ssa_def *or_components = nir_imm_int(&b, 0);
-            for (int i = 0; i < image_size->num_components; i++) {
-               if (i == (image_size->num_components - 1)) {
-                  nir_ssa_def *null_or_size[2] = {
-                     nir_imm_int(&b, 0),
-                     nir_imax(&b, nir_channel(&b, image_size, i),
-                                  nir_imm_int(&b, 1)),
-                  };
-                  nir_ssa_def *vec2_null_or_size = nir_vec(&b, null_or_size, 2);
-
-                  /* Using the ORed sizes select either the element 0 or 1
-                   * from this vec2. For NULL textures which have a size of
-                   * 0x0x0, we'll select the first element which is 0 and for
-                   * the rest MAX(depth, 1).
-                   */
-                  components[i] =
-                     nir_vector_extract(&b, vec2_null_or_size,
-                                            nir_imin(&b, or_components,
-                                                         nir_imm_int(&b, 1)));
-               } else {
-                  components[i] = nir_channel(&b, image_size, i);
-                  or_components = nir_ior(&b, components[i], or_components);
-               }
-            }
-            nir_ssa_def *image_size_replacement =
-               nir_vec(&b, components, image_size->num_components);
-
-            b.cursor = nir_after_instr(instr);
-
-            nir_ssa_def_rewrite_uses_after(image_size,
-                                           image_size_replacement,
-                                           image_size_replacement->parent_instr);
-
-            function_progress = true;
-         }
+   nir_ssa_def *image_size = NULL;
+
+   switch (instr->type) {
+   case nir_instr_type_intrinsic: {
+      nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
+
+      switch (intr->intrinsic) {
+      case nir_intrinsic_image_size:
+      case nir_intrinsic_bindless_image_size:
+         if (!nir_intrinsic_image_array(intr))
+            break;
+
+         image_size = &intr->dest.ssa;
+         break;
+
+      case nir_intrinsic_image_deref_size: {
+         nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
+
+         assert(glsl_type_is_image(deref->type));
+
+         if (!glsl_sampler_type_is_array(deref->type))
+            break;
+
+         image_size = &intr->dest.ssa;
+         break;
+      }
+
+      default:
+         break;
       }
+      break;
+   }
+
+   case nir_instr_type_tex: {
+      nir_tex_instr *tex_instr = nir_instr_as_tex(instr);
+      if (tex_instr->op != nir_texop_txs)
+         break;
 
-      if (function_progress) {
-         nir_metadata_preserve(func->impl, nir_metadata_block_index |
-                                           nir_metadata_dominance);
-         progress = function_progress;
+      if (!tex_instr->is_array)
+         break;
+
+      image_size = &tex_instr->dest.ssa;
+      break;
+   }
+
+   default:
+      break;
+   }
+
+   if (!image_size)
+      return false;
+
+   b->cursor = nir_after_instr(instr);
+
+   nir_ssa_def *components[4];
+   /* OR all the sizes for all components but the last. */
+   nir_ssa_def *or_components = nir_imm_int(b, 0);
+   for (int i = 0; i < image_size->num_components; i++) {
+      if (i == (image_size->num_components - 1)) {
+         nir_ssa_def *null_or_size[2] = {
+            nir_imm_int(b, 0),
+            nir_imax(b, nir_channel(b, image_size, i),
+                         nir_imm_int(b, 1)),
+         };
+         nir_ssa_def *vec2_null_or_size = nir_vec(b, null_or_size, 2);
+
+         /* Using the ORed sizes select either the element 0 or 1
+          * from this vec2. For NULL textures which have a size of
+          * 0x0x0, we'll select the first element which is 0 and for
+          * the rest MAX(depth, 1).
+          */
+         components[i] =
+            nir_vector_extract(b, vec2_null_or_size,
+                                   nir_imin(b, or_components,
+                                                nir_imm_int(b, 1)));
       } else {
-         nir_metadata_preserve(func->impl, nir_metadata_all);
+         components[i] = nir_channel(b, image_size, i);
+         or_components = nir_ior(b, components[i], or_components);
       }
    }
+   nir_ssa_def *image_size_replacement =
+      nir_vec(b, components, image_size->num_components);
+
+   b->cursor = nir_after_instr(instr);
 
-   return progress;
+   nir_ssa_def_rewrite_uses_after(image_size,
+                                  image_size_replacement,
+                                  image_size_replacement->parent_instr);
+
+   return true;
+}
+
+bool
+brw_nir_clamp_image_1d_2d_array_sizes(nir_shader *shader)
+{
+   return nir_shader_instructions_pass(shader,
+                                       brw_nir_clamp_image_1d_2d_array_sizes_instr,
+                                       nir_metadata_block_index |
+                                       nir_metadata_dominance,
+                                       NULL);
 }



More information about the mesa-commit mailing list