ilo: move aperture checks out of pipeline
authorChia-I Wu <olvaffe@gmail.com>
Mon, 22 Sep 2014 02:46:15 +0000 (10:46 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 22 Sep 2014 03:45:38 +0000 (11:45 +0800)
They can be done outside of the pipeline.  Move them and let the pipeline
focus on building commands.

src/gallium/drivers/ilo/ilo_3d.c
src/gallium/drivers/ilo/ilo_3d_pipeline.c
src/gallium/drivers/ilo/ilo_3d_pipeline.h

index 4bc70c67d8733dc386e3781714ac9ea061480d58..291ff1c102c9446fd89a356523dc8cec5c7d202c 100644 (file)
@@ -357,7 +357,7 @@ static bool
 draw_vbo(struct ilo_3d *hw3d, const struct ilo_state_vector *vec)
 {
    bool need_flush = false;
-   bool success;
+   bool success = true;
    int max_len, before_space;
 
    /* on GEN7+, we need SOL_RESET to reset the SO write offsets */
@@ -402,7 +402,30 @@ draw_vbo(struct ilo_3d *hw3d, const struct ilo_state_vector *vec)
 
    if (need_flush)
       ilo_3d_pipeline_emit_flush(hw3d->pipeline);
-   success = ilo_3d_pipeline_emit_draw(hw3d->pipeline, vec);
+
+   while (true) {
+      struct ilo_builder_snapshot snapshot;
+
+      ilo_builder_batch_snapshot(&hw3d->cp->builder, &snapshot);
+
+      ilo_3d_pipeline_emit_draw(hw3d->pipeline, vec);
+
+      if (!ilo_builder_validate(&hw3d->cp->builder, 0, NULL)) {
+         ilo_builder_batch_restore(&hw3d->cp->builder, &snapshot);
+
+         /* flush and try again */
+         if (ilo_builder_batch_used(&hw3d->cp->builder)) {
+            ilo_cp_submit(hw3d->cp, "out of aperture");
+            continue;
+         }
+
+         success = false;
+      }
+
+      break;
+   }
+
+   hw3d->pipeline->invalidate_flags = 0x0;
 
    /* sanity check size estimation */
    assert(before_space - ilo_cp_space(hw3d->cp) <= max_len);
@@ -442,8 +465,22 @@ ilo_3d_pass_render_condition(struct ilo_context *ilo)
 void
 ilo_3d_draw_rectlist(struct ilo_3d *hw3d, const struct ilo_blitter *blitter)
 {
+   int max_len, before_space;
+
    ilo_3d_own_render_ring(hw3d);
 
+   max_len = ilo_3d_pipeline_estimate_size(hw3d->pipeline,
+         ILO_3D_PIPELINE_RECTLIST, blitter);
+   max_len += ilo_3d_pipeline_estimate_size(hw3d->pipeline,
+         ILO_3D_PIPELINE_FLUSH, NULL) * 2;
+
+   if (max_len > ilo_cp_space(hw3d->cp)) {
+      ilo_cp_submit(hw3d->cp, "out of space");
+      assert(max_len <= ilo_cp_space(hw3d->cp));
+   }
+
+   before_space = ilo_cp_space(hw3d->cp);
+
    /*
     * From the Sandy Bridge PRM, volume 2 part 1, page 313:
     *
@@ -465,16 +502,37 @@ ilo_3d_draw_rectlist(struct ilo_3d *hw3d, const struct ilo_blitter *blitter)
     *  - we may sample from the fb shortly after
     *
     * Skip checking blitter->op and do the flushes.
-    *
-    * XXX need space check
     */
    if (!hw3d->new_batch)
       ilo_3d_pipeline_emit_flush(hw3d->pipeline);
 
-   ilo_3d_pipeline_emit_rectlist(hw3d->pipeline, blitter);
+   while (true) {
+      struct ilo_builder_snapshot snapshot;
+
+      ilo_builder_batch_snapshot(&hw3d->cp->builder, &snapshot);
+
+      ilo_3d_pipeline_emit_rectlist(hw3d->pipeline, blitter);
+
+      if (!ilo_builder_validate(&hw3d->cp->builder, 0, NULL)) {
+         ilo_builder_batch_restore(&hw3d->cp->builder, &snapshot);
+
+         /* flush and try again */
+         if (ilo_builder_batch_used(&hw3d->cp->builder)) {
+            ilo_cp_submit(hw3d->cp, "out of aperture");
+            continue;
+         }
+      }
+
+      break;
+   }
+
+   ilo_3d_pipeline_invalidate(hw3d->pipeline, ILO_3D_PIPELINE_INVALIDATE_HW);
 
    ilo_3d_pipeline_emit_flush(hw3d->pipeline);
 
+   /* sanity check size estimation */
+   assert(before_space - ilo_cp_space(hw3d->cp) <= max_len);
+
    hw3d->new_batch = false;
 }
 
index 298c2ec65b6d67dfba7bfa5132016aaf466026a9..cf7ce0bd680246506e62a6bd899edcff60836ae3 100644 (file)
@@ -148,44 +148,12 @@ handle_invalid_batch_bo(struct ilo_3d_pipeline *p, bool unset)
 /**
  * Emit context states and 3DPRIMITIVE.
  */
-bool
+void
 ilo_3d_pipeline_emit_draw(struct ilo_3d_pipeline *p,
                           const struct ilo_state_vector *vec)
 {
-   bool success;
-
-   while (true) {
-      struct ilo_builder_snapshot snapshot;
-
-      /* we will rewind if aperture check below fails */
-      ilo_builder_batch_snapshot(&p->cp->builder, &snapshot);
-
-      handle_invalid_batch_bo(p, false);
-
-      /* draw! */
-      p->emit_draw(p, vec);
-
-      if (ilo_builder_validate(&p->cp->builder, 0, NULL)) {
-         success = true;
-      } else {
-         /* rewind */
-         ilo_builder_batch_restore(&p->cp->builder, &snapshot);
-
-         /* flush and try again */
-         if (ilo_builder_batch_used(&p->cp->builder)) {
-            ilo_cp_submit(p->cp, "out of aperture");
-            continue;
-         }
-
-         success = false;
-      }
-
-      break;
-   }
-
-   p->invalidate_flags = 0x0;
-
-   return success;
+   handle_invalid_batch_bo(p, false);
+   p->emit_draw(p, vec);
 }
 
 /**
@@ -213,37 +181,8 @@ void
 ilo_3d_pipeline_emit_rectlist(struct ilo_3d_pipeline *p,
                               const struct ilo_blitter *blitter)
 {
-   const int max_len = ilo_3d_pipeline_estimate_size(p,
-         ILO_3D_PIPELINE_RECTLIST, blitter);
-
-   if (max_len > ilo_cp_space(p->cp))
-      ilo_cp_submit(p->cp, "out of space");
-
-   while (true) {
-      struct ilo_builder_snapshot snapshot;
-
-      /* we will rewind if aperture check below fails */
-      ilo_builder_batch_snapshot(&p->cp->builder, &snapshot);
-
-      handle_invalid_batch_bo(p, false);
-
-      p->emit_rectlist(p, blitter);
-
-      if (!ilo_builder_validate(&p->cp->builder, 0, NULL)) {
-         /* rewind */
-         ilo_builder_batch_restore(&p->cp->builder, &snapshot);
-
-         /* flush and try again */
-         if (ilo_builder_batch_used(&p->cp->builder)) {
-            ilo_cp_submit(p->cp, "out of aperture");
-            continue;
-         }
-      }
-
-      break;
-   }
-
-   ilo_3d_pipeline_invalidate(p, ILO_3D_PIPELINE_INVALIDATE_HW);
+   handle_invalid_batch_bo(p, false);
+   p->emit_rectlist(p, blitter);
 }
 
 void
index 802c965a8c44f0c74cd128a86ab7a325f827281e..8e074bcc4a051437ea290d684f41ffeb09c8119f 100644 (file)
@@ -159,7 +159,7 @@ ilo_3d_pipeline_estimate_size(struct ilo_3d_pipeline *pipeline,
    return pipeline->estimate_size(pipeline, action, arg);
 }
 
-bool
+void
 ilo_3d_pipeline_emit_draw(struct ilo_3d_pipeline *p,
                           const struct ilo_state_vector *vec);