From 2670d5a9aa50d64b076c3ab4af863605e57b831d Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Wed, 30 Mar 2022 19:46:06 +0100 Subject: [PATCH] Core: Move Applying GameFixes into GameEntry Also add similar logging to GS Hardware fixes (on Qt) --- pcsx2/GameDatabase.cpp | 108 ++++++++++++++++++++++++++++++++++++ pcsx2/GameDatabase.h | 3 + pcsx2/VMManager.cpp | 67 +--------------------- pcsx2/gui/AppCoreThread.cpp | 70 +---------------------- 4 files changed, 115 insertions(+), 133 deletions(-) diff --git a/pcsx2/GameDatabase.cpp b/pcsx2/GameDatabase.cpp index 1fd1f6009c..6b9b54b6d3 100644 --- a/pcsx2/GameDatabase.cpp +++ b/pcsx2/GameDatabase.cpp @@ -18,6 +18,7 @@ #include "GameDatabase.h" #include "Host.h" #include "Patch.h" +#include "vtlb.h" #include "common/FileSystem.h" #include "common/Path.h" @@ -327,6 +328,113 @@ bool GameDatabaseSchema::isUserHackHWFix(GSHWFixId id) } } +u32 GameDatabaseSchema::GameEntry::applyGameFixes(Pcsx2Config& config, bool applyAuto) const +{ + // Only apply core game fixes if the user has enabled them. + if (!applyAuto) + Console.Warning("[GameDB] Game Fixes are disabled"); + + u32 num_applied_fixes = 0; + + if (eeRoundMode != GameDatabaseSchema::RoundMode::Undefined) + { + const SSE_RoundMode eeRM = (SSE_RoundMode)enum_cast(eeRoundMode); + if (EnumIsValid(eeRM)) + { + if (applyAuto) + { + PatchesCon->WriteLn("(GameDB) Changing EE/FPU roundmode to %d [%s]", eeRM, EnumToString(eeRM)); + config.Cpu.sseMXCSR.SetRoundMode(eeRM); + num_applied_fixes++; + } + else + PatchesCon->Warning("[GameDB] Skipping changing EE/FPU roundmode to %d [%s]", eeRM, EnumToString(eeRM)); + } + } + + if (vuRoundMode != GameDatabaseSchema::RoundMode::Undefined) + { + const SSE_RoundMode vuRM = (SSE_RoundMode)enum_cast(vuRoundMode); + if (EnumIsValid(vuRM)) + { + if (applyAuto) + { + PatchesCon->WriteLn("(GameDB) Changing VU0/VU1 roundmode to %d [%s]", vuRM, EnumToString(vuRM)); + config.Cpu.sseVUMXCSR.SetRoundMode(vuRM); + num_applied_fixes++; + } + else + PatchesCon->Warning("[GameDB] Skipping changing VU0/VU1 roundmode to %d [%s]", vuRM, EnumToString(vuRM)); + } + } + + if (eeClampMode != GameDatabaseSchema::ClampMode::Undefined) + { + const int clampMode = enum_cast(eeClampMode); + if (applyAuto) + { + PatchesCon->WriteLn("(GameDB) Changing EE/FPU clamp mode [mode=%d]", clampMode); + config.Cpu.Recompiler.fpuOverflow = (clampMode >= 1); + config.Cpu.Recompiler.fpuExtraOverflow = (clampMode >= 2); + config.Cpu.Recompiler.fpuFullMode = (clampMode >= 3); + num_applied_fixes++; + } + else + PatchesCon->Warning("[GameDB] Skipping changing EE/FPU clamp mode [mode=%d]", clampMode); + } + + if (vuClampMode != GameDatabaseSchema::ClampMode::Undefined) + { + const int clampMode = enum_cast(vuClampMode); + if (applyAuto) + { + PatchesCon->WriteLn("(GameDB) Changing VU0/VU1 clamp mode [mode=%d]", clampMode); + config.Cpu.Recompiler.vuOverflow = (clampMode >= 1); + config.Cpu.Recompiler.vuExtraOverflow = (clampMode >= 2); + config.Cpu.Recompiler.vuSignOverflow = (clampMode >= 3); + num_applied_fixes++; + } + else + PatchesCon->Warning("[GameDB] Skipping changing VU0/VU1 clamp mode [mode=%d]", clampMode); + } + + // TODO - config - this could be simplified with maps instead of bitfields and enums + for (const auto& it : speedHacks) + { + const bool mode = it.second != 0; + if (!applyAuto) + { + PatchesCon->Warning("[GameDB] Skipping setting Speedhack '%s' to [mode=%d]", EnumToString(it.first), mode); + continue; + } + // Legacy note - speedhacks are setup in the GameDB as integer values, but + // are effectively booleans like the gamefixes + config.Speedhacks.Set(it.first, mode); + PatchesCon->WriteLn("(GameDB) Setting Speedhack '%s' to [mode=%d]", EnumToString(it.first), mode); + num_applied_fixes++; + } + + // TODO - config - this could be simplified with maps instead of bitfields and enums + for (const GamefixId id : gameFixes) + { + if (!applyAuto) + { + PatchesCon->Warning("[GameDB] Skipping Gamefix: %s", EnumToString(id)); + continue; + } + // if the fix is present, it is said to be enabled + config.Gamefixes.Set(id, true); + PatchesCon->WriteLn("(GameDB) Enabled Gamefix: %s", EnumToString(id)); + num_applied_fixes++; + + // The LUT is only used for 1 game so we allocate it only when the gamefix is enabled (save 4MB) + if (id == Fix_GoemonTlbMiss && true) + vtlb_Alloc_Ppmap(); + } + + return num_applied_fixes; +} + u32 GameDatabaseSchema::GameEntry::applyGSHardwareFixes(Pcsx2Config::GSOptions& config) const { // Only apply GS HW fixes if the user hasn't manually enabled HW fixes. diff --git a/pcsx2/GameDatabase.h b/pcsx2/GameDatabase.h index faa25cd523..185dbadc75 100644 --- a/pcsx2/GameDatabase.h +++ b/pcsx2/GameDatabase.h @@ -108,6 +108,9 @@ namespace GameDatabaseSchema const Patch* findPatch(const std::string_view& crc) const; const char* compatAsString() const; + /// Applies Core game fixes to an existing config. Returns the number of applied fixes. + u32 applyGameFixes(Pcsx2Config& config, bool applyAuto) const; + /// Applies GS hardware fixes to an existing config. Returns the number of applied fixes. u32 applyGSHardwareFixes(Pcsx2Config::GSOptions& config) const; }; diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index 84dda002b5..b12f705884 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -249,72 +249,7 @@ void VMManager::ApplyGameFixes() if (!game) return; - if (game->eeRoundMode != GameDatabaseSchema::RoundMode::Undefined) - { - SSE_RoundMode eeRM = (SSE_RoundMode)enum_cast(game->eeRoundMode); - if (EnumIsValid(eeRM)) - { - PatchesCon->WriteLn("(GameDB) Changing EE/FPU roundmode to %d [%s]", eeRM, EnumToString(eeRM)); - EmuConfig.Cpu.sseMXCSR.SetRoundMode(eeRM); - s_active_game_fixes++; - } - } - - if (game->vuRoundMode != GameDatabaseSchema::RoundMode::Undefined) - { - SSE_RoundMode vuRM = (SSE_RoundMode)enum_cast(game->vuRoundMode); - if (EnumIsValid(vuRM)) - { - PatchesCon->WriteLn("(GameDB) Changing VU0/VU1 roundmode to %d [%s]", vuRM, EnumToString(vuRM)); - EmuConfig.Cpu.sseVUMXCSR.SetRoundMode(vuRM); - s_active_game_fixes++; - } - } - - if (game->eeClampMode != GameDatabaseSchema::ClampMode::Undefined) - { - int clampMode = enum_cast(game->eeClampMode); - PatchesCon->WriteLn("(GameDB) Changing EE/FPU clamp mode [mode=%d]", clampMode); - EmuConfig.Cpu.Recompiler.fpuOverflow = (clampMode >= 1); - EmuConfig.Cpu.Recompiler.fpuExtraOverflow = (clampMode >= 2); - EmuConfig.Cpu.Recompiler.fpuFullMode = (clampMode >= 3); - s_active_game_fixes++; - } - - if (game->vuClampMode != GameDatabaseSchema::ClampMode::Undefined) - { - int clampMode = enum_cast(game->vuClampMode); - PatchesCon->WriteLn("(GameDB) Changing VU0/VU1 clamp mode [mode=%d]", clampMode); - EmuConfig.Cpu.Recompiler.vuOverflow = (clampMode >= 1); - EmuConfig.Cpu.Recompiler.vuExtraOverflow = (clampMode >= 2); - EmuConfig.Cpu.Recompiler.vuSignOverflow = (clampMode >= 3); - s_active_game_fixes++; - } - - // TODO - config - this could be simplified with maps instead of bitfields and enums - for (const auto& it : game->speedHacks) - { - // Legacy note - speedhacks are setup in the GameDB as integer values, but - // are effectively booleans like the gamefixes - const bool mode = it.second != 0; - EmuConfig.Speedhacks.Set(it.first, mode); - PatchesCon->WriteLn("(GameDB) Setting Speedhack '%s' to [mode=%d]", EnumToString(it.first), mode); - s_active_game_fixes++; - } - - // TODO - config - this could be simplified with maps instead of bitfields and enums - for (const GamefixId id : game->gameFixes) - { - // if the fix is present, it is said to be enabled - EmuConfig.Gamefixes.Set(id, true); - PatchesCon->WriteLn("(GameDB) Enabled Gamefix: %s", EnumToString(id)); - s_active_game_fixes++; - - // The LUT is only used for 1 game so we allocate it only when the gamefix is enabled (save 4MB) - if (id == Fix_GoemonTlbMiss && true) - vtlb_Alloc_Ppmap(); - } - + s_active_game_fixes += game->applyGameFixes(EmuConfig, EmuConfig.EnableGameFixes); s_active_game_fixes += game->applyGSHardwareFixes(EmuConfig.GS); } diff --git a/pcsx2/gui/AppCoreThread.cpp b/pcsx2/gui/AppCoreThread.cpp index b27d904e81..35d3d09883 100644 --- a/pcsx2/gui/AppCoreThread.cpp +++ b/pcsx2/gui/AppCoreThread.cpp @@ -268,71 +268,7 @@ static int loadGameSettings(Pcsx2Config& dest, const GameDatabaseSchema::GameEnt { int gf = 0; - if (game.eeRoundMode != GameDatabaseSchema::RoundMode::Undefined) - { - const SSE_RoundMode eeRM = (SSE_RoundMode)enum_cast(game.eeRoundMode); - if (EnumIsValid(eeRM)) - { - PatchesCon->WriteLn("(GameDB) Changing EE/FPU roundmode to %d [%s]", eeRM, EnumToString(eeRM)); - dest.Cpu.sseMXCSR.SetRoundMode(eeRM); - gf++; - } - } - - if (game.vuRoundMode != GameDatabaseSchema::RoundMode::Undefined) - { - const SSE_RoundMode vuRM = (SSE_RoundMode)enum_cast(game.vuRoundMode); - if (EnumIsValid(vuRM)) - { - PatchesCon->WriteLn("(GameDB) Changing VU0/VU1 roundmode to %d [%s]", vuRM, EnumToString(vuRM)); - dest.Cpu.sseVUMXCSR.SetRoundMode(vuRM); - gf++; - } - } - - if (game.eeClampMode != GameDatabaseSchema::ClampMode::Undefined) - { - const int clampMode = enum_cast(game.eeClampMode); - PatchesCon->WriteLn(L"(GameDB) Changing EE/FPU clamp mode [mode=%d]", clampMode); - dest.Cpu.Recompiler.fpuOverflow = (clampMode >= 1); - dest.Cpu.Recompiler.fpuExtraOverflow = (clampMode >= 2); - dest.Cpu.Recompiler.fpuFullMode = (clampMode >= 3); - gf++; - } - - if (game.vuClampMode != GameDatabaseSchema::ClampMode::Undefined) - { - const int clampMode = enum_cast(game.vuClampMode); - PatchesCon->WriteLn("(GameDB) Changing VU0/VU1 clamp mode [mode=%d]", clampMode); - dest.Cpu.Recompiler.vuOverflow = (clampMode >= 1); - dest.Cpu.Recompiler.vuExtraOverflow = (clampMode >= 2); - dest.Cpu.Recompiler.vuSignOverflow = (clampMode >= 3); - gf++; - } - - for (const auto& [id, mode] : game.speedHacks) - { - // Gamefixes are already guaranteed to be valid, any invalid ones are dropped - // Legacy note - speedhacks are setup in the GameDB as integer values, but - // are effectively booleans like the gamefixes - dest.Speedhacks.Set(id, mode != 0); - PatchesCon->WriteLn("(GameDB) Setting Speedhack '%s' to [mode=%d]", EnumToString(id), static_cast(mode != 0)); - gf++; - } - - for (const GamefixId id : game.gameFixes) - { - // Gamefixes are already guaranteed to be valid, any invalid ones are dropped - // if the fix is present, it is said to be enabled - dest.Gamefixes.Set(id, true); - PatchesCon->WriteLn("(GameDB) Enabled Gamefix: %s", EnumToString(id)); - gf++; - - // The LUT is only used for 1 game so we allocate it only when the gamefix is enabled (save 4MB) - if (id == Fix_GoemonTlbMiss && true) - vtlb_Alloc_Ppmap(); - } - + gf += game.applyGameFixes(dest, dest.EnablePatches); gf += game.applyGSHardwareFixes(dest.GS); return gf; @@ -456,9 +392,9 @@ static void _ApplySettings(const Pcsx2Config& src, Pcsx2Config& fixup) gamePatch.Printf(L" [%d Patches]", patches); PatchesCon->WriteLn(Color_Green, "(GameDB) Patches Loaded: %d", patches); } - if (int fixes = loadGameSettings(fixup, *game)) - gameFixes.Printf(L" [%d Fixes]", fixes); } + if (int fixes = loadGameSettings(fixup, *game)) + gameFixes.Printf(L" [%d Fixes]", fixes); } else {