From 5f8798cf942a97d7a1da07e63f77d1011a1b2d6d Mon Sep 17 00:00:00 2001 From: refractionpcsx2 Date: Sat, 13 May 2023 00:35:46 +0100 Subject: [PATCH] VMManager: Split reload game swap, avoid reloading patches --- pcsx2/CDVD/CDVD.cpp | 2 +- pcsx2/VMManager.cpp | 40 ++++++++++++++++++++++++---------------- pcsx2/VMManager.h | 1 + 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index 82d77a3e1f..c4f0ab290b 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -1452,7 +1452,7 @@ void cdvdUpdateTrayState() if (g_GameStarted) { cdvdReloadElfInfo(); - VMManager::Internal::GameStartingOnCPUThread(); + VMManager::Internal::SwappingGameOnCPUThread(); } break; case CDVD_DISC_SEEKING: diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index 1709c83117..262539ac7a 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -90,7 +90,7 @@ namespace VMManager static bool CheckBIOSAvailability(); static void LoadPatches(const std::string& serial, u32 crc, bool show_messages, bool show_messages_when_disabled); - static void UpdateRunningGame(bool resetting, bool game_starting); + static void UpdateRunningGame(bool resetting, bool game_starting, bool swapping); static std::string GetCurrentSaveStateFileName(s32 slot); static bool DoLoadState(const char* filename); @@ -669,7 +669,7 @@ void VMManager::LoadPatches(const std::string& serial, u32 crc, bool show_messag } } -void VMManager::UpdateRunningGame(bool resetting, bool game_starting) +void VMManager::UpdateRunningGame(bool resetting, bool game_starting, bool swapping_disc) { // The CRC can be known before the game actually starts (at the bios), so when // we have the CRC but we're still at the bios and the settings are changed @@ -731,20 +731,23 @@ void VMManager::UpdateRunningGame(bool resetting, bool game_starting) UpdateGameSettingsLayer(); ApplySettings(); - // Clear the memory card eject notification again when booting for the first time, or starting. - // Otherwise, games think the card was removed on boot. - if (game_starting || resetting) - AutoEject::ClearAll(); + if (!swapping_disc) + { + // Clear the memory card eject notification again when booting for the first time, or starting. + // Otherwise, games think the card was removed on boot. + if (game_starting || resetting) + AutoEject::ClearAll(); - // Check this here, for two cases: dynarec on, and when enable cheats is set per-game. - if (s_patches_crc != s_game_crc) - ReloadPatches(game_starting, false); + // Check this here, for two cases: dynarec on, and when enable cheats is set per-game. + if (s_patches_crc != s_game_crc) + ReloadPatches(game_starting, false); #ifdef ENABLE_ACHIEVEMENTS - // Per-game ini enabling of hardcore mode. We need to re-enforce the settings if so. - if (game_starting && Achievements::ResetChallengeMode()) - ApplySettings(); + // Per-game ini enabling of hardcore mode. We need to re-enforce the settings if so. + if (game_starting && Achievements::ResetChallengeMode()) + ApplySettings(); #endif + } GetMTGS().SendGameCRC(new_crc); @@ -1047,7 +1050,7 @@ bool VMManager::Initialize(VMBootParameters boot_params) s_state.store(VMState::Paused, std::memory_order_release); Host::OnVMStarted(); - UpdateRunningGame(true, false); + UpdateRunningGame(true, false, false); SetEmuThreadAffinities(); @@ -1184,7 +1187,7 @@ void VMManager::Reset() // gameid change, so apply settings if (game_was_started) - UpdateRunningGame(true, false); + UpdateRunningGame(true, false, false); if (g_InputRecording.isActive()) { @@ -1247,7 +1250,7 @@ bool VMManager::DoLoadState(const char* filename) { Host::OnSaveStateLoading(filename); SaveState_UnzipFromDisk(filename); - UpdateRunningGame(false, false); + UpdateRunningGame(false, false, false); Host::OnSaveStateLoaded(filename, true); if (g_InputRecording.isActive()) { @@ -1607,11 +1610,16 @@ void VMManager::Internal::EntryPointCompilingOnCPUThread() void VMManager::Internal::GameStartingOnCPUThread() { - UpdateRunningGame(false, true); + UpdateRunningGame(false, true, false); ApplyLoadedPatches(PPT_ONCE_ON_LOAD); ApplyLoadedPatches(PPT_COMBINED_0_1); } +void VMManager::Internal::SwappingGameOnCPUThread() +{ + UpdateRunningGame(false, false, true); +} + void VMManager::Internal::VSyncOnCPUThread() { // TODO: Move frame limiting here to reduce CPU usage after sleeping... diff --git a/pcsx2/VMManager.h b/pcsx2/VMManager.h index ef25a4e592..adefe5e7fc 100644 --- a/pcsx2/VMManager.h +++ b/pcsx2/VMManager.h @@ -207,6 +207,7 @@ namespace VMManager bool IsExecutionInterrupted(); void EntryPointCompilingOnCPUThread(); void GameStartingOnCPUThread(); + void SwappingGameOnCPUThread(); void VSyncOnCPUThread(); } // namespace Internal } // namespace VMManager