From b2073f5e5d689a8458b331b5be9608bf5717cfa4 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Sat, 1 Jan 2022 23:03:36 -0600 Subject: [PATCH] radv: Move QueueSignalReleaseImageANDROID to common code This is mostly a copy+paste job but with a few syntax changes to make it follow more closely with other common Vulkan code. Reviewed-by: Eric Engestrom Reviewed-by: Iago Toral Quiroga Part-of: --- src/amd/vulkan/radv_android.c | 50 ------------------------------------ src/vulkan/runtime/meson.build | 1 + src/vulkan/runtime/vk_android.c | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/amd/vulkan/radv_android.c b/src/amd/vulkan/radv_android.c index 4ead328..d0fca99 100644 --- a/src/amd/vulkan/radv_android.c +++ b/src/amd/vulkan/radv_android.c @@ -376,56 +376,6 @@ radv_GetSwapchainGrallocUsage2ANDROID(VkDevice device_h, VkFormat format, return VK_ERROR_FORMAT_NOT_SUPPORTED; #endif } - -VkResult -radv_QueueSignalReleaseImageANDROID(VkQueue _queue, uint32_t waitSemaphoreCount, - const VkSemaphore *pWaitSemaphores, VkImage image, - int *pNativeFenceFd) -{ - RADV_FROM_HANDLE(radv_queue, queue, _queue); - VkResult result = VK_SUCCESS; - - if (waitSemaphoreCount == 0) { - if (pNativeFenceFd) - *pNativeFenceFd = -1; - return VK_SUCCESS; - } - - int fd = -1; - - for (uint32_t i = 0; i < waitSemaphoreCount; ++i) { - int tmp_fd; - result = queue->device->vk.dispatch_table.GetSemaphoreFdKHR( - radv_device_to_handle(queue->device), - &(VkSemaphoreGetFdInfoKHR){ - .sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR, - .handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT, - .semaphore = pWaitSemaphores[i], - }, - &tmp_fd); - if (result != VK_SUCCESS) { - if (fd >= 0) - close(fd); - return result; - } - - if (fd < 0) - fd = tmp_fd; - else if (tmp_fd >= 0) { - sync_accumulate("radv", &fd, tmp_fd); - close(tmp_fd); - } - } - - if (pNativeFenceFd) { - *pNativeFenceFd = fd; - } else if (fd >= 0) { - close(fd); - /* We still need to do the exports, to reset the semaphores, but - * otherwise we don't wait on them. */ - } - return VK_SUCCESS; -} #endif #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER diff --git a/src/vulkan/runtime/meson.build b/src/vulkan/runtime/meson.build index 6026b17..2eabf06 100644 --- a/src/vulkan/runtime/meson.build +++ b/src/vulkan/runtime/meson.build @@ -81,6 +81,7 @@ endif if with_platform_android vulkan_runtime_files += files('vk_android.c') + vulkan_runtime_deps += dep_android endif vk_common_entrypoints = custom_target( diff --git a/src/vulkan/runtime/vk_android.c b/src/vulkan/runtime/vk_android.c index 88790f3..0a4a666 100644 --- a/src/vulkan/runtime/vk_android.c +++ b/src/vulkan/runtime/vk_android.c @@ -24,6 +24,9 @@ #include "vk_common_entrypoints.h" #include "vk_device.h" #include "vk_log.h" +#include "vk_queue.h" + +#include "util/libsync.h" #include @@ -104,3 +107,56 @@ vk_common_AcquireImageANDROID(VkDevice _device, return result; } + + +VKAPI_ATTR VkResult VKAPI_CALL +vk_common_QueueSignalReleaseImageANDROID(VkQueue _queue, + uint32_t waitSemaphoreCount, + const VkSemaphore *pWaitSemaphores, + VkImage image, + int *pNativeFenceFd) +{ + VK_FROM_HANDLE(vk_queue, queue, _queue); + struct vk_device *device = queue->base.device; + VkResult result = VK_SUCCESS; + + if (waitSemaphoreCount == 0) { + if (pNativeFenceFd) + *pNativeFenceFd = -1; + return VK_SUCCESS; + } + + int fd = -1; + + for (uint32_t i = 0; i < waitSemaphoreCount; ++i) { + const VkSemaphoreGetFdInfoKHR get_fd = { + .sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR, + .handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT, + .semaphore = pWaitSemaphores[i], + }; + int tmp_fd; + result = device->dispatch_table.GetSemaphoreFdKHR(vk_device_to_handle(device), + &get_fd, &tmp_fd); + if (result != VK_SUCCESS) { + if (fd >= 0) + close(fd); + return result; + } + + if (fd < 0) { + fd = tmp_fd; + } else if (tmp_fd >= 0) { + sync_accumulate("vulkan", &fd, tmp_fd); + close(tmp_fd); + } + } + + if (pNativeFenceFd) { + *pNativeFenceFd = fd; + } else if (fd >= 0) { + close(fd); + /* We still need to do the exports, to reset the semaphores, but + * otherwise we don't wait on them. */ + } + return VK_SUCCESS; +} -- 2.7.4