From 3938c0a3afeb935f406f3b0cf9aa35aae35e1d25 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 18 Nov 2022 23:11:11 -0800 Subject: [PATCH] Debugger: Combine mem info on duplicates. Gran Turismo does some churn on texture sizes, we can combine them and reduce the speed hit even when detailed. --- Core/Debugger/MemBlockInfo.cpp | 40 ++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/Core/Debugger/MemBlockInfo.cpp b/Core/Debugger/MemBlockInfo.cpp index e361b63014..909803b797 100644 --- a/Core/Debugger/MemBlockInfo.cpp +++ b/Core/Debugger/MemBlockInfo.cpp @@ -405,6 +405,29 @@ static inline uint32_t NormalizeAddress(uint32_t addr) { return addr & 0x3FFFFFFF; } +static inline bool MergeRecentMemInfo(const PendingNotifyMem &info, size_t copyLength) { + if (pendingNotifies.size() < 4) + return false; + + for (size_t i = 1; i <= 4; ++i) { + auto &prev = pendingNotifies[pendingNotifies.size() - i]; + if (prev.start >= info.start + info.size || prev.start + prev.size <= info.start) + continue; + + // This means there's overlap, but not a match, so we can't combine any. + if (prev.start != info.start || prev.size > info.size) + return false; + + memcpy(prev.tag, info.tag, copyLength + 1); + prev.size = info.size; + prev.ticks = info.ticks; + prev.pc = info.pc; + return true; + } + + return false; +} + void NotifyMemInfoPC(MemBlockFlags flags, uint32_t start, uint32_t size, uint32_t pc, const char *tagStr, size_t strLength) { if (size == 0) { return; @@ -427,14 +450,17 @@ void NotifyMemInfoPC(MemBlockFlags flags, uint32_t start, uint32_t size, uint32_ info.tag[copyLength] = 0; std::lock_guard guard(pendingMutex); - if (start < 0x08000000) { - pendingNotifyMinAddr1 = std::min(pendingNotifyMinAddr1.load(), start); - pendingNotifyMaxAddr1 = std::max(pendingNotifyMaxAddr1.load(), start + size); - } else { - pendingNotifyMinAddr2 = std::min(pendingNotifyMinAddr2.load(), start); - pendingNotifyMaxAddr2 = std::max(pendingNotifyMaxAddr2.load(), start + size); + // Sometimes we get duplicates, quickly check. + if (!MergeRecentMemInfo(info, copyLength)) { + if (start < 0x08000000) { + pendingNotifyMinAddr1 = std::min(pendingNotifyMinAddr1.load(), start); + pendingNotifyMaxAddr1 = std::max(pendingNotifyMaxAddr1.load(), start + size); + } else { + pendingNotifyMinAddr2 = std::min(pendingNotifyMinAddr2.load(), start); + pendingNotifyMaxAddr2 = std::max(pendingNotifyMaxAddr2.load(), start + size); + } + pendingNotifies.push_back(info); } - pendingNotifies.push_back(info); needFlush = pendingNotifies.size() > MAX_PENDING_NOTIFIES; }