Merge pull request #10250 from unknownbrackets/android-lock

Fix hangs on Android lock/unlock with Vulkan
This commit is contained in:
Henrik Rydgård 2017-12-04 09:46:50 +01:00 committed by GitHub
commit 752949bc3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 10 deletions

View file

@ -1101,6 +1101,10 @@ static void ProcessFrameCommands(JNIEnv *env) {
}
extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(JNIEnv *env, jobject obj, jobject _surf) {
exitRenderLoop = false;
// This is up here to prevent race conditions, in case we pause during init.
renderLoopRunning = true;
ANativeWindow *wnd = ANativeWindow_fromSurface(env, _surf);
// Need to get the local JNI env for the graphics thread. Used later in draw_text_android.
@ -1113,6 +1117,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
if (wnd == nullptr) {
ELOG("Error: Surface is null.");
renderLoopRunning = false;
return false;
}
@ -1131,7 +1136,7 @@ retry:
if (!graphicsContext->Init(wnd, desiredBackbufferSizeX, desiredBackbufferSizeY, backbuffer_format, androidVersion)) {
ELOG("Failed to initialize graphics context.");
if (vulkan && tries < 2) {
if (!exitRenderLoop && (vulkan && tries < 2)) {
ILOG("Trying again, this time with OpenGL.");
g_Config.iGPUBackend = GPU_BACKEND_OPENGL;
SetGPUBackend((GPUBackend)g_Config.iGPUBackend); // Wait, why do we need a separate enum here?
@ -1141,10 +1146,11 @@ retry:
delete graphicsContext;
graphicsContext = nullptr;
renderLoopRunning = false;
return false;
}
if (!renderer_inited) {
if (!exitRenderLoop && !renderer_inited) {
NativeInitGraphics(graphicsContext);
if (renderer_ever_inited) {
NativeDeviceRestore();
@ -1153,9 +1159,6 @@ retry:
renderer_ever_inited = true;
}
exitRenderLoop = false;
renderLoopRunning = true;
while (!exitRenderLoop) {
static bool hasSetThreadName = false;
if (!hasSetThreadName) {
@ -1174,9 +1177,11 @@ retry:
}
ILOG("Leaving EGL/Vulkan render loop.");
g_gameInfoCache->WorkQueue()->Flush();
if (g_gameInfoCache)
g_gameInfoCache->WorkQueue()->Flush();
NativeDeviceLost();
if (renderer_inited)
NativeDeviceLost();
renderer_inited = false;
ILOG("Shutting down graphics context.");

View file

@ -432,7 +432,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
// Start emulation using the provided Surface.
if (!runEGLRenderLoop(mSurface)) {
// Shouldn't happen.
Log.e(TAG, "Failed to start up OpenGL");
Log.e(TAG, "Failed to start up OpenGL/Vulkan");
}
Log.i(TAG, "Left the render loop: " + mSurface);
}

View file

@ -225,8 +225,12 @@ void VulkanRenderManager::StopThread() {
// when we restart...
for (int i = 0; i < vulkan_->GetInflightFrames(); i++) {
auto &frameData = frameData_[i];
if (frameData.readyForRun || frameData.hasInitCommands || frameData.steps.size() != 0) {
Crash();
_assert_(!frameData.readyForRun);
_assert_(frameData.steps.empty());
if (frameData.hasInitCommands) {
// Clear 'em out. This can happen on restart sometimes.
vkEndCommandBuffer(frameData.initCmd);
frameData.hasInitCommands = false;
}
frameData.readyForRun = false;
for (size_t i = 0; i < frameData.steps.size(); i++) {