Mesa (main): freedreno: Make a bunch of the batch cache take ctx as the arg.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 15 20:59:33 UTC 2021


Module: Mesa
Branch: main
Commit: 32bed95e0b17f8d94d04847e6d0d6f1603187475
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=32bed95e0b17f8d94d04847e6d0d6f1603187475

Author: Emma Anholt <emma at anholt.net>
Date:   Mon Jun 14 11:48:14 2021 -0700

freedreno: Make a bunch of the batch cache take ctx as the arg.

As we move the batch cache from screen to context, it cleans up the diff a
ton to separate this mechanical change out, and makes the API generally
more consistent (since you usually have to pass the ctx anyway).

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11368>

---

 src/gallium/drivers/freedreno/a5xx/fd5_blitter.c   |  2 +-
 src/gallium/drivers/freedreno/a6xx/fd6_blitter.c   |  2 +-
 .../drivers/freedreno/freedreno_batch_cache.c      | 33 +++++++++++-----------
 .../drivers/freedreno/freedreno_batch_cache.h      | 13 ++++-----
 src/gallium/drivers/freedreno/freedreno_context.c  | 16 +++++------
 src/gallium/drivers/freedreno/freedreno_draw.c     |  2 +-
 6 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_blitter.c b/src/gallium/drivers/freedreno/a5xx/fd5_blitter.c
index 9c837a5a01b..1b82a6993ad 100644
--- a/src/gallium/drivers/freedreno/a5xx/fd5_blitter.c
+++ b/src/gallium/drivers/freedreno/a5xx/fd5_blitter.c
@@ -441,7 +441,7 @@ fd5_blitter_blit(struct fd_context *ctx,
       return false;
    }
 
-   batch = fd_bc_alloc_batch(&ctx->screen->batch_cache, ctx, true);
+   batch = fd_bc_alloc_batch(ctx, true);
 
    fd_batch_update_queries(batch);
 
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c b/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
index e0af9b3d9dd..f9fffbf54d4 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
@@ -912,7 +912,7 @@ handle_rgba_blit(struct fd_context *ctx,
    fd6_validate_format(ctx, src, info->src.format);
    fd6_validate_format(ctx, dst, info->dst.format);
 
-   batch = fd_bc_alloc_batch(&ctx->screen->batch_cache, ctx, true);
+   batch = fd_bc_alloc_batch(ctx, true);
 
    fd_screen_lock(ctx->screen);
 
diff --git a/src/gallium/drivers/freedreno/freedreno_batch_cache.c b/src/gallium/drivers/freedreno/freedreno_batch_cache.c
index 3fb6b04f155..e6fe83ff35c 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch_cache.c
+++ b/src/gallium/drivers/freedreno/freedreno_batch_cache.c
@@ -142,9 +142,10 @@ fd_bc_fini(struct fd_batch_cache *cache)
 }
 
 static void
-bc_flush(struct fd_batch_cache *cache, struct fd_context *ctx,
-         bool deferred) assert_dt
+bc_flush(struct fd_context *ctx, bool deferred) assert_dt
 {
+   struct fd_batch_cache *cache = &ctx->screen->batch_cache;
+
    /* fd_batch_flush() (and fd_batch_add_dep() which calls it indirectly)
     * can cause batches to be unref'd and freed under our feet, so grab
     * a reference to all the batches we need up-front.
@@ -188,9 +189,9 @@ bc_flush(struct fd_batch_cache *cache, struct fd_context *ctx,
 }
 
 void
-fd_bc_flush(struct fd_batch_cache *cache, struct fd_context *ctx)
+fd_bc_flush(struct fd_context *ctx)
 {
-   bc_flush(cache, ctx, false);
+   bc_flush(ctx, false);
 }
 
 /* deferred flush doesn't actually flush, but it marks every other
@@ -199,20 +200,20 @@ fd_bc_flush(struct fd_batch_cache *cache, struct fd_context *ctx)
  * that came before also get flushed.
  */
 void
-fd_bc_flush_deferred(struct fd_batch_cache *cache, struct fd_context *ctx)
+fd_bc_flush_deferred(struct fd_context *ctx)
 {
-   bc_flush(cache, ctx, true);
+   bc_flush(ctx, true);
 }
 
 void
-fd_bc_dump(struct fd_screen *screen, const char *fmt, ...)
+fd_bc_dump(struct fd_context *ctx, const char *fmt, ...)
 {
-   struct fd_batch_cache *cache = &screen->batch_cache;
+   struct fd_batch_cache *cache = &ctx->screen->batch_cache;
 
    if (!FD_DBG(MSGS))
       return;
 
-   fd_screen_lock(screen);
+   fd_screen_lock(ctx->screen);
 
    va_list ap;
    va_start(ap, fmt);
@@ -229,7 +230,7 @@ fd_bc_dump(struct fd_screen *screen, const char *fmt, ...)
 
    printf("----\n");
 
-   fd_screen_unlock(screen);
+   fd_screen_unlock(ctx->screen);
 }
 
 void
@@ -393,9 +394,9 @@ alloc_batch_locked(struct fd_batch_cache *cache, struct fd_context *ctx,
 }
 
 struct fd_batch *
-fd_bc_alloc_batch(struct fd_batch_cache *cache, struct fd_context *ctx,
-                  bool nondraw)
+fd_bc_alloc_batch(struct fd_context *ctx, bool nondraw)
 {
+   struct fd_batch_cache *cache = &ctx->screen->batch_cache;
    struct fd_batch *batch;
 
    /* For normal draw batches, pctx->set_framebuffer_state() handles
@@ -416,9 +417,9 @@ fd_bc_alloc_batch(struct fd_batch_cache *cache, struct fd_context *ctx,
 }
 
 static struct fd_batch *
-batch_from_key(struct fd_batch_cache *cache, struct fd_batch_key *key,
-               struct fd_context *ctx) assert_dt
+batch_from_key(struct fd_context *ctx, struct fd_batch_key *key) assert_dt
 {
+   struct fd_batch_cache *cache = &ctx->screen->batch_cache;
    struct fd_batch *batch = NULL;
    uint32_t hash = fd_batch_key_hash(key);
    struct hash_entry *entry =
@@ -479,7 +480,7 @@ key_surf(struct fd_batch_key *key, unsigned idx, unsigned pos,
 }
 
 struct fd_batch *
-fd_batch_from_fb(struct fd_batch_cache *cache, struct fd_context *ctx,
+fd_batch_from_fb(struct fd_context *ctx,
                  const struct pipe_framebuffer_state *pfb)
 {
    unsigned idx = 0, n = pfb->nr_cbufs + (pfb->zsbuf ? 1 : 0);
@@ -501,7 +502,7 @@ fd_batch_from_fb(struct fd_batch_cache *cache, struct fd_context *ctx,
    key->num_surfs = idx;
 
    fd_screen_lock(ctx->screen);
-   struct fd_batch *batch = batch_from_key(cache, key, ctx);
+   struct fd_batch *batch = batch_from_key(ctx, key);
    fd_screen_unlock(ctx->screen);
 
    return batch;
diff --git a/src/gallium/drivers/freedreno/freedreno_batch_cache.h b/src/gallium/drivers/freedreno/freedreno_batch_cache.h
index 0c555670c35..277616cf677 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch_cache.h
+++ b/src/gallium/drivers/freedreno/freedreno_batch_cache.h
@@ -66,22 +66,19 @@ struct fd_batch_cache {
 void fd_bc_init(struct fd_batch_cache *cache);
 void fd_bc_fini(struct fd_batch_cache *cache);
 
-void fd_bc_flush(struct fd_batch_cache *cache,
-                 struct fd_context *ctx) assert_dt;
-void fd_bc_flush_deferred(struct fd_batch_cache *cache,
-                          struct fd_context *ctx) assert_dt;
-void fd_bc_dump(struct fd_screen *screen, const char *fmt, ...)
+void fd_bc_flush(struct fd_context *ctx) assert_dt;
+void fd_bc_flush_deferred(struct fd_context *ctx) assert_dt;
+void fd_bc_dump(struct fd_context *ctx, const char *fmt, ...)
    _util_printf_format(2, 3);
 
 void fd_bc_invalidate_context(struct fd_context *ctx);
 void fd_bc_invalidate_batch(struct fd_batch *batch, bool destroy);
 void fd_bc_invalidate_resource(struct fd_resource *rsc, bool destroy);
-struct fd_batch *fd_bc_alloc_batch(struct fd_batch_cache *cache,
-                                   struct fd_context *ctx,
+struct fd_batch *fd_bc_alloc_batch(struct fd_context *ctx,
                                    bool nondraw) assert_dt;
 
 struct fd_batch *
-fd_batch_from_fb(struct fd_batch_cache *cache, struct fd_context *ctx,
+fd_batch_from_fb(struct fd_context *ctx,
                  const struct pipe_framebuffer_state *pfb) assert_dt;
 
 #endif /* FREEDRENO_BATCH_CACHE_H_ */
diff --git a/src/gallium/drivers/freedreno/freedreno_context.c b/src/gallium/drivers/freedreno/freedreno_context.c
index 1bb72758493..70d0558cecd 100644
--- a/src/gallium/drivers/freedreno/freedreno_context.c
+++ b/src/gallium/drivers/freedreno/freedreno_context.c
@@ -57,7 +57,7 @@ fd_context_flush(struct pipe_context *pctx, struct pipe_fence_handle **fencep,
    if (fencep && !batch) {
       batch = fd_context_batch(ctx);
    } else if (!batch) {
-      fd_bc_dump(ctx->screen, "%p: NULL batch, remaining:\n", ctx);
+      fd_bc_dump(ctx, "%p: NULL batch, remaining:\n", ctx);
       return;
    }
 
@@ -83,7 +83,7 @@ fd_context_flush(struct pipe_context *pctx, struct pipe_fence_handle **fencep,
       if (ctx->last_fence) {
          fd_fence_repopulate(*fencep, ctx->last_fence);
          fd_fence_ref(&fence, *fencep);
-         fd_bc_dump(ctx->screen, "%p: (deferred) reuse last_fence, remaining:\n", ctx);
+         fd_bc_dump(ctx, "%p: (deferred) reuse last_fence, remaining:\n", ctx);
          goto out;
       }
 
@@ -109,7 +109,7 @@ fd_context_flush(struct pipe_context *pctx, struct pipe_fence_handle **fencep,
     */
    if (ctx->last_fence) {
       fd_fence_ref(&fence, ctx->last_fence);
-      fd_bc_dump(ctx->screen, "%p: reuse last_fence, remaining:\n", ctx);
+      fd_bc_dump(ctx, "%p: reuse last_fence, remaining:\n", ctx);
       goto out;
    }
 
@@ -119,7 +119,7 @@ fd_context_flush(struct pipe_context *pctx, struct pipe_fence_handle **fencep,
    if (flags & PIPE_FLUSH_FENCE_FD)
       fence->submit_fence.use_fence_fd = true;
 
-   fd_bc_dump(ctx->screen, "%p: flushing %p<%u>, flags=0x%x, pending:\n", ctx,
+   fd_bc_dump(ctx, "%p: flushing %p<%u>, flags=0x%x, pending:\n", ctx,
               batch, batch->seqno, flags);
 
    /* If we get here, we need to flush for a fence, even if there is
@@ -130,12 +130,12 @@ fd_context_flush(struct pipe_context *pctx, struct pipe_fence_handle **fencep,
    if (!ctx->screen->reorder) {
       fd_batch_flush(batch);
    } else if (flags & PIPE_FLUSH_DEFERRED) {
-      fd_bc_flush_deferred(&ctx->screen->batch_cache, ctx);
+      fd_bc_flush_deferred(ctx);
    } else {
-      fd_bc_flush(&ctx->screen->batch_cache, ctx);
+      fd_bc_flush(ctx);
    }
 
-   fd_bc_dump(ctx->screen, "%p: remaining:\n", ctx);
+   fd_bc_dump(ctx, "%p: remaining:\n", ctx);
 
 out:
    if (fencep)
@@ -297,7 +297,7 @@ fd_context_batch(struct fd_context *ctx)
 
    if (unlikely(!batch)) {
       batch =
-         fd_batch_from_fb(&ctx->screen->batch_cache, ctx, &ctx->framebuffer);
+         fd_batch_from_fb(ctx, &ctx->framebuffer);
       util_copy_framebuffer_state(&batch->framebuffer, &ctx->framebuffer);
       fd_batch_reference(&ctx->batch, batch);
       fd_context_all_dirty(ctx);
diff --git a/src/gallium/drivers/freedreno/freedreno_draw.c b/src/gallium/drivers/freedreno/freedreno_draw.c
index ab40b3ac609..4b8c33b0679 100644
--- a/src/gallium/drivers/freedreno/freedreno_draw.c
+++ b/src/gallium/drivers/freedreno/freedreno_draw.c
@@ -536,7 +536,7 @@ fd_launch_grid(struct pipe_context *pctx,
       &ctx->shaderbuf[PIPE_SHADER_COMPUTE];
    struct fd_batch *batch, *save_batch = NULL;
 
-   batch = fd_bc_alloc_batch(&ctx->screen->batch_cache, ctx, true);
+   batch = fd_bc_alloc_batch(ctx, true);
    fd_batch_reference(&save_batch, ctx->batch);
    fd_batch_reference(&ctx->batch, batch);
    fd_context_all_dirty(ctx);



More information about the mesa-commit mailing list