diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index 5b9e6b7da2..8a0960f425 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -163,16 +163,6 @@ bool GLRenderManager::ThreadFrame(bool waitIfEmpty) { return true; } -void GLRenderManager::StartThread() { - // There's not really a lot to do here anymore. - INFO_LOG(Log::G3D, "GLRenderManager::StartThread()"); - if (!runCompileThread_) { - runCompileThread_ = true; - } else { - INFO_LOG(Log::G3D, "GL submission thread was already running."); - } -} - std::string GLRenderManager::GetGpuProfileString() const { int curFrame = curFrame_; const GLQueueProfileContext &profile = frameData_[curFrame].profile; diff --git a/Common/GPU/OpenGL/GLRenderManager.h b/Common/GPU/OpenGL/GLRenderManager.h index 15114e3d80..766bd1916f 100644 --- a/Common/GPU/OpenGL/GLRenderManager.h +++ b/Common/GPU/OpenGL/GLRenderManager.h @@ -823,8 +823,6 @@ public: } } - void StartThread(); // Currently only used on iOS, since we fully recreate the context on Android - // Only supports a common subset. std::string GetGLString(int name) const { return queueRunner_.GetGLString(name); diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 51e615a1e5..52e3af2fef 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -34,6 +34,7 @@ #include "Core/Config.h" #include "Core/ConfigValues.h" +#include "Core/EmuThread.h" #include "Core/KeyMap.h" #include "Core/System.h" @@ -95,10 +96,6 @@ public: renderManager_->ThreadEnd(); } - void StartThread() { - renderManager_->StartThread(); - } - protected: void BeginShutdown() { renderManager_->SetSkipGLCalls(); @@ -109,9 +106,8 @@ private: GLRenderManager *renderManager_; }; -static std::atomic exitRenderLoop; static std::atomic renderLoopRunning; -static std::thread g_renderLoopThread; +static std::thread g_emuThread; PPSSPPBaseViewController *sharedViewController; @@ -141,61 +137,25 @@ PPSSPPBaseViewController *sharedViewController; return self; } -// The actual rendering is NOT on this thread, this is the emu thread -// that runs game logic. -void GLRenderLoop(IOSGLESContext *graphicsContext) { - SetCurrentThreadName("EmuThreadGL"); - renderLoopRunning = true; - - NativeInitGraphics(graphicsContext); - - INFO_LOG(Log::System, "Emulation thread starting\n"); - while (!exitRenderLoop) { - NativeFrame(graphicsContext); - } - - INFO_LOG(Log::System, "Emulation thread shutting down\n"); - NativeShutdownGraphics(graphicsContext); - - // Also ask the main thread to stop, so it doesn't hang waiting for a new frame. - INFO_LOG(Log::System, "Emulation thread stopping\n"); - - exitRenderLoop = false; - renderLoopRunning = false; -} - - (bool)runGLRenderLoop { if (!graphicsContext) { - ERROR_LOG(Log::G3D, "runVulkanRenderLoop: Tried to enter without a created graphics context."); + ERROR_LOG(Log::G3D, "runGLRenderLoop: Tried to enter without a created graphics context."); return false; } - if (g_renderLoopThread.joinable()) { - ERROR_LOG(Log::G3D, "runVulkanRenderLoop: Already running"); + if (g_emuThread.joinable()) { + ERROR_LOG(Log::G3D, "runGLRenderLoop: Already running"); return false; } - _dbg_assert_(!renderLoopRunning); - _dbg_assert_(!exitRenderLoop); - - graphicsContext->StartThread(); - - g_renderLoopThread = std::thread(GLRenderLoop, graphicsContext); + g_emuThread = EmuThread_Start(graphicsContext, new NativeApplication(), [](){}); return true; } - (void)requestExitGLRenderLoop { - if (!renderLoopRunning) { - ERROR_LOG(Log::System, "Render loop already exited"); - return; - } - _assert_(g_renderLoopThread.joinable()); - exitRenderLoop = true; - graphicsContext->ThreadFrameUntilCondition([]() -> bool { - return !renderLoopRunning.load(); - }); - g_renderLoopThread.join(); - _assert_(!g_renderLoopThread.joinable()); + _assert_(g_emuThread.joinable()); + EmuThread_Join(graphicsContext, g_emuThread); + _assert_(!g_emuThread.joinable()); } - (void)viewDidLoad { @@ -325,7 +285,7 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) { } - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { - if (!renderLoopRunning) { + if (!g_emuThread.joinable()) { INFO_LOG(Log::G3D, "Ignoring drawInRect"); return; } @@ -374,10 +334,6 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) { [[NSNotificationCenter defaultCenter] removeObserver:self]; - // Skipping GL calls here because the old context is lost. - graphicsContext->ThreadFrameUntilCondition([]() -> bool { - return !renderLoopRunning; - }); graphicsContext->ShutdownSurface(); graphicsContext->ShutdownAPI(); delete graphicsContext;