Mesa (master): v3d: Use nir_remove_unused_io_vars to handle binner shader output DCE

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 30 17:58:28 UTC 2018


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

Author: Eric Anholt <eric at anholt.net>
Date:   Wed Sep 26 09:22:51 2018 -0700

v3d: Use nir_remove_unused_io_vars to handle binner shader output DCE

We were doing this late after nir_lower_io, but we can just reuse the core
code.  By doing it at this stage, we won't even set up the VS attributes
as inputs, reducing our VPM size.

---

 src/broadcom/compiler/v3d_nir_lower_io.c | 42 --------------------------------
 src/broadcom/compiler/vir.c              | 16 +++++++++---
 src/gallium/drivers/v3d/v3d_program.c    |  2 +-
 3 files changed, 14 insertions(+), 46 deletions(-)

diff --git a/src/broadcom/compiler/v3d_nir_lower_io.c b/src/broadcom/compiler/v3d_nir_lower_io.c
index 9cdcc02195..10bc25811a 100644
--- a/src/broadcom/compiler/v3d_nir_lower_io.c
+++ b/src/broadcom/compiler/v3d_nir_lower_io.c
@@ -52,44 +52,6 @@ replace_intrinsic_with_vec(nir_builder *b, nir_intrinsic_instr *intr,
 }
 
 static void
-v3d_nir_lower_output(struct v3d_compile *c, nir_builder *b,
-                     nir_intrinsic_instr *intr)
-{
-        nir_variable *output_var = NULL;
-        nir_foreach_variable(var, &c->s->outputs) {
-                if (var->data.driver_location == nir_intrinsic_base(intr)) {
-                        output_var = var;
-                        break;
-                }
-        }
-        assert(output_var);
-
-        if (c->vs_key) {
-                int slot = output_var->data.location;
-                bool used = false;
-
-                switch (slot) {
-                case VARYING_SLOT_PSIZ:
-                case VARYING_SLOT_POS:
-                        used = true;
-                        break;
-
-                default:
-                        for (int i = 0; i < c->vs_key->num_fs_inputs; i++) {
-                                if (v3d_slot_get_slot(c->vs_key->fs_inputs[i]) == slot) {
-                                        used = true;
-                                        break;
-                                }
-                        }
-                        break;
-                }
-
-                if (!used)
-                        nir_instr_remove(&intr->instr);
-        }
-}
-
-static void
 v3d_nir_lower_uniform(struct v3d_compile *c, nir_builder *b,
                       nir_intrinsic_instr *intr)
 {
@@ -135,10 +97,6 @@ v3d_nir_lower_io_instr(struct v3d_compile *c, nir_builder *b,
         case nir_intrinsic_load_input:
                 break;
 
-        case nir_intrinsic_store_output:
-                v3d_nir_lower_output(c, b, intr);
-                break;
-
         case nir_intrinsic_load_uniform:
                 v3d_nir_lower_uniform(c, b, intr);
                 break;
diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c
index faad654115..3f5a28d1be 100644
--- a/src/broadcom/compiler/vir.c
+++ b/src/broadcom/compiler/vir.c
@@ -719,13 +719,23 @@ uint64_t *v3d_compile_vs(const struct v3d_compiler *compiler,
 
         c->vs_key = key;
 
-        /* Split our input vars and dead code eliminate the unused
+        /* Split our I/O vars and dead code eliminate the unused
          * components.
          */
-        NIR_PASS_V(c->s, nir_lower_io_to_scalar_early, nir_var_shader_in);
+        NIR_PASS_V(c->s, nir_lower_io_to_scalar_early,
+                   nir_var_shader_in | nir_var_shader_out);
+        uint64_t used_outputs[4] = {0};
+        for (int i = 0; i < c->vs_key->num_fs_inputs; i++) {
+                int slot = v3d_slot_get_slot(c->vs_key->fs_inputs[i]);
+                int comp = v3d_slot_get_component(c->vs_key->fs_inputs[i]);
+                used_outputs[comp] |= 1ull << slot;
+        }
+        NIR_PASS_V(c->s, nir_remove_unused_io_vars,
+                   &c->s->outputs, used_outputs, NULL); /* demotes to globals */
+        NIR_PASS_V(c->s, nir_lower_global_vars_to_local);
         v3d_optimize_nir(c->s);
         NIR_PASS_V(c->s, nir_remove_dead_variables, nir_var_shader_in);
-        NIR_PASS_V(c->s, nir_lower_io, nir_var_shader_in,
+        NIR_PASS_V(c->s, nir_lower_io, nir_var_shader_in | nir_var_shader_out,
                    type_size_vec4,
                    (nir_lower_io_options)0);
 
diff --git a/src/gallium/drivers/v3d/v3d_program.c b/src/gallium/drivers/v3d/v3d_program.c
index 17ded7571c..1dceade950 100644
--- a/src/gallium/drivers/v3d/v3d_program.c
+++ b/src/gallium/drivers/v3d/v3d_program.c
@@ -212,7 +212,7 @@ v3d_shader_state_create(struct pipe_context *pctx,
 
         nir_variable_mode lower_mode = nir_var_all & ~nir_var_uniform;
         if (s->info.stage == MESA_SHADER_VERTEX)
-                lower_mode &= ~nir_var_shader_in;
+                lower_mode &= ~(nir_var_shader_in | nir_var_shader_out);
         NIR_PASS_V(s, nir_lower_io, lower_mode,
                    type_size,
                    (nir_lower_io_options)0);




More information about the mesa-commit mailing list