From 6a4df2a641759ecc55c471e917d7231949fe8b15 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 24 May 2022 00:19:55 +1000 Subject: [PATCH] GS: Move GSinit()/GSshutdown() to GS thread This initializes COM, so it has to be done on the thread which is actually going to use it. --- pcsx2/MTGS.cpp | 12 +++++++++++- pcsx2/VMManager.cpp | 13 ------------- pcsx2/gui/SysCoreThread.cpp | 1 - 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index 933f03236f..2ec51dc1fb 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -110,9 +110,17 @@ void SysMtgsThread::ShutdownThread() void SysMtgsThread::ThreadEntryPoint() { - m_thread_handle = Threading::ThreadHandle::GetForCallingThread(); Threading::SetNameOfCurrentThread("GS"); + if (GSinit() != 0) + { + Host::ReportErrorAsync("Error", "GSinit() failed."); + m_open_or_close_done.Post(); + return; + } + + m_thread_handle = Threading::ThreadHandle::GetForCallingThread(); + for (;;) { // wait until we're actually asked to initialize (and config has been loaded, etc) @@ -154,6 +162,8 @@ void SysMtgsThread::ThreadEntryPoint() // we need to reset sem_event here, because MainLoop() kills it. m_sem_event.Reset(); } + + GSshutdown(); } void SysMtgsThread::ResetGS() diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index a61e1bf448..82dd1fdf02 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -647,19 +647,6 @@ bool VMManager::Initialize(const VMBootParameters& boot_params) ScopedGuard close_cdvd = [] { DoCDVDclose(); }; Console.WriteLn("Opening GS..."); - - // TODO: Get rid of thread state nonsense and just make it a "normal" thread. - static bool gs_initialized = false; - if (!gs_initialized) - { - if (GSinit() != 0) - { - Console.WriteLn("Failed to initialize GS."); - return false; - } - - gs_initialized = true; - } if (!GetMTGS().WaitForOpen()) { // we assume GS is going to report its own error diff --git a/pcsx2/gui/SysCoreThread.cpp b/pcsx2/gui/SysCoreThread.cpp index 7a9d4fbbec..35f441d1d6 100644 --- a/pcsx2/gui/SysCoreThread.cpp +++ b/pcsx2/gui/SysCoreThread.cpp @@ -112,7 +112,6 @@ void SysCoreThread::OnSuspendInThread() void SysCoreThread::Start() { - GSinit(); SPU2init(); PADinit(); DEV9init();