diff --git a/Common/Vulkan/VulkanContext.cpp b/Common/Vulkan/VulkanContext.cpp index fb92fb57913f..9118297bb851 100644 --- a/Common/Vulkan/VulkanContext.cpp +++ b/Common/Vulkan/VulkanContext.cpp @@ -596,7 +596,7 @@ VkResult VulkanContext::CreateDevice(int physical_device) { assert(queue_count >= 1); VkDeviceQueueCreateInfo queue_info = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO }; - float queue_priorities[1] = { 0.0 }; + float queue_priorities[1] = { 1.0f }; queue_info.queueCount = 1; queue_info.pQueuePriorities = queue_priorities; bool found = false; @@ -901,12 +901,25 @@ void VulkanContext::InitQueue() { // If the format list includes just one entry of VK_FORMAT_UNDEFINED, // the surface has no preferred format. Otherwise, at least one // supported format will be returned. - if (formatCount == 1 && surfFormats[0].format == VK_FORMAT_UNDEFINED) { + if (formatCount == 0 || (formatCount == 1 && surfFormats[0].format == VK_FORMAT_UNDEFINED)) { ILOG("swapchain_format: Falling back to B8G8R8A8_UNORM"); swapchain_format = VK_FORMAT_B8G8R8A8_UNORM; } else { - assert(formatCount >= 1); - swapchain_format = surfFormats[0].format; + swapchain_format = VK_FORMAT_UNDEFINED; + for (uint32_t i = 0; i < formatCount; ++i) { + if (surfFormats[i].colorSpace != VK_COLORSPACE_SRGB_NONLINEAR_KHR) { + continue; + } + + if (surfFormats[i].format == VK_FORMAT_B8G8R8A8_UNORM || surfFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM) { + swapchain_format = surfFormats[i].format; + break; + } + } + if (swapchain_format == VK_FORMAT_UNDEFINED) { + // Okay, take the first one then. + swapchain_format = surfFormats[0].format; + } ILOG("swapchain_format: %d (/%d)", swapchain_format, formatCount); } delete[] surfFormats; @@ -1005,6 +1018,7 @@ void VulkanContext::InitSwapchain(VkCommandBuffer cmd) { swap_chain_info.surface = surface_; swap_chain_info.minImageCount = desiredNumberOfSwapChainImages; swap_chain_info.imageFormat = swapchain_format; + swap_chain_info.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; swap_chain_info.imageExtent.width = swapChainExtent.width; swap_chain_info.imageExtent.height = swapChainExtent.height; swap_chain_info.preTransform = preTransform; @@ -1012,7 +1026,6 @@ void VulkanContext::InitSwapchain(VkCommandBuffer cmd) { swap_chain_info.presentMode = swapchainPresentMode; swap_chain_info.oldSwapchain = VK_NULL_HANDLE; swap_chain_info.clipped = true; - swap_chain_info.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; swap_chain_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; swap_chain_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; swap_chain_info.queueFamilyIndexCount = 0; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 5e5bbb27fc91..ba3401d71ac2 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -230,6 +230,13 @@ std::string NativeQueryConfig(std::string query) { return std::string(temp); } else if (query == "force44khz") { return std::string("0"); + } else if (query == "androidJavaGL") { + // If we're using Vulkan, we say no... need C++ to use Vulkan. + if (GetGPUBackend() == GPUBackend::VULKAN) { + return "false"; + } + // Otherwise, some devices prefer the Java init so play it safe. + return "true"; } else { return ""; } diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 01deff38ffb0..1046266a7fb9 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -343,6 +343,7 @@ InputState input_state; static bool renderer_inited = false; static bool first_lost = true; +// See NativeQueryConfig("androidJavaGL") to change this value. static bool javaGL = true; static std::string library_path; @@ -477,9 +478,8 @@ extern "C" jstring Java_org_ppsspp_ppsspp_NativeApp_queryConfig extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init (JNIEnv *env, jclass, jstring jmodel, jint jdeviceType, jstring jlangRegion, jstring japkpath, jstring jdataDir, jstring jexternalDir, jstring jlibraryDir, jstring jcacheDir, jstring jshortcutParam, - jint jAndroidVersion, jstring jboard, jboolean jjavaGL) { + jint jAndroidVersion, jstring jboard) { jniEnvUI = env; - javaGL = jjavaGL; setCurrentThreadName("androidInit"); ILOG("NativeApp.init() -- begin"); @@ -544,6 +544,9 @@ 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"; + ILOG("NativeApp.init() -- end"); } diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 226cf617953d..f9df80c970e3 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -60,7 +60,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { // Allows us to skip a lot of initialization on secondary calls to onCreate. private static boolean initialized = false; - // Change this to false to switch to C++ EGL. + // False to use C++ EGL, queried from C++ after NativeApp.init. private static boolean javaGL = true; // Graphics and audio interfaces for EGL (javaGL = false) @@ -266,7 +266,10 @@ public void Initialize() { String languageRegion = Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry(); NativeApp.audioConfig(optimalFramesPerBuffer, optimalSampleRate); - NativeApp.init(model, deviceType, languageRegion, apkFilePath, dataDir, externalStorageDir, libraryDir, cacheDir, shortcutParam, Build.VERSION.SDK_INT, Build.BOARD, javaGL); + NativeApp.init(model, deviceType, languageRegion, apkFilePath, dataDir, externalStorageDir, libraryDir, cacheDir, shortcutParam, Build.VERSION.SDK_INT, Build.BOARD); + + // Allow C++ to tell us to use JavaGL or not. + javaGL = NativeApp.queryConfig("androidJavaGL") == "true"; sendInitialGrants(); diff --git a/android/src/org/ppsspp/ppsspp/NativeApp.java b/android/src/org/ppsspp/ppsspp/NativeApp.java index 2bd743ea39e5..0e6f68d89314 100644 --- a/android/src/org/ppsspp/ppsspp/NativeApp.java +++ b/android/src/org/ppsspp/ppsspp/NativeApp.java @@ -13,7 +13,7 @@ public class NativeApp { public final static int DEVICE_TYPE_TV = 1; public final static int DEVICE_TYPE_DESKTOP = 2; - public static native void init(String model, int deviceType, String languageRegion, String apkPath, String dataDir, String externalDir, String libraryDir, String cacheDir, String shortcutParam, int androidVersion, String board, boolean javaGL); + public static native void init(String model, int deviceType, String languageRegion, String apkPath, String dataDir, String externalDir, String libraryDir, String cacheDir, String shortcutParam, int androidVersion, String board); public static native void audioInit(); public static native void audioShutdown(); public static native void audioConfig(int optimalFramesPerBuffer, int optimalSampleRate);