diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-04-13 02:34:18 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-04-13 02:34:18 +0000 |
| commit | 321dfe299cd3b15bd0216113068f13dfa4b99cf0 (patch) | |
| tree | fcbd6d410bdc1bb5b659471350dddf1e71e615ce /Graphics | |
| parent | Optimized memory layout of ObjectBase<> (reduced size by 40 bytes on msvc x64) (diff) | |
| download | DiligentCore-321dfe299cd3b15bd0216113068f13dfa4b99cf0.tar.gz DiligentCore-321dfe299cd3b15bd0216113068f13dfa4b99cf0.zip | |
Updated ALLOCATE macros to make it more convenient
Diffstat (limited to 'Graphics')
28 files changed, 61 insertions, 76 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) diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index 322e146f..2f24fd3f 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -113,11 +113,8 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun } } - auto* pStaticResLayoutRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", m_NumShaders * sizeof(ShaderResourceLayoutD3D11)); - m_pStaticResourceLayouts = reinterpret_cast<ShaderResourceLayoutD3D11*>(pStaticResLayoutRawMem); - - auto* pResCacheRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", m_NumShaders * sizeof(ShaderResourceCacheD3D11)); - m_pStaticResourceCaches = reinterpret_cast<ShaderResourceCacheD3D11*>(pResCacheRawMem); + m_pStaticResourceLayouts = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", ShaderResourceLayoutD3D11, m_NumShaders); + m_pStaticResourceCaches = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", ShaderResourceCacheD3D11, m_NumShaders); const auto& ResourceLayout = PipelineDesc.ResourceLayout; diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp index 7a6d1d91..0d1cab3d 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp @@ -75,7 +75,7 @@ ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, // Load shader resources auto& Allocator = GetRawAllocator(); - auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(ShaderResourcesD3D11)); + auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", ShaderResourcesD3D11, 1); auto* pResources = new (pRawMem) ShaderResourcesD3D11(pRenderDeviceD3D11, m_pShaderByteCode, m_Desc, ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr); m_pShaderResources.reset(pResources, STDDeleterRawMem<ShaderResourcesD3D11>(Allocator)); diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp index 40b6cd38..b204a3dd 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp @@ -39,12 +39,9 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounte { m_NumActiveShaders = static_cast<Uint8>(pPSO->GetNumShaders()); - auto* pResLayoutRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", m_NumActiveShaders * sizeof(ShaderResourceLayoutD3D11)); - m_pResourceLayouts = reinterpret_cast<ShaderResourceLayoutD3D11*>(pResLayoutRawMem); - - auto* pResCacheRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", m_NumActiveShaders * sizeof(ShaderResourceCacheD3D11)); - m_pBoundResourceCaches = reinterpret_cast<ShaderResourceCacheD3D11*>(pResCacheRawMem); - + m_pResourceLayouts = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", ShaderResourceLayoutD3D11, m_NumActiveShaders); + m_pBoundResourceCaches = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", ShaderResourceCacheD3D11, m_NumActiveShaders); + const auto& PSODesc = pPSO->GetDesc(); // Reserve memory for resource layouts diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp index 3e5363ce..d7543fcb 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp @@ -94,7 +94,7 @@ namespace Diligent #endif
if( BufferSize > 0 )
{
- m_pResourceData = reinterpret_cast<Uint8*>(MemAllocator.Allocate(BufferSize, "Shader resource cache data buffer", __FILE__, __LINE__ ));
+ m_pResourceData = ALLOCATE(MemAllocator, "Shader resource cache data buffer", Uint8, BufferSize);
memset(m_pResourceData, 0, BufferSize);
}
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp index 1ef0c9c2..4ac61366 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp @@ -137,7 +137,7 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& if (m_MemorySize)
{
- auto* pRawMem = ALLOCATE(ResLayoutDataAllocator, "Raw memory buffer for shader resource layout resources", m_MemorySize);
+ auto* pRawMem = ALLOCATE_RAW(ResLayoutDataAllocator, "Raw memory buffer for shader resource layout resources", m_MemorySize);
m_ResourceBuffer = std::unique_ptr<void, STDDeleterRawMem<void> >(pRawMem, ResLayoutDataAllocator);
}
diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index ac065da6..1027fb82 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -72,20 +72,17 @@ PipelineStateD3D12Impl :: PipelineStateD3D12Impl(IReferenceCounters* pRefCo { auto& ShaderResLayoutAllocator = GetRawAllocator(); - auto* pShaderResLayoutRawMem = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutD3D12", sizeof(ShaderResourceLayoutD3D12) * m_NumShaders * 2); - m_pShaderResourceLayouts = reinterpret_cast<ShaderResourceLayoutD3D12*>(pShaderResLayoutRawMem); + m_pShaderResourceLayouts = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutD3D12", ShaderResourceLayoutD3D12, m_NumShaders * 2); } { auto& ShaderResCacheAllocator = GetRawAllocator(); - auto* pShaderResCacheRawMem = ALLOCATE(ShaderResCacheAllocator, "Raw memory for ShaderResourceCacheD3D12", sizeof(ShaderResourceCacheD3D12) * m_NumShaders); - m_pStaticResourceCaches = reinterpret_cast<ShaderResourceCacheD3D12*>(pShaderResCacheRawMem); + m_pStaticResourceCaches = ALLOCATE(ShaderResCacheAllocator, "Raw memory for ShaderResourceCacheD3D12", ShaderResourceCacheD3D12, m_NumShaders); } { auto& ShaderVarMgrAllocator = GetRawAllocator(); - auto* pStaticVarsMgrRawMem = ALLOCATE(ShaderVarMgrAllocator, "Raw memory for ShaderVariableManagerD3D12", sizeof(ShaderVariableManagerD3D12) * m_NumShaders); - m_pStaticVarManagers = reinterpret_cast<ShaderVariableManagerD3D12*>(pStaticVarsMgrRawMem); + m_pStaticVarManagers = ALLOCATE(ShaderVarMgrAllocator, "Raw memory for ShaderVariableManagerD3D12", ShaderVariableManagerD3D12, m_NumShaders); } #ifdef DEVELOPMENT diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index 15e48743..a7d2f6c6 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -236,7 +236,7 @@ RenderDeviceD3D12Impl::PooledCommandContext RenderDeviceD3D12Impl::AllocateComma } auto& CmdCtxAllocator = GetRawAllocator(); - auto* pRawMem = ALLOCATE(CmdCtxAllocator, "CommandContext instance", sizeof(CommandContext)); + auto* pRawMem = ALLOCATE(CmdCtxAllocator, "CommandContext instance", CommandContext, 1); auto pCtx = new (pRawMem) CommandContext(m_CmdListManager); pCtx->SetID(ID); #ifdef DEVELOPMENT diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index 87139ef9..7f127ce7 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -56,7 +56,7 @@ D3D12_DESCRIPTOR_RANGE* RootSignature::RootParamsManager::Extend(Uint32 NumExtra VERIFY(NumExtraRootTables > 0 || NumExtraRootViews > 0 || NumExtraDescriptorRanges > 0, "At least one root table, root view or descriptor range must be added" ); auto MemorySize = GetRequiredMemorySize(NumExtraRootTables, NumExtraRootViews, NumExtraDescriptorRanges); VERIFY_EXPR(MemorySize > 0); - auto *pNewMemory = ALLOCATE(m_MemAllocator, "Memory buffer for root tables, root views & descriptor ranges", MemorySize); + auto* pNewMemory = ALLOCATE_RAW(m_MemAllocator, "Memory buffer for root tables, root views & descriptor ranges", MemorySize); memset(pNewMemory, 0, MemorySize); // Note: this order is more efficient than views->tables->ranges diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp index f4128b88..e331be89 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp @@ -40,7 +40,7 @@ ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters, { // Load shader resources auto& Allocator = GetRawAllocator(); - auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(ShaderResourcesD3D12)); + auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", ShaderResourcesD3D12, 1); auto* pResources = new (pRawMem) ShaderResourcesD3D12(m_pShaderByteCode, m_Desc, ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr); m_pShaderResources.reset(pResources, STDDeleterRawMem<ShaderResourcesD3D12>(Allocator)); } diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp index 7d4c396f..4498a9eb 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp @@ -43,8 +43,7 @@ ShaderResourceBindingD3D12Impl::ShaderResourceBindingD3D12Impl(IReferenceCounter auto& ResCacheDataAllocator = pPSO->GetSRBMemoryAllocator().GetResourceCacheDataAllocator(0); pPSO->GetRootSignature().InitResourceCache(pRenderDeviceD3D12Impl, m_ShaderResourceCache, ResCacheDataAllocator); - auto *pVarMgrsRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerD3D12", m_NumShaders * sizeof(ShaderVariableManagerD3D12)); - m_pShaderVarMgrs = reinterpret_cast<ShaderVariableManagerD3D12*>(pVarMgrsRawMem); + m_pShaderVarMgrs = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerD3D12", ShaderVariableManagerD3D12, m_NumShaders); for (Uint32 s = 0; s < m_NumShaders; ++s) { diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp index 64f1ff06..56d21ec1 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp @@ -61,9 +61,9 @@ namespace Diligent VERIFY_EXPR(MemorySize == GetRequiredMemorySize(NumTables, TableSizes)); if(MemorySize > 0) { - m_pMemory = ALLOCATE( *m_pAllocator, "Memory for shader resource cache data", MemorySize); - auto *pTables = reinterpret_cast<RootTable*>(m_pMemory); - auto *pCurrResPtr = reinterpret_cast<Resource*>(pTables + m_NumTables); + m_pMemory = ALLOCATE_RAW( *m_pAllocator, "Memory for shader resource cache data", MemorySize); + auto* pTables = reinterpret_cast<RootTable*>(m_pMemory); + auto* pCurrResPtr = reinterpret_cast<Resource*>(pTables + m_NumTables); for(Uint32 res=0; res < TotalResources; ++res) new(pCurrResPtr + res) Resource(); diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp index 393c1c3b..9b1a11f8 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -99,7 +99,7 @@ void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& if(MemSize == 0) return; - auto* pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader resource layout resources", MemSize); + auto* pRawMem = ALLOCATE_RAW(Allocator, "Raw memory buffer for shader resource layout resources", MemSize); m_ResourceBuffer = std::unique_ptr<void, STDDeleterRawMem<void> >(pRawMem, Allocator); } diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp index de8e9855..3a16e008 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp @@ -70,7 +70,7 @@ ShaderVariableManagerD3D12::ShaderVariableManagerD3D12(IObject& if(m_NumVariables == 0) return; - auto* pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader variables", MemSize); + auto* pRawMem = ALLOCATE_RAW(Allocator, "Raw memory buffer for shader variables", MemSize); m_pVariables = reinterpret_cast<ShaderVariableD3D12Impl*>(pRawMem); Uint32 VarInd = 0; diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index e906f31b..41df7223 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -87,7 +87,7 @@ void ShaderResources::AllocateMemory(IMemoryAllocator& Allocator, if( MemorySize ) { - auto* pRawMem = ALLOCATE(Allocator, "Allocator for shader resources", MemorySize ); + auto* pRawMem = ALLOCATE_RAW(Allocator, "Allocator for shader resources", MemorySize ); m_MemoryBuffer = std::unique_ptr< void, STDDeleterRawMem<void> >(pRawMem, Allocator); char* NamesPool = reinterpret_cast<char*>(reinterpret_cast<D3DShaderResourceAttribs*>(pRawMem) + m_TotalResources); m_ResourceNames.AssignMemory(NamesPool, ResourceNamesPoolSize); diff --git a/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h b/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h index 10e2baeb..3f7b42d1 100644 --- a/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h +++ b/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.h @@ -34,6 +34,7 @@ #include "RefCntAutoPtr.h" #include "PlatformMisc.h" #include "ResourceReleaseQueue.h" +#include "EngineMemory.h" namespace Diligent { @@ -56,7 +57,7 @@ public: TBase (pRefCounters, RawMemAllocator, pEngineFactory, NumDeferredContexts, ObjectSizes), m_CmdQueueCount (CmdQueueCount) { - m_CommandQueues = reinterpret_cast<CommandQueue*>(ALLOCATE(this->m_RawMemAllocator, "Raw memory for the device command/release queues", sizeof(CommandQueue)*m_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); } diff --git a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp index 710dc9fa..00f07ea0 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp @@ -132,7 +132,7 @@ namespace Diligent TotalMemorySize += AlignedStringPoolDataSize * sizeof(Char); auto& MemAllocator = GetRawAllocator(); - void* RawMemory = ALLOCATE(MemAllocator, "Memory buffer for GLProgramResources", TotalMemorySize); + void* RawMemory = ALLOCATE_RAW(MemAllocator, "Memory buffer for GLProgramResources", TotalMemorySize); m_UniformBuffers = reinterpret_cast<UniformBufferInfo*>(RawMemory); m_Samplers = reinterpret_cast<SamplerInfo*> (m_UniformBuffers + m_NumUniformBuffers); diff --git a/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp b/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp index 58b2b122..3d53a03a 100644 --- a/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp +++ b/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp @@ -297,8 +297,8 @@ namespace Diligent VERIFY_EXPR(ResourceStateToVkImageLayout(RESOURCE_STATE_SHADER_RESOURCE) == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); // Note that mip levels are relative to the view's most detailed mip - auto LowestMip = ViewDesc.NumMipLevels - 1; - for (uint32_t TopMip = 0; TopMip < LowestMip; ) + auto BottomMip = ViewDesc.NumMipLevels - 1; + for (uint32_t TopMip = 0; TopMip < BottomMip; ) { // In Vulkan all subresources of a view must be transitioned to the same layout, so // we can't bind the entire texture and have to bind single mip level at a time @@ -321,8 +321,8 @@ namespace Diligent // in the low bits. Zeros indicate we can divide by two without truncating. uint32_t AdditionalMips = PlatformMisc::GetLSB(DstWidth | DstHeight); uint32_t NumMips = 1 + (AdditionalMips > 3 ? 3 : AdditionalMips); - if (TopMip + NumMips > LowestMip) - NumMips = LowestMip - TopMip; + if (TopMip + NumMips > BottomMip) + NumMips = BottomMip - TopMip; // These are clamped to 1 after computing additional mips because clamped // dimensions should not limit us from downsampling multiple times. (E.g. @@ -356,12 +356,12 @@ namespace Diligent constexpr const Uint32 MaxMipsHandledByCS = 4; // Max number of mip levels processed by one CS shader invocation for (Uint32 u = 0; u < MaxMipsHandledByCS; ++u) { - auto* MipLevelUAV = TexView.GetMipLevelUAV(std::min(TopMip + u + 1, LowestMip)); + auto* MipLevelUAV = TexView.GetMipLevelUAV(std::min(TopMip + u + 1, BottomMip)); pOutMipVar[u]->Set(MipLevelUAV); } SubresRange.baseMipLevel = ViewDesc.MostDetailedMip + TopMip + 1; - SubresRange.levelCount = std::min(4u, LowestMip - TopMip); + SubresRange.levelCount = std::min(4u, BottomMip - TopMip); if (OriginalLayout != VK_IMAGE_LAYOUT_GENERAL) Ctx.TransitionImageLayout(*pTexVk, OriginalLayout, VK_IMAGE_LAYOUT_GENERAL, SubresRange); diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp index d8383418..3ee16537 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp @@ -155,7 +155,7 @@ void PipelineLayout::DescriptorSetLayoutManager::DescriptorSetLayout::ReserveMem size_t RequiredMemory = GetMemorySize(NumBindings); if (RequiredMemory > ReservedMemory) { - void *pNewBindings = ALLOCATE(MemAllocator, "Memory buffer for descriptor set layout bindings", RequiredMemory); + void* pNewBindings = ALLOCATE_RAW(MemAllocator, "Memory buffer for descriptor set layout bindings", RequiredMemory); if (pBindings != nullptr) { memcpy(pNewBindings, pBindings, sizeof(VkDescriptorSetLayoutBinding) * NumLayoutBindings); @@ -341,8 +341,8 @@ void PipelineLayout::DescriptorSetLayoutManager::AllocateResourceSlot(const SPIR // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and // descriptorCount is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a valid pointer // to an array of descriptorCount valid VkSampler handles (13.2.1) - auto *pImmutableSamplers = reinterpret_cast<VkSampler*>(ALLOCATE(m_MemAllocator, "Memory buffer for immutable samplers", sizeof(VkSampler) * VkBinding.descriptorCount)); - for(uint32_t s=0; s < VkBinding.descriptorCount; ++s) + auto* pImmutableSamplers = ALLOCATE(m_MemAllocator, "Memory buffer for immutable samplers", VkSampler, VkBinding.descriptorCount); + for (uint32_t s=0; s < VkBinding.descriptorCount; ++s) pImmutableSamplers[s] = vkImmutableSampler; VkBinding.pImmutableSamplers = pImmutableSamplers; } diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index b4be5e89..43e99202 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -156,12 +156,9 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters* pRefCounters auto& ShaderResLayoutAllocator = GetRawAllocator(); std::array<std::shared_ptr<const SPIRVShaderResources>, MaxShadersInPipeline> ShaderResources; std::array<std::vector<uint32_t>, MaxShadersInPipeline> ShaderSPIRVs; - auto* pResLayoutRawMem = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutVk", sizeof(ShaderResourceLayoutVk) * m_NumShaders * 2); - auto* pStaticResCacheRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheVk", sizeof(ShaderResourceCacheVk) * m_NumShaders); - auto* pStaticVarMgrRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerVk", sizeof(ShaderVariableManagerVk) * m_NumShaders); - m_ShaderResourceLayouts = reinterpret_cast<ShaderResourceLayoutVk*>(pResLayoutRawMem); - m_StaticResCaches = reinterpret_cast<ShaderResourceCacheVk*>(pStaticResCacheRawMem); - m_StaticVarsMgrs = reinterpret_cast<ShaderVariableManagerVk*>(pStaticVarMgrRawMem); + m_ShaderResourceLayouts = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutVk", ShaderResourceLayoutVk, m_NumShaders * 2); + m_StaticResCaches = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheVk", ShaderResourceCacheVk, m_NumShaders); + m_StaticVarsMgrs = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerVk", ShaderVariableManagerVk, m_NumShaders); for (Uint32 s=0; s < m_NumShaders; ++s) { new (m_ShaderResourceLayouts + s) ShaderResourceLayoutVk(LogicalDevice); diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp index 30e2ba8f..bdb85b8e 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp @@ -43,8 +43,7 @@ ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl(IReferenceCounters* pRe auto& ResourceCacheDataAllocator = pPSO->GetSRBMemoryAllocator().GetResourceCacheDataAllocator(0); pPSO->GetPipelineLayout().InitResourceCache(pRenderDeviceVkImpl, m_ShaderResourceCache, ResourceCacheDataAllocator, pPSO->GetDesc().Name); - auto* pVarMgrsRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerVk", m_NumShaders * sizeof(ShaderVariableManagerVk)); - m_pShaderVarMgrs = reinterpret_cast<ShaderVariableManagerVk*>(pVarMgrsRawMem); + m_pShaderVarMgrs = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerVk", ShaderVariableManagerVk, m_NumShaders); for (Uint32 s = 0; s < m_NumShaders; ++s) { diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp index 1d060871..4aad41d9 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp @@ -69,7 +69,7 @@ void ShaderResourceCacheVk::InitializeSets(IMemoryAllocator& MemAllocator, Uint3 #endif if (MemorySize > 0) { - m_pMemory = ALLOCATE( *m_pAllocator, "Memory for shader resource cache data", MemorySize); + m_pMemory = ALLOCATE_RAW( *m_pAllocator, "Memory for shader resource cache data", MemorySize); auto* pSets = reinterpret_cast<DescriptorSet*>(m_pMemory); auto* pCurrResPtr = reinterpret_cast<Resource*>(pSets + m_NumSets); for (Uint32 t = 0; t < NumSets; ++t) diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index fdf3f830..8486d586 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -155,7 +155,7 @@ void ShaderResourceLayoutVk::AllocateMemory(std::shared_ptr<const SPIRVShaderRes if (MemSize == 0) return; - auto* pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader resource layout resources", MemSize); + auto* pRawMem = ALLOCATE_RAW(Allocator, "Raw memory buffer for shader resource layout resources", MemSize); m_ResourceBuffer = std::unique_ptr<void, STDDeleterRawMem<void> >(pRawMem, Allocator); for (Uint32 s=0; s < m_NumImmutableSamplers; ++s) { diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp index 9d6bbf96..50bde9da 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp @@ -80,7 +80,7 @@ ShaderVariableManagerVk::ShaderVariableManagerVk(IObject& if(m_NumVariables == 0) return; - auto* pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader variables", MemSize); + auto* pRawMem = ALLOCATE_RAW(Allocator, "Raw memory buffer for shader variables", MemSize); m_pVariables = reinterpret_cast<ShaderVariableVkImpl*>(pRawMem); Uint32 VarInd = 0; diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index fe712cc8..1f1a2053 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -83,7 +83,7 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, // Load shader resources auto& Allocator = GetRawAllocator(); - auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(SPIRVShaderResources)); + auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", SPIRVShaderResources, 1); bool IsHLSLVertexShader = CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL && m_Desc.ShaderType == SHADER_TYPE_VERTEX; auto* pResources = new (pRawMem) SPIRVShaderResources(Allocator, pRenderDeviceVk, m_SPIRV, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr, IsHLSLVertexShader, m_EntryPoint); m_pShaderResources.reset(pResources, STDDeleterRawMem<SPIRVShaderResources>(Allocator)); diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index 4d05b81f..eaf88459 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -543,8 +543,7 @@ void TextureVkImpl::CreateViewInternal(const TextureViewDesc& ViewDesc, ITexture m_bCSBasedMipGenerationSupported && CheckCSBasedMipGenerationSupport(TexFormatToVkFormat(pViewVk->GetDesc().Format))) { - auto* pMipLevelViewsRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for mip level views", sizeof(TextureViewVkImpl::MipLevelViewAutoPtrType) * UpdatedViewDesc.NumMipLevels * 2); - auto* pMipLevelViews = reinterpret_cast<TextureViewVkImpl::MipLevelViewAutoPtrType*>(pMipLevelViewsRawMem); + auto* pMipLevelViews = ALLOCATE(GetRawAllocator(), "Raw memory for mip level views", TextureViewVkImpl::MipLevelViewAutoPtrType, UpdatedViewDesc.NumMipLevels * 2); for (Uint32 MipLevel = 0; MipLevel < UpdatedViewDesc.NumMipLevels; ++MipLevel) { auto CreateMipLevelView = [&](TEXTURE_VIEW_TYPE ViewType, Uint32 MipLevel, TextureViewVkImpl::MipLevelViewAutoPtrType* ppMipLevelView) |
