Mesa (master): zink: handle PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE in transfer_map for buffers

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Feb 23 04:01:54 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Sun Sep  6 11:57:06 2020 -0400

zink: handle PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE in transfer_map for buffers

when discarding the whole resource on an unused resource, we can deinit the buffer
range here

in the future, ideally we should be doing something like creating a new vk buffer/image
entirely here and demoting the existing one to a queue that destroys/caches it when
the batch finishes in order to avoid fencing

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9146>

---

 src/gallium/drivers/zink/zink_resource.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index a7f11ed7c23..7930a281518 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -568,21 +568,25 @@ zink_transfer_map(struct pipe_context *pctx,
 
    void *ptr;
    if (pres->target == PIPE_BUFFER) {
-      if (!(usage & PIPE_MAP_UNSYNCHRONIZED) && util_ranges_intersect(&res->valid_buffer_range, box->x, box->x + box->width)) {
-         /* special case compute reads since they aren't handled by zink_fence_wait() */
-         if (usage & PIPE_MAP_WRITE && (batch_uses & (ZINK_RESOURCE_ACCESS_READ << ZINK_COMPUTE_BATCH_ID)))
-            zink_wait_on_batch(ctx, ZINK_COMPUTE_BATCH_ID);
-         batch_uses &= ~(ZINK_RESOURCE_ACCESS_READ << ZINK_COMPUTE_BATCH_ID);
-         if (usage & PIPE_MAP_READ && batch_uses >= ZINK_RESOURCE_ACCESS_WRITE)
-            resource_sync_writes_from_batch_id(ctx, batch_uses, zink_curr_batch(ctx)->batch_id);
-         else if (usage & PIPE_MAP_WRITE && batch_uses) {
-            /* need to wait for all rendering to finish
-             * TODO: optimize/fix this to be much less obtrusive
-             * mesa/mesa#2966
-             */
+      if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) {
+         if (util_ranges_intersect(&res->valid_buffer_range, box->x, box->x + box->width)) {
+            /* special case compute reads since they aren't handled by zink_fence_wait() */
+            if (usage & PIPE_MAP_WRITE && (batch_uses & (ZINK_RESOURCE_ACCESS_READ << ZINK_COMPUTE_BATCH_ID)))
+               zink_wait_on_batch(ctx, ZINK_COMPUTE_BATCH_ID);
+            batch_uses &= ~(ZINK_RESOURCE_ACCESS_READ << ZINK_COMPUTE_BATCH_ID);
+            if (usage & PIPE_MAP_READ && batch_uses >= ZINK_RESOURCE_ACCESS_WRITE)
+               resource_sync_writes_from_batch_id(ctx, batch_uses, zink_curr_batch(ctx)->batch_id);
+            else if (usage & PIPE_MAP_WRITE && batch_uses) {
+               /* need to wait for all rendering to finish
+                * TODO: optimize/fix this to be much less obtrusive
+                * mesa/mesa#2966
+                */
 
-            zink_fence_wait(pctx);
+               zink_fence_wait(pctx);
+            }
          }
+         if (usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE)
+            util_range_set_empty(&res->valid_buffer_range);
       }
 
 



More information about the mesa-commit mailing list