Mali bridge (#517, by ASEbrahim) on the non-Adreno test branch

Squash of Droid-Deck/DroidDeck#517 (ASEbrahim/DroidDeck mali-bridge @ 6b823341): the Vulkan
bridge (tools/vkbridge) that runs the guest's Vulkan on the phone's own driver, with BC1-BC7,
clip/cull distance, vertex-divisor and depth-clip emulation and dma-heap memory sharing for Mali.
All of the bridge is ASEbrahim's work; squashed only to carry it on this test branch.

Combined with #570 on this branch, a device draws through exactly one path:
- Adreno: Turnip, unchanged (checked first; the bridge setting is ignored there).
- PowerVR / Xclipse with the system HAL and a render node: the system-Vulkan path (#570).
- Anything else with the Setup toggle on (Mali): the bridge.
This commit is contained in:
The412Banner committed 2026-10-12 18:34:49 -04:00
1 parent 56dc433673
commit a2637af094
125 files changed
+119982 -12

No files matched your search

@@ -146,6 +146,8 @@ class MainActivity : ComponentActivity() {
private var gameCores by mutableStateOf<Set<Int>>(emptySet())
private var tuSysmem by mutableStateOf(false)
private var zinkLazy by mutableStateOf(false)
private var vkBridge by mutableStateOf(false)
private val adrenoGpu by lazy { com.droiddeck.launcher.core.DeviceSupport.adreno() }
private var noXalia by mutableStateOf(true)
private var fastSync by mutableStateOf(false)
private var syncFallback by mutableStateOf(true)
@@ -554,6 +556,7 @@ class MainActivity : ComponentActivity() {
FrontEndScreen(
FrontEndState(
installed = installed, ready = ready, available = available?.version, removalPending = removalPending, runtimeActionsBlocked = runtimeChangesBlocked(),
vkBridge = vkBridge, adreno = adrenoGpu,
shortcutPicker = shortcutPicker,
shortcutLibraryScanning = shortcutLibraryScanning,
gameSyncFolder = gameSyncFolder,
@@ -681,6 +684,7 @@ class MainActivity : ComponentActivity() {
onInstallPackage = { id -> installPackage(id) },
onRemovePackage = { id -> removePackage(id) },
onRuntime = { onRuntimeButton() },
onVkBridge = { on -> SessionPrefs.setVkBridge(this, on); vkBridge = on },
onFrameGenPick = { mode ->
FrameGen.set(this, mode)
frameGenLabel = FrameGen.label(this)
@@ -1575,6 +1579,7 @@ class MainActivity : ComponentActivity() {
gameCores = CpuCores.parse(SessionPrefs.gameCpus(this)).ifEmpty { CpuCores.all.toSet() }
tuSysmem = SessionPrefs.tuSysmem(this)
zinkLazy = SessionPrefs.zinkLazy(this)
vkBridge = SessionPrefs.vkBridge(this)
noXalia = SessionPrefs.noXalia(this)
fastSync = SessionPrefs.fastSync(this)
syncFallback = SessionPrefs.syncFallback(this)
@@ -1677,7 +1682,7 @@ class MainActivity : ComponentActivity() {
// The runtime draws with Turnip, an Adreno driver: on Mali, Xclipse or PowerVR the
// compositor gets no usable Vulkan device and a session is sound over a black screen.
// Said before the download, not after it; the user may still go ahead.
if (installed == null && !com.droiddeck.launcher.core.DeviceSupport.graphicsAvailable()) { showNonAdreno = release; return }
if (installed == null && !com.droiddeck.launcher.core.DeviceSupport.canDraw(this)) { showNonAdreno = release; return }
install(release)
}
@@ -1689,7 +1694,7 @@ class MainActivity : ComponentActivity() {
showPhantomGate = true
return false
}
val warn = installed == null && !com.droiddeck.launcher.core.DeviceSupport.graphicsAvailable()
val warn = installed == null && !com.droiddeck.launcher.core.DeviceSupport.canDraw(this)
if (warn && available != null) { showNonAdreno = available; return false }
startActivity(intent)
return true
@@ -17,6 +17,17 @@ object DeviceSupport {
internal fun graphicsAvailable(adreno: Boolean, powerVrReady: Boolean): Boolean = adreno || powerVrReady
/**
* Whether the Linux side draws through the Vulkan bridge (tools/vkbridge, PR #517): asked for in
* Setup, and only on a GPU that is neither an Adreno nor one the system-Vulkan path (PowerVR,
* Xclipse) already handles. An Adreno keeps Turnip whatever the setting says.
*/
fun vkBridge(context: Context): Boolean =
!adreno() && !SystemVulkanDriver.isAvailable() && com.droiddeck.launcher.session.SessionPrefs.vkBridge(context)
/** A session can draw: Adreno with Turnip, PowerVR/Xclipse on the system driver, or the bridge. */
fun canDraw(context: Context): Boolean = graphicsAvailable() || vkBridge(context)
/** The chip as the device names it, for the card that explains the refusal. */
fun gpuName(context: Context): String {
val soc = if (Build.VERSION.SDK_INT >= 31) Build.SOC_MODEL.takeIf { it.isNotBlank() && it != Build.UNKNOWN } else null
@@ -0,0 +1,122 @@
package com.droiddeck.launcher.gpu
import android.content.Context
import android.os.Build
import android.os.PowerManager
import android.util.Log
import com.droiddeck.launcher.core.SessionPart
import java.io.File
import java.io.FileWriter
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
/**
* Clocks and thermal state through a Mali bridge session, into the session folder
* (vkbridge-clocks.log), for telling the bridge's overhead apart from the phone holding the chip
* back: Samsung's SSRM lowers the CPU policies' scaling_max_freq when the device warms, so a
* policy whose max is below its cpuinfo_max_freq is being clamped (upstream issue #64).
*
* Every [PERIOD_MS]: each CPU policy as cur/max(hardware max) MHz, the GPU clock from the first
* Mali/MediaTek source the app may read, and Android's thermal status and headroom. Which GPU
* sources were readable is logged once at the start - SELinux refuses apps most of them, each
* vendor differently, and this is how the next run finds out which.
*/
class ClockLogComponent(private val logFile: File) : SessionPart() {
@Volatile private var running = false
private var thread: Thread? = null
override fun start() {
running = true
thread = Thread({ run() }, "clock-log").apply { isDaemon = true; start() }
}
override fun stop() {
running = false
thread?.interrupt()
thread = null
}
private fun run() {
val policies = File("/sys/devices/system/cpu/cpufreq").listFiles { f -> f.name.startsWith("policy") }
?.sortedBy { it.name.removePrefix("policy").toIntOrNull() ?: 0 } ?: emptyList()
val gpuCandidates = gpuSources()
// The /proc status files hold several numbers: listed for whether they read, not taken as the clock.
val gpu = gpuCandidates.firstOrNull { !it.startsWith("/proc/") && firstNumber(it) != null }
val power = app().getSystemService(Context.POWER_SERVICE) as? PowerManager
val time = SimpleDateFormat("HH:mm:ss", Locale.US)
try {
FileWriter(logFile, true).use { w ->
w.write("== clocks: ${Build.MANUFACTURER} ${Build.MODEL} (${Build.HARDWARE}), every ${PERIOD_MS / 1000}s\n")
w.write("cpu policies: ${policies.joinToString { p -> p.name + " " + (File(p, "related_cpus").readTextOrNull()?.trim() ?: "?") }}\n")
for (source in gpuCandidates) {
val f = File(source)
val state = when {
!f.exists() -> continue
firstNumber(source) != null -> "readable"
else -> "refused"
}
w.write("gpu source $source: $state\n")
}
w.write("gpu clock from: ${gpu ?: "nothing readable"}\n")
w.flush()
while (running && logFile.length() < MAX_BYTES) {
val line = StringBuilder(time.format(Date()))
for (p in policies) {
val cur = firstNumber(File(p, "scaling_cur_freq").path)
val max = firstNumber(File(p, "scaling_max_freq").path)
val hw = firstNumber(File(p, "cpuinfo_max_freq").path)
line.append(" ${p.name.removePrefix("policy").let { "p$it" }} ${mhz(cur)}/${mhz(max)}")
if (hw != null && max != null && max < hw) line.append("(of ${mhz(hw)})")
}
gpu?.let { line.append(" | gpu ${mhz(firstNumber(it))} MHz") }
if (power != null && Build.VERSION.SDK_INT >= 29) {
line.append(" | thermal ${power.currentThermalStatus}")
if (Build.VERSION.SDK_INT >= 30) {
val h = power.getThermalHeadroom(10)
if (!h.isNaN()) line.append(String.format(Locale.US, " headroom %.2f", h))
}
}
w.write(line.append('\n').toString())
w.flush()
try { Thread.sleep(PERIOD_MS) } catch (e: InterruptedException) { break }
}
}
} catch (e: Exception) {
Log.w(TAG, "clock log stopped: $e")
}
}
companion object {
private const val TAG = "SessionService"
private const val PERIOD_MS = 2000L
private const val MAX_BYTES = 4L shl 20
/** Mali (Exynos, Tensor, MediaTek) and MediaTek GED clock files, plus any GPU devfreq node. */
private fun gpuSources(): List<String> {
val list = mutableListOf(
"/sys/kernel/ged/hal/current_freqency", "/sys/kernel/ged/hal/current_frequency",
"/proc/gpufreqv2/gpufreq_status", "/proc/gpufreq/gpufreq_var_dump",
"/sys/kernel/gpu/gpu_clock", "/sys/class/misc/mali0/device/cur_freq",
"/sys/class/misc/mali0/device/clock",
)
File("/sys/class/devfreq").list()?.sorted()?.forEach { node ->
if (node.contains("mali", true) || node.contains("gpu", true)) list.add("/sys/class/devfreq/$node/cur_freq")
}
return list.distinct()
}
private fun File.readTextOrNull(): String? = runCatching { readText() }.getOrNull()
private fun firstNumber(path: String): Long? =
runCatching { Regex("\\d+").find(File(path).readText())?.value?.toLong() }.getOrNull()
/** Hz, kHz or MHz to MHz; "?" when unread. */
private fun mhz(raw: Long?): String = when {
raw == null -> "?"
raw > 10_000_000 -> (raw / 1_000_000).toString()
raw > 10_000 -> (raw / 1_000).toString()
else -> raw.toString()
}
}
}
@@ -342,6 +342,13 @@ public final class TurnipDriver {
if (forced.startsWith("a7")) return DRIVER_A7XX;
}
if (SystemVulkanDriver.isPowerVr()) return null;
// Not an Adreno (Mali, Xclipse...): Turnip cannot open a GPU without KGSL. The compositor
// runs on the phone's own driver, which has the dma-buf import it needs (the Mali bridge
// depends on it too).
if (!com.droiddeck.launcher.core.DeviceSupport.INSTANCE.adreno()) {
Log.i(TAG, "no KGSL: the compositor uses the system Vulkan driver");
return null;
}
String model = gpuModel();
Log.i(TAG, "gpu model: " + (model == null ? "unknown" : model));
if (model != null) {
@@ -0,0 +1,79 @@
package com.droiddeck.launcher.gpu
import android.os.Process
import android.util.Log
import com.droiddeck.launcher.core.HostProcess
import com.droiddeck.launcher.core.SessionPart
import java.io.File
/**
* The Vulkan bridge server (tools/vkbridge, app/src/main/cpp/vkbridge) for one session.
*
* On a GPU without Adreno's KGSL nothing inside the Linux runtime can reach the GPU: Turnip needs
* KGSL, and the phone's own driver is a bionic library a glibc program cannot load. The server is
* a bionic process the app starts here - executed from the native library directory like the
* DirectAudio relay - which loads the system Vulkan loader and runs the Vulkan calls the
* session's programs send it through the bridge ICD over a Unix socket. It is the app's child, so
* it dies with the app (it also asks for that with PR_SET_PDEATHSIG).
*
* Started before the guest and waited for: the server runs a self-test first (which memory
* sharing works on this GPU), and only then listens; a program that starts before the socket
* exists would find no Vulkan driver.
*/
class VkBridgeComponent(private val socket: File, private val logFile: File) : SessionPart() {
@Volatile private var pid = -1
@Volatile private var exited = false
override fun start() {
stop()
val binary = File(app().applicationInfo.nativeLibraryDir, BINARY)
if (!binary.isFile) {
Log.e(TAG, "server missing at $binary; the session will have no Vulkan")
return
}
socket.parentFile?.mkdirs()
// Pipeline cache kept across sessions (Mali recompiles everything in a new process otherwise).
val cacheDir = File(app().cacheDir, "vkbridge-pipelines").apply { mkdirs() }
if (VkBridgeNative.start(app(), socket, logFile, cacheDir)) {
Log.i(TAG, "server ready in the app's process at $socket")
return
}
socket.delete()
exited = false
val cmd = listOf(binary.absolutePath, "--socket", socket.absolutePath, "--log", logFile.absolutePath,
"--cache-dir", cacheDir.absolutePath)
.joinToString(" ") { it.replace("\\", "\\\\").replace(" ", "\\ ") }
val env = arrayOf("HOME=" + app().filesDir)
pid = HostProcess.start(cmd, env, app().filesDir, { status ->
exited = true
Log.w(TAG, "server exited with status $status")
runCatching { logFile.appendText("== vkbridge server exited with status $status\n") }
}, { line -> Log.i(TAG, line) })
// The self-test takes about a second; a cold driver can take longer.
val deadline = System.currentTimeMillis() + 15_000L
while (!socket.exists() && !exited && System.currentTimeMillis() < deadline) {
try { Thread.sleep(50L) } catch (e: InterruptedException) { Thread.currentThread().interrupt(); break }
}
Log.i(TAG, if (socket.exists()) "server ready (pid $pid) at $socket" else "server NOT ready (pid $pid, exited=$exited); see $logFile")
}
override fun stop() {
// The in-app server outlives sessions: its socket stays.
if (pid > 0) {
Process.killProcess(pid)
pid = -1
}
if (!VkBridgeNative.serving) socket.delete()
}
override fun suspendPid(): Int = pid
companion object {
private const val TAG = "VkBridge"
/** The server, named as a library so Android extracts it and lets the app run it. */
const val BINARY = "libvkbridge_server.so"
/** Inside the runtime (staged by SessionFiles). */
const val GUEST_ICD = "/usr/local/share/vkbridge/droidbridge_icd.json"
const val GUEST_LIB = "/usr/local/lib/vkbridge/libvulkan_droidbridge.so"
}
}
@@ -0,0 +1,65 @@
package com.droiddeck.launcher.gpu
import android.content.Context
import android.content.pm.ApplicationInfo
import android.util.Log
import java.io.File
/**
* The bridge server inside the app's own process (libvkbridge_jni.so, server_main.c).
*
* Android chooses the GPU driver - Samsung's updatable one included - while the app starts up, and
* only for the app's process: the server run as a separate executable got the plain /vendor driver,
* which on the Tab S10+ lacked VK_EXT_robustness2 and more that the app itself sees. Started by the
* first bridge session and kept for the app's life; later sessions only point its log at their
* own folder. VkBridgeComponent falls back to the executable when this cannot start.
*/
object VkBridgeNative {
private const val TAG = "VkBridge"
@Volatile private var loaded: Boolean? = null
/**
* The packaged library, or - in a debuggable build only - files/vkbridge/dev/libvkbridge_jni.so
* when present, so a rebuilt server can be tried with `adb push` + `run-as cp` and an app
* restart instead of a new APK (the app targets SDK 28 and may load code from its files).
*/
private fun load(context: Context): Boolean {
loaded?.let { return it }
val ok = try {
val dev = File(context.filesDir, "vkbridge/dev/libvkbridge_jni.so")
val debuggable = context.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0
if (debuggable && dev.isFile) {
Log.w(TAG, "in-app server from the development override $dev")
System.load(dev.absolutePath)
} else {
System.loadLibrary("vkbridge_jni")
}
true
} catch (e: Throwable) {
Log.w(TAG, "in-app server unavailable: $e")
false
}
loaded = ok
return ok
}
/** Whether the in-app server is serving (its socket must then be left alone). */
@Volatile var serving = false
private set
/** Starts the server, or points its log at [log] when it already runs; false when it cannot serve. */
fun start(context: Context, socket: File, log: File, cacheDir: File): Boolean {
if (!load(context)) return false
val ok = try {
nativeStart(socket.absolutePath, log.absolutePath, cacheDir.absolutePath) == 1
} catch (e: Throwable) {
Log.w(TAG, "in-app server failed to start: $e")
false
}
if (ok) serving = true
return ok
}
@JvmStatic private external fun nativeStart(socket: String, log: String, cacheDir: String): Int
}
@@ -229,6 +229,7 @@ object BwrapSpawner {
* own choice of driver (VK_ICD_FILENAMES, MESA_LOADER_DRIVER_OVERRIDE) is left alone.
*/
private fun gpu(rootfs: String, root: File, env: MutableMap<String, String>): List<Bind>? {
env["VKBRIDGE_SOCKET"]?.let { sock -> if (File(sock).exists()) return bridgeGpu(rootfs, root, env, sock) }
val lib = File(rootfs, "usr/lib")
val driver = File(lib, "libvulkan_freedreno.so")
if (!driver.isFile || !File("/dev/kgsl-3d0").exists()) return null
@@ -258,6 +259,32 @@ object BwrapSpawner {
return binds
}
/**
* The GPU through the Mali bridge (tools/vkbridge), for a sandbox started from a bridge
* session: the bridge ICD (it needs nothing but libc) and the server's socket, at the paths
* the session uses. Unlike Turnip on KGSL it can also present to KWin's shared-memory
* windows, so desktop apps get it too. The session's own VK_DRIVER_FILES points at the
* runtime's copy of the manifest, which the sandbox cannot see; it is replaced here.
*/
private fun bridgeGpu(rootfs: String, root: File, env: MutableMap<String, String>, socket: String): List<Bind>? {
val driver = File(rootfs, "usr/local/lib/vkbridge/libvulkan_droidbridge.so")
if (!driver.isFile) { Log.w(TAG, "gpu: vkbridge session but no bridge ICD in the runtime"); return null }
val binds = ArrayList<Bind>()
binds.add(Bind(driver.canonicalPath, "$GPU_DIR/libvulkan_droidbridge.so"))
val sockDir = File(socket).parent ?: return null
binds.add(Bind(sockDir, sockDir))
val icd = File(root.parentFile, "vkbridge_icd.json")
icd.writeText("{\"file_format_version\": \"1.0.0\", \"ICD\": {\"library_path\": \"$GPU_DIR/libvulkan_droidbridge.so\", \"api_version\": \"1.3.247\"}}\n")
binds.add(Bind(icd.path, "$GPU_DIR/vkbridge_icd.json"))
env["VK_DRIVER_FILES"] = "$GPU_DIR/vkbridge_icd.json"
env["VK_ICD_FILENAMES"] = "$GPU_DIR/vkbridge_icd.json"
if (!env.containsKey("MESA_LOADER_DRIVER_OVERRIDE") && !env.containsKey("GALLIUM_DRIVER")) {
env["MESA_LOADER_DRIVER_OVERRIDE"] = "zink"
env["GALLIUM_DRIVER"] = "zink"
}
return binds
}
/**
* What every program in the session preloads (SessionFiles writes /etc/ld.so.preload): the
* session shim - SysV shared memory for X11, the network calls Android refuses - and the
@@ -332,10 +332,40 @@ public final class LinuxRuntime {
* may open) stands in: it appears as a render node with the sysfs entries libdrm reads, and our
* 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";
/**
* The device that stands in for the GPU's render node: KGSL on an Adreno; with the Mali bridge
* on, Mali's own device - nothing inside opens it for rendering (the bridge does that on the
* Android side), but gamescope and libdrm need a render node to name before they offer
* linux-dmabuf, and the bridge ICD reports this one's numbers. Null when there is none.
*/
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;
return null;
}
/** "major:minor" of a device node, or null. */
public static String deviceNumbers(String path) {
try {
long dev = Os.stat(path).st_rdev;
long major = ((dev >> 8) & 0xfff) | ((dev >> 32) & ~0xfffL);
long minor = (dev & 0xff) | ((dev >> 12) & ~0xffL);
return major + ":" + minor;
} catch (ErrnoException e) {
return null;
}
}
private static void bindGpuNode(Context context, List<String> cmd) {
String standIn = gpuStandIn(context);
if (standIn == null) return;
boolean kgsl = standIn.equals(KGSL_DEVICE);
StructStat st;
try {
st = Os.stat(KGSL_DEVICE);
st = Os.stat(standIn);
} catch (ErrnoException e) {
return;
}
@@ -355,7 +385,8 @@ public final class LinuxRuntime {
Files.write(new File(drm, "dev").toPath(),
(major + ":" + minor + "\n").getBytes(StandardCharsets.UTF_8));
Files.write(new File(device, "uevent").toPath(),
"DRIVER=kgsl-3d0\nMODALIAS=platform:kgsl-3d0\n".getBytes(StandardCharsets.UTF_8));
(kgsl ? "DRIVER=kgsl-3d0\nMODALIAS=platform:kgsl-3d0\n" : "DRIVER=mali\nMODALIAS=platform:mali\n")
.getBytes(StandardCharsets.UTF_8));
File subsystem = new File(device, "subsystem");
if (!Files.isSymbolicLink(subsystem.toPath())) {
Os.symlink("/sys/bus/platform", subsystem.getPath());
@@ -363,7 +394,7 @@ public final class LinuxRuntime {
// What MangoHud names a GPU's driver by; msm_drm is how an Adreno's render node reads
// on a mainline kernel, and the driver it reads the load of (bindAdrenoStats).
File driver = new File(device, "driver");
if (!Files.isSymbolicLink(driver.toPath())) {
if (kgsl && !Files.isSymbolicLink(driver.toPath())) {
Os.symlink("/sys/bus/platform/drivers/msm_drm", driver.getPath());
}
} catch (IOException | ErrnoException e) {
@@ -371,7 +402,7 @@ public final class LinuxRuntime {
}
bind(cmd, new File(base, "sys").getPath() + ":/sys/dev/char");
bind(cmd, dri.getPath() + ":/dev/dri");
bind(cmd, KGSL_DEVICE + ":/dev/dri/" + node);
bind(cmd, standIn + ":/dev/dri/" + node);
bindDrmClass(base, cmd, node, major + ":" + minor);
}
@@ -143,6 +143,10 @@ object SessionFiles {
} + listOf("libthunkaudit.so", "libvulkan-thunk.so").map { "x86_64/$it" to "usr/local/lib/droiddeck-fex/x86_64/$it" }
val optional = (arrayOf(
"usr/local/bin/gamescope" to "usr/local/bin/gamescope",
// The Mali bridge's Linux side (tools/vkbridge): the ICD, its manifest and the self-test.
"usr/local/lib/vkbridge/libvulkan_droidbridge.so" to "usr/local/lib/vkbridge/libvulkan_droidbridge.so",
"usr/local/share/vkbridge/droidbridge_icd.json" to "usr/local/share/vkbridge/droidbridge_icd.json",
"usr/local/bin/droiddeck-vkbridge-smoke" to "usr/local/bin/droiddeck-vkbridge-smoke",
"usr/local/lib/droiddeck/uruntime" to "usr/local/lib/droiddeck/uruntime",
"usr/local/share/licenses/uruntime/LICENSE" to "usr/local/share/licenses/uruntime/LICENSE",
) + mangoapp + xclipse.map { it to it } + listOf("comet", "GalaxyCommunication.exe", "update-permissions.exe", "LICENSE", "version").map { "usr/local/lib/droiddeck-comet/$it" to "usr/local/lib/droiddeck-comet/$it" } + msitools.map { it to it } + fexPreloads).filter { (asset, _) ->
@@ -497,6 +497,18 @@ object SessionPrefs {
*/
fun zinkLazy(context: Context): Boolean = prefs(context).getBoolean("zinkLazy", true)
/**
* The Mali bridge (experimental): the session's Vulkan goes through the app's bridge server to
* the phone's own driver instead of Turnip (tools/vkbridge). Only offered, and only used, on a
* GPU without Adreno's KGSL; off by default everywhere.
*/
@JvmStatic
fun vkBridge(context: Context): Boolean = prefs(context).getBoolean("vkBridge", false)
fun setVkBridge(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("vkBridge", on).apply()
}
fun setZinkLazy(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("zinkLazy", on).apply()
}
@@ -372,6 +372,7 @@ class SessionService : Service() {
val fastPathAt = guest.size
val pulse = startAudio(guest, sessionDir)
startVkBridge(guest, sessionDir)
guest.add("BL_WIDTH=" + size.first)
guest.add("BL_HEIGHT=" + size.second)
@@ -629,10 +630,13 @@ class SessionService : Service() {
// import falls back to. One driver for every session: the driver's shader cache is keyed on
// its build, and with one per mode every emulator compiled its shaders twice.
val linuxDriverId = SessionPrefs.linuxDriver(this)
if (SystemVulkanDriver.usesDefault(linuxDriverId)) {
// Mali bridge (PR #517) on: the bridge ICD is the driver (startVkBridge). Otherwise the system
// PowerVR/Xclipse path (PR #570) or the imported/runtime Turnip, as before.
val bridge = com.droiddeck.launcher.core.DeviceSupport.vkBridge(this)
if (!bridge && SystemVulkanDriver.usesDefault(linuxDriverId)) {
SystemVulkanDriver.addEnvironment(this, guest)
}
LinuxVulkanDriver.resolveIcdPath(this, linuxDriverId)
(if (bridge) null else LinuxVulkanDriver.resolveIcdPath(this, linuxDriverId))
?.let { guest.add(LinuxVulkanDriver.ENV + "=" + 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
@@ -696,6 +700,35 @@ class SessionService : Service() {
.takeIf { it.isNotEmpty() }?.let { guest.add("BL_GAME_CPUS=$it") }
}
/**
* The Mali bridge (Setup's experimental switch, non-Adreno GPUs only): the server that runs the
* session's Vulkan calls on the phone's own driver, started before the guest. The session
* script points the Vulkan loader at the bridge ICD when it sees BL_VKBRIDGE and runs the
* bridge's self-test into the session log first; both sides log into the session folder.
*/
private fun startVkBridge(guest: MutableList<String>, sessionDir: File) {
if (!com.droiddeck.launcher.core.DeviceSupport.vkBridge(this)) return
// Under the files dir, which the session binds at its own path: one string for both sides.
val socket = File(filesDir, "vkbridge/server.sock")
val bridge = com.droiddeck.launcher.gpu.VkBridgeComponent(socket, File(sessionDir, "vkbridge-server.log"))
bridge.attach(this)
components.add(bridge)
com.droiddeck.launcher.gpu.ClockLogComponent(File(sessionDir, "vkbridge-clocks.log")).let {
it.attach(this)
components.add(it)
}
guest.add("BL_VKBRIDGE=1")
guest.add("VKBRIDGE_SOCKET=" + socket.path)
guest.add("VKBRIDGE_CLIENT_LOG=" + File(sessionDir, "vkbridge-client.log").path)
// The render node gamescope sees is Mali's device standing in (LinuxRuntime.bindGpuNode):
// the ICD reports its numbers, and the session shim answers PRIME calls on it as on KGSL.
LinuxRuntime.gpuStandIn(this)?.let { node ->
guest.add("BL_DRM_STANDIN=$node")
LinuxRuntime.deviceNumbers(node)?.let { guest.add("VKBRIDGE_DRM_RENDER=$it") }
}
Log.i(TAG, "vkbridge: on (${com.droiddeck.launcher.core.DeviceSupport.gpuName(this)}), socket $socket")
}
/** PulseAudio, and the DirectAudio relay when a path needs it; returns the daemon for suspend and resume. */
private fun startAudio(guest: MutableList<String>, sessionDir: File): PulseAudioComponent {
// PulseAudio always: the client is a native Linux program and has no other way to make a
@@ -130,6 +130,10 @@ class FrontEndState(
val oscMode: String = SessionPrefs.OSC_AUTO,
val controller: com.droiddeck.launcher.input.ControllerPrefs.Settings? = null,
val phantomProcessStatus: PhantomProcessStatus = PhantomProcessStatus.NOT_APPLICABLE,
/** The GPU is an Adreno (Turnip); otherwise Setup offers the experimental Mali bridge. */
val adreno: Boolean = true,
/** Setup's "Mali bridge (experimental)" (SessionPrefs.vkBridge). */
val vkBridge: Boolean = false,
val showPhantomGate: Boolean = false,
val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
val launcherFullscreen: Boolean = true,
@@ -187,6 +191,7 @@ class FrontEndActions(
val onInstallPackage: (String) -> Unit,
val onRemovePackage: (String) -> Unit,
val onRuntime: () -> Unit,
val onVkBridge: (Boolean) -> Unit = {},
val onFrameGenPick: (FrameGen.Mode) -> Unit,
val onImportLossless: () -> Unit,
val onProtons: () -> Unit,
@@ -212,9 +212,17 @@ internal fun SetupPanel(
when (gpu.support) {
com.droiddeck.launcher.gpu.GpuInfo.Support.TESTED -> stringResource(R.string.setup_gpu_detail, gpu.displayName(ctx), gpuName)
com.droiddeck.launcher.gpu.GpuInfo.Support.UNTESTED -> stringResource(R.string.setup_gpu_untested_detail, gpu.displayName(ctx), gpu.supportText(ctx).replaceFirstChar { it.lowercase() })
else -> stringResource(R.string.setup_gpu_unsupported_detail, gpuName)
else -> if (s.vkBridge) stringResource(R.string.setup_gpu_bridge_detail, gpuName)
else stringResource(R.string.setup_gpu_unsupported_detail, gpuName)
},
divider = divider,
// Not an Adreno: the experimental Vulkan bridge is the one way to draw.
action = if (s.adreno) null else { {
SecondaryButton(
stringResource(if (s.vkBridge) R.string.setup_gpu_bridge_on else R.string.setup_gpu_bridge_off),
enabled = !s.sessionRunning, compact = true, onClick = { a.onVkBridge(!s.vkBridge) },
)
} },
)
}
val runtimeCheck: @Composable (Boolean) -> Unit = { divider ->