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 {
int curFrame = curFrame_;
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();
bool SawOutOfMemory() {
@ -873,6 +874,7 @@ private:
FastVec<GLRInitStep> 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.

View File

@ -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