summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineNextGenBase
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-11-24 02:41:15 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-11-24 02:41:15 +0000
commit52f884380f5954f3d1f0543d3482b89951f3e70e (patch)
tree202bfad4be6d8f40733fc1a7ce9e61f6f4f99566 /Graphics/GraphicsEngineNextGenBase
parentclang-formatted GraphicsEngineD3DBase project (diff)
downloadDiligentCore-52f884380f5954f3d1f0543d3482b89951f3e70e.tar.gz
DiligentCore-52f884380f5954f3d1f0543d3482b89951f3e70e.zip
clang-formatted GraphicsEngineNextGenBase project
Diffstat (limited to 'Graphics/GraphicsEngineNextGenBase')
-rw-r--r--Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.h19
-rw-r--r--Graphics/GraphicsEngineNextGenBase/include/DynamicHeap.h59
-rw-r--r--Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h70
-rw-r--r--Graphics/GraphicsEngineNextGenBase/src/dummy.cpp1
4 files changed, 81 insertions, 68 deletions
diff --git a/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.h b/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.h
index 5a22e919..c8f89b08 100644
--- a/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.h
+++ b/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.h
@@ -35,7 +35,7 @@ namespace Diligent
/// Base implementation of the device context for next-generation backends.
-template<typename BaseInterface, typename ImplementationTraits>
+template <typename BaseInterface, typename ImplementationTraits>
class DeviceContextNextGenBase : public DeviceContextBase<BaseInterface, ImplementationTraits>
{
public:
@@ -49,12 +49,14 @@ public:
Uint32 CommandQueueId,
Uint32 NumCommandsToFlush,
bool bIsDeferred) :
+ // clang-format off
TBase{pRefCounters, pRenderDevice, bIsDeferred},
m_ContextId {ContextId },
m_CommandQueueId {CommandQueueId },
m_NumCommandsToFlush {NumCommandsToFlush},
m_ContextFrameNumber {0},
m_SubmittedBuffersCmdQueueMask{bIsDeferred ? 0 : Uint64{1} << Uint64{CommandQueueId}}
+ // clang-format on
{
}
@@ -62,7 +64,7 @@ public:
{
}
- virtual ICommandQueueType* LockCommandQueue()override final
+ virtual ICommandQueueType* LockCommandQueue() override final
{
if (this->m_bIsDeferred)
{
@@ -72,7 +74,7 @@ public:
return this->m_pDevice->LockCommandQueue(m_CommandQueueId);
}
- virtual void UnlockCommandQueue()override final
+ virtual void UnlockCommandQueue() override final
{
if (this->m_bIsDeferred)
{
@@ -83,7 +85,6 @@ public:
}
protected:
-
// Should be called at the end of FinishFrame()
void EndFrame()
{
@@ -99,17 +100,17 @@ protected:
Atomics::AtomicIncrement(m_ContextFrameNumber);
}
- const Uint32 m_ContextId;
- const Uint32 m_CommandQueueId;
- const Uint32 m_NumCommandsToFlush;
+ const Uint32 m_ContextId;
+ const Uint32 m_CommandQueueId;
+ const Uint32 m_NumCommandsToFlush;
Atomics::AtomicInt64 m_ContextFrameNumber;
// 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 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;
};
-}
+} // namespace Diligent
diff --git a/Graphics/GraphicsEngineNextGenBase/include/DynamicHeap.h b/Graphics/GraphicsEngineNextGenBase/include/DynamicHeap.h
index 7e8c8849..6f69a9f7 100644
--- a/Graphics/GraphicsEngineNextGenBase/include/DynamicHeap.h
+++ b/Graphics/GraphicsEngineNextGenBase/include/DynamicHeap.h
@@ -39,7 +39,7 @@ namespace Diligent
namespace DynamicHeap
{
-
+
// Having global ring buffer shared between all contexts is inconvinient because all contexts
// must share the same frame. Having individual ring bufer per context may result in a lot of unused
// memory. As a result, ring buffer is not currently used for dynamic memory management.
@@ -47,19 +47,21 @@ namespace DynamicHeap
class MasterBlockRingBufferBasedManager
{
public:
- using OffsetType = RingBuffer::OffsetType;
- using MasterBlock = RingBuffer::OffsetType;
+ using OffsetType = RingBuffer::OffsetType;
+ using MasterBlock = RingBuffer::OffsetType;
static constexpr const OffsetType InvalidOffset = RingBuffer::InvalidOffset;
- MasterBlockRingBufferBasedManager(IMemoryAllocator& Allocator,
- Uint32 Size) :
- m_RingBuffer(Size, Allocator)
+ MasterBlockRingBufferBasedManager(IMemoryAllocator& Allocator,
+ Uint32 Size) :
+ m_RingBuffer{Size, Allocator}
{}
+ // clang-format off
MasterBlockRingBufferBasedManager (const MasterBlockRingBufferBasedManager&) = delete;
MasterBlockRingBufferBasedManager ( MasterBlockRingBufferBasedManager&&) = delete;
MasterBlockRingBufferBasedManager& operator= (const MasterBlockRingBufferBasedManager&) = delete;
MasterBlockRingBufferBasedManager& operator= ( MasterBlockRingBufferBasedManager&&) = delete;
+ // clang-format on
void DiscardMasterBlocks(std::vector<MasterBlock>& /*Blocks*/, Uint64 FenceValue)
{
@@ -73,8 +75,8 @@ public:
m_RingBuffer.ReleaseCompletedFrames(LastCompletedFenceValue);
}
- OffsetType GetSize() const { return m_RingBuffer.GetMaxSize(); }
- OffsetType GetUsedSize()const { return m_RingBuffer.GetUsedSize(); }
+ OffsetType GetSize() const { return m_RingBuffer.GetMaxSize(); }
+ OffsetType GetUsedSize() const { return m_RingBuffer.GetUsedSize(); }
protected:
MasterBlock AllocateMasterBlock(OffsetType SizeInBytes, OffsetType Alignment)
@@ -95,26 +97,28 @@ public:
using OffsetType = VariableSizeAllocationsManager::OffsetType;
using MasterBlock = VariableSizeAllocationsManager::Allocation;
- MasterBlockListBasedManager(IMemoryAllocator& Allocator,
- Uint32 Size) :
- m_AllocationsMgr(Size, Allocator)
+ MasterBlockListBasedManager(IMemoryAllocator& Allocator,
+ Uint32 Size) :
+ m_AllocationsMgr{Size, Allocator}
{
#ifdef DEVELOPMENT
m_MasterBlockCounter = 0;
#endif
}
+ // clang-format off
MasterBlockListBasedManager (const MasterBlockListBasedManager&) = delete;
MasterBlockListBasedManager ( MasterBlockListBasedManager&&) = delete;
MasterBlockListBasedManager& operator= (const MasterBlockListBasedManager&) = delete;
MasterBlockListBasedManager& operator= ( MasterBlockListBasedManager&&) = delete;
+ // clang-format on
~MasterBlockListBasedManager()
{
DEV_CHECK_ERR(m_MasterBlockCounter == 0, m_MasterBlockCounter, " master block(s) have not been returned to the manager");
}
- template<typename RenderDeviceImplType>
+ template <typename RenderDeviceImplType>
void ReleaseMasterBlocks(std::vector<MasterBlock>& Blocks, RenderDeviceImplType& Device, Uint64 CmdQueueMask)
{
struct StaleMasterBlock
@@ -122,9 +126,10 @@ public:
MasterBlock Block;
MasterBlockListBasedManager* Mgr;
+ // clang-format off
StaleMasterBlock(MasterBlock&& _Block, MasterBlockListBasedManager* _Mgr)noexcept :
- Block (std::move(_Block)),
- Mgr (_Mgr)
+ Block {std::move(_Block)},
+ Mgr {_Mgr }
{
}
@@ -133,12 +138,13 @@ public:
StaleMasterBlock& operator= ( StaleMasterBlock&&) = delete;
StaleMasterBlock(StaleMasterBlock&& rhs)noexcept :
- Block (std::move(rhs.Block)),
- Mgr (rhs.Mgr)
+ Block {std::move(rhs.Block)},
+ Mgr {rhs.Mgr }
{
rhs.Block = MasterBlock{};
rhs.Mgr = nullptr;
}
+ // clang-format on
~StaleMasterBlock()
{
@@ -152,25 +158,30 @@ public:
}
}
};
- for(auto& Block : Blocks)
+ for (auto& Block : Blocks)
{
DEV_CHECK_ERR(Block.IsValid(), "Attempting to release invalid master block");
Device.SafeReleaseDeviceObject(StaleMasterBlock{std::move(Block), this}, CmdQueueMask);
}
}
- OffsetType GetSize() const { return m_AllocationsMgr.GetMaxSize(); }
- OffsetType GetUsedSize()const { return m_AllocationsMgr.GetUsedSize();}
+ // clang-format off
+ OffsetType GetSize() const { return m_AllocationsMgr.GetMaxSize(); }
+ OffsetType GetUsedSize() const { return m_AllocationsMgr.GetUsedSize();}
+ // clang-format on
#ifdef DEVELOPMENT
- int32_t GetMasterBlockCounter()const{return m_MasterBlockCounter;}
+ int32_t GetMasterBlockCounter() const
+ {
+ return m_MasterBlockCounter;
+ }
#endif
protected:
MasterBlock AllocateMasterBlock(OffsetType SizeInBytes, OffsetType Alignment)
{
std::lock_guard<std::mutex> Lock{m_AllocationsMgrMtx};
- auto NewBlock = m_AllocationsMgr.Allocate(SizeInBytes, Alignment);
+ auto NewBlock = m_AllocationsMgr.Allocate(SizeInBytes, Alignment);
#ifdef DEVELOPMENT
if (NewBlock.IsValid())
{
@@ -181,11 +192,11 @@ protected:
}
private:
- std::mutex m_AllocationsMgrMtx;
- VariableSizeAllocationsManager m_AllocationsMgr;
+ std::mutex m_AllocationsMgrMtx;
+ VariableSizeAllocationsManager m_AllocationsMgr;
#ifdef DEVELOPMENT
- std::atomic_int32_t m_MasterBlockCounter;
+ std::atomic_int32_t m_MasterBlockCounter;
#endif
};
diff --git a/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h b/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h
index 41ceadfb..05ee8234 100644
--- a/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h
+++ b/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h
@@ -41,25 +41,25 @@ namespace Diligent
/// Base implementation of the render device for next-generation backends.
-template<class TBase, typename CommandQueueType>
+template <class TBase, typename CommandQueueType>
class RenderDeviceNextGenBase : public TBase
{
public:
using typename TBase::DeviceObjectSizes;
- RenderDeviceNextGenBase(IReferenceCounters* pRefCounters,
- IMemoryAllocator& RawMemAllocator,
+ RenderDeviceNextGenBase(IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
IEngineFactory* pEngineFactory,
size_t CmdQueueCount,
CommandQueueType** Queues,
Uint32 NumDeferredContexts,
const DeviceObjectSizes& ObjectSizes) :
- TBase (pRefCounters, RawMemAllocator, pEngineFactory, NumDeferredContexts, ObjectSizes),
- m_CmdQueueCount (CmdQueueCount)
+ TBase{pRefCounters, RawMemAllocator, pEngineFactory, NumDeferredContexts, ObjectSizes},
+ m_CmdQueueCount{CmdQueueCount}
{
m_CommandQueues = ALLOCATE(this->m_RawMemAllocator, "Raw memory for the device command/release queues", CommandQueue, m_CmdQueueCount);
- for(size_t q=0; q < m_CmdQueueCount; ++q)
- new(m_CommandQueues+q)CommandQueue(RefCntAutoPtr<CommandQueueType>(Queues[q]), this->m_RawMemAllocator);
+ for (size_t q = 0; q < m_CmdQueueCount; ++q)
+ new (m_CommandQueues + q) CommandQueue(RefCntAutoPtr<CommandQueueType>(Queues[q]), this->m_RawMemAllocator);
}
~RenderDeviceNextGenBase()
@@ -87,23 +87,23 @@ public:
// . . . . .
// -----------------------------.--------------.---------------.-------------------.----------------.-------------
// . . . . .
- //
+ //
// GPU | Cmd List N-2 | Cmd List N-1 | Cmd List N | Cmd List N+1 |
// |
// |
// Resource X can
// be released
- template<typename ObjectType, typename = typename std::enable_if<std::is_object<ObjectType>::value>::type>
+ template <typename ObjectType, typename = typename std::enable_if<std::is_object<ObjectType>::value>::type>
void SafeReleaseDeviceObject(ObjectType&& Object, Uint64 QueueMask)
{
QueueMask &= GetCommandQueueMask();
-
+
VERIFY(QueueMask != 0, "At least one bit should be set in the command queue mask");
if (QueueMask == 0)
return;
Atomics::Long NumReferences = PlatformMisc::CountOneBits(QueueMask);
- auto Wrapper = DynamicStaleResourceWrapper::Create(std::move(Object), NumReferences);
+ auto Wrapper = DynamicStaleResourceWrapper::Create(std::move(Object), NumReferences);
while (QueueMask != 0)
{
@@ -120,28 +120,28 @@ public:
Wrapper.GiveUpOwnership();
}
-
- size_t GetCommandQueueCount()const
+
+ size_t GetCommandQueueCount() const
{
return m_CmdQueueCount;
}
- Uint64 GetCommandQueueMask()const
+ Uint64 GetCommandQueueMask() const
{
return (m_CmdQueueCount < 64) ? ((Uint64{1} << Uint64{m_CmdQueueCount}) - 1) : ~Uint64{0};
}
void PurgeReleaseQueues(bool ForceRelease = false)
{
- for(Uint32 q=0; q < m_CmdQueueCount; ++q)
+ for (Uint32 q = 0; q < m_CmdQueueCount; ++q)
PurgeReleaseQueue(q, ForceRelease);
}
void PurgeReleaseQueue(Uint32 QueueIndex, bool ForceRelease = false)
{
VERIFY_EXPR(QueueIndex < m_CmdQueueCount);
- auto& Queue = m_CommandQueues[QueueIndex];
- auto CompletedFenceValue = ForceRelease ? std::numeric_limits<Uint64>::max() : Queue.CmdQueue->GetCompletedFenceValue();
+ auto& Queue = m_CommandQueues[QueueIndex];
+ auto CompletedFenceValue = ForceRelease ? std::numeric_limits<Uint64>::max() : Queue.CmdQueue->GetCompletedFenceValue();
Queue.ReleaseQueue.Purge(CompletedFenceValue);
}
@@ -176,7 +176,7 @@ public:
void IdleAllCommandQueues(bool ReleaseResources)
{
- for(size_t q=0; q < m_CmdQueueCount; ++q)
+ for (size_t q = 0; q < m_CmdQueueCount; ++q)
IdleCommandQueue(q, ReleaseResources);
}
@@ -185,7 +185,7 @@ public:
Uint64 CmdBufferNumber = 0;
Uint64 FenceValue = 0;
};
- template<typename SubmitDataType>
+ template <typename SubmitDataType>
SubmittedCommandBufferInfo SubmitCommandBuffer(Uint32 QueueIndex, SubmitDataType& SubmitData, bool DiscardStaleResources)
{
SubmittedCommandBufferInfo CmdBuffInfo;
@@ -212,8 +212,8 @@ public:
//
// Move stale objects into the release queue.
- // Note that objects are moved from stale list to release queue based on the cmd buffer number,
- // not fence value. This makes sure that basic requirement is met even when the fence value is
+ // Note that objects are moved from stale list to release queue based on the cmd buffer number,
+ // not fence value. This makes sure that basic requirement is met even when the fence value is
// not incremented while executing the command buffer (as is the case with Unity command queue).
// As long as resources used by deferred contexts are not released before the command list
@@ -230,7 +230,7 @@ public:
return m_CommandQueues[QueueIndex].ReleaseQueue;
}
- const CommandQueueType& GetCommandQueue(Uint32 QueueIndex)const
+ const CommandQueueType& GetCommandQueue(Uint32 QueueIndex) const
{
VERIFY_EXPR(QueueIndex < m_CmdQueueCount);
return *m_CommandQueues[QueueIndex].CmdQueue;
@@ -251,11 +251,11 @@ public:
return FenceValue <= GetCompletedFenceValue(QueueIndex);
}
- template<typename TAction>
+ template <typename TAction>
void LockCmdQueueAndRun(Uint32 QueueIndex, TAction Action)
{
VERIFY_EXPR(QueueIndex < m_CmdQueueCount);
- auto& Queue = m_CommandQueues[QueueIndex];
+ auto& Queue = m_CommandQueues[QueueIndex];
std::lock_guard<std::mutex> Lock{Queue.Mtx};
Action(Queue.CmdQueue);
}
@@ -280,7 +280,7 @@ protected:
{
if (m_CommandQueues != nullptr)
{
- for(size_t q=0; q < m_CmdQueueCount; ++q)
+ for (size_t q = 0; q < m_CmdQueueCount; ++q)
{
auto& Queue = m_CommandQueues[q];
DEV_CHECK_ERR(Queue.ReleaseQueue.GetStaleResourceCount() == 0, "All stale resources must be released before destroying a command queue");
@@ -294,18 +294,20 @@ protected:
struct CommandQueue
{
- CommandQueue(RefCntAutoPtr<CommandQueueType> _CmdQueue, IMemoryAllocator& Allocator)noexcept :
- CmdQueue (std::move(_CmdQueue)),
- ReleaseQueue(Allocator)
+ CommandQueue(RefCntAutoPtr<CommandQueueType> _CmdQueue, IMemoryAllocator& Allocator) noexcept :
+ CmdQueue{std::move(_CmdQueue)},
+ ReleaseQueue{Allocator}
{
NextCmdBufferNumber = 0;
}
- CommandQueue (const CommandQueue& rhs) = delete;
- CommandQueue ( CommandQueue&& rhs) = delete;
- CommandQueue& operator = (const CommandQueue& rhs) = delete;
- CommandQueue& operator = ( CommandQueue&& rhs) = delete;
-
+ // clang-format off
+ CommandQueue (const CommandQueue&) = delete;
+ CommandQueue ( CommandQueue&&) = delete;
+ CommandQueue& operator = (const CommandQueue&) = delete;
+ CommandQueue& operator = ( CommandQueue&&) = delete;
+ // clang-format on
+
std::mutex Mtx;
Atomics::AtomicInt64 NextCmdBufferNumber;
RefCntAutoPtr<CommandQueueType> CmdQueue;
@@ -315,4 +317,4 @@ protected:
CommandQueue* m_CommandQueues = nullptr;
};
-}
+} // namespace Diligent
diff --git a/Graphics/GraphicsEngineNextGenBase/src/dummy.cpp b/Graphics/GraphicsEngineNextGenBase/src/dummy.cpp
index 35d78452..0e2c170e 100644
--- a/Graphics/GraphicsEngineNextGenBase/src/dummy.cpp
+++ b/Graphics/GraphicsEngineNextGenBase/src/dummy.cpp
@@ -22,4 +22,3 @@
*/
#include "RenderDeviceNextGenBase.h"
-