Mesa (main): nir/lower_psiz: create the store instruction more accurately

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Feb 28 16:08:49 UTC 2022


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Tue Feb  1 16:53:20 2022 -0500

nir/lower_psiz: create the store instruction more accurately

creating this at the start of the shader means it will get optimized out
when the pass is used to overwrite existing psiz values, and creating it
at the end means it will get optimized out in geometry shaders, so instead
just walk the instructions and create another store right after the existing one

Acked-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15184>

---

 src/compiler/nir/nir_lower_point_size_mov.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_lower_point_size_mov.c b/src/compiler/nir/nir_lower_point_size_mov.c
index f7496816939..58d1868261a 100644
--- a/src/compiler/nir/nir_lower_point_size_mov.c
+++ b/src/compiler/nir/nir_lower_point_size_mov.c
@@ -41,7 +41,6 @@ lower_impl(nir_function_impl *impl,
    nir_variable *in;
 
    nir_builder_init(&b, impl);
-   b.cursor = nir_before_cf_list(&impl->body);
 
    in = nir_variable_create(shader, nir_var_uniform,
                             glsl_float_type(), "gl_PointSizeClampedMESA");
@@ -56,10 +55,25 @@ lower_impl(nir_function_impl *impl,
       out = nir_variable_create(shader, nir_var_shader_out,
                                 glsl_float_type(), "gl_PointSize");
       out->data.location = VARYING_SLOT_PSIZ;
+      b.cursor = nir_before_cf_list(&impl->body);
+      nir_copy_var(&b, out, in);
+   } else {
+      nir_foreach_block_safe(block, impl) {
+         nir_foreach_instr_safe(instr, block) {
+            if (instr->type == nir_instr_type_intrinsic) {
+               nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
+               if (intr->intrinsic == nir_intrinsic_store_deref) {
+                  nir_variable *var = nir_intrinsic_get_var(intr, 0);
+                  if (var == out) {
+                     b.cursor = nir_after_instr(instr);
+                     nir_copy_var(&b, out, in);
+                  }
+               }
+            }
+         }
+      }
    }
 
-   nir_copy_var(&b, out, in);
-
    nir_metadata_preserve(impl, nir_metadata_block_index |
                                nir_metadata_dominance);
    return true;



More information about the mesa-commit mailing list