freedreno: Add private-BO tracking
authorRob Clark <robdclark@chromium.org>
Mon, 2 Oct 2023 17:53:54 +0000 (10:53 -0700)
committerMarge Bot <emma+marge@anholt.net>
Tue, 3 Oct 2023 15:18:03 +0000 (15:18 +0000)
There are some internally used buffers that we should just attach to
every submit up-front.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25465>

src/gallium/drivers/freedreno/a6xx/fd6_context.cc
src/gallium/drivers/freedreno/a6xx/fd6_emit.cc
src/gallium/drivers/freedreno/a6xx/fd6_texture.cc
src/gallium/drivers/freedreno/freedreno_batch.c
src/gallium/drivers/freedreno/freedreno_context.c
src/gallium/drivers/freedreno/freedreno_context.h

index 0b217a0..300be5a 100644 (file)
@@ -308,6 +308,8 @@ fd6_context_create(struct pipe_screen *pscreen, void *priv,
    fd6_ctx->control_mem =
       fd_bo_new(screen->dev, 0x1000, 0, "control");
 
+   fd_context_add_private_bo(&fd6_ctx->base, fd6_ctx->control_mem);
+
    memset(fd_bo_map(fd6_ctx->control_mem), 0, sizeof(struct fd6_control));
 
    fd_context_setup_common_vbos(&fd6_ctx->base);
index cb3147e..bd639bd 100644 (file)
@@ -952,16 +952,13 @@ fd6_emit_restore(struct fd_batch *batch, struct fd_ringbuffer *ring)
 
    struct fd6_context *fd6_ctx = fd6_context(batch->ctx);
    struct fd_bo *bcolor_mem = fd6_ctx->bcolor_mem;
+
    OUT_PKT4(ring, REG_A6XX_SP_TP_BORDER_COLOR_BASE_ADDR, 2);
    OUT_RELOC(ring, bcolor_mem, 0, 0, 0);
 
    OUT_PKT4(ring, REG_A6XX_SP_PS_TP_BORDER_COLOR_BASE_ADDR, 2);
    OUT_RELOC(ring, bcolor_mem, 0, 0, 0);
 
-   fd_ringbuffer_attach_bo(ring, bcolor_mem);
-
-   fd_ringbuffer_attach_bo(ring, fd6_ctx->control_mem);
-
    if (!batch->nondraw) {
       trace_end_state_restore(&batch->trace, ring);
    }
index 72a1adf..d1b7880 100644 (file)
@@ -882,6 +882,8 @@ fd6_texture_init(struct pipe_context *pctx) disable_thread_safety_analysis
                                    FD6_MAX_BORDER_COLORS * FD6_BORDER_COLOR_SIZE,
                                    0, "bcolor");
 
+   fd_context_add_private_bo(ctx, fd6_ctx->bcolor_mem);
+
    fd6_ctx->tex_cache = _mesa_hash_table_create(NULL, tex_key_hash, tex_key_equals);
    util_idalloc_init(&fd6_ctx->tex_ids, 256);
 }
index d0e21a2..eff58cc 100644 (file)
@@ -119,6 +119,10 @@ fd_batch_create(struct fd_context *ctx, bool nondraw)
       }
    }
 
+   /* Pre-attach private BOs: */
+   for (unsigned i = 0; i < ctx->num_private_bos; i++)
+      fd_ringbuffer_attach_bo(batch->gmem, ctx->private_bos[i]);
+
    batch->subpass = subpass_create(batch);
 
    batch->in_fence_fd = -1;
index 36d8c92..e7f0981 100644 (file)
@@ -323,6 +323,13 @@ fd_context_switch_to(struct fd_context *ctx, struct fd_batch *batch)
    }
 }
 
+void
+fd_context_add_private_bo(struct fd_context *ctx, struct fd_bo *bo)
+{
+   assert(ctx->num_private_bos < ARRAY_SIZE(ctx->private_bos));
+   ctx->private_bos[ctx->num_private_bos++] = bo;
+}
+
 /**
  * Return a reference to the current batch, caller must unref.
  */
index e753b35..3dedfd3 100644 (file)
@@ -447,6 +447,14 @@ struct fd_context {
    /* Per vsc pipe bo's (a2xx-a5xx): */
    struct fd_bo *vsc_pipe_bo[32] dt;
 
+   /* Table of bo's attached to all batches up-front (because they
+    * are commonly used, and that is easier than attaching on-use).
+    * In particular, these are driver internal buffers which do not
+    * participate in batch resource tracking.
+    */
+   struct fd_bo *private_bos[3];
+   unsigned num_private_bos;
+
    /* Maps generic gallium oriented fd_dirty_3d_state bits to generation
     * specific bitmask of state "groups".
     */
@@ -671,6 +679,8 @@ fd_stream_output_target(struct pipe_stream_output_target *target)
    return (struct fd_stream_output_target *)target;
 }
 
+void fd_context_add_private_bo(struct fd_context *ctx, struct fd_bo *bo);
+
 /* Mark specified non-shader-stage related state as dirty: */
 static inline void
 fd_context_dirty(struct fd_context *ctx, BITMASK_ENUM(fd_dirty_3d_state) dirty)