diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-07-06 17:41:55 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-07-06 17:41:55 +0000 |
| commit | b3311e60b7dc6ee1581469e2d3ac8854cdcb5ba0 (patch) | |
| tree | f86c8128992f1ae2a4511ca124314b37411384ab /Graphics/GraphicsEngineVulkan | |
| parent | Always using negative viewport height in Vulkan to be 100% consistent with Di... (diff) | |
| download | DiligentCore-b3311e60b7dc6ee1581469e2d3ac8854cdcb5ba0.tar.gz DiligentCore-b3311e60b7dc6ee1581469e2d3ac8854cdcb5ba0.zip | |
Fixed Vulkan swapchain present error when window is minimized
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h | 1 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 76 |
2 files changed, 45 insertions, 32 deletions
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<ITextureViewVk> 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<DeviceContextVkImpl>(); + auto* pImmediateCtxVk = pDeviceContext.RawPtr<DeviceContextVkImpl>(); + auto* pDeviceVk = m_pRenderDevice.RawPtr<RenderDeviceVkImpl>(); - // 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<RenderDeviceVkImpl>(); - 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); } |
