From b3311e60b7dc6ee1581469e2d3ac8854cdcb5ba0 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Fri, 6 Jul 2018 10:41:55 -0700 Subject: Fixed Vulkan swapchain present error when window is minimized --- .../GraphicsEngineVulkan/include/SwapChainVkImpl.h | 1 + .../GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 76 +++++++++++++--------- 2 files changed, 45 insertions(+), 32 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h index 6d68758f..018e1eb8 100644 --- a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h @@ -85,6 +85,7 @@ private: RefCntAutoPtr m_pDepthBufferDSV; Uint32 m_SemaphoreIndex = 0; uint32_t m_BackBufferIndex = 0; + bool m_IsMinimized = false; }; } diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index 0187c5a2..e1d1810e 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -426,46 +426,56 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval) return; } - auto *pImmediateCtxVk = pDeviceContext.RawPtr(); + auto* pImmediateCtxVk = pDeviceContext.RawPtr(); + auto* pDeviceVk = m_pRenderDevice.RawPtr(); - // TransitionImageLayout() never triggers flush - pImmediateCtxVk->TransitionImageLayout(GetCurrentBackBufferRTV()->GetTexture(), VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); - // The context can be empty if no render commands were issued by the app - //VERIFY(pImmediateCtxVk->GetNumCommandsInCtx() != 0, "The context must not be flushed"); - pImmediateCtxVk->AddSignalSemaphore(m_DrawCompleteSemaphores[m_SemaphoreIndex]); - pImmediateCtxVk->Flush(); + if (!m_IsMinimized) + { + // TransitionImageLayout() never triggers flush + pImmediateCtxVk->TransitionImageLayout(GetCurrentBackBufferRTV()->GetTexture(), VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); + // The context can be empty if no render commands were issued by the app + //VERIFY(pImmediateCtxVk->GetNumCommandsInCtx() != 0, "The context must not be flushed"); + pImmediateCtxVk->AddSignalSemaphore(m_DrawCompleteSemaphores[m_SemaphoreIndex]); + } - VkPresentInfoKHR PresentInfo = {}; - PresentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; - PresentInfo.pNext = nullptr; - PresentInfo.waitSemaphoreCount = 1; - // Unlike fences or events, the act of waiting for a semaphore also unsignals that semaphore (6.4.2) - VkSemaphore WaitSemaphore[] = { m_DrawCompleteSemaphores[m_SemaphoreIndex] }; - PresentInfo.pWaitSemaphores = WaitSemaphore; - PresentInfo.swapchainCount = 1; - PresentInfo.pSwapchains = &m_VkSwapChain; - PresentInfo.pImageIndices = &m_BackBufferIndex; - VkResult Result = VK_SUCCESS; - PresentInfo.pResults = &Result; + pImmediateCtxVk->Flush(); + + if (!m_IsMinimized) + { + VkPresentInfoKHR PresentInfo = {}; + PresentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + PresentInfo.pNext = nullptr; + PresentInfo.waitSemaphoreCount = 1; + // Unlike fences or events, the act of waiting for a semaphore also unsignals that semaphore (6.4.2) + VkSemaphore WaitSemaphore[] = { m_DrawCompleteSemaphores[m_SemaphoreIndex] }; + PresentInfo.pWaitSemaphores = WaitSemaphore; + PresentInfo.swapchainCount = 1; + PresentInfo.pSwapchains = &m_VkSwapChain; + PresentInfo.pImageIndices = &m_BackBufferIndex; + VkResult Result = VK_SUCCESS; + PresentInfo.pResults = &Result; - auto *pDeviceVk = m_pRenderDevice.RawPtr(); - auto vkCmdQueue = pDeviceVk->GetCmdQueue()->GetVkQueue(); - vkQueuePresentKHR(vkCmdQueue, &PresentInfo); - VERIFY(Result == VK_SUCCESS, "Present failed"); + auto vkCmdQueue = pDeviceVk->GetCmdQueue()->GetVkQueue(); + vkQueuePresentKHR(vkCmdQueue, &PresentInfo); + VERIFY(Result == VK_SUCCESS, "Present failed"); + } pDeviceVk->FinishFrame(); - ++m_SemaphoreIndex; - if (m_SemaphoreIndex >= m_SwapChainDesc.BufferCount) - m_SemaphoreIndex = 0; + if (!m_IsMinimized) + { + ++m_SemaphoreIndex; + if (m_SemaphoreIndex >= m_SwapChainDesc.BufferCount) + m_SemaphoreIndex = 0; - AcquireNextImage(pImmediateCtxVk); + AcquireNextImage(pImmediateCtxVk); - if(pImmediateCtxVk->IsDefaultFBBound()) - { - // If default framebuffer is bound, we need to call SetRenderTargets() - // to bind new back buffer RTV - pImmediateCtxVk->SetRenderTargets(0, nullptr, nullptr); + if(pImmediateCtxVk->IsDefaultFBBound()) + { + // If default framebuffer is bound, we need to call SetRenderTargets() + // to bind new back buffer RTV + pImmediateCtxVk->SetRenderTargets(0, nullptr, nullptr); + } } } @@ -519,6 +529,8 @@ void SwapChainVkImpl::Resize( Uint32 NewWidth, Uint32 NewHeight ) } } } + + m_IsMinimized = (NewWidth == 0 && NewHeight == 0); } -- cgit v1.2.3