Mesa (master): st/nir: Trim out unused VS input variables.

Eric Anholt anholt at kemper.freedesktop.org
Mon Aug 22 19:11:32 UTC 2016


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

Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 19 17:12:12 2016 -0700

st/nir: Trim out unused VS input variables.

If we're going to skip setting up vertex input data in them, we should
probably not leave them as vertex inputs with a driver_location that
happens to alias to something else.

Fixes a regression in glsl-mat-attribute on vc4 when enabling GTN.

v2: Change commit message shortlog, lower the new globals away before
    handing off to the driver.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/mesa/state_tracker/st_glsl_to_nir.cpp | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index 73a692a..be2d5b2 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -73,8 +73,7 @@ st_nir_fixup_varying_slots(struct st_context *st, struct exec_list *var_list)
  * on varying-slot w/ the VS outputs)
  */
 static void
-st_nir_assign_vs_in_locations(struct gl_program *prog,
-                              struct exec_list *var_list, unsigned *size)
+st_nir_assign_vs_in_locations(struct gl_program *prog, nir_shader *nir)
 {
    unsigned attr, num_inputs = 0;
    unsigned input_to_index[VERT_ATTRIB_MAX] = {0};
@@ -88,15 +87,29 @@ st_nir_assign_vs_in_locations(struct gl_program *prog,
             /* add placeholder for second part of a double attribute */
             num_inputs++;
          }
+      } else {
+         input_to_index[attr] = ~0;
       }
    }
 
-   *size = 0;
-   nir_foreach_variable(var, var_list) {
+   nir->num_inputs = 0;
+   nir_foreach_variable_safe(var, &nir->inputs) {
       attr = var->data.location;
       assert(attr < ARRAY_SIZE(input_to_index));
-      var->data.driver_location = input_to_index[attr];
-      (*size)++;
+
+      if (input_to_index[attr] != ~0u) {
+         var->data.driver_location = input_to_index[attr];
+         nir->num_inputs++;
+      } else {
+         /* Move unused input variables to the globals list (with no
+          * initialization), to avoid confusing drivers looking through the
+          * inputs array and expecting to find inputs with a driver_location
+          * set.
+          */
+         exec_node_remove(&var->node);
+         var->data.mode = nir_var_global;
+         exec_list_push_tail(&nir->globals, &var->node);
+      }
    }
 }
 
@@ -304,7 +317,10 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog, nir_shader *nir)
 
    if (nir->stage == MESA_SHADER_VERTEX) {
       /* Needs special handling so drvloc matches the vbo state: */
-      st_nir_assign_vs_in_locations(prog, &nir->inputs, &nir->num_inputs);
+      st_nir_assign_vs_in_locations(prog, nir);
+      /* Re-lower global vars, to deal with any dead VS inputs. */
+      NIR_PASS_V(nir, nir_lower_global_vars_to_local);
+
       sort_varyings(&nir->outputs);
       nir_assign_var_locations(&nir->outputs,
                                &nir->num_outputs,




More information about the mesa-commit mailing list