Skip to content

Commit aeb9836

Browse files
Finish implementation of vmaSetPoolName, vmaGetPoolName
vmaSetPoolName was added to recording format. Recording format version was bumped to 1.7. #82
1 parent 49defd6 commit aeb9836

5 files changed

Lines changed: 83 additions & 6 deletions

File tree

src/VmaReplay/Common.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,16 @@ class CsvSplit
173173
size_t GetCount() const { return m_Count; }
174174
StrRange GetRange(size_t index) const
175175
{
176-
return StrRange {
177-
m_Line.beg + m_Ranges[index * 2],
178-
m_Line.beg + m_Ranges[index * 2 + 1] };
176+
if(index < m_Count)
177+
{
178+
return StrRange {
179+
m_Line.beg + m_Ranges[index * 2],
180+
m_Line.beg + m_Ranges[index * 2 + 1] };
181+
}
182+
else
183+
{
184+
return StrRange{0, 0};
185+
}
179186
}
180187

181188
private:

src/VmaReplay/Constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const char* VMA_FUNCTION_NAMES[] = {
5454
"vmaResizeAllocation",
5555
"vmaDefragmentationBegin",
5656
"vmaDefragmentationEnd",
57+
"vmaSetPoolName",
5758
};
5859
static_assert(
5960
_countof(VMA_FUNCTION_NAMES) == (size_t)VMA_FUNCTION::Count,

src/VmaReplay/Constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ enum class VMA_FUNCTION
8787
ResizeAllocation,
8888
DefragmentationBegin,
8989
DefragmentationEnd,
90+
SetPoolName,
9091
Count
9192
};
9293
extern const char* VMA_FUNCTION_NAMES[];

src/VmaReplay/VmaReplay.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ static size_t g_DefragmentAfterLineNextIndex = 0;
688688
static bool ValidateFileVersion()
689689
{
690690
if(GetVersionMajor(g_FileVersion) == 1 &&
691-
GetVersionMinor(g_FileVersion) <= 6)
691+
GetVersionMinor(g_FileVersion) <= 7)
692692
{
693693
return true;
694694
}
@@ -1665,6 +1665,7 @@ class Player
16651665
void ExecuteResizeAllocation(size_t lineNumber, const CsvSplit& csvSplit);
16661666
void ExecuteDefragmentationBegin(size_t lineNumber, const CsvSplit& csvSplit);
16671667
void ExecuteDefragmentationEnd(size_t lineNumber, const CsvSplit& csvSplit);
1668+
void ExecuteSetPoolName(size_t lineNumber, const CsvSplit& csvSplit);
16681669

16691670
void DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit, const char* functionName);
16701671

@@ -1819,6 +1820,8 @@ void Player::ExecuteLine(size_t lineNumber, const StrRange& line)
18191820
ExecuteDefragmentationBegin(lineNumber, csvSplit);
18201821
else if(StrRangeEq(functionName, VMA_FUNCTION_NAMES[(uint32_t)VMA_FUNCTION::DefragmentationEnd]))
18211822
ExecuteDefragmentationEnd(lineNumber, csvSplit);
1823+
else if(StrRangeEq(functionName, VMA_FUNCTION_NAMES[(uint32_t)VMA_FUNCTION::SetPoolName]))
1824+
ExecuteSetPoolName(lineNumber, csvSplit);
18221825
else
18231826
{
18241827
if(IssueWarning())
@@ -3863,6 +3866,48 @@ void Player::ExecuteDefragmentationEnd(size_t lineNumber, const CsvSplit& csvSpl
38633866
}
38643867
}
38653868

3869+
void Player::ExecuteSetPoolName(size_t lineNumber, const CsvSplit& csvSplit)
3870+
{
3871+
m_Stats.RegisterFunctionCall(VMA_FUNCTION::SetPoolName);
3872+
3873+
if(!g_UserDataEnabled)
3874+
{
3875+
return;
3876+
}
3877+
3878+
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 2, true))
3879+
{
3880+
uint64_t origPtr = 0;
3881+
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr))
3882+
{
3883+
if(origPtr != 0)
3884+
{
3885+
const auto it = m_Pools.find(origPtr);
3886+
if(it != m_Pools.end())
3887+
{
3888+
std::string poolName;
3889+
csvSplit.GetRange(FIRST_PARAM_INDEX + 1).to_str(poolName);
3890+
vmaSetPoolName(m_Allocator, it->second.pool, !poolName.empty() ? poolName.c_str() : nullptr);
3891+
}
3892+
else
3893+
{
3894+
if(IssueWarning())
3895+
{
3896+
printf("Line %zu: Pool %llX not found.\n", lineNumber, origPtr);
3897+
}
3898+
}
3899+
}
3900+
}
3901+
else
3902+
{
3903+
if(IssueWarning())
3904+
{
3905+
printf("Line %zu: Invalid parameters for vmaSetPoolName.\n", lineNumber);
3906+
}
3907+
}
3908+
}
3909+
}
3910+
38663911
////////////////////////////////////////////////////////////////////////////////
38673912
// Main functions
38683913

src/vk_mem_alloc.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolName(
25232523
VmaPool pool,
25242524
const char** ppName);
25252525

2526-
/* \brief Sets name of a custom pool.
2526+
/** \brief Sets name of a custom pool.
25272527

25282528
`pName` can be either null or pointer to a null-terminated string with new name for the pool.
25292529
Function makes internal copy of the string, so it can be changed or freed immediately after this call.
@@ -6702,6 +6702,9 @@ class VmaRecorder
67026702
VmaDefragmentationContext ctx);
67036703
void RecordDefragmentationEnd(uint32_t frameIndex,
67046704
VmaDefragmentationContext ctx);
6705+
void RecordSetPoolName(uint32_t frameIndex,
6706+
VmaPool pool,
6707+
const char* name);
67056708

67066709
private:
67076710
struct CallParams
@@ -13659,7 +13662,7 @@ VkResult VmaRecorder::Init(const VmaRecordSettings& settings, bool useMutex)
1365913662

1366013663
// Write header.
1366113664
fprintf(m_File, "%s\n", "Vulkan Memory Allocator,Calls recording");
13662-
fprintf(m_File, "%s\n", "1,6");
13665+
fprintf(m_File, "%s\n", "1,7");
1366313666

1366413667
return VK_SUCCESS;
1366513668
}
@@ -14092,6 +14095,19 @@ void VmaRecorder::RecordDefragmentationEnd(uint32_t frameIndex,
1409214095
Flush();
1409314096
}
1409414097

14098+
void VmaRecorder::RecordSetPoolName(uint32_t frameIndex,
14099+
VmaPool pool,
14100+
const char* name)
14101+
{
14102+
CallParams callParams;
14103+
GetBasicParams(callParams);
14104+
14105+
VmaMutexLock lock(m_FileMutex, m_UseMutex);
14106+
fprintf(m_File, "%u,%.3f,%u,vmaSetPoolName,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
14107+
pool, name != VMA_NULL ? name : "");
14108+
Flush();
14109+
}
14110+
1409514111
VmaRecorder::UserDataString::UserDataString(VmaAllocationCreateFlags allocFlags, const void* pUserData)
1409614112
{
1409714113
if(pUserData != VMA_NULL)
@@ -16303,6 +16319,13 @@ VMA_CALL_PRE void VMA_CALL_POST vmaSetPoolName(
1630316319
VMA_DEBUG_GLOBAL_MUTEX_LOCK
1630416320

1630516321
pool->SetName(pName);
16322+
16323+
#if VMA_RECORDING_ENABLED
16324+
if(allocator->GetRecorder() != VMA_NULL)
16325+
{
16326+
allocator->GetRecorder()->RecordSetPoolName(allocator->GetCurrentFrameIndex(), pool, pName);
16327+
}
16328+
#endif
1630616329
}
1630716330

1630816331
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemory(

0 commit comments

Comments
 (0)