Added support for vmaMapMemory, vmaUnmapMemory, vmaFlushAllocation, vmaInvalidateAllocation.

This commit is contained in:
Adam Sawicki 2018-08-20 13:54:54 +02:00
parent 29785d1169
commit 5557b0ed63
2 changed files with 212 additions and 0 deletions

View File

@ -524,6 +524,10 @@ private:
void ExecuteCreateLostAllocation(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteAllocateMemory(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteAllocateMemoryForBufferOrImage(size_t lineNumber, const CsvSplit& csvSplit, OBJECT_TYPE objType);
void ExecuteMapMemory(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteUnmapMemory(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteFlushAllocation(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteInvalidateAllocation(size_t lineNumber, const CsvSplit& csvSplit);
void DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit);
};
@ -656,6 +660,14 @@ void Player::ExecuteLine(size_t lineNumber, const StrRange& line)
ExecuteAllocateMemoryForBufferOrImage(lineNumber, csvSplit, OBJECT_TYPE::BUFFER);
else if(StrRangeEq(functionName, "vmaAllocateMemoryForImage"))
ExecuteAllocateMemoryForBufferOrImage(lineNumber, csvSplit, OBJECT_TYPE::IMAGE);
else if(StrRangeEq(functionName, "vmaMapMemory"))
ExecuteMapMemory(lineNumber, csvSplit);
else if(StrRangeEq(functionName, "vmaUnmapMemory"))
ExecuteUnmapMemory(lineNumber, csvSplit);
else if(StrRangeEq(functionName, "vmaFlushAllocation"))
ExecuteFlushAllocation(lineNumber, csvSplit);
else if(StrRangeEq(functionName, "vmaInvalidateAllocation"))
ExecuteInvalidateAllocation(lineNumber, csvSplit);
else
{
if(IssueWarning())
@ -1469,6 +1481,154 @@ void Player::ExecuteAllocateMemoryForBufferOrImage(size_t lineNumber, const CsvS
}
}
void Player::ExecuteMapMemory(size_t lineNumber, const CsvSplit& csvSplit)
{
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 1, false))
{
uint64_t origPtr = 0;
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr))
{
if(origPtr != 0)
{
const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end())
{
void* pData;
VkResult res = vmaMapMemory(m_Allocator, it->second.allocation, &pData);
if(res != VK_SUCCESS)
{
printf("Line %zu: vmaMapMemory failed (%u)\n", lineNumber, res);
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Allocation %llX not found.\n", lineNumber, origPtr);
}
}
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Invalid parameters for vmaMapMemory.\n", lineNumber);
}
}
}
}
void Player::ExecuteUnmapMemory(size_t lineNumber, const CsvSplit& csvSplit)
{
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 1, false))
{
uint64_t origPtr = 0;
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr))
{
if(origPtr != 0)
{
const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end())
{
vmaUnmapMemory(m_Allocator, it->second.allocation);
}
else
{
if(IssueWarning())
{
printf("Line %zu: Allocation %llX not found.\n", lineNumber, origPtr);
}
}
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Invalid parameters for vmaMapMemory.\n", lineNumber);
}
}
}
}
void Player::ExecuteFlushAllocation(size_t lineNumber, const CsvSplit& csvSplit)
{
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 3, false))
{
uint64_t origPtr = 0;
uint64_t offset = 0;
uint64_t size = 0;
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr) &&
StrRangeToUint(csvSplit.GetRange(FIRST_PARAM_INDEX + 1), offset) &&
StrRangeToUint(csvSplit.GetRange(FIRST_PARAM_INDEX + 2), size))
{
if(origPtr != 0)
{
const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end())
{
vmaFlushAllocation(m_Allocator, it->second.allocation, offset, size);
}
else
{
if(IssueWarning())
{
printf("Line %zu: Allocation %llX not found.\n", lineNumber, origPtr);
}
}
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Invalid parameters for vmaFlushAllocation.\n", lineNumber);
}
}
}
}
void Player::ExecuteInvalidateAllocation(size_t lineNumber, const CsvSplit& csvSplit)
{
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 3, false))
{
uint64_t origPtr = 0;
uint64_t offset = 0;
uint64_t size = 0;
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr) &&
StrRangeToUint(csvSplit.GetRange(FIRST_PARAM_INDEX + 1), offset) &&
StrRangeToUint(csvSplit.GetRange(FIRST_PARAM_INDEX + 2), size))
{
if(origPtr != 0)
{
const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end())
{
vmaInvalidateAllocation(m_Allocator, it->second.allocation, offset, size);
}
else
{
if(IssueWarning())
{
printf("Line %zu: Allocation %llX not found.\n", lineNumber, origPtr);
}
}
}
}
else
{
if(IssueWarning())
{
printf("Line %zu: Invalid parameters for vmaInvalidateAllocation.\n", lineNumber);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Main functions

View File

@ -10107,6 +10107,18 @@ VkResult vmaMapMemory(
{
VMA_ASSERT(allocator && allocation && ppData);
{
VmaMutexLock lock(g_FileMutex, true);
EnsureFile();
LARGE_INTEGER counter; QueryPerformanceCounter(&counter);
const DWORD threadId = GetCurrentThreadId();
const double time = (double)(counter.QuadPart - g_StartCounter.QuadPart) / (double)g_Freq.QuadPart;
const uint32_t frameIndex = allocator->GetCurrentFrameIndex();
fprintf(g_File, "%u,%.3f,%u,vmaMapMemory,%p\n", threadId, time, frameIndex,
allocation);
fflush(g_File);
}
VMA_DEBUG_GLOBAL_MUTEX_LOCK
return allocator->Map(allocation, ppData);
@ -10118,6 +10130,18 @@ void vmaUnmapMemory(
{
VMA_ASSERT(allocator && allocation);
{
VmaMutexLock lock(g_FileMutex, true);
EnsureFile();
LARGE_INTEGER counter; QueryPerformanceCounter(&counter);
const DWORD threadId = GetCurrentThreadId();
const double time = (double)(counter.QuadPart - g_StartCounter.QuadPart) / (double)g_Freq.QuadPart;
const uint32_t frameIndex = allocator->GetCurrentFrameIndex();
fprintf(g_File, "%u,%.3f,%u,vmaUnmapMemory,%p\n", threadId, time, frameIndex,
allocation);
fflush(g_File);
}
VMA_DEBUG_GLOBAL_MUTEX_LOCK
allocator->Unmap(allocation);
@ -10129,6 +10153,20 @@ void vmaFlushAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDevi
VMA_DEBUG_LOG("vmaFlushAllocation");
{
VmaMutexLock lock(g_FileMutex, true);
EnsureFile();
LARGE_INTEGER counter; QueryPerformanceCounter(&counter);
const DWORD threadId = GetCurrentThreadId();
const double time = (double)(counter.QuadPart - g_StartCounter.QuadPart) / (double)g_Freq.QuadPart;
const uint32_t frameIndex = allocator->GetCurrentFrameIndex();
fprintf(g_File, "%u,%.3f,%u,vmaFlushAllocation,%p,%llu,%llu\n", threadId, time, frameIndex,
allocation,
offset,
size);
fflush(g_File);
}
VMA_DEBUG_GLOBAL_MUTEX_LOCK
allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_FLUSH);
@ -10140,6 +10178,20 @@ void vmaInvalidateAllocation(VmaAllocator allocator, VmaAllocation allocation, V
VMA_DEBUG_LOG("vmaInvalidateAllocation");
{
VmaMutexLock lock(g_FileMutex, true);
EnsureFile();
LARGE_INTEGER counter; QueryPerformanceCounter(&counter);
const DWORD threadId = GetCurrentThreadId();
const double time = (double)(counter.QuadPart - g_StartCounter.QuadPart) / (double)g_Freq.QuadPart;
const uint32_t frameIndex = allocator->GetCurrentFrameIndex();
fprintf(g_File, "%u,%.3f,%u,vmaInvalidateAllocation,%p,%llu,%llu\n", threadId, time, frameIndex,
allocation,
offset,
size);
fflush(g_File);
}
VMA_DEBUG_GLOBAL_MUTEX_LOCK
allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_INVALIDATE);