From 4a3803e1de2669fb546bff0396f083766fad402e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 30 Oct 2019 09:57:39 -0700 Subject: Added methods to get command queue from the device context (API Version 240038) --- .../include/DeviceContextNextGenBase.h | 34 ++++++++++++++++++---- .../include/RenderDeviceNextGenBase.h | 19 ++++++++++-- 2 files changed, 46 insertions(+), 7 deletions(-) (limited to 'Graphics/GraphicsEngineNextGenBase') diff --git a/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.h b/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.h index 14f105d4..f92c0d93 100644 --- a/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.h +++ b/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.h @@ -27,16 +27,21 @@ #include "BasicTypes.h" #include "ReferenceCounters.h" #include "RefCntAutoPtr.h" +#include "DeviceContextBase.h" namespace Diligent { /// Base implementation of the device context for next-generation backends. -template -class DeviceContextNextGenBase : public TBase +template +class DeviceContextNextGenBase : public DeviceContextBase { public: + using TBase = DeviceContextBase; + using DeviceImplType = typename ImplementationTraits::DeviceType; + using ICommandQueueType = typename ImplementationTraits::ICommandQueueType; + DeviceContextNextGenBase(IReferenceCounters* pRefCounters, IRenderDevice* pRenderDevice, Uint32 ContextId, @@ -58,11 +63,30 @@ public: { } + virtual ICommandQueueType* LockCommandQueue()override final + { + if (m_bIsDeferred) + { + LOG_WARNING_MESSAGE("Deferred contexts have no associated command queues"); + return nullptr; + } + return m_pDevice.RawPtr()->LockCommandQueue(m_CommandQueueId); + } + + virtual void UnlockCommandQueue() + { + if (m_bIsDeferred) + { + LOG_WARNING_MESSAGE("Deferred contexts have no associated command queues"); + return; + } + m_pDevice.RawPtr()->UnlockCommandQueue(m_CommandQueueId); + } + protected: // Should be called at the end of FinishFrame() - template - void EndFrame(RenderDeviceImplType& RenderDeviceImpl) + void EndFrame() { if (this->m_bIsDeferred) { @@ -71,7 +95,7 @@ protected: } else { - RenderDeviceImpl.FlushStaleResources(m_CommandQueueId); + m_pDevice.RawPtr()->FlushStaleResources(m_CommandQueueId); } Atomics::AtomicIncrement(m_ContextFrameNumber); } diff --git a/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h b/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h index 135dd941..41ceadfb 100644 --- a/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h +++ b/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h @@ -230,7 +230,7 @@ public: return m_CommandQueues[QueueIndex].ReleaseQueue; } - const CommandQueueType& GetCommandQueue(Uint32 QueueIndex) + const CommandQueueType& GetCommandQueue(Uint32 QueueIndex)const { VERIFY_EXPR(QueueIndex < m_CmdQueueCount); return *m_CommandQueues[QueueIndex].CmdQueue; @@ -252,7 +252,7 @@ public: } template - void LockCommandQueue(Uint32 QueueIndex, TAction Action) + void LockCmdQueueAndRun(Uint32 QueueIndex, TAction Action) { VERIFY_EXPR(QueueIndex < m_CmdQueueCount); auto& Queue = m_CommandQueues[QueueIndex]; @@ -260,6 +260,21 @@ public: Action(Queue.CmdQueue); } + CommandQueueType* LockCommandQueue(Uint32 QueueIndex) + { + VERIFY_EXPR(QueueIndex < m_CmdQueueCount); + auto& Queue = m_CommandQueues[QueueIndex]; + Queue.Mtx.lock(); + return Queue.CmdQueue; + } + + void UnlockCommandQueue(Uint32 QueueIndex) + { + VERIFY_EXPR(QueueIndex < m_CmdQueueCount); + auto& Queue = m_CommandQueues[QueueIndex]; + Queue.Mtx.unlock(); + } + protected: void DestroyCommandQueues() { -- cgit v1.2.3