Mali bridge: Setup's "Safe mode" switch, on by default

A second row under the GPU check, shown only when the bridge is on: "Safe mode" keeps the
bridge's proven workarounds wherever its startup probe has not verified this GPU and driver;
off is performance mode, native paths wherever the probe passed. It reaches the server as
<cache dir>/mode ("safe" or "performance", written atomically before the server starts or is
reused, so the in-app server's JNI start stays as it is) and the guest as VKBRIDGE_MODE, which
/root/.vkbridge-env can still override. A server without modes ignores the file.
This commit is contained in:
Ahmad Sayed Alsayed Ebrahim authored and maxjivi05 committed 2026-10-26 13:55:31 -04:00
1 parent e04eb84090
commit 5b35ace098
7 files changed
+49 -3

No files matched your search

@@ -149,6 +149,7 @@ class FrontEndActivity : ComponentActivity() {
private var tuSysmem by mutableStateOf(false)
private var zinkLazy by mutableStateOf(false)
private var vkBridge by mutableStateOf(false)
private var vkBridgeSafe by mutableStateOf(true)
private val adrenoGpu by lazy { com.droiddeck.launcher.core.DeviceSupport.adreno() }
private var noXalia by mutableStateOf(true)
private var fastSync by mutableStateOf(false)
@@ -811,7 +812,7 @@ class FrontEndActivity : ComponentActivity() {
FrontEndScreen(
FrontEndState(
installed = installed, ready = ready, available = available?.version, removalPending = removalPending, runtimeActionsBlocked = runtimeChangesBlocked(),
vkBridge = vkBridge, adreno = adrenoGpu,
vkBridge = vkBridge, vkBridgeSafe = vkBridgeSafe, adreno = adrenoGpu,
shortcutPicker = shortcutPicker,
shortcutLibraryScanning = shortcutLibraryScanning,
gameSyncFolder = gameSyncFolder,
@@ -953,6 +954,7 @@ class FrontEndActivity : ComponentActivity() {
onRemovePackage = { id -> removePackage(id) },
onRuntime = { onRuntimeButton() },
onVkBridge = { on -> SessionPrefs.setVkBridge(this, on); vkBridge = on },
onVkBridgeSafe = { on -> SessionPrefs.setVkBridgeSafe(this, on); vkBridgeSafe = on },
onFrameGenPick = { mode ->
FrameGen.set(this, mode)
frameGenLabel = FrameGen.label(this)
@@ -2077,6 +2079,7 @@ class FrontEndActivity : ComponentActivity() {
tuSysmem = SessionPrefs.tuSysmem(this)
zinkLazy = SessionPrefs.zinkLazy(this)
vkBridge = SessionPrefs.vkBridge(this)
vkBridgeSafe = SessionPrefs.vkBridgeSafe(this)
noXalia = SessionPrefs.noXalia(this)
fastSync = SessionPrefs.fastSync(this)
syncFallback = SessionPrefs.syncFallback(this)
@@ -20,6 +20,7 @@ class VkBridgeComponent(private val socket: File, private val logFile: File) : S
}
socket.parentFile?.mkdirs()
val cacheDir = cacheDir(app())
writeMode(cacheDir, com.droiddeck.launcher.session.SessionPrefs.vkBridgeMode(app()))
if (VkBridgeNative.start(app(), socket, logFile, cacheDir)) {
Log.i(TAG, "server ready in the app's process at $socket")
return
@@ -56,6 +57,7 @@ class VkBridgeComponent(private val socket: File, private val logFile: File) : S
companion object {
private const val TAG = "VkBridge"
private const val CACHE_DIR = "vkbridge-pipelines"
private const val MODE_FILE = "mode"
fun cacheDir(context: Context): File {
val dir = File(context.filesDir, CACHE_DIR)
@@ -65,6 +67,17 @@ class VkBridgeComponent(private val socket: File, private val logFile: File) : S
return dir
}
fun writeMode(dir: File, mode: String) {
val file = File(dir, MODE_FILE)
if (runCatching { file.readText().trim() }.getOrNull() == mode) return
val tmp = File(dir, "$MODE_FILE.tmp")
runCatching {
tmp.writeText(mode + "\n")
if (!tmp.renameTo(file)) error("rename failed")
Log.i(TAG, "bridge mode: $mode")
}.onFailure { Log.w(TAG, "could not write $file: $it"); tmp.delete() }
}
private fun migrate(old: File, dir: File) {
val moved = if (!dir.exists()) old.renameTo(dir) else false
if (!moved) {
@@ -603,6 +603,16 @@ object SessionPrefs {
prefs(context).edit().putBoolean("vkBridge", on).apply()
}
@JvmStatic
fun vkBridgeSafe(context: Context): Boolean = prefs(context).getBoolean("vkBridgeSafe", true)
fun setVkBridgeSafe(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("vkBridgeSafe", on).apply()
}
@JvmStatic
fun vkBridgeMode(context: Context): String = if (vkBridgeSafe(context)) "safe" else "performance"
fun setZinkLazy(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("zinkLazy", on).apply()
}
@@ -828,11 +828,12 @@ class SessionService : Service() {
guest.add("BL_VKBRIDGE=1")
guest.add("VKBRIDGE_SOCKET=" + socket.path)
guest.add("VKBRIDGE_CLIENT_LOG=" + File(sessionDir, "vkbridge-client.log").path)
guest.add("VKBRIDGE_MODE=" + SessionPrefs.vkBridgeMode(this))
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")
Log.i(TAG, "vkbridge: on (${com.droiddeck.launcher.core.DeviceSupport.gpuName(this)}, ${SessionPrefs.vkBridgeMode(this)} mode), socket $socket")
}
private fun startAudio(guest: MutableList<String>, sessionDir: File, directAudioPack: Boolean): PulseAudioComponent {
@@ -139,6 +139,7 @@ class FrontEndState(
val phantomProcessStatus: PhantomProcessStatus = PhantomProcessStatus.NOT_APPLICABLE,
val adreno: Boolean = true,
val vkBridge: Boolean = false,
val vkBridgeSafe: Boolean = true,
val showPhantomGate: Boolean = false,
val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
val launcherOrientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER,
@@ -196,6 +197,7 @@ class FrontEndActions(
val onRemovePackage: (String) -> Unit,
val onRuntime: () -> Unit,
val onVkBridge: (Boolean) -> Unit = {},
val onVkBridgeSafe: (Boolean) -> Unit = {},
val onFrameGenPick: (FrameGen.Mode) -> Unit,
val onImportLossless: () -> Unit,
val onProtons: () -> Unit,
@@ -238,7 +238,7 @@ internal fun SetupPanel(
else -> if (s.vkBridge) stringResource(R.string.setup_gpu_bridge_detail, gpuName)
else stringResource(R.string.setup_gpu_unsupported_detail, gpuName)
},
divider = divider,
divider = divider || (!s.adreno && s.vkBridge),
action = if (s.adreno) null else { {
SecondaryButton(
stringResource(if (s.vkBridge) R.string.setup_gpu_bridge_on else R.string.setup_gpu_bridge_off),
@@ -246,6 +246,18 @@ internal fun SetupPanel(
)
} },
)
if (!s.adreno && s.vkBridge) CheckRow(
CheckState.OK,
stringResource(R.string.setup_bridge_safe),
stringResource(if (s.vkBridgeSafe) R.string.setup_bridge_safe_on_detail else R.string.setup_bridge_safe_off_detail),
divider = divider,
action = {
SecondaryButton(
stringResource(if (s.vkBridgeSafe) R.string.setup_bridge_safe_on else R.string.setup_bridge_safe_off),
enabled = !s.sessionRunning, compact = true, onClick = { a.onVkBridgeSafe(!s.vkBridgeSafe) },
)
},
)
}
val runtimeCheck: @Composable (Boolean) -> Unit = { divider ->
CheckRow(