From 313ddb7879ea627faf298c9292828a5ac0ee8799 Mon Sep 17 00:00:00 2001 From: Ty Lamontagne Date: Sun, 8 Dec 2024 14:05:03 -0500 Subject: [PATCH] EE Cache: Writeback dirty cache entries when exiting the interpreter. --- pcsx2/Cache.cpp | 11 +++++++++++ pcsx2/Cache.h | 3 +++ pcsx2/Interpreter.cpp | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/pcsx2/Cache.cpp b/pcsx2/Cache.cpp index 87d4a27a21..bc1e6a4f7b 100644 --- a/pcsx2/Cache.cpp +++ b/pcsx2/Cache.cpp @@ -163,6 +163,17 @@ void resetCache() std::memset(&cache, 0, sizeof(cache)); } +void writebackCache() +{ + for (int i = 0; i < 64; i++) + { + for (int j = 0; j < 2; j++) + { + cache.lineAt(i, j).writeBackIfNeeded(); + } + } +} + static bool findInCache(const CacheSet& set, uptr ppf, int* way) { auto check = [&](int checkWay) -> bool { diff --git a/pcsx2/Cache.h b/pcsx2/Cache.h index 68c0a4b11e..e77c04f15e 100644 --- a/pcsx2/Cache.h +++ b/pcsx2/Cache.h @@ -8,6 +8,9 @@ #include "common/SingleRegisterTypes.h" void resetCache(); +// Dumps all dirty cache entries to memory +// This is necessary to fix a bug when enabled the recompiler while the cache was enabled. +void writebackCache(); void writeCache8(u32 mem, u8 value, bool validPFN = true); void writeCache16(u32 mem, u16 value, bool validPFN = true); void writeCache32(u32 mem, u32 value, bool validPFN = true); diff --git a/pcsx2/Interpreter.cpp b/pcsx2/Interpreter.cpp index eebc0cd711..efca7d4896 100644 --- a/pcsx2/Interpreter.cpp +++ b/pcsx2/Interpreter.cpp @@ -5,6 +5,7 @@ #include "R5900OpcodeTables.h" #include "VMManager.h" #include "Elfheader.h" +#include "Cache.h" #include "DebugTools/Breakpoints.h" @@ -555,6 +556,8 @@ static void intEventTest() if (intExitExecution) { intExitExecution = false; + if (CHECK_EEREC) + writebackCache(); fastjmp_jmp(&intJmpBuf, 1); } } @@ -566,7 +569,11 @@ static void intSafeExitExecution() if (eeEventTestIsActive) intExitExecution = true; else + { + if (CHECK_EEREC) + writebackCache(); fastjmp_jmp(&intJmpBuf, 1); + } } static void intCancelInstruction()