Mesa (master): nir/lower_non_uniform: improve code with the same texture, sampler indices

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Nov 26 16:26:34 UTC 2020


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

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Thu Feb 13 15:09:53 2020 +0000

nir/lower_non_uniform: improve code with the same texture, sampler indices

NIR can't CSE the read_first_invocation intrinsics, so we can end up
creating iand(read_first_invocation(a) == a, read_first_invocation(a) == a)

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3813>

---

 src/compiler/nir/nir_lower_non_uniform_access.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/compiler/nir/nir_lower_non_uniform_access.c b/src/compiler/nir/nir_lower_non_uniform_access.c
index 76b5da9f4e1..73f9b879510 100644
--- a/src/compiler/nir/nir_lower_non_uniform_access.c
+++ b/src/compiler/nir/nir_lower_non_uniform_access.c
@@ -73,9 +73,10 @@ lower_non_uniform_tex_access(nir_builder *b, nir_tex_instr *tex)
       assert(handle_count < 2);
       assert(tex->src[i].src.is_ssa);
       nir_ssa_def *handle = tex->src[i].src.ssa;
+      nir_deref_instr *parent = NULL;
       if (handle->parent_instr->type == nir_instr_type_deref) {
          nir_deref_instr *deref = nir_instr_as_deref(handle->parent_instr);
-         nir_deref_instr *parent = nir_deref_instr_parent(deref);
+         parent = nir_deref_instr_parent(deref);
          if (deref->deref_type == nir_deref_type_var)
             continue;
 
@@ -87,16 +88,19 @@ lower_non_uniform_tex_access(nir_builder *b, nir_tex_instr *tex)
             continue;
 
          handle = deref->arr.index.ssa;
-
-         parent_derefs[handle_count] = parent;
+      }
+      unsigned handle_index = (!handle_count || handle != handles[0]) ? handle_count : 0;
+      if (parent) {
+         parent_derefs[handle_index] = parent;
          if (tex->src[i].src_type == nir_tex_src_texture_deref)
-            texture_deref_handle = handle_count;
+            texture_deref_handle = handle_index;
          else
-            sampler_deref_handle = handle_count;
+            sampler_deref_handle = handle_index;
       }
       assert(handle->num_components == 1);
 
-      handles[handle_count++] = handle;
+      if (handle_index == handle_count)
+         handles[handle_count++] = handle;
    }
 
    if (handle_count == 0)



More information about the mesa-commit mailing list