From f6ffb5ac365ea27c046fd2510953602caec585b3 Mon Sep 17 00:00:00 2001 From: Juston Li Date: Tue, 20 Dec 2022 14:19:13 -0800 Subject: [PATCH] venus: require exportable/importable bit for ext semaphores sync fd Signed-off-by: Juston Li Part-of: --- src/virtio/vulkan/vn_physical_device.c | 6 +++- src/virtio/vulkan/vn_queue.c | 53 ++++++++++++++++------------------ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/virtio/vulkan/vn_physical_device.c b/src/virtio/vulkan/vn_physical_device.c index d00357b..5ee4428 100644 --- a/src/virtio/vulkan/vn_physical_device.c +++ b/src/virtio/vulkan/vn_physical_device.c @@ -965,7 +965,11 @@ vn_physical_device_get_native_extensions( VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT)) exts->KHR_external_fence_fd = true; - exts->KHR_external_semaphore_fd = true; + if ((physical_dev->renderer_sync_fd_semaphore_features & + VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT) && + (physical_dev->renderer_sync_fd_semaphore_features & + VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT)) + exts->KHR_external_semaphore_fd = true; } #endif diff --git a/src/virtio/vulkan/vn_queue.c b/src/virtio/vulkan/vn_queue.c index 28e4052..1b9309f 100644 --- a/src/virtio/vulkan/vn_queue.c +++ b/src/virtio/vulkan/vn_queue.c @@ -1551,6 +1551,11 @@ vn_GetSemaphoreFdKHR(VkDevice device, assert(dev->instance->experimental.globalFencing); assert(sync_file); + assert((dev->physical_device->renderer_sync_fd_semaphore_features & + VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT)); + assert((dev->physical_device->renderer_sync_fd_semaphore_features & + VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT)); + int fd = -1; if (payload->type == VN_SYNC_TYPE_DEVICE_ONLY) { VkResult result = vn_create_sync_file(dev, sem->ring_idx, &fd); @@ -1565,36 +1570,28 @@ vn_GetSemaphoreFdKHR(VkDevice device, payload->fd = -1; } - /* required sync_fd features for fixing the host semaphore payload */ - static const VkExternalSemaphoreFeatureFlags req_sync_fd_feats = - VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT | - VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT; - if ((dev->physical_device->renderer_sync_fd_semaphore_features & - req_sync_fd_feats) == req_sync_fd_feats) { - - /* When payload->type is VN_SYNC_TYPE_IMPORTED_SYNC_FD, the current - * payload is from a prior temporary sync_fd import. The permanent - * payload of the sempahore might be in signaled state. So we do an - * import here to ensure later wait operation is legit. With resourceId - * 0, renderer does a signaled sync_fd -1 payload import on the host - * semaphore. - */ - if (payload->type == VN_SYNC_TYPE_IMPORTED_SYNC_FD) { - const VkImportSemaphoreResourceInfo100000MESA res_info = { - .sType = - VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_RESOURCE_INFO_100000_MESA, - .semaphore = pGetFdInfo->semaphore, - .resourceId = 0, - }; - vn_async_vkImportSemaphoreResource100000MESA(dev->instance, device, - &res_info); - } - - /* perform wait operation on the host semaphore */ - vn_async_vkWaitSemaphoreResource100000MESA(dev->instance, device, - pGetFdInfo->semaphore); + /* When payload->type is VN_SYNC_TYPE_IMPORTED_SYNC_FD, the current + * payload is from a prior temporary sync_fd import. The permanent + * payload of the sempahore might be in signaled state. So we do an + * import here to ensure later wait operation is legit. With resourceId + * 0, renderer does a signaled sync_fd -1 payload import on the host + * semaphore. + */ + if (payload->type == VN_SYNC_TYPE_IMPORTED_SYNC_FD) { + const VkImportSemaphoreResourceInfo100000MESA res_info = { + .sType = + VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_RESOURCE_INFO_100000_MESA, + .semaphore = pGetFdInfo->semaphore, + .resourceId = 0, + }; + vn_async_vkImportSemaphoreResource100000MESA(dev->instance, device, + &res_info); } + /* perform wait operation on the host semaphore */ + vn_async_vkWaitSemaphoreResource100000MESA(dev->instance, device, + pGetFdInfo->semaphore); + vn_sync_payload_release(dev, &sem->temporary); sem->payload = &sem->permanent; -- 2.7.4