This commit is contained in:
Adam Sawicki 2018-08-20 10:52:54 +02:00
parent ab8550340c
commit 87c8189002
2 changed files with 102 additions and 6 deletions

View File

@ -44,6 +44,15 @@ static enum class VERBOSITY
} g_Verbosity = VERBOSITY::DEFAULT; } g_Verbosity = VERBOSITY::DEFAULT;
static std::string g_FilePath; static std::string g_FilePath;
// Most significant 16 bits are major version, least significant 16 bits are minor version.
static uint32_t g_FileVersion;
static bool ValidateFileVersion()
{
const uint32_t major = g_FileVersion >> 16;
const uint32_t minor = g_FileVersion & 0xFFFF;
return major == 1 && minor <= 2;
}
struct StrRange struct StrRange
{ {
@ -176,6 +185,24 @@ void CsvSplit::Set(const StrRange& line, size_t maxCount)
m_Count = rangeIndex; m_Count = rangeIndex;
} }
static bool ParseFileVersion(const StrRange& s)
{
CsvSplit csvSplit;
csvSplit.Set(s, 2);
uint32_t major, minor;
if(csvSplit.GetCount() == 2 &&
StrRangeToUint(csvSplit.GetRange(0), major) &&
StrRangeToUint(csvSplit.GetRange(1), minor))
{
g_FileVersion = (major << 16) | minor;
return true;
}
else
{
return false;
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// class Statistics // class Statistics
@ -442,6 +469,7 @@ private:
void ExecuteCreateImage(size_t lineNumber, const CsvSplit& csvSplit); void ExecuteCreateImage(size_t lineNumber, const CsvSplit& csvSplit);
void ExecuteDestroyImage(size_t lineNumber, const CsvSplit& csvSplit) { DestroyAllocation(lineNumber, csvSplit); } void ExecuteDestroyImage(size_t lineNumber, const CsvSplit& csvSplit) { DestroyAllocation(lineNumber, csvSplit); }
void ExecuteFreeMemory(size_t lineNumber, const CsvSplit& csvSplit) { DestroyAllocation(lineNumber, csvSplit); } void ExecuteFreeMemory(size_t lineNumber, const CsvSplit& csvSplit) { DestroyAllocation(lineNumber, csvSplit); }
void ExecuteCreateLostAllocation(size_t lineNumber, const CsvSplit& csvSplit);
void DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit); void DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit);
}; };
@ -566,6 +594,8 @@ void Player::ExecuteLine(size_t lineNumber, const StrRange& line)
ExecuteDestroyImage(lineNumber, csvSplit); ExecuteDestroyImage(lineNumber, csvSplit);
else if(StrRangeEq(functionName, "vmaFreeMemory")) else if(StrRangeEq(functionName, "vmaFreeMemory"))
ExecuteFreeMemory(lineNumber, csvSplit); ExecuteFreeMemory(lineNumber, csvSplit);
else if(StrRangeEq(functionName, "vmaCreateLostAllocation"))
ExecuteCreateLostAllocation(lineNumber, csvSplit);
else else
{ {
if(IssueWarning()) if(IssueWarning())
@ -1250,6 +1280,64 @@ void Player::ExecuteCreateImage(size_t lineNumber, const CsvSplit& csvSplit)
} }
} }
void Player::ExecuteCreateLostAllocation(size_t lineNumber, const CsvSplit& csvSplit)
{
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 1, false))
{
uint64_t origPtr = 0;
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr))
{
// TODO
if(origPool != 0)
{
const auto poolIt = m_Pools.find(origPool);
if(poolIt != m_Pools.end())
allocCreateInfo.pool = poolIt->second.pool;
else
{
if(IssueWarning())
{
printf("Line %zu: Pool %llX not found.\n", lineNumber, origPool);
}
}
}
Allocation allocDesc = {};
VkResult res = vmaCreateBuffer(m_Allocator, &bufCreateInfo, &allocCreateInfo, &allocDesc.buffer, &allocDesc.allocation, nullptr);
if(res == VK_SUCCESS)
{
m_Stats.RegisterCreateBuffer(bufCreateInfo.usage);
}
else
{
if(IssueWarning())
{
printf("Line %zu: vmaCreateBuffer failed (%u).\n", lineNumber, res);
}
}
const auto existingIt = m_Allocations.find(origPtr);
if(existingIt != m_Allocations.end())
{
if(IssueWarning())
{
printf("Line %zu: Allocation %llX already exists.\n", lineNumber, origPtr);
}
}
m_Allocations[origPtr] = allocDesc;
}
else
{
if(IssueWarning())
{
printf("Line %zu: Invalid parameters for vmaCreateLostAllocation.\n", lineNumber);
}
}
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Main functions // Main functions
@ -1285,8 +1373,7 @@ static int ProcessFile(const char* data, size_t numBytes)
return RESULT_ERROR_FORMAT; return RESULT_ERROR_FORMAT;
} }
if(!lineSplit.GetNextLine(line) || if(!lineSplit.GetNextLine(line) || !ParseFileVersion(line) || !ValidateFileVersion())
!(StrRangeEq(line, "1,0") || StrRangeEq(line, "1,1")))
{ {
printf("ERROR: Incorrect file format version.\n"); printf("ERROR: Incorrect file format version.\n");
return RESULT_ERROR_FORMAT; return RESULT_ERROR_FORMAT;

View File

@ -2666,7 +2666,7 @@ void EnsureFile()
{ {
fopen_s(&g_File, "VMA_Usage_Dump", "wb"); fopen_s(&g_File, "VMA_Usage_Dump", "wb");
fprintf(g_File, "%s\n", "Vulkan Memory Allocator,Calls recording"); fprintf(g_File, "%s\n", "Vulkan Memory Allocator,Calls recording");
fprintf(g_File, "%s\n", "1,1"); fprintf(g_File, "%s\n", "1,2");
QueryPerformanceFrequency(&g_Freq); QueryPerformanceFrequency(&g_Freq);
QueryPerformanceCounter(&g_StartCounter); QueryPerformanceCounter(&g_StartCounter);
} }
@ -10003,12 +10003,23 @@ void vmaCreateLostAllocation(
VmaAllocator allocator, VmaAllocator allocator,
VmaAllocation* pAllocation) VmaAllocation* pAllocation)
{ {
Crash();
VMA_ASSERT(allocator && pAllocation); VMA_ASSERT(allocator && pAllocation);
VMA_DEBUG_GLOBAL_MUTEX_LOCK; VMA_DEBUG_GLOBAL_MUTEX_LOCK;
allocator->CreateLostAllocation(pAllocation); allocator->CreateLostAllocation(pAllocation);
{
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,vmaCreateLostAllocation,%p\n", threadId, time, frameIndex,
(*pAllocation));
fflush(g_File);
}
} }
VkResult vmaMapMemory( VkResult vmaMapMemory(
@ -10089,7 +10100,6 @@ VkResult vmaBindBufferMemory(
VmaAllocation allocation, VmaAllocation allocation,
VkBuffer buffer) VkBuffer buffer)
{ {
Crash();
VMA_ASSERT(allocator && allocation && buffer); VMA_ASSERT(allocator && allocation && buffer);
VMA_DEBUG_LOG("vmaBindBufferMemory"); VMA_DEBUG_LOG("vmaBindBufferMemory");
@ -10104,7 +10114,6 @@ VkResult vmaBindImageMemory(
VmaAllocation allocation, VmaAllocation allocation,
VkImage image) VkImage image)
{ {
Crash();
VMA_ASSERT(allocator && allocation && image); VMA_ASSERT(allocator && allocation && image);
VMA_DEBUG_LOG("vmaBindImageMemory"); VMA_DEBUG_LOG("vmaBindImageMemory");