From 5f8a9f0aeba852bdc3d71affd3eb920c95cca9a3 Mon Sep 17 00:00:00 2001 From: osy Date: Mon, 22 Dec 2025 10:25:12 -0800 Subject: [PATCH] vulkan: external sync for vk_sync_binary Venus uses vkImportSemaphoreFdKHR() with FD == -1 to signal a binary semaphore and vkGetSemaphoreFdKHR() to wait on a binary semaphore. Both KK and Dzn uses vk_sync_binary so supporting this special case for import/export sync file will enable Venus host support. Reviewed-by: Aitor Camacho Part-of: --- src/vulkan/runtime/vk_sync_binary.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/vulkan/runtime/vk_sync_binary.c b/src/vulkan/runtime/vk_sync_binary.c index c10cabe348a..d7ab4c610d2 100644 --- a/src/vulkan/runtime/vk_sync_binary.c +++ b/src/vulkan/runtime/vk_sync_binary.c @@ -24,6 +24,7 @@ #include "vk_sync_binary.h" #include "vk_util.h" +#include "util/os_time.h" static struct vk_sync_binary * to_vk_sync_binary(struct vk_sync *sync) @@ -44,7 +45,6 @@ vk_sync_binary_init(struct vk_device *device, container_of(binary->sync.type, struct vk_sync_binary_type, sync); assert(!(sync->flags & VK_SYNC_IS_TIMELINE)); - assert(!(sync->flags & VK_SYNC_IS_SHAREABLE)); binary->next_point = (initial_value == 0); @@ -114,6 +114,29 @@ vk_sync_binary_wait_many(struct vk_device *device, return result; } +static VkResult +vk_sync_binary_import_sync_file(struct vk_device *device, + struct vk_sync *sync, + int fd) +{ + /* FD == -1 case handled by vk_sync_import_sync_file() */ + return VK_ERROR_INVALID_EXTERNAL_HANDLE; +} + +static VkResult +vk_sync_binary_export_sync_file(struct vk_device *device, + struct vk_sync *sync, + int *pFd) +{ + VkResult result; + struct vk_sync_binary *binary = to_vk_sync_binary(sync); + + result = vk_sync_wait(device, &binary->timeline, binary->next_point, 0, + OS_TIMEOUT_INFINITE); + *pFd = -1; + return result; +} + struct vk_sync_binary_type vk_sync_binary_get_type(const struct vk_sync_type *timeline_type) { @@ -135,6 +158,8 @@ vk_sync_binary_get_type(const struct vk_sync_type *timeline_type) .reset = vk_sync_binary_reset, .signal = vk_sync_binary_signal, .wait_many = vk_sync_binary_wait_many, + .import_sync_file = vk_sync_binary_import_sync_file, + .export_sync_file = vk_sync_binary_export_sync_file, }, .timeline_type = timeline_type, };