From 2250c36e3570a949104a3a49b02546a3dd8f1917 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 7 Oct 2020 14:57:33 -0700 Subject: Updated PipelineState[D3D11,D3D12,Vk]Impl to allocate single chunk of memory for resource layout, resource cache and var managers objects --- .../src/PipelineStateD3D12Impl.cpp | 33 +++++++++++----------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') 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(pRawMem); + m_pStaticResourceCaches = reinterpret_cast(m_pShaderResourceLayouts + m_NumShaders * 2); + m_pStaticVarManagers = reinterpret_cast(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); -- cgit v1.2.3