diff --git a/docs/Recording file format.md b/docs/Recording file format.md index 65c0b9e..02e414b 100644 --- a/docs/Recording file format.md +++ b/docs/Recording file format.md @@ -154,6 +154,10 @@ No parameters. - offset : uint64 - size : uint64 +**vmaTouchAllocation, vmaGetAllocationInfo** (min format version 1.2) + +- allocation : pointer + ## Data types **bool** diff --git a/src/VmaReplay/VmaReplay.cpp b/src/VmaReplay/VmaReplay.cpp index d3dc579..7ab8df3 100644 --- a/src/VmaReplay/VmaReplay.cpp +++ b/src/VmaReplay/VmaReplay.cpp @@ -517,6 +517,8 @@ private: 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 ExecuteTouchAllocation(size_t lineNumber, const CsvSplit& csvSplit); + void ExecuteGetAllocationInfo(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); else if(StrRangeEq(functionName, "vmaInvalidateAllocation")) ExecuteInvalidateAllocation(lineNumber, csvSplit); + else if(StrRangeEq(functionName, "vmaTouchAllocation")) + ExecuteTouchAllocation(lineNumber, csvSplit); + else if(StrRangeEq(functionName, "vmaGetAllocationInfo")) + ExecuteGetAllocationInfo(lineNumber, csvSplit); else { if(IssueWarning()) @@ -1620,11 +1626,21 @@ void Player::ExecuteMapMemory(size_t lineNumber, const CsvSplit& csvSplit) 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) + if(it->second.allocation) { - 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 @@ -1659,7 +1675,17 @@ void Player::ExecuteUnmapMemory(size_t lineNumber, const CsvSplit& csvSplit) const auto it = m_Allocations.find(origPtr); 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 { @@ -1697,7 +1723,17 @@ void Player::ExecuteFlushAllocation(size_t lineNumber, const CsvSplit& csvSplit) const auto it = m_Allocations.find(origPtr); 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 { @@ -1735,7 +1771,17 @@ void Player::ExecuteInvalidateAllocation(size_t lineNumber, const CsvSplit& csvS const auto it = m_Allocations.find(origPtr); 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 { @@ -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 diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index b6d62c0..8fda710 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -4803,6 +4803,10 @@ public: VmaAllocation allocation); void RecordDestroyImage(uint32_t frameIndex, VmaAllocation allocation); + void RecordTouchAllocation(uint32_t frameIndex, + VmaAllocation allocation); + void RecordGetAllocationInfo(uint32_t frameIndex, + VmaAllocation allocation); private: struct CallParams @@ -8432,6 +8436,30 @@ void VmaRecorder::RecordDestroyImage(uint32_t frameIndex, 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) { if(pUserData != VMA_NULL) @@ -10519,6 +10547,15 @@ void vmaGetAllocationInfo( 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); } @@ -10530,6 +10567,15 @@ VkBool32 vmaTouchAllocation( 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); }