diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-04-21 03:01:05 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-04-21 03:01:05 +0000 |
| commit | 6ca3e20b9c6a4816241e834a68e6635f2830c4e9 (patch) | |
| tree | 1bc6faccd2693a71799939fed419a1dc697a330e /Graphics/GraphicsEngineVulkan | |
| parent | Implemented present in Vulkan swap chain; implemented clear color & depth out... (diff) | |
| download | DiligentCore-6ca3e20b9c6a4816241e834a68e6635f2830c4e9.tar.gz DiligentCore-6ca3e20b9c6a4816241e834a68e6635f2830c4e9.zip | |
Fixed issues with the swap chain resize in Vulkan
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
3 files changed, 42 insertions, 18 deletions
diff --git a/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp index 99ff89e8..e884b273 100644 --- a/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp @@ -21,6 +21,7 @@ * of the possibility of such damages. */ +#include <thread> #include "pch.h" #include "CommandQueueVkImpl.h" @@ -103,6 +104,14 @@ void CommandQueueVkImpl::IdleGPU() m_LastCompletedFenceValue = LastCompletedFenceValue; for(auto& val_fence : m_PendingFences) { + // For some reason after idling the queue not all fences are signaled + while(m_LogicalDevice->GetFenceStatus(val_fence.second) != VK_SUCCESS) + { + VkFence FenceToWait = val_fence.second; + auto res = vkWaitForFences(m_LogicalDevice->GetVkDevice(), 1, &FenceToWait, VK_TRUE, UINT64_MAX); + VERIFY_EXPR(res == VK_SUCCESS); + } + auto status = m_LogicalDevice->GetFenceStatus(val_fence.second); VERIFY(status == VK_SUCCESS, "All pending fences must now be complete!"); m_FencePool.DisposeFence(std::move(val_fence.second)); diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 91b058e9..43cf53c9 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -625,6 +625,10 @@ namespace Diligent { VERIFY(!m_bIsDeferred, "Flush() should only be called for immediate contexts"); + VkSubmitInfo SubmitInfo = {}; + SubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + SubmitInfo.pNext = nullptr; + auto pDeviceVkImpl = m_pDevice.RawPtr<RenderDeviceVkImpl>(); auto vkCmdBuff = m_CommandBuffer.GetVkCmdBuffer(); if(vkCmdBuff != VK_NULL_HANDLE ) @@ -639,24 +643,30 @@ namespace Diligent m_CommandBuffer.FlushBarriers(); m_CommandBuffer.EndCommandBuffer(); - - VkSubmitInfo SubmitInfo = {}; - SubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - SubmitInfo.pNext = nullptr; - SubmitInfo.waitSemaphoreCount = static_cast<uint32_t>(m_WaitSemaphores.size()); - VERIFY_EXPR(m_WaitSemaphores.size() == m_WaitDstStageMasks.size()); - SubmitInfo.pWaitSemaphores = SubmitInfo.waitSemaphoreCount != 0 ? m_WaitSemaphores.data() : nullptr; - SubmitInfo.pWaitDstStageMask = SubmitInfo.waitSemaphoreCount != 0 ? m_WaitDstStageMasks.data() : nullptr; + SubmitInfo.commandBufferCount = 1; SubmitInfo.pCommandBuffers = &vkCmdBuff; - SubmitInfo.signalSemaphoreCount = static_cast<uint32_t>(m_SignalSemaphores.size()); - SubmitInfo.pSignalSemaphores = SubmitInfo.signalSemaphoreCount != 0 ? m_SignalSemaphores.data() : nullptr; - pDeviceVkImpl->ExecuteCommandBuffer(SubmitInfo, true); - - m_WaitSemaphores.clear(); - m_WaitDstStageMasks.clear(); - m_SignalSemaphores.clear(); } + } + + SubmitInfo.waitSemaphoreCount = static_cast<uint32_t>(m_WaitSemaphores.size()); + VERIFY_EXPR(m_WaitSemaphores.size() == m_WaitDstStageMasks.size()); + SubmitInfo.pWaitSemaphores = SubmitInfo.waitSemaphoreCount != 0 ? m_WaitSemaphores.data() : nullptr; + SubmitInfo.pWaitDstStageMask = SubmitInfo.waitSemaphoreCount != 0 ? m_WaitDstStageMasks.data() : nullptr; + SubmitInfo.signalSemaphoreCount = static_cast<uint32_t>(m_SignalSemaphores.size()); + SubmitInfo.pSignalSemaphores = SubmitInfo.signalSemaphoreCount != 0 ? m_SignalSemaphores.data() : nullptr; + + if(SubmitInfo.commandBufferCount != 0 || SubmitInfo.waitSemaphoreCount !=0 || SubmitInfo.signalSemaphoreCount != 0) + { + pDeviceVkImpl->ExecuteCommandBuffer(SubmitInfo, true); + } + + m_WaitSemaphores.clear(); + m_WaitDstStageMasks.clear(); + m_SignalSemaphores.clear(); + + if (vkCmdBuff != VK_NULL_HANDLE) + { DisposeVkCmdBuffer(); } diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index 2b02a874..12e64cd4 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -197,6 +197,8 @@ void SwapChainVkImpl::CreateVulkanSwapChain() // If the surface size is defined, the swap chain size must match swapchainExtent = surfCapabilities.currentExtent; } + swapchainExtent.width = std::max(swapchainExtent.width, 1u); + swapchainExtent.height = std::max(swapchainExtent.height, 1u); m_SwapChainDesc.Width = swapchainExtent.width; m_SwapChainDesc.Height = swapchainExtent.height; @@ -475,14 +477,17 @@ void SwapChainVkImpl::Resize( Uint32 NewWidth, Uint32 NewHeight ) // All references to the swap chain must be released before it can be resized m_pBackBufferRTV.clear(); m_pDepthBufferDSV.Release(); - m_ImageAcquiredSemaphores.clear(); - m_DrawCompleteSemaphores.clear(); - m_SemaphoreIndex = 0; // This will release references to Vk swap chain buffers hold by // m_pBackBufferRTV[] pDeviceVk->IdleGPU(true); + // We must wait unitl GPU is idled before destroying semaphores as they + // are destroyed immediately + m_ImageAcquiredSemaphores.clear(); + m_DrawCompleteSemaphores.clear(); + m_SemaphoreIndex = 0; + CreateVulkanSwapChain(); InitBuffersAndViews(); AcquireNextImage(pImmediateCtxVk); |
