diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index b08c59a23a..9879b7b8c4 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -183,6 +183,16 @@ void GLRenderManager::StopThread() { } } +void GLRenderManager::StartThread() { + // There's not really a lot to do here anymore. + INFO_LOG(G3D, "GLRenderManager::StartThread()"); + if (!runCompileThread_) { + runCompileThread_ = true; + } else { + INFO_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 4c7e1a5509..558fd37879 100644 --- a/Common/GPU/OpenGL/GLRenderManager.h +++ b/Common/GPU/OpenGL/GLRenderManager.h @@ -834,6 +834,7 @@ public: } } + void StartThread(); // Currently only used on iOS, since we fully recreate the context on Android void StopThread(); bool SawOutOfMemory() { @@ -873,6 +874,7 @@ private: FastVec initSteps_; // Execution time state + // TODO: Rename this, as we don't actually use a compile thread on OpenGL. bool runCompileThread_ = true; // Thread is managed elsewhere, and should call ThreadFrame. diff --git a/ios/ViewController.mm b/ios/ViewController.mm index fcf29ec9ef..890ef4d3ae 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -73,6 +73,10 @@ public: renderManager_->ThreadEnd(); } + void StartThread() { + renderManager_->StartThread(); + } + void StopThread() override { renderManager_->StopThread(); } @@ -153,7 +157,6 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) { SetCurrentThreadName("EmuThreadGL"); renderLoopRunning = true; - // graphicsContext->StartThread(); NativeInitGraphics(graphicsContext); INFO_LOG(SYSTEM, "Emulation thread starting\n"); @@ -185,6 +188,8 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) { _dbg_assert_(!renderLoopRunning); _dbg_assert_(!exitRenderLoop); + graphicsContext->StartThread(); + g_renderLoopThread = std::thread(GLRenderLoop, graphicsContext); return true; } @@ -196,6 +201,10 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) { } _assert_(g_renderLoopThread.joinable()); exitRenderLoop = true; + graphicsContext->StopThread(); + while (graphicsContext->ThreadFrame()) { + continue; + } g_renderLoopThread.join(); _assert_(!g_renderLoopThread.joinable()); } @@ -310,9 +319,14 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) { self.gameController = nil; graphicsContext->StopThread(); + // Skipping GL calls here because the old context is lost. + while (graphicsContext->ThreadFrame()) { + continue; + } graphicsContext->Shutdown(); delete graphicsContext; graphicsContext = nullptr; + INFO_LOG(SYSTEM, "Done shutting down GL"); } - (void)dealloc