Module: Mesa
Branch: staging/23.2
Commit: 34ae85f587ee9f28bb12132c4c5a3a34e7034d34
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=34ae85f587ee9f28bb12132c4c5a3a34e7034d34

Author: Mike Blumenkrantz <[email protected]>
Date:   Tue Sep 19 09:01:45 2023 -0400

zink: move swapchain fence to swapchain object

this is more accurate in terms of usage/ownership and avoids potential
illegal fence usage in the scenario where multiple async presents are
in flight

cc: mesa-stable

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25288>
(cherry picked from commit 2b7b1059e418359c6445833e12dea27842810cc6)

---

 .pick_status.json                      | 2 +-
 src/gallium/drivers/zink/zink_kopper.c | 8 ++++----
 src/gallium/drivers/zink/zink_kopper.h | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index f5d1121567c..90d9cad5ba4 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -574,7 +574,7 @@
         "description": "zink: move swapchain fence to swapchain object",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null,
         "notes": null
diff --git a/src/gallium/drivers/zink/zink_kopper.c 
b/src/gallium/drivers/zink/zink_kopper.c
index 3a6dac8259e..0ea3c5515b3 100644
--- a/src/gallium/drivers/zink/zink_kopper.c
+++ b/src/gallium/drivers/zink/zink_kopper.c
@@ -145,6 +145,7 @@ destroy_swapchain(struct zink_screen *screen, struct 
kopper_swapchain *cswap)
 {
    if (!cswap)
       return;
+   util_queue_fence_destroy(&cswap->present_fence);
    for (unsigned i = 0; i < cswap->num_images; i++) {
       simple_mtx_lock(&screen->semaphores_lock);
       util_dynarray_append(&screen->semaphores, VkSemaphore, 
cswap->images[i].acquire);
@@ -237,7 +238,6 @@ zink_kopper_deinit_displaytarget(struct zink_screen 
*screen, struct kopper_displ
    VKSCR(DestroySurfaceKHR)(screen->instance, cdt->surface, NULL);
    cdt->swapchain = cdt->old_swapchain = NULL;
    cdt->surface = VK_NULL_HANDLE;
-   util_queue_fence_destroy(&cdt->present_fence);
 }
 
 static struct kopper_swapchain *
@@ -250,6 +250,7 @@ kopper_CreateSwapchain(struct zink_screen *screen, struct 
kopper_displaytarget *
       return NULL;
    }
    cswap->last_present_prune = 1;
+   util_queue_fence_init(&cswap->present_fence);
 
    bool has_alpha = cdt->info.has_alpha && (cdt->caps.supportedCompositeAlpha 
& VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR);
    if (cdt->swapchain) {
@@ -427,7 +428,6 @@ zink_kopper_displaytarget_create(struct zink_screen 
*screen, unsigned tex_usage,
    cdt->refcount = 1;
    cdt->loader_private = (void*)loader_private;
    cdt->info = *info;
-   util_queue_fence_init(&cdt->present_fence);
 
    enum pipe_format srgb = PIPE_FORMAT_NONE;
    if (screen->info.have_KHR_swapchain_mutable_format) {
@@ -529,7 +529,7 @@ kopper_acquire(struct zink_screen *screen, struct 
zink_resource *res, uint64_t t
       }
       if (timeout == UINT64_MAX && 
util_queue_is_initialized(&screen->flush_queue) &&
           p_atomic_read_relaxed(&cdt->swapchain->num_acquires) >= 
cdt->swapchain->max_acquires) {
-         util_queue_fence_wait(&cdt->present_fence);
+         util_queue_fence_wait(&cdt->swapchain->present_fence);
       }
       VkResult ret;
       if (!acquire) {
@@ -813,7 +813,7 @@ zink_kopper_present_queue(struct zink_screen *screen, 
struct zink_resource *res)
       p_atomic_inc(&cpi->swapchain->async_presents);
       struct pipe_resource *pres = NULL;
       pipe_resource_reference(&pres, &res->base.b);
-      util_queue_add_job(&screen->flush_queue, cpi, &cdt->present_fence,
+      util_queue_add_job(&screen->flush_queue, cpi, 
&cdt->swapchain->present_fence,
                          kopper_present, NULL, 0);
    } else {
       kopper_present(cpi, screen, -1);
diff --git a/src/gallium/drivers/zink/zink_kopper.h 
b/src/gallium/drivers/zink/zink_kopper.h
index 4b7d2d62ddf..f1062b657a5 100644
--- a/src/gallium/drivers/zink/zink_kopper.h
+++ b/src/gallium/drivers/zink/zink_kopper.h
@@ -58,6 +58,7 @@ struct kopper_swapchain {
    unsigned num_acquires;
    unsigned max_acquires;
    unsigned async_presents;
+   struct util_queue_fence present_fence;
    struct zink_batch_usage *batch_uses;
    struct kopper_swapchain_image *images;
 };
@@ -83,7 +84,6 @@ struct kopper_displaytarget
    struct kopper_swapchain *old_swapchain;
 
    struct kopper_loader_info info;
-   struct util_queue_fence present_fence;
 
    VkSurfaceCapabilitiesKHR caps;
    VkImageFormatListCreateInfo format_list;

Reply via email to