summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D11
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/GraphicsEngineD3D11
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/GraphicsEngineD3D11')
-rw-r--r--Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp
index 39a6ca4a..fb93f90d 100644
--- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp
@@ -132,8 +132,16 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pR
UNEXPECTED(GetPipelineTypeString(m_Desc.PipelineType), " pipelines are not supported by Direct3D11 backend");
}
- m_pStaticResourceLayouts = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", ShaderResourceLayoutD3D11, m_NumShaders);
- m_pStaticResourceCaches = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", ShaderResourceCacheD3D11, m_NumShaders);
+ // clang-format off
+ static_assert((sizeof(ShaderResourceLayoutD3D11) % sizeof(void*)) == 0, "sizeof(ShaderResourceLayoutD3D11) is expected to be a multiple of sizeof(void*)");
+ static_assert((sizeof(ShaderResourceCacheD3D11) % sizeof(void*)) == 0, "sizeof(ShaderResourceCacheD3D11) is expected to be a multiple of sizeof(void*)");
+ // clang-format on
+ const auto MemSize = (sizeof(ShaderResourceLayoutD3D11) + sizeof(ShaderResourceCacheD3D11)) * m_NumShaders;
+ auto* const pRawMem =
+ ALLOCATE_RAW(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11 and ShaderResourceCacheD3D11 arrays", MemSize);
+
+ m_pStaticResourceLayouts = reinterpret_cast<ShaderResourceLayoutD3D11*>(pRawMem);
+ m_pStaticResourceCaches = reinterpret_cast<ShaderResourceCacheD3D11*>(m_pStaticResourceLayouts + m_NumShaders);
const auto& ResourceLayout = m_Desc.ResourceLayout;
@@ -236,13 +244,14 @@ PipelineStateD3D11Impl::~PipelineStateD3D11Impl()
m_pStaticResourceCaches[s].Destroy(GetRawAllocator());
m_pStaticResourceCaches[s].~ShaderResourceCacheD3D11();
}
- GetRawAllocator().Free(m_pStaticResourceCaches);
for (Uint32 l = 0; l < m_NumShaders; ++l)
{
m_pStaticResourceLayouts[l].~ShaderResourceLayoutD3D11();
}
- GetRawAllocator().Free(m_pStaticResourceLayouts);
+ // m_pStaticResourceLayouts and m_pStaticResourceCaches are allocated in contiguous chunks of memory.
+ auto* pRawMem = m_pStaticResourceLayouts;
+ GetRawAllocator().Free(pRawMem);
}
IMPLEMENT_QUERY_INTERFACE(PipelineStateD3D11Impl, IID_PipelineStateD3D11, TPipelineStateBase)