Add Pool::GetName, SetName
diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp
index 06ecfe5..e648300 100644
--- a/src/D3D12MemAlloc.cpp
+++ b/src/D3D12MemAlloc.cpp
@@ -3728,11 +3728,8 @@
{
public:
PoolPimpl(AllocatorPimpl* allocator, const POOL_DESC& desc);
- ~PoolPimpl()
- {
- D3D12MA_DELETE(m_Allocator->GetAllocs(), m_BlockVector);
- }
HRESULT Init();
+ ~PoolPimpl();
AllocatorPimpl* GetAllocator() const { return m_Allocator; }
const POOL_DESC& GetDesc() const { return m_Desc; }
@@ -3740,34 +3737,25 @@
void CalculateStats(StatInfo& outStats);
+ void SetName(LPCWSTR Name);
+ LPCWSTR GetName() const { return m_Name; }
+
private:
friend class Allocator;
AllocatorPimpl* m_Allocator; // Externally owned object.
POOL_DESC m_Desc;
BlockVector* m_BlockVector; // Owned object.
+ wchar_t* m_Name;
+
+ void FreeName();
};
-HRESULT PoolPimpl::Init()
-{
- return m_BlockVector->CreateMinBlocks();
-}
-
-void PoolPimpl::CalculateStats(StatInfo& outStats)
-{
- ZeroMemory(&outStats, sizeof(outStats));
- outStats.AllocationSizeMin = UINT64_MAX;
- outStats.UnusedRangeSizeMin = UINT64_MAX;
-
- m_BlockVector->AddStats(outStats);
-
- PostProcessStatInfo(outStats);
-}
-
PoolPimpl::PoolPimpl(AllocatorPimpl* allocator, const POOL_DESC& desc) :
m_Allocator(allocator),
m_Desc(desc),
- m_BlockVector(NULL)
+ m_BlockVector(NULL),
+ m_Name(NULL)
{
const bool explicitBlockSize = desc.BlockSize != 0;
const UINT64 preferredBlockSize = explicitBlockSize ? desc.BlockSize : D3D12MA_DEFAULT_BLOCK_SIZE;
@@ -3787,6 +3775,49 @@
explicitBlockSize);
}
+HRESULT PoolPimpl::Init()
+{
+ return m_BlockVector->CreateMinBlocks();
+}
+
+PoolPimpl::~PoolPimpl()
+{
+ FreeName();
+ D3D12MA_DELETE(m_Allocator->GetAllocs(), m_BlockVector);
+}
+
+void PoolPimpl::CalculateStats(StatInfo& outStats)
+{
+ ZeroMemory(&outStats, sizeof(outStats));
+ outStats.AllocationSizeMin = UINT64_MAX;
+ outStats.UnusedRangeSizeMin = UINT64_MAX;
+
+ m_BlockVector->AddStats(outStats);
+
+ PostProcessStatInfo(outStats);
+}
+
+void PoolPimpl::SetName(LPCWSTR Name)
+{
+ FreeName();
+
+ if(Name)
+ {
+ const size_t nameCharCount = wcslen(Name) + 1;
+ m_Name = D3D12MA_NEW_ARRAY(m_Allocator->GetAllocs(), WCHAR, nameCharCount);
+ memcpy(m_Name, Name, nameCharCount * sizeof(WCHAR));
+ }
+}
+
+void PoolPimpl::FreeName()
+{
+ if(m_Name)
+ {
+ const size_t nameCharCount = wcslen(m_Name) + 1;
+ D3D12MA_DELETE_ARRAY(m_Allocator->GetAllocs(), m_Name, nameCharCount);
+ m_Name = NULL;
+ }
+}
////////////////////////////////////////////////////////////////////////////////
// Public class Pool implementation
@@ -3815,6 +3846,17 @@
m_Pimpl->CalculateStats(*pStats);
}
+void Pool::SetName(LPCWSTR Name)
+{
+ D3D12MA_DEBUG_GLOBAL_MUTEX_LOCK
+ m_Pimpl->SetName(Name);
+}
+
+LPCWSTR Pool::GetName() const
+{
+ return m_Pimpl->GetName();
+}
+
Pool::Pool(Allocator* allocator, const POOL_DESC &desc) :
m_Pimpl(D3D12MA_NEW(allocator->m_Pimpl->GetAllocs(), PoolPimpl)(allocator->m_Pimpl, desc))
{
diff --git a/src/D3D12MemAlloc.h b/src/D3D12MemAlloc.h
index 10c5735..02913ff 100644
--- a/src/D3D12MemAlloc.h
+++ b/src/D3D12MemAlloc.h
@@ -707,6 +707,23 @@
*/
void CalculateStats(StatInfo* pStats);
+ /** \brief Associates a name with the pool. This name is for use in debug diagnostics and tools.
+
+ Internal copy of the string is made, so the memory pointed by the argument can be
+ changed of freed immediately after this call.
+
+ `Name` can be NULL.
+ */
+ void SetName(LPCWSTR Name);
+
+ /** \brief Returns the name associated with the pool object.
+
+ Returned string points to an internal copy.
+
+ If no name was associated with the allocation, returns NULL.
+ */
+ LPCWSTR GetName() const;
+
private:
friend class Allocator;
friend class AllocatorPimpl;
diff --git a/src/Tests.cpp b/src/Tests.cpp
index 8b3b504..662e059 100644
--- a/src/Tests.cpp
+++ b/src/Tests.cpp
@@ -436,6 +436,11 @@
CHECK_BOOL( poolStats.UsedBytes == 0 );
CHECK_BOOL( poolStats.UnusedBytes == poolDesc.BlockSize );
+ // # SetName and GetName
+ static const wchar_t* NAME = L"Custom pool name 1";
+ pool->SetName(NAME);
+ CHECK_BOOL( wcscmp(pool->GetName(), NAME) == 0 );
+
// # Create buffers 2x 5 MB
D3D12MA::ALLOCATION_DESC allocDesc = {};