asahi: Add compute batches
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Fri, 3 Feb 2023 20:24:05 +0000 (15:24 -0500)
committerMarge Bot <emma+marge@anholt.net>
Sat, 4 Feb 2023 17:10:15 +0000 (17:10 +0000)
Add a specialized agx_batch for compute commands (queued to the CDM instead of
the VDM for graphics). This uses a sentinel value for the width.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21062>

src/gallium/drivers/asahi/agx_batch.c
src/gallium/drivers/asahi/agx_state.h

index 01eaf0e..40374b7 100644 (file)
@@ -76,7 +76,8 @@ agx_batch_init(struct agx_context *ctx,
    unsigned batch_idx = agx_batch_idx(batch);
    BITSET_SET(ctx->batches.active, batch_idx);
 
-   agx_batch_init_state(batch);
+   if (key->width != AGX_COMPUTE_BATCH_WIDTH)
+      agx_batch_init_state(batch);
 }
 
 void
@@ -172,6 +173,16 @@ agx_get_batch(struct agx_context *ctx)
    return ctx->batch;
 }
 
+struct agx_batch *
+agx_get_compute_batch(struct agx_context *ctx)
+{
+   agx_dirty_all(ctx);
+
+   struct pipe_framebuffer_state key = {.width = AGX_COMPUTE_BATCH_WIDTH};
+   ctx->batch = agx_get_batch_for_framebuffer(ctx, &key);
+   return ctx->batch;
+}
+
 void
 agx_flush_all(struct agx_context *ctx, const char *reason)
 {
index 9c8b14f..3d728ea 100644 (file)
@@ -551,7 +551,15 @@ void agx_batch_writes(struct agx_batch *batch, struct agx_resource *rsrc);
 bool agx_any_batch_uses_resource(struct agx_context *ctx,
                                  struct agx_resource *rsrc);
 
+/* 16384 is the maximum framebuffer dimension, so we use a larger width (the
+ * maximum uint16_t) as a sentinel to identify the compute batch. This ensures
+ * compute batches don't mix with graphics. This is a bit of a hack but it
+ * works.
+ */
+#define AGX_COMPUTE_BATCH_WIDTH 0xFFFF
+
 struct agx_batch *agx_get_batch(struct agx_context *ctx);
+struct agx_batch *agx_get_compute_batch(struct agx_context *ctx);
 void agx_batch_cleanup(struct agx_context *ctx, struct agx_batch *batch);
 
 /* Blit shaders */