Merge pull request #12482 from AdmiralCurtiss/globals-coreinit
Core: Pass System through more of the emulation thread init process.
This commit is contained in:
commit
feb7207a4c
|
@ -142,7 +142,8 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
|
|||
if (!boot->riivolution_patches.empty())
|
||||
Config::SetCurrent(Config::MAIN_FAST_DISC_SPEED, true);
|
||||
|
||||
Core::System::GetInstance().Initialize();
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.Initialize();
|
||||
|
||||
Core::UpdateWantDeterminism(/*initial*/ true);
|
||||
|
||||
|
@ -173,13 +174,14 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
|
|||
if (load_ipl)
|
||||
{
|
||||
return Core::Init(
|
||||
system,
|
||||
std::make_unique<BootParameters>(
|
||||
BootParameters::IPL{StartUp.m_region,
|
||||
std::move(std::get<BootParameters::Disc>(boot->parameters))},
|
||||
std::move(boot->boot_session_data)),
|
||||
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
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#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_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(
|
||||
[](auto& present_info) {
|
||||
|
@ -239,7 +241,7 @@ bool WantsDeterminism()
|
|||
|
||||
// This is called from the GUI thread. See the booting call schedule in
|
||||
// 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())
|
||||
{
|
||||
|
@ -257,8 +259,7 @@ bool Init(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
|
|||
HostDispatchJobs();
|
||||
|
||||
INFO_LOG_FMT(BOOT, "Starting core = {} mode", SConfig::GetInstance().bWii ? "Wii" : "GameCube");
|
||||
INFO_LOG_FMT(BOOT, "CPU Thread separate = {}",
|
||||
Core::System::GetInstance().IsDualCoreMode() ? "Yes" : "No");
|
||||
INFO_LOG_FMT(BOOT, "CPU Thread separate = {}", system.IsDualCoreMode() ? "Yes" : "No");
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
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();
|
||||
|
||||
if (Core::System::GetInstance().IsDualCoreMode())
|
||||
if (system.IsDualCoreMode())
|
||||
Common::SetCurrentThreadName("CPU thread");
|
||||
else
|
||||
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.
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetCPU().Run();
|
||||
|
||||
#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)
|
||||
{
|
||||
DeclareAsCPUThread();
|
||||
|
||||
auto& system = Core::System::GetInstance();
|
||||
if (system.IsDualCoreMode())
|
||||
Common::SetCurrentThreadName("FIFO player thread");
|
||||
else
|
||||
|
@ -490,9 +490,9 @@ static void FifoPlayerThread(const std::optional<std::string>& savestate_path,
|
|||
// Initialize and create emulation thread
|
||||
// Call browser: Init():s_emu_thread().
|
||||
// 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();
|
||||
CallOnStateChangedCallbacks(State::Starting);
|
||||
Common::ScopeGuard flag_guard{[] {
|
||||
|
@ -630,7 +630,8 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
|||
system.GetPowerPC().SetMode(PowerPC::CoreMode::Interpreter);
|
||||
|
||||
// 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))
|
||||
cpuThreadFunc = FifoPlayerThread;
|
||||
else
|
||||
|
@ -684,7 +685,8 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
|||
Common::FPU::LoadDefaultSIMDState();
|
||||
|
||||
// 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
|
||||
system.GetFifo().RunGpuLoop();
|
||||
|
@ -703,7 +705,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
|||
else // SingleCore mode
|
||||
{
|
||||
// Become the CPU thread
|
||||
cpuThreadFunc(savestate_path, delete_savestate);
|
||||
cpuThreadFunc(system, savestate_path, delete_savestate);
|
||||
}
|
||||
|
||||
INFO_LOG_FMT(CONSOLE, "{}", StopMessage(true, "Stopping GDB ..."));
|
||||
|
|
|
@ -124,7 +124,7 @@ private:
|
|||
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 Shutdown();
|
||||
|
||||
|
|
Loading…
Reference in New Issue