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 | |
| 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')
4 files changed, 68 insertions, 32 deletions
diff --git a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp index 7f6b54de..c87864ca 100644 --- a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp +++ b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp @@ -758,6 +758,9 @@ String GetBufferDescString( const BufferDesc &Desc ) Uint32 ComputeMipLevelsCount( Uint32 Width ) { + if (Width == 0) + return 0; + Uint32 MipLevels = 0; while( (Width >> MipLevels) > 0 ) ++MipLevels; diff --git a/Graphics/GraphicsEngine/src/Texture.cpp b/Graphics/GraphicsEngine/src/Texture.cpp index b1769cf3..b8d30af8 100644 --- a/Graphics/GraphicsEngine/src/Texture.cpp +++ b/Graphics/GraphicsEngine/src/Texture.cpp @@ -37,12 +37,32 @@ void ValidateTextureDesc( const TextureDesc& Desc ) LOG_TEXTURE_ERROR_AND_THROW("Resource dimension is undefined"); } + if ( !(Desc.Type >= RESOURCE_DIM_TEX_1D && Desc.Type <= RESOURCE_DIM_TEX_CUBE_ARRAY) ) + { + LOG_TEXTURE_ERROR_AND_THROW("Unexpected resource dimension"); + } + + if (Desc.Width == 0) + { + LOG_TEXTURE_ERROR_AND_THROW("Texture width cannot be zero"); + } + // Perform some parameter correctness check if( Desc.Type == RESOURCE_DIM_TEX_1D || Desc.Type == RESOURCE_DIM_TEX_1D_ARRAY ) { if( Desc.Height != 1 ) LOG_TEXTURE_ERROR_AND_THROW("Height (", Desc.Height,") of Texture 1D/Texture 1D Array must be 1"); } + else + { + if (Desc.Height == 0) + LOG_TEXTURE_ERROR_AND_THROW("Texture height cannot be zero"); + } + + if( Desc.Type == RESOURCE_DIM_TEX_3D && Desc.Depth == 0 ) + { + LOG_TEXTURE_ERROR_AND_THROW("3D texture depth cannot be zero"); + } if( Desc.Type == RESOURCE_DIM_TEX_1D || Desc.Type == RESOURCE_DIM_TEX_2D ) { 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); } |
