Permalink
Browse files

Merge pull request #10250 from unknownbrackets/android-lock

Fix hangs on Android lock/unlock with Vulkan
  • Loading branch information...
hrydgard committed Dec 4, 2017
2 parents 7f5ba21 + 5846016 commit 752949bc3e4660fe46ef987f7182748b8c0ce8ab
@@ -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 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
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 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
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 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
renderer_ever_inited = true;
}
exitRenderLoop = false;
renderLoopRunning = true;
while (!exitRenderLoop) {
static bool hasSetThreadName = false;
if (!hasSetThreadName) {
@@ -1174,9 +1177,11 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
}
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.");
@@ -432,7 +432,7 @@ public void run() {
// 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);
}
@@ -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++) {

0 comments on commit 752949b

Please sign in to comment.