diff --git a/src/VmaReplay/VmaReplay.cpp b/src/VmaReplay/VmaReplay.cpp index 24222c5..c0144bc 100644 --- a/src/VmaReplay/VmaReplay.cpp +++ b/src/VmaReplay/VmaReplay.cpp @@ -149,6 +149,39 @@ void CsvSplit::Set(const StrRange& line, size_t maxCount) m_Count = rangeIndex; } +//////////////////////////////////////////////////////////////////////////////// +// class Statistics + +class Statistics +{ +public: + Statistics() { } + + size_t GetImageCreationCount() const { return m_ImageCreationCount; } + size_t GetBufferCreationCount() const { return m_BufferCreationCount; } + size_t GetAllocationCreationCount() const { return m_AllocationCreationCount; } + + void RegisterCreateImage(); + void RegisterCreateBuffer(); + +private: + size_t m_ImageCreationCount = 0; + size_t m_BufferCreationCount = 0; + size_t m_AllocationCreationCount = 0; // Also includes buffers and images. +}; + +void Statistics::RegisterCreateImage() +{ + ++m_ImageCreationCount; + ++m_AllocationCreationCount; +} + +void Statistics::RegisterCreateBuffer() +{ + ++m_BufferCreationCount; + ++m_AllocationCreationCount; +} + //////////////////////////////////////////////////////////////////////////////// // class Player @@ -248,6 +281,8 @@ private: std::unordered_map m_Pools; std::unordered_map m_Allocations; + Statistics m_Stats; + void Destroy(const Allocation& alloc); // Increments warning counter. Returns true if warning message should be printed. @@ -256,6 +291,7 @@ private: int InitVulkan(); void FinalizeVulkan(); void RegisterDebugCallbacks(); + void PrintStats(); // If parmeter count doesn't match, issues warning and returns false. bool ValidateFunctionParameterCount(size_t lineNumber, const CsvSplit& csvSplit, size_t expectedParamCount, bool lastUnbound); @@ -282,6 +318,8 @@ int Player::Init() Player::~Player() { + PrintStats(); + FinalizeVulkan(); if(m_WarningCount > MAX_WARNINGS_TO_SHOW) @@ -321,6 +359,13 @@ void Player::ExecuteLine(size_t lineNumber, const StrRange& line) // Nothing to do. } } + else if(StrRangeEq(functionName, "vmaDestroyAllocator")) + { + if(ValidateFunctionParameterCount(lineNumber, csvSplit, 0, false)) + { + // Nothing to do. + } + } else if(StrRangeEq(functionName, "vmaCreatePool")) ExecuteCreatePool(lineNumber, csvSplit); else if(StrRangeEq(functionName, "vmaDestroyPool")) @@ -633,6 +678,14 @@ void Player::RegisterDebugCallbacks() assert(res == VK_SUCCESS); } +void Player::PrintStats() +{ + printf("Statistics:\n"); + printf(" Total allocations created: %zu\n", m_Stats.GetAllocationCreationCount()); + printf(" Total buffers created: %zu\n", m_Stats.GetBufferCreationCount()); + printf(" Total images created: %zu\n", m_Stats.GetImageCreationCount()); +} + bool Player::ValidateFunctionParameterCount(size_t lineNumber, const CsvSplit& csvSplit, size_t expectedParamCount, bool lastUnbound) { bool ok; @@ -756,18 +809,21 @@ void Player::ExecuteCreateBuffer(size_t lineNumber, const CsvSplit& csvSplit) VkResult res = vmaCreateBuffer(m_Allocator, &bufCreateInfo, &allocCreateInfo, &allocDesc.buffer, &allocDesc.allocation, nullptr); if(res == VK_SUCCESS) { - 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_Stats.RegisterCreateBuffer(); } 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 @@ -852,18 +908,21 @@ void Player::ExecuteCreateImage(size_t lineNumber, const CsvSplit& csvSplit) VkResult res = vmaCreateImage(m_Allocator, &imageCreateInfo, &allocCreateInfo, &allocDesc.image, &allocDesc.allocation, nullptr); if(res == VK_SUCCESS) { - 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_Stats.RegisterCreateImage(); } else { if(IssueWarning()) printf("Line %zu: vmaCreateImage 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 @@ -900,7 +959,7 @@ static int ProcessFile(const char* data, size_t numBytes) } if(!lineSplit.GetNextLine(line) || - !StrRangeEq(line, "1,0")) + !(StrRangeEq(line, "1,0") || StrRangeEq(line, "1,1"))) { printf("ERROR: Incorrect file format version.\n"); return RESULT_ERROR_FORMAT; diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index 53943bd..834adc5 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -2666,7 +2666,7 @@ void EnsureFile() { fopen_s(&g_File, "VMA_Usage_Dump", "wb"); fprintf(g_File, "%s\n", "Vulkan Memory Allocator,Calls recording"); - fprintf(g_File, "%s\n", "1,0"); + fprintf(g_File, "%s\n", "1,1"); QueryPerformanceFrequency(&g_Freq); QueryPerformanceCounter(&g_StartCounter); }