From 421d7d90773292f3960c8bc0f64c9b78fcefa4ce Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 16 Jan 2023 23:16:09 +0100 Subject: [PATCH] Revert "[vulkan] Use fence for acquiring a swap chain image" Breaks things and we don't really need this right now anyway. --- src/dxvk/dxvk_cmdlist.cpp | 7 +++++ src/vulkan/vulkan_presenter.cpp | 50 ++++++++------------------------- src/vulkan/vulkan_presenter.h | 13 ++------- 3 files changed, 21 insertions(+), 49 deletions(-) diff --git a/src/dxvk/dxvk_cmdlist.cpp b/src/dxvk/dxvk_cmdlist.cpp index ecfd5520..a59b7707 100644 --- a/src/dxvk/dxvk_cmdlist.cpp +++ b/src/dxvk/dxvk_cmdlist.cpp @@ -269,6 +269,13 @@ namespace dxvk { m_commandSubmission.waitSemaphore(m_sdmaSemaphore, 0, VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT); } + // We promise to never do weird stuff to WSI images on + // the transfer queue, so blocking graphics is sufficient + if (isFirst && m_wsiSemaphores.acquire) { + m_commandSubmission.waitSemaphore(m_wsiSemaphores.acquire, + 0, VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT); + } + // Submit graphics commands if (cmd.usedFlags.test(DxvkCmdBuffer::InitBuffer)) m_commandSubmission.executeCommandBuffer(cmd.initBuffer); diff --git a/src/vulkan/vulkan_presenter.cpp b/src/vulkan/vulkan_presenter.cpp index 21ea0064..62499530 100644 --- a/src/vulkan/vulkan_presenter.cpp +++ b/src/vulkan/vulkan_presenter.cpp @@ -12,15 +12,13 @@ namespace dxvk::vk { PresenterDevice device, const PresenterDesc& desc) : m_vki(vki), m_vkd(vkd), m_device(device) { - if (createFence() != VK_SUCCESS) - throw DxvkError("Failed to create presenter fence."); + } Presenter::~Presenter() { destroySwapchain(); destroySurface(); - destroyFence(); } @@ -41,19 +39,12 @@ namespace dxvk::vk { if (m_acquireStatus == VK_NOT_READY) { m_acquireStatus = m_vkd->vkAcquireNextImageKHR(m_vkd->device(), m_swapchain, std::numeric_limits::max(), - VK_NULL_HANDLE, m_acquireFence, &m_imageIndex); + sync.acquire, VK_NULL_HANDLE, &m_imageIndex); } if (m_acquireStatus != VK_SUCCESS && m_acquireStatus != VK_SUBOPTIMAL_KHR) return m_acquireStatus; - - VkResult vr = waitForAcquireFence(); - - if (vr != VK_SUCCESS) { - Logger::err(str::format("Failed to wait for presenter fence: ", vr)); - return vr; - } - + index = m_imageIndex; return m_acquireStatus; } @@ -83,7 +74,7 @@ namespace dxvk::vk { m_acquireStatus = m_vkd->vkAcquireNextImageKHR(m_vkd->device(), m_swapchain, std::numeric_limits::max(), - VK_NULL_HANDLE, m_acquireFence, &m_imageIndex); + sync.acquire, VK_NULL_HANDLE, &m_imageIndex); bool vsync = m_info.presentMode == VK_PRESENT_MODE_FIFO_KHR || m_info.presentMode == VK_PRESENT_MODE_FIFO_RELAXED_KHR; @@ -213,6 +204,10 @@ namespace dxvk::vk { for (uint32_t i = 0; i < m_semaphores.size(); i++) { VkSemaphoreCreateInfo semInfo = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO }; + if ((status = m_vkd->vkCreateSemaphore(m_vkd->device(), + &semInfo, nullptr, &m_semaphores[i].acquire))) + return status; + if ((status = m_vkd->vkCreateSemaphore(m_vkd->device(), &semInfo, nullptr, &m_semaphores[i].present))) return status; @@ -433,19 +428,14 @@ namespace dxvk::vk { } - VkResult Presenter::createFence() { - VkFenceCreateInfo fenceInfo = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO }; - - return m_vkd->vkCreateFence(m_vkd->device(), &fenceInfo, nullptr, &m_acquireFence); - } - - void Presenter::destroySwapchain() { for (const auto& img : m_images) m_vkd->vkDestroyImageView(m_vkd->device(), img.view, nullptr); - for (const auto& sem : m_semaphores) + for (const auto& sem : m_semaphores) { + m_vkd->vkDestroySemaphore(m_vkd->device(), sem.acquire, nullptr); m_vkd->vkDestroySemaphore(m_vkd->device(), sem.present, nullptr); + } m_vkd->vkDestroySwapchainKHR(m_vkd->device(), m_swapchain, nullptr); @@ -462,22 +452,4 @@ namespace dxvk::vk { m_surface = VK_NULL_HANDLE; } - - void Presenter::destroyFence() { - m_vkd->vkWaitForFences(m_vkd->device(), 1, &m_acquireFence, - VK_TRUE, std::numeric_limits::max()); - m_vkd->vkDestroyFence(m_vkd->device(), m_acquireFence, nullptr); - } - - - VkResult Presenter::waitForAcquireFence() { - VkResult vr = m_vkd->vkWaitForFences(m_vkd->device(), 1, - &m_acquireFence, VK_TRUE, std::numeric_limits::max()); - - if (vr == VK_SUCCESS) - vr = m_vkd->vkResetFences(m_vkd->device(), 1, &m_acquireFence); - - return vr; - } - } diff --git a/src/vulkan/vulkan_presenter.h b/src/vulkan/vulkan_presenter.h index af1129dd..641956f9 100644 --- a/src/vulkan/vulkan_presenter.h +++ b/src/vulkan/vulkan_presenter.h @@ -79,6 +79,7 @@ namespace dxvk::vk { * image acquisition. */ struct PresenterSync { + VkSemaphore acquire; VkSemaphore present; }; @@ -206,10 +207,8 @@ namespace dxvk::vk { PresenterDevice m_device; PresenterInfo m_info; - VkFence m_acquireFence = VK_NULL_HANDLE; - - VkSurfaceKHR m_surface = VK_NULL_HANDLE; - VkSwapchainKHR m_swapchain = VK_NULL_HANDLE; + VkSurfaceKHR m_surface = VK_NULL_HANDLE; + VkSwapchainKHR m_swapchain = VK_NULL_HANDLE; std::vector m_images; std::vector m_semaphores; @@ -258,16 +257,10 @@ namespace dxvk::vk { VkResult createSurface(); - VkResult createFence(); - void destroySwapchain(); void destroySurface(); - void destroyFence(); - - VkResult waitForAcquireFence(); - }; }