wsi/common: Implement swapchain present fence.
authorHans-Kristian Arntzen <post@arntzen-software.no>
Wed, 30 Nov 2022 11:07:58 +0000 (12:07 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 3 Mar 2023 03:59:13 +0000 (03:59 +0000)
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
Reviewed-by: Joshua Ashton <joshua@froggi.es>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20235>

src/vulkan/wsi/wsi_common.c

index 52d5526..7dd1927 100644 (file)
@@ -1186,9 +1186,10 @@ wsi_AcquireNextImage2KHR(VkDevice _device,
 }
 
 static VkResult wsi_signal_present_id_timeline(struct wsi_swapchain *swapchain,
-                                               VkQueue queue, uint64_t present_id)
+                                               VkQueue queue, uint64_t present_id,
+                                               VkFence present_fence)
 {
-   assert(swapchain->present_id_timeline);
+   assert(swapchain->present_id_timeline || present_fence);
 
    const VkTimelineSemaphoreSubmitInfo timeline_info = {
       .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO,
@@ -1203,7 +1204,8 @@ static VkResult wsi_signal_present_id_timeline(struct wsi_swapchain *swapchain,
       .pSignalSemaphores = &swapchain->present_id_timeline,
    };
 
-   return swapchain->wsi->QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
+   uint32_t submit_count = present_id ? 1 : 0;
+   return swapchain->wsi->QueueSubmit(queue, submit_count, &submit_info, present_fence);
 }
 
 VkResult
@@ -1224,6 +1226,8 @@ wsi_common_queue_present(const struct wsi_device *wsi,
       vk_find_struct_const(pPresentInfo->pNext, PRESENT_REGIONS_KHR);
    const VkPresentIdKHR *present_ids =
       vk_find_struct_const(pPresentInfo->pNext, PRESENT_ID_KHR);
+   const VkSwapchainPresentFenceInfoEXT *present_fence_info =
+      vk_find_struct_const(pPresentInfo->pNext, SWAPCHAIN_PRESENT_FENCE_INFO_EXT);
 
    for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) {
       VK_FROM_HANDLE(wsi_swapchain, swapchain, pPresentInfo->pSwapchains[i]);
@@ -1375,9 +1379,12 @@ wsi_common_queue_present(const struct wsi_device *wsi,
       uint64_t present_id = 0;
       if (present_ids && present_ids->pPresentIds)
          present_id = present_ids->pPresentIds[i];
+      VkFence present_fence = VK_NULL_HANDLE;
+      if (present_fence_info && present_fence_info->pFences)
+         present_fence = present_fence_info->pFences[i];
 
-      if (present_id) {
-         result = wsi_signal_present_id_timeline(swapchain, queue, present_id);
+      if (present_id || present_fence) {
+         result = wsi_signal_present_id_timeline(swapchain, queue, present_id, present_fence);
          if (result != VK_SUCCESS)
             goto fail_present;
       }