iris: Put batches in an array
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 20 Nov 2018 17:00:22 +0000 (09:00 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 21 Feb 2019 18:26:10 +0000 (10:26 -0800)
We keep re-making this array all over the place

13 files changed:
src/gallium/drivers/iris/iris_batch.c
src/gallium/drivers/iris/iris_batch.h
src/gallium/drivers/iris/iris_blit.c
src/gallium/drivers/iris/iris_border_color.c
src/gallium/drivers/iris/iris_clear.c
src/gallium/drivers/iris/iris_context.c
src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_draw.c
src/gallium/drivers/iris/iris_fence.c
src/gallium/drivers/iris/iris_pipe_control.c
src/gallium/drivers/iris/iris_query.c
src/gallium/drivers/iris/iris_resource.c
src/gallium/drivers/iris/iris_state.c

index cc346ca0029c7370b7b938ca2c2627fec62343b1..b9fa6d6dc2d475a0d2dff598f6a96e72b32b0a0e 100644 (file)
@@ -166,8 +166,8 @@ iris_init_batch(struct iris_batch *batch,
                 struct iris_screen *screen,
                 struct iris_vtable *vtbl,
                 struct pipe_debug_callback *dbg,
-                struct iris_batch **all_batches,
-                const char *name,
+                struct iris_batch *all_batches,
+                enum iris_batch_name name,
                 uint8_t engine)
 {
    batch->screen = screen;
@@ -201,8 +201,8 @@ iris_init_batch(struct iris_batch *batch,
    memset(batch->other_batches, 0, sizeof(batch->other_batches));
 
    for (int i = 0, j = 0; i < IRIS_BATCH_COUNT; i++) {
-      if (all_batches[i] != batch)
-         batch->other_batches[j++] = all_batches[i];
+      if (&all_batches[i] != batch)
+         batch->other_batches[j++] = &all_batches[i];
    }
 
    if (unlikely(INTEL_DEBUG)) {
@@ -520,6 +520,16 @@ submit_batch(struct iris_batch *batch)
    return ret;
 }
 
+static const char *
+batch_name_to_string(enum iris_batch_name name)
+{
+   const char *names[IRIS_BATCH_COUNT] = {
+      [IRIS_BATCH_RENDER]  = "render",
+      [IRIS_BATCH_COMPUTE] = "compute",
+   };
+   return names[name];
+}
+
 /**
  * Flush the batch buffer, submitting it to the GPU and resetting it so
  * we're ready to emit the next batch.
@@ -549,7 +559,7 @@ _iris_batch_flush(struct iris_batch *batch, const char *file, int line)
       }
       fprintf(stderr, "%19s:%-3d: %s batch [%u] flush with %5d+%5db (%0.1f%%) "
               "(cmds), %4d BOs (%0.1fMb aperture)\n",
-              file, line, batch->name, batch->hw_ctx_id,
+              file, line, batch_name_to_string(batch->name), batch->hw_ctx_id,
               batch->primary_batch_size, second_bytes,
               100.0f * bytes_for_commands / BATCH_SZ,
               batch->exec_count,
index cf119dd326a7a96bf0d2bcccf4fb0d557b8b0698..32434e807496606bc5f2663fe71d977fca2ec8e5 100644 (file)
 /* Our target batch size - flush approximately at this point. */
 #define BATCH_SZ (20 * 1024)
 
+enum iris_batch_name {
+   IRIS_BATCH_RENDER,
+   IRIS_BATCH_COMPUTE,
+};
+
 #define IRIS_BATCH_COUNT 2
 
 struct iris_address {
@@ -52,8 +57,8 @@ struct iris_batch {
    struct iris_vtable *vtbl;
    struct pipe_debug_callback *dbg;
 
-   /** The name of this batch for debug info (e.g. "render") */
-   const char *name;
+   /** What batch is this? (e.g. IRIS_BATCH_RENDER/COMPUTE) */
+   enum iris_batch_name name;
 
    /** Current batchbuffer being queued up. */
    struct iris_bo *bo;
@@ -126,8 +131,8 @@ void iris_init_batch(struct iris_batch *batch,
                      struct iris_screen *screen,
                      struct iris_vtable *vtbl,
                      struct pipe_debug_callback *dbg,
-                     struct iris_batch **other_batches,
-                     const char *name,
+                     struct iris_batch *all_batches,
+                     enum iris_batch_name name,
                      uint8_t ring);
 void iris_chain_to_new_batch(struct iris_batch *batch);
 void iris_batch_free(struct iris_batch *batch);
index 241fce2660b4ce429b643b52b5776209a60428f0..96fb8fc276886e9127d94fd648c0b2dc9ac478eb 100644 (file)
@@ -335,7 +335,7 @@ iris_blit(struct pipe_context *ctx, const struct pipe_blit_info *info)
       filter = BLORP_FILTER_NEAREST;
    }
 
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
 
    struct blorp_batch blorp_batch;
    blorp_batch_init(&ice->blorp, &blorp_batch, batch, 0);
@@ -406,7 +406,7 @@ iris_resource_copy_region(struct pipe_context *ctx,
 
    assert(src_box->depth == 1);
 
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
 
    iris_batch_maybe_flush(batch, 1500);
 
index 753513b94d26a2a420afa63cd675c36360a14e0d..72c7ee4904c7a695c0b03d78489de9e1be05eaea 100644 (file)
@@ -106,10 +106,10 @@ iris_border_color_pool_reserve(struct iris_context *ice, unsigned count)
 
    if (remaining_entries < count) {
       /* It's safe to flush because we're called outside of state upload. */
-      if (iris_batch_references(&ice->render_batch, pool->bo))
-         iris_batch_flush(&ice->render_batch);
-      if (iris_batch_references(&ice->compute_batch, pool->bo))
-         iris_batch_flush(&ice->compute_batch);
+      for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
+         if (iris_batch_references(&ice->batches[i], pool->bo))
+            iris_batch_flush(&ice->batches[i]);
+      }
 
       iris_reset_border_color_pool(pool, pool->bo->bufmgr);
    }
index 3b16bbb13b3b8e2032d705c1ef6caef64eef4d9c..c9c47afcaa6f2bfe5f37d48f7cafce8fe7a549ae 100644 (file)
@@ -51,7 +51,7 @@ iris_clear(struct pipe_context *ctx,
    struct pipe_framebuffer_state *cso_fb = &ice->state.framebuffer;
    assert(buffers != 0);
 
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
 
    iris_batch_maybe_flush(batch, 1500);
 
@@ -124,7 +124,7 @@ iris_clear_texture(struct pipe_context *ctx,
    struct iris_context *ice = (void *) ctx;
    struct iris_resource *res = (void *) p_res;
 
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
    const struct gen_device_info *devinfo = &batch->screen->devinfo;
 
    iris_batch_maybe_flush(batch, 1500);
index efcdf128e710123951d7c5cff096e13424c9aeef..75b1be273066904e237147e3c267c13640a03f0a 100644 (file)
@@ -115,8 +115,8 @@ iris_destroy_context(struct pipe_context *ctx)
 
    slab_destroy_child(&ice->transfer_pool);
 
-   iris_batch_free(&ice->render_batch);
-   iris_batch_free(&ice->compute_batch);
+   iris_batch_free(&ice->batches[IRIS_BATCH_RENDER]);
+   iris_batch_free(&ice->batches[IRIS_BATCH_COMPUTE]);
    iris_destroy_binder(&ice->state.binder);
 
    ralloc_free(ice);
@@ -194,21 +194,16 @@ iris_create_context(struct pipe_screen *pscreen, void *priv, unsigned flags)
    genX_call(devinfo, init_state, ice);
    genX_call(devinfo, init_blorp, ice);
 
-   struct iris_batch *batches[IRIS_BATCH_COUNT] = {
-      &ice->render_batch,
-      &ice->compute_batch,
-   };
-   const char *batch_names[IRIS_BATCH_COUNT] = { "render", "compute", };
-
    for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
-      iris_init_batch(batches[i], screen, &ice->vtbl, &ice->dbg,
-                      batches, batch_names[i], I915_EXEC_RENDER);
+      iris_init_batch(&ice->batches[i], screen, &ice->vtbl, &ice->dbg,
+                      ice->batches, (enum iris_batch_name) i,
+                      I915_EXEC_RENDER);
    }
 
-   ice->vtbl.init_render_context(screen, &ice->render_batch, &ice->vtbl,
-                                 &ice->dbg);
-   ice->vtbl.init_compute_context(screen, &ice->compute_batch, &ice->vtbl,
-                                  &ice->dbg);
+   ice->vtbl.init_render_context(screen, &ice->batches[IRIS_BATCH_RENDER],
+                                 &ice->vtbl, &ice->dbg);
+   ice->vtbl.init_compute_context(screen, &ice->batches[IRIS_BATCH_COMPUTE],
+                                  &ice->vtbl, &ice->dbg);
 
    return ctx;
 }
index 21d333276b3148a29d3d6f63d61d4fe9ef7dcdcb..3eb50238b0cf5ba8868c6c0e7680732b178c4a91 100644 (file)
@@ -388,11 +388,7 @@ struct iris_context {
 
    struct blorp_context blorp;
 
-   /** The main batch for rendering. */
-   struct iris_batch render_batch;
-
-   /** The batch for compute shader dispatch */
-   struct iris_batch compute_batch;
+   struct iris_batch batches[IRIS_BATCH_COUNT];
 
    struct {
       struct iris_uncompiled_shader *uncompiled[MESA_SHADER_STAGES];
index 9139f894473d559cdecbcd645b6738e2606b936b..cf9d3c638330b9a97a7255f4806c8eb3b8bc11ad 100644 (file)
@@ -68,7 +68,7 @@ void
 iris_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
 {
    struct iris_context *ice = (struct iris_context *) ctx;
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
 
    if (unlikely(INTEL_DEBUG & DEBUG_REEMIT))
       ice->state.dirty |= ~0ull;
@@ -146,7 +146,7 @@ void
 iris_launch_grid(struct pipe_context *ctx, const struct pipe_grid_info *grid)
 {
    struct iris_context *ice = (struct iris_context *) ctx;
-   struct iris_batch *batch = &ice->compute_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_COMPUTE];
 
    if (unlikely(INTEL_DEBUG & DEBUG_REEMIT))
       ice->state.dirty |= ~0ull;
index 2ab11b80697bfa4f87a31e3da32e81864bd7737e..f14f329cc4db2a4b02d76b927be4fa16c2380903 100644 (file)
@@ -160,14 +160,10 @@ iris_fence_flush(struct pipe_context *ctx,
 {
    struct iris_screen *screen = (void *) ctx->screen;
    struct iris_context *ice = (struct iris_context *)ctx;
-   struct iris_batch *batch[IRIS_BATCH_COUNT] = {
-      &ice->render_batch,
-      &ice->compute_batch,
-   };
 
    /* XXX PIPE_FLUSH_DEFERRED */
-   for (unsigned i = 0; i < ARRAY_SIZE(batch); i++)
-      iris_batch_flush(batch[i]);
+   for (unsigned i = 0; i < IRIS_BATCH_COUNT; i++)
+      iris_batch_flush(&ice->batches[i]);
 
    if (!out_fence)
       return;
@@ -178,12 +174,12 @@ iris_fence_flush(struct pipe_context *ctx,
 
    pipe_reference_init(&fence->ref, 1);
 
-   for (unsigned b = 0; b < ARRAY_SIZE(batch); b++) {
-      if (!check_syncpt(ctx->screen, batch[b]->last_syncpt))
+   for (unsigned b = 0; b < IRIS_BATCH_COUNT; b++) {
+      if (!check_syncpt(ctx->screen, ice->batches[b].last_syncpt))
          continue;
 
       iris_syncpt_reference(screen, &fence->syncpt[fence->count++],
-                            batch[b]->last_syncpt);
+                            ice->batches[b].last_syncpt);
    }
    *out_fence = fence;
 }
@@ -193,13 +189,10 @@ iris_fence_await(struct pipe_context *ctx,
                  struct pipe_fence_handle *fence)
 {
    struct iris_context *ice = (struct iris_context *)ctx;
-   struct iris_batch *batch[IRIS_BATCH_COUNT] = {
-      &ice->render_batch,
-      &ice->compute_batch,
-   };
-   for (unsigned b = 0; b < ARRAY_SIZE(batch); b++) {
+
+   for (unsigned b = 0; b < IRIS_BATCH_COUNT; b++) {
       for (unsigned i = 0; i < fence->count; i++) {
-         iris_batch_add_syncpt(batch[b], fence->syncpt[i],
+         iris_batch_add_syncpt(&ice->batches[b], fence->syncpt[i],
                                I915_EXEC_FENCE_WAIT);
       }
    }
index 3face134def69aab75ed571c16bcc4f24e41916d..5e5a996e40b189cf4df0a781aa8301b9185953ae 100644 (file)
@@ -150,19 +150,19 @@ iris_texture_barrier(struct pipe_context *ctx, unsigned flags)
 {
    struct iris_context *ice = (void *) ctx;
 
-   if (ice->render_batch.contains_draw) {
-      iris_emit_pipe_control_flush(&ice->render_batch,
+   if (ice->batches[IRIS_BATCH_RENDER].contains_draw) {
+      iris_emit_pipe_control_flush(&ice->batches[IRIS_BATCH_RENDER],
                                    PIPE_CONTROL_DEPTH_CACHE_FLUSH |
                                    PIPE_CONTROL_RENDER_TARGET_FLUSH |
                                    PIPE_CONTROL_CS_STALL);
-      iris_emit_pipe_control_flush(&ice->render_batch,
+      iris_emit_pipe_control_flush(&ice->batches[IRIS_BATCH_RENDER],
                                    PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE);
    }
 
-   if (ice->compute_batch.contains_draw) {
-      iris_emit_pipe_control_flush(&ice->compute_batch,
+   if (ice->batches[IRIS_BATCH_COMPUTE].contains_draw) {
+      iris_emit_pipe_control_flush(&ice->batches[IRIS_BATCH_COMPUTE],
                                    PIPE_CONTROL_CS_STALL);
-      iris_emit_pipe_control_flush(&ice->compute_batch,
+      iris_emit_pipe_control_flush(&ice->batches[IRIS_BATCH_COMPUTE],
                                    PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE);
    }
 }
@@ -198,10 +198,10 @@ iris_memory_barrier(struct pipe_context *ctx, unsigned flags)
    // XXX: don't unconditionally emit flushes in both engines, we don't
    // even know if we're even using e.g. the compute engine...
 
-   if (ice->render_batch.contains_draw)
-      iris_emit_pipe_control_flush(&ice->render_batch, bits);
-   if (ice->compute_batch.contains_draw)
-      iris_emit_pipe_control_flush(&ice->compute_batch, bits);
+   for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
+      if (ice->batches[i].contains_draw)
+         iris_emit_pipe_control_flush(&ice->batches[i], bits);
+   }
 }
 
 void
index a0df8c6504d1fea80a58ad7b3ca4c5085183916e..145fb5c7416cdffcb723c8a2adbc5545c93f0071 100644 (file)
@@ -129,7 +129,7 @@ iris_is_query_pipelined(struct iris_query *q)
 static void
 mark_available(struct iris_context *ice, struct iris_query *q)
 {
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
    unsigned flags = PIPE_CONTROL_WRITE_IMMEDIATE;
    unsigned offset = offsetof(struct iris_query_snapshots, snapshots_landed);
 
@@ -162,7 +162,7 @@ iris_pipelined_write(struct iris_batch *batch,
 static void
 write_value(struct iris_context *ice, struct iris_query *q, unsigned offset)
 {
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
    const struct gen_device_info *devinfo = &batch->screen->devinfo;
 
    if (!iris_is_query_pipelined(q)) {
@@ -182,7 +182,7 @@ write_value(struct iris_context *ice, struct iris_query *q, unsigned offset)
           */
          iris_emit_pipe_control_flush(batch, PIPE_CONTROL_DEPTH_STALL);
       }
-      iris_pipelined_write(&ice->render_batch, q,
+      iris_pipelined_write(&ice->batches[IRIS_BATCH_RENDER], q,
                            PIPE_CONTROL_WRITE_DEPTH_COUNT |
                            PIPE_CONTROL_DEPTH_STALL,
                            offset);
@@ -190,7 +190,7 @@ write_value(struct iris_context *ice, struct iris_query *q, unsigned offset)
    case PIPE_QUERY_TIME_ELAPSED:
    case PIPE_QUERY_TIMESTAMP:
    case PIPE_QUERY_TIMESTAMP_DISJOINT:
-      iris_pipelined_write(&ice->render_batch, q,
+      iris_pipelined_write(&ice->batches[IRIS_BATCH_RENDER], q,
                            PIPE_CONTROL_WRITE_TIMESTAMP,
                            offset);
       break;
@@ -284,7 +284,7 @@ calculate_result_on_cpu(const struct gen_device_info *devinfo,
 static void
 gpr0_to_bool(struct iris_context *ice)
 {
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
 
    ice->vtbl.load_register_imm64(batch, CS_GPR(1), 1ull);
 
@@ -308,7 +308,7 @@ gpr0_to_bool(struct iris_context *ice)
 static void
 calculate_result_on_gpu(struct iris_context *ice, struct iris_query *q)
 {
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
 
    ice->vtbl.load_register_mem64(batch, CS_GPR(1), q->bo,
                                  offsetof(struct iris_query_snapshots, start));
@@ -417,8 +417,8 @@ iris_get_query_result(struct pipe_context *ctx,
    const struct gen_device_info *devinfo = &screen->devinfo;
 
    if (!q->ready) {
-      if (iris_batch_references(&ice->render_batch, q->bo))
-         iris_batch_flush(&ice->render_batch);
+      if (iris_batch_references(&ice->batches[IRIS_BATCH_RENDER], q->bo))
+         iris_batch_flush(&ice->batches[IRIS_BATCH_RENDER]);
 
       if (!q->map->snapshots_landed) {
          if (wait)
@@ -487,7 +487,7 @@ iris_get_query_result_resource(struct pipe_context *ctx,
 {
    struct iris_context *ice = (void *) ctx;
    struct iris_query *q = (void *) query;
-   struct iris_batch *batch = &ice->render_batch;
+   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
    const struct gen_device_info *devinfo = &batch->screen->devinfo;
    unsigned snapshots_landed_offset =
       offsetof(struct iris_query_snapshots, snapshots_landed);
index 0ea72a9075b6432f826c3ad82c8d831a37eed507..de0456258cb0f04308746015e36592dc789eae6a 100644 (file)
@@ -813,14 +813,11 @@ iris_transfer_map(struct pipe_context *ctx,
        (usage & PIPE_TRANSFER_MAP_DIRECTLY))
       return NULL;
 
-   if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED) &&
-       iris_batch_references(&ice->render_batch, res->bo)) {
-      iris_batch_flush(&ice->render_batch);
-   }
-
-   if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED) &&
-       iris_batch_references(&ice->compute_batch, res->bo)) {
-      iris_batch_flush(&ice->compute_batch);
+   if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
+      for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
+         if (iris_batch_references(&ice->batches[i], res->bo))
+            iris_batch_flush(&ice->batches[i]);
+      }
    }
 
    if ((usage & PIPE_TRANSFER_DONTBLOCK) && iris_bo_busy(res->bo))
index a21fcc17dca28e3d10dadcc8db5fe532d0efcc4d..1d34ef285473b2d35c2002801055c94201ab4d78 100644 (file)
@@ -2123,7 +2123,7 @@ iris_set_framebuffer_state(struct pipe_context *ctx,
     *    be set in this packet."
     */
    // XXX: does this need to happen at 3DSTATE_BTP_PS time?
-   iris_emit_pipe_control_flush(&ice->render_batch,
+   iris_emit_pipe_control_flush(&ice->batches[IRIS_BATCH_RENDER],
                                 PIPE_CONTROL_RENDER_TARGET_FLUSH |
                                 PIPE_CONTROL_STALL_AT_SCOREBOARD);
 #endif