summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-03-21 03:26:24 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-03-21 03:26:24 +0000
commita0465cee3a1868a717e9180373e95ef551c09296 (patch)
tree58bd0054b385d32cf63860297bd64b3c37717fcf /Graphics/GraphicsEngineVulkan
parentExplicitly waiting on fences to avoid indefinite command queue growth in Vulk... (diff)
downloadDiligentCore-a0465cee3a1868a717e9180373e95ef551c09296.tar.gz
DiligentCore-a0465cee3a1868a717e9180373e95ef551c09296.zip
Fixed Vulkan validation layer warnings when resizing the window
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp
index 71629388..3587d8e7 100644
--- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp
@@ -344,7 +344,7 @@ SwapChainVkImpl::~SwapChainVkImpl()
void SwapChainVkImpl::InitBuffersAndViews()
{
- auto *pDeviceVkImpl = m_pRenderDevice.RawPtr<RenderDeviceVkImpl>();
+ auto* pDeviceVkImpl = m_pRenderDevice.RawPtr<RenderDeviceVkImpl>();
auto LogicalVkDevice = pDeviceVkImpl->GetVkDevice();
#ifdef _DEBUG
@@ -435,7 +435,7 @@ VkResult SwapChainVkImpl::AcquireNextImage(DeviceContextVkImpl* pDeviceCtxVk)
// When acquiring swap chain image for frame N, we need to make sure that
// frame N-Nsc has completed. To achieve that, we wait for the image acquire
// fence for frame N-Nsc-1. Thus we will have no more than Nsc frames in the queue.
- auto OldestSubmittedImageFenceInd = (m_SemaphoreIndex+1u) % static_cast<Uint32>(m_ImageAcquiredFenceSubmitted.size());
+ auto OldestSubmittedImageFenceInd = (m_SemaphoreIndex + 1u) % static_cast<Uint32>(m_ImageAcquiredFenceSubmitted.size());
if (m_ImageAcquiredFenceSubmitted[OldestSubmittedImageFenceInd])
{
VkFence OldestSubmittedFence = m_ImageAcquiredFences[OldestSubmittedImageFenceInd];
@@ -445,6 +445,7 @@ VkResult SwapChainVkImpl::AcquireNextImage(DeviceContextVkImpl* pDeviceCtxVk)
VERIFY_EXPR(res == VK_SUCCESS); (void)res;
}
LogicalDevice.ResetFence(OldestSubmittedFence);
+ m_ImageAcquiredFenceSubmitted[OldestSubmittedImageFenceInd] = false;
}
VkFence ImageAcquiredFence = m_ImageAcquiredFences [m_SemaphoreIndex];
@@ -560,17 +561,32 @@ void SwapChainVkImpl::RecreateVulkanSwapchain(DeviceContextVkImpl* pImmediateCtx
if (pImmediateCtxVk->IsDefaultFBBound())
pImmediateCtxVk->ResetRenderTargets();
+ RenderDeviceVkImpl* pDeviceVk = m_pRenderDevice.RawPtr<RenderDeviceVkImpl>();
+ const auto& LogicalDevice = pDeviceVk->GetLogicalDevice();
+
+ // This will release references to Vk swap chain buffers hold by
+ // m_pBackBufferRTV[].
+ pDeviceVk->IdleGPU();
+
+ // We need to explicitly wait for all submitted Image Acquired Fences to signal.
+ // Just idling the GPU is not enough and results in validation warnings.
+ // As a matter of fact, it is only required to check the fence status.
+ for(size_t i=0; i < m_ImageAcquiredFences.size(); ++i)
+ {
+ if (m_ImageAcquiredFenceSubmitted[i])
+ {
+ VkFence vkFence = m_ImageAcquiredFences[i];
+ if (LogicalDevice.GetFenceStatus(vkFence) != VK_SUCCESS)
+ LogicalDevice.WaitForFences(1, &vkFence, VK_TRUE, UINT64_MAX);
+ }
+ }
+
// All references to the swap chain must be released before it can be resized
m_pBackBufferRTV.clear();
m_SwapChainImagesInitialized.clear();
m_ImageAcquiredFenceSubmitted.clear();
m_pDepthBufferDSV.Release();
- RenderDeviceVkImpl* pDeviceVk = m_pRenderDevice.RawPtr<RenderDeviceVkImpl>();
- // This will release references to Vk swap chain buffers hold by
- // m_pBackBufferRTV[]
- pDeviceVk->IdleGPU();
-
// We must wait unitl GPU is idled before destroying semaphores as they
// are destroyed immediately
m_ImageAcquiredSemaphores.clear();