intel: Add a batch flush between front-buffer downsample and X protocol.
[mesa.git] / src / mesa / drivers / dri / i965 / gen6_sol.c
index 07316c869a93ce622d9877101c687b01561b4e8f..5c294b1d768e31dfe5c4cd2451f2e5f24783f154 100644 (file)
 #include "intel_batchbuffer.h"
 #include "brw_defines.h"
 #include "brw_state.h"
+#include "main/transformfeedback.h"
 
 static void
 gen6_update_sol_surfaces(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->intel.ctx;
-   /* _NEW_TRANSFORM_FEEDBACK */
+   struct gl_context *ctx = &brw->ctx;
+   /* BRW_NEW_TRANSFORM_FEEDBACK */
    struct gl_transform_feedback_object *xfb_obj =
       ctx->TransformFeedback.CurrentObject;
    /* BRW_NEW_VERTEX_PROGRAM */
@@ -48,7 +49,7 @@ gen6_update_sol_surfaces(struct brw_context *brw)
 
    for (i = 0; i < BRW_MAX_SOL_BINDINGS; ++i) {
       const int surf_index = SURF_INDEX_SOL_BINDING(i);
-      if (xfb_obj->Active && !xfb_obj->Paused &&
+      if (_mesa_is_xfb_active_and_unpaused(ctx) &&
           i < linked_xfb_info->NumOutputs) {
          unsigned buffer = linked_xfb_info->Outputs[i].OutputBuffer;
          unsigned buffer_offset =
@@ -68,9 +69,10 @@ gen6_update_sol_surfaces(struct brw_context *brw)
 
 const struct brw_tracked_state gen6_sol_surface = {
    .dirty = {
-      .mesa = _NEW_TRANSFORM_FEEDBACK,
+      .mesa = 0,
       .brw = (BRW_NEW_BATCH |
-              BRW_NEW_VERTEX_PROGRAM),
+              BRW_NEW_VERTEX_PROGRAM |
+              BRW_NEW_TRANSFORM_FEEDBACK),
       .cache = 0
    },
    .emit = gen6_update_sol_surfaces,
@@ -83,7 +85,7 @@ const struct brw_tracked_state gen6_sol_surface = {
 static void
 brw_gs_upload_binding_table(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->intel.ctx;
+   struct gl_context *ctx = &brw->ctx;
    /* BRW_NEW_VERTEX_PROGRAM */
    const struct gl_shader_program *shaderprog =
       ctx->Shader.CurrentVertexProgram;
@@ -130,29 +132,6 @@ const struct brw_tracked_state gen6_gs_binding_table = {
    .emit = brw_gs_upload_binding_table,
 };
 
-static void
-gen6_update_sol_indices(struct brw_context *brw)
-{
-   struct intel_context *intel = &brw->intel;
-
-   BEGIN_BATCH(4);
-   OUT_BATCH(_3DSTATE_GS_SVB_INDEX << 16 | (4 - 2));
-   OUT_BATCH(0);
-   OUT_BATCH(brw->sol.svbi_0_starting_index); /* BRW_NEW_SOL_INDICES */
-   OUT_BATCH(brw->sol.svbi_0_max_index); /* BRW_NEW_SOL_INDICES */
-   ADVANCE_BATCH();
-}
-
-const struct brw_tracked_state gen6_sol_indices = {
-   .dirty = {
-      .mesa = 0,
-      .brw = (BRW_NEW_BATCH |
-              BRW_NEW_SOL_INDICES),
-      .cache = 0
-   },
-   .emit = gen6_update_sol_indices,
-};
-
 void
 brw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
                             struct gl_transform_feedback_object *obj)
@@ -165,29 +144,35 @@ brw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
    struct gl_transform_feedback_object *xfb_obj =
       ctx->TransformFeedback.CurrentObject;
 
-   unsigned max_index = 0xffffffff;
+   assert(brw->gen == 6);
 
    /* Compute the maximum number of vertices that we can write without
     * overflowing any of the buffers currently being used for feedback.
     */
-   for (int i = 0; i < BRW_MAX_SOL_BUFFERS; ++i) {
-      unsigned stride = linked_xfb_info->BufferStride[i];
-
-      /* Skip any inactive buffers, which have a stride of 0. */
-      if (stride == 0)
-        continue;
+   unsigned max_index
+      = _mesa_compute_max_transform_feedback_vertices(xfb_obj,
+                                                      linked_xfb_info);
 
-      unsigned max_for_this_buffer = xfb_obj->Size[i] / (4 * stride);
-      max_index = MIN2(max_index, max_for_this_buffer);
-   }
+   /* Initialize the SVBI 0 register to zero and set the maximum index. */
+   BEGIN_BATCH(4);
+   OUT_BATCH(_3DSTATE_GS_SVB_INDEX << 16 | (4 - 2));
+   OUT_BATCH(0); /* SVBI 0 */
+   OUT_BATCH(0); /* starting index */
+   OUT_BATCH(max_index);
+   ADVANCE_BATCH();
 
-   /* Initialize the SVBI 0 register to zero and set the maximum index.
-    * These values will be sent to the hardware on the next draw.
+   /* Initialize the rest of the unused streams to sane values.  Otherwise,
+    * they may indicate that there is no room to write data and prevent
+    * anything from happening at all.
     */
-   brw->state.dirty.brw |= BRW_NEW_SOL_INDICES;
-   brw->sol.svbi_0_starting_index = 0;
-   brw->sol.svbi_0_max_index = max_index;
-   brw->sol.offset_0_batch_start = 0;
+   for (int i = 1; i < 4; i++) {
+      BEGIN_BATCH(4);
+      OUT_BATCH(_3DSTATE_GS_SVB_INDEX << 16 | (4 - 2));
+      OUT_BATCH(i << SVB_INDEX_SHIFT);
+      OUT_BATCH(0); /* starting index */
+      OUT_BATCH(0xffffffff);
+      ADVANCE_BATCH();
+   }
 }
 
 void
@@ -201,6 +186,5 @@ brw_end_transform_feedback(struct gl_context *ctx,
     * simplicity, just do a full flush.
     */
    struct brw_context *brw = brw_context(ctx);
-   struct intel_context *intel = &brw->intel;
-   intel_batchbuffer_emit_mi_flush(intel);
+   intel_batchbuffer_emit_mi_flush(brw);
 }