Merge pull request #12482 from AdmiralCurtiss/globals-coreinit

Core: Pass System through more of the emulation thread init process.
This commit is contained in:
Mai 2024-01-05 01:53:11 -05:00 committed by GitHub
commit feb7207a4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 18 deletions

View File

@ -142,7 +142,8 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
if (!boot->riivolution_patches.empty()) if (!boot->riivolution_patches.empty())
Config::SetCurrent(Config::MAIN_FAST_DISC_SPEED, true); Config::SetCurrent(Config::MAIN_FAST_DISC_SPEED, true);
Core::System::GetInstance().Initialize(); auto& system = Core::System::GetInstance();
system.Initialize();
Core::UpdateWantDeterminism(/*initial*/ true); Core::UpdateWantDeterminism(/*initial*/ true);
@ -173,13 +174,14 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
if (load_ipl) if (load_ipl)
{ {
return Core::Init( return Core::Init(
system,
std::make_unique<BootParameters>( std::make_unique<BootParameters>(
BootParameters::IPL{StartUp.m_region, BootParameters::IPL{StartUp.m_region,
std::move(std::get<BootParameters::Disc>(boot->parameters))}, std::move(std::get<BootParameters::Disc>(boot->parameters))},
std::move(boot->boot_session_data)), std::move(boot->boot_session_data)),
wsi); wsi);
} }
return Core::Init(std::move(boot), wsi); return Core::Init(system, std::move(boot), wsi);
} }
// SYSCONF can be modified during emulation by the user and internally, which makes it // SYSCONF can be modified during emulation by the user and internally, which makes it

View File

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <cstring> #include <cstring>
#include <functional>
#include <mutex> #include <mutex>
#include <queue> #include <queue>
#include <utility> #include <utility>
@ -134,7 +135,8 @@ static thread_local bool tls_is_cpu_thread = false;
static thread_local bool tls_is_gpu_thread = false; static thread_local bool tls_is_gpu_thread = false;
static thread_local bool tls_is_host_thread = false; static thread_local bool tls_is_host_thread = false;
static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi); static void EmuThread(Core::System& system, std::unique_ptr<BootParameters> boot,
WindowSystemInfo wsi);
static Common::EventHook s_frame_presented = AfterPresentEvent::Register( static Common::EventHook s_frame_presented = AfterPresentEvent::Register(
[](auto& present_info) { [](auto& present_info) {
@ -239,7 +241,7 @@ bool WantsDeterminism()
// This is called from the GUI thread. See the booting call schedule in // This is called from the GUI thread. See the booting call schedule in
// BootManager.cpp // BootManager.cpp
bool Init(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi) bool Init(Core::System& system, std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
{ {
if (s_emu_thread.joinable()) if (s_emu_thread.joinable())
{ {
@ -257,8 +259,7 @@ bool Init(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
HostDispatchJobs(); HostDispatchJobs();
INFO_LOG_FMT(BOOT, "Starting core = {} mode", SConfig::GetInstance().bWii ? "Wii" : "GameCube"); INFO_LOG_FMT(BOOT, "Starting core = {} mode", SConfig::GetInstance().bWii ? "Wii" : "GameCube");
INFO_LOG_FMT(BOOT, "CPU Thread separate = {}", INFO_LOG_FMT(BOOT, "CPU Thread separate = {}", system.IsDualCoreMode() ? "Yes" : "No");
Core::System::GetInstance().IsDualCoreMode() ? "Yes" : "No");
Host_UpdateMainFrame(); // Disable any menus or buttons at boot Host_UpdateMainFrame(); // Disable any menus or buttons at boot
@ -271,7 +272,7 @@ bool Init(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
// Start the emu thread // Start the emu thread
s_is_booting.Set(); s_is_booting.Set();
s_emu_thread = std::thread(EmuThread, std::move(boot), prepared_wsi); s_emu_thread = std::thread(EmuThread, std::ref(system), std::move(boot), prepared_wsi);
return true; return true;
} }
@ -371,11 +372,12 @@ static void CPUSetInitialExecutionState(bool force_paused = false)
} }
// Create the CPU thread, which is a CPU + Video thread in Single Core mode. // Create the CPU thread, which is a CPU + Video thread in Single Core mode.
static void CpuThread(const std::optional<std::string>& savestate_path, bool delete_savestate) static void CpuThread(Core::System& system, const std::optional<std::string>& savestate_path,
bool delete_savestate)
{ {
DeclareAsCPUThread(); DeclareAsCPUThread();
if (Core::System::GetInstance().IsDualCoreMode()) if (system.IsDualCoreMode())
Common::SetCurrentThreadName("CPU thread"); Common::SetCurrentThreadName("CPU thread");
else else
Common::SetCurrentThreadName("CPU-GPU thread"); Common::SetCurrentThreadName("CPU-GPU thread");
@ -434,7 +436,6 @@ static void CpuThread(const std::optional<std::string>& savestate_path, bool del
} }
// Enter CPU run loop. When we leave it - we are done. // Enter CPU run loop. When we leave it - we are done.
auto& system = Core::System::GetInstance();
system.GetCPU().Run(); system.GetCPU().Run();
#ifdef USE_MEMORYWATCHER #ifdef USE_MEMORYWATCHER
@ -454,12 +455,11 @@ static void CpuThread(const std::optional<std::string>& savestate_path, bool del
} }
} }
static void FifoPlayerThread(const std::optional<std::string>& savestate_path, static void FifoPlayerThread(Core::System& system, const std::optional<std::string>& savestate_path,
bool delete_savestate) bool delete_savestate)
{ {
DeclareAsCPUThread(); DeclareAsCPUThread();
auto& system = Core::System::GetInstance();
if (system.IsDualCoreMode()) if (system.IsDualCoreMode())
Common::SetCurrentThreadName("FIFO player thread"); Common::SetCurrentThreadName("FIFO player thread");
else else
@ -490,9 +490,9 @@ static void FifoPlayerThread(const std::optional<std::string>& savestate_path,
// Initialize and create emulation thread // Initialize and create emulation thread
// Call browser: Init():s_emu_thread(). // Call browser: Init():s_emu_thread().
// See the BootManager.cpp file description for a complete call schedule. // See the BootManager.cpp file description for a complete call schedule.
static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi) static void EmuThread(Core::System& system, std::unique_ptr<BootParameters> boot,
WindowSystemInfo wsi)
{ {
Core::System& system = Core::System::GetInstance();
const SConfig& core_parameter = SConfig::GetInstance(); const SConfig& core_parameter = SConfig::GetInstance();
CallOnStateChangedCallbacks(State::Starting); CallOnStateChangedCallbacks(State::Starting);
Common::ScopeGuard flag_guard{[] { Common::ScopeGuard flag_guard{[] {
@ -630,7 +630,8 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
system.GetPowerPC().SetMode(PowerPC::CoreMode::Interpreter); system.GetPowerPC().SetMode(PowerPC::CoreMode::Interpreter);
// Determine the CPU thread function // Determine the CPU thread function
void (*cpuThreadFunc)(const std::optional<std::string>& savestate_path, bool delete_savestate); void (*cpuThreadFunc)(Core::System & system, const std::optional<std::string>& savestate_path,
bool delete_savestate);
if (std::holds_alternative<BootParameters::DFF>(boot->parameters)) if (std::holds_alternative<BootParameters::DFF>(boot->parameters))
cpuThreadFunc = FifoPlayerThread; cpuThreadFunc = FifoPlayerThread;
else else
@ -684,7 +685,8 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
Common::FPU::LoadDefaultSIMDState(); Common::FPU::LoadDefaultSIMDState();
// Spawn the CPU thread. The CPU thread will signal the event that boot is complete. // Spawn the CPU thread. The CPU thread will signal the event that boot is complete.
s_cpu_thread = std::thread(cpuThreadFunc, savestate_path, delete_savestate); s_cpu_thread =
std::thread(cpuThreadFunc, std::ref(system), std::ref(savestate_path), delete_savestate);
// become the GPU thread // become the GPU thread
system.GetFifo().RunGpuLoop(); system.GetFifo().RunGpuLoop();
@ -703,7 +705,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
else // SingleCore mode else // SingleCore mode
{ {
// Become the CPU thread // Become the CPU thread
cpuThreadFunc(savestate_path, delete_savestate); cpuThreadFunc(system, savestate_path, delete_savestate);
} }
INFO_LOG_FMT(CONSOLE, "{}", StopMessage(true, "Stopping GDB ...")); INFO_LOG_FMT(CONSOLE, "{}", StopMessage(true, "Stopping GDB ..."));

View File

@ -124,7 +124,7 @@ private:
bool m_was_unpaused = false; bool m_was_unpaused = false;
}; };
bool Init(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi); bool Init(Core::System& system, std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi);
void Stop(); void Stop();
void Shutdown(); void Shutdown();