zink: guarantee egl syncobj lifetime
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 28 Sep 2023 17:35:12 +0000 (13:35 -0400)
committerMarge Bot <emma+marge@anholt.net>
Wed, 4 Oct 2023 02:27:53 +0000 (02:27 +0000)
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
src/gallium/drivers/zink/zink_context.c
src/gallium/drivers/zink/zink_fence.c
src/gallium/drivers/zink/zink_types.h

index a48f9ea..7e3b268 100644 (file)
@@ -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);
index ecb0df6..7f3efca 100644 (file)
@@ -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);
index 2a2007a..33ea9d7 100644 (file)
@@ -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;
index 3350f11..8692675 100644 (file)
@@ -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;