From e4d9650e21355f696cced1575267a79e741841cc Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Wed, 27 Aug 2025 14:17:05 -0400 Subject: [PATCH] vulkan/wsi: Move a couple of dma-buf sync checks In 14b416079203 ("vulkan/wsi: Only test for dma-buf sync file support once"), I moved the dma-buf sync file import/export check earlier. This is fine for hardware implementations where we have real dma-buf import/export but it broke lavapipe because the check itself ignored whether or not we actually have dma-buf import/export. Add a couple more checks to wsi_drm_check_dma_buf_sync_file_import_export() so it's safe even for SW drivers. Also, in wsi_create_sync_for_dma_buf_wait(), check if we actually have a dma-buf. Fixes: 14b416079203 ("vulkan/wsi: Only test for dma-buf sync file support once") Reviewed-by: Mike Blumenkrantz Part-of: --- src/vulkan/wsi/wsi_common_drm.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/vulkan/wsi/wsi_common_drm.c b/src/vulkan/wsi/wsi_common_drm.c index 8aff11de5c0..65bc5251ef9 100644 --- a/src/vulkan/wsi/wsi_common_drm.c +++ b/src/vulkan/wsi/wsi_common_drm.c @@ -102,6 +102,23 @@ wsi_drm_check_dma_buf_sync_file_import_export(const struct wsi_device *wsi, if (likely(cached_result != 0)) return (VkResult) (cached_result + 1); + /* If we don't have dma-buf export, we don't have dma-buf sync, either */ + VkResult result; + if (wsi->GetMemoryFdKHR == NULL) { + result = VK_ERROR_FEATURE_NOT_PRESENT; + goto out; + } + + /* If semaphores don't support sync FD or if the kernel doesn't support + * sync file import/export, then WSI will fall back to requesting BO-based + * implicit sync from the driver. + */ + if (!(wsi->semaphore_export_handle_types & + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT)) { + result = VK_ERROR_FEATURE_NOT_PRESENT; + goto out; + } + struct VkExportMemoryAllocateInfo export_info = { .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO, .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, @@ -110,7 +127,6 @@ wsi_drm_check_dma_buf_sync_file_import_export(const struct wsi_device *wsi, .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = 4096, .pNext = (void *)&export_info}; - VkResult result; VkDeviceMemory mem; result = wsi->AllocateMemory(device, &mem_info, NULL, &mem); if (result != VK_SUCCESS) { @@ -223,6 +239,9 @@ wsi_create_sync_for_dma_buf_wait(const struct wsi_swapchain *chain, VK_FROM_HANDLE(vk_device, device, chain->device); VkResult result; + if (image->dma_buf_fd < 0) + return VK_ERROR_FEATURE_NOT_PRESENT; + /* First, check if we even have the feature */ result = wsi_drm_check_dma_buf_sync_file_import_export(chain->wsi, chain->device); @@ -356,14 +375,6 @@ wsi_drm_init_swapchain_implicit_sync(struct wsi_swapchain *chain) if (chain->image_info.explicit_sync) return VK_SUCCESS; - /* If semaphores don't support sync FD or if the kernel doesn't support - * sync file import/export, then WSI will fall back to requesting BO-based - * implicit sync from the driver. - */ - if (!(chain->wsi->semaphore_export_handle_types & - VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT)) - return VK_SUCCESS; - VkResult result = wsi_drm_check_dma_buf_sync_file_import_export(chain->wsi, chain->device); if (result == VK_ERROR_FEATURE_NOT_PRESENT)