Merge pull request #10599 from unknownbrackets/gl-render-manager

Fix yet more shutdown shenanigans
This commit is contained in:
Henrik Rydgård 2018-02-11 09:07:40 +01:00 committed by GitHub
commit 030de0ad0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 36 additions and 3 deletions

View File

@ -32,6 +32,7 @@ public:
virtual void ThreadStart() {}
virtual bool ThreadFrame() { return true; }
virtual void ThreadEnd() {}
virtual void StopThread() {}
virtual Draw::DrawContext *GetDrawContext() = 0;
};

View File

@ -208,6 +208,7 @@ void MainUI::EmuThreadFunc() {
emuThreadState = (int)EmuThreadState::STOPPED;
NativeShutdownGraphics();
graphicsContext->StopThread();
}
void MainUI::EmuThreadStart() {

View File

@ -82,6 +82,11 @@ public:
renderManager_->ThreadEnd();
}
void StopThread() override {
renderManager_->WaitUntilQueueIdle();
renderManager_->StopThread();
}
private:
Draw::DrawContext *draw_ = nullptr;
GLRenderManager *renderManager_ = nullptr;

View File

@ -38,6 +38,11 @@ public:
renderManager_->ThreadEnd();
}
void StopThread() override {
renderManager_->WaitUntilQueueIdle();
renderManager_->StopThread();
}
private:
Draw::DrawContext *draw_ = nullptr;
SDL_Window *window_;

View File

@ -423,6 +423,7 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext) {
emuThreadState = (int)EmuThreadState::STOPPED;
NativeShutdownGraphics();
graphicsContext->StopThread();
}
static void EmuThreadStart(GraphicsContext *context) {

View File

@ -86,6 +86,9 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext) {
emuThreadState = (int)EmuThreadState::STOPPED;
NativeShutdownGraphics();
// Ask the main thread to stop. This prevents a hang on a race condition.
graphicsContext->StopThread();
}
static void EmuThreadStart(GraphicsContext *graphicsContext) {
@ -231,6 +234,10 @@ void MainThreadFunc() {
}
}
Core_Stop();
if (!useEmuThread) {
// Process the shutdown. Without this, non-GL delays 800ms on shutdown.
Core_Run(g_graphicsContext);
}
Core_WaitInactive(800);
g_inLoop = false;

View File

@ -432,3 +432,8 @@ bool WindowsGLContext::ThreadFrame() {
void WindowsGLContext::ThreadEnd() {
renderManager_->ThreadEnd();
}
void WindowsGLContext::StopThread() {
renderManager_->WaitUntilQueueIdle();
renderManager_->StopThread();
}

View File

@ -29,6 +29,7 @@ public:
void ThreadStart() override;
void ThreadEnd() override;
bool ThreadFrame() override;
void StopThread() override;
Draw::DrawContext *GetDrawContext() override { return draw_; }

View File

@ -915,7 +915,7 @@ namespace MainWindow
MainThread_Stop();
coreState = CORE_POWERUP;
ResetUIState();
MainThread_Start(false);
MainThread_Start(g_Config.iGPUBackend == (int)GPUBackend::OPENGL);
InputDevice::BeginPolling();
break;

View File

@ -27,5 +27,4 @@ void AndroidJavaEGLGraphicsContext::ShutdownFromRenderThread() {
}
void AndroidJavaEGLGraphicsContext::Shutdown() {
// TODO
}

View File

@ -44,6 +44,11 @@ public:
renderManager_->ThreadEnd();
}
void StopThread() override {
renderManager_->WaitUntilQueueIdle();
renderManager_->StopThread();
}
private:
Draw::DrawContext *draw_ = nullptr;
GLRenderManager *renderManager_ = nullptr;

View File

@ -196,6 +196,9 @@ static void EmuThreadFunc() {
NativeShutdownGraphics();
// Also ask the main thread to stop, so it doesn't hang waiting for a new frame.
graphicsContext->StopThread();
gJvm->DetachCurrentThread();
ILOG("Leaving emu thread");
}

View File

@ -735,7 +735,7 @@ bool OpenGLContext::CopyFramebufferToMemorySync(Framebuffer *src, int channelBit
aspect |= GL_DEPTH_BUFFER_BIT;
if (channelBits & FB_STENCIL_BIT)
aspect |= GL_STENCIL_BUFFER_BIT;
renderManager_.CopyFramebufferToMemorySync(fb->framebuffer, aspect, x, y, w, h, dataFormat, (uint8_t *)pixels, pixelStride);
renderManager_.CopyFramebufferToMemorySync(fb ? fb->framebuffer : nullptr, aspect, x, y, w, h, dataFormat, (uint8_t *)pixels, pixelStride);
return true;
}