From 079680f868c1ec09013e62efde42fdd95cc1347c Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 15 Apr 2019 21:41:20 -0700 Subject: Fixed issue with FenceVkImpl not waiting for Vulkan fences to signal when being destroyed, which causes Vulkan validation errors. --- Graphics/GraphicsEngine/interface/Fence.h | 5 ++++- Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp | 13 +++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngine/interface/Fence.h b/Graphics/GraphicsEngine/interface/Fence.h index d2a27473..ef27e5df 100644 --- a/Graphics/GraphicsEngine/interface/Fence.h +++ b/Graphics/GraphicsEngine/interface/Fence.h @@ -43,7 +43,10 @@ struct FenceDesc : DeviceObjectAttribs /// Fence interface -/// Fence the methods to manipulate a fence object +/// Defines the methods to manipulate a fence object +/// +/// \remarks When a fence that was previously signaled by IDeviceContext::SignalFence() is destroyed, +/// it may block the GPU until all prior commands have completed execution. class IFence : public IDeviceObject { public: diff --git a/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp index 12273300..3314598a 100644 --- a/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp @@ -41,10 +41,15 @@ FenceVkImpl :: FenceVkImpl(IReferenceCounters* pRefCounters, FenceVkImpl :: ~FenceVkImpl() { - // Do not dispose pending fences as the pool checks that the fence - // is signaled, while pending fences may not be. - // The pool will be destroyed next anyway, so it makes no difference. - m_PendingFences.clear(); + if (!m_PendingFences.empty()) + { + LOG_INFO_MESSAGE("FenceVkImpl::~FenceVkImpl(): waiting for ", m_PendingFences.size(), " pending Vulkan ", + (m_PendingFences.size() > 1 ? "fences." : "fence.")); + // Vulkan spec states that all queue submission commands that refer to + // a fence must have completed execution before the fence is destroyed. + // (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-vkDestroyFence-fence-01120) + Wait(); + } } Uint64 FenceVkImpl :: GetCompletedValue() -- cgit v1.2.3