panfrost: Add a panfrost_flush_batches_accessing_bo() helper
authorBoris Brezillon <boris.brezillon@collabora.com>
Sun, 15 Sep 2019 18:17:14 +0000 (20:17 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Thu, 3 Oct 2019 20:55:38 +0000 (16:55 -0400)
This will allow us to only flush batches touching a specific resource,
which is particularly useful when the CPU needs to access a BO.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/pan_job.c
src/gallium/drivers/panfrost/pan_job.h

index 3ccf4bb6b3e9d9b31d49e0b9625a2bcc8370a4d6..e7eae399830f92fa11b2aee0707e43de8258724c 100644 (file)
@@ -952,6 +952,37 @@ panfrost_flush_all_batches(struct panfrost_context *ctx, bool wait)
         util_dynarray_fini(&syncobjs);
 }
 
+void
+panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx,
+                                    struct panfrost_bo *bo,
+                                    uint32_t access_type)
+{
+        struct panfrost_bo_access *access;
+        struct hash_entry *hentry;
+
+        /* It doesn't make any to flush only the readers. */
+        assert(access_type == PAN_BO_ACCESS_WRITE ||
+               access_type == PAN_BO_ACCESS_RW);
+
+        hentry = _mesa_hash_table_search(ctx->accessed_bos, bo);
+        access = hentry ? hentry->data : NULL;
+        if (!access)
+                return;
+
+        if (access_type & PAN_BO_ACCESS_WRITE && access->writer &&
+            access->writer->batch)
+                panfrost_batch_submit(access->writer->batch);
+
+        if (!(access_type & PAN_BO_ACCESS_READ))
+                return;
+
+        util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *,
+                              reader) {
+                if (*reader && (*reader)->batch)
+                        panfrost_batch_submit((*reader)->batch);
+        }
+}
+
 void
 panfrost_batch_set_requirements(struct panfrost_batch *batch)
 {
index e95e156a40f89f852161ce9aec3b5e1a44ca96ef..25905b516739e139edafda01e13dd8a81c42ec4e 100644 (file)
@@ -185,6 +185,10 @@ panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
 void
 panfrost_flush_all_batches(struct panfrost_context *ctx, bool wait);
 
+void
+panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx,
+                                    struct panfrost_bo *bo, uint32_t flags);
+
 void
 panfrost_batch_set_requirements(struct panfrost_batch *batch);