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

Author: Mike Blumenkrantz <[email protected]>
Date:   Thu Sep 28 13:35:12 2023 -0400

zink: guarantee egl syncobj lifetime

according to spec, egl syncobjs can be deleted before they complete,
which means they need to be preserved while they're still in progress

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25460>

---

 src/gallium/drivers/zink/zink_batch.c   | 5 +++++
 src/gallium/drivers/zink/zink_context.c | 4 ++++
 src/gallium/drivers/zink/zink_fence.c   | 2 ++
 src/gallium/drivers/zink/zink_types.h   | 1 +
 4 files changed, 12 insertions(+)

diff --git a/src/gallium/drivers/zink/zink_batch.c 
b/src/gallium/drivers/zink/zink_batch.c
index a48f9eaa457..7e3b268fc0c 100644
--- a/src/gallium/drivers/zink/zink_batch.c
+++ b/src/gallium/drivers/zink/zink_batch.c
@@ -172,6 +172,10 @@ zink_reset_batch_state(struct zink_context *ctx, struct 
zink_batch_state *bs)
    }
    bs->swapchain = NULL;
 
+   util_dynarray_foreach(&bs->fences, struct zink_tc_fence*, mfence)
+      zink_fence_reference(screen, mfence, NULL);
+   util_dynarray_clear(&bs->fences);
+
    bs->unordered_write_access = 0;
    bs->unordered_write_stages = 0;
 
@@ -354,6 +358,7 @@ create_batch_state(struct zink_context *ctx)
    util_dynarray_init(&bs->signal_semaphores, NULL);
    util_dynarray_init(&bs->wait_semaphores, NULL);
    util_dynarray_init(&bs->fd_wait_semaphores, NULL);
+   util_dynarray_init(&bs->fences, NULL);
    util_dynarray_init(&bs->dead_querypools, NULL);
    util_dynarray_init(&bs->dgc.pipelines, NULL);
    util_dynarray_init(&bs->dgc.layouts, NULL);
diff --git a/src/gallium/drivers/zink/zink_context.c 
b/src/gallium/drivers/zink/zink_context.c
index ecb0df68036..7f3efca517c 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -3790,6 +3790,10 @@ zink_flush(struct pipe_context *pctx,
          mfence->submit_count = submit_count;
          util_dynarray_append(&fence->mfences, struct zink_tc_fence *, mfence);
       }
+      if (export_sem) {
+         pipe_reference(NULL, &mfence->reference);
+         util_dynarray_append(&ctx->batch.state->fences, struct 
zink_tc_fence*, mfence);
+      }
 
       if (deferred_fence) {
          assert(fence);
diff --git a/src/gallium/drivers/zink/zink_fence.c 
b/src/gallium/drivers/zink/zink_fence.c
index 2a2007a2872..33ea9d7d90e 100644
--- a/src/gallium/drivers/zink/zink_fence.c
+++ b/src/gallium/drivers/zink/zink_fence.c
@@ -255,6 +255,8 @@ zink_fence_server_sync(struct pipe_context *pctx, struct 
pipe_fence_handle *pfen
    VkPipelineStageFlags flag = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
    util_dynarray_append(&ctx->batch.state->wait_semaphores, VkSemaphore, 
mfence->sem);
    util_dynarray_append(&ctx->batch.state->wait_semaphore_stages, 
VkPipelineStageFlags, flag);
+   pipe_reference(NULL, &mfence->reference);
+   util_dynarray_append(&ctx->batch.state->fences, struct zink_tc_fence*, 
mfence);
 
    /* transfer the external wait sempahore ownership to the next submit */
    mfence->sem = VK_NULL_HANDLE;
diff --git a/src/gallium/drivers/zink/zink_types.h 
b/src/gallium/drivers/zink/zink_types.h
index 3350f11a872..86926758a34 100644
--- a/src/gallium/drivers/zink/zink_types.h
+++ b/src/gallium/drivers/zink/zink_types.h
@@ -605,6 +605,7 @@ struct zink_batch_state {
    struct util_dynarray wait_semaphore_stages; //external wait semaphores
    struct util_dynarray fd_wait_semaphores; //dmabuf wait semaphores
    struct util_dynarray fd_wait_semaphore_stages; //dmabuf wait semaphores
+   struct util_dynarray fences; //zink_tc_fence refs
 
    VkSemaphore present;
    struct zink_resource *swapchain;

Reply via email to