Added recording and replaying of calls to functions: vmaTouchAllocation, vmaGetAllocationInfo. VmaReplay: fixed handling of null allocation.

This commit is contained in:
Adam Sawicki 2018-08-21 10:59:53 +02:00
parent b3ea2c62f1
commit 80cb2365c5
3 changed files with 184 additions and 7 deletions

View file

@ -154,6 +154,10 @@ No parameters.
- offset : uint64 - offset : uint64
- size : uint64 - size : uint64
**vmaTouchAllocation, vmaGetAllocationInfo** (min format version 1.2)
- allocation : pointer
## Data types ## Data types
**bool** **bool**

View file

@ -517,6 +517,8 @@ private:
void ExecuteUnmapMemory(size_t lineNumber, const CsvSplit& csvSplit); void ExecuteUnmapMemory(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteFlushAllocation(size_t lineNumber, const CsvSplit& csvSplit); void ExecuteFlushAllocation(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteInvalidateAllocation(size_t lineNumber, const CsvSplit& csvSplit); void ExecuteInvalidateAllocation(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteTouchAllocation(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteGetAllocationInfo(size_t lineNumber, const CsvSplit& csvSplit);
void DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit); void DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit);
}; };
@ -644,6 +646,10 @@ void Player::ExecuteLine(size_t lineNumber, const StrRange& line)
ExecuteFlushAllocation(lineNumber, csvSplit); ExecuteFlushAllocation(lineNumber, csvSplit);
else if(StrRangeEq(functionName, "vmaInvalidateAllocation")) else if(StrRangeEq(functionName, "vmaInvalidateAllocation"))
ExecuteInvalidateAllocation(lineNumber, csvSplit); ExecuteInvalidateAllocation(lineNumber, csvSplit);
else if(StrRangeEq(functionName, "vmaTouchAllocation"))
ExecuteTouchAllocation(lineNumber, csvSplit);
else if(StrRangeEq(functionName, "vmaGetAllocationInfo"))
ExecuteGetAllocationInfo(lineNumber, csvSplit);
else else
{ {
if(IssueWarning()) if(IssueWarning())
@ -1620,11 +1626,21 @@ void Player::ExecuteMapMemory(size_t lineNumber, const CsvSplit& csvSplit)
const auto it = m_Allocations.find(origPtr); const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end()) if(it != m_Allocations.end())
{ {
void* pData; if(it->second.allocation)
VkResult res = vmaMapMemory(m_Allocator, it->second.allocation, &pData);
if(res != VK_SUCCESS)
{ {
printf("Line %zu: vmaMapMemory failed (%d)\n", lineNumber, res); void* pData;
VkResult res = vmaMapMemory(m_Allocator, it->second.allocation, &pData);
if(res != VK_SUCCESS)
{
printf("Line %zu: vmaMapMemory failed (%d)\n", lineNumber, res);
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Cannot call vmaMapMemory - allocation is null.\n", lineNumber);
}
} }
} }
else else
@ -1659,7 +1675,17 @@ void Player::ExecuteUnmapMemory(size_t lineNumber, const CsvSplit& csvSplit)
const auto it = m_Allocations.find(origPtr); const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end()) if(it != m_Allocations.end())
{ {
vmaUnmapMemory(m_Allocator, it->second.allocation); if(it->second.allocation)
{
vmaUnmapMemory(m_Allocator, it->second.allocation);
}
else
{
if(IssueWarning())
{
printf("Line %zu: Cannot call vmaUnmapMemory - allocation is null.\n", lineNumber);
}
}
} }
else else
{ {
@ -1697,7 +1723,17 @@ void Player::ExecuteFlushAllocation(size_t lineNumber, const CsvSplit& csvSplit)
const auto it = m_Allocations.find(origPtr); const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end()) if(it != m_Allocations.end())
{ {
vmaFlushAllocation(m_Allocator, it->second.allocation, offset, size); if(it->second.allocation)
{
vmaFlushAllocation(m_Allocator, it->second.allocation, offset, size);
}
else
{
if(IssueWarning())
{
printf("Line %zu: Cannot call vmaFlushAllocation - allocation is null.\n", lineNumber);
}
}
} }
else else
{ {
@ -1735,7 +1771,17 @@ void Player::ExecuteInvalidateAllocation(size_t lineNumber, const CsvSplit& csvS
const auto it = m_Allocations.find(origPtr); const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end()) if(it != m_Allocations.end())
{ {
vmaInvalidateAllocation(m_Allocator, it->second.allocation, offset, size); if(it->second.allocation)
{
vmaInvalidateAllocation(m_Allocator, it->second.allocation, offset, size);
}
else
{
if(IssueWarning())
{
printf("Line %zu: Cannot call vmaInvalidateAllocation - allocation is null.\n", lineNumber);
}
}
} }
else else
{ {
@ -1756,6 +1802,87 @@ void Player::ExecuteInvalidateAllocation(size_t lineNumber, const CsvSplit& csvS
} }
} }
void Player::ExecuteTouchAllocation(size_t lineNumber, const CsvSplit& csvSplit)
{
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 1, false))
{
uint64_t origPtr = 0;
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr))
{
const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end())
{
if(it->second.allocation)
{
vmaTouchAllocation(m_Allocator, it->second.allocation);
}
else
{
if(IssueWarning())
{
printf("Line %zu: Cannot call vmaTouchAllocation - allocation is null.\n", lineNumber);
}
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Allocation %llX not found.\n", lineNumber, origPtr);
}
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Invalid parameters for vmaTouchAllocation.\n", lineNumber);
}
}
}
}
void Player::ExecuteGetAllocationInfo(size_t lineNumber, const CsvSplit& csvSplit)
{
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 1, false))
{
uint64_t origPtr = 0;
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr))
{
const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end())
{
if(it->second.allocation)
{
VmaAllocationInfo allocInfo;
vmaGetAllocationInfo(m_Allocator, it->second.allocation, &allocInfo);
}
else
{
if(IssueWarning())
{
printf("Line %zu: Cannot call vmaGetAllocationInfo - allocation is null.\n", lineNumber);
}
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Allocation %llX not found.\n", lineNumber, origPtr);
}
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Invalid parameters for vmaGetAllocationInfo.\n", lineNumber);
}
}
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Main functions // Main functions

View file

@ -4803,6 +4803,10 @@ public:
VmaAllocation allocation); VmaAllocation allocation);
void RecordDestroyImage(uint32_t frameIndex, void RecordDestroyImage(uint32_t frameIndex,
VmaAllocation allocation); VmaAllocation allocation);
void RecordTouchAllocation(uint32_t frameIndex,
VmaAllocation allocation);
void RecordGetAllocationInfo(uint32_t frameIndex,
VmaAllocation allocation);
private: private:
struct CallParams struct CallParams
@ -8432,6 +8436,30 @@ void VmaRecorder::RecordDestroyImage(uint32_t frameIndex,
Flush(); Flush();
} }
void VmaRecorder::RecordTouchAllocation(uint32_t frameIndex,
VmaAllocation allocation)
{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaTouchAllocation,%p\n", callParams.threadId, callParams.time, frameIndex,
allocation);
Flush();
}
void VmaRecorder::RecordGetAllocationInfo(uint32_t frameIndex,
VmaAllocation allocation)
{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaGetAllocationInfo,%p\n", callParams.threadId, callParams.time, frameIndex,
allocation);
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)
@ -10519,6 +10547,15 @@ void vmaGetAllocationInfo(
VMA_DEBUG_GLOBAL_MUTEX_LOCK VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordGetAllocationInfo(
allocator->GetCurrentFrameIndex(),
allocation);
}
#endif
allocator->GetAllocationInfo(allocation, pAllocationInfo); allocator->GetAllocationInfo(allocation, pAllocationInfo);
} }
@ -10530,6 +10567,15 @@ VkBool32 vmaTouchAllocation(
VMA_DEBUG_GLOBAL_MUTEX_LOCK VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordTouchAllocation(
allocator->GetCurrentFrameIndex(),
allocation);
}
#endif
return allocator->TouchAllocation(allocation); return allocator->TouchAllocation(allocation);
} }