const VkPresentInfoKHR* pPresentInfo)
{
RADV_FROM_HANDLE(radv_queue, queue, _queue);
- 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++) {
- RADV_FROM_HANDLE(wsi_swapchain, swapchain, pPresentInfo->pSwapchains[i]);
- struct radeon_winsys_cs *cs;
- const VkPresentRegionKHR *region = NULL;
- VkResult item_result;
- struct radv_winsys_sem_info sem_info;
-
- item_result = radv_alloc_sem_info(&sem_info,
- pPresentInfo->waitSemaphoreCount,
- pPresentInfo->pWaitSemaphores,
- 0,
- NULL);
- if (pPresentInfo->pResults != NULL)
- pPresentInfo->pResults[i] = item_result;
- result = result == VK_SUCCESS ? item_result : result;
- if (item_result != VK_SUCCESS) {
- radv_free_sem_info(&sem_info);
- continue;
- }
-
- assert(radv_device_from_handle(swapchain->device) == queue->device);
- if (swapchain->fences[0] == VK_NULL_HANDLE) {
- item_result = radv_CreateFence(radv_device_to_handle(queue->device),
- &(VkFenceCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
- .flags = 0,
- }, &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) {
- radv_free_sem_info(&sem_info);
- continue;
- }
- } else {
- radv_ResetFences(radv_device_to_handle(queue->device),
- 1, &swapchain->fences[0]);
- }
-
- cs = queue->device->empty_cs[queue->queue_family_index];
- RADV_FROM_HANDLE(radv_fence, fence, swapchain->fences[0]);
- struct radeon_winsys_fence *base_fence = fence->fence;
- struct radeon_winsys_ctx *ctx = queue->hw_ctx;
-
- queue->device->ws->cs_submit(ctx, queue->queue_idx,
- &cs,
- 1, NULL, NULL,
- &sem_info,
- false, base_fence);
- fence->submitted = true;
-
- if (regions && regions->pRegions)
- region = ®ions->pRegions[i];
-
- item_result = swapchain->queue_present(swapchain,
- _queue,
- pPresentInfo->waitSemaphoreCount,
- pPresentInfo->pWaitSemaphores,
- pPresentInfo->pImageIndices[i],
- region);
- /* TODO: What if one of them returns OUT_OF_DATE? */
- if (pPresentInfo->pResults != NULL)
- pPresentInfo->pResults[i] = item_result;
- result = result == VK_SUCCESS ? item_result : result;
- if (item_result != VK_SUCCESS) {
- radv_free_sem_info(&sem_info);
- 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) {
- radv_WaitForFences(radv_device_to_handle(queue->device),
- 1, &last, true, 1);
- }
-
- radv_free_sem_info(&sem_info);
- }
-
- return VK_SUCCESS;
+ return wsi_common_queue_present(&queue->device->physical_device->wsi_device,
+ radv_device_to_handle(queue->device),
+ _queue,
+ queue->queue_family_index,
+ pPresentInfo);
}
#include "wsi_common_private.h"
#include "util/macros.h"
+#include "vk_util.h"
void
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);
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
}
};
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;
+}
WSI_CB(CmdCopyImageToBuffer);
WSI_CB(CreateBuffer);
WSI_CB(CreateCommandPool);
+ WSI_CB(CreateFence);
WSI_CB(CreateImage);
WSI_CB(DestroyBuffer);
WSI_CB(DestroyCommandPool);
+ WSI_CB(DestroyFence);
WSI_CB(DestroyImage);
WSI_CB(EndCommandBuffer);
WSI_CB(FreeMemory);
WSI_CB(GetImageMemoryRequirements);
WSI_CB(GetImageSubresourceLayout);
WSI_CB(GetMemoryFdKHR);
+ WSI_CB(ResetFences);
WSI_CB(QueueSubmit);
+ WSI_CB(WaitForFences);
#undef WSI_CB
struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];
void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc);
+VkResult
+wsi_common_queue_present(const struct wsi_device *wsi,
+ VkDevice device_h,
+ VkQueue queue_h,
+ int queue_family_index,
+ const VkPresentInfoKHR *pPresentInfo);
#endif