st/mesa: assign driver locations for VS inputs for NIR before caching
authorMarek Olšák <marek.olsak@amd.com>
Fri, 18 Oct 2019 17:02:15 +0000 (13:02 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 24 Oct 2019 01:12:52 +0000 (21:12 -0400)
fix up edge flags in the NIR pass, because st/mesa doesn't touch the inputs
after caching

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir_lower_passthrough_edgeflags.c
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_nir.h
src/mesa/state_tracker/st_nir_builtins.c
src/mesa/state_tracker/st_program.c

index f34078c89999d72bbb0e6df931c59b7f1eb86aeb..0afcaa0b1256b88ed2d4fdfa2682c2d5fb24852d 100644 (file)
@@ -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;
index 6ec14076b582cf4c9c163eea8444fc2e6f3a0ac4..67d93d61f1c713ed2c88676f031a577ae6228d3d 100644 (file)
@@ -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);
index a46422413d9fd985a6531a76d3e0e852047ee2f7..21358419aa93a894d3d5568184a2716319a55996 100644 (file)
@@ -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);
 
index 7e52e5a8f114ddfbba700332b32acbb65c0cd230..b09d470bf3a18c6b2a32f77af85f04c6108fa23d 100644 (file)
@@ -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);
index e60a9924f81a7b49f3dbdf771678b77d1d201916..21252492fc519a699d3a955e87723ddb2c1ede85 100644 (file)
@@ -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);
 }
 
 /**