Mesa (main): turnip: use nir_shader_instructions_pass in tu_lower_io

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 19 13:33:25 UTC 2021


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

Author: Marcin Ślusarz <marcin.slusarz at intel.com>
Date:   Tue Aug 10 15:02:51 2021 +0200

turnip: use nir_shader_instructions_pass in tu_lower_io

No functional changes.

Signed-off-by: Marcin Ślusarz <marcin.slusarz at intel.com>
Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12467>

---

 src/freedreno/vulkan/tu_shader.c | 58 +++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 34 deletions(-)

diff --git a/src/freedreno/vulkan/tu_shader.c b/src/freedreno/vulkan/tu_shader.c
index 55f38fff7fa..8060fd68313 100644
--- a/src/freedreno/vulkan/tu_shader.c
+++ b/src/freedreno/vulkan/tu_shader.c
@@ -546,39 +546,26 @@ lower_tex(nir_builder *b, nir_tex_instr *tex,
    return true;
 }
 
+struct lower_instr_params {
+   struct tu_shader *shader;
+   const struct tu_pipeline_layout *layout;
+};
+
 static bool
-lower_impl(nir_function_impl *impl, struct tu_shader *shader,
-            const struct tu_pipeline_layout *layout)
+lower_instr(nir_builder *b, nir_instr *instr, void *cb_data)
 {
-   nir_builder b;
-   nir_builder_init(&b, impl);
-   bool progress = false;
-
-   nir_foreach_block(block, impl) {
-      nir_foreach_instr_safe(instr, block) {
-         b.cursor = nir_before_instr(instr);
-         switch (instr->type) {
-         case nir_instr_type_tex:
-            progress |= lower_tex(&b, nir_instr_as_tex(instr), shader, layout);
-            break;
-         case nir_instr_type_intrinsic:
-            progress |= lower_intrinsic(&b, nir_instr_as_intrinsic(instr), shader, layout);
-            break;
-         default:
-            break;
-         }
-      }
+   struct lower_instr_params *params = cb_data;
+   b->cursor = nir_before_instr(instr);
+   switch (instr->type) {
+   case nir_instr_type_tex:
+      return lower_tex(b, nir_instr_as_tex(instr), params->shader, params->layout);
+   case nir_instr_type_intrinsic:
+      return lower_intrinsic(b, nir_instr_as_intrinsic(instr), params->shader, params->layout);
+   default:
+      return false;
    }
-
-   if (progress)
-      nir_metadata_preserve(impl, nir_metadata_none);
-   else
-      nir_metadata_preserve(impl, nir_metadata_all);
-
-   return progress;
 }
 
-
 /* Figure out the range of push constants that we're actually going to push to
  * the shader, and tell the backend to reserve this range when pushing UBO
  * constants.
@@ -629,14 +616,17 @@ static bool
 tu_lower_io(nir_shader *shader, struct tu_shader *tu_shader,
             const struct tu_pipeline_layout *layout)
 {
-   bool progress = false;
-
    gather_push_constants(shader, tu_shader);
 
-   nir_foreach_function(function, shader) {
-      if (function->impl)
-         progress |= lower_impl(function->impl, tu_shader, layout);
-   }
+   struct lower_instr_params params = {
+      .shader = tu_shader,
+      .layout = layout,
+   };
+
+   bool progress = nir_shader_instructions_pass(shader,
+                                                lower_instr,
+                                                nir_metadata_none,
+                                                &params);
 
    /* Remove now-unused variables so that when we gather the shader info later
     * they won't be counted.



More information about the mesa-commit mailing list