From 064da7189446d49c5e125a310d137d1b730ae764 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 26 Jun 2023 20:27:47 +0100 Subject: [PATCH] c/util: Track and free native sync handle from semaphore The layer above IPC & st/oxr doesn't consume this handle, instead it has dup semantics, so we need to keep track of the handle and free it once done. --- src/xrt/compositor/util/comp_semaphore.c | 11 ++++++++++- src/xrt/compositor/util/comp_semaphore.h | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/xrt/compositor/util/comp_semaphore.c b/src/xrt/compositor/util/comp_semaphore.c index adace53d0..34eff6637 100644 --- a/src/xrt/compositor/util/comp_semaphore.c +++ b/src/xrt/compositor/util/comp_semaphore.c @@ -7,6 +7,8 @@ * @ingroup comp_util */ +#include "util/u_handles.h" + #include "util/comp_semaphore.h" @@ -61,6 +63,10 @@ semaphore_destroy(struct xrt_compositor_semaphore *xcsem) csem->semaphore = VK_NULL_HANDLE; } + // Does invalid checking and sets to invalid. + u_graphics_sync_unref(&csem->handle); + + // Do the final freeing. free(csem); } #endif @@ -85,7 +91,8 @@ comp_semaphore_create(struct vk_bundle *vk, } VkSemaphore semaphore; - ret = vk_create_timeline_semaphore_and_native(vk, &semaphore, out_handle); + xrt_graphics_sync_handle_t handle; + ret = vk_create_timeline_semaphore_and_native(vk, &semaphore, &handle); if (ret != VK_SUCCESS) { return XRT_ERROR_VULKAN; } @@ -97,9 +104,11 @@ comp_semaphore_create(struct vk_bundle *vk, csem->base.destroy = semaphore_destroy; csem->base.wait = semaphore_wait; csem->semaphore = semaphore; + csem->handle = handle; csem->vk = vk; *out_xcsem = &csem->base; + *out_handle = handle; return XRT_SUCCESS; #else diff --git a/src/xrt/compositor/util/comp_semaphore.h b/src/xrt/compositor/util/comp_semaphore.h index ea303f3f2..0baa7c591 100644 --- a/src/xrt/compositor/util/comp_semaphore.h +++ b/src/xrt/compositor/util/comp_semaphore.h @@ -1,4 +1,4 @@ -// Copyright 2019-2022, Collabora, Ltd. +// Copyright 2019-2023, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -32,6 +32,14 @@ struct comp_semaphore struct vk_bundle *vk; VkSemaphore semaphore; + + /*! + * Shared handle, the layer above compositor, such as IPC & st/oxr, + * doesn't consume this handle, instead it has dup semantics. So we + * need to keep track of the handle and free it once done. This is + * because the platform may be required by the platform. + */ + xrt_graphics_sync_handle_t handle; };