From f196a877e6ff791ba7dd2e138e538756acd2e189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 3 Mar 2018 00:00:18 +0100 Subject: [PATCH] Android: Fix fallback from Vulkan to GL. --- android/jni/AndroidVulkanContext.cpp | 9 +++++- android/jni/AndroidVulkanContext.h | 4 ++- android/jni/app-android.cpp | 30 ++++++++++--------- .../src/org/ppsspp/ppsspp/NativeActivity.java | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/android/jni/AndroidVulkanContext.cpp b/android/jni/AndroidVulkanContext.cpp index 04481b3377..e5f4987920 100644 --- a/android/jni/AndroidVulkanContext.cpp +++ b/android/jni/AndroidVulkanContext.cpp @@ -72,12 +72,15 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL Vulkan_Dbg(VkDebugReportFlagsEXT msgFlags, return false; } +AndroidVulkanContext::AndroidVulkanContext() { +} + AndroidVulkanContext::~AndroidVulkanContext() { delete g_Vulkan; g_Vulkan = nullptr; } -bool AndroidVulkanContext::InitFromRenderThread(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) { +bool AndroidVulkanContext::InitAPI() { ILOG("AndroidVulkanContext::Init"); init_glslang(); @@ -124,6 +127,10 @@ bool AndroidVulkanContext::InitFromRenderThread(ANativeWindow *wnd, int desiredB g_Vulkan = nullptr; return false; } + return true; +} + +bool AndroidVulkanContext::InitFromRenderThread(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) { int width = desiredBackbufferSizeX; int height = desiredBackbufferSizeY; if (!width || !height) { diff --git a/android/jni/AndroidVulkanContext.h b/android/jni/AndroidVulkanContext.h index 2c65de11c3..affc330157 100644 --- a/android/jni/AndroidVulkanContext.h +++ b/android/jni/AndroidVulkanContext.h @@ -8,9 +8,11 @@ class VulkanContext; class AndroidVulkanContext : public AndroidGraphicsContext { public: - AndroidVulkanContext() : draw_(nullptr) {} + AndroidVulkanContext(); ~AndroidVulkanContext(); + bool InitAPI(); + bool InitFromRenderThread(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) override; void Shutdown() override; void SwapInterval(int interval) override; diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 1e54500f0f..ad91edae81 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -431,25 +431,33 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init NativeInit(2, argv, user_data_path.c_str(), externalDir.c_str(), cacheDir.c_str()); } - // Now that we've loaded config, set javaGL. - javaGL = NativeQueryConfig("androidJavaGL") == "true"; retry: + // Now that we've loaded config, set javaGL. + javaGL = NativeQueryConfig("androidJavaGL") == "true"; switch (g_Config.iGPUBackend) { case (int)GPUBackend::OPENGL: - ILOG("NativeApp.init() -- creating OpenGL context"); useCPUThread = true; - if (javaGL) { - graphicsContext = new AndroidJavaEGLGraphicsContext(); - } else { - graphicsContext = new AndroidEGLGraphicsContext(); - } + _assert_(javaGL); + ILOG("NativeApp.init() -- creating OpenGL context (JavaGL)"); + graphicsContext = new AndroidJavaEGLGraphicsContext(); break; case (int)GPUBackend::VULKAN: + { ILOG("NativeApp.init() -- creating Vulkan context"); useCPUThread = false; // The Vulkan render manager manages its own thread. // We create and destroy the Vulkan graphics context in the "EGL" thread. + AndroidVulkanContext *ctx = new AndroidVulkanContext(); + if (!ctx->InitAPI()) { + ILOG("Failed to initialize Vulkan, switching to OpenGL"); + g_Config.iGPUBackend = (int)GPUBackend::OPENGL; + SetGPUBackend(GPUBackend::OPENGL); + goto retry; + } else { + graphicsContext = ctx; + } break; + } default: ELOG("NativeApp.init(): iGPUBackend %d not supported. Switching to OpenGL.", (int)g_Config.iGPUBackend); g_Config.iGPUBackend = (int)GPUBackend::OPENGL; @@ -931,12 +939,6 @@ retry: int tries = 0; - _assert_msg_(G3D, !graphicsContext, "Graphics context already exists entering runEGLRenderLoop - this is wrong."); - - if (vulkan) { - graphicsContext = new AndroidVulkanContext(); - } - if (!graphicsContext->InitFromRenderThread(wnd, desiredBackbufferSizeX, desiredBackbufferSizeY, backbuffer_format, androidVersion)) { ELOG("Failed to initialize graphics context."); diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 01c2a107a1..30b25854a2 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -482,7 +482,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C gainAudioFocus(this.audioManager, this.audioFocusChangeListener); NativeApp.audioInit(); - if (javaGL) { + if (javaGL) { mGLSurfaceView = new NativeGLView(this); nativeRenderer = new NativeRenderer(this); mGLSurfaceView.setEGLContextClientVersion(2);