fix(drivers): never load a KGSL-only display driver on a GPU without KGSL, and report the drivers actually in use (#2588)

* fix(drivers): never load a KGSL-only display driver on a GPU without KGSL, and report the drivers actually in use

* fix(drivers): gate KGSL-only drivers on the KGSL kernel node, not Adreno detection
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-15 09:36:47 -05:00
1 parent 1570d4457c
commit b424bfa353
5 files changed
+96 -7

No files matched your search

@@ -233,6 +233,10 @@ object DeviceReport {
else "${turnip.displayName(displayId)} ${turnip.driverVersion(displayId)}".trim()
k("Display driver (chosen)", if (androidChoice.isEmpty()) "Auto -> $displayLabel" else androidChoice)
k(" name / version", displayLabel)
turnip.effectiveId().takeIf { it != displayId }?.let { used ->
k(" in use", if (used == "system") DeviceInfo.builtinDriverLabel(SystemVulkanDriver.isPowerVr(), runtime = false)
else "${turnip.displayName(used)} ${turnip.driverVersion(used)}".trim())
}
k(" imported available", turnip.enumerateImported().ifEmpty { listOf("none") }.joinToString(", "))
val lm = LinuxVulkanDriverManager(context)
run {
@@ -242,7 +246,9 @@ object DeviceReport {
lm.getMinGlibc(id).let { if (it.isEmpty()) "" else " (glibc $it+)" } +
if (lm.isInstalled(id)) "" else if (SystemVulkanDriver.isPowerVr()) " [MISSING - select an installed driver or Auto]"
else " [MISSING - falls back to the runtime's own]"
k("Linux driver", label)
val route = DeviceInfo.hostRoute(context)
k("Linux driver", route ?: label)
if (route != null) k(" chosen, not used", label)
}
k("Runtime's own ICD", LinuxRuntime.vulkanIcd(context)?.path)
k("Mali (Venus)", if (com.droiddeck.launcher.session.VenusComponent.wanted(context)) "in use"
@@ -145,16 +145,22 @@ object DeviceInfo {
private fun drivers(context: Context, gpu: GpuInfo) = Section("Drivers DroidDeck uses", buildList<Pair<String, String>> {
add("Driver mode", SessionPrefs.gpuDriverMode(context))
val turnip = TurnipDriver(context)
val choice = SessionPrefs.androidDriver(context).ifEmpty { turnip.autoId() }
val choice = turnip.effectiveId()
val powerVr = gpu.family == GpuInfo.Family.POWERVR
add("Display driver", if (choice == "system") builtinDriverLabel(powerVr, runtime = false)
else "${turnip.displayName(choice)} ${turnip.driverVersion(choice)}".trim())
val linux = LinuxVulkanDriverManager(context)
val id = SessionPrefs.linuxDriver(context)
add("Game driver", if (id.isEmpty()) builtinDriverLabel(powerVr, runtime = true) else "${linux.getDriverName(id)} ${linux.getDriverVersion(id)}".trim())
add("Game driver", hostRoute(context) ?: if (id.isEmpty()) builtinDriverLabel(powerVr, runtime = true) else "${linux.getDriverName(id)} ${linux.getDriverVersion(id)}".trim())
if (gpu.oneUi8Gen2) add("Note", "One UI on an 8 Gen 2: needs the OneUI Turnip build")
})
internal fun hostRoute(context: Context): String? = when {
com.droiddeck.launcher.session.VenusComponent.wanted(context) -> "Mali (Venus)"
com.droiddeck.launcher.core.DeviceSupport.vkBridge(context) -> "the Mali bridge"
else -> null
}
/** Shared by the device card and the session report, which are written in English. */
internal fun builtinDriverLabel(powerVr: Boolean, runtime: Boolean): String = when {
powerVr -> "System PowerVR"
@@ -34,6 +34,8 @@ public final class TurnipDriver {
public static final List<String> BUNDLED = Collections.unmodifiableList(Arrays.asList(
DRIVER_A7XX, DRIVER_A8XX, com.droiddeck.launcher.session.QuestExperimental.DRIVER,
DRIVER_A6XX, com.droiddeck.launcher.session.QuestExperimental.DRIVER_A6XX));
private static final String KGSL_NODE = "/dev/kgsl-3d0";
private static final String KGSL_SYSFS = "/sys/class/kgsl/kgsl-3d0";
private static final String OVERRIDE_FILE = "Download/droiddeck-driver";
private static final String PREFS = "graphics_driver";
private static final String KEY_HIDDEN = "hiddenBundled";
@@ -140,6 +142,25 @@ public final class TurnipDriver {
return id == null ? "system" : id;
}
public String effectiveId() {
String id = choose();
return id == null || !reachesGpu(id) ? "system" : id;
}
public boolean reachesGpu(String driverId) {
String library = libraryName(driverId);
return library == null || !needsMissingKgsl(new File(new File(contentDir, driverId), library),
kgslPresent(new File(KGSL_NODE), new File(KGSL_SYSFS)));
}
static boolean kgslPresent(File node, File sysfs) {
return node.exists() || sysfs.exists();
}
static boolean needsMissingKgsl(File library, boolean kgsl) {
return !kgsl && library.isFile() && LinuxVulkanDriverManager.containsAscii(library, KGSL_NODE);
}
public void remove(String driverId) {
if (driverId == null || driverId.isEmpty() || BUNDLED.contains(driverId)
|| driverId.contains("/") || driverId.contains("..")) return;
@@ -257,6 +278,11 @@ public final class TurnipDriver {
Log.e(TAG, id + " unpacked without " + library);
return null;
}
if (!reachesGpu(id)) {
Log.w(TAG, id + " needs " + KGSL_NODE + ", which this GPU does not have; display on the system Vulkan loader");
DriverSetupLog.write(context, "install.no-kgsl driver=" + id);
return null;
}
Log.i(TAG, "graphics driver " + id + " (" + library + ")");
DriverSetupLog.write(context, "install.ready driver=" + id + " library=" + library);
return id;
@@ -60,17 +60,19 @@ object GraphicsReport {
appendLine("-- path")
appendLine("path: " + path(context))
appendLine("driver mode: " + SessionPrefs.gpuDriverMode(context))
appendLine("display driver (compositor): " + SessionPrefs.androidDriver(context).ifEmpty {
if (DeviceSupport.adreno()) "(auto: bundled Turnip)" else "(auto: the phone's own Vulkan driver, ${SystemVulkanDriver.hal() ?: "vendor HAL"})"
})
val display = SessionPrefs.androidDriver(context)
val shown = com.droiddeck.launcher.gpu.TurnipDriver(context).effectiveId()
appendLine("display driver (compositor): " +
(if (shown == "system") "the phone's own Vulkan driver, ${SystemVulkanDriver.hal() ?: "vendor HAL"}" else shown) +
if (display.isEmpty()) " (auto)" else if (display != shown) " (picked $display, not used)" else "")
appendLine("display driver chosen by: " + when {
display.isEmpty() -> "auto (or a pair on a non-Adreno GPU: the phone's own driver)"
DriverBundle.containing(context, display, false) != null -> "pair (its display half)"
else -> "user (picked on its own)"
})
val linux = SessionPrefs.linuxDriver(context)
appendLine("runtime driver: " + linux.ifEmpty { "(runtime default)" })
appendLine("runtime driver: " + (com.droiddeck.launcher.gpu.DeviceInfo.hostRoute(context)
?.let { "$it (picked ${linux.ifEmpty { "runtime default" }}, not used)" } ?: linux.ifEmpty { "(runtime default)" }))
if (linux.isNotEmpty()) {
val dir = com.droiddeck.launcher.gpu.LinuxVulkanDriverManager(context).getDriverDir(linux)
appendLine("runtime driver dir: ${dir.path} (" + (dir.listFiles()?.filter { it.name.endsWith(".so") }?.joinToString { it.name } ?: "missing") + ")")
@@ -96,6 +96,55 @@ class TurnipDriverAutoTest {
assertEquals("test-pinned", TurnipDriver(context) { error("manual choice must precede detection") }.install())
}
private fun pin(library: String): String {
val context = RuntimeEnvironment.getApplication()
val dir = File(context.filesDir, "graphics_driver/test-pinned").apply { mkdirs() }
File(dir, "meta.json").writeText("""{"libraryName":"test.so"}""")
File(dir, "test.so").writeText(library)
SessionPrefs.setAndroidDriver(context, "test-pinned")
return "test-pinned"
}
@Test fun aPickedDriverThatNeedsKgslFallsBackToTheSystemLoaderWithoutKgsl() {
val context = RuntimeEnvironment.getApplication()
pin("\u0000tu_kgsl\u0000/dev/kgsl-3d0\u0000")
val driver = TurnipDriver(context) { error("manual choice must precede detection") }
assertEquals(null, driver.install())
assertEquals("system", driver.effectiveId())
assertEquals(false, driver.reachesGpu("test-pinned"))
}
@Test fun aPickedDriverForAnotherKernelInterfaceIsStillLoaded() {
val context = RuntimeEnvironment.getApplication()
val id = pin("\u0000panvk\u0000/dev/mali0\u0000")
val driver = TurnipDriver(context) { error("manual choice must precede detection") }
assertEquals(id, driver.install())
assertEquals(id, driver.effectiveId())
}
@Test fun kgslDriversStayUsableWhereKgslExists() {
val lib = File(RuntimeEnvironment.getApplication().filesDir, "graphics_driver/test-pinned/test.so")
lib.parentFile!!.mkdirs()
lib.writeText("/dev/kgsl-3d0")
assertEquals(false, TurnipDriver.needsMissingKgsl(lib, true))
assertEquals(true, TurnipDriver.needsMissingKgsl(lib, false))
lib.writeText("/dev/mali0")
assertEquals(false, TurnipDriver.needsMissingKgsl(lib, false))
assertEquals(false, TurnipDriver.needsMissingKgsl(File(lib.parentFile, "absent.so"), false))
}
@Test fun kgslIsTheKernelInterfaceNotTheVendorVulkanLibrary() {
val root = File(RuntimeEnvironment.getApplication().filesDir, "kgsl-probe").apply { mkdirs() }
val node = File(root, "dev-kgsl-3d0")
val sysfs = File(root, "sys-kgsl-3d0")
assertEquals(false, TurnipDriver.kgslPresent(node, sysfs))
node.writeText("")
assertEquals(true, TurnipDriver.kgslPresent(node, sysfs))
node.delete()
sysfs.mkdirs()
assertEquals(true, TurnipDriver.kgslPresent(node, sysfs))
}
@Test fun normalizedGpuModelsSelectExistingGenerationDrivers() {
for (sdk in listOf(28, 36)) {
assertEquals("turnip26.3.0-a6xx", TurnipDriver.chooseByModel(650, sdk))