From d8825f5635b70188e3fbfa8f92c736991115af81 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Fri, 7 Jan 2022 03:50:18 +0100 Subject: [PATCH] Config: Port dual core setting to new config system. --- Source/Core/Core/BootManager.cpp | 9 +++---- .../Core/ConfigLoaders/IsSettingSaveable.cpp | 1 + Source/Core/Core/ConfigManager.cpp | 3 --- Source/Core/Core/ConfigManager.h | 1 - Source/Core/Core/Core.cpp | 27 +++++++++---------- Source/Core/Core/DolphinAnalytics.cpp | 2 +- Source/Core/Core/System.cpp | 7 +++++ Source/Core/Core/System.h | 6 +++++ .../Core/DolphinQt/Settings/GeneralPane.cpp | 5 ++-- Source/Core/VideoCommon/CommandProcessor.cpp | 3 ++- Source/Core/VideoCommon/Fifo.cpp | 25 +++++++---------- Source/Core/VideoCommon/PixelEngine.cpp | 5 +++- Source/Core/VideoCommon/VideoBackendBase.cpp | 4 +-- 13 files changed, 50 insertions(+), 48 deletions(-) diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index a5e0f434c1..b58818cc29 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -44,6 +44,7 @@ #include "Core/Movie.h" #include "Core/NetPlayProto.h" #include "Core/PowerPC/PowerPC.h" +#include "Core/System.h" #include "Core/WiiRoot.h" #include "DiscIO/Enums.h" @@ -69,7 +70,6 @@ public: private: bool valid = false; - bool bCPUThread = false; bool bMMU = false; bool bSyncGPU = false; int iSyncGpuMaxDistance = 0; @@ -82,7 +82,6 @@ void ConfigCache::SaveConfig(const SConfig& config) { valid = true; - bCPUThread = config.bCPUThread; bMMU = config.bMMU; bSyncGPU = config.bSyncGPU; iSyncGpuMaxDistance = config.iSyncGpuMaxDistance; @@ -103,7 +102,6 @@ void ConfigCache::RestoreConfig(SConfig* config) valid = false; - config->bCPUThread = bCPUThread; config->bMMU = bMMU; config->bSyncGPU = bSyncGPU; config->iSyncGpuMaxDistance = iSyncGpuMaxDistance; @@ -146,7 +144,6 @@ bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) IniFile::Section* core_section = game_ini.GetOrCreateSection("Core"); IniFile::Section* controls_section = game_ini.GetOrCreateSection("Controls"); - core_section->Get("CPUThread", &StartUp.bCPUThread, StartUp.bCPUThread); core_section->Get("MMU", &StartUp.bMMU, StartUp.bMMU); core_section->Get("SyncGPU", &StartUp.bSyncGPU, StartUp.bSyncGPU); @@ -181,7 +178,6 @@ bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) if (Movie::IsPlayingInput() && Movie::IsConfigSaved()) { // TODO: remove this once ConfigManager starts using OnionConfig. - StartUp.bCPUThread = Config::Get(Config::MAIN_CPU_THREAD); StartUp.bSyncGPU = Config::Get(Config::MAIN_SYNC_GPU); for (int i = 0; i < 2; ++i) { @@ -203,7 +199,6 @@ bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) { const NetPlay::NetSettings& netplay_settings = NetPlay::GetNetSettings(); Config::AddLayer(ConfigLoaders::GenerateNetPlayConfigLoader(netplay_settings)); - StartUp.bCPUThread = netplay_settings.m_CPUthread; StartUp.bCopyWiiSaveNetplay = netplay_settings.m_CopyWiiSave; StartUp.bSyncGPU = netplay_settings.m_SyncGPU; StartUp.iSyncGpuMaxDistance = netplay_settings.m_SyncGpuMaxDistance; @@ -263,6 +258,8 @@ bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) if (!boot->riivolution_patches.empty()) Config::SetCurrent(Config::MAIN_FAST_DISC_SPEED, true); + Core::System::GetInstance().Initialize(); + Core::UpdateWantDeterminism(/*initial*/ true); if (StartUp.bWii) diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index a505a815ae..fa2937363b 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -117,6 +117,7 @@ bool IsSettingSaveable(const Config::Location& config_location) &Config::GetInfoForSIDevice(1).GetLocation(), &Config::GetInfoForSIDevice(2).GetLocation(), &Config::GetInfoForSIDevice(3).GetLocation(), + &Config::MAIN_CPU_THREAD.GetLocation(), // UI.General diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 09f4c79853..bfbc84d38b 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -99,7 +99,6 @@ void SConfig::SaveCoreSettings(IniFile& ini) { IniFile::Section* core = ini.GetOrCreateSection("Core"); - core->Set("CPUThread", bCPUThread); core->Set("SyncGPU", bSyncGPU); core->Set("SyncGpuMaxDistance", iSyncGpuMaxDistance); core->Set("SyncGpuMinDistance", iSyncGpuMinDistance); @@ -122,7 +121,6 @@ void SConfig::LoadCoreSettings(IniFile& ini) { IniFile::Section* core = ini.GetOrCreateSection("Core"); - core->Get("CPUThread", &bCPUThread, true); core->Get("MMU", &bMMU, bMMU); core->Get("BBDumpPort", &iBBDumpPort, -1); core->Get("SyncGPU", &bSyncGPU, false); @@ -244,7 +242,6 @@ void SConfig::LoadDefaults() bAutomaticStart = false; bBootToPause = false; - bCPUThread = false; bMMU = false; iBBDumpPort = -1; bSyncGPU = false; diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index a8a1c70fdf..4f965da655 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -56,7 +56,6 @@ struct SConfig bool bJITNoBlockCache = false; bool bJITNoBlockLinking = false; - bool bCPUThread = true; bool bCopyWiiSaveNetplay = true; bool bMMU = false; diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index df575b431f..1687c9900f 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -67,6 +67,7 @@ #include "Core/PowerPC/JitInterface.h" #include "Core/PowerPC/PowerPC.h" #include "Core/State.h" +#include "Core/System.h" #include "Core/WiiRoot.h" #ifdef USE_MEMORYWATCHER @@ -202,8 +203,7 @@ bool IsCPUThread() bool IsGPUThread() { - const SConfig& _CoreParameter = SConfig::GetInstance(); - if (_CoreParameter.bCPUThread) + if (Core::System::GetInstance().IsDualCoreMode()) { return (s_emu_thread.joinable() && (s_emu_thread.get_id() == std::this_thread::get_id())); } @@ -238,7 +238,8 @@ bool Init(std::unique_ptr boot, const WindowSystemInfo& wsi) HostDispatchJobs(); INFO_LOG_FMT(BOOT, "Starting core = {} mode", SConfig::GetInstance().bWii ? "Wii" : "GameCube"); - INFO_LOG_FMT(BOOT, "CPU Thread separate = {}", SConfig::GetInstance().bCPUThread ? "Yes" : "No"); + INFO_LOG_FMT(BOOT, "CPU Thread separate = {}", + Core::System::GetInstance().IsDualCoreMode() ? "Yes" : "No"); Host_UpdateMainFrame(); // Disable any menus or buttons at boot @@ -272,8 +273,6 @@ void Stop() // - Hammertime! if (GetState() == State::Stopping || GetState() == State::Uninitialized) return; - const SConfig& _CoreParameter = SConfig::GetInstance(); - s_is_stopping = true; s_timer.Stop(); @@ -291,7 +290,7 @@ void Stop() // - Hammertime! INFO_LOG_FMT(CONSOLE, "{}", StopMessage(true, "Stop CPU")); CPU::Stop(); - if (_CoreParameter.bCPUThread) + if (Core::System::GetInstance().IsDualCoreMode()) { // Video_EnterLoop() should now exit so that EmuThread() // will continue concurrently with the rest of the commands @@ -333,8 +332,7 @@ static void CpuThread(const std::optional& savestate_path, bool del { DeclareAsCPUThread(); - const SConfig& _CoreParameter = SConfig::GetInstance(); - if (_CoreParameter.bCPUThread) + if (Core::System::GetInstance().IsDualCoreMode()) Common::SetCurrentThreadName("CPU thread"); else Common::SetCurrentThreadName("CPU-GPU thread"); @@ -413,8 +411,7 @@ static void FifoPlayerThread(const std::optional& savestate_path, { DeclareAsCPUThread(); - const SConfig& _CoreParameter = SConfig::GetInstance(); - if (_CoreParameter.bCPUThread) + if (Core::System::GetInstance().IsDualCoreMode()) Common::SetCurrentThreadName("FIFO player thread"); else Common::SetCurrentThreadName("FIFO-GPU thread"); @@ -446,6 +443,7 @@ static void FifoPlayerThread(const std::optional& savestate_path, // See the BootManager.cpp file description for a complete call schedule. static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi) { + const Core::System& system = Core::System::GetInstance(); const SConfig& core_parameter = SConfig::GetInstance(); CallOnStateChangedCallbacks(State::Starting); Common::ScopeGuard flag_guard{[] { @@ -647,7 +645,7 @@ static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi } // ENTER THE VIDEO THREAD LOOP - if (core_parameter.bCPUThread) + if (system.IsDualCoreMode()) { // This thread, after creating the EmuWindow, spawns a CPU // thread, and then takes over and becomes the video thread @@ -930,8 +928,6 @@ void Callback_NewField() void UpdateTitle(u32 ElapseTime) { - SConfig& _CoreParameter = SConfig::GetInstance(); - if (ElapseTime == 0) ElapseTime = 1; @@ -942,8 +938,9 @@ void UpdateTitle(u32 ElapseTime) // Settings are shown the same for both extended and summary info const std::string SSettings = fmt::format( - "{} {} | {} | {}", PowerPC::GetCPUName(), _CoreParameter.bCPUThread ? "DC" : "SC", - g_video_backend->GetDisplayName(), Config::Get(Config::MAIN_DSP_HLE) ? "HLE" : "LLE"); + "{} {} | {} | {}", PowerPC::GetCPUName(), + Core::System::GetInstance().IsDualCoreMode() ? "DC" : "SC", g_video_backend->GetDisplayName(), + Config::Get(Config::MAIN_DSP_HLE) ? "HLE" : "LLE"); std::string SFPS; if (Movie::IsPlayingInput()) diff --git a/Source/Core/Core/DolphinAnalytics.cpp b/Source/Core/Core/DolphinAnalytics.cpp index 93ed3888dd..0ff6fc52e7 100644 --- a/Source/Core/Core/DolphinAnalytics.cpp +++ b/Source/Core/Core/DolphinAnalytics.cpp @@ -359,7 +359,7 @@ void DolphinAnalytics::MakePerGameBuilder() builder.AddData("cfg-dsp-hle", Config::Get(Config::MAIN_DSP_HLE)); builder.AddData("cfg-dsp-jit", Config::Get(Config::MAIN_DSP_JIT)); builder.AddData("cfg-dsp-thread", Config::Get(Config::MAIN_DSP_THREAD)); - builder.AddData("cfg-cpu-thread", SConfig::GetInstance().bCPUThread); + builder.AddData("cfg-cpu-thread", Config::Get(Config::MAIN_CPU_THREAD)); builder.AddData("cfg-fastmem", Config::Get(Config::MAIN_FASTMEM)); builder.AddData("cfg-syncgpu", SConfig::GetInstance().bSyncGPU); builder.AddData("cfg-audio-backend", Config::Get(Config::MAIN_AUDIO_BACKEND)); diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp index f13d28d6b1..b665d6f6c7 100644 --- a/Source/Core/Core/System.cpp +++ b/Source/Core/Core/System.cpp @@ -3,6 +3,8 @@ #include "Core/System.h" +#include "Core/Config/MainSettings.h" + namespace Core { struct System::Impl @@ -14,4 +16,9 @@ System::System() : m_impl{std::make_unique()} } System::~System() = default; + +void System::Initialize() +{ + m_separate_cpu_and_gpu_threads = Config::Get(Config::MAIN_CPU_THREAD); +} } // namespace Core diff --git a/Source/Core/Core/System.h b/Source/Core/Core/System.h index 23a29aa0ca..7b045d2a80 100644 --- a/Source/Core/Core/System.h +++ b/Source/Core/Core/System.h @@ -26,10 +26,16 @@ public: return instance; } + void Initialize(); + + bool IsDualCoreMode() const { return m_separate_cpu_and_gpu_threads; } + private: System(); struct Impl; std::unique_ptr m_impl; + + bool m_separate_cpu_and_gpu_threads = false; }; } // namespace Core diff --git a/Source/Core/DolphinQt/Settings/GeneralPane.cpp b/Source/Core/DolphinQt/Settings/GeneralPane.cpp index 05ea785484..e8ec3eeab0 100644 --- a/Source/Core/DolphinQt/Settings/GeneralPane.cpp +++ b/Source/Core/DolphinQt/Settings/GeneralPane.cpp @@ -252,7 +252,7 @@ void GeneralPane::LoadConfig() #if defined(USE_ANALYTICS) && USE_ANALYTICS m_checkbox_enable_analytics->setChecked(Settings::Instance().IsAnalyticsEnabled()); #endif - m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread); + m_checkbox_dualcore->setChecked(Config::Get(Config::MAIN_CPU_THREAD)); m_checkbox_cheats->setChecked(Settings::Instance().GetCheatsEnabled()); m_checkbox_override_region_settings->setChecked( Config::Get(Config::MAIN_OVERRIDE_REGION_SETTINGS)); @@ -263,7 +263,7 @@ void GeneralPane::LoadConfig() int selection = qRound(Config::Get(Config::MAIN_EMULATION_SPEED) * 10); if (selection < m_combobox_speedlimit->count()) m_combobox_speedlimit->setCurrentIndex(selection); - m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread); + m_checkbox_dualcore->setChecked(Config::Get(Config::MAIN_CPU_THREAD)); const auto fallback = Settings::Instance().GetFallbackRegion(); @@ -346,7 +346,6 @@ void GeneralPane::OnSaveConfig() Settings::Instance().SetAnalyticsEnabled(m_checkbox_enable_analytics->isChecked()); DolphinAnalytics::Instance().ReloadConfig(); #endif - settings.bCPUThread = m_checkbox_dualcore->isChecked(); Config::SetBaseOrCurrent(Config::MAIN_CPU_THREAD, m_checkbox_dualcore->isChecked()); Settings::Instance().SetCheatsEnabled(m_checkbox_cheats->isChecked()); Config::SetBaseOrCurrent(Config::MAIN_OVERRIDE_REGION_SETTINGS, diff --git a/Source/Core/VideoCommon/CommandProcessor.cpp b/Source/Core/VideoCommon/CommandProcessor.cpp index ddaa0e72a3..c80469f89d 100644 --- a/Source/Core/VideoCommon/CommandProcessor.cpp +++ b/Source/Core/VideoCommon/CommandProcessor.cpp @@ -17,6 +17,7 @@ #include "Core/HW/GPFifo.h" #include "Core/HW/MMIO.h" #include "Core/HW/ProcessorInterface.h" +#include "Core/System.h" #include "VideoCommon/Fifo.h" namespace CommandProcessor @@ -42,7 +43,7 @@ static Common::Flag s_interrupt_waiting; static bool IsOnThread() { - return SConfig::GetInstance().bCPUThread; + return Core::System::GetInstance().IsDualCoreMode(); } static void UpdateInterrupts_Wrapper(u64 userdata, s64 cyclesLate) diff --git a/Source/Core/VideoCommon/Fifo.cpp b/Source/Core/VideoCommon/Fifo.cpp index 33dd94817d..cf105b9acf 100644 --- a/Source/Core/VideoCommon/Fifo.cpp +++ b/Source/Core/VideoCommon/Fifo.cpp @@ -19,6 +19,7 @@ #include "Core/CoreTiming.h" #include "Core/HW/Memmap.h" #include "Core/Host.h" +#include "Core/System.h" #include "VideoCommon/AsyncRequests.h" #include "VideoCommon/CPMemory.h" @@ -95,9 +96,7 @@ void PauseAndLock(bool doLock, bool unpauseOnUnlock) SyncGPU(SyncGPUReason::Other); EmulatorState(false); - const SConfig& param = SConfig::GetInstance(); - - if (!param.bCPUThread || s_use_deterministic_gpu_thread) + if (!Core::System::GetInstance().IsDualCoreMode() || s_use_deterministic_gpu_thread) return; s_gpu_mainloop.WaitYield(std::chrono::milliseconds(100), Host_YieldToUI); @@ -114,7 +113,7 @@ void Init() // Padded so that SIMD overreads in the vertex loader are safe s_video_buffer = static_cast(Common::AllocateMemoryPages(FIFO_SIZE + 4)); ResetVideoBuffer(); - if (SConfig::GetInstance().bCPUThread) + if (Core::System::GetInstance().IsDualCoreMode()) s_gpu_mainloop.Prepare(); s_sync_ticks.store(0); } @@ -400,9 +399,7 @@ void RunGpuLoop() void FlushGpu() { - const SConfig& param = SConfig::GetInstance(); - - if (!param.bCPUThread || s_use_deterministic_gpu_thread) + if (!Core::System::GetInstance().IsDualCoreMode() || s_use_deterministic_gpu_thread) return; s_gpu_mainloop.Wait(); @@ -423,17 +420,16 @@ bool AtBreakpoint() void RunGpu() { - const SConfig& param = SConfig::GetInstance(); + const bool is_dual_core = Core::System::GetInstance().IsDualCoreMode(); // wake up GPU thread - if (param.bCPUThread && !s_use_deterministic_gpu_thread) + if (is_dual_core && !s_use_deterministic_gpu_thread) { s_gpu_mainloop.Wakeup(); } // if the sync GPU callback is suspended, wake it up. - if (!SConfig::GetInstance().bCPUThread || s_use_deterministic_gpu_thread || - SConfig::GetInstance().bSyncGPU) + if (!is_dual_core || s_use_deterministic_gpu_thread || SConfig::GetInstance().bSyncGPU) { if (s_syncing_suspended) { @@ -508,7 +504,6 @@ void UpdateWantDeterminism(bool want) { // We are paused (or not running at all yet), so // it should be safe to change this. - const SConfig& param = SConfig::GetInstance(); bool gpu_thread = false; switch (Config::GetGPUDeterminismMode()) { @@ -523,7 +518,7 @@ void UpdateWantDeterminism(bool want) break; } - gpu_thread = gpu_thread && param.bCPUThread; + gpu_thread = gpu_thread && Core::System::GetInstance().IsDualCoreMode(); if (s_use_deterministic_gpu_thread != gpu_thread) { @@ -579,7 +574,7 @@ static void SyncGPUCallback(u64 ticks, s64 cyclesLate) ticks += cyclesLate; int next = -1; - if (!SConfig::GetInstance().bCPUThread || s_use_deterministic_gpu_thread) + if (!Core::System::GetInstance().IsDualCoreMode() || s_use_deterministic_gpu_thread) { next = RunGpuOnCpu((int)ticks); } @@ -597,7 +592,7 @@ void SyncGPUForRegisterAccess() { SyncGPU(SyncGPUReason::Other); - if (!SConfig::GetInstance().bCPUThread || s_use_deterministic_gpu_thread) + if (!Core::System::GetInstance().IsDualCoreMode() || s_use_deterministic_gpu_thread) RunGpuOnCpu(GPU_TIME_SLOT_SIZE); else if (SConfig::GetInstance().bSyncGPU) WaitForGpuThread(GPU_TIME_SLOT_SIZE); diff --git a/Source/Core/VideoCommon/PixelEngine.cpp b/Source/Core/VideoCommon/PixelEngine.cpp index 747328b3c6..bdfaa599d5 100644 --- a/Source/Core/VideoCommon/PixelEngine.cpp +++ b/Source/Core/VideoCommon/PixelEngine.cpp @@ -10,11 +10,14 @@ #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" + #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/HW/MMIO.h" #include "Core/HW/ProcessorInterface.h" +#include "Core/System.h" + #include "VideoCommon/BoundingBox.h" #include "VideoCommon/Fifo.h" #include "VideoCommon/PerfQueryBase.h" @@ -286,7 +289,7 @@ static void RaiseEvent(int cycles_into_future) CoreTiming::FromThread from = CoreTiming::FromThread::NON_CPU; s64 cycles = 0; // we don't care about timings for dual core mode. - if (!SConfig::GetInstance().bCPUThread || Fifo::UseDeterministicGPUThread()) + if (!Core::System::GetInstance().IsDualCoreMode() || Fifo::UseDeterministicGPUThread()) { from = CoreTiming::FromThread::CPU; diff --git a/Source/Core/VideoCommon/VideoBackendBase.cpp b/Source/Core/VideoCommon/VideoBackendBase.cpp index 03d46b7ff6..b84f6f9b24 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.cpp +++ b/Source/Core/VideoCommon/VideoBackendBase.cpp @@ -13,7 +13,6 @@ #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" -#include "Common/Config/Config.h" #include "Common/Event.h" #include "Common/FileUtil.h" #include "Common/Logging/Log.h" @@ -21,6 +20,7 @@ #include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" +#include "Core/System.h" // TODO: ugly #ifdef _WIN32 @@ -289,7 +289,7 @@ void VideoBackendBase::PopulateBackendInfoFromUI() void VideoBackendBase::DoState(PointerWrap& p) { - if (!SConfig::GetInstance().bCPUThread) + if (!Core::System::GetInstance().IsDualCoreMode()) { VideoCommon_DoState(p); return;