From 0e77fa7493bdb5916315740b4f5fc536f439280c Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 24 Apr 2018 08:22:16 -0700 Subject: Fixed a number of synchronization issues in Vulkan --- Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h | 5 ++--- .../include/VulkanUtilities/VulkanCommandBufferPool.h | 2 ++ Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 3 +++ Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp | 1 + Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 1 + .../src/VulkanUtilities/VulkanCommandBufferPool.cpp | 7 +++++++ 6 files changed, 16 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index 9bc54e82..7c87e5fb 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -134,9 +134,6 @@ private: void CommitViewports(); void CommitScissorRects(); -#if 0 - friend class SwapChainVkImpl; -#endif inline void EnsureVkCmdBuffer(); inline void DisposeVkCmdBuffer(); @@ -171,8 +168,10 @@ private: FixedBlockMemoryAllocator m_CmdListAllocator; const Uint32 m_ContextId; #endif + VulkanUtilities::VulkanCommandBufferPool m_CmdPool; + // Semaphores are not owned by the command context std::vector m_WaitSemaphores; std::vector m_WaitDstStageMasks; std::vector m_SignalSemaphores; diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBufferPool.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBufferPool.h index 22429fe8..d898bae2 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBufferPool.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBufferPool.h @@ -45,6 +45,8 @@ namespace VulkanUtilities VkCommandBuffer GetCommandBuffer(uint64_t LastCompletedFence, const char* DebugName = ""); void DisposeCommandBuffer(VkCommandBuffer CmdBuffer, uint64_t FenceValue); + + CommandPoolWrapper&& Release(); private: // Shared point to logical device must be defined before the command pool diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 0297f4a3..32e8116e 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -84,6 +84,9 @@ namespace Diligent Flush(); } + + auto VkCmdPool = m_CmdPool.Release(); + m_pDevice.RawPtr()->SafeReleaseVkObject(std::move(VkCmdPool)); } IMPLEMENT_QUERY_INTERFACE( DeviceContextVkImpl, IID_DeviceContextVk, TDeviceContextBase ) diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 6d370ca0..3d77fa07 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -406,6 +406,7 @@ template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUt template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::DescriptorPoolWrapper &&Object); template void RenderDeviceVkImpl::SafeReleaseVkObject(VulkanUtilities::DescriptorSetLayoutWrapper &&Object); template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::SemaphoreWrapper &&Object); +template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::CommandPoolWrapper &&Object); void RenderDeviceVkImpl::DiscardStaleVkObjects(Uint64 CmdListNumber, Uint64 FenceValue) diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index 03722eb8..cb00e700 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -321,6 +321,7 @@ SwapChainVkImpl::~SwapChainVkImpl() if(m_VkSwapChain != VK_NULL_HANDLE) { auto *pDeviceVkImpl = m_pRenderDevice.RawPtr(); + pDeviceVkImpl->IdleGPU(true); vkDestroySwapchainKHR(pDeviceVkImpl->GetVkDevice(), m_VkSwapChain, NULL); } } diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanCommandBufferPool.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanCommandBufferPool.cpp index d94a83f3..b5ec40b0 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanCommandBufferPool.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanCommandBufferPool.cpp @@ -112,4 +112,11 @@ namespace VulkanUtilities // executed the command buffer m_DiscardedCmdBuffers.emplace_back(FenceValue, CmdBuffer); } + + CommandPoolWrapper&& VulkanCommandBufferPool::Release() + { + m_LogicalDevice.reset(); + m_DiscardedCmdBuffers.clear(); + return std::move(m_CmdPool); + } } -- cgit v1.2.3