summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-04-13 02:34:18 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-04-13 02:34:18 +0000
commit321dfe299cd3b15bd0216113068f13dfa4b99cf0 (patch)
treefcbd6d410bdc1bb5b659471350dddf1e71e615ce /Graphics/GraphicsEngine
parentOptimized memory layout of ObjectBase<> (reduced size by 40 bytes on msvc x64) (diff)
downloadDiligentCore-321dfe299cd3b15bd0216113068f13dfa4b99cf0.tar.gz
DiligentCore-321dfe299cd3b15bd0216113068f13dfa4b99cf0.zip
Updated ALLOCATE macros to make it more convenient
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/DeviceObjectBase.h26
-rw-r--r--Graphics/GraphicsEngine/include/EngineMemory.h3
-rw-r--r--Graphics/GraphicsEngine/include/PipelineStateBase.h10
3 files changed, 19 insertions, 20 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceObjectBase.h b/Graphics/GraphicsEngine/include/DeviceObjectBase.h
index 0ecacb0c..7d83d025 100644
--- a/Graphics/GraphicsEngine/include/DeviceObjectBase.h
+++ b/Graphics/GraphicsEngine/include/DeviceObjectBase.h
@@ -44,16 +44,16 @@ public:
typedef ObjectBase<BaseInterface> TBase;
/// \param pRefCounters - reference counters object that controls the lifetime of this device object
- /// \param pDevice - pointer to the render device.
- /// \param ObjDesc - object description.
- /// \param bIsDeviceInternal - flag indicating if the object is an internal device object
- /// and must not keep a strong reference to the device.
+ /// \param pDevice - pointer to the render device.
+ /// \param ObjDesc - object description.
+ /// \param bIsDeviceInternal - flag indicating if the object is an internal device object
+ /// and must not keep a strong reference to the device.
DeviceObjectBase( IReferenceCounters* pRefCounters,
RenderDeviceImplType* pDevice,
- const ObjectDescType& ObjDesc,
- bool bIsDeviceInternal = false) :
+ const ObjectDescType& ObjDesc,
+ bool bIsDeviceInternal = false) :
TBase(pRefCounters),
- m_pDevice (pDevice),
+ m_pDevice (pDevice),
m_Desc (ObjDesc),
m_bIsDeviceInternal(bIsDeviceInternal)
{
@@ -66,14 +66,14 @@ public:
if (ObjDesc.Name != nullptr)
{
auto size = strlen(ObjDesc.Name) + 1;
- auto* NameCopy = reinterpret_cast<char*>(ALLOCATE(GetStringAllocator(), "Object name copy", size));
+ auto* NameCopy = ALLOCATE(GetStringAllocator(), "Object name copy", char, size);
memcpy(NameCopy, ObjDesc.Name, size);
m_Desc.Name = NameCopy;
}
else
{
size_t size = 16 + 2 + 1; // 0x12345678
- auto* AddressStr = reinterpret_cast<char*>(ALLOCATE(GetStringAllocator(), "Object address string", size));
+ auto* AddressStr = ALLOCATE(GetStringAllocator(), "Object address string", char, size);
snprintf(AddressStr, size, "0x%llX", static_cast<unsigned long long>(reinterpret_cast<size_t>(this)));
m_Desc.Name = AddressStr;
}
@@ -135,10 +135,10 @@ public:
return m_Desc;
}
- /// Returns unique identifier
+ /// Returns unique identifier
UniqueIdentifier GetUniqueID()const
{
- /// \note
+ /// \note
/// This unique ID is used to unambiguously identify device object for
/// tracking purposes.
/// Niether GL handle nor pointer could be safely used for this purpose
@@ -146,13 +146,13 @@ public:
return m_UniqueID.GetID();
}
- RenderDeviceImplType* GetDevice()const{return m_pDevice;}
+ RenderDeviceImplType* GetDevice()const{return m_pDevice;}
protected:
/// Pointer to the device
RenderDeviceImplType* const m_pDevice;
- /// Object description
+ /// Object description
ObjectDescType m_Desc;
// Template argument is only used to separate counters for
diff --git a/Graphics/GraphicsEngine/include/EngineMemory.h b/Graphics/GraphicsEngine/include/EngineMemory.h
index cf84193d..ba80de4b 100644
--- a/Graphics/GraphicsEngine/include/EngineMemory.h
+++ b/Graphics/GraphicsEngine/include/EngineMemory.h
@@ -39,7 +39,8 @@ namespace Diligent
IMemoryAllocator& GetStringAllocator();
-#define ALLOCATE(Allocator, Desc, Size) (Allocator).Allocate(Size, Desc, __FILE__, __LINE__)
+#define ALLOCATE_RAW(Allocator, Desc, Size) (Allocator).Allocate(Size, Desc, __FILE__, __LINE__)
+#define ALLOCATE(Allocator, Desc, Type, Count) reinterpret_cast<Type*>(ALLOCATE_RAW(Allocator, Desc, sizeof(Type) * Count))
#define FREE(Allocator, Ptr) Allocator.Free(Ptr)
}
diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.h b/Graphics/GraphicsEngine/include/PipelineStateBase.h
index 2f27cb6b..110452ff 100644
--- a/Graphics/GraphicsEngine/include/PipelineStateBase.h
+++ b/Graphics/GraphicsEngine/include/PipelineStateBase.h
@@ -84,7 +84,7 @@ public:
if (SrcLayout.Variables != nullptr)
{
ShaderResourceVariableDesc* Variables =
- reinterpret_cast<ShaderResourceVariableDesc*>(ALLOCATE(GetRawAllocator(), "Memory for ShaderResourceVariableDesc array", sizeof(ShaderResourceVariableDesc) * SrcLayout.NumVariables));
+ ALLOCATE(GetRawAllocator(), "Memory for ShaderResourceVariableDesc array", ShaderResourceVariableDesc, SrcLayout.NumVariables);
DstLayout.Variables = Variables;
for (Uint32 i=0; i < SrcLayout.NumVariables; ++i)
{
@@ -97,7 +97,7 @@ public:
if (SrcLayout.StaticSamplers != nullptr)
{
StaticSamplerDesc* StaticSamplers =
- reinterpret_cast<StaticSamplerDesc*>(ALLOCATE(GetRawAllocator(), "Memory for StaticSamplerDesc array", sizeof(StaticSamplerDesc) * SrcLayout.NumStaticSamplers));
+ ALLOCATE(GetRawAllocator(), "Memory for StaticSamplerDesc array", StaticSamplerDesc, SrcLayout.NumStaticSamplers);
DstLayout.StaticSamplers = StaticSamplers;
for (Uint32 i=0; i < SrcLayout.NumStaticSamplers; ++i)
{
@@ -179,8 +179,7 @@ public:
LayoutElement* pLayoutElements = nullptr;
if (InputLayout.NumElements > 0)
{
- auto* pLayoutElementsRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for input layout elements", sizeof(LayoutElement) * InputLayout.NumElements);
- pLayoutElements = reinterpret_cast<LayoutElement*>(pLayoutElementsRawMem);
+ pLayoutElements = ALLOCATE(GetRawAllocator(), "Raw memory for input layout elements", LayoutElement, InputLayout.NumElements);
}
this->m_Desc.GraphicsPipeline.InputLayout.LayoutElements = pLayoutElements;
for (size_t Elem = 0; Elem < InputLayout.NumElements; ++Elem)
@@ -256,8 +255,7 @@ public:
if (m_BufferSlotsUsed > 0)
{
- auto* pStridesRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for buffer strides", sizeof(Uint32) * m_BufferSlotsUsed);
- m_pStrides = reinterpret_cast<Uint32*>(pStridesRawMem);
+ m_pStrides = ALLOCATE(GetRawAllocator(), "Raw memory for buffer strides", Uint32, m_BufferSlotsUsed);
// Set strides for all unused slots to 0
for (Uint32 i=0; i < m_BufferSlotsUsed; ++i)