Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adreno shutdown crash workaround #11786

Merged
merged 2 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ static void EmuThreadFunc() {
while (emuThreadState != (int)EmuThreadState::QUIT_REQUESTED) {
UpdateRunLoopAndroid(env);
}
ILOG("QUIT_REQUESTED found, left loop. Setting state to STOPPED.");
emuThreadState = (int)EmuThreadState::STOPPED;

NativeShutdownGraphics();
Expand All @@ -213,8 +214,8 @@ static void EmuThreadStart() {
// Call EmuThreadStop first, then keep running the GPU (or eat commands)
// as long as emuThreadState isn't STOPPED and/or there are still things queued up.
// Only after that, call EmuThreadJoin.
static void EmuThreadStop() {
ILOG("EmuThreadStop - stopping...");
static void EmuThreadStop(const char *caller) {
ILOG("EmuThreadStop - stopping (%s)...", caller);
emuThreadState = (int)EmuThreadState::QUIT_REQUESTED;
}

Expand Down Expand Up @@ -527,15 +528,16 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_pause(JNIEnv *, jclass) {
extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) {
if (renderer_inited && useCPUThread && graphicsContext) {
// Only used in Java EGL path.
EmuThreadStop();
EmuThreadStop("shutdown");
ILOG("BeginAndroidShutdown");
graphicsContext->BeginAndroidShutdown();
// Skipping GL calls, the old context is gone.
while (graphicsContext->ThreadFrame()) {
ILOG("graphicsContext->ThreadFrame executed to clear buffers");
continue;
}
ILOG("Joining emuthread");
EmuThreadJoin();
ILOG("Joined emuthread");

graphicsContext->ThreadEnd();
graphicsContext->ShutdownFromRenderThread();
Expand Down Expand Up @@ -566,15 +568,17 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
// We should be running on the render thread here.
std::string errorMessage;
if (renderer_inited) {
// Would be really nice if we could get something on the GL thread immediately when shutting down...
// Would be really nice if we could get something on the GL thread immediately when shutting down.
ILOG("NativeApp.displayInit() restoring");
if (useCPUThread) {
EmuThreadStop();
EmuThreadStop("displayInit");
graphicsContext->BeginAndroidShutdown();
ILOG("BeginAndroidShutdown. Looping until emu thread done...");
// Skipping GL calls here because the old context is lost.
while (graphicsContext->ThreadFrame()) {
continue;
}
ILOG("Joining emu thread");
EmuThreadJoin();
} else {
NativeShutdownGraphics();
Expand Down Expand Up @@ -1018,7 +1022,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
ILOG("Leaving EGL/Vulkan render loop.");

if (useCPUThread) {
EmuThreadStop();
EmuThreadStop("exitrenderloop");
while (graphicsContext->ThreadFrame()) {
continue;
}
Expand Down
11 changes: 8 additions & 3 deletions ext/native/thin3d/GLRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ void GLRenderManager::ThreadStart(Draw::DrawContext *draw) {
bufferStrategy_ = GLBufferStrategy::FRAME_UNMAP;
break;

case GPU_VENDOR_QUALCOMM:
bufferStrategy_ = GLBufferStrategy::FLUSH_INVALIDATE_UNMAP;
break;
// Temporarily disabled because it doesn't work with task switching on Android.
// The mapped buffer seems to just be pulled out like a rug from under us, crashing
// as soon as any write happens, which can happen during shutdown since we write from the
// Emu thread which may not yet have shut down. There may be solutions to this, but for now,
// disable this strategy to avoid crashing.
//case GPU_VENDOR_QUALCOMM:
// bufferStrategy_ = GLBufferStrategy::FLUSH_INVALIDATE_UNMAP;
// break;

default:
bufferStrategy_ = GLBufferStrategy::SUBDATA;
Expand Down