Mesa (main): zink: add and use fencing functions which take batch usage structs

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 22 21:08:01 UTC 2021


Module: Mesa
Branch: main
Commit: 1226628eb652171943cee3e79b61a0bdf1b9c2d1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1226628eb652171943cee3e79b61a0bdf1b9c2d1

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Fri May  7 08:45:15 2021 -0400

zink: add and use fencing functions which take batch usage structs

this hides the exact mechanics of fencing based on batch usage and makes
the usage a bit more explicit

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

---

 src/gallium/drivers/zink/zink_batch.c    | 16 ++++++++++++++++
 src/gallium/drivers/zink/zink_batch.h    |  5 +++++
 src/gallium/drivers/zink/zink_resource.c | 22 ++++++++--------------
 3 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c
index deb17fc868c..3afe9610a5c 100644
--- a/src/gallium/drivers/zink/zink_batch.c
+++ b/src/gallium/drivers/zink/zink_batch.c
@@ -655,3 +655,19 @@ zink_batch_reference_image_view(struct zink_batch *batch,
    else
       zink_batch_reference_surface(batch, image_view->surface);
 }
+
+bool
+zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_batch_usage *u)
+{
+   if (!zink_batch_usage_exists(u))
+      return true;
+   return zink_check_batch_completion(ctx, u->usage);
+}
+
+void
+zink_batch_usage_wait(struct zink_context *ctx, const struct zink_batch_usage *u)
+{
+   if (!zink_batch_usage_exists(u))
+      return;
+   zink_wait_on_batch(ctx, u->usage);
+}
diff --git a/src/gallium/drivers/zink/zink_batch.h b/src/gallium/drivers/zink/zink_batch.h
index ebba92c0f3b..a15747d21f0 100644
--- a/src/gallium/drivers/zink/zink_batch.h
+++ b/src/gallium/drivers/zink/zink_batch.h
@@ -200,4 +200,9 @@ zink_batch_usage_exists(struct zink_batch_usage *u)
    return !!usage;
 }
 
+bool
+zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_batch_usage *u);
+
+void
+zink_batch_usage_wait(struct zink_context *ctx, const struct zink_batch_usage *u);
 #endif
diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index 800d7e29805..4316506db6b 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -902,10 +902,9 @@ buffer_transfer_map(struct zink_context *ctx, struct zink_resource *res, unsigne
       /* Check if mapping this buffer would cause waiting for the GPU.
        */
 
-      uint32_t latest_access = get_most_recent_access(res, ZINK_RESOURCE_ACCESS_RW);
       if (!res->obj->host_visible ||
-          zink_resource_has_curr_read_usage(ctx, res) ||
-          (latest_access && !zink_check_batch_completion(ctx, latest_access))) {
+          !zink_batch_usage_check_completion(ctx, &res->obj->reads) ||
+          !zink_batch_usage_check_completion(ctx, &res->obj->writes)) {
          /* Do a wait-free write-only transfer using a temporary buffer. */
          unsigned offset;
 
@@ -929,17 +928,13 @@ buffer_transfer_map(struct zink_context *ctx, struct zink_resource *res, unsigne
       }
    } else if ((usage & PIPE_MAP_READ) && !(usage & PIPE_MAP_PERSISTENT)) {
       assert(!(usage & (TC_TRANSFER_MAP_THREADED_UNSYNC | PIPE_MAP_THREAD_SAFE)));
-      uint32_t latest_write = get_most_recent_access(res, ZINK_RESOURCE_ACCESS_WRITE);
       if (usage & PIPE_MAP_DONTBLOCK) {
          /* sparse/device-local will always need to wait since it has to copy */
          if (!res->obj->host_visible)
             return NULL;
-         if (latest_write &&
-             (latest_write == ctx->curr_batch || !zink_check_batch_completion(ctx, latest_write)))
+         if (!zink_batch_usage_check_completion(ctx, &res->obj->writes))
             return NULL;
-         latest_write = 0;
-      }
-      if (!res->obj->host_visible) {
+      } else if (!res->obj->host_visible) {
          zink_fence_wait(&ctx->base);
          trans->staging_res = pipe_buffer_create(&screen->base, PIPE_BIND_LINEAR, PIPE_USAGE_STAGING, box->x + box->width);
          if (!trans->staging_res)
@@ -948,10 +943,9 @@ buffer_transfer_map(struct zink_context *ctx, struct zink_resource *res, unsigne
          trans->offset = staging_res->obj->offset;
          zink_copy_buffer(ctx, NULL, staging_res, res, box->x, box->x, box->width);
          res = staging_res;
-         latest_write = ctx->curr_batch;
-      }
-      if (latest_write)
-         zink_wait_on_batch(ctx, latest_write);
+         zink_fence_wait(&ctx->base);
+      } else
+         zink_batch_usage_wait(ctx, &res->obj->writes);
    }
 
    if (!ptr) {
@@ -1078,7 +1072,7 @@ zink_transfer_map(struct pipe_context *pctx,
             if (usage & PIPE_MAP_WRITE)
                zink_fence_wait(pctx);
             else
-               resource_sync_writes_from_batch_usage(ctx, res);
+               zink_batch_usage_wait(ctx, &res->obj->writes);
          }
          VkImageSubresource isr = {
             res->aspect,



More information about the mesa-commit mailing list