Finish implementation of vmaSetPoolName, vmaGetPoolName

vmaSetPoolName was added to recording format. Recording format version was bumped to 1.7. #82
This commit is contained in:
Adam Sawicki 2019-11-18 12:34:54 +01:00
parent 49defd6056
commit aeb9836f4c
5 changed files with 83 additions and 6 deletions

View File

@ -172,11 +172,18 @@ public:
size_t GetCount() const { return m_Count; } size_t GetCount() const { return m_Count; }
StrRange GetRange(size_t index) const StrRange GetRange(size_t index) const
{
if(index < m_Count)
{ {
return StrRange { return StrRange {
m_Line.beg + m_Ranges[index * 2], m_Line.beg + m_Ranges[index * 2],
m_Line.beg + m_Ranges[index * 2 + 1] }; m_Line.beg + m_Ranges[index * 2 + 1] };
} }
else
{
return StrRange{0, 0};
}
}
private: private:
StrRange m_Line = { nullptr, nullptr }; StrRange m_Line = { nullptr, nullptr };

View File

@ -54,6 +54,7 @@ const char* VMA_FUNCTION_NAMES[] = {
"vmaResizeAllocation", "vmaResizeAllocation",
"vmaDefragmentationBegin", "vmaDefragmentationBegin",
"vmaDefragmentationEnd", "vmaDefragmentationEnd",
"vmaSetPoolName",
}; };
static_assert( static_assert(
_countof(VMA_FUNCTION_NAMES) == (size_t)VMA_FUNCTION::Count, _countof(VMA_FUNCTION_NAMES) == (size_t)VMA_FUNCTION::Count,

View File

@ -87,6 +87,7 @@ enum class VMA_FUNCTION
ResizeAllocation, ResizeAllocation,
DefragmentationBegin, DefragmentationBegin,
DefragmentationEnd, DefragmentationEnd,
SetPoolName,
Count Count
}; };
extern const char* VMA_FUNCTION_NAMES[]; extern const char* VMA_FUNCTION_NAMES[];

View File

@ -688,7 +688,7 @@ static size_t g_DefragmentAfterLineNextIndex = 0;
static bool ValidateFileVersion() static bool ValidateFileVersion()
{ {
if(GetVersionMajor(g_FileVersion) == 1 && if(GetVersionMajor(g_FileVersion) == 1 &&
GetVersionMinor(g_FileVersion) <= 6) GetVersionMinor(g_FileVersion) <= 7)
{ {
return true; return true;
} }
@ -1665,6 +1665,7 @@ private:
void ExecuteResizeAllocation(size_t lineNumber, const CsvSplit& csvSplit); void ExecuteResizeAllocation(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteDefragmentationBegin(size_t lineNumber, const CsvSplit& csvSplit); void ExecuteDefragmentationBegin(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteDefragmentationEnd(size_t lineNumber, const CsvSplit& csvSplit); void ExecuteDefragmentationEnd(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteSetPoolName(size_t lineNumber, const CsvSplit& csvSplit);
void DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit, const char* functionName); void DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit, const char* functionName);
@ -1819,6 +1820,8 @@ void Player::ExecuteLine(size_t lineNumber, const StrRange& line)
ExecuteDefragmentationBegin(lineNumber, csvSplit); ExecuteDefragmentationBegin(lineNumber, csvSplit);
else if(StrRangeEq(functionName, VMA_FUNCTION_NAMES[(uint32_t)VMA_FUNCTION::DefragmentationEnd])) else if(StrRangeEq(functionName, VMA_FUNCTION_NAMES[(uint32_t)VMA_FUNCTION::DefragmentationEnd]))
ExecuteDefragmentationEnd(lineNumber, csvSplit); ExecuteDefragmentationEnd(lineNumber, csvSplit);
else if(StrRangeEq(functionName, VMA_FUNCTION_NAMES[(uint32_t)VMA_FUNCTION::SetPoolName]))
ExecuteSetPoolName(lineNumber, csvSplit);
else else
{ {
if(IssueWarning()) if(IssueWarning())
@ -3863,6 +3866,48 @@ void Player::ExecuteDefragmentationEnd(size_t lineNumber, const CsvSplit& csvSpl
} }
} }
void Player::ExecuteSetPoolName(size_t lineNumber, const CsvSplit& csvSplit)
{
m_Stats.RegisterFunctionCall(VMA_FUNCTION::SetPoolName);
if(!g_UserDataEnabled)
{
return;
}
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 2, true))
{
uint64_t origPtr = 0;
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr))
{
if(origPtr != 0)
{
const auto it = m_Pools.find(origPtr);
if(it != m_Pools.end())
{
std::string poolName;
csvSplit.GetRange(FIRST_PARAM_INDEX + 1).to_str(poolName);
vmaSetPoolName(m_Allocator, it->second.pool, !poolName.empty() ? poolName.c_str() : nullptr);
}
else
{
if(IssueWarning())
{
printf("Line %zu: Pool %llX not found.\n", lineNumber, origPtr);
}
}
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Invalid parameters for vmaSetPoolName.\n", lineNumber);
}
}
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Main functions // Main functions

View File

@ -2523,7 +2523,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolName(
VmaPool pool, VmaPool pool,
const char** ppName); const char** ppName);
/* \brief Sets name of a custom pool. /** \brief Sets name of a custom pool.
`pName` can be either null or pointer to a null-terminated string with new name for the pool. `pName` can be either null or pointer to a null-terminated string with new name for the pool.
Function makes internal copy of the string, so it can be changed or freed immediately after this call. Function makes internal copy of the string, so it can be changed or freed immediately after this call.
@ -6702,6 +6702,9 @@ public:
VmaDefragmentationContext ctx); VmaDefragmentationContext ctx);
void RecordDefragmentationEnd(uint32_t frameIndex, void RecordDefragmentationEnd(uint32_t frameIndex,
VmaDefragmentationContext ctx); VmaDefragmentationContext ctx);
void RecordSetPoolName(uint32_t frameIndex,
VmaPool pool,
const char* name);
private: private:
struct CallParams struct CallParams
@ -13659,7 +13662,7 @@ VkResult VmaRecorder::Init(const VmaRecordSettings& settings, bool useMutex)
// Write header. // Write header.
fprintf(m_File, "%s\n", "Vulkan Memory Allocator,Calls recording"); fprintf(m_File, "%s\n", "Vulkan Memory Allocator,Calls recording");
fprintf(m_File, "%s\n", "1,6"); fprintf(m_File, "%s\n", "1,7");
return VK_SUCCESS; return VK_SUCCESS;
} }
@ -14092,6 +14095,19 @@ void VmaRecorder::RecordDefragmentationEnd(uint32_t frameIndex,
Flush(); Flush();
} }
void VmaRecorder::RecordSetPoolName(uint32_t frameIndex,
VmaPool pool,
const char* name)
{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaSetPoolName,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
pool, name != VMA_NULL ? name : "");
Flush();
}
VmaRecorder::UserDataString::UserDataString(VmaAllocationCreateFlags allocFlags, const void* pUserData) VmaRecorder::UserDataString::UserDataString(VmaAllocationCreateFlags allocFlags, const void* pUserData)
{ {
if(pUserData != VMA_NULL) if(pUserData != VMA_NULL)
@ -16303,6 +16319,13 @@ VMA_CALL_PRE void VMA_CALL_POST vmaSetPoolName(
VMA_DEBUG_GLOBAL_MUTEX_LOCK VMA_DEBUG_GLOBAL_MUTEX_LOCK
pool->SetName(pName); pool->SetName(pName);
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordSetPoolName(allocator->GetCurrentFrameIndex(), pool, pName);
}
#endif
} }
VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemory( VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemory(