Mesa (main): zink: replace some direct batch_usage calls with resource abstractions

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jul 27 00:05:29 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Wed Jul  7 09:42:46 2021 -0400

zink: replace some direct batch_usage calls with resource abstractions

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

---

 src/gallium/drivers/zink/zink_batch.c    |  3 +--
 src/gallium/drivers/zink/zink_context.c  |  6 ++----
 src/gallium/drivers/zink/zink_resource.c | 16 +++++++---------
 3 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c
index 9e132640da7..276997f8d14 100644
--- a/src/gallium/drivers/zink/zink_batch.c
+++ b/src/gallium/drivers/zink/zink_batch.c
@@ -36,8 +36,7 @@ zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
    /* unref all used resources */
    set_foreach_remove(bs->resources, entry) {
       struct zink_resource_object *obj = (struct zink_resource_object *)entry->key;
-      zink_batch_usage_unset(&obj->reads, bs);
-      zink_batch_usage_unset(&obj->writes, bs);
+      zink_resource_object_usage_unset(obj, bs);
       zink_resource_object_reference(screen, &obj, NULL);
    }
 
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index 9df354f9fe4..18edf0e7da2 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -3232,8 +3232,7 @@ zink_resource_commit(struct pipe_context *pctx, struct pipe_resource *pres, unsi
    struct zink_screen *screen = zink_screen(pctx->screen);
 
    /* if any current usage exists, flush the queue */
-   if (zink_batch_usage_is_unflushed(res->obj->reads) ||
-       zink_batch_usage_is_unflushed(res->obj->writes))
+   if (zink_resource_has_unflushed_usage(res))
       zink_flush_queue(ctx);
 
    uint8_t *mem = malloc(sizeof(VkBindSparseInfo) + sizeof(VkSparseBufferMemoryBindInfo) + sizeof(VkSparseMemoryBind) + sizeof(void*));
@@ -3339,8 +3338,7 @@ zink_context_replace_buffer_storage(struct pipe_context *pctx, struct pipe_resou
 
    assert(d->internal_format == s->internal_format);
    util_idalloc_mt_free(&zink_screen(pctx->screen)->buffer_ids, delete_buffer_id);
-   if (zink_batch_usage_is_unflushed(d->obj->reads) ||
-       zink_batch_usage_is_unflushed(d->obj->writes))
+   if (zink_resource_has_unflushed_usage(d))
       zink_batch_reference_resource(&zink_context(pctx)->batch, d);
    zink_resource_object_reference(zink_screen(pctx->screen), &d->obj, s->obj);
    d->access = s->access;
diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index ee9f752905e..b4a975bbcbd 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -1174,13 +1174,11 @@ buffer_transfer_map(struct zink_context *ctx, struct zink_resource *res, unsigne
    if ((usage & PIPE_MAP_WRITE) &&
        (usage & PIPE_MAP_DISCARD_RANGE || (!(usage & PIPE_MAP_READ) && zink_resource_has_usage(res))) &&
        ((!res->obj->host_visible) || !(usage & (PIPE_MAP_UNSYNCHRONIZED | PIPE_MAP_PERSISTENT)))) {
-
       /* Check if mapping this buffer would cause waiting for the GPU.
        */
 
       if (!res->obj->host_visible ||
-          !zink_batch_usage_check_completion(ctx, res->obj->reads) ||
-          !zink_batch_usage_check_completion(ctx, res->obj->writes)) {
+          !zink_resource_usage_check_completion(screen, res, ZINK_RESOURCE_ACCESS_RW)) {
          /* Do a wait-free write-only transfer using a temporary buffer. */
          unsigned offset;
 
@@ -1208,7 +1206,7 @@ buffer_transfer_map(struct zink_context *ctx, struct zink_resource *res, unsigne
          /* sparse/device-local will always need to wait since it has to copy */
          if (!res->obj->host_visible)
             return NULL;
-         if (!zink_batch_usage_check_completion(ctx, res->obj->writes))
+         if (!zink_resource_usage_check_completion(screen, res, ZINK_RESOURCE_ACCESS_WRITE))
             return NULL;
       } else if (!res->obj->host_visible) {
          trans->staging_res = pipe_buffer_create(&screen->base, PIPE_BIND_LINEAR, PIPE_USAGE_STAGING, box->x + box->width);
@@ -1219,7 +1217,7 @@ buffer_transfer_map(struct zink_context *ctx, struct zink_resource *res, unsigne
          res = staging_res;
          zink_fence_wait(&ctx->base);
       } else
-         zink_batch_usage_wait(ctx, res->obj->writes);
+         zink_resource_usage_wait(ctx, res, ZINK_RESOURCE_ACCESS_WRITE);
    }
 
    if (!ptr) {
@@ -1330,8 +1328,8 @@ zink_transfer_map(struct pipe_context *pctx,
 
          if (usage & PIPE_MAP_READ) {
             /* force multi-context sync */
-            if (zink_batch_usage_is_unflushed(res->obj->writes))
-               zink_batch_usage_wait(ctx, res->obj->writes);
+            if (zink_resource_usage_is_unflushed_write(res))
+               zink_resource_usage_wait(ctx, res, ZINK_RESOURCE_ACCESS_WRITE);
             zink_transfer_copy_bufimage(ctx, staging_res, res, trans);
             /* need to wait for rendering to finish */
             zink_fence_wait(pctx);
@@ -1349,7 +1347,7 @@ zink_transfer_map(struct pipe_context *pctx,
             if (usage & PIPE_MAP_WRITE)
                zink_fence_wait(pctx);
             else
-               zink_batch_usage_wait(ctx, res->obj->writes);
+               zink_resource_usage_wait(ctx, res, ZINK_RESOURCE_ACCESS_WRITE);
          }
          VkImageSubresource isr = {
             res->obj->modifier_aspect ? res->obj->modifier_aspect : res->aspect,
@@ -1551,7 +1549,7 @@ zink_resource_object_init_storage(struct zink_context *ctx, struct zink_resource
       struct zink_resource staging = *res;
       staging.obj = old_obj;
       bool needs_unref = true;
-      if (get_resource_usage(res)) {
+      if (zink_resource_has_usage(res)) {
          zink_batch_reference_resource_move(&ctx->batch, res);
          needs_unref = false;
       }



More information about the mesa-commit mailing list