diff options
author | Dave Airlie <[email protected]> | 2017-11-16 11:52:39 +1000 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2017-12-04 10:04:19 -0800 |
commit | 6dc3a5e8f0c07d1f1ed6ff3fb71d8f2f6eb32d7c (patch) | |
tree | 4b6306bd0d42ce4309b6c8fd098e5c8b96a98126 /src/vulkan/wsi/wsi_common.c | |
parent | 42dd06d957036ae68d6e670af8b156f15ac750ea (diff) |
radv/wsi: Move the guts of QueuePresent to wsi common
v2 (Jason Ekstrand):
- Better comit message
- Rebase
- Re-indent to follow wsi_common style
- Drop the unneeded _swapchain from the newly added helper
- Make the clone more true to the original (as per the rebase)
Reviewed-by: Dave Airlie <[email protected]>
Reviewed-by: Chad Versace <[email protected]>
Diffstat (limited to 'src/vulkan/wsi/wsi_common.c')
-rw-r--r-- | src/vulkan/wsi/wsi_common.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c index b86bb90cec6..5920359c631 100644 --- a/src/vulkan/wsi/wsi_common.c +++ b/src/vulkan/wsi/wsi_common.c @@ -23,6 +23,7 @@ #include "wsi_common_private.h" #include "util/macros.h" +#include "vk_util.h" void wsi_device_init(struct wsi_device *wsi, @@ -50,9 +51,11 @@ wsi_device_init(struct wsi_device *wsi, WSI_GET_CB(CmdCopyImageToBuffer); WSI_GET_CB(CreateBuffer); WSI_GET_CB(CreateCommandPool); + WSI_GET_CB(CreateFence); WSI_GET_CB(CreateImage); WSI_GET_CB(DestroyBuffer); WSI_GET_CB(DestroyCommandPool); + WSI_GET_CB(DestroyFence); WSI_GET_CB(DestroyImage); WSI_GET_CB(EndCommandBuffer); WSI_GET_CB(FreeMemory); @@ -61,7 +64,9 @@ wsi_device_init(struct wsi_device *wsi, WSI_GET_CB(GetImageMemoryRequirements); WSI_GET_CB(GetImageSubresourceLayout); WSI_GET_CB(GetMemoryFdKHR); + WSI_GET_CB(ResetFences); WSI_GET_CB(QueueSubmit); + WSI_GET_CB(WaitForFences); #undef WSI_GET_CB } @@ -501,3 +506,76 @@ wsi_prime_image_blit_to_linear(const struct wsi_swapchain *chain, }; return chain->wsi->QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); } + +VkResult +wsi_common_queue_present(const struct wsi_device *wsi, + VkDevice device, + VkQueue queue, + int queue_family_index, + const VkPresentInfoKHR *pPresentInfo) +{ + VkResult result = VK_SUCCESS; + + const VkPresentRegionsKHR *regions = + vk_find_struct_const(pPresentInfo->pNext, PRESENT_REGIONS_KHR); + + for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) { + WSI_FROM_HANDLE(wsi_swapchain, swapchain, pPresentInfo->pSwapchains[i]); + VkResult item_result; + + if (swapchain->fences[0] == VK_NULL_HANDLE) { + const VkFenceCreateInfo fence_info = { + .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, + .pNext = NULL, + .flags = 0, + }; + item_result = wsi->CreateFence(device, &fence_info, + &swapchain->alloc, + &swapchain->fences[0]); + if (pPresentInfo->pResults != NULL) + pPresentInfo->pResults[i] = item_result; + result = result == VK_SUCCESS ? item_result : result; + if (item_result != VK_SUCCESS) { + continue; + } + } else { + wsi->ResetFences(device, 1, &swapchain->fences[0]); + } + + VkSubmitInfo submit_info = { + .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, + .pNext = NULL, + .waitSemaphoreCount = pPresentInfo->waitSemaphoreCount, + .pWaitSemaphores = pPresentInfo->pWaitSemaphores, + }; + wsi->QueueSubmit(queue, 1, &submit_info, swapchain->fences[0]); + + const VkPresentRegionKHR *region = NULL; + if (regions && regions->pRegions) + region = ®ions->pRegions[i]; + + item_result = swapchain->queue_present(swapchain, + queue, + pPresentInfo->waitSemaphoreCount, + pPresentInfo->pWaitSemaphores, + pPresentInfo->pImageIndices[i], + region); + + if (pPresentInfo->pResults != NULL) + pPresentInfo->pResults[i] = item_result; + result = result == VK_SUCCESS ? item_result : result; + if (item_result != VK_SUCCESS) { + continue; + } + + VkFence last = swapchain->fences[2]; + swapchain->fences[2] = swapchain->fences[1]; + swapchain->fences[1] = swapchain->fences[0]; + swapchain->fences[0] = last; + + if (last != VK_NULL_HANDLE) { + wsi->WaitForFences(device, 1, &last, true, 1); + } + } + return VK_SUCCESS; +} |