Mesa (staging/21.3): lavapipe: reference gallium fences correctly.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Feb 20 17:40:41 UTC 2022


Module: Mesa
Branch: staging/21.3
Commit: 3652e1e57ef82e83deeb25923cc50fc07d0697dd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3652e1e57ef82e83deeb25923cc50fc07d0697dd

Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Feb  8 16:33:38 2022 +1000

lavapipe: reference gallium fences correctly.

Make sure to take references in all the correct places to get
right lifetimes for these objects and avoid leaks.

Fixes: 94a498280516 ("lavapipe: implement timeline semaphores")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15046>
(cherry picked from commit b805d3e6abc07c8a6865516707854d295791e862)

---

 .pick_status.json                           |  2 +-
 src/gallium/frontends/lavapipe/lvp_device.c | 21 ++++++++++++---------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 0427e48f959..df6040d400b 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -886,7 +886,7 @@
         "description": "lavapipe: reference gallium fences correctly.",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "94a4982805164f87ec5ad7cb22251315c0577d71"
     },
diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c
index bfc07ba84eb..389b7a4fcea 100644
--- a/src/gallium/frontends/lavapipe/lvp_device.c
+++ b/src/gallium/frontends/lavapipe/lvp_device.c
@@ -1174,11 +1174,13 @@ thread_flush(struct lvp_device *device, struct lvp_fence *fence, uint64_t timeli
    struct pipe_fence_handle *handle = NULL;
    device->queue.ctx->flush(device->queue.ctx, &handle, 0);
    if (fence)
-      fence->handle = handle;
+      device->pscreen->fence_reference(device->pscreen, &fence->handle, handle);
    set_last_fence(device, handle, timeline);
    /* this is the array of signaling timeline semaphore links */
    for (unsigned i = 0; i < num_timelines; i++)
-      timelines[i]->fence = handle;
+      device->pscreen->fence_reference(device->pscreen, &timelines[i]->fence, handle);
+
+   device->pscreen->fence_reference(device->pscreen, &handle, NULL);
 }
 
 /* get a new timeline link for creating a new signal event
@@ -1210,7 +1212,8 @@ get_semaphore_link(struct lvp_semaphore *sema)
  * sema->lock MUST be locked before calling
  */
 static void
-prune_semaphore_links(struct lvp_semaphore *sema, uint64_t timeline)
+prune_semaphore_links(struct lvp_device *device,
+                      struct lvp_semaphore *sema, uint64_t timeline)
 {
    if (!timeline)
       /* zero isn't a valid id to prune with */
@@ -1225,7 +1228,7 @@ prune_semaphore_links(struct lvp_semaphore *sema, uint64_t timeline)
       util_dynarray_append(&sema->links, struct lvp_semaphore_timeline*, tl);
       tl = tl->next;
       cur->next = NULL;
-      cur->fence = NULL;
+      device->pscreen->fence_reference(device->pscreen, &cur->fence, NULL);
    }
    /* this is now the current timeline link */
    sema->timeline = tl;
@@ -1288,7 +1291,7 @@ static VkResult wait_semaphores(struct lvp_device *device,
             /* no timeline link was available yet: try to find one */
             simple_mtx_lock(&sema->lock);
             /* always prune first to update current timeline id */
-            prune_semaphore_links(sema, device->queue.last_finished);
+            prune_semaphore_links(device, sema, device->queue.last_finished);
             tl_array[i].tl = find_semaphore_timeline(sema, waitval);
             if (timeout && !tl_array[i].tl) {
                /* still no timeline link available:
@@ -1540,7 +1543,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_QueueSubmit(
          }
          simple_mtx_lock(&sema->lock);
          /* always prune first to make links available and update timeline id */
-         prune_semaphore_links(sema, queue->last_finished);
+         prune_semaphore_links(queue->device, sema, queue->last_finished);
          if (sema->current < info->pSignalSemaphoreValues[j]) {
             /* only signal semaphores if the new id is >= the current one */
             struct lvp_semaphore_timeline *tl = get_semaphore_link(sema);
@@ -1562,7 +1565,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_QueueSubmit(
          }
          simple_mtx_lock(&sema->lock);
          /* always prune first to update timeline id */
-         prune_semaphore_links(sema, queue->last_finished);
+         prune_semaphore_links(queue->device, sema, queue->last_finished);
          if (info->pWaitSemaphoreValues[j] &&
              pSubmits[i].pWaitDstStageMask && pSubmits[i].pWaitDstStageMask[j] &&
              sema->current < info->pWaitSemaphoreValues[j]) {
@@ -2316,7 +2319,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_GetSemaphoreCounterValue(
    LVP_FROM_HANDLE(lvp_device, device, _device);
    LVP_FROM_HANDLE(lvp_semaphore, sema, _semaphore);
    simple_mtx_lock(&sema->lock);
-   prune_semaphore_links(sema, device->queue.last_finished);
+   prune_semaphore_links(device, sema, device->queue.last_finished);
    *pValue = sema->current;
    simple_mtx_unlock(&sema->lock);
    return VK_SUCCESS;
@@ -2334,7 +2337,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_SignalSemaphore(
       sema->current = pSignalInfo->value;
    cnd_broadcast(&sema->submit);
    simple_mtx_lock(&sema->lock);
-   prune_semaphore_links(sema, device->queue.last_finished);
+   prune_semaphore_links(device, sema, device->queue.last_finished);
    simple_mtx_unlock(&sema->lock);
    return VK_SUCCESS;
 }



More information about the mesa-commit mailing list