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

Author: Mike Blumenkrantz <[email protected]>
Date:   Sun Mar 21 10:47:30 2021 -0400

zink: move batch-tracked resources to fence object

these are effectively managed by the fence, so it makes sense to store
them there

the set is ralloc-allocated, so explicitly destroying it isn't needed

Reviewed-by: Adam Jackson <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9753>

---

 src/gallium/drivers/zink/zink_batch.c | 20 +++-----------------
 src/gallium/drivers/zink/zink_batch.h |  1 -
 src/gallium/drivers/zink/zink_fence.c | 17 +++++++++++++++--
 src/gallium/drivers/zink/zink_fence.h |  3 +++
 4 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_batch.c 
b/src/gallium/drivers/zink/zink_batch.c
index bcc4310483c..af31d97419e 100644
--- a/src/gallium/drivers/zink/zink_batch.c
+++ b/src/gallium/drivers/zink/zink_batch.c
@@ -16,25 +16,12 @@
 
 #include "wsi_common.h"
 
-void
-zink_batch_state_clear_resources(struct zink_screen *screen, struct 
zink_batch_state *bs)
-{
-   /* unref all used resources */
-   set_foreach(bs->resources, entry) {
-      struct zink_resource_object *obj = (struct zink_resource_object 
*)entry->key;
-      zink_batch_usage_unset(&obj->reads, !!bs->fence.is_compute, 
bs->fence.batch_id);
-      zink_batch_usage_unset(&obj->writes, !!bs->fence.is_compute, 
bs->fence.batch_id);
-      zink_resource_object_reference(screen, &obj, NULL);
-      _mesa_set_remove(bs->resources, entry);
-   }
-}
-
 void
 zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
 {
    struct zink_screen *screen = zink_screen(ctx->base.screen);
 
-   zink_batch_state_clear_resources(screen, bs);
+   zink_fence_clear_resources(screen, &bs->fence);
 
    set_foreach(bs->active_queries, entry) {
       struct zink_query *query = (void*)entry->key;
@@ -123,7 +110,6 @@ zink_batch_state_destroy(struct zink_screen *screen, struct 
zink_batch_state *bs
       vkDestroyCommandPool(screen->dev, bs->cmdpool, NULL);
 
    _mesa_set_destroy(bs->fbs, NULL);
-   _mesa_set_destroy(bs->resources, NULL);
    util_dynarray_fini(&bs->zombie_samplers);
    _mesa_set_destroy(bs->surfaces, NULL);
    _mesa_set_destroy(bs->bufferviews, NULL);
@@ -160,7 +146,7 @@ create_batch_state(struct zink_context *ctx, enum 
zink_queue queue)
       goto fail
 
    SET_CREATE_OR_FAIL(bs->fbs);
-   SET_CREATE_OR_FAIL(bs->resources);
+   SET_CREATE_OR_FAIL(bs->fence.resources);
    SET_CREATE_OR_FAIL(bs->surfaces);
    SET_CREATE_OR_FAIL(bs->bufferviews);
    SET_CREATE_OR_FAIL(bs->programs);
@@ -344,7 +330,7 @@ zink_batch_reference_resource_rw(struct zink_batch *batch, 
struct zink_resource
    if (!zink_batch_usage_matches(&res->obj->reads, batch->queue, 
batch->state->fence.batch_id) &&
        !zink_batch_usage_matches(&res->obj->writes, batch->queue, 
batch->state->fence.batch_id)) {
       bool found = false;
-      _mesa_set_search_and_add(batch->state->resources, res->obj, &found);
+      _mesa_set_search_and_add(batch->state->fence.resources, res->obj, 
&found);
       if (!found) {
          pipe_reference(NULL, &res->obj->reference);
          if (!batch->last_batch_id || 
!zink_batch_usage_matches(&res->obj->reads, batch->queue, batch->last_batch_id))
diff --git a/src/gallium/drivers/zink/zink_batch.h 
b/src/gallium/drivers/zink/zink_batch.h
index 1cff6ae5b72..ceeb9b88714 100644
--- a/src/gallium/drivers/zink/zink_batch.h
+++ b/src/gallium/drivers/zink/zink_batch.h
@@ -67,7 +67,6 @@ struct zink_batch_state {
    struct set *fbs;
    struct set *programs;
 
-   struct set *resources;
    struct set *surfaces;
    struct set *bufferviews;
    struct set *desc_sets;
diff --git a/src/gallium/drivers/zink/zink_fence.c 
b/src/gallium/drivers/zink/zink_fence.c
index 8569baf9a7c..3464b650e2e 100644
--- a/src/gallium/drivers/zink/zink_fence.c
+++ b/src/gallium/drivers/zink/zink_fence.c
@@ -31,6 +31,20 @@
 #include "util/set.h"
 #include "util/u_memory.h"
 
+
+void
+zink_fence_clear_resources(struct zink_screen *screen, struct zink_fence 
*fence)
+{
+   /* unref all used resources */
+   set_foreach(fence->resources, entry) {
+      struct zink_resource_object *obj = (struct zink_resource_object 
*)entry->key;
+      zink_batch_usage_unset(&obj->reads, !!fence->is_compute, 
fence->batch_id);
+      zink_batch_usage_unset(&obj->writes, !!fence->is_compute, 
fence->batch_id);
+      zink_resource_object_reference(screen, &obj, NULL);
+      _mesa_set_remove(fence->resources, entry);
+   }
+}
+
 static void
 destroy_fence(struct zink_screen *screen, struct zink_fence *fence)
 {
@@ -109,8 +123,7 @@ zink_fence_finish(struct zink_screen *screen, struct 
pipe_context *pctx, struct
       success = vkGetFenceStatus(screen->dev, fence->fence) == VK_SUCCESS;
 
    if (success) {
-      struct zink_batch_state *bs = zink_batch_state(fence);
-      zink_batch_state_clear_resources(screen, bs);
+      zink_fence_clear_resources(screen, fence);
       p_atomic_set(&fence->submitted, false);
    }
    return success;
diff --git a/src/gallium/drivers/zink/zink_fence.h 
b/src/gallium/drivers/zink/zink_fence.h
index c49dae68732..afa82ac07c2 100644
--- a/src/gallium/drivers/zink/zink_fence.h
+++ b/src/gallium/drivers/zink/zink_fence.h
@@ -40,6 +40,7 @@ struct zink_fence {
    VkFence fence;
    struct pipe_context *deferred_ctx;
    uint32_t batch_id;
+   struct set *resources; /* resources need access removed asap, so they're on 
the fence */
    bool submitted;
    bool is_compute;
 };
@@ -70,4 +71,6 @@ zink_fence_server_sync(struct pipe_context *pctx, struct 
pipe_fence_handle *pfen
 void
 zink_screen_fence_init(struct pipe_screen *pscreen);
 
+void
+zink_fence_clear_resources(struct zink_screen *screen, struct zink_fence 
*fence);
 #endif

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

Reply via email to