Add system and imported Qualcomm drivers as Linux runtime choices

(cherry picked from commit 08fbd19f74561231e6a3adc2069686af111bd0ad)
(cherry picked from commit dd6a86a187)
This commit is contained in:
K11MCH1 authored and The412Banner committed 2026-10-25 23:09:02 +00:00
1 parent 6339d00a7a
commit 3dfe06b05a
18 files changed
+403 -14

No files matched your search

@@ -19,6 +19,8 @@ import com.droiddeck.launcher.gpu.GpuInfo
import com.droiddeck.launcher.gpu.LinuxVulkanDriver
import com.droiddeck.launcher.gpu.LinuxVulkanDriverManager
import com.droiddeck.launcher.gpu.TurnipDriver
import com.droiddeck.launcher.gpu.QualcommSystemDriver
import com.droiddeck.launcher.gpu.QualcommDriverPackage
import com.droiddeck.launcher.gpu.TurnipReleases
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionPrefs
@@ -143,6 +145,10 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl
}
linuxRows = LinuxVulkanDriver.optionValues(activity).map { id ->
if (id.isEmpty()) DriverRow("", activity.getString(R.string.gpu_runtime_default), activity.getString(R.string.drivers_runtime_builtin), false)
else if (id == QualcommSystemDriver.ID) DriverRow(id, "System Qualcomm driver", QualcommSystemDriver.label(), false)
else if (QualcommDriverPackage.isRuntimeId(id)) DriverRow(id,
QualcommDriverPackage.label(activity, id), listOf(QualcommDriverPackage.version(activity, id),
activity.getString(R.string.drivers_qualcomm_runtime_display)).filter { it.isNotEmpty() }.joinToString(" · "), false, DriverRow.IMPORTED)
else bundleRow(id, linux = true) ?: DriverRow(
id, lm.getDriverName(id),
listOfNotNull(
@@ -157,6 +163,8 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl
val td = TurnipDriver(activity)
val auto = td.autoId()
androidRows = buildList {
if (QualcommSystemDriver.detected()) add(DriverRow(TurnipDriver.SYSTEM,
"System Qualcomm driver", QualcommSystemDriver.label(), false))
add(DriverRow(
TurnipDriver.AUTO, activity.getString(R.string.gpu_auto_by_gpu),
if (auto == "system") activity.getString(R.string.drivers_system_vulkan) else activity.getString(R.string.drivers_bundled, td.displayName(auto)),
@@ -431,7 +439,10 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl
val bundle = DriverBundle.containing(activity, id, linux)
when {
bundle != null -> useBundle(bundle)
linux -> SessionPrefs.setLinuxDriver(activity, id)
linux -> {
SessionPrefs.setLinuxDriver(activity, id)
if (QualcommSystemDriver.handles(id)) SessionPrefs.setAndroidDriver(activity, TurnipDriver.SYSTEM)
}
else -> SessionPrefs.setAndroidDriver(activity, id)
}
pairModeOpen = false
@@ -222,7 +222,10 @@ object DeviceReport {
val lm = LinuxVulkanDriverManager(context)
run {
val id = SessionPrefs.linuxDriver(context)
val label = if (id.isEmpty()) "runtime default (the Turnip built into the runtime)"
val label = if (id == com.droiddeck.launcher.gpu.QualcommSystemDriver.ID) com.droiddeck.launcher.gpu.QualcommSystemDriver.label()
else if (com.droiddeck.launcher.gpu.QualcommDriverPackage.isRuntimeId(id))
"${com.droiddeck.launcher.gpu.QualcommDriverPackage.label(context, id)} ${com.droiddeck.launcher.gpu.QualcommDriverPackage.version(context, id)}"
else if (id.isEmpty()) "runtime default (the Turnip built into the runtime)"
else "${lm.getDriverName(id)} ${lm.getDriverVersion(id)}".trim() +
lm.getMinGlibc(id).let { if (it.isEmpty()) "" else " (glibc $it+)" } +
if (lm.isInstalled(id)) "" else " [MISSING - falls back to the runtime's own]"
@@ -149,7 +149,9 @@ object DeviceInfo {
add("Display driver", "${turnip.displayName(choice)} ${turnip.driverVersion(choice)}".trim())
val linux = LinuxVulkanDriverManager(context)
val id = SessionPrefs.linuxDriver(context)
add("Game driver", if (id.isEmpty()) "the runtime's own Turnip" else "${linux.getDriverName(id)} ${linux.getDriverVersion(id)}".trim())
add("Game driver", if (id == QualcommSystemDriver.ID) QualcommSystemDriver.label()
else if (QualcommDriverPackage.isRuntimeId(id)) "${QualcommDriverPackage.label(context, id)} ${QualcommDriverPackage.version(context, id)}"
else if (id.isEmpty()) "the runtime's own Turnip" 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")
})
}
@@ -12,8 +12,8 @@ public final class LinuxVulkanDriver {
public static final String HELP_TEXT =
"The driver the Steam client, the games it launches and the desktop's programs render on, "
+ "inside the Linux runtime. Imported \"-Linux\" Turnip zips only: these are Linux processes "
+ "and cannot load an Android or Wayland driver. Frames still reach the screen through the "
+ "inside the Linux runtime. Import \"-Linux\" Turnip zips, or select the experimental system "
+ "Qualcomm bridge or a Qualcomm package already imported as an AdrenoTools zip. Frames reach the screen through the "
+ "display driver below. Takes effect at the next session start.";
private LinuxVulkanDriver() {}
@@ -21,12 +21,18 @@ public final class LinuxVulkanDriver {
public static List<String> optionValues(Context context) {
ArrayList<String> values = new ArrayList<>();
values.add("");
if (QualcommSystemDriver.detected()) {
values.add(QualcommSystemDriver.ID);
values.addAll(QualcommDriverPackage.available(context));
}
values.addAll(new LinuxVulkanDriverManager(context).enumerateInstalledDrivers());
return values;
}
public static String optionLabel(Context context, String value) {
if (value == null || value.isEmpty()) return "Runtime default (built into the runtime)";
if (QualcommSystemDriver.ID.equals(value)) return QualcommSystemDriver.label();
if (QualcommDriverPackage.isRuntimeId(value)) return QualcommDriverPackage.label(context, value);
LinuxVulkanDriverManager m = new LinuxVulkanDriverManager(context);
if (!m.isInstalled(value)) return value + " (imported, missing - uses the runtime default)";
String ver = m.getDriverVersion(value);
@@ -35,6 +41,11 @@ public final class LinuxVulkanDriver {
public static String resolveIcdPath(Context context, String value) {
if (value == null || value.isEmpty()) return null;
if (QualcommSystemDriver.handles(value)) {
if (QualcommDriverPackage.isRuntimeId(value) && !QualcommDriverPackage.isInstalled(context, value))
throw new IllegalStateException("The selected Qualcomm AdrenoTools package is missing or incompatible");
return QualcommSystemDriver.prepare(context).getAbsolutePath();
}
LinuxVulkanDriverManager m = new LinuxVulkanDriverManager(context);
String icd = m.getIcdPath(value);
if (icd == null) {
@@ -0,0 +1,73 @@
package com.droiddeck.launcher.gpu
import android.content.Context
import android.os.Build
import com.droiddeck.launcher.core.FileUtils
import org.json.JSONObject
import java.io.File
object QualcommDriverPackage {
private const val PREFIX = "qualcomm-adrenotools:"
@JvmStatic fun runtimeId(importedId: String): String {
require(validName(importedId)) { "Invalid imported driver ID" }
return PREFIX + importedId
}
@JvmStatic fun importedId(runtimeId: String?): String? = runtimeId
?.takeIf { it.startsWith(PREFIX) }?.removePrefix(PREFIX)?.takeIf(::validName)
@JvmStatic fun isRuntimeId(id: String?): Boolean = id?.startsWith(PREFIX) == true
private fun validName(name: String): Boolean = name.isNotBlank() && name != "." && !name.contains("..") &&
name.none { it == '/' || it == '\\' || it == ':' || it == '\u0000' }
private fun metadata(context: Context, id: String): JSONObject? {
if (!validName(id)) return null
return runCatching { JSONObject(FileUtils.readString(File(TurnipDriver(context).driverPath(id), "meta.json"))) }.getOrNull()
}
@JvmStatic fun available(context: Context): List<String> = TurnipDriver(context).enumerateImported()
.filter { isInstalled(context, runtimeId(it)) }.map(::runtimeId)
@JvmStatic fun isInstalled(context: Context, runtimeId: String): Boolean {
val id = importedId(runtimeId) ?: return false
val meta = metadata(context, id) ?: return false
val vendor = meta.optString("vendor")
val description = listOf(meta.optString("name"), meta.optString("description"), meta.optString("libraryName")).joinToString(" ")
if (!vendor.equals("Qualcomm", true) || description.contains("turnip", true) || description.contains("mesa", true)) return false
if (meta.optInt("minApi", 0) > Build.VERSION.SDK_INT) return false
val library = meta.optString("libraryName")
return validName(library) && library.endsWith(".so") && TurnipDriver(context).isInstalled(id) &&
LinuxVulkanDriverManager.isAarch64Elf(File(TurnipDriver(context).driverPath(id), library))
}
@JvmStatic fun label(context: Context, runtimeId: String): String {
val id = importedId(runtimeId) ?: return "Invalid Qualcomm package"
val driver = TurnipDriver(context)
return "${driver.displayName(id)} · Qualcomm (AdrenoTools, experimental)" +
if (isInstalled(context, runtimeId)) "" else " [missing or incompatible]"
}
@JvmStatic fun version(context: Context, runtimeId: String): String = importedId(runtimeId)
?.let { TurnipDriver(context).driverVersion(it) }.orEmpty()
@JvmStatic fun mounts(context: Context, runtimeId: String): List<String> {
check(isInstalled(context, runtimeId)) { "The selected Qualcomm AdrenoTools package is missing or incompatible" }
val id = importedId(runtimeId)!!
val driver = TurnipDriver(context)
val directory = File(driver.driverPath(id))
val primary = driver.libraryName(id)!!
val mounts = arrayListOf("${File(directory, primary).path}:${QualcommSystemDriver.HAL}")
for (library in directory.listFiles().orEmpty().sortedBy { it.name }) {
val name = library.name
if (name == primary || !name.endsWith(".so") || !validName(name) ||
name in setOf("libc.so", "libdl.so", "libm.so", "liblog.so", "libvulkan.so") ||
!LinuxVulkanDriverManager.isAarch64Elf(library)) continue
mounts.add("${library.path}:/vendor/lib64/$name")
// The SP-HAL namespace resolves libc++ from system before vendor.
if (name == "libc++.so") mounts.add("${library.path}:/system/lib64/$name")
}
return mounts
}
}
@@ -0,0 +1,110 @@
package com.droiddeck.launcher.gpu
import android.content.Context
import android.os.Build
import com.droiddeck.launcher.BuildConfig
import com.droiddeck.launcher.core.FileUtils
import com.droiddeck.launcher.core.TarZst
import com.droiddeck.launcher.session.SessionPrefs
import org.json.JSONObject
import java.io.File
object QualcommSystemDriver {
const val ID = "system-qualcomm"
const val HAL = "/vendor/lib64/hw/vulkan.adreno.so"
private val required = listOf("lib/libhybris-vulkan-icd.so.0", "lib/libhybris-common.so.1", "lib/libhybris/linker/q.so",
"bin/gamescope", "shaders/qualcomm-shaders.so", "wsi/libVkLayer_window_system_integration.so")
@JvmStatic fun detected(): Boolean {
if (Build.VERSION.SDK_INT < 29 || !File(HAL).canRead()) return false
val vk = VulkanInfo.query()
return isQualcomm(vk)
}
internal fun isQualcomm(vk: Map<String, String>): Boolean =
vk["vendor_id"] == "0x5143" && (vk["driver_id"] == "8" ||
(vk["driver_id"] == null && vk["driver_name"]?.contains("Qualcomm", ignoreCase = true) == true))
@JvmStatic fun handles(id: String?) = id == ID || QualcommDriverPackage.isRuntimeId(id)
@JvmStatic fun selected(context: Context) = handles(SessionPrefs.linuxDriver(context))
@JvmStatic fun mounts(context: Context, id: String): List<String> = androidPaths() +
if (QualcommDriverPackage.isRuntimeId(id)) QualcommDriverPackage.mounts(context, id) else emptyList()
@JvmStatic fun label(): String {
val vk = VulkanInfo.query()
val version = vk["driver_version_raw"]?.toULongOrNull()?.let { "${(it shr 22) and 0x7fu}.${(it shr 12) and 0x3ffu}.${it and 0xfffu}" }
?: vk["driver_version"] ?: "unknown version"
return "System Qualcomm · ${vk["device"] ?: "Adreno"} · $version (experimental)"
}
@JvmStatic @Synchronized fun prepare(context: Context): File {
check(detected()) { "The installed Vulkan driver is not a supported Qualcomm Android driver" }
val sha = BuildConfig.QUALCOMM_BRIDGE_SHA256 + "-" + BuildConfig.QUALCOMM_FIXES_REVISION.take(16)
val root = File(context.filesDir, "qualcomm-system")
val dir = File(root, sha)
if (!File(dir, ".complete").isFile || required.any { !File(dir, it).isFile }) {
val staging = File(root, "$sha.partial")
FileUtils.delete(staging)
check(TarZst.extractAsset(context, "qualcomm/runtime.tzst", staging)) { "Cannot extract the Qualcomm Vulkan bridge" }
val gamescope = File(staging, "bin/gamescope")
gamescope.parentFile!!.mkdirs()
check(FileUtils.copyAsset(context, "qualcomm/gamescope", gamescope)) { "Cannot prepare Qualcomm Gamescope" }
check(gamescope.setExecutable(true, false)) { "Cannot prepare Qualcomm Gamescope" }
copyAssets(context, "qualcomm/wsi", File(staging, "wsi"))
copyAssets(context, "qualcomm/shaders", File(staging, "shaders"))
copyAssets(context, "qualcomm/licenses", File(staging, "licenses"))
check(required.all { File(staging, it).isFile }) { "The Qualcomm Vulkan bridge is incomplete" }
File(staging, ".complete").writeText(sha)
FileUtils.delete(dir)
check(staging.renameTo(dir)) { "Cannot install the Qualcomm Vulkan bridge" }
}
val manifest = JSONObject().put("file_format_version", "1.0.0").put("ICD", JSONObject()
.put("library_path", File(dir, "lib/libhybris-vulkan-icd.so.0").path)
.put("api_version", VulkanInfo.query()["api"] ?: "1.1.0"))
val icd = File(dir, "icd.json")
if (!icd.isFile || icd.readText() != manifest.toString()) icd.writeText(manifest.toString())
return icd
}
@JvmStatic @JvmOverloads fun addEnvironment(context: Context, environment: MutableList<String>, id: String = SessionPrefs.linuxDriver(context)) {
if (QualcommDriverPackage.isRuntimeId(id)) check(QualcommDriverPackage.isInstalled(context, id)) {
"The selected Qualcomm AdrenoTools package is missing or incompatible"
}
val icd = prepare(context)
val dir = icd.parentFile!!
val source = if (id == ID) label() else QualcommDriverPackage.label(context, id)
android.util.Log.i("QualcommSystemDriver", "$source; Android mounts: ${mounts(context, id).joinToString()}")
environment.addAll(listOf(
"VK_DRIVER_FILES=${icd.path}", "VK_ICD_FILENAMES=${icd.path}",
"HYBRIS_ANDROID_SDK_VERSION=${Build.VERSION.SDK_INT}", "HYBRIS_VULKAN_HAL=$HAL",
"HYBRIS_LINKER_DIR=${File(dir, "lib/libhybris/linker").path}",
"HYBRIS_LD_LIBRARY_PATH=/system/lib64:/system_ext/lib64:/vendor/lib64/egl:/vendor/lib64/hw:/vendor/lib64",
"DROIDDECK_SYSTEM_QUALCOMM=1", "BL_GAMESCOPE_BACKEND=sdl",
"DROIDDECK_QUALCOMM_DRIVER=$id",
"BL_STEAM_CEF_SOFTWARE=1",
"BL_GAMESCOPE_BINARY=${File(dir, "bin/gamescope").path}",
"DROIDDECK_QUALCOMM_ROOT=${dir.path}",
"DROIDDECK_QUALCOMM_SHADERS=${File(dir, "shaders").path}",
"VK_LAYER_PATH=${File(dir, "shaders").path}",
"VK_INSTANCE_LAYERS=VK_LAYER_DROIDDECK_qualcomm_shaders",
"PATH=${File(dir, "bin").path}:/usr/local/bin:/usr/bin:/bin",
))
}
private fun copyAssets(context: Context, path: String, destination: File) {
val children = context.assets.list(path) ?: emptyArray()
if (children.isEmpty()) {
check(FileUtils.copyAsset(context, path, destination)) { "Cannot prepare $path" }
} else {
check(destination.isDirectory || destination.mkdirs()) { "Cannot prepare $path" }
for (child in children) copyAssets(context, "$path/$child", File(destination, child))
}
}
@JvmStatic fun androidPaths(): List<String> = listOf(
"/system", "/vendor", "/odm", "/system_ext", "/product", "/apex", "/linkerconfig",
"/dev/__properties__"
).filter { File(it).exists() }
}
@@ -37,6 +37,7 @@ public final class TurnipDriver {
private static final String PREFS = "graphics_driver";
private static final String KEY_HIDDEN = "hiddenBundled";
public static final String AUTO = "";
public static final String SYSTEM = "system";
public static final String HELP_TEXT =
"The driver the app's compositor puts frames on the screen with - the last step of every "
@@ -139,6 +140,8 @@ public final class TurnipDriver {
Log.d(TAG, "removing imported driver " + driverId);
FileUtils.delete(new File(contentDir, driverId));
if (driverId.equals(SessionPrefs.androidDriver(context))) SessionPrefs.setAndroidDriver(context, AUTO);
if (driverId.equals(QualcommDriverPackage.importedId(SessionPrefs.INSTANCE.linuxDriver(context))))
SessionPrefs.INSTANCE.setLinuxDriver(context, "");
}
public String installFromZip(Uri zipUri, String displayName) throws IOException {
@@ -257,6 +260,7 @@ public final class TurnipDriver {
private String choose() {
String chosen = SessionPrefs.androidDriver(context);
if (SYSTEM.equals(chosen)) return null;
if (chosen != null && !chosen.isEmpty()) {
if (BUNDLED.contains(chosen)) {
Log.i(TAG, "driver pinned by the user: " + chosen);
@@ -179,6 +179,15 @@ object BwrapSpawner {
val argv = request.getJSONArray("argv").let { a -> (0 until a.length()).map { a.getString(it) } }
val env = LinkedHashMap<String, String>()
request.optJSONObject("env")?.let { e -> e.keys().forEach { k -> env[k] = e.getString(k) } }
val runtimeDriver = com.droiddeck.launcher.session.SessionState.runtimeDriver
if (com.droiddeck.launcher.gpu.QualcommSystemDriver.handles(runtimeDriver)) {
val driver = com.droiddeck.launcher.gpu.QualcommSystemDriver
val variables = ArrayList<String>()
driver.addEnvironment(context, variables, runtimeDriver!!)
for (entry in variables) env.putIfAbsent(entry.substringBefore('='), entry.substringAfter('='))
for (path in driver.mounts(context, runtimeDriver) + File(context.filesDir, "qualcomm-system").path)
addBind(Bind.parse(path))
}
if (binds.any { it.guest == "/dev" }) gpu(rootfs, root, env)?.forEach { addBind(it) }
preload(session, rootfs, env).forEach { addBind(it) }
zypakShims(binds, root, dir).forEach { addBind(it) }
@@ -160,6 +160,10 @@ public final class LinuxRuntime {
bind(cmd, "/dev");
bind(cmd, "/proc");
bind(cmd, "/sys");
if (com.droiddeck.launcher.gpu.QualcommSystemDriver.selected(context)) {
for (String path : com.droiddeck.launcher.gpu.QualcommSystemDriver.mounts(context,
SessionPrefs.INSTANCE.linuxDriver(context))) bind(cmd, path);
}
bind(cmd, "/dev/urandom:/dev/random");
bind(cmd, "/proc/self/fd:/dev/fd");
bind(cmd, "/proc/self/fd/0:/dev/stdin");
@@ -56,6 +56,8 @@ object SessionFiles {
"usr/local/bin/droiddeck-desktop-clipboard" to "usr/local/bin/droiddeck-desktop-clipboard",
"usr/local/bin/droiddeck-gpu-window" to "usr/local/bin/droiddeck-gpu-window",
"usr/local/bin/droiddeck-steam-install" to "usr/local/bin/droiddeck-steam-install",
"usr/local/bin/droiddeck-steam-taskset" to "usr/local/bin/droiddeck-steam-taskset",
"usr/local/bin/droiddeck-steam-taskset" to "usr/local/libexec/droiddeck-steam/taskset",
"usr/local/bin/droiddeck-steam-ui-scale" to "usr/local/bin/droiddeck-steam-ui-scale",
"usr/local/bin/droiddeck-steam-language" to "usr/local/bin/droiddeck-steam-language",
"usr/local/bin/droiddeck-steam-shaders" to "usr/local/bin/droiddeck-steam-shaders",
@@ -719,8 +719,10 @@ class SessionService : Service() {
guest.add("MESA_LOADER_DRIVER_OVERRIDE=zink")
guest.add("GALLIUM_DRIVER=zink")
guest.add("LIBGL_KOPPER_DRI2=true")
LinuxRuntime.vulkanIcd(this)?.let { guest.add("VK_ICD_FILENAMES=" + it.path) }
val linuxDriverId = SessionPrefs.linuxDriver(this)
val systemQualcomm = com.droiddeck.launcher.gpu.QualcommSystemDriver.handles(linuxDriverId)
if (systemQualcomm) com.droiddeck.launcher.gpu.QualcommSystemDriver.addEnvironment(this, guest)
else LinuxRuntime.vulkanIcd(this)?.let { guest.add("VK_ICD_FILENAMES=" + it.path) }
SessionState.runtimeDriver = linuxDriverId
com.droiddeck.launcher.gpu.AutoDriverTrial.sessionStarting(
this,
@@ -730,9 +732,9 @@ class SessionService : Service() {
)
LinuxVulkanDriver.resolveIcdPath(this, linuxDriverId)
?.let { guest.add(LinuxVulkanDriver.ENV + "=" + it) }
val tuOverride = tuDebugOverride()
val tuOverride = if (systemQualcomm) null else tuDebugOverride()
val tuDriver = sysmemDriver(linuxDriverId)
(tuOverride ?: "sysmem".takeIf { tuDriver || SessionPrefs.tuSysmem(this) })?.let { guest.add("TU_DEBUG=$it") }
if (!systemQualcomm) (tuOverride ?: "sysmem".takeIf { tuDriver || SessionPrefs.tuSysmem(this) })?.let { guest.add("TU_DEBUG=$it") }
if (SessionPrefs.zinkLazy(this)) {
guest.add("ZINK_DESCRIPTORS=lazy")
guest.add("ZINK_DEBUG=compact")
@@ -740,7 +742,9 @@ class SessionService : Service() {
if (SessionPrefs.glThread(this)) guest.add("mesa_glthread=true")
if (SessionPrefs.noGlError(this)) guest.add("MESA_NO_ERROR=1")
guest.add("MESA_DISK_CACHE_DATABASE=1")
guest.add("GLIBC_TUNABLES=glibc.pthread.rseq=0:glibc.malloc.top_pad=16777216")
// Steam loads libhybris after other TLS users; its Bionic TLS bridge requires static storage.
val staticTls = if (systemQualcomm) ":glibc.rtld.optional_static_tls=16384" else ""
guest.add("GLIBC_TUNABLES=glibc.pthread.rseq=0:glibc.malloc.top_pad=16777216$staticTls")
if (SessionState.mode == MODE_STEAM) guest.add("BL_MANGOAPP=" + (if (SessionPrefs.mangoapp(this)) "1" else "0"))
SessionState.steamClientArch = if (steamHere) SessionPrefs.steamClientArch(this) else null
SessionState.steamClientArch?.let { arch ->