From 81325cf887c8abe1af4fa8eba05402320aca9a1b Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 18 Aug 2025 10:51:16 -0400 Subject: [PATCH] vulkan,anv,hasvk: Drop vk_queue_wait_before_present() This helper existed to ensure that drivers waited for semaphores to materialize before processing a QueuePresent(). However, most drivers never called this and they were kind-of fine. Now that we have explicit and dma-buf sync built into WSI, this wait happens as part GetSemaphoreFd when we fetch the sync file from the semaphore. It's also less racy to just rely on GetSemaphoreFd() because, even though we were stalling the submit thread prior to present, the present itself does one or more submits and those may go to the thread and potentially race with the window system. The GetSemaphoreFd(), however, happens at the right time to ensure we actually stall before handing off to the window system. Reviewed-by: Lars-Ivar Hesselberg Simonsen Reviewed-by: Adam Jackson Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_wsi.c | 4 -- src/intel/vulkan_hasvk/anv_wsi.c | 4 -- src/vulkan/runtime/vk_queue.c | 65 -------------------------------- src/vulkan/runtime/vk_queue.h | 3 -- 4 files changed, 76 deletions(-) diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c index 99e4f65487f..42a73d77193 100644 --- a/src/intel/vulkan/anv_wsi.c +++ b/src/intel/vulkan/anv_wsi.c @@ -108,10 +108,6 @@ VkResult anv_QueuePresentKHR( if (u_trace_should_process(&device->ds.trace_context)) anv_queue_trace(queue, NULL, true /* frame */, false /* begin */); - result = vk_queue_wait_before_present(&queue->vk, pPresentInfo); - if (result != VK_SUCCESS) - return result; - result = wsi_common_queue_present(&device->physical->wsi_device, anv_device_to_handle(queue->device), _queue, 0, diff --git a/src/intel/vulkan_hasvk/anv_wsi.c b/src/intel/vulkan_hasvk/anv_wsi.c index c3daa408b8c..a423e1838dd 100644 --- a/src/intel/vulkan_hasvk/anv_wsi.c +++ b/src/intel/vulkan_hasvk/anv_wsi.c @@ -105,10 +105,6 @@ VkResult anv_QueuePresentKHR( #endif } - result = vk_queue_wait_before_present(&queue->vk, pPresentInfo); - if (result != VK_SUCCESS) - return result; - result = wsi_common_queue_present(&device->physical->wsi_device, anv_device_to_handle(queue->device), _queue, 0, diff --git a/src/vulkan/runtime/vk_queue.c b/src/vulkan/runtime/vk_queue.c index 1052650966d..609b8e63096 100644 --- a/src/vulkan/runtime/vk_queue.c +++ b/src/vulkan/runtime/vk_queue.c @@ -1125,71 +1125,6 @@ vk_queue_merge_submit(struct vk_queue *queue, return result; } -VkResult -vk_queue_wait_before_present(struct vk_queue *queue, - const VkPresentInfoKHR *pPresentInfo) -{ - if (vk_device_is_lost(queue->base.device)) - return VK_ERROR_DEVICE_LOST; - - /* From the Vulkan 1.2.194 spec: - * - * VUID-vkQueuePresentKHR-pWaitSemaphores-03268 - * - * "All elements of the pWaitSemaphores member of pPresentInfo must - * reference a semaphore signal operation that has been submitted for - * execution and any semaphore signal operations on which it depends (if - * any) must have also been submitted for execution." - * - * As with vkQueueSubmit above, we need to ensure that any binary - * semaphores we use in this present actually exist. If we don't have - * timeline semaphores, this is a non-issue. If they're emulated, then - * this is ensured for us by the vk_device_flush() at the end of every - * vkQueueSubmit() and every vkSignalSemaphore(). For real timeline - * semaphores, however, we need to do a wait. Thanks to the above bit of - * spec text, that wait should never block for long. - */ - if (!vk_device_supports_threaded_submit(queue->base.device)) - return VK_SUCCESS; - - const uint32_t wait_count = pPresentInfo->waitSemaphoreCount; - - if (wait_count == 0) - return VK_SUCCESS; - - STACK_ARRAY(struct vk_sync_wait, waits, wait_count); - - for (uint32_t i = 0; i < wait_count; i++) { - VK_FROM_HANDLE(vk_semaphore, semaphore, - pPresentInfo->pWaitSemaphores[i]); - - /* From the Vulkan 1.2.194 spec: - * - * VUID-vkQueuePresentKHR-pWaitSemaphores-03267 - * - * "All elements of the pWaitSemaphores member of pPresentInfo must - * be created with a VkSemaphoreType of VK_SEMAPHORE_TYPE_BINARY." - */ - assert(semaphore->type == VK_SEMAPHORE_TYPE_BINARY); - - waits[i] = (struct vk_sync_wait) { - .sync = vk_semaphore_get_active_sync(semaphore), - .stage_mask = ~(VkPipelineStageFlags2)0, - }; - } - - VkResult result = vk_sync_wait_many(queue->base.device, wait_count, waits, - VK_SYNC_WAIT_PENDING, UINT64_MAX); - - STACK_ARRAY_FINISH(waits); - - /* Check again, just in case */ - if (vk_device_is_lost(queue->base.device)) - return VK_ERROR_DEVICE_LOST; - - return result; -} - static VkResult vk_queue_signal_sync(struct vk_queue *queue, struct vk_sync *sync, diff --git a/src/vulkan/runtime/vk_queue.h b/src/vulkan/runtime/vk_queue.h index 11cdf9683d6..9d0042f0ce6 100644 --- a/src/vulkan/runtime/vk_queue.h +++ b/src/vulkan/runtime/vk_queue.h @@ -192,9 +192,6 @@ VkResult vk_queue_enable_submit_thread(struct vk_queue *queue); VkResult vk_queue_flush(struct vk_queue *queue, uint32_t *submit_count_out); -VkResult vk_queue_wait_before_present(struct vk_queue *queue, - const VkPresentInfoKHR *pPresentInfo); - VkResult PRINTFLIKE(4, 5) _vk_queue_set_lost(struct vk_queue *queue, const char *file, int line,