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

Author: Mike Blumenkrantz <[email protected]>
Date:   Fri Jun 26 15:16:17 2020 -0400

zink: optimize transfer_map for resources with pending reads/writes

we don't need to stall here if we know that we're not about to have any io
conflicts in the buffer

Reviewed-by: Erik Faye-Lun <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6924>

---

 src/gallium/drivers/zink/zink_resource.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_resource.c 
b/src/gallium/drivers/zink/zink_resource.c
index 6e41fdd8be4..a811eba5453 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -425,6 +425,15 @@ zink_transfer_copy_bufimage(struct zink_context *ctx,
    return true;
 }
 
+static uint32_t
+get_resource_usage(struct zink_resource *res)
+{
+   uint32_t batch_uses = 0;
+   for (unsigned i = 0; i < 4; i++)
+      batch_uses |= p_atomic_read(&res->batch_uses[i]) << i;
+   return batch_uses;
+}
+
 static void *
 zink_transfer_map(struct pipe_context *pctx,
                   struct pipe_resource *pres,
@@ -436,6 +445,7 @@ zink_transfer_map(struct pipe_context *pctx,
    struct zink_context *ctx = zink_context(pctx);
    struct zink_screen *screen = zink_screen(pctx->screen);
    struct zink_resource *res = zink_resource(pres);
+   uint32_t batch_uses = get_resource_usage(res);
 
    struct zink_transfer *trans = slab_alloc(&ctx->transfer_pool);
    if (!trans)
@@ -451,12 +461,15 @@ zink_transfer_map(struct pipe_context *pctx,
 
    void *ptr;
    if (pres->target == PIPE_BUFFER) {
-      if (usage & PIPE_MAP_READ) {
-         /* need to wait for rendering to finish
-          * TODO: optimize/fix this to be much less obtrusive
-          * mesa/mesa#2966
-          */
-         zink_fence_wait(pctx);
+      if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) {
+         if ((usage & PIPE_MAP_READ && batch_uses >= 
ZINK_RESOURCE_ACCESS_WRITE) ||
+             (usage & PIPE_MAP_WRITE && batch_uses)) {
+            /* need to wait for rendering to finish
+             * TODO: optimize/fix this to be much less obtrusive
+             * mesa/mesa#2966
+             */
+            zink_fence_wait(pctx);
+         }
       }
 
 

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to