[Mesa-dev] [PATCH 09/14] i965/gen8: Expose emission for system generated values

Topi Pohjolainen topi.pohjolainen at intel.com
Thu Feb 25 09:46:14 UTC 2016


Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 src/mesa/drivers/dri/i965/brw_draw.h         |   6 ++
 src/mesa/drivers/dri/i965/gen8_draw_upload.c | 101 +++++++++++++++------------
 2 files changed, 63 insertions(+), 44 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_draw.h b/src/mesa/drivers/dri/i965/brw_draw.h
index 56445d1..3fba3ff 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.h
+++ b/src/mesa/drivers/dri/i965/brw_draw.h
@@ -62,4 +62,10 @@ brw_handle_primitive_restart(struct gl_context *ctx,
                              const struct _mesa_index_buffer *ib,
                              struct gl_buffer_object *indirect);
 
+/* gen8_draw_upload.c */
+
+void gen8_emit_system_gen_values(struct brw_context *brw,
+                                 bool uses_vertexid, bool uses_instanceid,
+                                 unsigned nr_vb_enabled, bool uses_edge_flag);
+
 #endif
diff --git a/src/mesa/drivers/dri/i965/gen8_draw_upload.c b/src/mesa/drivers/dri/i965/gen8_draw_upload.c
index ff89e5f..ee34b06 100644
--- a/src/mesa/drivers/dri/i965/gen8_draw_upload.c
+++ b/src/mesa/drivers/dri/i965/gen8_draw_upload.c
@@ -34,6 +34,59 @@
 #include "intel_batchbuffer.h"
 #include "intel_buffer_objects.h"
 
+void
+gen8_emit_system_gen_values(struct brw_context *brw,
+                            bool uses_vertexid, bool uses_instanceid,
+                            unsigned nr_vb_enabled, bool uses_edge_flag)
+{
+   if (!uses_vertexid && !uses_instanceid) {
+      BEGIN_BATCH(2);
+      OUT_BATCH(_3DSTATE_VF_SGVS << 16 | (2 - 2));
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+      return;
+   }
+
+   struct gl_context *ctx = &brw->ctx;
+   unsigned vue = nr_vb_enabled;
+
+   /* The element for the edge flags must always be last, so we have to
+    * insert the SGVS before it in that case.
+    */
+   if (uses_edge_flag) {
+      assert(vue > 0);
+      vue--;
+   }
+
+   WARN_ONCE(vue >= 33,
+             "Trying to insert VID/IID past 33rd vertex element, "
+             "need to reorder the vertex attrbutes.");
+
+   unsigned dw1 = 0;
+   if (uses_vertexid) {
+      dw1 |= GEN8_SGVS_ENABLE_VERTEX_ID |
+             (2 << GEN8_SGVS_VERTEX_ID_COMPONENT_SHIFT) |  /* .z channel */
+             (vue << GEN8_SGVS_VERTEX_ID_ELEMENT_OFFSET_SHIFT);
+   }
+
+   if (uses_instanceid) {
+      dw1 |= GEN8_SGVS_ENABLE_INSTANCE_ID |
+             (3 << GEN8_SGVS_INSTANCE_ID_COMPONENT_SHIFT) | /* .w channel */
+             (vue << GEN8_SGVS_INSTANCE_ID_ELEMENT_OFFSET_SHIFT);
+   }
+
+   BEGIN_BATCH(2);
+   OUT_BATCH(_3DSTATE_VF_SGVS << 16 | (2 - 2));
+   OUT_BATCH(dw1);
+   ADVANCE_BATCH();
+
+   BEGIN_BATCH(3);
+   OUT_BATCH(_3DSTATE_VF_INSTANCING << 16 | (3 - 2));
+   OUT_BATCH(vue | GEN8_VF_INSTANCING_ENABLE);
+   OUT_BATCH(0);
+   ADVANCE_BATCH();
+}
+
 static void
 gen8_emit_vertices(struct brw_context *brw)
 {
@@ -47,50 +100,10 @@ gen8_emit_vertices(struct brw_context *brw)
    uses_edge_flag = (ctx->Polygon.FrontMode != GL_FILL ||
                      ctx->Polygon.BackMode != GL_FILL);
 
-   if (brw->vs.prog_data->uses_vertexid || brw->vs.prog_data->uses_instanceid) {
-      unsigned vue = brw->vb.nr_enabled;
-
-      /* The element for the edge flags must always be last, so we have to
-       * insert the SGVS before it in that case.
-       */
-      if (uses_edge_flag) {
-         assert(vue > 0);
-         vue--;
-      }
-
-      WARN_ONCE(vue >= 33,
-                "Trying to insert VID/IID past 33rd vertex element, "
-                "need to reorder the vertex attrbutes.");
-
-      unsigned dw1 = 0;
-      if (brw->vs.prog_data->uses_vertexid) {
-         dw1 |= GEN8_SGVS_ENABLE_VERTEX_ID |
-                (2 << GEN8_SGVS_VERTEX_ID_COMPONENT_SHIFT) |  /* .z channel */
-                (vue << GEN8_SGVS_VERTEX_ID_ELEMENT_OFFSET_SHIFT);
-      }
-
-      if (brw->vs.prog_data->uses_instanceid) {
-         dw1 |= GEN8_SGVS_ENABLE_INSTANCE_ID |
-                (3 << GEN8_SGVS_INSTANCE_ID_COMPONENT_SHIFT) | /* .w channel */
-                (vue << GEN8_SGVS_INSTANCE_ID_ELEMENT_OFFSET_SHIFT);
-      }
-
-      BEGIN_BATCH(2);
-      OUT_BATCH(_3DSTATE_VF_SGVS << 16 | (2 - 2));
-      OUT_BATCH(dw1);
-      ADVANCE_BATCH();
-
-      BEGIN_BATCH(3);
-      OUT_BATCH(_3DSTATE_VF_INSTANCING << 16 | (3 - 2));
-      OUT_BATCH(vue | GEN8_VF_INSTANCING_ENABLE);
-      OUT_BATCH(0);
-      ADVANCE_BATCH();
-   } else {
-      BEGIN_BATCH(2);
-      OUT_BATCH(_3DSTATE_VF_SGVS << 16 | (2 - 2));
-      OUT_BATCH(0);
-      ADVANCE_BATCH();
-   }
+   gen8_emit_system_gen_values(brw,
+                               brw->vs.prog_data->uses_vertexid,
+                               brw->vs.prog_data->uses_instanceid,
+                               brw->vb.nr_enabled, uses_edge_flag);
 
    /* If the VS doesn't read any inputs (calculating vertex position from
     * a state variable for some reason, for example), emit a single pad
-- 
2.5.0



More information about the mesa-dev mailing list