i965: Fix primitive restart on Haswell.
authorKenneth Graunke <kenneth@whitecape.org>
Sat, 25 Aug 2012 01:40:40 +0000 (18:40 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 6 Sep 2012 23:39:48 +0000 (16:39 -0700)
Haswell moved the "Cut Index Enable" bit from the INDEX_BUFFER packet to
a new 3DSTATE_VF packet, so we need to emit that.  Also, it requires us
to specify the cut index rather than assuming it's 0xffffffff.

This adds a new Haswell-specific tracked state atom to gen7_atoms.
Normally, we would create a new generation-specific atom list, but since
there's only one difference over Ivybridge so far, I chose to simply
make it return without doing any work on non-Haswell systems.

Fixes five piglit tests:
- general/primitive-restart-DISABLE_VBO
- general/primitive-restart-VBO_COMBINED_VERTEX_AND_INDEX
- general/primitive-restart-VBO_INDEX_ONLY
- general/primitive-restart-VBO_SEPARATE_VERTEX_AND_INDEX
- general/primitive-restart-VBO_VERTEX_ONLY

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
src/mesa/drivers/dri/i965/brw_defines.h
src/mesa/drivers/dri/i965/brw_draw_upload.c
src/mesa/drivers/dri/i965/brw_primitive_restart.c
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_state_upload.c

index 3605c188d37a02e3fee90f0198ebe2f3482a2c80..6dc470768a2fa42fed33d0ccce481db07409563d 100644 (file)
@@ -1037,6 +1037,9 @@ enum brw_message_target {
 # define GEN6_URB_GS_ENTRIES_SHIFT                     8
 # define GEN6_URB_GS_SIZE_SHIFT                                0
 
+#define _3DSTATE_VF                             0x780c /* GEN7.5+ */
+#define HSW_CUT_INDEX_ENABLE                            (1 << 8)
+
 #define _3DSTATE_URB_VS                         0x7830 /* GEN7+ */
 #define _3DSTATE_URB_HS                         0x7831 /* GEN7+ */
 #define _3DSTATE_URB_DS                         0x7832 /* GEN7+ */
index e40c7d555deda6f90211e3f32b43a8a6010cc593..33cce8fdf3ab2deec2243991b0e0f4af656b6d39 100644 (file)
@@ -930,7 +930,7 @@ static void brw_emit_index_buffer(struct brw_context *brw)
    if (index_buffer == NULL)
       return;
 
-   if (brw->prim_restart.enable_cut_index) {
+   if (brw->prim_restart.enable_cut_index && !intel->is_haswell) {
       cut_index_setting = BRW_CUT_INDEX_ENABLE;
    } else {
       cut_index_setting = 0;
index 02deba4fbb60c5b100b59a0ba26443395093d927..38b52438c097d93cbb1e550b2e981ad00874d349 100644 (file)
 #include "main/bufferobj.h"
 
 #include "brw_context.h"
+#include "brw_defines.h"
 #include "brw_draw.h"
 
+#include "intel_batchbuffer.h"
+
 /**
  * Check if the hardware's cut index support can handle the primitive
  * restart index value.
@@ -39,6 +42,12 @@ static bool
 can_cut_index_handle_restart_index(struct gl_context *ctx,
                                    const struct _mesa_index_buffer *ib)
 {
+   struct intel_context *intel = intel_context(ctx);
+
+   /* Haswell supports an arbitrary cut index. */
+   if (intel->is_haswell)
+      return true;
+
    bool cut_index_will_work;
 
    switch (ib->type) {
@@ -176,3 +185,30 @@ brw_handle_primitive_restart(struct gl_context *ctx,
    return GL_TRUE;
 }
 
+static void
+haswell_upload_cut_index(struct brw_context *brw)
+{
+   struct intel_context *intel = &brw->intel;
+   struct gl_context *ctx = &intel->ctx;
+
+   /* Don't trigger on Ivybridge */
+   if (!intel->is_haswell)
+      return;
+
+   const unsigned cut_index_setting =
+      ctx->Array.PrimitiveRestart ? HSW_CUT_INDEX_ENABLE : 0;
+
+   BEGIN_BATCH(2);
+   OUT_BATCH(_3DSTATE_VF << 16 | cut_index_setting | (2 - 2));
+   OUT_BATCH(ctx->Array.RestartIndex);
+   ADVANCE_BATCH();
+}
+
+const struct brw_tracked_state haswell_cut_index = {
+   .dirty = {
+      .mesa  = _NEW_TRANSFORM,
+      .brw   = 0,
+      .cache = 0,
+   },
+   .emit = haswell_upload_cut_index,
+};
index a80ee865a9e4a222b450ae3200ae176df3149e7d..99fa088a90f865df82d05525601e3c0855f4e9dc 100644 (file)
@@ -133,6 +133,7 @@ extern const struct brw_tracked_state gen7_wm_constants;
 extern const struct brw_tracked_state gen7_wm_constant_surface;
 extern const struct brw_tracked_state gen7_wm_state;
 extern const struct brw_tracked_state gen7_wm_surfaces;
+extern const struct brw_tracked_state haswell_cut_index;
 
 /* brw_misc_state.c */
 uint32_t
index 7291988c8a4c6016fbe455dc678d4040717b7835..ec0f765635b7d3c69e373c903b35bcf4085652ea 100644 (file)
@@ -246,6 +246,8 @@ const struct brw_tracked_state *gen7_atoms[] =
    &brw_indices,
    &brw_index_buffer,
    &brw_vertices,
+
+   &haswell_cut_index,
 };