From fe734bb6e2cd9c6bc7198dee1b180a0cf31c0ca3 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sun, 31 May 2020 19:00:56 -0700 Subject: [PATCH] aux/vk: Add functions to create semaphores from FDs --- src/xrt/auxiliary/vk/vk_helpers.c | 34 +++++++++++++++++++++++++++++++ src/xrt/auxiliary/vk/vk_helpers.h | 9 ++++++++ 2 files changed, 43 insertions(+) diff --git a/src/xrt/auxiliary/vk/vk_helpers.c b/src/xrt/auxiliary/vk/vk_helpers.c index 00b536f1a..10f42d244 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.c +++ b/src/xrt/auxiliary/vk/vk_helpers.c @@ -346,6 +346,38 @@ vk_create_image_from_fd(struct vk_bundle *vk, return ret; } +VkResult +vk_create_semaphore_from_fd(struct vk_bundle *vk, int fd, VkSemaphore *out_sem) +{ + VkResult ret; + + VkSemaphoreCreateInfo semaphore_create_info = { + .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, + }; + ret = vk->vkCreateSemaphore(vk->device, &semaphore_create_info, NULL, + out_sem); + if (ret != VK_SUCCESS) { + VK_ERROR(vk, "vkCreateSemaphore: %s", vk_result_string(ret)); + // Nothing to cleanup + return ret; + } + + VkImportSemaphoreFdInfoKHR import_semaphore_fd_info = { + .sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR, + .semaphore = *out_sem, + .handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT, + .fd = fd, + }; + ret = vk->vkImportSemaphoreFdKHR(vk->device, &import_semaphore_fd_info); + if (ret != VK_SUCCESS) { + VK_ERROR(vk, "vkImportSemaphoreFdKHR: %s", + vk_result_string(ret)); + vk->vkDestroySemaphore(vk->device, *out_sem, NULL); + return ret; + } + return ret; +} + VkResult vk_create_sampler(struct vk_bundle *vk, VkSampler *out_sampler) { @@ -705,6 +737,8 @@ vk_get_device_functions(struct vk_bundle *vk) vk->vkGetSwapchainImagesKHR = GET_DEV_PROC(vk, vkGetSwapchainImagesKHR); vk->vkAcquireNextImageKHR = GET_DEV_PROC(vk, vkAcquireNextImageKHR); vk->vkQueuePresentKHR = GET_DEV_PROC(vk, vkQueuePresentKHR); + vk->vkImportSemaphoreFdKHR = GET_DEV_PROC(vk, vkImportSemaphoreFdKHR); + vk->vkGetSemaphoreFdKHR = GET_DEV_PROC(vk, vkGetSemaphoreFdKHR); // clang-format on return VK_SUCCESS; diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h index 8f47ca450..b71215b61 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.h +++ b/src/xrt/auxiliary/vk/vk_helpers.h @@ -178,6 +178,9 @@ struct vk_bundle PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR; PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR; PFN_vkQueuePresentKHR vkQueuePresentKHR; + + PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHR; + PFN_vkGetSemaphoreFdKHR vkGetSemaphoreFdKHR; // clang-format on }; @@ -351,6 +354,12 @@ vk_create_image_from_fd(struct vk_bundle *vk, VkImage *out_image, VkDeviceMemory *out_mem); +/*! + * @ingroup aux_vk + */ +VkResult +vk_create_semaphore_from_fd(struct vk_bundle *vk, int fd, VkSemaphore *out_sem); + /*! * @ingroup aux_vk */