iOS: Fix hang when task switching in GL mode

This commit is contained in:
Henrik Rydgård 2024-05-29 18:21:58 +02:00
parent f23f54bf87
commit 3065979528
3 changed files with 27 additions and 1 deletions

View File

@ -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 { std::string GLRenderManager::GetGpuProfileString() const {
int curFrame = curFrame_; int curFrame = curFrame_;
const GLQueueProfileContext &profile = frameData_[curFrame].profile; const GLQueueProfileContext &profile = frameData_[curFrame].profile;

View File

@ -834,6 +834,7 @@ public:
} }
} }
void StartThread(); // Currently only used on iOS, since we fully recreate the context on Android
void StopThread(); void StopThread();
bool SawOutOfMemory() { bool SawOutOfMemory() {
@ -873,6 +874,7 @@ private:
FastVec<GLRInitStep> initSteps_; FastVec<GLRInitStep> initSteps_;
// Execution time state // Execution time state
// TODO: Rename this, as we don't actually use a compile thread on OpenGL.
bool runCompileThread_ = true; bool runCompileThread_ = true;
// Thread is managed elsewhere, and should call ThreadFrame. // Thread is managed elsewhere, and should call ThreadFrame.

View File

@ -73,6 +73,10 @@ public:
renderManager_->ThreadEnd(); renderManager_->ThreadEnd();
} }
void StartThread() {
renderManager_->StartThread();
}
void StopThread() override { void StopThread() override {
renderManager_->StopThread(); renderManager_->StopThread();
} }
@ -153,7 +157,6 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
SetCurrentThreadName("EmuThreadGL"); SetCurrentThreadName("EmuThreadGL");
renderLoopRunning = true; renderLoopRunning = true;
// graphicsContext->StartThread();
NativeInitGraphics(graphicsContext); NativeInitGraphics(graphicsContext);
INFO_LOG(SYSTEM, "Emulation thread starting\n"); INFO_LOG(SYSTEM, "Emulation thread starting\n");
@ -185,6 +188,8 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
_dbg_assert_(!renderLoopRunning); _dbg_assert_(!renderLoopRunning);
_dbg_assert_(!exitRenderLoop); _dbg_assert_(!exitRenderLoop);
graphicsContext->StartThread();
g_renderLoopThread = std::thread(GLRenderLoop, graphicsContext); g_renderLoopThread = std::thread(GLRenderLoop, graphicsContext);
return true; return true;
} }
@ -196,6 +201,10 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
} }
_assert_(g_renderLoopThread.joinable()); _assert_(g_renderLoopThread.joinable());
exitRenderLoop = true; exitRenderLoop = true;
graphicsContext->StopThread();
while (graphicsContext->ThreadFrame()) {
continue;
}
g_renderLoopThread.join(); g_renderLoopThread.join();
_assert_(!g_renderLoopThread.joinable()); _assert_(!g_renderLoopThread.joinable());
} }
@ -310,9 +319,14 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
self.gameController = nil; self.gameController = nil;
graphicsContext->StopThread(); graphicsContext->StopThread();
// Skipping GL calls here because the old context is lost.
while (graphicsContext->ThreadFrame()) {
continue;
}
graphicsContext->Shutdown(); graphicsContext->Shutdown();
delete graphicsContext; delete graphicsContext;
graphicsContext = nullptr; graphicsContext = nullptr;
INFO_LOG(SYSTEM, "Done shutting down GL");
} }
- (void)dealloc - (void)dealloc