iris: Rework edgeflag handling
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 23 Oct 2019 22:38:52 +0000 (15:38 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 23 Oct 2019 23:38:27 +0000 (16:38 -0700)
We were relying on specific pass ordering in st to avoid setting
inputs_read/outputs_written for edge flags.  Instead, just assume
that it happens and throw out the results we don't want.

We should probably revisit this and try and add a vertex element
property like I originally wanted so we can avoid having it be
associated with the VS altogether.

src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_program.c

index 74a66f4a5cf18f95ad4609ac40f85965bc91068d..6833d360fb112c7606613e0632900bef7b8dbfc5 100644 (file)
@@ -281,6 +281,8 @@ struct iris_uncompiled_shader {
    /** Should we use ALT mode for math?  Useful for ARB programs. */
    bool use_alt_mode;
 
+   bool needs_edge_flag;
+
    /** Constant data scraped from the shader by nir_opt_large_constants */
    struct pipe_resource *const_data;
 
index 6f2b320bb44c3f7da0156e626f072670a237a83f..2189825231f669bef57de0d6dbeea4cbb7918b66 100644 (file)
@@ -185,6 +185,28 @@ iris_lower_storage_image_derefs(nir_shader *nir)
 
 // XXX: need unify_interfaces() at link time...
 
+/**
+ * Undo nir_lower_passthrough_edgeflags but keep the inputs_read flag.
+ */
+static bool
+iris_fix_edge_flags(nir_shader *nir)
+{
+   if (nir->info.stage != MESA_SHADER_VERTEX)
+      return false;
+
+   nir_foreach_variable(var, &nir->outputs) {
+      if (var->data.location == VARYING_SLOT_EDGE) {
+         var->data.mode = nir_var_shader_temp;
+         nir->info.outputs_written &= ~VARYING_BIT_EDGE;
+         nir->info.inputs_read &= ~VERT_BIT_EDGEFLAG;
+         nir_fixup_deref_modes(nir);
+         return true;
+      }
+   }
+
+   return false;
+}
+
 /**
  * Fix an uncompiled shader's stream output info.
  *
@@ -1042,22 +1064,17 @@ iris_update_compiled_vs(struct iris_context *ice)
       const bool needs_sgvs_element = uses_draw_params ||
                                       vs_prog_data->uses_instanceid ||
                                       vs_prog_data->uses_vertexid;
-      bool needs_edge_flag = false;
-      nir_foreach_variable(var, &ish->nir->inputs) {
-         if (var->data.location == VERT_ATTRIB_EDGEFLAG)
-            needs_edge_flag = true;
-      }
 
       if (ice->state.vs_uses_draw_params != uses_draw_params ||
           ice->state.vs_uses_derived_draw_params != uses_derived_draw_params ||
-          ice->state.vs_needs_edge_flag != needs_edge_flag) {
+          ice->state.vs_needs_edge_flag != ish->needs_edge_flag) {
          ice->state.dirty |= IRIS_DIRTY_VERTEX_BUFFERS |
                              IRIS_DIRTY_VERTEX_ELEMENTS;
       }
       ice->state.vs_uses_draw_params = uses_draw_params;
       ice->state.vs_uses_derived_draw_params = uses_derived_draw_params;
       ice->state.vs_needs_sgvs_element = needs_sgvs_element;
-      ice->state.vs_needs_edge_flag = needs_edge_flag;
+      ice->state.vs_needs_edge_flag = ish->needs_edge_flag;
    }
 }
 
@@ -1992,6 +2009,8 @@ iris_create_uncompiled_shader(struct pipe_context *ctx,
    if (!ish)
       return NULL;
 
+   ish->needs_edge_flag = iris_fix_edge_flags(nir);
+
    brw_preprocess_nir(screen->compiler, nir, NULL);
 
    NIR_PASS_V(nir, brw_nir_lower_image_load_store, devinfo);