From 9286fdcd21cfa7cdbc70a42d6bd1ea2d7b907e5e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 1 Oct 2018 23:17:55 -0700 Subject: Reworked D3D12DynamicHeap to use release queues --- .../include/DeviceContextVkImpl.h | 17 +++----------- .../src/DeviceContextVkImpl.cpp | 26 ++++++++++------------ 2 files changed, 15 insertions(+), 28 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index cd598c40..71f7a28c 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -29,6 +29,7 @@ #include "DeviceContextVk.h" #include "DeviceContextBase.h" +#include "DeviceContextNextGenBase.h" #include "VulkanUtilities/VulkanCommandBufferPool.h" #include "VulkanUtilities/VulkanCommandBuffer.h" #include "VulkanUploadHeap.h" @@ -46,10 +47,10 @@ namespace Diligent { /// Implementation of the Diligent::IDeviceContext interface -class DeviceContextVkImpl final : public DeviceContextBase +class DeviceContextVkImpl final : public DeviceContextNextGenBase< DeviceContextBase > { public: - using TDeviceContextBase = DeviceContextBase; + using TDeviceContextBase = DeviceContextNextGenBase< DeviceContextBase >; DeviceContextVkImpl(IReferenceCounters* pRefCounters, class RenderDeviceVkImpl* pDevice, @@ -233,16 +234,6 @@ private: FixedBlockMemoryAllocator m_CmdListAllocator; - const Uint32 m_ContextId; - const Uint32 m_CommandQueueId; - - // This mask indicates which command queues command buffers from this context were submitted to. - // For immediate context, this will always be 1 << m_CommandQueueId. - // For deferred contexts, this will accumulate bits of the queues to which command buffers - // were submitted to before FinishFrame() was called. This mask is used to release resources - // allocated by the context during the frame when FinishFrame() is called. - Uint64 m_SubmittedBuffersCmdQueueMask = 0; - // Semaphores are not owned by the command context std::vector m_WaitSemaphores; std::vector m_WaitDstStageMasks; @@ -286,8 +277,6 @@ private: VulkanDynamicHeap m_DynamicHeap; DynamicDescriptorSetAllocator m_DynamicDescrSetAllocator; - Atomics::AtomicInt64 m_ContextFrameNumber; - PipelineLayout::DescriptorSetBindInfo m_DescrSetBindInfo; std::shared_ptr m_GenerateMipsHelper; RefCntAutoPtr m_GenerateMipsSRB; diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 202babab..d7e572ac 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -52,12 +52,16 @@ namespace Diligent Uint32 ContextId, Uint32 CommandQueueId, std::shared_ptr GenerateMipsHelper) : - TDeviceContextBase {pRefCounters, pDeviceVkImpl, bIsDeferred}, - m_NumCommandsToFlush {bIsDeferred ? std::numeric_limits::max() : Attribs.NumCommandsToFlushCmdBuffer}, - m_CmdListAllocator { GetRawAllocator(), sizeof(CommandListVkImpl), 64 }, - m_ContextId {ContextId}, - m_CommandQueueId {CommandQueueId}, - m_SubmittedBuffersCmdQueueMask{bIsDeferred ? 0 : Uint64{1} << CommandQueueId}, + TDeviceContextBase + { + pRefCounters, + pDeviceVkImpl, + ContextId, + CommandQueueId, + bIsDeferred ? std::numeric_limits::max() : Attribs.NumCommandsToFlushCmdBuffer, + bIsDeferred + }, + m_CmdListAllocator { GetRawAllocator(), sizeof(CommandListVkImpl), 64 }, // Command pools must be thread safe because command buffers are returned into pools by release queues // potentially running in another thread m_CmdPool @@ -84,7 +88,6 @@ namespace Diligent pDeviceVkImpl->GetDynamicDescriptorPool(), GetContextObjectName("Dynamic descriptor set allocator", bIsDeferred, ContextId), }, - m_ContextFrameNumber(0), m_GenerateMipsHelper(std::move(GenerateMipsHelper)) { m_GenerateMipsHelper->CreateSRB(&m_GenerateMipsSRB); @@ -774,18 +777,13 @@ namespace Diligent // be destroyed before the pools are actually returned to the global pool manager. m_DynamicDescrSetAllocator.ReleasePools(m_SubmittedBuffersCmdQueueMask); - if (m_bIsDeferred) - { - // For deferred context, reset submitted cmd queue mask - m_SubmittedBuffersCmdQueueMask = 0; - } - else + if (!m_bIsDeferred) { // Make all stale resource move into the release queue DeviceVkImpl.FlushStaleResources(m_CommandQueueId); } - Atomics::AtomicIncrement(m_ContextFrameNumber); + EndFrame(); } void DeviceContextVkImpl::Flush() -- cgit v1.2.3