summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-10-07 21:57:33 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-10-07 21:57:33 +0000
commit2250c36e3570a949104a3a49b02546a3dd8f1917 (patch)
treeef7bb54fa2db2692c53d88c8662542c727c43e67 /Graphics/GraphicsEngineD3D12
parentFew minor updates (diff)
downloadDiligentCore-2250c36e3570a949104a3a49b02546a3dd8f1917.tar.gz
DiligentCore-2250c36e3570a949104a3a49b02546a3dd8f1917.zip
Updated PipelineState[D3D11,D3D12,Vk]Impl to allocate single chunk of memory for resource layout, resource cache and var managers objects
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp
index 138b6b3d..e9c313a5 100644
--- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp
@@ -110,20 +110,18 @@ PipelineStateD3D12Impl::PipelineStateD3D12Impl(IReferenceCounters* pR
const auto& ResourceLayout = m_Desc.ResourceLayout;
m_RootSig.AllocateStaticSamplers(ResourceLayout);
- {
- auto& ShaderResLayoutAllocator = GetRawAllocator();
- m_pShaderResourceLayouts = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutD3D12", ShaderResourceLayoutD3D12, m_NumShaders * 2);
- }
-
- {
- auto& ShaderResCacheAllocator = GetRawAllocator();
- m_pStaticResourceCaches = ALLOCATE(ShaderResCacheAllocator, "Raw memory for ShaderResourceCacheD3D12", ShaderResourceCacheD3D12, m_NumShaders);
- }
-
- {
- auto& ShaderVarMgrAllocator = GetRawAllocator();
- m_pStaticVarManagers = ALLOCATE(ShaderVarMgrAllocator, "Raw memory for ShaderVariableManagerD3D12", ShaderVariableManagerD3D12, m_NumShaders);
- }
+ // clang-format off
+ static_assert((sizeof(ShaderResourceLayoutD3D12) % sizeof(void*)) == 0, "sizeof(ShaderResourceLayoutD3D12) is expected to be a multiple of sizeof(void*)");
+ static_assert((sizeof(ShaderResourceCacheD3D12) % sizeof(void*)) == 0, "sizeof(ShaderResourceCacheD3D12) is expected to be a multiple of sizeof(void*)");
+ static_assert((sizeof(ShaderVariableManagerD3D12) % sizeof(void*)) == 0, "sizeof(ShaderVariableManagerD3D12) is expected to be a multiple of sizeof(void*)");
+ // clang-format on
+ const auto MemSize = (sizeof(ShaderResourceLayoutD3D12) * 2 + sizeof(ShaderResourceCacheD3D12) + sizeof(ShaderVariableManagerD3D12)) * m_NumShaders;
+ auto* const pRawMem =
+ ALLOCATE_RAW(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D12, ShaderResourceCacheD3D12, and ShaderVariableManagerD3D12 arrays", MemSize);
+
+ m_pShaderResourceLayouts = reinterpret_cast<ShaderResourceLayoutD3D12*>(pRawMem);
+ m_pStaticResourceCaches = reinterpret_cast<ShaderResourceCacheD3D12*>(m_pShaderResourceLayouts + m_NumShaders * 2);
+ m_pStaticVarManagers = reinterpret_cast<ShaderVariableManagerD3D12*>(m_pStaticResourceCaches + m_NumShaders);
#ifdef DILIGENT_DEVELOPMENT
{
@@ -444,9 +442,10 @@ PipelineStateD3D12Impl::~PipelineStateD3D12Impl()
m_pShaderResourceLayouts[s].~ShaderResourceLayoutD3D12();
m_pShaderResourceLayouts[m_NumShaders + s].~ShaderResourceLayoutD3D12();
}
- ShaderResLayoutAllocator.Free(m_pStaticVarManagers);
- ShaderResLayoutAllocator.Free(m_pStaticResourceCaches);
- ShaderResLayoutAllocator.Free(m_pShaderResourceLayouts);
+ // m_pShaderResourceLayouts, m_pStaticResourceCaches, and m_pShaderResourceLayouts are allocated in
+ // contiguous chunks of memory.
+ auto* pRawMem = m_pShaderResourceLayouts;
+ ShaderResLayoutAllocator.Free(pRawMem);
// D3D12 object can only be destroyed when it is no longer used by the GPU
m_pDevice->SafeReleaseDeviceObject(std::move(m_pd3d12PSO), m_Desc.CommandQueueMask);