@@ -2512,6 +2512,20 @@ Possible return values:
25122512*/
25132513VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckPoolCorruption(VmaAllocator allocator, VmaPool pool);
25142514
2515+ /** TODO
2516+ */
2517+ VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolName(
2518+ VmaAllocator allocator,
2519+ VmaPool pool,
2520+ const char** ppName);
2521+
2522+ /* TODO
2523+ */
2524+ VMA_CALL_PRE void VMA_CALL_POST vmaSetPoolName(
2525+ VmaAllocator allocator,
2526+ VmaPool pool,
2527+ const char* pName);
2528+
25152529/** \struct VmaAllocation
25162530\brief Represents single memory allocation.
25172531
@@ -4038,6 +4052,30 @@ static void vma_delete_array(const VkAllocationCallbacks* pAllocationCallbacks,
40384052 }
40394053}
40404054
4055+ static char* VmaCreateStringCopy(const VkAllocationCallbacks* allocs, const char* srcStr)
4056+ {
4057+ if(srcStr != VMA_NULL)
4058+ {
4059+ const size_t len = strlen(srcStr);
4060+ char* const result = vma_new_array(allocs, char, len + 1);
4061+ memcpy(result, srcStr, len + 1);
4062+ return result;
4063+ }
4064+ else
4065+ {
4066+ return VMA_NULL;
4067+ }
4068+ }
4069+
4070+ static void VmaFreeString(const VkAllocationCallbacks* allocs, char* str)
4071+ {
4072+ if(str != VMA_NULL)
4073+ {
4074+ const size_t len = strlen(str);
4075+ vma_delete_array(allocs, str, len + 1);
4076+ }
4077+ }
4078+
40414079// STL-compatible allocator.
40424080template<typename T>
40434081class VmaStlAllocator
@@ -5994,6 +6032,7 @@ struct VmaBlockVector
59946032
59956033 VkResult CreateMinBlocks();
59966034
6035+ VmaAllocator GetAllocator() const { return m_hAllocator; }
59976036 VmaPool GetParentPool() const { return m_hParentPool; }
59986037 uint32_t GetMemoryTypeIndex() const { return m_MemoryTypeIndex; }
59996038 VkDeviceSize GetPreferredBlockSize() const { return m_PreferredBlockSize; }
@@ -6135,12 +6174,16 @@ struct VmaPool_T
61356174 uint32_t GetId() const { return m_Id; }
61366175 void SetId(uint32_t id) { VMA_ASSERT(m_Id == 0); m_Id = id; }
61376176
6177+ const char* GetName() const { return m_Name; }
6178+ void SetName(const char* pName);
6179+
61386180#if VMA_STATS_STRING_ENABLED
61396181 //void PrintDetailedMap(class VmaStringBuilder& sb);
61406182#endif
61416183
61426184private:
61436185 uint32_t m_Id;
6186+ char* m_Name;
61446187};
61456188
61466189/*
@@ -7388,11 +7431,7 @@ void VmaAllocation_T::SetUserData(VmaAllocator hAllocator, void* pUserData)
73887431
73897432 if(pUserData != VMA_NULL)
73907433 {
7391- const char* const newStrSrc = (char*)pUserData;
7392- const size_t newStrLen = strlen(newStrSrc);
7393- char* const newStrDst = vma_new_array(hAllocator, char, newStrLen + 1);
7394- memcpy(newStrDst, newStrSrc, newStrLen + 1);
7395- m_pUserData = newStrDst;
7434+ m_pUserData = VmaCreateStringCopy(hAllocator->GetAllocationCallbacks(), (const char*)pUserData);
73967435 }
73977436 }
73987437 else
@@ -7595,13 +7634,8 @@ void VmaAllocation_T::PrintParameters(class VmaJsonWriter& json) const
75957634void VmaAllocation_T::FreeUserDataString(VmaAllocator hAllocator)
75967635{
75977636 VMA_ASSERT(IsUserDataString());
7598- if(m_pUserData != VMA_NULL)
7599- {
7600- char* const oldStr = (char*)m_pUserData;
7601- const size_t oldStrLen = strlen(oldStr);
7602- vma_delete_array(hAllocator, oldStr, oldStrLen + 1);
7603- m_pUserData = VMA_NULL;
7604- }
7637+ VmaFreeString(hAllocator->GetAllocationCallbacks(), (char*)m_pUserData);
7638+ m_pUserData = VMA_NULL;
76057639}
76067640
76077641void VmaAllocation_T::BlockAllocMap()
@@ -11407,14 +11441,30 @@ VmaPool_T::VmaPool_T(
1140711441 true, // isCustomPool
1140811442 createInfo.blockSize != 0, // explicitBlockSize
1140911443 createInfo.flags & VMA_POOL_CREATE_ALGORITHM_MASK), // algorithm
11410- m_Id(0)
11444+ m_Id(0),
11445+ m_Name(VMA_NULL)
1141111446{
1141211447}
1141311448
1141411449VmaPool_T::~VmaPool_T()
1141511450{
1141611451}
1141711452
11453+ void VmaPool_T::SetName(const char* pName)
11454+ {
11455+ const VkAllocationCallbacks* allocs = m_BlockVector.GetAllocator()->GetAllocationCallbacks();
11456+ VmaFreeString(allocs, m_Name);
11457+
11458+ if(pName != VMA_NULL)
11459+ {
11460+ m_Name = VmaCreateStringCopy(allocs, pName);
11461+ }
11462+ else
11463+ {
11464+ m_Name = VMA_NULL;
11465+ }
11466+ }
11467+
1141811468#if VMA_STATS_STRING_ENABLED
1141911469
1142011470#endif // #if VMA_STATS_STRING_ENABLED
@@ -15769,6 +15819,15 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
1576915819 {
1577015820 json.BeginString();
1577115821 json.ContinueString(m_Pools[poolIndex]->GetId());
15822+ const char* poolName = m_Pools[poolIndex]->GetName();
15823+ if(poolName != VMA_NULL && poolName[0] != '\0')
15824+ {
15825+ json.ContinueString(" ");
15826+ json.ContinueString(poolName);
15827+ }
15828+ else
15829+ {
15830+ }
1577215831 json.EndString();
1577315832
1577415833 m_Pools[poolIndex]->m_BlockVector.PrintDetailedMap(json);
@@ -16213,6 +16272,34 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckPoolCorruption(VmaAllocator allocato
1621316272 return allocator->CheckPoolCorruption(pool);
1621416273}
1621516274
16275+ VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolName(
16276+ VmaAllocator allocator,
16277+ VmaPool pool,
16278+ const char** ppName)
16279+ {
16280+ VMA_ASSERT(allocator && pool);
16281+
16282+ VMA_DEBUG_LOG("vmaGetPoolName");
16283+
16284+ VMA_DEBUG_GLOBAL_MUTEX_LOCK
16285+
16286+ *ppName = pool->GetName();
16287+ }
16288+
16289+ VMA_CALL_PRE void VMA_CALL_POST vmaSetPoolName(
16290+ VmaAllocator allocator,
16291+ VmaPool pool,
16292+ const char* pName)
16293+ {
16294+ VMA_ASSERT(allocator && pool);
16295+
16296+ VMA_DEBUG_LOG("vmaSetPoolName");
16297+
16298+ VMA_DEBUG_GLOBAL_MUTEX_LOCK
16299+
16300+ pool->SetName(pName);
16301+ }
16302+
1621616303VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemory(
1621716304 VmaAllocator allocator,
1621816305 const VkMemoryRequirements* pVkMemoryRequirements,
0 commit comments