From 7c508e8940c1a0873385cefe9744d1eece1039fd Mon Sep 17 00:00:00 2001 From: The412Banner Date: Mon, 12 Oct 2026 20:08:03 -0400 Subject: [PATCH] Mali pairs: a stand-in render node, the driver's real library name, and a Mali known by its chip - Auto on Jim's Dimensity 9300+ chose the bridge: the GPU had no name (the app had not asked Vulkan yet and kbase's gpuinfo is unreadable under SELinux), so a Mali-G720 counted as a Mali no build covers. The name now falls back to the GPU the chip is known to carry (Dimensity, Helio, Kompanio, Tensor); and when nothing names it, Auto asks the vendor Vulkan driver off the main thread before it settles for the bridge. Auto logs what it decided and why. - An open Mali driver pair gets /dev/mali0 as the guest's render node, as the bridge does (bindGpuNode, BL_DRM_STANDIN): gamescope needs the node the driver reports. The session shim only answers libdrm's PRIME and GEM-close calls on it, which PanVK on kbase never makes. - A PanVK or RADV runtime half is installed as libvulkan_panfrost.so / libvulkan_radeon.so rather than under Turnip's name; Turnip keeps libvulkan_freedreno.so. - graphics-report.txt names the render node the guest got, adds the session script's driver lines and flags a failed Mali-bridge self-test at the top. --- .../com/droiddeck/launcher/DriverMenus.kt | 20 ++++++++++++- .../droiddeck/launcher/gpu/DriverBundle.kt | 2 +- .../com/droiddeck/launcher/gpu/GpuInfo.kt | 29 ++++++++++++++++++- .../gpu/LinuxVulkanDriverManager.java | 25 +++++++++++++--- .../launcher/runtime/LinuxRuntime.java | 5 +++- .../launcher/session/GraphicsReport.kt | 16 ++++++++++ .../launcher/session/SessionService.kt | 6 ++++ .../droiddeck/launcher/gpu/DriverPairsTest.kt | 10 +++++++ .../launcher/session/GraphicsReportTest.kt | 2 +- 9 files changed, 106 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt index a70f07b4f..42a8fb64c 100644 --- a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt +++ b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt @@ -46,7 +46,8 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl /** Asset name -> download percent, while it downloads. */ private val releaseProgress = HashMap() var linuxSelected by mutableStateOf("") - val gpu: GpuInfo = GpuInfo.detect() + var gpu: GpuInfo = GpuInfo.detect() + private set // Read in refreshDrivers/ensureAuto: the activity has no context yet while its fields are made. var mode by mutableStateOf(SessionPrefs.GPU_DRIVERS_AUTO) var pairRows by mutableStateOf>(emptyList()) @@ -165,6 +166,23 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl } if (!force && autoCheckedThisProcess) return autoCheckedThisProcess = true + if (gpu.family.mali && DriverPairs.recommendedKey(gpu, emptyList()) == null && + com.droiddeck.launcher.gpu.VulkanInfo.cachedOrNull() == null) { + // No name for this Mali yet: ask its own Vulkan driver (it creates an instance, so off + // the main thread), then decide again with the name it gives. + autoStatus = activity.getString(R.string.drivers_checking_latest) + Thread({ + com.droiddeck.launcher.gpu.VulkanInfo.query() + ui.post { + gpu = GpuInfo.detect() + Log.i(TAG, "auto: Mali named by its driver: ${gpu.name} -> ${gpu.family}") + autoCheckedThisProcess = false + ensureAuto(force) + } + }, "gpu-name").start() + return + } + Log.i(TAG, "auto: ${gpu.name} (${gpu.family}) -> " + (DriverPairs.recommendedKey(gpu, emptyList()) ?: "no pair")) if (gpu.family.mali && DriverPairs.recommendedKey(gpu, emptyList()) == null) { useMaliBridge() autoStatus = activity.getString(R.string.drivers_mali_bridge_auto) diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt b/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt index 16f3d2c1b..cc269e170 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt @@ -101,7 +101,7 @@ object DriverBundle { val linuxStage = lm.newStagingDir() val linuxId = try { val library = linuxDir.listFiles()?.firstOrNull { it.isFile && LinuxVulkanDriverManager.isDriverLibrary(it.name) } - library?.copyTo(File(linuxStage, LinuxVulkanDriverManager.LIB_NAME)) + library?.copyTo(File(linuxStage, LinuxVulkanDriverManager.storedName(library.name))) val meta = File(linuxDir, LinuxVulkanDriverManager.META_NAME).takeIf { it.isFile } ?.let { runCatching { JSONObject(FileUtils.readString(it)) }.getOrNull() } lm.adopt(linuxStage, library?.name, meta, manifest.name) diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt b/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt index 287dd054e..7662f4ce5 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt @@ -154,13 +154,40 @@ data class GpuInfo( "" } - /** The Mali's name, "" when the device has a kbase node but names no GPU. */ + /** + * The Mali's name, "" when nothing names it: the vendor Vulkan driver's own name when this + * process has asked it, kbase's gpuinfo where SELinux lets the app read it (most phones do + * not), else the GPU the chip is known to carry ([MALI_SOCS]). + */ private fun maliName(): String = VulkanInfo.cachedOrNull()?.get("device")?.takeIf { it.contains("Mali", ignoreCase = true) } ?: FileUtils.readString(File("/sys/class/misc/mali0/device/gpuinfo"))?.trim()?.takeIf { it.contains("Mali", ignoreCase = true) } ?.substringBefore(" ") + ?: maliOfSoc(socIds()) ?: "" + /** The chip's names as the platform gives them: "mt6989", "MT6989", "gs201". */ + private fun socIds(): List = listOfNotNull( + if (Build.VERSION.SDK_INT >= 31) Build.SOC_MODEL else null, + systemProperty("ro.board.platform"), systemProperty("ro.soc.model"), Build.HARDWARE, Build.BOARD, + ).filter { it.isNotBlank() } + + /** Chips whose Mali is known for certain (MediaTek Dimensity / Helio / Kompanio, Google Tensor). */ + private val MALI_SOCS = mapOf( + "mt6991" to "Mali-G925", "mt6989" to "Mali-G720", "mt6899" to "Mali-G720", "mt6985" to "Mali-G715", + "mt6983" to "Mali-G710", "mt6897" to "Mali-G615", "mt6878" to "Mali-G615", "mt6895" to "Mali-G610", + "mt6896" to "Mali-G610", "mt6886" to "Mali-G610", "mt6893" to "Mali-G77", "mt6891" to "Mali-G77", + "mt6889" to "Mali-G77", "mt6885" to "Mali-G77", "mt6877" to "Mali-G68", "mt6853" to "Mali-G57", + "mt6833" to "Mali-G57", "mt6835" to "Mali-G57", "mt6789" to "Mali-G57", "mt6785" to "Mali-G76", + "mt6781" to "Mali-G52", "mt6769" to "Mali-G52", "mt8192" to "Mali-G57", "mt8195" to "Mali-G57", + "gs101" to "Mali-G78", "gs201" to "Mali-G710", "zuma" to "Mali-G715", "zumapro" to "Mali-G715", + ) + + /** The Mali [ids] name a chip of, "Mali-G720 (by chip mt6989)", or null for an unknown chip. */ + internal fun maliOfSoc(ids: List): String? = ids.firstNotNullOfOrNull { id -> + MALI_SOCS[id.trim().lowercase()]?.let { "$it (by chip ${id.trim().lowercase()})" } + } + /** The number in a Mali's name: 720 for "Mali-G720-Immortalis MC12". */ fun maliNumber(name: String): Int? = Regex("""G(\d{2,3})""", RegexOption.IGNORE_CASE).find(name)?.groupValues?.get(1)?.toIntOrNull() diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java b/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java index ff7fa246f..f35c2e9aa 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java +++ b/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java @@ -70,7 +70,9 @@ public class LinuxVulkanDriverManager { public boolean isInstalled(String id) { if (id == null || id.isEmpty() || id.contains("/") || id.contains("..")) return false; File dir = getDriverDir(id); - return new File(dir, LIB_NAME).isFile() && new File(dir, ICD_NAME).isFile(); + if (!new File(dir, ICD_NAME).isFile()) return false; + for (String name : STORED_NAMES) if (new File(dir, name).isFile()) return true; + return false; } /** Absolute path of the driver's ICD manifest, or null when the id isn't installed. */ @@ -144,7 +146,7 @@ public class LinuxVulkanDriverManager { if (isDriverLibrary(base)) { if (soName != null) Log.w(TAG, "zip has several driver libraries; using the first (" + soName + ")"); else { - Files.copy(zis, new File(tmpDir, LIB_NAME).toPath(), StandardCopyOption.REPLACE_EXISTING); + Files.copy(zis, new File(tmpDir, storedName(base)).toPath(), StandardCopyOption.REPLACE_EXISTING); soName = base; } } else if (base.equals(META_NAME)) { @@ -184,7 +186,8 @@ public class LinuxVulkanDriverManager { if (soName == null) { throw new IllegalArgumentException(context.getString(R.string.lvd_no_library)); } - File so = new File(tmpDir, LIB_NAME); + String stored = storedName(soName); + File so = new File(tmpDir, stored); if (!isAarch64Elf(so)) { throw new IllegalArgumentException(context.getString(R.string.lvd_not_aarch64, soName)); } @@ -214,7 +217,7 @@ public class LinuxVulkanDriverManager { JSONObject icd = new JSONObject(); icd.put("file_format_version", "1.0.0"); JSONObject icdBody = new JSONObject(); - icdBody.put("library_path", new File(dir, LIB_NAME).getAbsolutePath()); + icdBody.put("library_path", new File(dir, stored).getAbsolutePath()); icdBody.put("api_version", "1.1.274"); icd.put("ICD", icdBody); if (!FileUtils.writeString(new File(tmpDir, ICD_NAME), icd.toString(2))) throw new IOException("cannot write icd.json"); @@ -227,6 +230,7 @@ public class LinuxVulkanDriverManager { meta.put("libc", "glibc"); meta.put("minGlibc", minGlibc); meta.put("sourceLibraryName", soName); + meta.put("libraryName", stored); meta.put("importedAt", System.currentTimeMillis()); if (!FileUtils.writeString(new File(tmpDir, META_NAME), meta.toString(2))) throw new IOException("cannot write meta.json"); @@ -250,6 +254,19 @@ public class LinuxVulkanDriverManager { * (panfrost) on Mali, RADV (radeon) on Xclipse. Whichever it is, it is installed as * {@link #LIB_NAME}; the ICD manifest loads it by that absolute path. */ + /** The names an installed driver's library is kept under; Turnip keeps {@link #LIB_NAME}. */ + private static final String[] STORED_NAMES = {LIB_NAME, "libvulkan_panfrost.so", "libvulkan_radeon.so"}; + + /** + * The name a driver library is installed under: its own driver's (PanVK, RADV), so the session + * log and the graphics report say which driver it is; a Turnip build keeps {@link #LIB_NAME}. + */ + public static String storedName(String soName) { + if (soName != null && soName.startsWith("libvulkan_panfrost")) return "libvulkan_panfrost.so"; + if (soName != null && soName.startsWith("libvulkan_radeon")) return "libvulkan_radeon.so"; + return LIB_NAME; + } + public static boolean isDriverLibrary(String base) { return base.endsWith(".so") && (base.startsWith("libvulkan_freedreno") || base.startsWith("libvulkan_panfrost") || base.startsWith("libvulkan_radeon")); diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java index 374c0b7b4..b524ab553 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -333,7 +333,7 @@ public final class LinuxRuntime { * Turnip build reports the same device numbers for it. */ /** Mali's kbase device, the stand-in render node on a Mali GPU (the Mali bridge's gamescope). */ - private static final String MALI_DEVICE = "/dev/mali0"; + public static final String MALI_DEVICE = "/dev/mali0"; /** * The device that stands in for the GPU's render node: KGSL on an Adreno; with the Mali bridge @@ -344,6 +344,9 @@ public final class LinuxRuntime { public static String gpuStandIn(Context context) { if (new File(KGSL_DEVICE).exists()) return KGSL_DEVICE; if (com.droiddeck.launcher.core.DeviceSupport.INSTANCE.vkBridge(context) && new File(MALI_DEVICE).exists()) return MALI_DEVICE; + // An open Mali driver pair (PanVK on kbase): gamescope needs a DRM node for the device the + // driver reports, and the driver reports /dev/mali0's numbers as its primary and render node. + if (com.droiddeck.launcher.core.DeviceSupport.INSTANCE.openDriverActive(context) && new File(MALI_DEVICE).exists()) return MALI_DEVICE; return null; } diff --git a/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt b/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt index ff53893d3..2abdf3861 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt @@ -66,6 +66,10 @@ object GraphicsReport { appendLine("auto would pick: " + (DriverPairs.recommendedKey(gpu, pairs) ?: "(no pair: system driver or bridge)")) } appendLine("mali bridge setting: " + SessionPrefs.vkBridge(context) + ", in use: " + DeviceSupport.vkBridge(context)) + val standIn = runCatching { com.droiddeck.launcher.runtime.LinuxRuntime.gpuStandIn(context) }.getOrNull() + appendLine("render node for the guest: " + (standIn?.let { node -> + com.droiddeck.launcher.runtime.LinuxRuntime.deviceNumbers(node)?.let { n -> "/dev/dri/renderD${n.substringAfter(':')} -> $node ($n)" } ?: node + } ?: if (SystemVulkanDriver.isPowerVr()) "the system GPU's own /dev/dri node (#570)" else "none")) appendLine() appendLine("-- gpu") if (gpu != null) { @@ -134,6 +138,9 @@ object GraphicsReport { RegexOption.IGNORE_CASE, ) + /** The session script's driver lines: what it exported, the bridge's self-test, vulkaninfo, gamescope's Vulkan errors. */ + private val GUEST = Regex("""== vulkan driver|== vkbridge|== vulkaninfo|vulkan:|panvk|PanVK|radv|primary node|No compatible|DRM format""", RegexOption.IGNORE_CASE) + /** * The end of the report, from the finished folder: the compositor's driver lines out of * app.log, and games/ held to its size limits. Never throws. @@ -144,7 +151,16 @@ object GraphicsReport { if (!report.isFile) return val lines = File(dir, "app.log").takeIf { it.isFile }?.useLines { seq -> seq.filter { COMPOSITOR.containsMatchIn(it) }.take(400).toList() }.orEmpty() val games = File(dir, GAMES_DIR).listFiles()?.filter { it.isDirectory }?.sortedBy { it.name }.orEmpty() + val guestLines = File(dir, "session.log").takeIf { it.isFile }?.useLines { seq -> + seq.filter { GUEST.containsMatchIn(it) }.take(200).toList() + }.orEmpty() report.appendText(buildString { + if (guestLines.any { it.contains("vkbridge", ignoreCase = true) && it.contains("FAIL") }) { + appendLine("!! MALI BRIDGE SELF-TEST FAILED: this GPU's driver did not pass the bridge's checks (see below)") + } + appendLine("-- driver lines from the session log (${guestLines.size})") + guestLines.forEach { appendLine(it) } + appendLine() appendLine("-- compositor and driver lines from app.log (${lines.size})") lines.forEach { appendLine(it) } appendLine() diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 03b98f7fb..3873eda09 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -645,6 +645,12 @@ class SessionService : Service() { } (if (bridge) null else LinuxVulkanDriver.resolveIcdPath(this, linuxDriverId)) ?.let { guest.add(LinuxVulkanDriver.ENV + "=" + it) } + // An open Mali driver pair: /dev/mali0 stands in as the render node (LinuxRuntime.bindGpuNode) + // and the session shim answers gamescope's PRIME calls on it as on KGSL. It only covers + // libdrm's PRIME/GEM entry points, which PanVK on kbase never calls on its own device. + if (!bridge && com.droiddeck.launcher.core.DeviceSupport.openDriverActive(this)) { + LinuxRuntime.gpuStandIn(this)?.takeIf { it == LinuxRuntime.MALI_DEVICE }?.let { guest.add("BL_DRM_STANDIN=$it") } + } // Turnip's own debug switches, for the runtime's driver and everything on it. The file in // Downloads holds the value verbatim ("sysmem", "sysmem,deck_emu"); with nothing there, an // imported driver from the A710/A720/A722 legs gets "sysmem" on its own, which is what both diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt index 84d2108c8..5401fa4cd 100644 --- a/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt @@ -219,4 +219,14 @@ class DriverPairsTest { assertEquals(DriverPairs.NAD_MALI_JM, DriverPairs.recommendedKey(g77, pairs, sdk = 34)) assertTrue(DriverPairs.isNonAdreno("PanVK-faux123-RP4Pro")) } + + @Test + fun aMaliTheDeviceDoesNotNameIsKnownByItsChip() { + assertEquals("Mali-G720 (by chip mt6989)", GpuInfo.maliOfSoc(listOf("", "mt6989"))) + assertEquals("Mali-G710 (by chip gs201)", GpuInfo.maliOfSoc(listOf("GS201"))) + assertEquals(null, GpuInfo.maliOfSoc(listOf("unknown-chip"))) + assertEquals(Family.MALI_G720, GpuInfo.familyOf(false, 0, mali = "Mali-G720 (by chip mt6989)")) + assertEquals(Family.MALI_LATEST, GpuInfo.familyOf(false, 0, mali = "Mali-G925 (by chip mt6991)")) + assertTrue(GpuInfo.maliKbaseCovered("Mali-G720 (by chip mt6989)")) + } } diff --git a/app/src/test/java/com/droiddeck/launcher/session/GraphicsReportTest.kt b/app/src/test/java/com/droiddeck/launcher/session/GraphicsReportTest.kt index d71247247..0900617ae 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/GraphicsReportTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/GraphicsReportTest.kt @@ -25,7 +25,7 @@ class GraphicsReportTest { val old = launch("20261012-100000-1", 60) val mid = launch("20261012-110000-2", 60) val new = launch("20261012-120000-3", 200) - GraphicsReport.capGames(games, fileMax = 100, totalMax = 150) + GraphicsReport.capGames(games, fileMax = 100, totalMax = 170) assertEquals(100L, File(new, "steam-1.log").length()) assertFalse(old.exists()) assertTrue(mid.exists())