Mesa (staging/20.0): nir: reuse existing psiz-variable

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 9 18:01:49 UTC 2020


Module: Mesa
Branch: staging/20.0
Commit: 8df640b461d1f104b17209d97a280ff764fa39bc
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8df640b461d1f104b17209d97a280ff764fa39bc

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Tue Jun  2 10:44:13 2020 +0200

nir: reuse existing psiz-variable

For shaders where there's already a psiz-variable, we should rather
reuse it than create a second one. This can happen if a shader writes
gl_PointSize, but disables GL_PROGRAM_POINT_SIZE.

Fixes: 878c94288a8 ("nir: add lowering-pass for point-size mov")
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5328>
(cherry picked from commit e61a98877ccdaf7ec1f9f890f0f7c1a993ee70a1)

---

 .pick_status.json                           |  2 +-
 src/compiler/nir/nir_lower_point_size_mov.c | 26 ++++++++++++++++++++------
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 0abfa29890f..5b386012507 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -967,7 +967,7 @@
         "description": "nir: reuse existing psiz-variable",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": "878c94288a8aed3479517660be3e9a88f9b44269"
     },
diff --git a/src/compiler/nir/nir_lower_point_size_mov.c b/src/compiler/nir/nir_lower_point_size_mov.c
index 56cee7746fd..0b9226b60fa 100644
--- a/src/compiler/nir/nir_lower_point_size_mov.c
+++ b/src/compiler/nir/nir_lower_point_size_mov.c
@@ -33,11 +33,12 @@
 
 static bool
 lower_impl(nir_function_impl *impl,
-           const gl_state_index16 *pointsize_state_tokens)
+           const gl_state_index16 *pointsize_state_tokens,
+           nir_variable *out)
 {
    nir_shader *shader = impl->function->shader;
    nir_builder b;
-   nir_variable *in, *out;
+   nir_variable *in;
 
    nir_builder_init(&b, impl);
    b.cursor = nir_before_cf_list(&impl->body);
@@ -50,9 +51,11 @@ lower_impl(nir_function_impl *impl,
          pointsize_state_tokens,
          sizeof(in->state_slots[0].tokens));
 
-   out = nir_variable_create(shader, nir_var_shader_out,
-                             glsl_float_type(), "gl_PointSize");
-   out->data.location = VARYING_SLOT_PSIZ;
+   if (!out) {
+      out = nir_variable_create(shader, nir_var_shader_out,
+                                glsl_float_type(), "gl_PointSize");
+      out->data.location = VARYING_SLOT_PSIZ;
+   }
 
    nir_copy_var(&b, out, in);
 
@@ -65,5 +68,16 @@ void
 nir_lower_point_size_mov(nir_shader *shader,
                          const gl_state_index16 *pointsize_state_tokens)
 {
-   lower_impl(nir_shader_get_entrypoint(shader), pointsize_state_tokens);
+   assert(shader->info.stage == MESA_SHADER_VERTEX);
+
+   nir_variable *out = NULL;
+   nir_foreach_variable(var, &shader->outputs) {
+      if (var->data.location == VARYING_SLOT_PSIZ) {
+         out = var;
+         break;
+      }
+   }
+
+   lower_impl(nir_shader_get_entrypoint(shader), pointsize_state_tokens,
+              out);
 }



More information about the mesa-commit mailing list