summaryrefslogtreecommitdiffstats
path: root/Common
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-06-22 04:33:43 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-06-22 04:33:43 +0000
commitbc393d8fd195f2d4400b6aeb42fa40b92d6b4b68 (patch)
treeb31a704e4492f3e0c1da375ca8cdd1fdb4ee6c9c /Common
parentUpdated vulkan backend source formatting (diff)
downloadDiligentCore-bc393d8fd195f2d4400b6aeb42fa40b92d6b4b68.tar.gz
DiligentCore-bc393d8fd195f2d4400b6aeb42fa40b92d6b4b68.zip
Improved memory allocation for shader variables and resource cache in Vk backend
Diffstat (limited to 'Common')
-rw-r--r--Common/interface/FixedBlockMemoryAllocator.h18
-rw-r--r--Common/src/FixedBlockMemoryAllocator.cpp23
2 files changed, 17 insertions, 24 deletions
diff --git a/Common/interface/FixedBlockMemoryAllocator.h b/Common/interface/FixedBlockMemoryAllocator.h
index c092c203..2b9a5f3e 100644
--- a/Common/interface/FixedBlockMemoryAllocator.h
+++ b/Common/interface/FixedBlockMemoryAllocator.h
@@ -52,7 +52,7 @@ namespace Diligent
class FixedBlockMemoryAllocator : public IMemoryAllocator
{
public:
- FixedBlockMemoryAllocator(IMemoryAllocator &RawMemoryAllocator, size_t BlockSize, Uint32 NumBlocksInPage);
+ FixedBlockMemoryAllocator(IMemoryAllocator& RawMemoryAllocator, size_t BlockSize, Uint32 NumBlocksInPage);
~FixedBlockMemoryAllocator();
/// Allocates block of memory
@@ -62,10 +62,10 @@ public:
virtual void Free(void *Ptr)override final;
private:
- FixedBlockMemoryAllocator(const FixedBlockMemoryAllocator&) = delete;
- FixedBlockMemoryAllocator(FixedBlockMemoryAllocator&&) = delete;
+ FixedBlockMemoryAllocator (const FixedBlockMemoryAllocator&) = delete;
+ FixedBlockMemoryAllocator (FixedBlockMemoryAllocator&&) = delete;
FixedBlockMemoryAllocator& operator = (const FixedBlockMemoryAllocator&) = delete;
- FixedBlockMemoryAllocator& operator = (FixedBlockMemoryAllocator&&) = delete;
+ FixedBlockMemoryAllocator& operator = (FixedBlockMemoryAllocator&&) = delete;
void CreateNewPage();
@@ -74,15 +74,15 @@ private:
class MemoryPage
{
public:
- static constexpr Uint8 NewPageMemPattern = 0xAA;
- static constexpr Uint8 AllocatedBlockMemPattern = 0xAB;
+ static constexpr Uint8 NewPageMemPattern = 0xAA;
+ static constexpr Uint8 AllocatedBlockMemPattern = 0xAB;
static constexpr Uint8 DeallocatedBlockMemPattern = 0xDE;
static constexpr Uint8 InitializedBlockMemPattern = 0xCF;
- MemoryPage(FixedBlockMemoryAllocator &OwnerAllocator):
- m_NumFreeBlocks(OwnerAllocator.m_NumBlocksInPage),
+ MemoryPage(FixedBlockMemoryAllocator& OwnerAllocator):
+ m_NumFreeBlocks (OwnerAllocator.m_NumBlocksInPage),
m_NumInitializedBlocks(0),
- m_pOwnerAllocator(&OwnerAllocator)
+ m_pOwnerAllocator (&OwnerAllocator)
{
auto PageSize = OwnerAllocator.m_BlockSize * OwnerAllocator.m_NumBlocksInPage;
m_pPageStart = reinterpret_cast<Uint8*>(
diff --git a/Common/src/FixedBlockMemoryAllocator.cpp b/Common/src/FixedBlockMemoryAllocator.cpp
index 261336ea..37a21e36 100644
--- a/Common/src/FixedBlockMemoryAllocator.cpp
+++ b/Common/src/FixedBlockMemoryAllocator.cpp
@@ -26,25 +26,22 @@
namespace Diligent
{
- FixedBlockMemoryAllocator::FixedBlockMemoryAllocator(IMemoryAllocator &RawMemoryAllocator, size_t BlockSize, Uint32 NumBlocksInPage) :
- m_PagePool(STD_ALLOCATOR_RAW_MEM(MemoryPage, RawMemoryAllocator, "Allocator for vector<MemoryPage>")),
- m_AvailablePages(STD_ALLOCATOR_RAW_MEM(size_t, RawMemoryAllocator, "Allocator for unordered_set<size_t>")),
- m_AddrToPageId(STD_ALLOCATOR_RAW_MEM(AddrToPageIdMapElem, RawMemoryAllocator, "Allocator for unordered_map<void*, size_t>")),
+ FixedBlockMemoryAllocator::FixedBlockMemoryAllocator(IMemoryAllocator& RawMemoryAllocator,
+ size_t BlockSize,
+ Uint32 NumBlocksInPage) :
+ m_PagePool (STD_ALLOCATOR_RAW_MEM(MemoryPage, RawMemoryAllocator, "Allocator for vector<MemoryPage>")),
+ m_AvailablePages (STD_ALLOCATOR_RAW_MEM(size_t, RawMemoryAllocator, "Allocator for unordered_set<size_t>")),
+ m_AddrToPageId (STD_ALLOCATOR_RAW_MEM(AddrToPageIdMapElem, RawMemoryAllocator, "Allocator for unordered_map<void*, size_t>")),
m_RawMemoryAllocator(RawMemoryAllocator),
- m_BlockSize(BlockSize),
- m_NumBlocksInPage(NumBlocksInPage)
+ m_BlockSize (BlockSize),
+ m_NumBlocksInPage (NumBlocksInPage)
{
- //tmpLargeBuffer = new Uint8[100 << 20];
- //tmpCurrPtr = tmpLargeBuffer;
-
// Allocate one page
CreateNewPage();
}
FixedBlockMemoryAllocator::~FixedBlockMemoryAllocator()
{
- //delete[] tmpLargeBuffer;
-
#ifdef _DEBUG
for (size_t p = 0; p < m_PagePool.size(); ++p)
{
@@ -63,10 +60,6 @@ namespace Diligent
void* FixedBlockMemoryAllocator::Allocate( size_t Size, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber)
{
- //auto *ptr = tmpCurrPtr;
- //tmpCurrPtr += Size;
- //return ptr;
-
VERIFY(m_BlockSize == Size, "Requested size (", Size, ") does not match the block size (", m_BlockSize, ")");
std::lock_guard<std::mutex> LockGuard(m_Mutex);