Mesa (master): panfrost: Copy resources when mapping to avoid waiting for readers

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jun 22 12:28:54 UTC 2020


Module: Mesa
Branch: master
Commit: 361fb38662f80e645e9087781faa4bec10dd6ac7
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=361fb38662f80e645e9087781faa4bec10dd6ac7

Author: Icecream95 <ixn at keemail.me>
Date:   Sat Jun 20 19:30:54 2020 +1200

panfrost: Copy resources when mapping to avoid waiting for readers

It is often faster to copy the whole resource and modify that than
to flush and wait for readers of the BO.

Helps anything which updates textures after already using them in a
frame, such as most GLQuake ports.

Reviewed-by: Tomeu Vizoso <tomeu.vizoso at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5573>

---

 src/gallium/drivers/panfrost/pan_resource.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index 8c1cda9513d..9d1905d6c71 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -597,7 +597,26 @@ panfrost_transfer_map(struct pipe_context *pctx,
         if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC))
                 pandecode_inject_mmap(bo->gpu, bo->cpu, bo->size, NULL);
 
-        if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
+        bool create_new_bo = usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
+        bool copy_resource = false;
+
+        if (!create_new_bo &&
+            !(usage & PIPE_TRANSFER_UNSYNCHRONIZED) &&
+            (usage & PIPE_TRANSFER_WRITE) &&
+            !(resource->target == PIPE_BUFFER
+              && !util_ranges_intersect(&rsrc->valid_buffer_range, box->x, box->x + box->width))) {
+
+                /* It is often faster to copy the whole resource than to flush
+                 * readers */
+
+                panfrost_flush_batches_accessing_bo(ctx, bo, PAN_BO_ACCESS_WRITE);
+                panfrost_bo_wait(bo, INT64_MAX, PAN_BO_ACCESS_WRITE);
+
+                create_new_bo = true;
+                copy_resource = true;
+        }
+
+        if (create_new_bo) {
                 /* If the BO is used by one of the pending batches or if it's
                  * not ready yet (still accessed by one of the already flushed
                  * batches), we try to allocate a new one to avoid waiting.
@@ -619,6 +638,9 @@ panfrost_transfer_map(struct pipe_context *pctx,
                                                            flags);
 
                         if (newbo) {
+                                if (copy_resource)
+                                        memcpy(newbo->cpu, rsrc->bo->cpu, bo->size);
+
                                 panfrost_bo_unreference(bo);
                                 rsrc->bo = newbo;
                                 bo = newbo;



More information about the mesa-commit mailing list