Mesa (master): st/mesa: assign driver locations for VS inputs for NIR before caching

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Oct 24 01:15:11 UTC 2019


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

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Fri Oct 18 13:02:15 2019 -0400

st/mesa: assign driver locations for VS inputs for NIR before caching

fix up edge flags in the NIR pass, because st/mesa doesn't touch the inputs
after caching

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

---

 src/compiler/nir/nir_lower_passthrough_edgeflags.c |  5 +++++
 src/mesa/state_tracker/st_glsl_to_nir.cpp          | 15 ++++++---------
 src/mesa/state_tracker/st_nir.h                    |  1 +
 src/mesa/state_tracker/st_nir_builtins.c           |  1 +
 src/mesa/state_tracker/st_program.c                |  2 ++
 5 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/compiler/nir/nir_lower_passthrough_edgeflags.c b/src/compiler/nir/nir_lower_passthrough_edgeflags.c
index f34078c8999..0afcaa0b125 100644
--- a/src/compiler/nir/nir_lower_passthrough_edgeflags.c
+++ b/src/compiler/nir/nir_lower_passthrough_edgeflags.c
@@ -39,6 +39,11 @@ lower_impl(nir_function_impl *impl)
                              glsl_vec4_type(), "edgeflag_in");
    in->data.location = VERT_ATTRIB_EDGEFLAG;
 
+   /* The edge flag is the last input in st/mesa. */
+   assert(shader->num_inputs == util_bitcount64(shader->info.inputs_read));
+   in->data.driver_location = shader->num_inputs++;
+   shader->info.inputs_read |= BITFIELD64_BIT(VERT_ATTRIB_EDGEFLAG);
+
    out = nir_variable_create(shader, nir_var_shader_out,
                              glsl_vec4_type(), "edgeflag_out");
    out->data.location = VARYING_SLOT_EDGE;
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index 6ec14076b58..67d93d61f1c 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -83,9 +83,12 @@ st_nir_fixup_varying_slots(struct st_context *st, struct exec_list *var_list)
  * (This isn't the case with, for ex, FS inputs, which only need to agree
  * on varying-slot w/ the VS outputs)
  */
-static void
-st_nir_assign_vs_in_locations(nir_shader *nir)
+void
+st_nir_assign_vs_in_locations(struct nir_shader *nir)
 {
+   if (nir->info.stage != MESA_SHADER_VERTEX)
+      return;
+
    bool removed_inputs = false;
 
    nir->num_inputs = util_bitcount64(nir->info.inputs_read);
@@ -93,10 +96,7 @@ st_nir_assign_vs_in_locations(nir_shader *nir)
       /* NIR already assigns dual-slot inputs to two locations so all we have
        * to do is compact everything down.
        */
-      if (var->data.location == VERT_ATTRIB_EDGEFLAG) {
-         /* bit of a hack, mirroring st_translate_vertex_program */
-         var->data.driver_location = nir->num_inputs++;
-      } else if (nir->info.inputs_read & BITFIELD64_BIT(var->data.location)) {
+      if (nir->info.inputs_read & BITFIELD64_BIT(var->data.location)) {
          var->data.driver_location =
             util_bitcount64(nir->info.inputs_read &
                               BITFIELD64_MASK(var->data.location));
@@ -851,9 +851,6 @@ void
 st_nir_assign_varying_locations(struct st_context *st, nir_shader *nir)
 {
    if (nir->info.stage == MESA_SHADER_VERTEX) {
-      /* Needs special handling so drvloc matches the vbo state: */
-      st_nir_assign_vs_in_locations(nir);
-
       nir_assign_io_var_locations(&nir->outputs,
                                   &nir->num_outputs,
                                   nir->info.stage);
diff --git a/src/mesa/state_tracker/st_nir.h b/src/mesa/state_tracker/st_nir.h
index a46422413d9..21358419aa9 100644
--- a/src/mesa/state_tracker/st_nir.h
+++ b/src/mesa/state_tracker/st_nir.h
@@ -51,6 +51,7 @@ bool
 st_link_nir(struct gl_context *ctx,
             struct gl_shader_program *shader_program);
 
+void st_nir_assign_vs_in_locations(struct nir_shader *nir);
 void st_nir_assign_varying_locations(struct st_context *st,
                                      struct nir_shader *nir);
 
diff --git a/src/mesa/state_tracker/st_nir_builtins.c b/src/mesa/state_tracker/st_nir_builtins.c
index 7e52e5a8f11..b09d470bf3a 100644
--- a/src/mesa/state_tracker/st_nir_builtins.c
+++ b/src/mesa/state_tracker/st_nir_builtins.c
@@ -56,6 +56,7 @@ st_nir_finish_builtin_shader(struct st_context *st,
 
    nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
 
+   st_nir_assign_vs_in_locations(nir);
    st_nir_assign_varying_locations(st, nir);
 
    st_nir_lower_samplers(screen, nir, NULL, NULL);
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index e60a9924f81..21252492fc5 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -400,6 +400,8 @@ st_finalize_nir_before_variants(struct nir_shader *nir)
    } else if (nir->info.stage == MESA_SHADER_FRAGMENT) {
       NIR_PASS_V(nir, nir_lower_io_arrays_to_elements_no_indirects, true);
    }
+
+   st_nir_assign_vs_in_locations(nir);
 }
 
 /**




More information about the mesa-commit mailing list