From 826b338b4e317a09991fef71d4c4a1750d4f2488 Mon Sep 17 00:00:00 2001 From: Vera-Firefly <1964762970@qq.com> Date: Sun, 6 Oct 2024 10:17:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD[=E4=BD=BF=E7=94=A8=E7=B3=BB?= =?UTF-8?q?=E7=BB=9FVulkan=E9=A9=B1=E5=8A=A8=E7=A8=8B=E5=BA=8F]:=20?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E6=A3=80=E6=B5=8B=E8=AE=BE=E5=A4=87=E4=B8=BA?= =?UTF-8?q?"AdrenoGPU"=E7=9A=84=E7=94=A8=E6=88=B7=E5=9C=A8=E6=89=93?= =?UTF-8?q?=E5=BC=80"=E4=BD=BF=E7=94=A8=E7=B3=BB=E7=BB=9FVulkan=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8"=E9=80=89=E9=A1=B9=E6=97=B6=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/firefly/utils/PGWTools.java | 71 +++++++++++++++++++ ...uncherPreferenceMiscellaneousFragment.java | 31 ++++++++ .../main/res/values-zh-rCN/pgw_strings.xml | 1 + .../main/res/values-zh-rTW/pgw_strings.xml | 1 + .../src/main/res/values/pgw_strings.xml | 1 + 5 files changed, 105 insertions(+) create mode 100644 app_pojavlauncher/src/main/java/com/firefly/utils/PGWTools.java diff --git a/app_pojavlauncher/src/main/java/com/firefly/utils/PGWTools.java b/app_pojavlauncher/src/main/java/com/firefly/utils/PGWTools.java new file mode 100644 index 000000000..af21bb1a8 --- /dev/null +++ b/app_pojavlauncher/src/main/java/com/firefly/utils/PGWTools.java @@ -0,0 +1,71 @@ +package com.firefly.utils; + +import android.opengl.EGL14; +import android.opengl.EGLConfig; +import android.opengl.EGLContext; +import android.opengl.EGLDisplay; +import android.opengl.GLES20; +import android.util.Log; + +public class PGWTools { + + public static boolean isAdrenoGPU() { + EGLDisplay eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); + if (eglDisplay == EGL14.EGL_NO_DISPLAY) { + Log.e("CheckVendor", "Failed to get EGL display"); + return false; + } + + if (!EGL14.eglInitialize(eglDisplay, null, 0, null, 0)) { + Log.e("CheckVendor", "Failed to initialize EGL"); + return false; + } + + int[] eglAttributes = new int[]{ + EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, + EGL14.EGL_NONE + }; + + EGLConfig[] configs = new EGLConfig[1]; + int[] numConfigs = new int[1]; + if (!EGL14.eglChooseConfig(eglDisplay, eglAttributes, 0, configs, 0, 1, numConfigs, 0) || numConfigs[0] == 0) { + EGL14.eglTerminate(eglDisplay); + Log.e("CheckVendor", "Failed to choose EGL config"); + return false; + } + + int[] contextAttributes = new int[]{ + EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, // OpenGL ES 2.0 + EGL14.EGL_NONE + }; + + EGLContext context = EGL14.eglCreateContext(eglDisplay, configs[0], EGL14.EGL_NO_CONTEXT, contextAttributes, 0); + if (context == EGL14.EGL_NO_CONTEXT) { + EGL14.eglTerminate(eglDisplay); + Log.e("CheckVendor", "Failed to create EGL context"); + return false; + } + + if (!EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, context)) { + EGL14.eglDestroyContext(eglDisplay, context); + EGL14.eglTerminate(eglDisplay); + Log.e("CheckVendor", "Failed to make EGL context current"); + return false; + } + + String vendor = GLES20.glGetString(GLES20.GL_VENDOR); + String renderer = GLES20.glGetString(GLES20.GL_RENDERER); + boolean isAdreno = (vendor != null && renderer != null && + vendor.equalsIgnoreCase("Qualcomm") && + renderer.toLowerCase().contains("adreno")); + + // Cleanup + EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); + EGL14.eglDestroyContext(eglDisplay, context); + EGL14.eglTerminate(eglDisplay); + + Log.d("CheckVendor", "Running on Adreno GPU: " + isAdreno); + return isAdreno; + } + +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java index b521fde42..436a67e47 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java @@ -3,6 +3,11 @@ import android.os.Bundle; import androidx.preference.Preference; +import androidx.preference.SwitchPreference; +import androidx.preference.Preference.OnPreferenceChangeListener; + +import com.firefly.utils.PGWTools; +import com.firefly.ui.dialog.CustomDialog; import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.Tools; @@ -15,5 +20,31 @@ public void onCreatePreferences(Bundle b, String str) { if (!Tools.checkVulkanSupport(driverPreference.getContext().getPackageManager())) { driverPreference.setVisible(false); } + SwitchPreference useSystemVulkan = requirePreference("zinkPreferSystemDriver", SwitchPreference.class); + useSystemVulkan.setOnPreferenceChangeListener((p, v) -> { + boolean set = (boolean) v; + boolean isAdreno = PGWTools.isAdrenoGPU(); + if (set && isAdreno) { + onCheckGPUDialog(p); + } else { + return true; + } + return false; + }); + } + + private void onCheckGPUDialog(Preference pre) { + new CustomDialog.Builder(getContext()) + .setTitle("No No No No No!") + .setMessage(getString(R.string.worning_system_vulkan_adreno)) + .setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> { + ((SwitchPreference) pre).setChecked(true); + return true; + }) + .setCancelListener(R.string.alertdialog_cancel, customView -> true) + .setCancelable(false) + .build() + .show(); } + } diff --git a/app_pojavlauncher/src/main/res/values-zh-rCN/pgw_strings.xml b/app_pojavlauncher/src/main/res/values-zh-rCN/pgw_strings.xml index 8e22ef081..d60ddf905 100644 --- a/app_pojavlauncher/src/main/res/values-zh-rCN/pgw_strings.xml +++ b/app_pojavlauncher/src/main/res/values-zh-rCN/pgw_strings.xml @@ -48,6 +48,7 @@ 在应用正式开始运行游戏时,是否退出启动器 修复 Q3 行为 修复 740v3 上的 Q3 行为 + 我们检测到您的设备为 AdrenoGPU ,打开该选项可能会导致 Zink 渲染器无法正常使用\n你真的确定你要开启这个选项? Terminal 初始化 diff --git a/app_pojavlauncher/src/main/res/values-zh-rTW/pgw_strings.xml b/app_pojavlauncher/src/main/res/values-zh-rTW/pgw_strings.xml index 88e4e1a7c..66d384698 100644 --- a/app_pojavlauncher/src/main/res/values-zh-rTW/pgw_strings.xml +++ b/app_pojavlauncher/src/main/res/values-zh-rTW/pgw_strings.xml @@ -48,6 +48,7 @@ 在運行遊戲時退出啟動器 修復 Q3 行為 修復 740v3 上的 Q3 行為 + 我們檢測到您的設備為 Adreno GPU,開啟該選項可能會導致 Zink 渲染器無法正常使用。\n您真的確定要開啟這個選項嗎? Terminal 初始化 diff --git a/app_pojavlauncher/src/main/res/values/pgw_strings.xml b/app_pojavlauncher/src/main/res/values/pgw_strings.xml index 1f05024bb..311744c0e 100644 --- a/app_pojavlauncher/src/main/res/values/pgw_strings.xml +++ b/app_pojavlauncher/src/main/res/values/pgw_strings.xml @@ -23,6 +23,7 @@ Exit the launcher when the running the game Fix Q3 behavior Fix Q3 behavior on 740v3 + We have detected that your device is an Adreno GPU. Turning this option on may cause the Zink renderer to not work properly.\nAre you sure you want to turn this option on? Terminal Initialization