From 57666965556e79bf3572a5c299ede4f21de5c000 Mon Sep 17 00:00:00 2001 From: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> Date: Tue, 3 Nov 2026 22:41:58 +0900 Subject: [PATCH 01/85] gamescope: ship p20 so the EA sign-in stays above the launcher splash Patch 0126 (#2037) is in the source tree, but the app still stages the p19 binary pinned here, built on Oct 29 before the patch existed. A fresh install keeps drawing the EA Steam Launcher splash over the EA sign-in. p20 is the gamescope-patched archive from the main build of 951270bc (Droid-Deck/DroidDeck actions run 41637838020): patches 0002-0126 applied, gamescope tests Ok 2 / Fail 0. --- tools/gamescope/release.env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/gamescope/release.env b/tools/gamescope/release.env index a73f1985b8..753e3e0781 100644 --- a/tools/gamescope/release.env +++ b/tools/gamescope/release.env @@ -1,3 +1,3 @@ GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components -GAMESCOPE_TAG=gamescope-3.16.29-p19 -GAMESCOPE_SHA256=e7333c6a2b95708b199c2c5bd0973e3f0e711e2dc746950cc648c2515ea2926b +GAMESCOPE_TAG=gamescope-3.16.29-p20 +GAMESCOPE_SHA256=4537fa58b042f84e605123c4778ee7089442591cd3bfe0648ad96e113ef6117d From d62f017bcec39d2962277e435c5626ffd97c18c3 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:05:56 -0500 Subject: [PATCH 02/85] Add session log management to setup diagnostics (#2099) * feat: manage session logs in setup * fix: address session log review feedback * fix: honor device date and time settings --- .../droiddeck/launcher/FrontEndActivity.kt | 43 +++++++++++++ .../launcher/session/SessionLogShare.kt | 27 +++++++- .../droiddeck/launcher/ui/FrontEndScreen.kt | 3 + .../droiddeck/launcher/ui/FrontEndSetup.kt | 63 +++++++++++++++++-- app/src/main/res/values/strings.xml | 13 ++++ 5 files changed, 144 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 22301e220b..f163bf6401 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -209,6 +209,7 @@ class FrontEndActivity : ComponentActivity() { private var wifiDiscoveryBlocked by mutableStateOf(false) private var integrationState by mutableStateOf(SteamIntegration.State()) private var integrationFocus by mutableStateOf(null) + private var pendingSessionLogExport: File? = null private val wifiLocationReceiver = object : android.content.BroadcastReceiver() { override fun onReceive(context: android.content.Context?, intent: Intent?) { refreshWifiDiscovery() @@ -267,6 +268,26 @@ class FrontEndActivity : ComponentActivity() { val then = onSavePicked.also { onSavePicked = null } ?: return@registerForActivityResult if (r.resultCode == RESULT_OK) InAppFilePicker.pickedFile(r.data)?.let(then) } + private val pickSessionLogExport = registerForActivityResult(ActivityResultContracts.CreateDocument("application/zip")) { uri -> + val folder = pendingSessionLogExport.also { pendingSessionLogExport = null } ?: return@registerForActivityResult + if (uri != null) { + SessionLogShare.prepare(this, { folder }) { zip -> + if (zip == null) { + android.widget.Toast.makeText(this, R.string.setup_log_export_failed, android.widget.Toast.LENGTH_LONG).show() + } else Thread({ + val saved = runCatching { + contentResolver.openOutputStream(uri)?.use { output -> zip.inputStream().buffered().use { it.copyTo(output) } } + ?: error("Could not open destination") + }.isSuccess + ui.post { + android.widget.Toast.makeText(this, + if (saved) R.string.setup_log_export_saved else R.string.setup_log_export_failed, + android.widget.Toast.LENGTH_LONG).show() + } + }, "save-session-logs").start() + } + } + } private fun refreshWifiDiscovery() { wifiDiscoveryPermission = WifiDiscovery.permissionGranted(this) @@ -1027,6 +1048,7 @@ class FrontEndActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + pendingSessionLogExport = savedInstanceState?.getString(KEY_PENDING_SESSION_LOG_EXPORT)?.let(::File) homeChoiceOpen = savedInstanceState?.getBoolean(STATE_HOME_CHOICE_OPEN) == true gameSpaceOffered = savedInstanceState?.getBoolean(STATE_GAME_SPACE_OFFERED) == true if (savedInstanceState == null) readIntegrationIntent(intent) @@ -1299,6 +1321,25 @@ class FrontEndActivity : ComponentActivity() { else startActivity(SessionLogShare.shareIntent(this, zip)) } }, + onShareSessionLog = { folder -> + SessionLogShare.prepare(this, { folder }) { zip -> + if (zip == null) android.widget.Toast.makeText(this, R.string.main_no_logs_yet, android.widget.Toast.LENGTH_LONG).show() + else startActivity(SessionLogShare.shareIntent(this, zip)) + } + }, + onSaveSessionLog = { folder -> + pendingSessionLogExport = folder + pickSessionLogExport.launch("DroidDeck-${folder.name}.zip") + }, + onDeleteSessionLog = { folder, done -> + Thread({ + val deleted = runCatching { SessionLogShare.deleteSession(this, folder) }.getOrDefault(false) + ui.post { + if (!deleted) android.widget.Toast.makeText(this, R.string.setup_log_delete_failed, android.widget.Toast.LENGTH_SHORT).show() + done() + } + }, "delete-session-logs").start() + }, onClearLogs = { Thread({ val cleared = runCatching { SessionArtifacts.clearAll(this) }.getOrDefault(0) @@ -1804,6 +1845,7 @@ class FrontEndActivity : ComponentActivity() { super.onSaveInstanceState(outState) outState.putBoolean(STATE_HOME_CHOICE_OPEN, homeChoiceOpen) outState.putBoolean(STATE_GAME_SPACE_OFFERED, gameSpaceOffered) + pendingSessionLogExport?.let { outState.putString(KEY_PENDING_SESSION_LOG_EXPORT, it.absolutePath) } if (slowUsbNever) SessionPrefs.setSlowUsbWarningOff(this) saveCompatLaunch(outState) pendingSwitch?.let { outState.putParcelable(KEY_PENDING_SWITCH, it) } @@ -2875,6 +2917,7 @@ class FrontEndActivity : ComponentActivity() { companion object { private const val STATE_HOME_CHOICE_OPEN = "home_choice_open" + private const val KEY_PENDING_SESSION_LOG_EXPORT = "pending_session_log_export" private const val STATE_GAME_SPACE_OFFERED = "game_space_offered" private const val TAG = "MainActivity" private const val MEDIA_SETTLE_MS = 1500L diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt index 1855503700..4cf737c04c 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt @@ -19,6 +19,8 @@ import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream object SessionLogShare { + data class Details(val sizeBytes: Long, val modifiedAt: Long) + private val main = Handler(Looper.getMainLooper()) var progress by mutableStateOf(null) @@ -35,7 +37,30 @@ object SessionLogShare { }, "share-logs").start() } - fun latest(context: Context): File? = SessionPaths.sessionFolders(context).lastOrNull() + fun latest(context: Context): File? = sessions(context).lastOrNull() + + fun sessions(context: Context): List { + val current = SessionPaths.current()?.takeIf { it.isDirectory && SessionPaths.isSessionFolder(it) } + return (SessionPaths.sessionFolders(context) + listOfNotNull(current)) + .distinctBy { it.absoluteFile.toPath().normalize().toString() } + .sortedWith(SessionPaths.chronological) + } + + fun details(folder: File): Details { + var size = 0L + var modified = folder.lastModified() + folder.walkTopDown().filter { it.isFile }.forEach { file -> + size += file.length() + modified = maxOf(modified, file.lastModified()) + } + return Details(size, modified) + } + + fun deleteSession(context: Context, folder: File): Boolean { + if (runCatching { SessionPaths.current()?.canonicalFile == folder.canonicalFile }.getOrDefault(false)) return false + val knownSession = runCatching { folder.canonicalFile }.getOrNull() in sessions(context).mapNotNull { runCatching { it.canonicalFile }.getOrNull() } + return knownSession && folder.isDirectory && folder.deleteRecursively() + } fun zipFolder(context: Context, folder: File, onProgress: ((Float) -> Unit)? = null): File? { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 9bf266b834..30acb4d85d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -232,6 +232,9 @@ class FrontEndActions( val onMemoryHud: (String) -> Unit = {}, val onBackgroundAppLimit: (Int) -> Unit = {}, val onShareLogs: () -> Unit = {}, + val onShareSessionLog: (File) -> Unit = {}, + val onSaveSessionLog: (File) -> Unit = {}, + val onDeleteSessionLog: (File, () -> Unit) -> Unit = { _, done -> done() }, val onClearLogs: () -> Unit = {}, val onResetSettings: () -> Unit = {}, val onOffline: () -> Unit, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index f7969fe6c4..795b1b1c1c 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -193,11 +193,13 @@ internal fun SetupPanel( ) val tabs = listOf(stringResource(R.string.setup_tab_overview), stringResource(R.string.setup_tab_controller), stringResource(R.string.setup_tab_launcher), stringResource(R.string.setup_tab_storage), stringResource(R.string.setup_tab_sync), stringResource(R.string.setup_tab_diagnostics), stringResource(R.string.setup_tab_glasses)) var tab by rememberSaveable { mutableStateOf(if (SetupTabs.openLauncher) LAUNCHER_TAB else 0) } + var logsRefresh by remember { mutableStateOf(0) } + var deleteSessionLogs by remember { mutableStateOf(null) } SetupTabs.openLauncher = false if (SetupTabs.openOverview) { tab = 0; SetupTabs.openOverview = false } val chipFocus = remember { List(tabs.size) { FocusRequester() } } var tabTurned by remember { mutableStateOf(false) } - val pick: (Int) -> Unit = { i -> tab = i; tabTurned = true } + val pick: (Int) -> Unit = { i -> tab = i; tabTurned = true; if (i == 5) logsRefresh++ } val inputModeManager = LocalInputModeManager.current LaunchedEffect(com.droiddeck.launcher.storage.StorageState.openRequests) { if (com.droiddeck.launcher.storage.StorageState.openPending) { @@ -382,11 +384,12 @@ internal fun SetupPanel( val shownChecks = all.filterIndexed { i, _ -> checks[i] } shownChecks.forEachIndexed { i, check -> check(i < shownChecks.lastIndex) } } - if (passing < checks.size) { + val needsAttention = all.filterIndexed { i, _ -> !checks[i] && i != 1 } + if (needsAttention.isNotEmpty()) { SectionTitle(stringResource(R.string.setup_needs_you), null) Column(verticalArrangement = Arrangement.spacedBy(10.dp)) { - all.forEachIndexed { i, check -> - if (!checks[i]) Column(Modifier.fillMaxWidth().clip(Shape14).background(colors.surface).border(1.dp, AttentionAmber.copy(alpha = 0.5f), Shape14)) { check(false) } + needsAttention.forEach { check -> + Column(Modifier.fillMaxWidth().clip(Shape14).background(colors.surface).border(1.dp, AttentionAmber.copy(alpha = 0.5f), Shape14)) { check(false) } } } } @@ -553,6 +556,44 @@ internal fun SetupPanel( ToggleRow(host, "agent-commands", stringResource(R.string.setup_agent_commands), null, s.agentCommands) { a.onAgentCommands() } ActionRow(stringResource(R.string.setup_latest_logs), stringResource(R.string.drawer_logs_hint), stringResource(R.string.drawer_share_logs), a.onShareLogs, progress = com.droiddeck.launcher.session.SessionLogShare.progress) + androidx.compose.material3.HorizontalDivider() + Text(stringResource(R.string.setup_log_sessions), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, + color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp)) + Text(stringResource(R.string.setup_log_export_hint), fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(start = 14.dp, end = 14.dp, bottom = 8.dp)) + val sessionLogs = remember(ctx, logsRefresh) { com.droiddeck.launcher.session.SessionLogShare.sessions(ctx).asReversed() } + if (sessionLogs.isEmpty()) { + Text(stringResource(R.string.setup_log_empty), fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp)) + } + sessionLogs.forEach { folder -> + val active = folder == com.droiddeck.launcher.session.SessionPaths.current() + var details by remember(folder) { mutableStateOf(null) } + LaunchedEffect(folder, logsRefresh) { + details = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { + com.droiddeck.launcher.session.SessionLogShare.details(folder) + } + } + Column(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 8.dp)) { + Text(folder.name, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground, + maxLines = 1, overflow = TextOverflow.Ellipsis) + details?.let { detail -> + Text( + stringResource(R.string.setup_log_size_date, + android.text.format.Formatter.formatShortFileSize(ctx, detail.sizeBytes), + "${android.text.format.DateFormat.getDateFormat(ctx).format(java.util.Date(detail.modifiedAt))} ${android.text.format.DateFormat.getTimeFormat(ctx).format(java.util.Date(detail.modifiedAt))}"), + fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + if (active) Text(stringResource(R.string.setup_log_current), fontSize = 12.sp, color = MaterialTheme.colorScheme.primary) + Row(Modifier.fillMaxWidth().padding(top = 6.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) { + SecondaryButton(stringResource(R.string.setup_log_share), enabled = com.droiddeck.launcher.session.SessionLogShare.progress == null, compact = true, modifier = Modifier.weight(1f)) { a.onShareSessionLog(folder) } + SecondaryButton(stringResource(R.string.setup_log_save), enabled = com.droiddeck.launcher.session.SessionLogShare.progress == null, compact = true, modifier = Modifier.weight(1f)) { a.onSaveSessionLog(folder) } + SecondaryButton(stringResource(R.string.setup_log_delete), compact = true, enabled = !active, modifier = Modifier.weight(1f)) { deleteSessionLogs = folder } + } + } + androidx.compose.material3.HorizontalDivider() + } ActionRow(stringResource(R.string.setup_saved_logs), stringResource(R.string.setup_saved_logs_hint, com.droiddeck.launcher.session.SessionPaths.KEEP_SESSIONS), stringResource(R.string.setup_clear_logs), a.onClearLogs) ActionRow(stringResource(R.string.setup_reset_settings), stringResource(R.string.setup_reset_settings_hint), stringResource(R.string.setup_reset_settings_button), a.onResetSettings) @@ -595,6 +636,20 @@ internal fun SetupPanel( } } } + deleteSessionLogs?.let { folder -> + androidx.compose.material3.AlertDialog( + onDismissRequest = { deleteSessionLogs = null }, + title = { Text(stringResource(R.string.setup_log_delete_title)) }, + text = { Text(stringResource(R.string.setup_log_delete_message, folder.name)) }, + confirmButton = { + androidx.compose.material3.TextButton(onClick = { + deleteSessionLogs = null + a.onDeleteSessionLog(folder) { logsRefresh++ } + }) { Text(stringResource(R.string.setup_log_delete)) } + }, + dismissButton = { androidx.compose.material3.TextButton(onClick = { deleteSessionLogs = null }) { Text(stringResource(R.string.common_cancel)) } }, + ) + } } @Composable diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 21231e223b..83b8208209 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -919,6 +919,19 @@ Saved session logs Keeps the newest %1$d Clear logs + Available session logs + No saved session logs yet. + Shared and saved ZIPs include the selected session plus related Steam, store, tool, and Battle.net diagnostics. + %1$s · %2$s + Current session + Share + Save to device + Delete + Delete session logs? + Delete %1$s? This cannot be undone. + Session logs saved. + Could not save session logs. + Could not delete session logs. Reset all settings Puts every setting back to its default Reset From ab92033b90f3ce8dc6f99812337ad8e92c8333cb Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Wed, 4 Nov 2026 17:47:00 -0500 Subject: [PATCH 03/85] fix(desktop): Steam's own header moves and resizes its windows (#2097) * fix(desktop): Steam's own header moves and resizes its windows Steam never asks KWin to move or resize its windows, and its maximize button can only maximize. Each normal Steam window now reports presses on its header and edges, and KWin handles them natively. No extra title bar is added and other apps are unchanged. * fix(desktop): drag regions cover the elements inside them * fix(desktop): find Steam's drag regions by position The Friends window's drag region ignores pointer events, so a hit test never finds it. The check now runs once a press moves, so plain clicks cost nothing. --- .../usr/local/bin/droiddeck-steam-compat | 174 ++++++++++++++++++ tools/tests/test_steam_window_controls.py | 116 ++++++++++++ 2 files changed, 290 insertions(+) create mode 100644 tools/tests/test_steam_window_controls.py diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat index 0b0b1b0560..97e2b8525b 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat @@ -317,6 +317,74 @@ FRAME_LIMIT_JS = r""" return "installed"; })() """ +WINDOW_BINDING = "droiddeckWindowAction" +WINDOW_TARGET = "createflags=18" +WINDOW_MOVES = {"nw": 0, "n": 1, "ne": 2, "e": 3, "se": 4, "s": 5, "sw": 6, "w": 7, "move": 8} +WINDOW_JS = r""" +(() => { + if (window.__droiddeckWindow) return "present"; + const EDGE = 5, CORNER = 10, THRESHOLD = 3; + const CURSORS = { n: "ns-resize", s: "ns-resize", e: "ew-resize", w: "ew-resize", + ne: "nesw-resize", sw: "nesw-resize", nw: "nwse-resize", se: "nwse-resize" }; + const send = action => window.droiddeckWindowAction(action); + const filled = () => innerWidth >= screen.availWidth && innerHeight >= screen.availHeight - 60; + const side = e => { + if (filled()) return ""; + const right = innerWidth - e.clientX, bottom = innerHeight - e.clientY; + const near = (a, b) => a < EDGE || (a < CORNER && b < CORNER); + const across = Math.min(e.clientX, right), along = Math.min(e.clientY, bottom); + const v = near(e.clientY, across) ? "n" : near(bottom, across) ? "s" : ""; + const h = near(e.clientX, along) ? "w" : near(right, along) ? "e" : ""; + return v + h; + }; + const dragging = (x, y) => { + for (const node of document.elementsFromPoint(x, y)) { + const region = getComputedStyle(node).webkitAppRegion; + if (region === "drag") return true; + if (region === "no-drag") return false; + } + return [...document.querySelectorAll("*")].some(node => { + if (getComputedStyle(node).webkitAppRegion !== "drag") return false; + const box = node.getBoundingClientRect(); + return x >= box.left && x < box.right && y >= box.top && y < box.bottom; + }); + }; + const style = document.createElement("style"); + document.documentElement.append(style); + let press = null, shown = ""; + addEventListener("pointermove", e => { + if (press) { + if (Math.hypot(e.clientX - press.x, e.clientY - press.y) >= THRESHOLD) { + const hit = dragging(press.x, press.y); + press = null; + if (hit) send("move"); + } + return; + } + const cursor = e.buttons ? shown : side(e); + if (cursor !== shown) { + shown = cursor; + style.textContent = cursor ? `* { cursor: ${CURSORS[cursor]} !important; }` : ""; + } + }, true); + addEventListener("pointerdown", e => { + if (e.button !== 0) return; + const edge = side(e); + if (edge) { + e.stopPropagation(); + e.preventDefault(); + send(edge); + } else { + press = { x: e.clientX, y: e.clientY }; + } + }, true); + addEventListener("pointerup", () => { press = null; }, true); + addEventListener("dblclick", e => { if (dragging(e.clientX, e.clientY) && !side(e)) send("maximize"); }, true); + SteamClient.Window.ToggleMaximize = () => send("maximize"); + window.__droiddeckWindow = true; + return "installed"; +})() +""" FILE_BINDING = "droiddeckOpenFileDialog" FILE_JS = r""" (() => { @@ -739,6 +807,71 @@ class Watcher: return any(n in wanted or n.startswith("appmanifest_") for n in names) +class XMessage(ctypes.Structure): + _fields_ = [("type", ctypes.c_int), ("serial", ctypes.c_ulong), ("send_event", ctypes.c_int), + ("display", ctypes.c_void_p), ("window", ctypes.c_ulong), ("message_type", ctypes.c_ulong), + ("format", ctypes.c_int), ("data", ctypes.c_long * 5), ("pad", ctypes.c_long * 20)] + + +X_ERRORS = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p)(lambda display, error: 0) + + +def window_action(action): + if action != "maximize" and action not in WINDOW_MOVES: + return False + x11 = ctypes.CDLL("libX11.so.6") + x11.XOpenDisplay.restype = ctypes.c_void_p + x11.XOpenDisplay.argtypes = [ctypes.c_char_p] + x11.XDefaultRootWindow.restype = ctypes.c_ulong + x11.XDefaultRootWindow.argtypes = [ctypes.c_void_p] + x11.XInternAtom.restype = ctypes.c_ulong + x11.XInternAtom.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int] + x11.XGetWindowProperty.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_long, ctypes.c_long, + ctypes.c_int, ctypes.c_ulong] + [ctypes.c_void_p] * 5 + x11.XQueryPointer.argtypes = [ctypes.c_void_p, ctypes.c_ulong] + [ctypes.c_void_p] * 7 + x11.XSendEvent.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_int, ctypes.c_long, ctypes.c_void_p] + x11.XFree.argtypes = [ctypes.c_void_p] + x11.XFlush.argtypes = [ctypes.c_void_p] + x11.XCloseDisplay.argtypes = [ctypes.c_void_p] + x11.XSetErrorHandler(X_ERRORS) + display = x11.XOpenDisplay(None) + if not display: + return False + try: + root = x11.XDefaultRootWindow(display) + atom = lambda name: x11.XInternAtom(display, name, 0) + kind, width, count, after = ctypes.c_ulong(), ctypes.c_int(), ctypes.c_ulong(), ctypes.c_ulong() + data = ctypes.c_void_p() + if x11.XGetWindowProperty(display, root, atom(b"_NET_ACTIVE_WINDOW"), 0, 1, 0, 33, ctypes.byref(kind), + ctypes.byref(width), ctypes.byref(count), ctypes.byref(after), + ctypes.byref(data)) != 0 or not data.value: + return False + window = ctypes.cast(data, ctypes.POINTER(ctypes.c_ulong))[0] if count.value else 0 + x11.XFree(data) + if not window: + return False + if action == "maximize": + kind_name = b"_NET_WM_STATE" + values = [2, atom(b"_NET_WM_STATE_MAXIMIZED_VERT"), atom(b"_NET_WM_STATE_MAXIMIZED_HORZ"), 1, 0] + else: + ignored = ctypes.c_ulong() + x, y, inner, mask = ctypes.c_int(), ctypes.c_int(), ctypes.c_int(), ctypes.c_uint() + if not x11.XQueryPointer(display, root, ctypes.byref(ignored), ctypes.byref(ignored), ctypes.byref(x), + ctypes.byref(y), ctypes.byref(inner), ctypes.byref(inner), ctypes.byref(mask)): + return False + if not mask.value & 0x100: + return False + kind_name = b"_NET_WM_MOVERESIZE" + values = [x.value, y.value, WINDOW_MOVES[action], 1, 1] + message = XMessage(type=33, window=window, message_type=atom(kind_name), format=32) + message.data[:] = values + sent = x11.XSendEvent(display, root, 0, (1 << 19) | (1 << 20), ctypes.byref(message)) + x11.XFlush(display) + return bool(sent) + finally: + x11.XCloseDisplay(display) + + class Helper: def __init__(self, steam_root, port, steamos=False, files_only=False): self.steam_root = steam_root @@ -757,6 +890,8 @@ class Helper: self.controls_installed = False self.frame_limit_state = None self.frame_limit_retry = 0 + self.windows = {} + self.windows_retry = 0 def sync_controls(self): try: @@ -780,6 +915,41 @@ class Helper: except (OSError, ValueError, TypeError): pass + def sync_windows(self): + if os.environ.get("XDG_CURRENT_DESKTOP") != "KDE": + return + if time.monotonic() >= self.windows_retry: + self.windows_retry = time.monotonic() + 2 + try: + targets = http_get(self.port, "/json/list") + except (OSError, ValueError): + targets = [] + seen = set() + for target in targets: + url = target.get("webSocketDebuggerUrl") + if WINDOW_TARGET not in target.get("url", "").split("&")[0] or not url: + continue + seen.add(target.get("id")) + try: + page = self.windows.get(target.get("id")) + if page is None: + page = Page(self.port, "/" + url.split("/", 3)[3]) + page.call("Runtime.addBinding", {"name": WINDOW_BINDING}, timeout=5) + self.windows[target.get("id")] = page + page.evaluate(WINDOW_JS, timeout=5) + except (Closed, OSError, RuntimeError, ValueError) as e: + say("window controls: %s" % e) + self.windows.pop(target.get("id"), None) + for ident in set(self.windows) - seen: + del self.windows[ident] + for ident, page in list(self.windows.items()): + try: + for event in page.drain(): + if called(event, WINDOW_BINDING): + window_action(event.get("params", {}).get("payload")) + except (Closed, OSError, ValueError): + del self.windows[ident] + def sync_frame_limit(self): if self.frame_limit_state in ("installed", "present") or time.monotonic() < self.frame_limit_retry: return @@ -1025,7 +1195,9 @@ class Helper: say("attached to the client on port %d for its file dialogs" % self.port) while True: self.sync_controls() + self.sync_windows() sources = [self.page.ws] + ([self.chooser[1].stdout] if self.chooser is not None else []) + sources += [page.ws for page in self.windows.values()] queued = self.page.ws.pending() or bool(self.page.events) ready = [self.page.ws] if queued else select.select(sources, [], [], 0.25)[0] if self.chooser is not None and self.chooser[1].stdout in ready: @@ -1044,7 +1216,9 @@ class Helper: while True: self.sync_controls() self.sync_frame_limit() + self.sync_windows() sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else []) + sources += [page.ws for page in self.windows.values()] if self.chooser is not None: sources.append(self.chooser[1].stdout) queued = self.page.ws.pending() or bool(self.page.events) diff --git a/tools/tests/test_steam_window_controls.py b/tools/tests/test_steam_window_controls.py new file mode 100644 index 0000000000..bb184cb659 --- /dev/null +++ b/tools/tests/test_steam_window_controls.py @@ -0,0 +1,116 @@ +import json +from pathlib import Path +import runpy +import shutil +import subprocess +import unittest + +BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin" +LIVE = runpy.run_path(str(BIN / "droiddeck-steam-compat")) + +HARNESS = r""" +const assert = require('assert'); +const listeners = {}, sent = []; +globalThis.window = globalThis; +globalThis.innerWidth = 1000; +globalThis.innerHeight = 600; +globalThis.screen = { availWidth: 1280, availHeight: 670 }; +globalThis.addEventListener = (type, callback) => { listeners[type] = callback; }; +let stack = [], layers = []; +globalThis.document = { createElement: () => ({}), documentElement: { append() {} }, elementsFromPoint: () => stack, + querySelectorAll: () => layers }; +globalThis.getComputedStyle = target => ({ webkitAppRegion: target.region }); +globalThis.droiddeckWindowAction = action => sent.push(action); +globalThis.SteamClient = { Window: { ToggleMaximize() { throw new Error('native'); } } }; +assert.strictEqual(eval(SCRIPT), 'installed'); +assert.strictEqual(eval(SCRIPT), 'present'); +const event = (x, y, region = 'none', extra = {}) => { + stack = [].concat(region).map(name => ({ region: name })); + return { clientX: x, clientY: y, button: 0, buttons: 0, + stopPropagation() { this.stopped = true; }, preventDefault() {}, ...extra }; +}; +const take = () => sent.splice(0); + +listeners.pointerdown(event(500, 300)); +listeners.pointermove(event(520, 300, 'none', { buttons: 1 })); +assert.deepStrictEqual(take(), []); + +listeners.pointerdown(event(500, 12, 'drag')); +listeners.pointerup(event(500, 12, 'drag')); +listeners.pointermove(event(520, 12, 'drag')); +assert.deepStrictEqual(take(), []); + +listeners.pointerdown(event(500, 12, 'drag')); +listeners.pointermove(event(501, 12, 'drag', { buttons: 1 })); +assert.deepStrictEqual(take(), []); +listeners.pointermove(event(510, 12, 'drag', { buttons: 1 })); +assert.deepStrictEqual(take(), ['move']); +listeners.pointermove(event(530, 12, 'drag', { buttons: 1 })); +assert.deepStrictEqual(take(), []); +listeners.pointerup(event(530, 12, 'drag')); + +for (const [x, y, side] of [[2, 300, 'w'], [998, 300, 'e'], [500, 2, 'n'], [500, 598, 's'], + [8, 8, 'nw'], [992, 8, 'ne'], [8, 592, 'sw'], [992, 592, 'se']]) { + const press = event(x, y); + listeners.pointerdown(press); + assert.strictEqual(press.stopped, true); + assert.deepStrictEqual(take(), [side]); +} + +listeners.pointerdown(event(500, 12, ['none', 'none', 'drag'])); +listeners.pointermove(event(520, 12, ['none', 'none', 'drag'], { buttons: 1 })); +assert.deepStrictEqual(take(), ['move']); +listeners.pointerup(event(520, 12)); +listeners.pointerdown(event(500, 12, ['none', 'no-drag', 'drag'])); +listeners.pointermove(event(520, 12, ['none', 'no-drag', 'drag'], { buttons: 1 })); +assert.deepStrictEqual(take(), []); +listeners.pointerup(event(520, 12)); + +layers = [{ region: 'none', getBoundingClientRect: () => ({ left: 0, right: 1000, top: 0, bottom: 600 }) }, + { region: 'drag', getBoundingClientRect: () => ({ left: 0, right: 1000, top: 0, bottom: 66 }) }]; +listeners.pointerdown(event(500, 12)); +listeners.pointermove(event(520, 12, 'none', { buttons: 1 })); +assert.deepStrictEqual(take(), ['move']); +listeners.pointerup(event(520, 12)); +listeners.pointerdown(event(500, 300)); +listeners.pointermove(event(520, 300, 'none', { buttons: 1 })); +assert.deepStrictEqual(take(), []); +listeners.pointerup(event(520, 300)); +layers = []; + +const right = event(2, 300, 'none', { button: 2 }); +listeners.pointerdown(right); +assert.deepStrictEqual(take(), []); + +listeners.dblclick(event(500, 12, 'drag')); +assert.deepStrictEqual(take(), ['maximize']); +listeners.dblclick(event(500, 300)); +assert.deepStrictEqual(take(), []); +SteamClient.Window.ToggleMaximize(); +assert.deepStrictEqual(take(), ['maximize']); + +globalThis.innerWidth = 1280; +globalThis.innerHeight = 670; +listeners.pointerdown(event(2, 300)); +assert.deepStrictEqual(take(), []); +""" + + +class SteamWindowControlsTest(unittest.TestCase): + @unittest.skipUnless(shutil.which("node"), "needs node") + def test_header_and_edges_request_window_actions(self): + script = "const SCRIPT = %s;\n%s" % (json.dumps(LIVE["WINDOW_JS"]), HARNESS) + result = subprocess.run(["node", "-e", script], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr) + + def test_unknown_actions_are_refused(self): + self.assertFalse(LIVE["window_action"]("destroy")) + self.assertFalse(LIVE["window_action"](None)) + + def test_moves_use_the_ewmh_directions(self): + self.assertEqual(LIVE["WINDOW_MOVES"], {"nw": 0, "n": 1, "ne": 2, "e": 3, "se": 4, "s": 5, "sw": 6, "w": 7, + "move": 8}) + + +if __name__ == "__main__": + unittest.main() From 516e3862fa104a8646f9bd19530c2e4a7f63ce79 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:54:00 -0500 Subject: [PATCH 04/85] fix: refresh repaired components and render Ubisoft Connect (#2090) * fix: refresh repaired components and render Ubisoft Connect * fix: address component repair and Wine registry review * fix: repair manually enabled components and check registry writes * fix: serialize component repairs and use Proton runinprefix * fix: report queued component repair failures * fix: preserve newer component repair waits * Make component queue transitions atomic * Isolate component apply failures by game * Preserve pending repair when catalog is stale * Restore persisted component repair revisions * Update pending requirements atomically * Respect disabled pending components per game * Keep queue key state atomic while worker waits * Pass selected game to component repairs * Preserve pending repair when component is absent * Preserve pending revision on catalog failure * Test legacy pending repair revision recovery * Isolate fake worker Steam app info lookup * Merge queued Steam app info lookups * Persist launch component revisions before repair * Gate launch on component repair discovery * Expand and refresh launch repair discovery * Include new automatic picks in launch requirements * Log repair persistence failures and align repair keys * Use runtime key for Battle.net component repairs * Retain failed component reapplications for retry * Harden pending repairs and launch preparation * Isolate wait-cool sleep mocking * Allow launches without catalog when no repair is pending * Queue launch repairs even if persistence fails * Block launch when repair state cannot persist * Allow launch when no component repair is needed * Persist selected repairs when catalog is offline * Drain offline component repair in test --- .../droiddeck/launcher/FrontEndActivity.kt | 11 +- .../launcher/frontend/AutoComponents.kt | 262 ++++++++++++---- .../launcher/session/WinComponents.kt | 38 ++- .../droiddeck/launcher/ui/ComponentsPage.kt | 1 + .../launcher/ui/WinComponentsEditor.kt | 35 ++- app/src/main/res/values/strings.xml | 3 + .../launcher/frontend/WinCompSourcesTest.kt | 285 +++++++++++++++++- .../session/WinComponentRevisionTest.kt | 73 +++++ tools/droiddeckctl | 6 +- .../overlay/usr/local/bin/droiddeck-game-env | 16 + .../usr/local/bin/droiddeck-wincomponents | 23 +- tools/tests/test_droiddeckctl.py | 2 +- tools/tests/test_game_environment.py | 60 ++++ tools/tests/test_wincomponents.py | 24 +- 14 files changed, 756 insertions(+), 83 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/session/WinComponentRevisionTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index f163bf6401..14e7f5722c 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -198,6 +198,7 @@ class FrontEndActivity : ComponentActivity() { private var gameStoresEnabled by mutableStateOf(true) private var gameStoresSpeedTier by mutableStateOf("fast") private var navRequest by mutableStateOf(null) + private val gameLaunchRequest = java.util.concurrent.atomic.AtomicLong() private var storesShowMature by mutableStateOf(false) private var storesSort by mutableStateOf(SessionPrefs.STORES_SORTS.first()) private var storesView by mutableStateOf(SessionPrefs.DEFAULT_STORES_VIEW) @@ -1185,8 +1186,13 @@ class FrontEndActivity : ComponentActivity() { onSteamGame = { g -> if (shortcutPicker) chooseGameShortcut(g) else { - com.droiddeck.launcher.frontend.AutoComponents.beforeLaunch(this, g) - com.droiddeck.launcher.stores.StoreLaunch.prepare(this, g) { launchGame(g) } + val request = gameLaunchRequest.incrementAndGet() + com.droiddeck.launcher.frontend.AutoComponents.beforeLaunch(this, g) { + if (request != gameLaunchRequest.get() || isFinishing || isDestroyed) return@beforeLaunch + com.droiddeck.launcher.stores.StoreLaunch.prepare(this, g) { + if (request == gameLaunchRequest.get() && !isFinishing && !isDestroyed) launchGame(g) + } + } } }, onEpicLauncher = { openEpicLauncher() }, @@ -1860,6 +1866,7 @@ class FrontEndActivity : ComponentActivity() { else @Suppress("DEPRECATION") state.getParcelable(key) override fun onDestroy() { + gameLaunchRequest.incrementAndGet() cancelCompatLaunch() updates.unregister() super.onDestroy() diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AutoComponents.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AutoComponents.kt index 1d4fb5ef55..c68d8ed2ae 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AutoComponents.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AutoComponents.kt @@ -3,6 +3,8 @@ package com.droiddeck.launcher.frontend import android.content.Context import android.net.ConnectivityManager import android.os.Build +import android.os.Handler +import android.os.Looper import android.os.PowerManager import android.util.AtomicFile import android.util.Log @@ -20,7 +22,11 @@ object AutoComponents { private const val TAG = "AutoComponents" fun appKey(game: Library.SteamGame): String? = - if (game.library == Library.ADDED) Integer.toUnsignedString(game.appId) else game.appId.takeIf { it > 0 }?.toString() + when { + game.source == com.droiddeck.launcher.stores.Store.BATTLENET.id -> game.profileKey + game.library == Library.ADDED -> Integer.toUnsignedString(game.appId) + else -> game.appId.takeIf { it > 0 }?.toString() + } fun autoPicks(findings: List, catalog: Map): Map { val out = LinkedHashMap() @@ -48,6 +54,8 @@ object AutoComponents { val downloading = MutableStateFlow>(emptyMap()) + val repairFailures = MutableStateFlow>(emptyMap()) + val pendingGames = MutableStateFlow>(emptySet()) val pendingComponents = MutableStateFlow>(emptySet()) @@ -56,12 +64,12 @@ object AutoComponents { if (job.pics != null) return val flow = if (job.component != null) pendingComponents else pendingGames val id = job.component ?: job.game?.let { appKey(it) } ?: return - flow.value = if (on) flow.value + id else flow.value - id + flow.value = if (on || job.component != null && job.key in queuedKeys) flow.value + id else flow.value - id } internal class Job( val game: Library.SteamGame?, val component: String?, val asked: Boolean, val seq: Long, val pics: List? = null, - val inSession: Boolean = false, + val inSession: Boolean = false, val revision: Int? = null, ) { val key get() = when { pics != null -> "pics" @@ -79,29 +87,45 @@ object AutoComponents { @Volatile private var worker: Thread? = null private const val PAUSE_MS = 15_000L + private fun waitFor(game: Library.SteamGame, id: String) { + val key = appKey(game) ?: return + synchronized(waiting) { waiting.getOrPut(id) { ArrayList() }.let { if (it.none { g -> appKey(g) == key }) it.add(game) } } + } + fun queueGame(context: Context, game: Library.SteamGame, asked: Boolean) { if (appKey(game) == null) return enqueue(context, Job(game, null, asked, seq.incrementAndGet())) } - private fun queueDownload(context: Context, id: String, asked: Boolean, inSession: Boolean = false) = - enqueue(context, Job(null, id, asked, seq.incrementAndGet(), inSession = inSession)) + fun queueRepair(context: Context, id: String, gameKey: String?, revision: Int) { + if (!WinComponents.validId(id)) return + gameKey?.let { Pending.add(context, it, listOf(id), mapOf(id to revision)) } + queueDownload(context, id, asked = true, inSession = gameKey != null, + revision = maxOf(revision, Pending.revision(context, id) ?: 0)) + } + + private fun queueDownload(context: Context, id: String, asked: Boolean, inSession: Boolean = false, revision: Int? = null) = + enqueue(context, Job(null, id, asked, seq.incrementAndGet(), inSession = inSession, revision = revision)) private fun enqueue(context: Context, job: Job) { - if (!queuedKeys.add(job.key)) { - synchronized(jobs) { + val added = synchronized(jobs) { + if (!queuedKeys.add(job.key)) { val old = jobs.firstOrNull { it.key == job.key } - if (old != null && ((job.asked && !old.asked) || (job.inSession && !old.inSession)) && jobs.remove(old)) { + val revision = listOfNotNull(old?.revision, job.revision).maxOrNull() + val pics = listOfNotNull(old?.pics, job.pics).flatten().distinct().takeIf { old?.pics != null || job.pics != null } + if (old != null && ((job.asked && !old.asked) || (job.inSession && !old.inSession) || revision != old.revision || pics != old.pics) && jobs.remove(old)) { jobs.add(Job(old.game ?: job.game, old.component, old.asked || job.asked, - if (job.asked && !old.asked) job.seq else old.seq, old.pics ?: job.pics, old.inSession || job.inSession)) + if (job.asked && !old.asked) job.seq else old.seq, pics, + old.inSession || job.inSession, revision)) } - } - if (runNow && !draining) drain(context) - return + false + } else { + jobs.add(job) + mark(job, true) + true + }.also { (jobs as java.lang.Object).notifyAll() } } - if (job.component != null) Log.i(TAG, "wincomp: queued ${job.component}") - mark(job, true) - jobs.add(job) + if (added && job.component != null) Log.i(TAG, "wincomp: queued ${job.component}") if (runNow) { if (!draining) drain(context) } else ensureWorker(context.applicationContext) } @@ -113,8 +137,15 @@ object AutoComponents { private fun gameProcessRunning(): Boolean = com.droiddeck.launcher.session.SteamGameProcess.running() + private fun queuePending(context: Context, key: String) { + Pending.ids(context, key).forEach { id -> + queueDownload(context, id, asked = true, inSession = true, revision = Pending.revision(context, id)) + } + } + fun queueInSession(context: Context, game: Library.SteamGame) { - if (appKey(game) == null) return + val key = appKey(game) ?: return + queuePending(context, key) enqueue(context, Job(game, null, true, seq.incrementAndGet(), inSession = true)) } @@ -124,7 +155,6 @@ object AutoComponents { try { while (true) { val job = next(context) ?: return - queuedKeys.remove(job.key) run(context, job) } } finally { @@ -135,6 +165,7 @@ object AutoComponents { private fun next(context: Context): Job? = synchronized(jobs) { val job = jobs.sortedWith(order).firstOrNull { !mustWait(context, it) } ?: return null jobs.remove(job) + queuedKeys.remove(job.key) job } @@ -148,13 +179,17 @@ object AutoComponents { worker = Thread({ android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND) while (true) { - try { jobs.put(jobs.take()) } catch (e: InterruptedException) { return@Thread } - val job = next(app) - if (job == null) { - try { Thread.sleep(PAUSE_MS) } catch (e: InterruptedException) { return@Thread } - continue + val job = try { + synchronized(jobs) { + next(app) ?: run { + (jobs as java.lang.Object).wait(PAUSE_MS) + next(app) + } + } + } catch (e: InterruptedException) { + return@Thread } - queuedKeys.remove(job.key) + if (job == null) continue WinComponents.background { run(app, job) } } }, "auto-components").apply { isDaemon = true; start() } @@ -164,18 +199,23 @@ object AutoComponents { try { when { job.pics != null -> SteamAppInfo.lookup(context, job.pics) - job.component != null -> download(context, job.component, job.asked, job.inSession) + job.component != null -> download(context, job.component, job.asked, job.inSession, job.revision) else -> job.game?.let { apply(context, it, job.asked, job.inSession) } } } catch (e: Exception) { Log.w(TAG, "wincomp: ${job.key}: ${e.javaClass.simpleName}: ${e.message}") + job.component?.let { + repairFailures.value = repairFailures.value + (it to (e.message ?: "Install failed")) + Pending.drop(context, it, job.revision) + } } finally { mark(job, false) changes.value = changes.value + 1 } } - private fun apply(context: Context, game: Library.SteamGame, asked: Boolean, inSession: Boolean = false) { + private fun apply(context: Context, game: Library.SteamGame, asked: Boolean, inSession: Boolean = false, + knownCatalog: Map? = null) { val key = appKey(game) ?: return val folder = game.gameFiles if (game.library == Library.ADDED && game.source == Library.ADDED && folder != null && SteamMatch.get(context, folder.path) == null) { @@ -183,9 +223,10 @@ object AutoComponents { } val store = com.droiddeck.launcher.stores.Store.byId(game.source) if (folder != null && (store == com.droiddeck.launcher.stores.Store.GOG || store == com.droiddeck.launcher.stores.Store.EPIC)) StoreListBackfill.fill(context, folder) - if (asked && online(context)) steamAppOf(context, game)?.let { SteamAppInfo.lookup(context, listOf(it)) } + if (knownCatalog == null && asked && online(context)) steamAppOf(context, game)?.let { SteamAppInfo.lookup(context, listOf(it)) } val findings = findings(context, game) - val catalog = (catalogOf(context, false) ?: catalogOf(context, true))?.associateBy { it.name } ?: return + val refreshed = if (knownCatalog == null && asked && online(context)) catalogOf(context, true) else null + val catalog = knownCatalog ?: (refreshed ?: catalogOf(context, false) ?: catalogOf(context, true))?.associateBy { it.name } ?: return val wanted = autoPicks(findings, catalog) val user = WinComponents.selection(context, key).user val before = WinComponents.selection(context, key).auto @@ -196,22 +237,37 @@ object AutoComponents { if (user[id] == false) { kept[id] = reason; continue } if (id in installed) { kept[id] = reason; continue } if (id in before) kept[id] = reason - synchronized(waiting) { waiting.getOrPut(id) { ArrayList() }.let { if (it.none { g -> appKey(g) == key }) it.add(game) } } - queueDownload(context, id, asked, inSession) + waitFor(game, id) missing.add(id) } - if (inSession) Pending.set(context, key, (Pending.ids(context, key).filter { it !in installed && it !in wanted } + missing).distinct()) if (before.keys != kept.keys) { WinComponents.setAuto(context, key, kept) Log.i(TAG, "${game.name}: on by itself ${kept.keys.joinToString().ifEmpty { "(none)" }}") } + Pending.update(context, key, catalog.mapValues { it.value.revision }) { ids -> + ids.filter { id -> user[id] != false && (id !in installed && id !in wanted || (Pending.revision(context, id) ?: 0) > (catalog[id]?.revision ?: 0)) } + missing + } + missing.forEach { id -> queueDownload(context, id, asked, inSession, catalog[id]?.revision) } changes.value = changes.value + 1 } - private fun download(context: Context, id: String, asked: Boolean, inSession: Boolean = false) { - val catalog = catalogOf(context, true)?.associateBy { it.name } ?: run { Pending.drop(context, id); return } + private fun download(context: Context, id: String, asked: Boolean, inSession: Boolean = false, requestedRevision: Int? = null) { + val catalog = catalogOf(context, true)?.associateBy { it.name } ?: run { + repairFailures.value = repairFailures.value + (id to "Could not load the component catalog") + return + } + val catalogComponent = catalog[id] + val requiredRevision = maxOf(requestedRevision ?: 0, Pending.revision(context, id) ?: 0) + if (catalogComponent != null && catalogComponent.revision < requiredRevision) { + repairFailures.value = repairFailures.value + (id to "The component catalog is older than the requested revision") + return + } if (id !in installedOf(context)) { - val c = catalog[id] ?: run { Pending.drop(context, id); return } + val c = catalogComponent ?: run { + repairFailures.value = repairFailures.value + (id to "Component is no longer available") + Pending.drop(context, id, requestedRevision) + return + } val started = System.currentTimeMillis() downloading.value = downloading.value + (id to WinComponents.Progress(id, "", WinComponents.Phase.DOWNLOAD, -1)) val problem = try { @@ -219,12 +275,28 @@ object AutoComponents { } finally { downloading.value = downloading.value - id } - if (problem != null) { Log.w(TAG, "wincomp: $id did not install: $problem"); Pending.drop(context, id); return } + if (problem != null) { + repairFailures.value = repairFailures.value + (id to problem) + Log.w(TAG, "wincomp: $id did not install: $problem") + Pending.drop(context, id, maxOf(requestedRevision ?: 0, c.revision)) + return + } Log.i(TAG, "wincomp: $id installed in ${System.currentTimeMillis() - started}ms") } val games = synchronized(waiting) { waiting.remove(id).orEmpty() } - games.forEach { apply(context, it, asked, inSession) } - Pending.drop(context, id) + var applied = true + games.forEach { game -> + try { + apply(context, game, asked, inSession, knownCatalog = catalog) + } catch (e: Exception) { + applied = false + appKey(game)?.let { key -> Pending.add(context, key, listOf(id), mapOf(id to (catalog[id]?.revision ?: requestedRevision ?: 0))) } + waitFor(game, id) + Log.w(TAG, "wincomp: $id installed, but ${game.name} was not updated: ${e.javaClass.simpleName}: ${e.message}") + } + } + if (applied) Pending.drop(context, id, maxOf(requestedRevision ?: 0, catalog[id]?.revision ?: 0)) + repairFailures.value = repairFailures.value - id } internal object Pending { @@ -233,24 +305,37 @@ object AutoComponents { @Synchronized fun read(context: Context): JSONObject = runCatching { JSONObject(file(context).readText()) }.getOrDefault(JSONObject()).let { it.optJSONObject("games") ?: JSONObject() } - @Synchronized fun set(context: Context, key: String, ids: List) { + @Synchronized fun set(context: Context, key: String, ids: List, revisions: Map = emptyMap()) { val games = read(context) if (ids.isEmpty()) games.remove(key) else games.put(key, JSONArray(ids)) - write(context, games) + write(context, games, revisions) } @Synchronized fun ids(context: Context, key: String): List = read(context).optJSONArray(key)?.let { a -> (0 until a.length()).map { a.optString(it) } }.orEmpty() - @Synchronized fun add(context: Context, key: String, ids: List) { + @Synchronized fun update(context: Context, key: String, revisions: Map, transform: (List) -> List): Boolean { + val games = read(context) + val current = games.optJSONArray(key)?.let { a -> (0 until a.length()).map { a.optString(it) } }.orEmpty() + val ids = transform(current).distinct() + if (ids.isEmpty()) games.remove(key) else games.put(key, JSONArray(ids)) + return write(context, games, revisions) + } + + @Synchronized fun revision(context: Context, id: String): Int? = + runCatching { JSONObject(file(context).readText()).optJSONObject("revisions")?.optInt(id) }.getOrNull() + + @Synchronized fun add(context: Context, key: String, ids: List, revisions: Map = emptyMap()) { val games = read(context) val have = games.optJSONArray(key)?.let { a -> (0 until a.length()).map { a.optString(it) } }.orEmpty() games.put(key, JSONArray((have + ids).distinct())) - write(context, games) + write(context, games, revisions) } - @Synchronized fun drop(context: Context, id: String) { + @Synchronized fun drop(context: Context, id: String, throughRevision: Int? = null) { val games = read(context) + val required = runCatching { JSONObject(file(context).readText()).optJSONObject("revisions")?.optInt(id, 0) ?: 0 }.getOrDefault(0) + if (throughRevision != null && required > throughRevision) return for (k in games.keys().asSequence().toList()) { val left = games.optJSONArray(k)?.let { a -> (0 until a.length()).map { a.optString(it) } }.orEmpty() - id if (left.isEmpty()) games.remove(k) else games.put(k, JSONArray(left)) @@ -258,13 +343,29 @@ object AutoComponents { write(context, games) } - private fun write(context: Context, games: JSONObject) { + private fun write(context: Context, games: JSONObject, required: Map = emptyMap()): Boolean { val f = file(context) - runCatching { + return runCatching { f.parentFile?.mkdirs() val tmp = File(f.path + ".tmp") - tmp.writeText(JSONObject().put("games", games).toString()) - if (!tmp.renameTo(f)) { f.delete(); tmp.renameTo(f) } + val before = runCatching { JSONObject(f.readText()).optJSONObject("revisions") }.getOrNull() + val revisions = JSONObject() + for (key in games.keys()) { + val ids = games.getJSONArray(key) + for (i in 0 until ids.length()) { + val id = ids.getString(i) + revisions.put(id, maxOf(before?.optInt(id, 0) ?: 0, required[id] ?: 0)) + } + } + tmp.writeText(JSONObject().put("games", games).put("revisions", revisions).toString()) + if (!tmp.renameTo(f)) { + f.delete() + if (!tmp.renameTo(f)) throw java.io.IOException("Could not replace pending repair file") + } + true + }.getOrElse { + Log.w(TAG, "wincomp: could not save pending repairs: ${it.javaClass.simpleName}: ${it.message}") + false } } } @@ -329,21 +430,76 @@ object AutoComponents { } - fun beforeLaunch(context: Context, game: Library.SteamGame) = queueGame(context, game, asked = false) + internal fun prepareLaunch(context: Context, game: Library.SteamGame): Boolean { + val key = appKey(game) ?: return false + val findings = findings(context, game) + val cached = catalogOf(context, false) + val current = if (online(context)) catalogOf(context, true) else null + val catalog = (current ?: cached)?.associateBy { it.name } ?: run { + val missing = WinComponents.selection(context, key).effective + .filter { WinComponents.validId(it) && it !in installedOf(context) } + val pendingSaved = missing.isEmpty() || Pending.update(context, key, emptyMap()) { ids -> (ids + missing).distinct() } + val pending = Pending.ids(context, key) + pending.forEach { waitFor(game, it) } + queuePending(context, key) + if (!pendingSaved) { + missing.forEach { id -> + waitFor(game, id) + queueDownload(context, id, asked = true, inSession = true, revision = Pending.revision(context, id)) + repairFailures.value = repairFailures.value + (id to "Could not save pending repairs") + } + } + return pendingSaved && pending.isEmpty() + } + val wanted = autoPicks(findings, catalog) + val selection = WinComponents.selection(context, key) + val user = selection.user + val installed = installedOf(context) + val roots = selection.effective + wanted.keys.filter { user[it] != false } + val required = withParts(roots.filter { WinComponents.validId(it) }, catalog) + val missing = required.filter { user[it] != false && it !in installed } + val pendingSaved = Pending.update(context, key, catalog.mapValues { it.value.revision }) { ids -> + ids.filter { id -> user[id] != false && (id !in installed && id !in wanted || (Pending.revision(context, id) ?: 0) > (catalog[id]?.revision ?: 0)) } + missing + } + missing.forEach { id -> + waitFor(game, id) + queueDownload(context, id, asked = true, inSession = true, + revision = maxOf(catalog[id]?.revision ?: 0, Pending.revision(context, id) ?: 0)) + } + Pending.ids(context, key).forEach { waitFor(game, it) } + queuePending(context, key) + if (!pendingSaved && missing.isNotEmpty()) { + missing.forEach { id -> repairFailures.value = repairFailures.value + (id to "Could not save pending repairs") } + return false + } + return true + } + + fun beforeLaunch(context: Context, game: Library.SteamGame, onReady: () -> Unit) { + val app = context.applicationContext + Thread({ + val ready = runCatching { prepareLaunch(app, game) }.getOrElse { + Log.w(TAG, "${game.name}: launch repair discovery failed: ${it.javaClass.simpleName}: ${it.message}") + false + } + queueGame(app, game, asked = false) + if (ready) Handler(Looper.getMainLooper()).post(onReady) + }, "auto-components-launch").apply { isDaemon = true; start() } + } fun restoreMissing(context: Context): List { val selections = WinComponents.selections(context) - if (selections.isEmpty()) return emptyList() - val catalog = (catalogOf(context, false) ?: catalogOf(context, true))?.associateBy { it.name } ?: return emptyList() + val catalog = (catalogOf(context, false) ?: catalogOf(context, true))?.associateBy { it.name } val installed = installedOf(context) - val lostFor = selections.mapValues { (_, selection) -> + val lostFor = if (catalog == null) emptyMap() else selections.mapValues { (_, selection) -> withParts(selection.effective.filter { WinComponents.validId(it) }, catalog).filter { it !in installed && it in catalog } }.filterValues { it.isNotEmpty() } - if (lostFor.isEmpty()) return emptyList() val lost = lostFor.values.flatten().distinct() - Log.i(TAG, "wincomp: reinstalling ${lost.joinToString()}, picked for games but missing from the runtime") - lostFor.forEach { (key, ids) -> Pending.add(context, key, ids) } - lost.forEach { queueDownload(context, it, asked = true, inSession = true) } + if (lost.isNotEmpty()) { + Log.i(TAG, "wincomp: reinstalling ${lost.joinToString()}, picked for games but missing from the runtime") + lostFor.forEach { (key, ids) -> Pending.add(context, key, ids, catalog!!.mapValues { it.value.revision }) } + } + Pending.read(context).keys().asSequence().toList().forEach { queuePending(context, it) } return lost } diff --git a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt index 21398bc4c8..b309bca43b 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt @@ -38,6 +38,7 @@ object WinComponents { private const val MSI_CACHE = "$STORE/.packages" private val PROTON_PROVIDES = setOf("gecko", "mono", "cjkfonts", "powershell", "VulkanRT") private val NESTED_KEYS = setOf("url", "file_name", "file_checksum", "file_size") + private val installLock = Any() fun validId(id: String): Boolean = ID.matches(id) && ".." !in id @@ -61,7 +62,7 @@ object WinComponents { class Component( val name: String, val description: String, val provider: String, val status: String, val dependencies: List, val steps: List, - val snapshot: String = "", + val snapshot: String = "", val revision: Int = 0, ) enum class Support { READY, NEEDS_INSTALLER, UNSUPPORTED } @@ -127,7 +128,7 @@ object WinComponents { name, o.optString("description"), o.optString("provider"), o.optString("status"), (0 until deps.length()).map { deps.getString(it) }.filter { validId(it) }, (0 until steps.length()).map { steps.getJSONObject(it).let { s -> Step(s.optString("action"), s) } }, - o.optString("snapshot"), + o.optString("snapshot"), o.optInt("revision", 0).coerceAtLeast(0), ) } if (listed.any { it.name == VCREDIST_ARM64 }) listed else listed + builtInArm64Runtime() @@ -170,15 +171,31 @@ object WinComponents { else -> true } - fun installed(context: Context, id: String): String? = runCatching { - JSONObject(File(LinuxRuntime.rootDir(context), "$STORE/$id/component.json").readText()).optString("version", "?") + internal fun installedVersion(directory: File, revision: Int): String? = runCatching { + val meta = JSONObject(File(directory, "component.json").readText()) + if (meta.optInt("revision", 0) < revision) null else meta.optString("version", "?") }.getOrNull() - fun installedIds(context: Context): List = - File(LinuxRuntime.rootDir(context), STORE).listFiles { f -> f.isDirectory && validId(f.name) } - .orEmpty().map { it.name }.filter { installed(context, it) != null }.sorted() + fun installed(context: Context, id: String): String? = installedVersion( + File(LinuxRuntime.rootDir(context), "$STORE/$id"), cached(context)?.firstOrNull { it.name == id }?.revision ?: 0, + ) - fun install(context: Context, c: Component, all: Map, onProgress: (Progress) -> Unit): String? { + internal fun downloadedIds(store: File): List = + store.listFiles { f -> f.isDirectory && validId(f.name) }.orEmpty() + .filter { installedVersion(it, 0) != null }.map { it.name }.sorted() + + fun downloadedIds(context: Context): List = downloadedIds(File(LinuxRuntime.rootDir(context), STORE)) + + fun installedIds(context: Context): List { + val revisions = cached(context).orEmpty().associate { it.name to it.revision } + return File(LinuxRuntime.rootDir(context), STORE).listFiles { f -> f.isDirectory && validId(f.name) } + .orEmpty().filter { installedVersion(it, revisions[it.name] ?: 0) != null }.map { it.name }.sorted() + } + + fun install(context: Context, c: Component, all: Map, onProgress: (Progress) -> Unit): String? = + synchronized(installLock) { installLocked(context, c, all, onProgress) } + + private fun installLocked(context: Context, c: Component, all: Map, onProgress: (Progress) -> Unit): String? { if (support(c, all) != Support.READY) return "${c.name} cannot be installed here yet" val order = ArrayList() fun visit(x: Component, depth: Int) { @@ -353,7 +370,7 @@ object WinComponents { val version = msi?.optString("version")?.takeIf { it.isNotEmpty() } ?: Regex("""\b(\d+\.\d+(\.\d+)*)\b""").find(c.description)?.value ?: "catalog" val meta = JSONObject() - .put("id", c.name).put("version", version) + .put("id", c.name).put("version", version).put("revision", c.revision) .put("overrides", JSONArray(overrides.distinct())) .put("requires", JSONArray(c.dependencies)) msi?.let { meta.put("kind", it.optString("kind", "msi")).put("product", it.optString("product")).put("notes", it.optJSONArray("notes") ?: JSONArray()) } @@ -556,8 +573,7 @@ object WinComponents { matches.forEach { f -> f.copyTo(File(dest, f.name.lowercase()), overwrite = true) } } - @Synchronized - fun uninstall(context: Context, id: String) { + fun uninstall(context: Context, id: String) = synchronized(installLock) { require(validId(id)) FileUtils.delete(File(LinuxRuntime.rootDir(context), "$STORE/$id")) save(context, selections(context).mapValues { (_, sel) -> Selection(sel.auto - id, sel.user - id) }) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt index a28326a4b1..6c15923b69 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt @@ -900,6 +900,7 @@ fun ComponentsPage( winOpen, compat = selectedGame.protonPrefix, steamAppId = selectedGame.appId.takeIf { selectedGame.library != Library.ADDED }, + game = selectedGame, ) { winComponentsOpen = null winComponentsRevision++ diff --git a/app/src/main/java/com/droiddeck/launcher/ui/WinComponentsEditor.kt b/app/src/main/java/com/droiddeck/launcher/ui/WinComponentsEditor.kt index 235f2f98b6..4dff5d4d60 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/WinComponentsEditor.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/WinComponentsEditor.kt @@ -104,6 +104,7 @@ internal fun WinComponentsDialog( var slowCatalog by remember { mutableStateOf(false) } LaunchedEffect(Unit) { kotlinx.coroutines.delay(300); slowCatalog = true } var installed by remember { mutableStateOf(emptySet()) } + var freshInstalled by remember { mutableStateOf(emptySet()) } var present by remember { mutableStateOf(emptySet()) } var selection by remember { mutableStateOf(WinComponents.selection(context, appKey)) } val picks = selection.effective @@ -141,9 +142,11 @@ internal fun WinComponentsDialog( findings = found selection = withContext(Dispatchers.IO) { WinComponents.selection(context, appKey) } present = withContext(Dispatchers.IO) { PrefixInstalledDetector.detect(compat) } - installed = withContext(Dispatchers.IO) { WinComponents.installedIds(context).toSet() } + installed = withContext(Dispatchers.IO) { WinComponents.downloadedIds(context).toSet() } + freshInstalled = withContext(Dispatchers.IO) { WinComponents.installedIds(context).toSet() } } val autoDownloading by com.droiddeck.launcher.frontend.AutoComponents.downloading.collectAsState() + val repairFailures by com.droiddeck.launcher.frontend.AutoComponents.repairFailures.collectAsState() val online = rememberOnline() val autoChanges by com.droiddeck.launcher.frontend.AutoComponents.changes.collectAsState() val pendingGames by com.droiddeck.launcher.frontend.AutoComponents.pendingGames.collectAsState() @@ -152,7 +155,8 @@ internal fun WinComponentsDialog( if (game != null) withContext(Dispatchers.IO) { com.droiddeck.launcher.frontend.AutoComponents.cachedFindings(context, appKey) } ?.let { findings = it; if (appKey !in pendingGames) findingsKnown = true } selection = withContext(Dispatchers.IO) { WinComponents.selection(context, appKey) } - installed = withContext(Dispatchers.IO) { WinComponents.installedIds(context).toSet() } + installed = withContext(Dispatchers.IO) { WinComponents.downloadedIds(context).toSet() } + freshInstalled = withContext(Dispatchers.IO) { WinComponents.installedIds(context).toSet() } } fun setUser(id: String, on: Boolean) { selection = WinComponents.Selection(selection.auto, selection.user + (id to on)) @@ -173,15 +177,25 @@ internal fun WinComponentsDialog( } val all = catalog.orEmpty() val c = all[id] - if (id in installed || c == null) { setUser(id, true); return } + if (id in installed) { + setUser(id, true) + if (c != null && id !in freshInstalled) { + com.droiddeck.launcher.frontend.AutoComponents.queueRepair(context, id, + game?.let { com.droiddeck.launcher.frontend.AutoComponents.appKey(it) }, c.revision) + } + return + } + if (c == null) { setUser(id, true); return } busyId = id; reverting = false - progress = WinComponents.Progress(id, "", WinComponents.Phase.DOWNLOAD, -1) + progress = null coroutine.launch { val problem = withContext(Dispatchers.IO) { - WinComponents.install(context, c, all) { p -> progress = p } + if (WinComponents.installed(context, id) != null) null + else WinComponents.install(context, c, all) { p -> progress = p } } progress = null - installed = withContext(Dispatchers.IO) { WinComponents.installedIds(context).toSet() } + installed = withContext(Dispatchers.IO) { WinComponents.downloadedIds(context).toSet() } + freshInstalled = withContext(Dispatchers.IO) { WinComponents.installedIds(context).toSet() } if (problem != null) { error = problem; failed = id } else setUser(id, true) busyId = null } @@ -244,6 +258,9 @@ internal fun WinComponentsDialog( val status = when { !online && id !in installed && support == Support.READY -> stringResource(R.string.wincomp_when_online) id == failed && error != null -> stringResource(R.string.wincomp_failed, error.orEmpty()) + id in repairFailures -> stringResource(R.string.wincomp_failed, repairFailures.getValue(id)) + id in pendingComponents && id in installed && id !in freshInstalled -> stringResource(R.string.wincomp_repair_queued) + id in installed && id !in freshInstalled -> stringResource(R.string.wincomp_repair_required) id in here && id !in picks -> stringResource(R.string.wincomp_already_here) id in installed -> stringResource(R.string.wincomp_downloaded) support == Support.NEEDS_INSTALLER -> stringResource(R.string.wincomp_needs_installer) @@ -275,6 +292,12 @@ internal fun WinComponentsDialog( modifier = (if (usable && focus != null) Modifier.focusRequester(focus) else Modifier) .onFocusChanged { if (it.isFocused) switchFocused = true }, ) { on -> toggle(id, on) } + if (id in repairFailures && c != null) { + SecondaryButton(stringResource(R.string.wincomp_retry), compact = true) { + com.droiddeck.launcher.frontend.AutoComponents.queueRepair(context, id, + game?.let { com.droiddeck.launcher.frontend.AutoComponents.appKey(it) }, c.revision) + } + } } fun firstUsable(ids: List, focus: FocusRequester): (String) -> FocusRequester? { val first = ids.firstOrNull { supportOf(it) == Support.READY } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83b8208209..74312a921c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -428,6 +428,9 @@ Not supported here yet Loading the components… Could not install: %1$s + This download needs an update. + Update queued. + Retry update Downloaded Downloading %1$s Installing: %1$s diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt index 4d1d23ee13..a1bb5b8365 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt @@ -34,6 +34,14 @@ class WinCompSourcesTest { private fun auto(findings: List) = findings.filter { it.auto }.map { it.component to it.origin } + @Test fun battleNetRepairKeysMatchRuntimeProfileKeys() { + val battlenet = game(null, Store.BATTLENET.id, 4242, library = "battlenet") + val steam = game(null, Library.SOURCE_STEAM, 4242, library = "steam") + + assertEquals(battlenet.profileKey, AutoComponents.appKey(battlenet)) + assertEquals("4242", AutoComponents.appKey(steam)) + } + @Test fun gogDependencyIdsMapToComponents() { assertEquals(listOf("vcredist2015"), WinCompSources.gog("MSVC2017_x64")) @@ -233,16 +241,19 @@ class WinCompSourcesTest { private var session = false private var gameUp = false - private fun payback(): Library.SteamGame { + private fun payback(appId: Int = 1262580): Library.SteamGame { val steamapps = tmp.newFolder("steamapps") val folder = File(steamapps, "common/Payback").apply { mkdirs() } - File(steamapps, "appmanifest_1262580.acf").writeText( + File(steamapps, "appmanifest_$appId.acf").writeText( "\"AppState\"\n{\n\t\"SharedDepots\"\n\t{\n\t\t\"228985\"\t\t\"228980\"\n\t\t\"228988\"\t\t\"228980\"\n\t\t\"228990\"\t\t\"228980\"\n\t}\n}\n", ) - return game(folder, Library.SOURCE_STEAM, 1262580, library = "steam", name = "Need for Speed Payback") + return game(folder, Library.SOURCE_STEAM, appId, library = "steam", name = "Need for Speed Payback") } private fun withFakeWorker(block: () -> T): T { + val steamPics = SteamAppInfo.pics + SteamAppInfo.pics = { null } + AutoComponents.repairFailures.value = emptyMap() AutoComponents.catalogOf = { _, _ -> catalog3 } AutoComponents.installedOf = { installedNow.toSet() } AutoComponents.installer = { _, c, _, _ -> downloaded.add(c.name); installedNow.add(c.name); null } @@ -255,6 +266,8 @@ class WinCompSourcesTest { return block() } finally { AutoComponents.runNow = false + SteamAppInfo.pics = steamPics + AutoComponents.repairFailures.value = emptyMap() AutoComponents.catalogOf = { c, network -> if (network) WinComponents.fetch(c) else WinComponents.cached(c) } AutoComponents.installedOf = { WinComponents.installedIds(it).toSet() } AutoComponents.installer = { c, comp, all, progress -> WinComponents.install(c, comp, all, progress) } @@ -264,6 +277,19 @@ class WinCompSourcesTest { } } + @Test fun anExplicitCheckRefreshesTheCatalogAndAnOfflineCheckUsesTheCache() = withFakeWorker { + installedNow.addAll(catalog3.map { it.name }) + val requests = ArrayList() + AutoComponents.catalogOf = { _, network -> requests.add(network); catalog3 } + val game = payback() + AutoComponents.queueGame(app, game, asked = true) + assertTrue(requests.first()) + requests.clear() + AutoComponents.online = { false } + AutoComponents.queueGame(app, game, asked = true) + assertFalse(requests.first()) + } + @Test fun aSteamListedComponentNotYetDownloadedTurnsOnWhenItLands() = withFakeWorker { installedNow.add("d3dx9") val game = payback() @@ -277,6 +303,244 @@ class WinCompSourcesTest { assertEquals(3, AutoComponents.cachedFindings(app, "1262580")!!.count { it.auto }) } + @Test fun downloadCallbacksReuseTheCatalogInsteadOfRefreshingAgain() = withFakeWorker { + val requests = ArrayList() + AutoComponents.catalogOf = { _, network -> requests.add(network); catalog3 } + AutoComponents.queueGame(app, payback(), asked = true) + assertEquals(3, downloaded.size) + assertEquals(1 + downloaded.size, requests.count { it }) + } + + @Test fun normalLaunchRecordsPendingComponentsBeforeQueueingTheirRepairs() = withFakeWorker { + AutoComponents.installer = { _, c, _, _ -> + assertTrue(c.name in AutoComponents.Pending.ids(app, "1262580")) + assertEquals(c.revision, AutoComponents.Pending.revision(app, c.name)) + downloaded.add(c.name) + installedNow.add(c.name) + null + } + + AutoComponents.queueGame(app, payback(), asked = true) + + assertTrue(AutoComponents.Pending.ids(app, "1262580").isEmpty()) + } + + @Test fun launchDiscoveryPersistsMissingComponentsWhileAWorkerWaitsForTheSession() = withFakeWorker { + session = true + gameUp = true + val appId = 9876543 + + assertTrue(AutoComponents.prepareLaunch(app, payback(appId))) + + assertEquals(setOf("d3dx9", "vcredist2013_dll", "vcredist2019_dll"), AutoComponents.Pending.ids(app, appId.toString()).toSet()) + session = false + gameUp = false + AutoComponents.drain(app) + } + + @Test fun launchDiscoveryUsesFreshCatalogAndIncludesManualDependencies() = withFakeWorker { + session = true + gameUp = true + val appId = 9876544 + val manual = WinComponents.Component("manual_component", "", "", "ready", listOf("d3dx9"), emptyList(), revision = 3) + val catalog = catalog3 + manual + val requests = ArrayList() + AutoComponents.catalogOf = { _, network -> requests.add(network); catalog } + WinComponents.setUser(app, appId.toString(), manual.name, true) + + assertTrue(AutoComponents.prepareLaunch(app, game(null, Library.SOURCE_STEAM, appId, library = "steam"))) + + assertTrue(requests.contains(true)) + assertEquals(setOf("manual_component", "d3dx9"), AutoComponents.Pending.ids(app, appId.toString()).toSet()) + session = false + gameUp = false + AutoComponents.drain(app) + } + + @Test fun pendingRepairsSurviveTemporaryCatalogFetchFailure() = withFakeWorker { + val id = "vcredist2010_dll" + AutoComponents.catalogOf = { _, _ -> null } + + AutoComponents.queueRepair(app, id, "4242", revision = 2) + + assertEquals(listOf(id), AutoComponents.Pending.ids(app, "4242")) + assertEquals(2, AutoComponents.Pending.revision(app, id)) + } + + @Test fun launchCanProceedWithoutCatalogOnlyWhenNoRepairIsPending() = withFakeWorker { + AutoComponents.catalogOf = { _, _ -> null } + val noPending = game(null, Library.SOURCE_STEAM, 9876545, library = "steam") + assertTrue(AutoComponents.prepareLaunch(app, noPending)) + + AutoComponents.Pending.add(app, "9876546", listOf("vcredist2010_dll"), mapOf("vcredist2010_dll" to 2)) + val pending = game(null, Library.SOURCE_STEAM, 9876546, library = "steam") + assertFalse(AutoComponents.prepareLaunch(app, pending)) + assertEquals(listOf("vcredist2010_dll"), AutoComponents.Pending.ids(app, "9876546")) + } + + @Test fun offlineLaunchPersistsMissingSelectedComponentsWithoutACatalog() = withFakeWorker { + AutoComponents.catalogOf = { _, _ -> null } + AutoComponents.online = { false } + val appId = 9876547 + val id = "vcredist2010_dll" + WinComponents.setUser(app, appId.toString(), id, true) + + assertFalse(AutoComponents.prepareLaunch(app, game(null, Library.SOURCE_STEAM, appId, library = "steam"))) + assertEquals(listOf(id), AutoComponents.Pending.ids(app, appId.toString())) + AutoComponents.catalogOf = { _, _ -> catalog3 + ready(id) } + AutoComponents.online = { true } + AutoComponents.drain(app) + } + + @Test fun pendingRepairsKeepTheirRequiredRevisionUntilTheyFinish() = withFakeWorker { + val repair = WinComponents.Component("vcredist2010_dll", "", "", "ready", emptyList(), emptyList(), revision = 2) + AutoComponents.catalogOf = { _, _ -> catalog3 + repair } + WinComponents.setUser(app, "4242", repair.name, true) + session = true + gameUp = true + AutoComponents.restoreMissing(app) + val pending = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), "root/.config/droiddeck/wincomponents-pending.json") + fun revision() = JSONObject(pending.readText()).getJSONObject("revisions").getInt(repair.name) + assertEquals(2, revision()) + AutoComponents.Pending.add(app, "other", listOf(repair.name), mapOf(repair.name to 1)) + AutoComponents.Pending.set(app, "4242", listOf(repair.name)) + assertEquals(2, revision()) + gameUp = false + AutoComponents.drain(app) + assertFalse(JSONObject(pending.readText()).getJSONObject("revisions").has(repair.name)) + } + + @Test fun manualRepairKeepsPendingWhenCatalogIsOlderThanRequestedRevision() = withFakeWorker { + val repair = WinComponents.Component("vcredist2010_dll", "", "", "ready", emptyList(), emptyList(), revision = 1) + AutoComponents.catalogOf = { _, _ -> catalog3 + repair } + installedNow.add(repair.name) + AutoComponents.Pending.add(app, "4242", listOf(repair.name), mapOf(repair.name to 2)) + AutoComponents.queueRepair(app, repair.name, "4242", revision = 1) + AutoComponents.drain(app) + assertEquals("The component catalog is older than the requested revision", AutoComponents.repairFailures.value[repair.name]) + assertEquals(listOf(repair.name), AutoComponents.Pending.ids(app, "4242")) + val pendingFile = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), "root/.config/droiddeck/wincomponents-pending.json") + assertEquals(2, JSONObject(pendingFile.readText()).getJSONObject("revisions").getInt(repair.name)) + } + + @Test fun restoreRequeuesPersistedRevisionEvenWhenOlderComponentIsInstalled() = withFakeWorker { + val repair = WinComponents.Component("vcredist2010_dll", "", "", "ready", emptyList(), emptyList(), revision = 1) + AutoComponents.catalogOf = { _, _ -> catalog3 + repair } + installedNow.add(repair.name) + AutoComponents.Pending.add(app, "4242", listOf(repair.name), mapOf(repair.name to 2)) + assertTrue(WinComponents.selections(app).isEmpty()) + assertTrue(AutoComponents.restoreMissing(app).isEmpty()) + assertEquals("The component catalog is older than the requested revision", AutoComponents.repairFailures.value[repair.name]) + assertEquals(listOf(repair.name), AutoComponents.Pending.ids(app, "4242")) + assertEquals(2, AutoComponents.Pending.revision(app, repair.name)) + WinComponents.setUser(app, "4242", repair.name, false) + AutoComponents.queueInSession(app, game(null, Library.SOURCE_STEAM, 4242, library = "steam")) + assertTrue(AutoComponents.Pending.ids(app, "4242").isEmpty()) + } + + @Test fun missingCatalogComponentCannotDropANewerPendingRepair() = withFakeWorker { + val id = "vcredist2010_dll" + AutoComponents.catalogOf = { _, _ -> catalog3 } + session = true + gameUp = true + AutoComponents.queueRepair(app, id, "4242", revision = 1) + AutoComponents.Pending.add(app, "other", listOf(id), mapOf(id to 2)) + gameUp = false + AutoComponents.drain(app) + assertEquals(listOf(id), AutoComponents.Pending.ids(app, "4242")) + assertEquals(listOf(id), AutoComponents.Pending.ids(app, "other")) + assertEquals(2, AutoComponents.Pending.revision(app, id)) + } + + @Test fun restoredLegacyPendingRepairUsesThePersistedRevision() = withFakeWorker { + val id = "vcredist2010_dll" + val repair = WinComponents.Component(id, "", "", "ready", emptyList(), emptyList(), revision = 1) + AutoComponents.catalogOf = { _, _ -> catalog3 + repair } + var attempts = 0 + AutoComponents.installer = { _, _, _, _ -> attempts++; null } + val pendingFile = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), "root/.config/droiddeck/wincomponents-pending.json") + pendingFile.parentFile?.mkdirs() + pendingFile.writeText(JSONObject().put("games", JSONObject().put("4242", org.json.JSONArray(listOf(id)))).toString()) + session = true + gameUp = true + AutoComponents.queueInSession(app, game(null, Library.SOURCE_STEAM, 4242, library = "steam")) + AutoComponents.Pending.add(app, "other", listOf(id), mapOf(id to 2)) + gameUp = false + AutoComponents.drain(app) + assertEquals("The component catalog is older than the requested revision", AutoComponents.repairFailures.value[id]) + assertEquals(0, attempts) + assertEquals(2, AutoComponents.Pending.revision(app, id)) + } + + @Test fun catalogLoadFailureCannotDropANewerPendingRepair() = withFakeWorker { + val id = "vcredist2010_dll" + AutoComponents.catalogOf = { _, _ -> null } + session = true + gameUp = true + AutoComponents.queueRepair(app, id, "4242", revision = 1) + AutoComponents.Pending.add(app, "other", listOf(id), mapOf(id to 2)) + gameUp = false + AutoComponents.drain(app) + assertEquals("Could not load the component catalog", AutoComponents.repairFailures.value[id]) + assertEquals(listOf(id), AutoComponents.Pending.ids(app, "4242")) + assertEquals(listOf(id), AutoComponents.Pending.ids(app, "other")) + assertEquals(2, AutoComponents.Pending.revision(app, id)) + } + + @Test fun manualRepairsRecordTheirRevisionAndExposeFailuresForRetry() = withFakeWorker { + val repair = WinComponents.Component("vcredist2010_dll", "", "", "ready", emptyList(), emptyList(), revision = 2) + AutoComponents.catalogOf = { _, _ -> catalog3 + repair } + var attempts = 0 + AutoComponents.installer = { _, c, _, _ -> + attempts++ + if (attempts == 1) throw IllegalStateException("network unavailable") else { installedNow.add(c.name); null } + } + session = true + gameUp = true + AutoComponents.queueRepair(app, repair.name, "4242", repair.revision) + val pending = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), "root/.config/droiddeck/wincomponents-pending.json") + assertEquals(2, JSONObject(pending.readText()).getJSONObject("revisions").getInt(repair.name)) + gameUp = false + AutoComponents.drain(app) + assertEquals("network unavailable", AutoComponents.repairFailures.value[repair.name]) + assertEquals(1, attempts) + assertFalse(JSONObject(pending.readText()).getJSONObject("games").has("4242")) + session = false + AutoComponents.queueRepair(app, repair.name, "4242", repair.revision) + assertEquals(2, attempts) + assertEquals(null, AutoComponents.repairFailures.value[repair.name]) + assertTrue(repair.name in installedNow) + assertFalse(JSONObject(pending.readText()).getJSONObject("revisions").has(repair.name)) + } + + @Test fun anEarlierRepairCannotDropANewerGamesPendingRevision() = withFakeWorker { + session = false + gameUp = false + val first = WinComponents.Component("vcredist2010_dll", "", "", "ready", emptyList(), emptyList(), revision = 2) + val newer = WinComponents.Component("vcredist2010_dll", "", "", "ready", emptyList(), emptyList(), revision = 3) + AutoComponents.catalogOf = { _, _ -> catalog3 + first } + var attempts = 0 + AutoComponents.installer = { _, c, _, _ -> + attempts++ + if (attempts == 1) { + AutoComponents.catalogOf = { _, _ -> catalog3 + newer } + session = true + gameUp = true + AutoComponents.queueRepair(app, c.name, "other", newer.revision) + } else installedNow.add(c.name) + null + } + AutoComponents.queueRepair(app, first.name, "first", first.revision) + val pending = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), "root/.config/droiddeck/wincomponents-pending.json") + assertEquals(3, JSONObject(pending.readText()).getJSONObject("revisions").getInt(first.name)) + assertEquals(listOf(first.name), AutoComponents.Pending.ids(app, "other")) + gameUp = false + session = false + AutoComponents.drain(app) + assertEquals(2, attempts) + assertFalse(JSONObject(pending.readText()).getJSONObject("revisions").has(first.name)) + } + @Test fun theQueueWaitsWhileASessionRunsAndResumesAfter() = withFakeWorker { val game = payback() session = true @@ -310,6 +574,21 @@ class WinCompSourcesTest { assertEquals(downloaded.distinct(), downloaded) } + @Test fun queuedPicsLookupsMergeAppIdsFromLaterSweeps() = withFakeWorker { + val lookedUp = ArrayList>() + SteamAppInfo.pics = { ids -> lookedUp.add(ids); ids.associateWith { null } } + session = true + val first = game(null, Library.SOURCE_STEAM, 810001, library = "steam") + val second = game(null, Library.SOURCE_STEAM, 810002, library = "steam") + + AutoComponents.sweep(app, listOf(first)) + AutoComponents.sweep(app, listOf(second)) + session = false + AutoComponents.drain(app) + + assertEquals(listOf(listOf(810001, 810002)), lookedUp) + } + @Test fun aDownloadWaitsForANetwork() = withFakeWorker { val game = payback() AutoComponents.online = { false } diff --git a/app/src/test/java/com/droiddeck/launcher/session/WinComponentRevisionTest.kt b/app/src/test/java/com/droiddeck/launcher/session/WinComponentRevisionTest.kt new file mode 100644 index 0000000000..e594134a35 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/WinComponentRevisionTest.kt @@ -0,0 +1,73 @@ +package com.droiddeck.launcher.session + +import com.droiddeck.launcher.runtime.LinuxRuntime +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33]) +class WinComponentRevisionTest { + @get:Rule val temp = TemporaryFolder() + + private fun installed(revision: Int? = null): File = temp.newFolder().also { directory -> + val meta = JSONObject().put("version", "10.0.40219") + revision?.let { meta.put("revision", it) } + File(directory, "component.json").writeText(meta.toString()) + } + + @Test fun legacyComponentsStayInstalledUntilTheCatalogRequestsARepair() { + val directory = installed() + assertEquals("10.0.40219", WinComponents.installedVersion(directory, 0)) + assertNull(WinComponents.installedVersion(directory, 1)) + } + + @Test fun repairedComponentsStayInstalledAndAreNotDowngradedByAnOlderCatalog() { + val directory = installed(2) + assertEquals("10.0.40219", WinComponents.installedVersion(directory, 2)) + assertEquals("10.0.40219", WinComponents.installedVersion(directory, 1)) + assertNull(WinComponents.installedVersion(directory, 3)) + } + + @Test fun outdatedComponentsRemainDownloadedForOfflineControls() { + val directory = installed() + assertNull(WinComponents.installedVersion(directory, 1)) + assertEquals(listOf(directory.name), WinComponents.downloadedIds(directory.parentFile)) + } + + @Test fun enablingDownloadedComponentsRequiresTheCatalogRevision() { + val context = RuntimeEnvironment.getApplication() + val id = "vcredist2010_dll" + val directory = File(LinuxRuntime.rootDir(context), "opt/droiddeck/wincomponents/$id").apply { mkdirs() } + val metadata = File(directory, "component.json") + metadata.writeText("""{"version":"10.0.40219"}""") + val catalog = File(context.filesDir, "wincomponents-catalog.json") + catalog.writeText("""{"components":[{"name":"$id","revision":1}]}""") + try { + assertEquals(listOf(id), WinComponents.downloadedIds(context)) + assertNull(WinComponents.installed(context, id)) + metadata.writeText("""{"version":"10.0.40219","revision":1}""") + assertEquals("10.0.40219", WinComponents.installed(context, id)) + catalog.delete() + assertEquals("10.0.40219", WinComponents.installed(context, id)) + } finally { + directory.deleteRecursively() + catalog.delete() + } + } + + @Test fun missingOrInvalidInstallMetadataNeedsInstallation() { + val directory = temp.newFolder() + assertNull(WinComponents.installedVersion(directory, 0)) + File(directory, "component.json").writeText("{") + assertNull(WinComponents.installedVersion(directory, 1)) + } +} diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 47abef41e5..3615b05b97 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -392,6 +392,10 @@ def thermal(adb: str, serial: str) -> dict: return {"ok": True, "command": "thermal", **summary} +def wait_sleep(seconds: float) -> None: + time.sleep(seconds) + + def wait_cool(adb: str, serial: str, below: float, timeout: float) -> dict: started = time.monotonic() while True: @@ -404,7 +408,7 @@ def wait_cool(adb: str, serial: str, below: float, timeout: float) -> dict: if remaining <= 0: raise ControlError(f"Battery still at {reading['batteryC']:g} °C after {timeout:g} s, wanted below {below:g}", "TIMEOUT") - time.sleep(min(10.0, remaining)) + wait_sleep(min(10.0, remaining)) def start_session(adb: str, serial: str, request: dict) -> dict: diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index 90651a3467..5624cbc2be 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -243,6 +243,20 @@ def ubisoft_overlay_off(env): print("droiddeck-game-env: Ubisoft Connect overlay left as is (%s)" % error, file=sys.stderr) +def ubisoft_composition_off(proton, env): + prefix = Path(env.get("STEAM_COMPAT_DATA_PATH", "/nonexistent")) / "pfx" + if not (prefix / UBISOFT_LAUNCHER).is_dir() or not (prefix / "user.reg").is_file(): + return + try: + for program in ("upc.exe", "UplayWebCore.exe"): + key = r"HKCU\Software\Wine\AppDefaults\%s\DllOverrides" % program + subprocess.run([proton, "runinprefix", "reg.exe", "add", key, + "/v", "dcomp", "/t", "REG_SZ", "/d", "", "/f"], env=env, check=True) + print("droiddeck-game-env: Ubisoft Connect uses CEF without DirectComposition", file=sys.stderr) + except (OSError, ValueError, subprocess.CalledProcessError) as error: + print("droiddeck-game-env: Ubisoft Connect composition configuration failed (%s)" % error, file=sys.stderr) + + PZ_JVM_FLAGS = ("-XX:+UseG1GC", "-XX:TieredStopAtLevel=1") @@ -973,6 +987,8 @@ def wait_forwarding_signals(process): def start(launch, launch_env, digest, after=None): + if len(launch) > 1 and launch[1] == "waitforexitandrun": + ubisoft_composition_off(launch[0], launch_env) if after: process = subprocess.Popen(launch, env=launch_env) try: diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-wincomponents b/tools/linuxfs/overlay/usr/local/bin/droiddeck-wincomponents index d7c3f61afd..e09a5e8d80 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-wincomponents +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-wincomponents @@ -476,15 +476,30 @@ def save_state(compat, state): def pending_for(app_id, pending=PENDING): try: with open(pending, encoding="utf-8") as source: - ids = json.load(source).get("games", {}).get(str(app_id), []) + config = json.load(source) + ids = config.get("games", {}).get(str(app_id), []) + revisions = config.get("revisions", {}) except (OSError, ValueError, AttributeError): - return [] - return [i for i in ids if valid_id(i)] if isinstance(ids, list) else [] + return {} + revisions = revisions if isinstance(revisions, dict) else {} + return {i: max(0, revisions[i]) if type(revisions.get(i)) is int else 0 + for i in ids if valid_id(i)} if isinstance(ids, list) else {} def wait_for_pending(app_id, pending=PENDING, store=STORE, timeout=PENDING_WAIT, sleep=time.sleep, clock=time.monotonic): def missing(): - return [cid for cid in pending_for(app_id, pending) if component(store, cid) is None] + left = [] + for cid, revision in pending_for(app_id, pending).items(): + try: + with open(Path(store) / cid / "component.json", encoding="utf-8") as source: + meta = json.load(source) + installed = meta.get("revision", 0) + ready = type(installed) is int and installed >= revision + except (OSError, ValueError, AttributeError): + ready = False + if not ready: + left.append(cid) + return left left = missing() if not left: return None diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 1fb7e3fde6..e2dc5290d8 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -490,7 +490,7 @@ class DroiddeckctlTest(FakeAdbTest): def test_wait_cool_polls_until_the_battery_is_below(self): self.configure({}, battery=[battery(412), battery(395), battery(379)], thermalservice=THERMALSERVICE) - with unittest.mock.patch.object(ctl.time, "sleep") as slept: + with unittest.mock.patch.object(ctl, "wait_sleep") as slept: code, out = self.run_ctl("wait", "cool", "--below", "38", "--timeout", "600") self.assertEqual(0, code, out) self.assertEqual(["wait", 37.9], [out["command"], out["batteryC"]]) diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index 919d6673bb..55387436b9 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -2190,6 +2190,66 @@ class UbisoftOverlayTest(unittest.TestCase): self.assertEqual(sorted(p.name for p in settings.parent.iterdir()), ["settings.yaml"]) +class UbisoftCompositionTest(unittest.TestCase): + def test_writes_through_wine_without_replacing_a_live_servers_registry(self): + with tempfile.TemporaryDirectory() as tmp: + prefix = Path(tmp) / "pfx" + (prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True) + registry = prefix / "user.reg" + registry.write_text("registry last saved by Wine\n") + env = {"STEAM_COMPAT_DATA_PATH": tmp, "WINESERVER": "/selected/wineserver"} + keys = [] + + def write_registry(argv, **kwargs): + self.assertEqual(argv[:4], ["/selected/proton", "runinprefix", "reg.exe", "add"]) + self.assertEqual(argv[5:], ["/v", "dcomp", "/t", "REG_SZ", "/d", "", "/f"]) + self.assertIs(kwargs["env"], env) + self.assertTrue(kwargs["check"]) + keys.append(argv[4]) + registry.write_text("newer state saved by the active Wine server\n") + return subprocess.CompletedProcess(argv, 0) + + with mock.patch("subprocess.run", side_effect=write_registry) as run: + MODULE["ubisoft_composition_off"]("/selected/proton", env) + self.assertEqual(run.call_count, 2) + self.assertEqual(registry.read_text(), "newer state saved by the active Wine server\n") + self.assertEqual(keys, [r"HKCU\Software\Wine\AppDefaults\%s\DllOverrides" % program + for program in ("upc.exe", "UplayWebCore.exe")]) + self.assertEqual(list(prefix.glob(".ubisoft-*.reg")), []) + + def test_other_prefixes_and_uninitialized_registries_are_untouched(self): + with tempfile.TemporaryDirectory() as tmp: + prefix = Path(tmp) / "pfx" + prefix.mkdir() + registry = prefix / "user.reg" + registry.write_text("WINE REGISTRY Version 2\n") + env = {"STEAM_COMPAT_DATA_PATH": tmp} + with mock.patch("subprocess.run") as run: + MODULE["ubisoft_composition_off"]("proton", env) + self.assertEqual(registry.read_text(), "WINE REGISTRY Version 2\n") + registry.unlink() + (prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True) + MODULE["ubisoft_composition_off"]("proton", env) + self.assertFalse(registry.exists()) + run.assert_not_called() + + def test_failed_registry_write_keeps_the_game_launch_available(self): + with tempfile.TemporaryDirectory() as tmp: + prefix = Path(tmp) / "pfx" + (prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True) + (prefix / "user.reg").write_text("WINE REGISTRY Version 2\n") + for failed_write in (0, 1): + stderr = io.StringIO() + results = [subprocess.CompletedProcess([], 0)] * failed_write + results.append(subprocess.CalledProcessError(1, "proton")) + with mock.patch("subprocess.run", side_effect=results) as run, mock.patch("sys.stderr", stderr): + MODULE["ubisoft_composition_off"]("proton", {"STEAM_COMPAT_DATA_PATH": tmp}) + self.assertEqual(run.call_count, failed_write + 1) + self.assertIn("configuration failed", stderr.getvalue()) + self.assertNotIn("uses CEF", stderr.getvalue()) + self.assertEqual(list(prefix.glob(".ubisoft-*.reg")), []) + + if __name__ == "__main__": unittest.main() diff --git a/tools/tests/test_wincomponents.py b/tools/tests/test_wincomponents.py index d7686ebf16..8e88e00f9c 100644 --- a/tools/tests/test_wincomponents.py +++ b/tools/tests/test_wincomponents.py @@ -274,10 +274,13 @@ class PendingWaitTest(unittest.TestCase): def tearDown(self): self.tmp.cleanup() - def install(self, cid): + def install(self, cid, revision=0): folder = self.store / cid folder.mkdir(parents=True, exist_ok=True) - (folder / "component.json").write_text(json.dumps({"id": cid, "overrides": []})) + metadata = {"id": cid, "overrides": []} + if revision is not None: + metadata["revision"] = revision + (folder / "component.json").write_text(json.dumps(metadata)) def clock(self): return len(self.slept) * 0.5 @@ -296,6 +299,8 @@ class PendingWaitTest(unittest.TestCase): self.install("d3dx9") self.pending.write_text(json.dumps({"games": {"1262580": ["d3dx9"]}})) self.assertIsNone(self.wait()) + self.install("d3dx9", revision=None) + self.assertIsNone(self.wait()) self.assertEqual([], self.slept) def test_waits_until_the_component_lands(self): @@ -311,6 +316,21 @@ class PendingWaitTest(unittest.TestCase): self.assertEqual(4, len(self.slept)) self.assertEqual("wincomp: 1262580 launched without vcredist2019_dll (not ready)", note) + def test_an_existing_old_revision_waits_until_the_repair_lands(self): + self.install("vcredist2010_dll", revision=0) + self.pending.write_text(json.dumps({"games": {"1262580": ["vcredist2010_dll"]}, + "revisions": {"vcredist2010_dll": 1}})) + note = self.wait(on_sleep=lambda n: self.install("vcredist2010_dll", revision=1) if n == 3 else None) + self.assertEqual(3, len(self.slept)) + self.assertEqual(note, "wincomp: 1262580 waited 1500ms for vcredist2010_dll") + + def test_an_old_revision_does_not_satisfy_a_pending_repair(self): + self.install("vcredist2010_dll", revision=1) + self.pending.write_text(json.dumps({"games": {"1262580": ["vcredist2010_dll"]}, + "revisions": {"vcredist2010_dll": 2}})) + self.assertEqual(self.wait(timeout=1.0), "wincomp: 1262580 launched without vcredist2010_dll (not ready)") + self.assertEqual(2, len(self.slept)) + def test_a_damaged_pending_file_is_no_wait(self): self.pending.write_text("{not json") self.assertIsNone(self.wait()) From a9d2d09e646d15b320e8aebfebe65ec52345f164 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 4 Nov 2026 22:15:03 -0500 Subject: [PATCH 05/85] fix: restore single-screen session menu controls (#2110) --- .../main/java/com/droiddeck/launcher/ui/BottomScreenBar.kt | 5 ++++- .../main/java/com/droiddeck/launcher/ui/SessionOverlay.kt | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomScreenBar.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomScreenBar.kt index 4897801863..4930b6db81 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomScreenBar.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomScreenBar.kt @@ -112,16 +112,19 @@ internal fun BarActions( qamModifier: Modifier = Modifier, qamInteraction: MutableInteractionSource? = null, onQamConfirm: (() -> Unit)? = null, + showShortcuts: Boolean = false, ) { onMenu?.let { BarButton(stringResource(R.string.touch_droiddeck_menu), menuModifier.testTag("bottom-bar-menu"), icon = R.drawable.ic_stat_session, active = menuActive, onClick = it) } onSteam?.let { - BarButton(stringResource(R.string.drawer_steam_menu), steamModifier.testTag("bottom-bar-steam"), label = "STEAM", onClick = it) + BarButton(stringResource(R.string.drawer_steam_menu), steamModifier.testTag("bottom-bar-steam"), label = "STEAM", + shortcut = if (showShortcuts) "⧉" else null, onClick = it) } onQam?.let { BarButton(stringResource(R.string.drawer_open_qam), qamModifier.testTag("bottom-bar-qam"), vector = Icons.Outlined.MoreHoriz, + shortcut = if (showShortcuts) "☰" else null, interactionSource = qamInteraction ?: remember { MutableInteractionSource() }, onConfirm = onQamConfirm, onClick = it) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index d6356a7ee8..b11b0640b6 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -493,7 +493,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont if (a.pipSupported) SteamActionPill( stringResource(R.string.pip_title), Icons.Outlined.PictureInPictureAlt, focus.track(page, "pip"), ) { host.open = null; a.onPip() } - StopSessionButton(modifier = focus.track(page, "stop").onGloballyPositioned { stopCoords = it }) { host.open = null; confirmStop = true } + if (docked) StopSessionButton(modifier = focus.track(page, "stop").onGloballyPositioned { stopCoords = it }) { host.open = null; confirmStop = true } val steamActions = a.steam && a.onSteamMenu != null && a.onQam != null val qamInteraction = remember { MutableInteractionSource() } var qamStartedOnPress by remember { mutableStateOf(false) } @@ -509,7 +509,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont } } BarActions( - onMenu = { host.open = null; a.onClose() }, menuActive = true, + onMenu = if (docked) ({ host.open = null; a.onClose() }) else null, menuActive = true, onSteam = if (steamActions) ({ host.open = null; a.onSteamMenu?.invoke() }) else null, onQam = if (steamActions) ({ host.open = null @@ -521,7 +521,9 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont qamModifier = focus.track(page, "qam"), qamInteraction = qamInteraction, onQamConfirm = { host.open = null; a.onQam?.invoke() }, + showShortcuts = !docked, ) + if (!docked) StopSessionButton(modifier = focus.track(page, "stop").onGloballyPositioned { stopCoords = it }) { host.open = null; confirmStop = true } } a.onAchievements?.let { show -> DrawerAchievementsRow(a.achievementsProgress, Modifier.padding(top = if (short) 6.dp else 10.dp).then(focus.track(page, "achievements"))) { From b9dbd006beca9f129e1ad655573d66638d832d4e Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Thu, 5 Nov 2026 00:47:38 -0500 Subject: [PATCH 06/85] fix(storage): Windows installs on a natively mounted card no longer ask for an administrator (#2100) * fix(storage): Windows installs on a natively mounted card no longer ask for an administrator Cards mounted directly as FAT, exFAT or NTFS were not treated as Android storage, so wineserver reported an Anonymous owner and refused permission changes. Its chmod on these volumes also no longer fails the request. * fix(storage): keep NTFS owners and the chmod error --- tools/linuxfs/preload/owner.c | 34 +++++++++++++++++++++-- tools/tests/test_storage_owner_preload.py | 34 +++++++++++++++++++---- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/tools/linuxfs/preload/owner.c b/tools/linuxfs/preload/owner.c index d4e42964cc..78ada3bf00 100644 --- a/tools/linuxfs/preload/owner.c +++ b/tools/linuxfs/preload/owner.c @@ -1,4 +1,5 @@ #define _GNU_SOURCE +#include #include #include #include @@ -8,6 +9,8 @@ #define FUSE_MAGIC 0x65735546 #define SDCARDFS_MAGIC 0x5dca2df5 +#define FAT_MAGIC 0x4d44 +#define EXFAT_MAGIC 0x2011bab0 static int is_wineserver(void) { static int cached = -1; @@ -27,15 +30,42 @@ static int is_wineserver(void) { return cached; } +static int has_no_unix_owner(int fd) { + struct statfs fs; + + if (fstatfs(fd, &fs) != 0) return 0; + return fs.f_type == FUSE_MAGIC || fs.f_type == SDCARDFS_MAGIC || fs.f_type == FAT_MAGIC || + (unsigned int)fs.f_type == EXFAT_MAGIC; +} + __attribute__((visibility("hidden"))) void bl_storage_owner(int fd, struct stat *st) { - struct statfs fs; int saved = errno; uid_t uid; if (st != NULL && is_wineserver()) { uid = getuid(); - if (st->st_uid != uid && fstatfs(fd, &fs) == 0 && (fs.f_type == FUSE_MAGIC || fs.f_type == SDCARDFS_MAGIC)) st->st_uid = uid; + if (st->st_uid != uid && has_no_unix_owner(fd)) st->st_uid = uid; } errno = saved; } + +int fchmod(int fd, mode_t mode) { + static int (*next_fchmod)(int, mode_t); + int saved = errno, result; + + if (next_fchmod == NULL) next_fchmod = dlsym(RTLD_NEXT, "fchmod"); + if (next_fchmod == NULL) { + errno = ENOSYS; + return -1; + } + result = next_fchmod(fd, mode); + if (result != 0 && errno == EPERM && is_wineserver()) { + if (has_no_unix_owner(fd)) { + errno = saved; + return 0; + } + errno = EPERM; + } + return result; +} diff --git a/tools/tests/test_storage_owner_preload.py b/tools/tests/test_storage_owner_preload.py index a667198602..42f66c61eb 100644 --- a/tools/tests/test_storage_owner_preload.py +++ b/tools/tests/test_storage_owner_preload.py @@ -11,7 +11,9 @@ FAKE = r""" #define _GNU_SOURCE #include #include +#include #include +#include #include #include #include @@ -29,8 +31,22 @@ int fstatfs(int fd, struct statfs *out) { if (result == 0 && strstr(path, "/fuse/")) out->f_type = 0x65735546; if (result == 0 && strstr(path, "/sdcardfs/")) out->f_type = 0x5dca2df5; if (result == 0 && strstr(path, "/ext4/")) out->f_type = 0xef53; + if (result == 0 && strstr(path, "/fat/")) out->f_type = 0x4d44; + if (result == 0 && strstr(path, "/exfat/")) out->f_type = 0x2011bab0; + if (result == 0 && strstr(path, "/ntfs/")) out->f_type = 0x5346544e; + if (strstr(path, "/broken/")) { + errno = EIO; + return -1; + } return result; } + +int fchmod(int fd, mode_t mode) { + (void)fd; + (void)mode; + errno = EPERM; + return -1; +} """ PROGRAM = r""" @@ -50,6 +66,8 @@ int main(int argc, char **argv) { errno = 1234; int result = fstat(fd, &st); printf("%s %d\n", st.st_uid == real ? "real" : st.st_uid == real + 1 ? "user" : "other", result == 0 && errno == 1234); + errno = 0; + printf("%s\n", fchmod(fd, 0755) == 0 ? "chmod-ok" : errno == EPERM ? "chmod-denied" : "chmod-other"); close(fd); } return 0; @@ -76,7 +94,7 @@ class StorageOwnerPreloadTest(unittest.TestCase): subprocess.run(["cc", "-O2", "-o", str(cls.wineserver), str(build / "program.c")], check=True) cls.other = build / "wine64-preloader" shutil.copy(cls.wineserver, cls.other) - for kind in ("fuse", "sdcardfs", "ext4"): + for kind in ("fuse", "sdcardfs", "ext4", "fat", "exfat", "ntfs", "broken"): (cls.dir / kind).mkdir() (cls.dir / kind / "file").write_text("x") @@ -85,20 +103,26 @@ class StorageOwnerPreloadTest(unittest.TestCase): cls.temp.cleanup() def owners(self, program, *kinds): - env = dict(os.environ, LD_PRELOAD="%s:%s" % (self.fake, self.preload)) + env = dict(os.environ, LD_PRELOAD="%s:%s" % (self.preload, self.fake)) env.pop("BL_STORAGE_DIAGNOSTICS", None) paths = [str(self.dir / kind / "file") for kind in kinds] result = subprocess.run([str(program)] + paths, env=env, capture_output=True, text=True, check=True) return result.stdout.split() def test_wineserver_owns_what_is_on_android_storage(self): - self.assertEqual(["user", "1", "user", "1"], self.owners(self.wineserver, "fuse", "sdcardfs")) + self.assertEqual(["user", "1", "chmod-ok"] * 2, self.owners(self.wineserver, "fuse", "sdcardfs")) + + def test_wineserver_owns_what_is_on_a_native_card(self): + self.assertEqual(["user", "1", "chmod-ok"] * 2, self.owners(self.wineserver, "fat", "exfat")) def test_other_filesystems_keep_their_owner(self): - self.assertEqual(["real", "1"], self.owners(self.wineserver, "ext4")) + self.assertEqual(["real", "1", "chmod-denied"] * 2, self.owners(self.wineserver, "ext4", "ntfs")) + + def test_chmod_keeps_its_error_when_the_volume_is_unknown(self): + self.assertEqual(["real", "1", "chmod-denied"], self.owners(self.wineserver, "broken")) def test_other_programs_see_the_real_owner(self): - self.assertEqual(["real", "1", "real", "1"], self.owners(self.other, "fuse", "sdcardfs")) + self.assertEqual(["real", "1", "chmod-denied"] * 2, self.owners(self.other, "fuse", "sdcardfs")) if __name__ == "__main__": From a309428a2aa8f963aa26bc4e2ef8638d296cfced Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Thu, 5 Nov 2026 02:04:03 -0500 Subject: [PATCH 07/85] feat(battlenet): import, list and delete World of Warcraft addons (#2111) World of Warcraft, Classic and Forever get an Addons tab in the Library. It imports addon zips into the right Interface/AddOns folder, lists the installed addons, and deletes one after a confirmation. --- README.md | 1 + .../droiddeck/launcher/FrontEndActivity.kt | 28 +++ .../droiddeck/launcher/runtime/WowAddons.kt | 164 +++++++++++++ .../droiddeck/launcher/ui/FrontEndScreen.kt | 2 + .../com/droiddeck/launcher/ui/GameDetail.kt | 47 +++- app/src/main/res/values-ar/strings.xml | 28 +++ app/src/main/res/values-b+es+419/strings.xml | 22 ++ app/src/main/res/values-bg/strings.xml | 20 ++ app/src/main/res/values-cs/strings.xml | 24 ++ app/src/main/res/values-da/strings.xml | 20 ++ app/src/main/res/values-de/strings.xml | 20 ++ app/src/main/res/values-el/strings.xml | 20 ++ app/src/main/res/values-es/strings.xml | 22 ++ app/src/main/res/values-fi/strings.xml | 20 ++ app/src/main/res/values-fr/strings.xml | 22 ++ app/src/main/res/values-hi/strings.xml | 20 ++ app/src/main/res/values-hu/strings.xml | 20 ++ app/src/main/res/values-in/strings.xml | 18 ++ app/src/main/res/values-it/strings.xml | 22 ++ app/src/main/res/values-ja/strings.xml | 18 ++ app/src/main/res/values-ko/strings.xml | 18 ++ app/src/main/res/values-ms/strings.xml | 18 ++ app/src/main/res/values-nb/strings.xml | 20 ++ app/src/main/res/values-nl/strings.xml | 20 ++ app/src/main/res/values-pl/strings.xml | 24 ++ app/src/main/res/values-pt-rPT/strings.xml | 22 ++ app/src/main/res/values-pt/strings.xml | 22 ++ app/src/main/res/values-ro/strings.xml | 22 ++ app/src/main/res/values-ru/strings.xml | 24 ++ app/src/main/res/values-sv/strings.xml | 20 ++ app/src/main/res/values-th/strings.xml | 18 ++ app/src/main/res/values-tr/strings.xml | 20 ++ app/src/main/res/values-uk/strings.xml | 24 ++ app/src/main/res/values-vi/strings.xml | 18 ++ app/src/main/res/values-zh-rCN/strings.xml | 18 ++ app/src/main/res/values-zh-rHK/strings.xml | 18 ++ app/src/main/res/values-zh-rTW/strings.xml | 18 ++ app/src/main/res/values/strings.xml | 20 ++ .../launcher/runtime/WowAddonsTest.kt | 221 ++++++++++++++++++ 39 files changed, 1142 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/runtime/WowAddons.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/runtime/WowAddonsTest.kt diff --git a/README.md b/README.md index cc233c380c..8b834ff00d 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V - Epic's official Linux launcher preview runs through FEX. That setup is outside Epic's listed Linux support. - Battle.net is by [@kayakyakr](https://github.com/kayakyakr). It runs Blizzard's own client in Proton (downloaded from Blizzard, not included) and shows key art from the [Battle.net Shop](https://shop.battle.net). Without Steam, its games see the pad as an Xbox 360 controller via `PROTON_SPOOF_STEAMINPUT_VIDPID` in [Proton](https://github.com/ValveSoftware/wine)'s `dlls/winebus.sys`. - Battle.net installs drive Blizzard's Agent the way [@barncastle](https://github.com/barncastle)'s [Battle.Net-Installer](https://github.com/barncastle/Battle.Net-Installer) does, with requests from [wowdev.wiki](https://wowdev.wiki/Agent). Read without taking code: [@mubaraknumann](https://github.com/mubaraknumann)'s [unifideck](https://github.com/mubaraknumann/unifideck), [@djmittens](https://github.com/djmittens)'s [neo-mittens](https://github.com/djmittens/neo-mittens) `bnetswitch`, [@BCD1210](https://github.com/BCD1210)'s [soju](https://github.com/BCD1210/soju) and [Lutris](https://github.com/lutris/lutris)'s `product.db` reader. +- World of Warcraft addon imports replace an addon's folder from a temporary copy, as [WowUp](https://github.com/WowUp/WowUp) does, and read flavour folders the way [WoWDeck](https://github.com/sigboe/wowdeck) does. No code from either is used. - Xbox games load [@domsvoboda](https://github.com/domsvoboda)'s [xodus-nexus](https://github.com/domsvoboda/xodus-nexus) modules (LGPL-2.1-or-later), including `wintypes.dll`. Minecraft's GameInput setup was checked against [@Wyze3306](https://github.com/Wyze3306)'s [BedrockOnLinux](https://github.com/Wyze3306/BedrockOnLinux) (MIT). - The Xbox Cloud Gaming player uses the WebRTC client of [@unknownskl](https://github.com/unknownskl)'s [Greenlight](https://github.com/unknownskl/greenlight) (MIT), and its offer tweaks and sharpening follow [@redphx](https://github.com/redphx)'s [Better xCloud](https://github.com/redphx/better-xcloud) (MIT). See `tools/xcloud-player/NOTICE.md`. - The itch.io butler pack ships butler's `7z.so`, itch.io's build of [7-Zip](https://www.7-zip.org) by Igor Pavlov (LGPL-2.1, unRAR restriction on RAR code), unmodified. Other archives use Apache Commons Compress and the runtime's bsdtar (libarchive). diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 14e7f5722c..a7edaa3692 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -433,6 +433,27 @@ class FrontEndActivity : ComponentActivity() { pickSaveZip.launch(InAppFilePicker.buildIntent(this, listOf("zip"), getString(R.string.main_saves_pick_zip, name), GameSaves.savesDir().parentFile?.parentFile?.path)) } + private fun importAddons(name: String, target: com.droiddeck.launcher.runtime.WowAddons.Target) { + if (SessionState.running) { + android.widget.Toast.makeText(this, R.string.main_addons_close_session, android.widget.Toast.LENGTH_LONG).show() + return + } + onSavePicked = { zip -> + saveAction(getString(R.string.main_addons_importing, name)) { + if (SessionState.running) return@saveAction getString(R.string.main_addons_close_session) + val imported = try { + com.droiddeck.launcher.runtime.WowAddons.import(zip, target) + } catch (_: com.droiddeck.launcher.runtime.WowAddons.TooLarge) { + return@saveAction getString(R.string.main_addons_too_large, zip.name) + } + if (imported.isEmpty()) getString(R.string.main_addons_none, zip.name) + else resources.getQuantityString(R.plurals.main_addons_imported, imported.size, imported.size, target.flavor) + } + } + val downloads = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS).path + pickSaveZip.launch(InAppFilePicker.buildIntent(this, listOf("zip"), getString(R.string.main_addons_pick_zip, name), downloads)) + } + private fun exportSaves(name: String, layout: GameSaves.Layout, game: () -> GameSaves.Game) { onSavePicked = { dir -> saveAction(getString(R.string.main_saves_exporting, name)) { @@ -1282,6 +1303,13 @@ class FrontEndActivity : ComponentActivity() { onGameComponents = { game -> openComponents(gameKey = game.profileKey) }, onComponentsTab = { tab -> openComponents(focusContent = true, tab = tab) }, onSaveImport = { sg -> importSaves(sg.name) { GameSaves.game(sg) } }, + onAddonImport = { sg, target -> importAddons(sg.name, target) }, + onAddonDelete = { target, name -> + saveAction(getString(R.string.main_addons_deleting, name)) { + com.droiddeck.launcher.runtime.WowAddons.delete(target, name) + getString(R.string.main_addons_deleted, name) + } + }, onSaveExport = { sg, layout -> exportSaves(sg.name, layout) { GameSaves.game(sg) } }, onPerformance = { refreshCores(); showComponents = false; showMapping = false; showPerformance = true }, onRoms = { showRoms = true }, diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/WowAddons.kt b/app/src/main/java/com/droiddeck/launcher/runtime/WowAddons.kt new file mode 100644 index 0000000000..60cfbf37c3 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/runtime/WowAddons.kt @@ -0,0 +1,164 @@ +package com.droiddeck.launcher.runtime + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.setValue +import com.droiddeck.launcher.frontend.Library +import com.droiddeck.launcher.stores.Store +import com.droiddeck.launcher.stores.StoreInstalls +import org.apache.commons.compress.archivers.zip.ZipFile +import java.io.File +import java.io.IOException +import java.nio.file.Files +import java.nio.file.LinkOption + +object WowAddons { + var imports by mutableIntStateOf(0) + private set + + class TooLarge : IOException() + + class Target(val flavor: String, val addOns: File) + + class Addon(val name: String, val root: String) + + internal const val MAX_EXPANDED_BYTES = 4L * 1024 * 1024 * 1024 + + private val SUFFIX = Regex("[-_](standard|mainline|classic|vanilla|tbc|bcc|wrath|wotlkc|cata|mists|forever)$", RegexOption.IGNORE_CASE) + + fun targets(game: Library.SteamGame): List { + if (game.source != Store.BATTLENET.id) return emptyList() + val title = game.storeId?.let(BattleNet::title) ?: return emptyList() + if (title.flavor == null) return emptyList() + val folder = game.gameFiles ?: return emptyList() + return targets(title, folder) + } + + internal fun targets(title: BattleNet.Title, folder: File): List { + val flavors = BattleNet.TITLES.filter { it.code == title.code }.mapNotNull { it.flavor } + .flatMap { listOf(it, it.dropLast(1) + "_beta_") }.distinct() + val root = if (folder.name in flavors) folder.parentFile ?: return emptyList() else folder + return flavors.map { File(root, it) }.filter { it.isDirectory }.map { Target(it.name, addOnsFolder(it)) } + } + + fun installed(target: Target): List = + target.addOns.listFiles().orEmpty().filter { it.isDirectory && !it.name.startsWith(".") } + .map { it.name }.sortedBy { it.lowercase() } + + fun delete(target: Target, name: String) { + val folder = target.addOns.listFiles()?.firstOrNull { it.name == name && !it.name.startsWith(".") } + ?: throw IOException("Cannot find $name") + StoreInstalls.deleteTree(folder) + if (Files.exists(folder.toPath(), LinkOption.NOFOLLOW_LINKS)) throw IOException("Cannot delete $name") + imports++ + } + + fun import(zipFile: File, target: Target): List { + ZipFile.builder().setFile(zipFile).get().use { zip -> + val all = zip.entries.toList() + if (all.any { it.isUnixSymlink }) return emptyList() + val entries = all.filter { clean(it.name) != null } + val addons = addons(entries.filter { !it.isDirectory }.mapNotNull { clean(it.name) }) + if (addons.isEmpty()) return emptyList() + val addOns = target.addOns + if (!addOns.isDirectory && !addOns.mkdirs()) throw IOException("Cannot create ${addOns.path}") + val stage = File(addOns.parentFile, ".addon-import-${System.nanoTime()}") + try { + val fresh = File(stage, "new") + val buffer = ByteArray(64 * 1024) + var written = 0L + for (entry in entries) { + if (entry.isDirectory) continue + val path = clean(entry.name) ?: continue + val addon = addons.firstOrNull { path.startsWith(it.root) } ?: continue + val out = inside(fresh, addon.name + "/" + path.removePrefix(addon.root)) ?: continue + out.parentFile?.mkdirs() + zip.getInputStream(entry).use { input -> + out.outputStream().use { output -> + while (true) { + val read = input.read(buffer) + if (read < 0) break + written += read + if (written > MAX_EXPANDED_BYTES) throw TooLarge() + output.write(buffer, 0, read) + } + } + } + } + swap(addons.map { File(fresh, it.name) to it.name }, addOns, File(stage, "old").apply { mkdirs() }) + } finally { + StoreInstalls.deleteTree(stage) + } + imports++ + return addons.map { it.name } + } + } + + internal fun addons(files: List): List { + val tocs = files.filter { it.endsWith(".toc", ignoreCase = true) } + val folders = tocs.map { it.substringBeforeLast('/', "") }.distinct().sortedBy { it.length } + val roots = ArrayList() + for (folder in folders) { + if (roots.none { it.isEmpty() || folder.startsWith("$it/") }) roots.add(folder) + } + return roots.mapNotNull { root -> + val inFolder = tocs.filter { it.substringBeforeLast('/', "") == root } + .map { it.substringAfterLast('/').dropLast(4) } + val name = addonName(root.substringAfterLast('/'), inFolder) + name.takeIf { it.isNotEmpty() && !it.startsWith(".") }?.let { Addon(it, if (root.isEmpty()) "" else "$root/") } + }.distinctBy { it.name.lowercase() } + } + + private fun addonName(folder: String, tocs: List): String { + val match = tocs.firstOrNull { it.equals(folder, ignoreCase = true) } + ?: tocs.firstOrNull { it.replace(SUFFIX, "").equals(folder, ignoreCase = true) } + if (match != null) return folder + return tocs.map { it.replace(SUFFIX, "") }.minByOrNull { it.length }.orEmpty() + } + + private fun clean(name: String): String? { + val parts = name.replace('\\', '/').trim('/').split('/') + if (name.startsWith("/") || name.startsWith("\\") || parts.any { it.isEmpty() || it == "." || it == ".." || it.endsWith(":") }) return null + if (parts.first() == "__MACOSX" || parts.last().startsWith("._")) return null + return parts.joinToString("/") + } + + private fun inside(root: File, path: String): File? { + val out = File(root, path) + return out.takeIf { it.canonicalPath.startsWith(root.canonicalPath + File.separator) } + } + + private fun addOnsFolder(flavor: File): File = child(child(flavor, "Interface"), "AddOns") + + private fun child(parent: File, name: String): File = + parent.listFiles()?.firstOrNull { it.name.equals(name, ignoreCase = true) } ?: File(parent, name) + + internal fun swap(fresh: List>, addOns: File, old: File) { + val done = ArrayList() + try { + for ((folder, name) in fresh) done.add(replace(folder, addOns, name, old)) + } catch (e: IOException) { + done.asReversed().forEach { undo(it) } + throw e + } + } + + private class Replaced(val installed: File, val previous: File?, val kept: File?) + + private fun undo(replaced: Replaced) { + StoreInstalls.deleteTree(replaced.installed) + if (replaced.previous != null) replaced.kept?.renameTo(replaced.previous) + } + + private fun replace(fresh: File, addOns: File, name: String, old: File): Replaced { + val current = addOns.listFiles()?.firstOrNull { it.name.equals(name, ignoreCase = true) } + val kept = current?.let { File(old, it.name) } + if (current != null && !current.renameTo(kept!!)) throw IOException("Cannot replace ${current.path}") + val installed = File(addOns, name) + if (!fresh.renameTo(installed)) { + kept?.renameTo(current) + throw IOException("Cannot install $name") + } + return Replaced(installed, current, kept) + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 30acb4d85d..44f629b348 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -219,6 +219,8 @@ class FrontEndActions( val onGameComponents: (Library.SteamGame) -> Unit = { onComponents(true) }, val onComponentsTab: (String) -> Unit = {}, val onSaveImport: (Library.SteamGame) -> Unit = {}, + val onAddonImport: (Library.SteamGame, com.droiddeck.launcher.runtime.WowAddons.Target) -> Unit = { _, _ -> }, + val onAddonDelete: (com.droiddeck.launcher.runtime.WowAddons.Target, String) -> Unit = { _, _ -> }, val onSaveExport: (Library.SteamGame, com.droiddeck.launcher.session.GameSaves.Layout) -> Unit = { _, _ -> }, val onPerformance: () -> Unit, val onRoms: () -> Unit, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt index f7efc043ff..915a621756 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt @@ -73,6 +73,7 @@ import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics @@ -86,7 +87,9 @@ import coil.compose.AsyncImage import com.droiddeck.launcher.R import com.droiddeck.launcher.frontend.GameRemoval import com.droiddeck.launcher.frontend.Library +import com.droiddeck.launcher.runtime.WowAddons import com.droiddeck.launcher.session.GameSaves +import com.droiddeck.launcher.session.SessionState import com.droiddeck.launcher.stores.CatalogItem import com.droiddeck.launcher.stores.CloudSaves import com.droiddeck.launcher.stores.InstalledStoreGame @@ -136,7 +139,7 @@ internal class GameRef(val appId: Int?, val store: Store?, val storeId: String?) } } -internal enum class GameTab { ABOUT, ACHIEVEMENTS, LAUNCH, SAVES, INSTALL } +internal enum class GameTab { ABOUT, ACHIEVEMENTS, LAUNCH, SAVES, ADDONS, INSTALL } @Composable internal fun GameDetail( @@ -180,12 +183,14 @@ internal fun GameDetail( .takeUnless { it.trim().equals(title.trim(), ignoreCase = true) }.orEmpty() val scored = scores != null && (scores.metacritic != Lookup.None || scores.hltb != Lookup.None) val prefix = game?.protonPrefix?.takeIf { it.isDirectory } + val addonTargets = remember(game?.gameId, game?.gameFiles) { game?.let(WowAddons::targets).orEmpty() } val tabs = buildList { if (description.isNotBlank() || developer.isNotBlank() || publisher.isNotBlank() || releaseDate.isNotBlank() || scored || (!s.shortcutPicker && title.isNotBlank() && title != id)) add(GameTab.ABOUT) if (achievementState != null) add(GameTab.ACHIEVEMENTS) val cloud = game?.library == Library.XBOX_CLOUD if (game != null && !cloud) add(GameTab.LAUNCH) if (game != null && game.library == Library.ADDED && prefix != null) add(GameTab.SAVES) + if (addonTargets.isNotEmpty()) add(GameTab.ADDONS) if ((game != null && !cloud) || installed != null) add(GameTab.INSTALL) } var picked by remember(key) { mutableStateOf(null) } @@ -248,6 +253,7 @@ internal fun GameDetail( } ?: stringResource(R.string.achievements_title) GameTab.LAUNCH -> stringResource(R.string.game_tab_launch) GameTab.SAVES -> stringResource(if (Store.byId(source).let { it == Store.GOG || it == Store.EPIC }) R.string.game_tab_saves_cloud else R.string.games_saves) + GameTab.ADDONS -> stringResource(R.string.game_tab_addons) GameTab.INSTALL -> stringResource(R.string.game_tab_install) } } @@ -263,6 +269,7 @@ internal fun GameDetail( GameTab.ACHIEVEMENTS -> achievementState?.let { st -> AchievementsTab(StoreAchievements.forSource(store?.id)?.label.orEmpty(), st) } GameTab.LAUNCH -> if (game != null) LaunchTab(game, s, a, hopRail) GameTab.SAVES -> if (game != null && prefix != null) SavesTab(game, prefix, a) + GameTab.ADDONS -> if (game != null) AddonsTab(game, addonTargets, a) GameTab.INSTALL -> InstallTab(game, installed, item, store) } } @@ -857,6 +864,44 @@ private fun SavesTab(g: Library.SteamGame, prefix: File, a: FrontEndActions) { } } +@Composable +private fun AddonsTab(g: Library.SteamGame, targets: List, a: FrontEndActions) { + Column(Modifier.fillMaxWidth().tabPanel(), verticalArrangement = Arrangement.spacedBy(2.dp)) { + targets.forEach { target -> + val names by produceState(emptyList(), target.addOns, WowAddons.imports) { + value = withContext(Dispatchers.IO) { WowAddons.installed(target) } + } + if (targets.size > 1) SectionLabel(target.flavor) + MenuItem( + stringResource(R.string.games_import_addons), checked = false, + detail = pluralStringResource(R.plurals.games_addons_count, names.size, names.size), + ) { a.onAddonImport(g, target) } + MenuItem(stringResource(R.string.games_open_addons_folder), checked = false) { + target.addOns.mkdirs() + a.onBrowseFiles(target.addOns) + } + names.forEach { name -> AddonRow(name, target, a) } + } + } +} + +@Composable +private fun AddonRow(name: String, target: WowAddons.Target, a: FrontEndActions) { + var asking by remember(target.addOns, name) { mutableStateOf(false) } + val delete = stringResource(R.string.common_delete) + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(start = 16.dp, top = 2.dp, bottom = 2.dp)) { + Text(name, fontSize = 14.sp, color = MaterialTheme.colorScheme.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) + if (!SessionState.running) IconAction(Icons.Outlined.Delete, delete, "addon:delete:${target.flavor}:$name", danger = true) { asking = true } + } + if (asking) ConfirmDialog( + title = stringResource(R.string.games_delete_addon_title, name), + text = stringResource(R.string.games_delete_addon_body), + confirm = delete, + onConfirm = { a.onAddonDelete(target, name) }, + onDismiss = { asking = false }, + ) +} + @Composable private fun CloudRows(g: Library.SteamGame) { val store = Store.byId(g.source)?.takeIf { it != Store.AMAZON } ?: return diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index b3068a6f5e..20c77a1377 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -1207,6 +1207,18 @@ تصدير بصيغة GameHub المضغوطة… تصدير بصيغة Winlator المضغوطة… فتح مجلد الحفظ + استيراد الإضافات من zip… + فتح مجلد الإضافات + حذف %1$s؟ + يؤدي هذا إلى حذف مجلد الإضافة. تبقى إعداداتها. + + %1$d إضافة + %1$d إضافة + %1$d إضافتان + %1$d إضافات + %1$d إضافة + %1$d إضافة + لم يتم تشغيلها أبدًا بيئة التشغيل مشغولة · %1$d%% بيئة التشغيل مشغولة @@ -1393,6 +1405,21 @@ تم استيراد %1$d ملفًا من %2$s إلى %3$s. تم نسخ ملفات الحفظ القديمة احتياطيًا إلى Download/DroidDeck/Saves/backups تم استيراد %1$d ملف من %2$s إلى %3$s. تم نسخ ملفات الحفظ القديمة احتياطيًا إلى Download/DroidDeck/Saves/backups + أغلِق الجلسة أولاً حتى لا تستخدم اللعبة إضافاتها أثناء الاستيراد + استيراد الإضافات إلى %1$s + اختر ملف zip للإضافات الخاصة بـ %1$s + %1$s كبير جدًا بحيث لا يمكن استيراده + جارٍ حذف %1$s + تم حذف %1$s + لم يتم العثور على إضافات في %1$s + + تم استيراد %1$d إضافة إلى %2$s + تم استيراد %1$d إضافة إلى %2$s + تم استيراد %1$d إضافتين إلى %2$s + تم استيراد %1$d إضافات إلى %2$s + تم استيراد %1$d إضافة إلى %2$s + تم استيراد %1$d إضافة إلى %2$s + اختر ملف zip لملفات حفظ %1$s تصدير %1$s @@ -3616,6 +3643,7 @@ Steam Cloud للألعاب التي تُحفظ بياناتها في حساب Steam الخاص بك البحث في الويب + الإضافات تثبيت الموقع مجلد diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index 4f608ee523..73698d9d57 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -1259,6 +1259,15 @@ Exportar como zip de GameHub… Exportar como zip de Winlator… Abrir carpeta de guardado + Importar addons desde zip… + Abrir carpeta de addons + ¿Eliminar %1$s? + Esto elimina la carpeta del addon. Sus ajustes se conservan. + + %1$d addon + %1$d addons + %1$d de addons + Nunca jugado Runtime ocupado · %1$d%% Runtime ocupado @@ -1438,6 +1447,18 @@ Se importaron %1$d archivos del %2$s en %3$s. Copia de las partidas anteriores en Download/DroidDeck/Saves/backups Se importaron %1$d archivos del %2$s en %3$s. Copia de las partidas anteriores en Download/DroidDeck/Saves/backups + Cierra primero la sesión para que el juego no use sus addons durante la importación + Importando addons en %1$s + Elige un zip de addons para %1$s + %1$s es demasiado grande para importarlo + Eliminando %1$s + Se eliminó %1$s + No se encontraron addons en %1$s + + Se importó %1$d addon en %2$s + Se importaron %1$d addons en %2$s + Se importaron %1$d de addons en %2$s + Elige un zip de partidas guardadas para %1$s Exportando %1$s @@ -3481,6 +3502,7 @@ Steam Cloud Para juegos con partidas guardadas en tu cuenta de Steam Búsqueda web + Addons Instalar Ubicación Carpeta diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 4f5c248d61..678a118f74 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -1183,6 +1183,14 @@ Експортиране като GameHub zip… Експортиране като Winlator zip… Отваряне на папката за записи + Импортиране на добавки от ZIP… + Отваряне на папката с добавки + Да се изтрие ли %1$s? + Това изтрива папката на добавката. Настройките ѝ се запазват. + + %1$d добавка + %1$d добавки + Никога не е играна Средата за изпълнение е заета · %1$d%% Средата за изпълнение е заета @@ -1361,6 +1369,17 @@ Импортиран %1$d файл от %2$s в %3$s. Старите запазвания са архивирани в Download/DroidDeck/Saves/backups Импортирани %1$d файла от %2$s в %3$s. Старите запазвания са архивирани в Download/DroidDeck/Saves/backups + Затвори сесията първо, за да не използва играта добавките си по време на импортирането + Импортиране на добавки в %1$s + Избор на ZIP файл с добавки за %1$s + %1$s е твърде голям за импортиране + Изтриване на %1$s + Изтрито: %1$s + Не са намерени добавки в %1$s + + Импортирана %1$d добавка в %2$s + Импортирани %1$d добавки в %2$s + Избор на ZIP файл със запазвания за %1$s Експортиране на %1$s @@ -3472,6 +3491,7 @@ Steam Cloud За игри със записи в акаунта ви в Steam Търсене в мрежата + Добавки Инсталиране Местоположение Папка diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 954f6e48e9..158be592d8 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -1195,6 +1195,16 @@ Exportovat jako GameHub zip… Exportovat jako Winlator zip… Otevřít složku s uloženými pozicemi + Importovat doplňky ze ZIP… + Otevřít složku s doplňky + Smazat %1$s? + Tím se smaže složka doplňku. Jeho nastavení zůstane zachováno. + + %1$d doplněk + %1$d doplňky + %1$d doplňku + %1$d doplňků + Nikdy nehráno Runtime zaneprázdněn · %1$d%% Runtime zaneprázdněn @@ -1377,6 +1387,19 @@ Importováno %1$d souborů z %2$s do %3$s. Staré uložené pozice byly zálohovány do Download/DroidDeck/Saves/backups Importováno %1$d souborů z %2$s do %3$s. Staré uložené pozice byly zálohovány do Download/DroidDeck/Saves/backups + Nejprve zavřete relaci, aby hra během importu nepoužívala své doplňky. + Importování doplňků do %1$s + Vyberte ZIP s doplňky pro %1$s + %1$s je pro import příliš velký + Mazání: %1$s + Smazáno: %1$s + V %1$s nebyly nalezeny žádné doplňky + + Importován %1$d doplněk do %2$s + Importovány %1$d doplňky do %2$s + Importováno %1$d doplňku do %2$s + Importováno %1$d doplňků do %2$s + Vyberte ZIP s uloženou pozicí pro %1$s Exportování %1$s @@ -3544,6 +3567,7 @@ Steam Cloud Pro hry s uloženými pozicemi ve vašem účtu Steam Hledat na webu + Doplňky Instalovat Umístění Složka diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 05cf267e74..b673ffe66b 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -1183,6 +1183,14 @@ Eksporter som GameHub-zip… Eksporter som Winlator-zip… Åbn savemappe + Importer addons fra zip… + Åbn addon-mappe + Slet %1$s? + Dette fjerner addonens mappe. Dens indstillinger bevares. + + %1$d addon + %1$d addons + Aldrig spillet Runtime optaget · %1$d%% Runtime optaget @@ -1361,6 +1369,17 @@ Importerede %1$d fil fra %2$s til %3$s. Gamle gemte spil sikkerhedskopieret til Download/DroidDeck/Saves/backups Importerede %1$d filer fra %2$s til %3$s. Gamle gemte spil sikkerhedskopieret til Download/DroidDeck/Saves/backups + Luk sessionen først, så spillet ikke bruger sine addons under importen + Importerer addons til %1$s + Vælg en zip med addons til %1$s + %1$s er for stor til at blive importeret + Sletter %1$s + %1$s slettet + Ingen addons fundet i %1$s + + Importerede %1$d addon til %2$s + Importerede %1$d addons til %2$s + Vælg en zip med gemte spil til %1$s Eksporterer %1$s @@ -3472,6 +3491,7 @@ Steam Cloud Til spil med gemte data på din Steam-konto Websøgning + Addons Installer Placering Mappe diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index bf8236f70e..6bb4a27a19 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1175,6 +1175,14 @@ Als GameHub-ZIP exportieren… Als Winlator-ZIP exportieren… Spielstandordner öffnen + Addons aus ZIP importieren… + Addon-Ordner öffnen + %1$s löschen? + Dadurch wird der Ordner des Addons entfernt. Die Einstellungen bleiben erhalten. + + %1$d Addon + %1$d Addons + Nie gespielt Laufzeit beschäftigt · %1$d %% Laufzeit beschäftigt @@ -1353,6 +1361,17 @@ %1$d Datei aus %2$s in %3$s importiert. Alte Spielstände gesichert unter Download/DroidDeck/Saves/backups %1$d Dateien aus %2$s in %3$s importiert. Alte Spielstände gesichert unter Download/DroidDeck/Saves/backups + Schließe zuerst die Sitzung, damit das Spiel seine Addons während des Imports nicht verwendet + Addons werden in %1$s importiert + Addon-ZIP für %1$s auswählen + %1$s ist zu groß zum Importieren + %1$s wird gelöscht + %1$s gelöscht + Keine Addons in %1$s gefunden + + %1$d Addon in %2$s importiert + %1$d Addons in %2$s importiert + Spielstand-ZIP für %1$s auswählen Export von %1$s @@ -3472,6 +3491,7 @@ Steam Cloud Für Spiele mit Speicherständen in deinem Steam-Konto Websuche + Addons Installieren Speicherort Ordner diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index ad9263c98c..17be0c8bce 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -1183,6 +1183,14 @@ Εξαγωγή ως zip GameHub… Εξαγωγή ως zip Winlator… Άνοιγμα φακέλου αποθήκευσης + Εισαγωγή προσθέτων από zip… + Άνοιγμα φακέλου προσθέτων + Διαγραφή του %1$s; + Ο φάκελος του πρόσθετου θα διαγραφεί. Οι ρυθμίσεις του παραμένουν. + + %1$d πρόσθετο + %1$d πρόσθετα + Δεν έχει παιχτεί ποτέ Το runtime είναι απασχολημένο · %1$d%% Το runtime είναι απασχολημένο @@ -1361,6 +1369,17 @@ Έγινε εισαγωγή %1$d αρχείου από το %2$s στο %3$s. Τα παλιά αρχεία αποθήκευσης κρατήθηκαν ως αντίγραφο ασφαλείας στο Download/DroidDeck/Saves/backups Έγινε εισαγωγή %1$d αρχείων από το %2$s στο %3$s. Τα παλιά αρχεία αποθήκευσης κρατήθηκαν ως αντίγραφο ασφαλείας στο Download/DroidDeck/Saves/backups + Κλείστε πρώτα τη συνεδρία, ώστε το παιχνίδι να μη χρησιμοποιεί τα πρόσθετά του κατά την εισαγωγή + Εισαγωγή προσθέτων στο %1$s + Επιλέξτε ένα zip προσθέτων για το %1$s + Το %1$s είναι πολύ μεγάλο για εισαγωγή + Γίνεται διαγραφή του %1$s + Το %1$s διαγράφηκε + Δεν βρέθηκαν πρόσθετα στο %1$s + + Έγινε εισαγωγή %1$d προσθέτου στο %2$s + Έγινε εισαγωγή %1$d προσθέτων στο %2$s + Επιλέξτε ένα zip αποθηκευμένων αρχείων για το %1$s Εξαγωγή %1$s @@ -3472,6 +3491,7 @@ Steam Cloud Για παιχνίδια με αποθηκεύσεις στον λογαριασμό σας Steam Αναζήτηση στον ιστό + Πρόσθετα Εγκατάσταση Τοποθεσία Φάκελος diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index f7cc0570d3..b9ad21bbe0 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1189,6 +1189,15 @@ Exportar como zip de GameHub… Exportar como zip de Winlator… Abrir carpeta de guardado + Importar addons desde zip… + Abrir carpeta de addons + ¿Eliminar %1$s? + Esto elimina la carpeta del addon. Sus ajustes se conservan. + + %1$d addon + %1$d de addons + %1$d addons + Nunca jugado Runtime ocupado · %1$d%% Runtime ocupado @@ -1369,6 +1378,18 @@ Se importaron %1$d archivos del %2$s en %3$s. Copia de las partidas anteriores en Download/DroidDeck/Saves/backups Se importaron %1$d archivos del %2$s en %3$s. Copia de las partidas anteriores en Download/DroidDeck/Saves/backups + Cierra primero la sesión para que el juego no use sus addons durante la importación + Importando addons en %1$s + Elige un zip de addons para %1$s + %1$s es demasiado grande para importarlo + Eliminando %1$s + Se eliminó %1$s + No se encontraron addons en %1$s + + Se importó %1$d addon en %2$s + Se importaron %1$d de addons en %2$s + Se importaron %1$d addons en %2$s + Elige un zip de partidas guardadas para %1$s Exportando %1$s @@ -3508,6 +3529,7 @@ Steam Cloud Para juegos con partidas guardadas en tu cuenta de Steam Búsqueda web + Addons Instalar Ubicación Carpeta diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 921ab377cf..06dd2d1a1e 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -1183,6 +1183,14 @@ Vie GameHub-zipinä… Vie Winlator-zipinä… Avaa tallennuskansio + Tuo lisäosat zip-tiedostosta… + Avaa lisäosakansio + Poistetaanko %1$s? + Tämä poistaa lisäosan kansion. Sen asetukset säilyvät. + + %1$d lisäosa + %1$d lisäosaa + Ei pelattu koskaan Ajoympäristö varattu · %1$d %% Ajoympäristö varattu @@ -1361,6 +1369,17 @@ Tuotiin %1$d tiedosto %2$s-muodosta kohteeseen %3$s. Vanhat tallennukset varmuuskopioitu kansioon Download/DroidDeck/Saves/backups Tuotiin %1$d tiedostoa %2$s-muodosta kohteeseen %3$s. Vanhat tallennukset varmuuskopioitu kansioon Download/DroidDeck/Saves/backups + Sulje istunto ensin, jotta peli ei käytä lisäosiaan tuonnin aikana + Tuodaan lisäosia kohteeseen %1$s + Valitse lisäosien zip-tiedosto kohteelle %1$s + %1$s on liian suuri tuotavaksi + Poistetaan %1$s + %1$s poistettu + Lisäosia ei löytynyt kohteesta %1$s + + Tuotiin %1$d lisäosa kohteeseen %2$s + Tuotiin %1$d lisäosaa kohteeseen %2$s + Valitse tallennusten zip-tiedosto kohteelle %1$s Viedään %1$s @@ -3472,6 +3491,7 @@ Steam Cloud Peleille, joiden tallennukset ovat Steam-tililläsi Verkkohaku + Lisäosat Asenna Sijainti Kansio diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 3c3a65ebf9..7a2200fa92 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1189,6 +1189,15 @@ Exporter en tant qu\'archive GameHub… Exporter en tant qu\'archive Winlator… Ouvrir le dossier de sauvegarde + Importer des addons depuis un zip… + Ouvrir le dossier des addons + Supprimer %1$s ? + Cela supprime le dossier de l\'addon. Ses paramètres sont conservés. + + %1$d addon + %1$d d\'addons + %1$d addons + Jamais lancé Environnement d\'exécution occupé · %1$d%% Environnement d\'exécution occupé @@ -1369,6 +1378,18 @@ %1$d fichiers importés (%2$s) dans %3$s. Anciennes sauvegardes copiées dans Download/DroidDeck/Saves/backups %1$d fichiers importés (%2$s) dans %3$s. Anciennes sauvegardes copiées dans Download/DroidDeck/Saves/backups + Fermez d\'abord la session, pour que le jeu n\'utilise pas ses addons pendant l\'importation + Importation des addons dans %1$s + Choisir un zip d\'addons pour %1$s + %1$s est trop volumineux pour être importé + Suppression de %1$s + %1$s supprimé + Aucun addon trouvé dans %1$s + + %1$d addon importé dans %2$s + %1$d d\'addons importés dans %2$s + %1$d addons importés dans %2$s + Choisir un zip de sauvegarde pour %1$s Exportation de %1$s @@ -3508,6 +3529,7 @@ Steam Cloud Pour les jeux dont les sauvegardes sont sur votre compte Steam Recherche web + Addons Installer Emplacement Dossier diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 68fe010453..0005d2dfad 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -1183,6 +1183,14 @@ GameHub zip के रूप में एक्सपोर्ट करें… Winlator zip के रूप में एक्सपोर्ट करें… सेव फ़ोल्डर खोलें + zip से ऐडऑन इंपोर्ट करें… + ऐडऑन फ़ोल्डर खोलें + %1$s हटाएं? + यह ऐडऑन का फ़ोल्डर हटा देता है। इसकी सेटिंग्स बनी रहती हैं। + + %1$d ऐडऑन + %1$d ऐडऑन + कभी नहीं खेला रनटाइम व्यस्त · %1$d%% रनटाइम व्यस्त @@ -1361,6 +1369,17 @@ %2$s से %1$d फ़ाइल %3$s में इंपोर्ट हुई। पुराने सेव Download/DroidDeck/Saves/backups में बैकअप हो गए %2$s से %1$d फ़ाइलें %3$s में इंपोर्ट हुईं। पुराने सेव Download/DroidDeck/Saves/backups में बैकअप हो गए + पहले सेशन बंद करें, ताकि इंपोर्ट के दौरान गेम अपने ऐडऑन का उपयोग न करे + %1$s में ऐडऑन इंपोर्ट हो रहे हैं + %1$s के लिए ऐडऑन zip चुनें + %1$s इंपोर्ट करने के लिए बहुत बड़ा है + %1$s हटाया जा रहा है + %1$s हटाया गया + %1$s में कोई ऐडऑन नहीं मिला + + %1$d ऐडऑन %2$s में इंपोर्ट हुआ + %1$d ऐडऑन %2$s में इंपोर्ट हुए + %1$s के लिए एक सेव zip चुनें %1$s एक्सपोर्ट हो रहा है @@ -3472,6 +3491,7 @@ Steam Cloud उन गेम के लिए जिनके सेव आपके Steam अकाउंट पर हैं वेब सर्च + ऐडऑन इंस्टॉल करें जगह फ़ोल्डर diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index cc32a257af..86fe25afa8 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -1183,6 +1183,14 @@ Exportálás GameHub zipként… Exportálás Winlator zipként… Mentésmappa megnyitása + Kiegészítők importálása zipből… + Kiegészítők mappájának megnyitása + Törlöd ezt: %1$s? + Ez törli a kiegészítő mappáját. A beállításai megmaradnak. + + %1$d kiegészítő + %1$d kiegészítő + Még nem játszott Futtatókörnyezet dolgozik · %1$d%% Futtatókörnyezet dolgozik @@ -1361,6 +1369,17 @@ %1$d fájl importálva innen: %2$s, ide: %3$s. A régi mentések mentve itt: Download/DroidDeck/Saves/backups %1$d fájl importálva innen: %2$s, ide: %3$s. A régi mentések mentve itt: Download/DroidDeck/Saves/backups + Előbb zárja be a munkamenetet, hogy a játék ne használja a kiegészítőit az importálás alatt + Kiegészítők importálása ide: %1$s + Válasszon kiegészítő zip fájlt ehhez: %1$s + A(z) %1$s túl nagy az importáláshoz + %1$s törlése folyamatban + %1$s törölve + Nem található kiegészítő itt: %1$s + + %1$d kiegészítő importálva ide: %2$s + %1$d kiegészítő importálva ide: %2$s + Válasszon mentés zip fájlt ehhez: %1$s %1$s exportálása @@ -3472,6 +3491,7 @@ Steam Cloud A Steam-fiókjában mentéseket tároló játékokhoz Webes keresés + Kiegészítők Telepítés Hely Mappa diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 1ef496df4b..0aa46114f7 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -1177,6 +1177,13 @@ Ekspor sebagai zip GameHub… Ekspor sebagai zip Winlator… Buka folder simpanan + Impor addon dari zip… + Buka folder addon + Hapus %1$s? + Ini menghapus folder addon. Pengaturannya tetap ada. + + %1$d addon + Belum pernah dimainkan Runtime sibuk · %1$d%% Runtime sibuk @@ -1353,6 +1360,16 @@ %1$d file diimpor dari %2$s ke %3$s. Save lama dicadangkan ke Download/DroidDeck/Saves/backups + Tutup sesi dulu, agar game tidak memakai addon-nya saat impor + Mengimpor addon ke %1$s + Pilih zip addon untuk %1$s + %1$s terlalu besar untuk diimpor + Menghapus %1$s + %1$s dihapus + Tidak ada addon di %1$s + + %1$d addon diimpor ke %2$s + Pilih zip save untuk %1$s Mengekspor %1$s @@ -3445,6 +3462,7 @@ Steam Cloud Untuk gim dengan save di akun Steam Anda Penelusuran web + Addon Pasang Lokasi Folder diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index a1419b704c..4f816b30b9 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1181,6 +1181,15 @@ Esporta come zip GameHub… Esporta come zip Winlator… Apri cartella di salvataggio + Importa addon da zip… + Apri cartella degli addon + Eliminare %1$s? + Questo rimuove la cartella dell\'addon. Le sue impostazioni restano. + + %1$d addon + %1$d di addon + %1$d addon + Mai giocato Runtime occupato · %1$d%% Runtime occupato @@ -1361,6 +1370,18 @@ %1$d file importati (%2$s) in %3$s. Backup dei vecchi salvataggi in Download/DroidDeck/Saves/backups %1$d file importati (%2$s) in %3$s. Backup dei vecchi salvataggi in Download/DroidDeck/Saves/backups + Chiudi prima la sessione, così il gioco non usa i suoi addon durante l\'importazione + Importazione degli addon in %1$s + Scegli uno zip di addon per %1$s + %1$s è troppo grande per essere importato + Eliminazione di %1$s + %1$s eliminato + Nessun addon trovato in %1$s + + %1$d addon importato in %2$s + %1$d di addon importati in %2$s + %1$d addon importati in %2$s + Scegli uno zip di salvataggi per %1$s Esportazione di %1$s @@ -3508,6 +3529,7 @@ Steam Cloud Per i giochi con salvataggi nel tuo account Steam Ricerca web + Addon Installa Posizione Cartella diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index b5a2fc424c..f72c30c8be 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -1177,6 +1177,13 @@ GameHubアーカイブとしてエクスポート… Winlatorアーカイブとしてエクスポート… セーブフォルダを開く + zipからアドオンをインポート… + アドオンフォルダを開く + %1$sを削除しますか? + アドオンのフォルダが削除されます。設定は残ります。 + + %1$d個のアドオン + 未プレイ 実行環境は使用中 · %1$d%% 実行環境は使用中 @@ -1353,6 +1360,16 @@ %2$sから%1$d個のファイルを%3$sにインポートしました。以前のセーブデータはDownload/DroidDeck/Saves/backupsにバックアップされました + インポート中にゲームがアドオンを使用しないよう、先にセッションを終了してください + %1$sにアドオンをインポート中 + %1$sのアドオンzipを選択 + %1$s は大きすぎるためインポートできません + %1$sを削除中 + %1$sを削除しました + %1$sにアドオンが見つかりません + + %1$d個のアドオンを%2$sにインポートしました + %1$sのセーブデータzipを選択 %1$sをエクスポート中 @@ -3445,6 +3462,7 @@ Steam Cloud Steamアカウントにセーブデータがあるゲーム向け ウェブ検索 + アドオン インストール 場所 フォルダ diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 4ede4632a3..16d3a1e5c3 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -1177,6 +1177,13 @@ GameHub 아카이브로 내보내기… Winlator 아카이브로 내보내기… 저장 폴더 열기 + zip에서 애드온 가져오기… + 애드온 폴더 열기 + %1$s을(를) 삭제할까요? + 애드온 폴더가 삭제됩니다. 설정은 유지됩니다. + + 애드온 %1$d개 + 플레이한 적 없음 런타임 사용 중 · %1$d%% 런타임 사용 중 @@ -1353,6 +1360,16 @@ %2$s에서 %3$s(으)로 파일 %1$d개를 가져왔습니다. 이전 저장 데이터는 Download/DroidDeck/Saves/backups에 백업되었습니다 + 가져오는 동안 게임이 애드온을 사용하지 않도록 먼저 세션을 종료하세요 + %1$s(으)로 애드온 가져오는 중 + %1$s의 애드온 zip 선택 + %1$s은(는) 너무 커서 가져올 수 없습니다 + %1$s 삭제 중 + %1$s 삭제됨 + %1$s에서 애드온을 찾을 수 없습니다 + + 애드온 %1$d개를 %2$s(으)로 가져왔습니다 + %1$s의 저장 데이터 zip 선택 %1$s 내보내는 중 @@ -3445,6 +3462,7 @@ Steam Cloud Steam 계정에 저장 파일이 있는 게임용 웹 검색 + 애드온 설치 위치 폴더 diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 4dcdb4e3fc..14dc814a73 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -1177,6 +1177,13 @@ Eksport sebagai zip GameHub… Eksport sebagai zip Winlator… Buka folder simpanan + Import addon daripada zip… + Buka folder addon + Padam %1$s? + Ini memadam folder addon. Tetapannya kekal. + + %1$d addon + Belum pernah dimainkan Masa jalan sibuk · %1$d%% Masa jalan sibuk @@ -1353,6 +1360,16 @@ Mengimport %1$d fail daripada %2$s ke %3$s. Simpanan lama disandarkan ke Download/DroidDeck/Saves/backups + Tutup sesi dahulu, supaya permainan tidak menggunakan addonnya semasa import + Mengimport addon ke %1$s + Pilih zip addon untuk %1$s + %1$s terlalu besar untuk diimport + Memadam %1$s + %1$s dipadam + Tiada addon ditemui dalam %1$s + + Berjaya mengimport %1$d addon ke %2$s + Pilih zip simpanan untuk %1$s Mengeksport %1$s @@ -3445,6 +3462,7 @@ Steam Cloud Untuk permainan dengan simpanan pada akaun Steam anda Carian web + Addon Pasang Lokasi Folder diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index a2b8f0ed8a..7a644c67e9 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -1183,6 +1183,14 @@ Eksporter som GameHub-zip… Eksporter som Winlator-zip… Åpne lagringsmappe + Importer tillegg fra zip… + Åpne tilleggsmappe + Slett %1$s? + Dette fjerner tilleggets mappe. Innstillingene beholdes. + + %1$d tillegg + %1$d tillegg + Aldri spilt Kjøretid opptatt · %1$d%% Kjøretid opptatt @@ -1361,6 +1369,17 @@ Importerte %1$d fil fra %2$s til %3$s. Gamle lagringer sikkerhetskopiert til Download/DroidDeck/Saves/backups Importerte %1$d filer fra %2$s til %3$s. Gamle lagringer sikkerhetskopiert til Download/DroidDeck/Saves/backups + Lukk sesjonen først, så spillet ikke bruker tilleggene under importen + Importerer tillegg til %1$s + Velg en zip med tillegg for %1$s + %1$s er for stor til å importeres + Sletter %1$s + Slettet %1$s + Fant ingen tillegg i %1$s + + Importerte %1$d tillegg til %2$s + Importerte %1$d tillegg til %2$s + Velg en lagrings-zip for %1$s Eksporterer %1$s @@ -3472,6 +3491,7 @@ Steam Cloud For spill med lagringer på Steam-kontoen din Nettsøk + Tillegg Installer Plassering Mappe diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index aacc9dd20e..26caeb73c8 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -1183,6 +1183,14 @@ Exporteren als GameHub-zip… Exporteren als Winlator-zip… Opslagmap openen + Addons importeren uit zip… + Addonmap openen + %1$s verwijderen? + Hiermee wordt de map van de addon verwijderd. De instellingen blijven behouden. + + %1$d addon + %1$d addons + Nooit gespeeld Runtime bezig · %1$d%% Runtime bezig @@ -1361,6 +1369,17 @@ %1$d bestand uit de %2$s geïmporteerd in %3$s. Oude savegames als back-up bewaard in Download/DroidDeck/Saves/backups %1$d bestanden uit de %2$s geïmporteerd in %3$s. Oude savegames als back-up bewaard in Download/DroidDeck/Saves/backups + Sluit eerst de sessie, zodat de game tijdens de import geen addons gebruikt + Addons importeren in %1$s + Kies een addon-zip voor %1$s + %1$s is te groot om te importeren + %1$s wordt verwijderd + %1$s verwijderd + Geen addons gevonden in %1$s + + %1$d addon geïmporteerd in %2$s + %1$d addons geïmporteerd in %2$s + Kies een savegame-zip voor %1$s %1$s exporteren @@ -3472,6 +3491,7 @@ Steam Cloud Voor games met opslagbestanden in je Steam-account Zoeken op het web + Addons Installeren Locatie Map diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index bf3d93d8b9..2304171da3 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -1195,6 +1195,16 @@ Eksportuj jako zip GameHub… Eksportuj jako zip Winlator… Otwórz folder zapisów + Importuj dodatki z zip… + Otwórz folder dodatków + Usunąć %1$s? + Spowoduje to usunięcie folderu dodatku. Jego ustawienia zostaną zachowane. + + %1$d dodatek + %1$d dodatki + %1$d dodatków + %1$d dodatku + Nigdy nie grano Środowisko zajęte · %1$d%% Środowisko zajęte @@ -1377,6 +1387,19 @@ Zaimportowano %1$d plików z %2$s do %3$s. Kopię starych zapisów umieszczono w Download/DroidDeck/Saves/backups Zaimportowano %1$d pliku z %2$s do %3$s. Kopię starych zapisów umieszczono w Download/DroidDeck/Saves/backups + Najpierw zamknij sesję, aby gra nie używała dodatków podczas importu + Importowanie dodatków do %1$s + Wybierz plik zip z dodatkami dla %1$s + Plik %1$s jest za duży, aby go zaimportować + Usuwanie: %1$s + Usunięto: %1$s + Nie znaleziono dodatków w %1$s + + Zaimportowano %1$d dodatek do %2$s + Zaimportowano %1$d dodatki do %2$s + Zaimportowano %1$d dodatków do %2$s + Zaimportowano %1$d dodatku do %2$s + Wybierz plik zip z zapisami dla %1$s Eksportowanie %1$s @@ -3544,6 +3567,7 @@ Steam Cloud Dla gier z zapisami na Twoim koncie Steam Wyszukiwanie w sieci + Dodatki Zainstaluj Lokalizacja Folder diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index ca404e28fb..43cb70df8c 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -1181,6 +1181,15 @@ Exportar como zip do GameHub… Exportar como zip do Winlator… Abrir pasta de gravações + Importar addons de zip… + Abrir pasta de addons + Eliminar %1$s? + Isto elimina a pasta do addon. As definições dele mantêm-se. + + %1$d addon + %1$d de addons + %1$d addons + Nunca jogado Ambiente de execução ocupado · %1$d%% Ambiente de execução ocupado @@ -1361,6 +1370,18 @@ %1$d ficheiros importados do %2$s para %3$s. Cópia de segurança dos dados guardados antigos em Download/DroidDeck/Saves/backups %1$d ficheiros importados do %2$s para %3$s. Cópia de segurança dos dados guardados antigos em Download/DroidDeck/Saves/backups + Feche primeiro a sessão, para que o jogo não use os addons durante a importação + A importar addons para %1$s + Escolha um zip de addons para %1$s + %1$s é demasiado grande para importar + A eliminar %1$s + %1$s eliminado + Nenhum addon encontrado em %1$s + + %1$d addon importado para %2$s + %1$d de addons importados para %2$s + %1$d addons importados para %2$s + Escolha um zip de dados guardados para %1$s A exportar %1$s @@ -3508,6 +3529,7 @@ Steam Cloud Para jogos com guardados na sua conta Steam Pesquisa na Web + Addons Instalar Localização Pasta diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 5376a6f731..ba5bbf1479 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -1181,6 +1181,15 @@ Exportar como zip do GameHub… Exportar como zip do Winlator… Abrir pasta de jogos salvos + Importar addons de zip… + Abrir pasta de addons + Excluir %1$s? + Isso remove a pasta do addon. As configurações dele permanecem. + + %1$d addon + %1$d de addons + %1$d addons + Nunca jogado Runtime ocupado · %1$d%% Runtime ocupado @@ -1361,6 +1370,18 @@ %1$d arquivos importados de %2$s para %3$s. Backup dos saves antigos em Download/DroidDeck/Saves/backups %1$d arquivos importados de %2$s para %3$s. Backup dos saves antigos em Download/DroidDeck/Saves/backups + Feche a sessão primeiro, para que o jogo não use os addons durante a importação + Importando addons para %1$s + Escolha um zip de addons para %1$s + %1$s é grande demais para importar + Excluindo %1$s + %1$s excluído + Nenhum addon encontrado em %1$s + + %1$d addon importado para %2$s + %1$d de addons importados para %2$s + %1$d addons importados para %2$s + Escolha um zip de saves para %1$s Exportando %1$s @@ -3508,6 +3529,7 @@ Steam Cloud Para jogos com salvamentos na sua conta Steam Pesquisa na web + Addons Instalar Local Pasta diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index 0104424cd5..dd0580d81a 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -1189,6 +1189,15 @@ Exportă ca arhivă GameHub… Exportă ca arhivă Winlator… Deschide folderul de salvare + Importă suplimente din zip… + Deschide folderul de suplimente + Ștergi %1$s? + Aceasta șterge folderul suplimentului. Setările sale rămân. + + %1$d supliment + %1$d suplimente + %1$d de suplimente + Niciodată jucat Mediu de execuție ocupat · %1$d%% Mediu de execuție ocupat @@ -1369,6 +1378,18 @@ S-au importat %1$d fișiere din %2$s în %3$s. Salvările vechi au fost copiate de rezervă în Download/DroidDeck/Saves/backups S-au importat %1$d de fișiere din %2$s în %3$s. Salvările vechi au fost copiate de rezervă în Download/DroidDeck/Saves/backups + Închide mai întâi sesiunea, ca jocul să nu folosească suplimentele în timpul importului + Se importă suplimente în %1$s + Alege o arhivă zip de suplimente pentru %1$s + %1$s este prea mare pentru a fi importat + Se șterge %1$s + S-a șters %1$s + Nu s-au găsit suplimente în %1$s + + S-a importat %1$d supliment în %2$s + S-au importat %1$d suplimente în %2$s + S-au importat %1$d de suplimente în %2$s + Alege o arhivă de salvare pentru %1$s Se exportă %1$s @@ -3508,6 +3529,7 @@ Steam Cloud Pentru jocurile cu salvări în contul tău Steam Căutare pe web + Suplimente Instalează Locație Folder diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 38d47aa156..55287bdd9c 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -1195,6 +1195,16 @@ Экспорт как архив GameHub… Экспорт как архив Winlator… Открыть папку сохранений + Импорт аддонов из zip… + Открыть папку аддонов + Удалить %1$s? + Папка аддона будет удалена. Его настройки сохранятся. + + %1$d аддон + %1$d аддона + %1$d аддонов + %1$d аддона + Никогда не запускалась Среда выполнения занята · %1$d%% Среда выполнения занята @@ -1377,6 +1387,19 @@ Импортировано %1$d файлов (%2$s) в %3$s. Старые сохранения скопированы в Download/DroidDeck/Saves/backups Импортировано %1$d файла (%2$s) в %3$s. Старые сохранения скопированы в Download/DroidDeck/Saves/backups + Сначала закройте сессию, чтобы игра не использовала аддоны во время импорта + Импорт аддонов в %1$s + Выберите zip-архив аддонов для %1$s + %1$s слишком большой для импорта + Удаление: %1$s + Удалено: %1$s + Аддоны не найдены в %1$s + + Импортирован %1$d аддон в %2$s + Импортировано %1$d аддона в %2$s + Импортировано %1$d аддонов в %2$s + Импортировано %1$d аддона в %2$s + Выберите zip-архив сохранений для %1$s Экспорт %1$s @@ -3544,6 +3567,7 @@ Steam Cloud Для игр с сохранениями в аккаунте Steam Поиск в интернете + Аддоны Установить Расположение Папка diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index f94dc7d290..6de4336e33 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -1183,6 +1183,14 @@ Exportera som GameHub-zip… Exportera som Winlator-zip… Öppna sparmappen + Importera tillägg från zip… + Öppna tilläggsmappen + Ta bort %1$s? + Detta tar bort tilläggets mapp. Inställningarna behålls. + + %1$d tillägg + %1$d tillägg + Aldrig spelat Körmiljö upptagen · %1$d %% Körmiljö upptagen @@ -1361,6 +1369,17 @@ Importerade %1$d fil från %2$s till %3$s. Gamla sparfiler säkerhetskopierades till Download/DroidDeck/Saves/backups Importerade %1$d filer från %2$s till %3$s. Gamla sparfiler säkerhetskopierades till Download/DroidDeck/Saves/backups + Stäng sessionen först, så att spelet inte använder sina tillägg under importen + Importerar tillägg till %1$s + Välj en zip-fil med tillägg för %1$s + %1$s är för stor för att importeras + Tar bort %1$s + Tog bort %1$s + Inga tillägg hittades i %1$s + + Importerade %1$d tillägg till %2$s + Importerade %1$d tillägg till %2$s + Välj en zip-fil med sparfiler för %1$s Exporterar %1$s @@ -3472,6 +3491,7 @@ Steam Cloud För spel med sparningar på ditt Steam-konto Webbsökning + Tillägg Installera Plats Mapp diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index faaf350e24..538a3817d0 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -1177,6 +1177,13 @@ ส่งออกเป็น GameHub zip… ส่งออกเป็น Winlator zip… เปิดโฟลเดอร์เซฟ + นำเข้าแอดออนจาก zip… + เปิดโฟลเดอร์แอดออน + ลบ %1$s ไหม + การดำเนินการนี้จะลบโฟลเดอร์ของแอดออน ส่วนการตั้งค่ายังคงอยู่ + + %1$d แอดออน + ยังไม่เคยเล่น รันไทม์กำลังทำงาน · %1$d%% รันไทม์กำลังทำงาน @@ -1353,6 +1360,16 @@ นำเข้า %1$d ไฟล์จาก %2$s สู่ %3$s แล้ว เซฟเก่าสำรองไว้ที่ Download/DroidDeck/Saves/backups + ปิดเซสชันก่อน เพื่อไม่ให้เกมใช้แอดออนระหว่างการนำเข้า + กำลังนำเข้าแอดออนสู่ %1$s + เลือกไฟล์ zip แอดออนสำหรับ %1$s + %1$s มีขนาดใหญ่เกินกว่าจะนำเข้าได้ + กำลังลบ %1$s + ลบ %1$s แล้ว + ไม่พบแอดออนใน %1$s + + นำเข้า %1$d แอดออนสู่ %2$s แล้ว + เลือกไฟล์ zip เซฟสำหรับ %1$s กำลังส่งออก %1$s @@ -3445,6 +3462,7 @@ Steam Cloud สำหรับเกมที่มีเซฟอยู่ในบัญชี Steam ของคุณ ค้นหาเว็บ + แอดออน ติดตั้ง ตำแหน่ง โฟลเดอร์ diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 1b5613944b..8a864ce992 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -1175,6 +1175,14 @@ GameHub zip\'i olarak dışa aktar… Winlator zip\'i olarak dışa aktar… Kayıt klasörünü aç + Eklentileri zip\'ten içe aktar… + Eklentiler klasörünü aç + %1$s silinsin mi? + Bu işlem eklentinin klasörünü kaldırır. Ayarları korunur. + + %1$d eklenti + %1$d eklenti + Hiç oynanmadı Çalışma ortamı meşgul · %1$d%% Çalışma ortamı meşgul @@ -1353,6 +1361,17 @@ %2$s içinden %1$d dosya %3$s oyununa aktarıldı. Eski kayıtlar Download/DroidDeck/Saves/backups klasörüne yedeklendi %2$s içinden %1$d dosya %3$s oyununa aktarıldı. Eski kayıtlar Download/DroidDeck/Saves/backups klasörüne yedeklendi + Önce oturumu kapatın; böylece oyun içe aktarma sırasında eklentilerini kullanmaz + Eklentiler içe aktarılıyor: %1$s + %1$s için bir eklenti zip dosyası seçin + %1$s içe aktarılamayacak kadar büyük + %1$s siliniyor + %1$s silindi + %1$s içinde eklenti bulunamadı + + %1$d eklenti %2$s oyununa aktarıldı + %1$d eklenti %2$s oyununa aktarıldı + %1$s için bir kayıt zip dosyası seçin Dışa aktarılıyor: %1$s @@ -3472,6 +3491,7 @@ Steam Cloud Kayıtları Steam hesabınızda olan oyunlar için Web\'de ara + Eklentiler Yükle Konum Klasör diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index d80343472b..e317a43f64 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -1195,6 +1195,16 @@ Експортувати як zip GameHub… Експортувати як zip Winlator… Відкрити папку збережень + Імпортувати аддони з zip… + Відкрити папку аддонів + Видалити %1$s? + Папку аддона буде видалено. Його налаштування збережуться. + + %1$d аддон + %1$d аддони + %1$d аддонів + %1$d аддона + Ще не грали Середовище зайняте · %1$d%% Середовище зайняте @@ -1377,6 +1387,19 @@ Імпортовано %1$d файлів з %2$s у %3$s. Резервну копію старих збережень записано в Download/DroidDeck/Saves/backups Імпортовано %1$d файлу з %2$s у %3$s. Резервну копію старих збережень записано в Download/DroidDeck/Saves/backups + Спершу закрийте сеанс, щоб гра не використовувала аддони під час імпорту + Імпорт аддонів у %1$s + Виберіть zip-архів аддонів для %1$s + %1$s завеликий для імпорту + Видалення: %1$s + Видалено: %1$s + Аддони не знайдено в %1$s + + Імпортовано %1$d аддон у %2$s + Імпортовано %1$d аддони в %2$s + Імпортовано %1$d аддонів у %2$s + Імпортовано %1$d аддона в %2$s + Виберіть zip-архів збережень для %1$s Експорт %1$s @@ -3544,6 +3567,7 @@ Steam Cloud Для ігор зі збереженнями в обліковому записі Steam Пошук в інтернеті + Аддони Установити Розташування Папка diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 6a2d94d83a..7af05a293b 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -1177,6 +1177,13 @@ Xuất dưới dạng zip GameHub… Xuất dưới dạng zip Winlator… Mở thư mục lưu + Nhập addon từ zip… + Mở thư mục addon + Xóa %1$s? + Thao tác này xóa thư mục của addon. Cài đặt của addon vẫn được giữ lại. + + %1$d addon + Chưa chơi bao giờ Runtime đang bận · %1$d%% Runtime đang bận @@ -1353,6 +1360,16 @@ Đã nhập %1$d tệp từ %2$s vào %3$s. Tệp lưu cũ đã được sao lưu vào Download/DroidDeck/Saves/backups + Hãy đóng phiên trước, để game không dùng addon trong lúc nhập + Đang nhập addon vào %1$s + Chọn một tệp zip addon cho %1$s + %1$s quá lớn để nhập + Đang xóa %1$s + Đã xóa %1$s + Không tìm thấy addon nào trong %1$s + + Đã nhập %1$d addon vào %2$s + Chọn một tệp zip lưu cho %1$s Đang xuất %1$s @@ -3445,6 +3462,7 @@ Steam Cloud Cho game có bản lưu trong tài khoản Steam của bạn Tìm kiếm trên web + Addon Cài đặt Vị trí Thư mục diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 4d23bbf244..34d9c50231 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -1261,6 +1261,13 @@ 导出为 GameHub zip 包… 导出为 Winlator zip 包… 打开存档文件夹 + 从 zip 导入插件… + 打开插件文件夹 + 删除 %1$s? + 这会移除插件的文件夹,其设置会保留。 + + %1$d 个插件 + 从未游玩 运行时繁忙 · %1$d%% 运行时繁忙 @@ -1437,6 +1444,16 @@ 已从 %2$s 导入 %1$d 个文件到 %3$s。旧存档已备份到 Download/DroidDeck/Saves/backups + 请先关闭会话,以免游戏在导入期间使用其插件 + 正在导入插件到 %1$s + 为 %1$s 选择插件 zip 包 + %1$s 太大,无法导入 + 正在删除 %1$s + 已删除 %1$s + 在 %1$s 中未找到插件 + + 已导入 %1$d 个插件到 %2$s + 为 %1$s 选择存档 zip 包 正在导出 %1$s @@ -3448,6 +3465,7 @@ Steam Cloud 适用于存档保存在 Steam 账户中的游戏 网页搜索 + 插件 安装 位置 文件夹 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index d1024c1c57..6df9a2425e 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1177,6 +1177,13 @@ 匯出為 GameHub zip… 匯出為 Winlator zip… 開啟存檔資料夾 + 從 zip 匯入外掛… + 開啟外掛資料夾 + 刪除 %1$s? + 這會移除外掛的資料夾,其設定會保留。 + + %1$d 個外掛 + 從未玩過 運行環境繁忙 · %1$d%% 運行環境繁忙 @@ -1353,6 +1360,16 @@ 已從 %2$s 匯入 %1$d 個檔案至 %3$s。舊存檔已備份至 Download/DroidDeck/Saves/backups + 請先關閉會話,以免遊戲在匯入期間使用外掛 + 正在匯入外掛至 %1$s + 選擇 %1$s 的外掛 zip + %1$s 太大,無法匯入 + 正在刪除 %1$s + 已刪除 %1$s + 在 %1$s 中找不到外掛 + + 已匯入 %1$d 個外掛至 %2$s + 為 %1$s 選擇存檔 zip 正在匯出 %1$s @@ -3445,6 +3462,7 @@ Steam Cloud 適用於存檔儲存在 Steam 帳戶中的遊戲 網上搜尋 + 外掛 安裝 位置 資料夾 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 3065f3a452..9e32ee2b54 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1177,6 +1177,13 @@ 匯出為 GameHub 壓縮檔… 匯出為 Winlator 壓縮檔… 開啟存檔資料夾 + 從 zip 匯入外掛… + 開啟外掛資料夾 + 刪除 %1$s? + 這會移除外掛的資料夾,其設定會保留。 + + %1$d 個外掛 + 從未執行 執行環境繁忙 · %1$d%% 執行環境繁忙 @@ -1353,6 +1360,16 @@ 已從 %2$s 匯入 %1$d 個檔案到 %3$s。舊存檔已備份到 Download/DroidDeck/Saves/backups + 請先關閉工作階段,以免遊戲在匯入期間使用外掛 + 正在匯入外掛到 %1$s + 選擇 %1$s 的外掛 zip + %1$s 太大,無法匯入 + 正在刪除 %1$s + 已刪除 %1$s + 在 %1$s 中找不到外掛 + + 已匯入 %1$d 個外掛到 %2$s + 選擇 %1$s 的存檔壓縮檔 正在匯出 %1$s @@ -3445,6 +3462,7 @@ Steam Cloud 適用於存檔儲存在 Steam 帳戶中的遊戲 網路搜尋 + 外掛 安裝 位置 資料夾 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 74312a921c..5ea9cf34c7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1317,6 +1317,14 @@ Export as GameHub zip… Export as Winlator zip… Open save folder + Import addons from zip… + Open addons folder + Delete %1$s? + This removes the addon\'s folder. Its settings stay. + + %1$d addon + %1$d addons + Never played Runtime busy · %1$d%% Runtime busy @@ -1504,6 +1512,17 @@ Imported %1$d file from the %2$s into %3$s. Old saves backed up to Download/DroidDeck/Saves/backups Imported %1$d files from the %2$s into %3$s. Old saves backed up to Download/DroidDeck/Saves/backups + Close the session first, so the game isn\'t using its addons during the import + Importing addons into %1$s + Choose an addon zip for %1$s + %1$s is too large to import + Deleting %1$s + Deleted %1$s + No addons found in %1$s + + Imported %1$d addon into %2$s + Imported %1$d addons into %2$s + Choose a save zip for %1$s Exporting %1$s @@ -3669,6 +3688,7 @@ Web search %1$s %2$d/%3$d Launch + Addons Saves & cloud Install Steam shortcut diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/WowAddonsTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/WowAddonsTest.kt new file mode 100644 index 0000000000..8350ef519b --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/runtime/WowAddonsTest.kt @@ -0,0 +1,221 @@ +package com.droiddeck.launcher.runtime + +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry +import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertThrows +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import java.io.File +import java.io.IOException +import java.nio.file.Files +import java.nio.file.LinkOption +import java.util.zip.ZipEntry +import java.util.zip.ZipOutputStream + +class WowAddonsTest { + @get:Rule val temp = TemporaryFolder() + + private fun zip(vararg files: Pair): File { + val file = temp.newFile("addon-${System.nanoTime()}.zip") + ZipOutputStream(file.outputStream()).use { out -> + for ((name, text) in files) { + out.putNextEntry(ZipEntry(name)) + out.write(text.toByteArray()) + out.closeEntry() + } + } + return file + } + + private fun target(): WowAddons.Target { + val root = temp.newFolder("World of Warcraft") + File(root, "_retail_").mkdirs() + return WowAddons.targets(BattleNet.title("wow")!!, root).single() + } + + private fun names(vararg files: String) = WowAddons.addons(files.toList()).map { it.name to it.root } + + @Test fun plainFoldersKeepTheirNames() { + assertEquals(listOf("Foo" to "Foo/", "Bar" to "Bar/"), names("Foo/Foo.toc", "Foo/a.lua", "Bar/Bar.toc")) + } + + @Test fun flavourTocsKeepTheFolderName() { + assertEquals(listOf("Foo" to "Foo/"), names("Foo/Foo_Mainline.toc", "Foo/Foo_Vanilla.toc", "Foo/Foo-Classic.toc")) + } + + @Test fun anAddonNamedLikeAFlavourStaysWhole() { + assertEquals(listOf("Foo_Classic" to "Foo_Classic/"), names("Foo_Classic/Foo_Classic.toc")) + } + + @Test fun sourceWrappersTakeTheTocName() { + assertEquals(listOf("Foo" to "Foo-main/"), names("Foo-main/Foo.toc", "Foo-main/README.md")) + assertEquals(listOf("Foo" to "Repo-1.2.3/"), names("Repo-1.2.3/Foo_Mainline.toc", "Repo-1.2.3/Foo_TBC.toc")) + } + + @Test fun packsAndGameFolderWrappersFindEveryAddon() { + assertEquals( + listOf("Foo" to "Interface/AddOns/Foo/", "Bar" to "Interface/AddOns/Bar/"), + names("Interface/AddOns/Foo/Foo.toc", "Interface/AddOns/Bar/Bar.toc"), + ) + } + + @Test fun bareFilesGetAFolder() { + assertEquals(listOf("Foo" to ""), names("Foo.toc", "core.lua")) + } + + @Test fun nestedTocsBelongToTheirAddon() { + assertEquals(listOf("Foo" to "Foo/"), names("Foo/Foo.toc", "Foo/Libs/Lib/Lib.toc")) + } + + @Test fun anAddonInTheFolderOfASimilarNameIsNotNested() { + assertEquals(listOf("Foo" to "Foo/", "FooOptions" to "FooOptions/"), names("Foo/Foo.toc", "FooOptions/FooOptions.toc")) + } + + @Test fun importsIntoInterfaceAddOns() { + val target = target() + val zip = zip("Foo-main/Foo.toc" to "toc", "Foo-main/sub/a.lua" to "lua", "__MACOSX/Foo-main/._Foo.toc" to "x") + assertEquals(listOf("Foo"), WowAddons.import(zip, target)) + assertEquals(File(target.addOns.parentFile, "AddOns"), target.addOns) + assertEquals("lua", File(target.addOns, "Foo/sub/a.lua").readText()) + assertEquals(listOf("Foo"), WowAddons.installed(target)) + assertEquals(listOf("AddOns"), target.addOns.parentFile!!.list()!!.toList()) + } + + @Test fun reimportReplacesTheFolderIgnoringCase() { + val target = target() + File(target.addOns, "foo").mkdirs() + File(target.addOns, "foo/stale.lua").writeText("old") + File(target.addOns, "Keep").mkdirs() + WowAddons.import(zip("Foo/Foo.toc" to "new"), target) + assertTrue(File(target.addOns, "Foo/Foo.toc").isFile) + assertFalse(File(target.addOns, "foo").exists()) + assertTrue(File(target.addOns, "Keep").isDirectory) + } + + @Test fun replacingALinkLeavesItsTargetAlone() { + val target = target() + val outside = temp.newFolder("outside") + File(outside, "keep.lua").writeText("keep") + target.addOns.mkdirs() + Files.createSymbolicLink(File(target.addOns, "Foo").toPath(), outside.toPath()) + WowAddons.import(zip("Foo/Foo.toc" to "new"), target) + assertEquals("keep", File(outside, "keep.lua").readText()) + assertFalse(Files.isSymbolicLink(File(target.addOns, "Foo").toPath())) + } + + @Test fun deletesOnlyTheChosenAddon() { + val target = target() + WowAddons.import(zip("Foo/Foo.toc" to "a", "Bar/Bar.toc" to "b"), target) + assertEquals(listOf("Bar", "Foo"), WowAddons.installed(target)) + WowAddons.delete(target, "Foo") + assertEquals(listOf("Bar"), WowAddons.installed(target)) + assertTrue(File(target.addOns, "Bar/Bar.toc").isFile) + } + + @Test fun deletingALinkLeavesItsTargetAlone() { + val target = target() + val outside = temp.newFolder("linked") + File(outside, "keep.lua").writeText("keep") + target.addOns.mkdirs() + Files.createSymbolicLink(File(target.addOns, "Foo").toPath(), outside.toPath()) + WowAddons.delete(target, "Foo") + assertFalse(Files.exists(File(target.addOns, "Foo").toPath(), LinkOption.NOFOLLOW_LINKS)) + assertEquals("keep", File(outside, "keep.lua").readText()) + } + + @Test fun onlyAFolderDirectlyInAddOnsCanBeDeleted() { + val target = target() + val outside = File(target.addOns.parentFile!!.parentFile, "Outside").apply { mkdirs() } + target.addOns.mkdirs() + assertThrows(IOException::class.java) { WowAddons.delete(target, "../../Outside") } + assertTrue(outside.isDirectory) + } + + @Test fun aFailedReplacementRestoresEarlierAddons() { + val base = temp.newFolder("swap") + val addOns = File(base, "AddOns").apply { mkdirs() } + File(addOns, "Foo").mkdirs() + File(addOns, "Foo/old.lua").writeText("old") + File(addOns, "Bar").mkdirs() + File(addOns, "Bar/old.lua").writeText("old") + val fresh = File(base, "fresh/Foo").apply { mkdirs() } + File(fresh, "new.lua").writeText("new") + val old = File(base, "old").apply { mkdirs() } + assertThrows(IOException::class.java) { + WowAddons.swap(listOf(fresh to "Foo", File(base, "fresh/Missing") to "Bar"), addOns, old) + } + assertEquals("old", File(addOns, "Foo/old.lua").readText()) + assertEquals("old", File(addOns, "Bar/old.lua").readText()) + assertFalse(File(addOns, "Foo/new.lua").exists()) + } + + @Test fun zipsWithoutAnAddonChangeNothing() { + val target = target() + assertEquals(emptyList(), WowAddons.import(zip("readme.txt" to "x"), target)) + assertFalse(target.addOns.exists()) + } + + @Test fun linkEntriesDoNotCountAsAddons() { + val target = target() + val file = temp.newFile("links.zip") + ZipArchiveOutputStream(file).use { out -> + val link = ZipArchiveEntry("Foo/Foo.toc").apply { unixMode = 0xA1FF } + out.putArchiveEntry(link) + out.write("/etc/passwd".toByteArray()) + out.closeArchiveEntry() + } + assertEquals(emptyList(), WowAddons.import(file, target)) + assertFalse(target.addOns.exists()) + } + + @Test fun aZipWithAnyLinkIsRefusedWhole() { + val target = target() + File(target.addOns, "Ace3").mkdirs() + File(target.addOns, "Ace3/keep.lua").writeText("keep") + val file = temp.newFile("nested.zip") + ZipArchiveOutputStream(file).use { out -> + out.putArchiveEntry(ZipArchiveEntry("Foo/Foo.toc").apply { unixMode = 0xA1FF }) + out.write("/etc/passwd".toByteArray()) + out.closeArchiveEntry() + out.putArchiveEntry(ZipArchiveEntry("Foo/Libs/Ace3/Ace3.toc")) + out.write("toc".toByteArray()) + out.closeArchiveEntry() + } + assertEquals(emptyList(), WowAddons.import(file, target)) + assertEquals("keep", File(target.addOns, "Ace3/keep.lua").readText()) + } + + @Test fun escapingEntriesAreNeverWritten() { + val target = target() + WowAddons.import(zip("Foo/Foo.toc" to "a", "../../evil.lua" to "x", "Foo/../../evil2.lua" to "x"), target) + val written = target.addOns.parentFile!!.parentFile!!.walkTopDown().map { it.name }.toList() + assertFalse("evil.lua" in written) + assertFalse("evil2.lua" in written) + assertTrue("Foo.toc" in written) + } + + @Test fun usesTheInstalledFlavourFolders() { + val root = temp.newFolder("wow") + listOf("_classic_", "_classic_era_", "_anniversary_", "_retail_").forEach { File(root, it).mkdirs() } + val classic = BattleNet.title("wow_classic")!! + assertEquals(setOf("_classic_", "_classic_era_", "_anniversary_"), WowAddons.targets(classic, root).map { it.flavor }.toSet()) + assertEquals(listOf("_retail_"), WowAddons.targets(BattleNet.title("wow")!!, File(root, "_retail_")).map { it.flavor }) + } + + @Test fun reusesAnExistingFolderSpelling() { + val root = temp.newFolder("wow2") + File(root, "_forever_/interface/addons").mkdirs() + val target = WowAddons.targets(BattleNet.title("wow_forever")!!, root).single() + assertEquals(File(root, "_forever_/interface/addons"), target.addOns) + } + + @Test fun otherGamesHaveNoTargets() { + val root = temp.newFolder("d4") + File(root, "_retail_").mkdirs() + assertEquals(emptyList(), WowAddons.targets(BattleNet.title("fenris")!!, root).map { it.flavor }) + } +} From 4c23092c55a6e446f7a5dc34f2544bbd28858c4f Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Thu, 5 Nov 2026 08:43:21 -0500 Subject: [PATCH 08/85] fix(components): repaired components reach prefixes that already have them (#2121) fix(components): the library sweep refreshes the catalog when it is safe to A game job reads the cached catalog, and the installed check compares against the cached revision, so a repaired component never reached a prefix that already had it. The sweep now fetches the catalog first when online and not on a metered or constrained connection. --- .../launcher/frontend/AutoComponents.kt | 1 + .../launcher/frontend/WinCompSourcesTest.kt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AutoComponents.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AutoComponents.kt index c68d8ed2ae..1359ecf953 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AutoComponents.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AutoComponents.kt @@ -516,6 +516,7 @@ object AutoComponents { fun refreshLater(context: Context, game: Library.SteamGame) = queueGame(context, game, asked = true) fun sweep(context: Context, games: List) { + if (online(context) && !unfavourable(context)) catalogOf(context, true) val apps = games.mapNotNull { steamAppOf(context, it) }.distinct() if (apps.isNotEmpty() && SteamAppInfo.needLookup(context, apps).isNotEmpty()) enqueue(context, Job(null, null, false, seq.incrementAndGet(), pics = apps)) games.forEach { queueGame(context, it, asked = false) } diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt index a1bb5b8365..409637e0cc 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt @@ -290,6 +290,24 @@ class WinCompSourcesTest { assertFalse(requests.first()) } + @Test fun aSweepRefreshesTheCatalogOnlyOnAFavourableConnection() = withFakeWorker { + installedNow.addAll(catalog3.map { it.name }) + val requests = ArrayList() + AutoComponents.catalogOf = { _, network -> requests.add(network); catalog3 } + val games = listOf(payback()) + AutoComponents.sweep(app, games) + assertTrue(requests.first()) + requests.clear() + AutoComponents.unfavourable = { true } + AutoComponents.sweep(app, games) + assertFalse(requests.contains(true)) + requests.clear() + AutoComponents.unfavourable = { false } + AutoComponents.online = { false } + AutoComponents.sweep(app, games) + assertFalse(requests.contains(true)) + } + @Test fun aSteamListedComponentNotYetDownloadedTurnsOnWhenItLands() = withFakeWorker { installedNow.add("d3dx9") val game = payback() From d4fe440b49e761a728dfccbd4e27bbea1ad33265 Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Thu, 5 Nov 2026 08:43:24 -0500 Subject: [PATCH 09/85] docs: README install step links the current APK (#2122) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b834ff00d..e9f172bfa1 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ DroidDeck brings the SteamOS experience to Android: Steam Gaming Mode, full Linu 1. Android 9 or newer on Adreno 730 or newer, or any 8xx. Adreno 6xx is experimental. Mali, Xclipse, PowerVR and Adreno 710 are unsupported. No root needed. 2. About 3 GB free for the runtime, plus 1.1 GB for the desktop and emulators. -3. Install the [APK](https://github.com/Droid-Deck/DroidDeck/releases/download/0.6.7/DroidDeck-0.6.7.apk), install the Linux runtime, press **Play** and sign in to Steam. +3. Install the [APK](https://github.com/Droid-Deck/DroidDeck/releases/download/0.6.9/DroidDeck-0.6.9.apk), install the Linux runtime, press **Play** and sign in to Steam. 4. On Android 14 and newer, turn on **Disable child process restrictions** in Developer options. On Android 12 and 13, Steam's first launch shows a **Fix it for me** button that walks you through it. Smart glasses setup is in the [support matrix](docs/smart-glasses-support.md). Release notes are in [docs/releases](docs/releases). From e1c2b0e34086a297e8383f2346000939a628ce0a Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 09:38:38 -0500 Subject: [PATCH 10/85] ci: trust ASEbrahim for signed test builds (#2124) --- .github/trusted-test-builds.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/trusted-test-builds.txt b/.github/trusted-test-builds.txt index f91528f395..8f7b0148c5 100644 --- a/.github/trusted-test-builds.txt +++ b/.github/trusted-test-builds.txt @@ -1,3 +1,4 @@ +ASEbrahim FX192 K11MCH1 kingokksa From 26c562c1744a0fe7d579b2dd37ed4494c72a372a Mon Sep 17 00:00:00 2001 From: kmnkv1 <95131920+kmnkv1@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:44:45 +0700 Subject: [PATCH 11/85] fix(stores): moving through the side menu no longer freezes the launcher (#2105) --- .../droiddeck/launcher/stores/StoresState.kt | 46 ++++--- .../launcher/stores/gog/GogMaintenance.kt | 2 +- .../launcher/stores/StoresStateRefreshTest.kt | 127 ++++++++++++++++++ 3 files changed, 155 insertions(+), 20 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/stores/StoresStateRefreshTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt index f28c402e8e..e7a9383f32 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt @@ -74,29 +74,36 @@ object StoresState { fun register(backend: StoreBackend) { backends[backend.store] = backend } + private val refreshRequests = java.util.concurrent.atomic.AtomicInteger() + fun refresh(context: Context) { val app = context.applicationContext com.droiddeck.launcher.stores.download.SavedQueue.restore(app) - background("stores-refresh") { - runCatching { com.droiddeck.launcher.stores.battlenet.BattleNetClient.syncAccount(app) } - val found = Store.entries.mapNotNull { store -> StoreAccounts.displayName(app, store)?.let { store to it } } - val onDisk = StoreInstallRoot.gameFolders(app).mapNotNull { folder -> - StoreGameSidecar.read(folder)?.takeIf { it.isInstalled || it.state == StoreGameSidecar.STATE_UPDATING }?.let { InstalledStoreGame(it, folder) } - } + runCatching { com.droiddeck.launcher.stores.battlenet.BattleNetBackend.installedGames(app) }.getOrDefault(emptyList()) - val partial = StoreInstallRoot.unfinished(app) - val version = if (StoresNative.available) StoresNative.version ?: "" else "" - main.post { - androidx.compose.runtime.snapshots.Snapshot.withMutableSnapshot { - val restored = found.toMap() - accounts.keys.toList().filter { it !in restored }.forEach { accounts.remove(it); libraryAsked.remove(it) } - accounts.putAll(restored) - installed = onDisk - unfinished = partial - engine = version - accountsLoaded = true + if (refreshRequests.getAndIncrement() > 0) return + var seen = 0 + background("stores-refresh", onFailure = { if (refreshRequests.getAndSet(0) > seen) main.post { refresh(app) } }) { + do { + seen = refreshRequests.get() + runCatching { com.droiddeck.launcher.stores.battlenet.BattleNetClient.syncAccount(app) } + val found = Store.entries.mapNotNull { store -> StoreAccounts.displayName(app, store)?.let { store to it } } + val onDisk = StoreInstallRoot.gameFolders(app).mapNotNull { folder -> + StoreGameSidecar.read(folder)?.takeIf { it.isInstalled || it.state == StoreGameSidecar.STATE_UPDATING }?.let { InstalledStoreGame(it, folder) } + } + runCatching { com.droiddeck.launcher.stores.battlenet.BattleNetBackend.installedGames(app) }.getOrDefault(emptyList()) + val partial = StoreInstallRoot.unfinished(app) + val version = if (StoresNative.available) StoresNative.version ?: "" else "" + main.post { + androidx.compose.runtime.snapshots.Snapshot.withMutableSnapshot { + val restored = found.toMap() + accounts.keys.toList().filter { it !in restored }.forEach { accounts.remove(it); libraryAsked.remove(it) } + accounts.putAll(restored) + installed = onDisk + unfinished = partial + engine = version + accountsLoaded = true + } + com.droiddeck.launcher.stores.gog.GogMaintenance.checkInstalled(app, onDisk) } - com.droiddeck.launcher.stores.gog.GogMaintenance.checkInstalled(app, onDisk) - } + } while (!refreshRequests.compareAndSet(seen, 0)) } } @@ -206,6 +213,7 @@ object StoresState { main.post { if (store == Store.XBOX && StoreAccounts.signedInAs(app, store) != null) return@post accounts.remove(store); library.remove(store); status.remove(store); problems.remove(store); libraryAsked.remove(store) + if (store == Store.GOG) com.droiddeck.launcher.stores.gog.GogMaintenance.reset() logLine("${store.label}: signed out") } } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogMaintenance.kt b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogMaintenance.kt index 20d523ec69..84cb27802d 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogMaintenance.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogMaintenance.kt @@ -41,7 +41,7 @@ internal object GogMaintenance { } fun checkInstalled(context: Context, games: List) { - val user = StoreAccounts.displayName(context, Store.GOG).orEmpty() + val user = StoresState.accounts[Store.GOG].orEmpty() if (user != account) { reset(); account = user } if (user.isBlank()) return games.filter { it.sidecar.store == Store.GOG && it.sidecar.isInstalled }.forEach { check(context, it) } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/StoresStateRefreshTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/StoresStateRefreshTest.kt new file mode 100644 index 0000000000..2bd7417176 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/stores/StoresStateRefreshTest.kt @@ -0,0 +1,127 @@ +package com.droiddeck.launcher.stores + +import android.app.Application +import com.droiddeck.launcher.stores.gog.GogMaintenance +import org.json.JSONObject +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import org.robolectric.shadows.ShadowLooper +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicInteger +import javax.crypto.SecretKey +import javax.crypto.spec.SecretKeySpec +import kotlin.concurrent.thread + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33], application = Application::class) +class StoresStateRefreshTest { + private val app get() = RuntimeEnvironment.getApplication() + private val secret: SecretKey = SecretKeySpec(ByteArray(32), "AES") + private val plain = CredentialCipher.KeyProvider { secret } + + private fun opening(onOpen: () -> Unit) = object : CredentialCipher.KeyProvider { + override fun key() = secret + override fun existing(): SecretKey { onOpen(); return secret } + } + + private fun refreshRunning() = Thread.getAllStackTraces().keys.any { it.name == "stores-refresh" } + + private fun awaitRefreshDone() { + val deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10) + while (refreshRunning() && System.nanoTime() < deadline) Thread.sleep(10) + assertTrue("refresh did not finish", !refreshRunning()) + ShadowLooper.idleMainLooper() + } + + @Before fun setUp() { + StoreAccounts.keys = plain + StoreAccounts.keystoreFailed = false + StoreAccounts.write(app, Store.EPIC, JSONObject().put("access_token", "token").put("display_name", "Someone")) + StoresState.accounts.clear() + } + + @After fun tearDown() { + StoreAccounts.keys = plain + for (store in Store.entries) StoreAccounts.clear(app, store) + StoreAccounts.keys = CredentialCipher.Keystore + } + + @Test fun gogCheckDoesNotWaitForTheCredentialLock() { + val held = CountDownLatch(1) + val release = CountDownLatch(1) + val holder = thread { synchronized(StoreAccounts) { held.countDown(); release.await() } } + held.await() + val done = CountDownLatch(1) + thread { GogMaintenance.checkInstalled(app, emptyList()); done.countDown() } + try { + assertTrue("checkInstalled waited for the credential lock", done.await(2, TimeUnit.SECONDS)) + } finally { + release.countDown() + holder.join() + } + } + + @Test fun overlappingRefreshesShareOneMorePass() { + val opens = AtomicInteger() + val entered = CountDownLatch(1) + val release = CountDownLatch(1) + StoreAccounts.keys = opening { + opens.incrementAndGet() + entered.countDown() + release.await() + } + StoresState.refresh(app) + try { + assertTrue(entered.await(5, TimeUnit.SECONDS)) + repeat(4) { StoresState.refresh(app) } + } finally { + release.countDown() + } + awaitRefreshDone() + assertEquals(2, opens.get()) + assertEquals("Someone", StoresState.accounts[Store.EPIC]) + } + + @Test fun aRequestMadeDuringAFailedPassStillRuns() { + val entered = CountDownLatch(1) + val release = CountDownLatch(1) + StoreAccounts.keys = opening { + entered.countDown() + release.await() + throw Error("keystore died") + } + StoresState.refresh(app) + try { + assertTrue(entered.await(5, TimeUnit.SECONDS)) + StoresState.refresh(app) + StoreAccounts.keys = plain + } finally { + release.countDown() + } + awaitRefreshDone() + awaitRefreshDone() + assertEquals("Someone", StoresState.accounts[Store.EPIC]) + } + + @Test fun aFailedRefreshDoesNotBlockTheNextOne() { + val failed = CountDownLatch(1) + StoreAccounts.keys = opening { failed.countDown(); throw Error("keystore died") } + StoresState.refresh(app) + assertTrue(failed.await(5, TimeUnit.SECONDS)) + awaitRefreshDone() + assertNull(StoresState.accounts[Store.EPIC]) + StoreAccounts.keys = plain + StoresState.refresh(app) + awaitRefreshDone() + assertEquals("Someone", StoresState.accounts[Store.EPIC]) + } +} From a0a7a664704a7e6454deec3f20b0dd74199e9a87 Mon Sep 17 00:00:00 2001 From: visail Date: Tue, 27 Oct 2026 14:01:43 +0800 Subject: [PATCH 12/85] fix: use Blizzard's China hosts for Battle.net installs and update checks The Agent's install request pointed at http://cn.patch.battle.net:1119/. That host only 301-redirects to the country's version service today; Blizzard's China client asks cn.patch.battlenet.com.cn:1119 directly. The update check built .version.battle.net, so a China install (branch cn) asked cn.version.battle.net, which does not answer; the China service is cn.version.battlenet.com.cn. Only region cn changes. --- .../launcher/stores/battlenet/BattleNetInstall.kt | 9 +++++++-- .../launcher/stores/battlenet/BattleNetInstallTest.kt | 5 +++++ tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet | 4 +++- tools/tests/test_battlenet.py | 5 +++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstall.kt b/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstall.kt index 0fe38c49db..fdd4db2495 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstall.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstall.kt @@ -34,11 +34,16 @@ object BattleNetInstall { internal const val STATE = "BNET_STATE " internal const val DONE = "BNET_DONE " internal const val ERROR = "BNET_ERROR " - private const val VERSIONS = "https://%s.version.battle.net/v2/products/%s/versions" + private const val CN = "cn" private const val BUILD_INFO = ".build.info" private const val CHECK_AGAIN_MS = 30 * 60_000L private const val START_WAIT_MS = 60_000L + /** Blizzard serves China from battlenet.com.cn; its global version hostnames do not answer for that region. */ + internal fun versionsUrl(region: String, product: String): String = + "https://" + (if (region == CN) "cn.version.battlenet.com.cn" else "$region.version.battle.net") + + "/v2/products/$product/versions" + internal val LOCALES = listOf( "enUS", "enGB", "esMX", "esES", "ptBR", "ptPT", "frFR", "deDE", "itIT", "ruRU", "jaJP", "koKR", "plPL", "trTR", "zhTW", "zhCN", "thTH", "arSA", @@ -187,7 +192,7 @@ object BattleNetInstall { checks.execute { val local = runCatching { buildKey(File(folder, BUILD_INFO).readText()) }.getOrNull() ?: return@execute retryLater() - val latest = runCatching { latestBuild(fetch(VERSIONS.format(Locale.ROOT, local.first, product)), local.first) } + val latest = runCatching { latestBuild(fetch(versionsUrl(local.first, product)), local.first) } .onFailure { Log.w(TAG, "versions of $product: ${it.javaClass.simpleName}") }.getOrNull() ?: return@execute retryLater() val behind = latest != local.second diff --git a/app/src/test/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstallTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstallTest.kt index 027a1db73b..05a5708158 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstallTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstallTest.kt @@ -38,6 +38,11 @@ class BattleNetInstallTest { assertNull(BattleNetInstall.latestBuild("", "us")) } + @Test fun theVersionServiceIsBlizzardsChineseOneForChina() { + assertEquals("https://us.version.battle.net/v2/products/wow/versions", BattleNetInstall.versionsUrl("us", "wow")) + assertEquals("https://cn.version.battlenet.com.cn/v2/products/d3cn/versions", BattleNetInstall.versionsUrl("cn", "d3cn")) + } + @Test fun theDeviceLanguagePicksABlizzardLocale() { assertEquals("enUS", BattleNetInstall.locale(Locale.US)) assertEquals("enGB", BattleNetInstall.locale(Locale.UK)) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet index 0f78812eac..2f93eeaafc 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet @@ -113,7 +113,9 @@ function field(text, name) { } function install() { - var form = call("POST", "/install", '{"uid":"' + uid + '","instructions_patch_url":"http://' + zone + '.patch.battle.net:1119/' + + // Blizzard's China repository moved to cn.patch.battlenet.com.cn; cn.patch.battle.net only redirects away from it. + var patch = zone == "cn" ? "cn.patch.battlenet.com.cn" : zone + ".patch.battle.net"; + var form = call("POST", "/install", '{"uid":"' + uid + '","instructions_patch_url":"http://' + patch + ':1119/' + product + '","instructions_product":"NGDP","monitor_pid":12345,"priority":{"insert_at_head":true,"value":900}}'); save(".form", form); if (form.indexOf('"' + lang + '"') < 0) lang = "enUS"; diff --git a/tools/tests/test_battlenet.py b/tools/tests/test_battlenet.py index c0d0a76311..c99cb3e680 100644 --- a/tools/tests/test_battlenet.py +++ b/tools/tests/test_battlenet.py @@ -1130,6 +1130,11 @@ class AgentTest(Temp): self.assertIn("lang = a(5), country = a(6), region = a(7), out = a(8)", script) self.assertIn('"--internalclienttools"', (BIN / "droiddeck-battlenet").read_text()) + def test_the_driver_asks_blizzards_chinese_repository_for_chinese_installs(self): + script = BNET["AGENT_SCRIPT"] + self.assertIn('var patch = zone == "cn" ? "cn.patch.battlenet.com.cn" : zone + ".patch.battle.net";', script) + self.assertIn("+ patch + ':1119/'", script) + class AgentJobTest(Harness): def setUp(self): From 7c5bf77f17dab0d9e080f12cb4db23aa3bfeab4f Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 09:44:56 -0500 Subject: [PATCH 13/85] fix: fit output after pip resize --- .../main/java/com/droiddeck/launcher/SessionActivity.kt | 4 +++- .../main/java/com/droiddeck/launcher/session/PipPolicy.kt | 8 ++++++++ .../java/com/droiddeck/launcher/session/PipPolicyTest.kt | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 6aa3354ba7..023679de27 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -2220,7 +2220,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } private fun windowOutputSize(width: Int, height: Int): Pair? { - if (isInPictureInPictureMode || width <= 0 || height <= 0) return null + if (width <= 0 || height <= 0) return null + if (isInPictureInPictureMode) return com.droiddeck.launcher.session.PipPolicy.outputSize( + width, height, SessionState.outputSize.first, SessionState.outputSize.second) if (bottomGame != null) return when { SessionState.followScreen -> com.droiddeck.launcher.session.SessionDisplay.followSize(width, height, false, SessionState.followScale) diff --git a/app/src/main/java/com/droiddeck/launcher/session/PipPolicy.kt b/app/src/main/java/com/droiddeck/launcher/session/PipPolicy.kt index d2d4d49bd9..b5c9f112f8 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/PipPolicy.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/PipPolicy.kt @@ -11,4 +11,12 @@ object PipPolicy { height.toDouble() / width > 2.39 -> 100 to 239 else -> width to height } + + fun outputSize(width: Int, height: Int, outputWidth: Int, outputHeight: Int): Pair? { + if (width <= 0 || height <= 0 || outputWidth <= 0 || outputHeight <= 0) return null + val scale = minOf(width.toFloat() / outputWidth, height.toFloat() / outputHeight) + val fittedWidth = ((outputWidth * scale).toInt() and 1.inv()).coerceAtLeast(2) + val fittedHeight = ((outputHeight * scale).toInt() and 1.inv()).coerceAtLeast(2) + return fittedWidth to fittedHeight + } } diff --git a/app/src/test/java/com/droiddeck/launcher/session/PipPolicyTest.kt b/app/src/test/java/com/droiddeck/launcher/session/PipPolicyTest.kt index 1261abd542..40b169fad9 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/PipPolicyTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/PipPolicyTest.kt @@ -24,4 +24,10 @@ class PipPolicyTest { assertEquals(100 to 239, PipPolicy.aspect(1080, 5760)) assertEquals(16 to 9, PipPolicy.aspect(0, 0)) } + + @Test fun pipOutputFitsTheResizedSurfaceWithoutChangingAspectRatio() { + assertEquals(640 to 360, PipPolicy.outputSize(640, 480, 1920, 1080)) + assertEquals(480 to 270, PipPolicy.outputSize(480, 270, 1920, 1080)) + assertNull(PipPolicy.outputSize(0, 270, 1920, 1080)) + } } From e879375ca46f986e5646653c4dc24916440db627 Mon Sep 17 00:00:00 2001 From: cphillam Date: Thu, 5 Nov 2026 08:34:19 -0700 Subject: [PATCH 14/85] fix: upscale game buffers before native-resolution composition (#1367) * fix: upscale game buffers before native-resolution composition * fix: drop an added code comment from the effects source draw * fix: effects source keeps pillarboxed games and near-full source rectangles * fix: a larger opaque draw above keeps the full composition path --------- Co-authored-by: maxjivi05 --- .../main/cpp/waylandcomp/src/effects_chain.c | 12 + .../main/cpp/waylandcomp/src/effects_chain.h | 3 + app/src/main/cpp/waylandcomp/src/vk_present.c | 159 ++++- docs/development/steam-display-scaling.md | 39 ++ tools/tests/effects_source_cache_harness.c | 26 + tools/tests/test_effects_source_resolution.py | 566 ++++++++++++++++++ 6 files changed, 786 insertions(+), 19 deletions(-) create mode 100644 tools/tests/test_effects_source_resolution.py diff --git a/app/src/main/cpp/waylandcomp/src/effects_chain.c b/app/src/main/cpp/waylandcomp/src/effects_chain.c index aa5e5cb9dd..b73c92f711 100644 --- a/app/src/main/cpp/waylandcomp/src/effects_chain.c +++ b/app/src/main/cpp/waylandcomp/src/effects_chain.c @@ -1,5 +1,6 @@ #define _POSIX_C_SOURCE 200809L #include "effects_chain.h" +#include "blend_pass.h" #include "vk_loader.h" #include "vk_present.h" #include @@ -146,6 +147,16 @@ int vkp_effects_active(void) { return spatial_mode(g_cur.scaling) || effect_count(&g_cur) > 0; } +int vkp_effects_upscaling(void) { + vkp_effects_sync(); + return spatial_mode(g_cur.scaling) && g_cur.scaling != 6; +} + +int vkp_effects_postprocessing(void) { + vkp_effects_sync(); + return effect_count(&g_cur) > 0; +} + VkFilter vkp_effects_blit_filter(void) { vkp_effects_sync(); return g_cur.scaling == 2 ? VK_FILTER_NEAREST : VK_FILTER_LINEAR; @@ -233,6 +244,7 @@ static VkImageView make_view(VkImage img, VkFormat fmt) { } static void target_destroy(struct fx_target *t) { + if (t->img) blendp_forget_image(t->img); if (t->ds) g_vk.FreeDescriptorSets(g_dev, g_dpool, 1, &t->ds); if (t->fb) g_vk.DestroyFramebuffer(g_dev, t->fb, NULL); if (t->view) g_vk.DestroyImageView(g_dev, t->view, NULL); diff --git a/app/src/main/cpp/waylandcomp/src/effects_chain.h b/app/src/main/cpp/waylandcomp/src/effects_chain.h index 50e5e34942..9e9ad6859b 100644 --- a/app/src/main/cpp/waylandcomp/src/effects_chain.h +++ b/app/src/main/cpp/waylandcomp/src/effects_chain.h @@ -10,6 +10,9 @@ int vkp_effects_sync(void); int vkp_effects_active(void); +int vkp_effects_upscaling(void); +int vkp_effects_postprocessing(void); + VkFilter vkp_effects_blit_filter(void); VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h, diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index 895e1f6b47..9e1d1f7d61 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -1271,6 +1271,57 @@ static int draw_to_scene_blit(const struct vkp_draw *d, int scene_w, int scene_h return map_draw(d, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, (float)scene_w, (float)scene_h, blit); } +static int effects_source_draw(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + struct vkp_draw *out) { + if (!draws) return 0; + int opaque_above = 0; + for (int i = n - 1; i >= 0; i--) { + const struct vkp_draw *d = &draws[i]; + const struct vkp_image *im = d->img; + if (!im || d->blend || d->dx != 0 || d->dy != 0 || d->dw != scene_w || d->dh != scene_h) { + if (im && !d->blend && d->dw * d->dh > opaque_above) opaque_above = d->dw * d->dh; + continue; + } + if (opaque_above > im->w * im->h) return 0; + if (d->sx != 0 || d->sy != 0 || d->sw <= im->w - 1.0f || d->sw >= im->w + 1.0f || + d->sh <= im->h - 1.0f || d->sh >= im->h + 1.0f || + im->w <= 0 || im->h <= 0 || im->w > scene_w || im->h > scene_h || + (im->w == scene_w && im->h == scene_h) || + (i + 1 < n && vkp_effects_postprocessing())) return 0; + *out = *d; + out->dw = im->w; + out->dh = im->h; + return i + 1; + } + return 0; +} + +static void effects_source_note(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + int input_w, int input_h, int output_w, int output_h) { + static uint64_t previous; + uint64_t key = 14695981039346656037ULL; + const int sizes[] = {scene_w, scene_h, n, input_w, input_h, output_w, output_h}; + for (unsigned i = 0; i < sizeof(sizes) / sizeof(sizes[0]); i++) + key = (key ^ (uint32_t)sizes[i]) * 1099511628211ULL; + for (int i = 0; i < n; i++) { + const struct vkp_draw *d = &draws[i]; + const int values[] = {d->img ? d->img->w : 0, d->img ? d->img->h : 0, d->dw, d->dh, d->blend, + d->sx != 0 || d->sy != 0 || !d->img || d->sw != d->img->w || d->sh != d->img->h}; + for (unsigned j = 0; j < sizeof(values) / sizeof(values[0]); j++) + key = (key ^ (uint32_t)values[j]) * 1099511628211ULL; + } + if (key == previous) return; + previous = key; + droiddeck_log("effects", "input %dx%d -> %dx%d, logical scene %dx%d, %d draws", + input_w, input_h, output_w, output_h, scene_w, scene_h, n); + for (int i = 0; i < n && i < 8; i++) { + const struct vkp_draw *d = &draws[i]; + droiddeck_log("effects", "draw %d: buffer %dx%d, source %.1f,%.1f %.1fx%.1f -> scene %d,%d %dx%d, blend %d", + i, d->img ? d->img->w : 0, d->img ? d->img->h : 0, + d->sx, d->sy, d->sw, d->sh, d->dx, d->dy, d->dw, d->dh, d->blend); + } +} + static void record_draw(VkCommandBuffer cmd, const struct vkp_draw *d, const VkImageBlit *blit, VkImage target, VkFormat target_fmt, int target_w, int target_h, VkFilter filter) { const struct vkp_image *im = d->img; @@ -1282,6 +1333,34 @@ static void record_draw(VkCommandBuffer cmd, const struct vkp_draw *d, const VkI target, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, blit, filter); } +static void effects_overlay_draws(VkCommandBuffer cmd, VkImage result, int result_w, int result_h, + int scene_w, int scene_h, const struct vkp_draw *draws, int n) { + if (n <= 0) return; + VkImageMemoryBarrier b = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = result, .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}, + .srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + 0, 0, NULL, 0, NULL, 1, &b); + for (int i = 0; i < n; i++) { + VkImageBlit blit; + if (!draws[i].img || !map_draw(&draws[i], (float)result_w / scene_w, (float)result_h / scene_h, + 0, 0, 0, 0, (float)result_w, (float)result_h, &blit)) continue; + record_draw(cmd, &draws[i], &blit, result, SCENE_FMT, result_w, result_h, VK_FILTER_LINEAR); + } + b.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + b.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; + b.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, NULL, 0, NULL, 1, &b); +} + static void destroy_scene_image(void) { if (g_scene.img) vkp_effects_forget_image(g_scene.img); if (g_scene.img) hdrc_forget_image(g_scene.img); @@ -1673,6 +1752,20 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i cb = 0; } vkp_cardboard_begin_frame(); + int input_w = scene_w, input_h = scene_h; + int pass_n = n; + int overlay_start = n; + struct vkp_draw source_draw; + const struct vkp_draw *pass_draws = draws; + const int source_end = fx && !hf && vkp_effects_upscaling() + ? effects_source_draw(scene_w, scene_h, draws, n, &source_draw) : 0; + if (source_end) { + input_w = source_draw.dw; + input_h = source_draw.dh; + pass_draws = &source_draw; + pass_n = 1; + overlay_start = source_end; + } const int deep = hf && n > 0 && fg && g_swap_is_hdr && !hf->tonemap && vkp_framegen_format_ok(FG_HDR_FMT) && ensure_img(&g_fgscene, scene_w, scene_h, FG_HDR_FMT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | @@ -1692,7 +1785,11 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i "into the HDR10 swapchain (%s): banding possible in smooth gradients", sw); } } - const int pass = deep || ((fx || fg || cb || (hf && n > 0)) && ensure_scene_image(scene_w, scene_h) == 0); + const int pass = deep || ((fx || fg || cb || (hf && n > 0)) && ensure_scene_image(input_w, input_h) == 0); + const int draw_n = pass ? pass_n : n; + if (pass && fx && !hf && vkp_effects_upscaling()) + effects_source_note(scene_w, scene_h, draws, n, input_w, input_h, + (int)(scene_w * g_map.kx + 0.5f), (int)(scene_h * g_map.ky + 0.5f)); VkImage scene_img = deep ? g_fgscene.img : g_scene.img; const VkFormat scene_fmt = deep ? FG_HDR_FMT : SCENE_FMT; const VkFilter blit_filter = vkp_effects_blit_filter(); @@ -1743,11 +1840,12 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i int covered = 0; VkImageBlit cover_blit; if (!(hf && pass)) { - for (int i = n - 1; i >= 0 && !covered; i--) { - const struct vkp_draw *d = &draws[i]; - if (!d->img || d->blend || d->dx > 0 || d->dy > 0 || d->dx + d->dw < scene_w || - d->dy + d->dh < scene_h) continue; - covered = pass ? draw_to_scene_blit(d, scene_w, scene_h, &cover_blit) : draw_to_blit(d, &cover_blit); + for (int i = draw_n - 1; i >= 0 && !covered; i--) { + const struct vkp_draw *d = pass ? &pass_draws[i] : &draws[i]; + const int target_w = pass ? input_w : scene_w, target_h = pass ? input_h : scene_h; + if (!d->img || d->blend || d->dx > 0 || d->dy > 0 || d->dx + d->dw < target_w || + d->dy + d->dh < target_h) continue; + covered = pass ? draw_to_scene_blit(d, input_w, input_h, &cover_blit) : draw_to_blit(d, &cover_blit); } } const int cleared = covered && (pass || record_bars_clear(cmd, target, &cover_blit)); @@ -1771,12 +1869,13 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i hdr_how = g_swap_is_hdr ? 1 : 2; drawn = n; } - for (int i = 0; i < n && !hdr_how; i++) { + for (int i = 0; i < draw_n && !hdr_how; i++) { VkImageBlit blit; - if (!draws[i].img) continue; - if (pass ? !draw_to_scene_blit(&draws[i], scene_w, scene_h, &blit) : !draw_to_blit(&draws[i], &blit)) continue; - record_draw(cmd, &draws[i], &blit, target, pass ? scene_fmt : g_swap_fmt, - pass ? scene_w : (int)g_extent.width, pass ? scene_h : (int)g_extent.height, + const struct vkp_draw *d = pass ? &pass_draws[i] : &draws[i]; + if (!d->img) continue; + if (pass ? !draw_to_scene_blit(d, input_w, input_h, &blit) : !draw_to_blit(d, &blit)) continue; + record_draw(cmd, d, &blit, target, pass ? scene_fmt : g_swap_fmt, + pass ? input_w : (int)g_extent.width, pass ? input_h : (int)g_extent.height, pass ? VK_FILTER_LINEAR : blit_filter); drawn++; } @@ -1784,7 +1883,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i int ngen = 0; VkImage gens[VKP_FG_MAX_GENERATIONS] = {VK_NULL_HANDLE}; VkImage result = scene_img; - int rw = scene_w, rh = scene_h; + int rw = input_w, rh = input_h; if (!pass) { VkImageMemoryBarrier b_present = { .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, @@ -1799,7 +1898,9 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f); if (fg) { mapped_w = scene_w; mapped_h = scene_h; } vkp_effects_set_formats(scene_fmt, scene_fmt); - result = vkp_effects_run(cmd, scene_img, scene_w, scene_h, mapped_w, mapped_h, &rw, &rh); + result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h, &rw, &rh); + effects_overlay_draws(cmd, result, rw, rh, scene_w, scene_h, + draws ? draws + overlay_start : NULL, n - overlay_start); result_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; } VkImageMemoryBarrier b_general = { @@ -2158,13 +2259,31 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw const struct vkp_hdr_frame *hf, int *rw, int *rh) { if (g_pass.active) vkp_pass_abort(); if (vkp_update_map(scene_w, scene_h) != 0) return -1; + int input_w = scene_w, input_h = scene_h; + int pass_n = n, overlay_start = n; + struct vkp_draw source_draw; + const struct vkp_draw *pass_draws = draws; + const int source_end = !hf && vkp_effects_upscaling() + ? effects_source_draw(scene_w, scene_h, draws, n, &source_draw) : 0; + if (source_end) { + input_w = source_draw.dw; + input_h = source_draw.dh; + effects_source_note(scene_w, scene_h, draws, n, input_w, input_h, + (int)(scene_w * g_map.kx + 0.5f), (int)(scene_h * g_map.ky + 0.5f)); + pass_draws = &source_draw; + pass_n = 1; + overlay_start = source_end; + } else if (!hf && vkp_effects_upscaling()) { + effects_source_note(scene_w, scene_h, draws, n, input_w, input_h, + (int)(scene_w * g_map.kx + 0.5f), (int)(scene_h * g_map.ky + 0.5f)); + } if (hf) { if (ensure_img(&g_hdrscene, scene_w, scene_h, HDR_FMT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, "HDR composition (picture)") != 0) return -1; - } else if (ensure_scene_image(scene_w, scene_h) != 0) return -1; + } else if (ensure_scene_image(input_w, input_h) != 0) return -1; VkCommandBuffer cmd = g_cmds[0]; g_vk.ResetCommandBuffer(cmd, 0); @@ -2224,19 +2343,21 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &mb, 0, NULL, 0, NULL); - for (int i = 0; i < n; i++) { + for (int i = 0; i < pass_n; i++) { VkImageBlit blit; - if (!draws[i].img || !draw_to_scene_blit(&draws[i], scene_w, scene_h, &blit)) continue; - record_draw(cmd, &draws[i], &blit, g_scene.img, SCENE_FMT, scene_w, scene_h, + if (!pass_draws[i].img || !draw_to_scene_blit(&pass_draws[i], input_w, input_h, &blit)) continue; + record_draw(cmd, &pass_draws[i], &blit, g_scene.img, SCENE_FMT, input_w, input_h, VK_FILTER_LINEAR); } if (vkp_effects_active()) vkp_effects_set_formats(VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM); } int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f); - g_pass.rw = scene_w; g_pass.rh = scene_h; - g_pass.result = vkp_effects_run(cmd, scene_img, scene_w, scene_h, mapped_w, mapped_h, + g_pass.rw = input_w; g_pass.rh = input_h; + g_pass.result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h, &g_pass.rw, &g_pass.rh); + effects_overlay_draws(cmd, g_pass.result, g_pass.rw, g_pass.rh, scene_w, scene_h, + draws ? draws + overlay_start : NULL, n - overlay_start); g_pass.active = 1; if (rw) *rw = g_pass.rw; if (rh) *rh = g_pass.rh; diff --git a/docs/development/steam-display-scaling.md b/docs/development/steam-display-scaling.md index 3cc677db76..496995ad05 100644 --- a/docs/development/steam-display-scaling.md +++ b/docs/development/steam-display-scaling.md @@ -236,3 +236,42 @@ The launcher's Execute Steam settings, under Display, offer Picture position: To Positioning keeps the selected resolution, fit scale, aspect ratio and full surface intact. It distributes outer letterboxing above or below the picture; it does not crop game-authored black bars inside the surface. A surface that already fills the panel has no vertical space to move. Use a 16:9 resolution for fixed-16:9 games when a separate controls area is desired. The compositor publishes actual bounds for touch mapping and ignores touches starting outside the picture. The mapping harness covers top, bottom and center across tall, 16:9 and wide surfaces, including inverse input mapping and legacy half-screen mode compatibility. + +## Upscaler input resolution with a native-size session + +A low-resolution game buffer can have a native-resolution Wayland viewport destination. For +example, Gamescope can forward a 1280x720 game buffer into a 1920x1080 Steam session. Copying +that buffer into a 1920x1080 intermediate before the effects chain makes spatial upscalers +see equal input and output sizes, so FSR/GSR/NIS skip their upscaling pass. + +With a spatial upscaler selected, the renderer keeps an opaque, uncropped SDR fullscreen +source at its buffer size. That source hides preceding draws, which are omitted. Foreground +planes are drawn over the upscaled result in their original order, preserving the cursor's +native size. Their coordinates use the actual result dimensions, including a source-sized +fallback when the effects chain cannot allocate its output. Both swapchain presentation and +the SurfaceControl effects path retain the logical scene size and input mapping. + +Additional whole-scene effects, such as CAS, color adjustment and CRT, keep full composition +when foreground planes are present, so those effects still cover every plane. Spatial +upscaling can therefore still be bypassed in that combination. Cropped, blended, HDR and +larger-source fullscreen sources, and scenes without an eligible fullscreen source, retain +the existing path. Off, linear, nearest and sharpen-only modes retain their behavior. + +To reproduce, start a 1920x1080 Steam session on a native 1080p panel, run a game that presents +real 1280x720 buffers, and compare Linear with FSR in DroidDeck's session drawer. Show and hide +the game's cursor. The `effects` log should keep 1280x720 input and 1920x1080 output with both +the game alone and its foreground cursor plane. + +Odin 3 validation, 2026-10-22: Risk of Rain 2 at 1280x720 with fullscreen disabled, a 1920x1080 +session, FSR at 70%, CAS off and Look Off. The user confirms the updated build works. Captured +logs show `input 1280x720 -> 1920x1080, logical scene 1920x1080` with both two draws (background +and game) and three draws (including the blended 24x24 cursor), without a native-size fallback +when the cursor appears. Twelve source-resolution tests and four effects-cache tests pass; +an ARM64 debug APK builds and passes the asset, runtime-input and native-library checks. +Other scaler modes, a 720p -> 1080p -> 720p game-resolution round trip, HDR, frame generation +and the SurfaceControl path have not been independently validated on this device. + +This cannot recover a lower internal render resolution from an already-native backbuffer. +Steam's per-game Properties -> Game Resolution can instead provide a lower-resolution virtual +display. Changing the whole session's resolution through Steam's Display settings is separate: +the nested Wayland backend does not expose physical output modes there. diff --git a/tools/tests/effects_source_cache_harness.c b/tools/tests/effects_source_cache_harness.c index 1d355c2449..f947b230b0 100644 --- a/tools/tests/effects_source_cache_harness.c +++ b/tools/tests/effects_source_cache_harness.c @@ -12,6 +12,31 @@ struct vk_api g_vk; static unsigned views, sets, freed_views, freed_sets; static VkImageView bound_view; +static VkImage target_image; +static unsigned target_events, target_forgot_at, target_destroyed_at; + +void blendp_forget_image(VkImage image) { + assert(image == target_image && target_forgot_at == 0); + target_forgot_at = ++target_events; +} + +static void VKAPI_CALL destroy_image(VkDevice dev, VkImage image, const VkAllocationCallbacks *alloc) { + (void)dev; (void)alloc; + assert(image == target_image && target_forgot_at > 0); + target_destroyed_at = ++target_events; +} + +static void check_blend_cache_target_lifetime(void) { + target_image = (VkImage)(uintptr_t)50; + struct fx_target target = {.img = target_image}; + g_vk.DestroyImage = destroy_image; + target_destroy(&target); + assert(target_forgot_at == 1 && target_destroyed_at == 2); + assert(target.img == VK_NULL_HANDLE); + target_destroy(&target); + assert(target_events == 2); +} + static VkResult VKAPI_CALL create_view(VkDevice dev, const VkImageViewCreateInfo *info, const VkAllocationCallbacks *alloc, VkImageView *out) { (void)dev; (void)alloc; @@ -78,6 +103,7 @@ int main(int argc, char **argv) { assert(scene_ensure(source, 1920, 1080) == 0); assert(bound_view != original && views == 2 && freed_views == 1 && freed_sets == 1); } + check_blend_cache_target_lifetime(); puts("PASS"); return 0; } diff --git a/tools/tests/test_effects_source_resolution.py b/tools/tests/test_effects_source_resolution.py new file mode 100644 index 0000000000..2a229812fd --- /dev/null +++ b/tools/tests/test_effects_source_resolution.py @@ -0,0 +1,566 @@ +"""Exercise the renderer's source selection and both presentation paths without a GPU.""" +import os +from pathlib import Path +import re +import shutil +import subprocess +import tempfile +import unittest + + +REPO = Path(__file__).resolve().parents[2] + + +def function(source, signature): + start = source.rindex(signature) + return source[start:source.index('\n}\n', start) + 3] + + +class EffectsSourceResolutionTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + compiler = shutil.which(os.environ.get('CC', 'cc')) + if not compiler: + raise unittest.SkipTest('A host C compiler is required') + source = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_present.c').read_text() + header = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_present.h').read_text() + effects = (REPO / 'app/src/main/cpp/waylandcomp/src/effects_chain.c').read_text() + functions = '\n'.join(function(source, signature) for signature in ( + 'static int map_draw(', 'static int draw_to_blit(', + 'static int draw_to_scene_blit(', 'static int effects_source_draw(', + 'static void effects_source_note(', + 'static void effects_overlay_draws(', + 'static int render_impl(', 'static int pass_begin_impl(')) + functions = (re.search(r'static int spatial_mode\([^\n]+', effects).group() + '\n' + + function(effects, 'int vkp_effects_upscaling(') + + function(effects, 'int vkp_effects_postprocessing(') + functions) + image = source[source.index('struct vkp_image {'):source.index('\n};', source.index('struct vkp_image {')) + 3] + draw = header[header.index('struct vkp_draw {'):header.index('\n};', header.index('struct vkp_draw {')) + 3] + hdr = header[header.index('struct vkp_hdr_frame {'):header.index('\n};', header.index('struct vkp_hdr_frame {')) + 3] + constants = sorted(set(re.findall(r'\bVK_[A-Z0-9_]+\b', functions + image)) - + {'VK_FORMAT_R8G8B8A8_UNORM'}) + definitions = '\n'.join(f'#define {name} {0 if name in ("VK_SUCCESS", "VK_NULL_HANDLE") else i + 1}' + for i, name in enumerate(constants)) + code = TYPES + definitions + '\n' + image + '\n' + draw + '\n' + hdr + STUBS + functions + CASES + cls.temp = tempfile.TemporaryDirectory(prefix='droiddeck-effects-resolution-') + cls.addClassCleanup(cls.temp.cleanup) + folder = Path(cls.temp.name) + (folder / 'resolution.c').write_text(code) + cls.binary = folder / 'resolution' + build = subprocess.run([compiler, '-std=c11', '-Wall', '-Wextra', + '-Wno-unused-parameter', '-Wno-unused-function', + str(folder / 'resolution.c'), '-o', str(cls.binary)], + capture_output=True, text=True) + if build.returncode: + raise RuntimeError(build.stderr) + + def check_case(self, case): + result = subprocess.run([str(self.binary), case], capture_output=True, text=True, timeout=10) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(result.stdout.strip(), 'PASS') + + def test_low_resolution_viewport_is_copied_at_native_buffer_size(self): + self.check_case('helper') + + def test_a_source_within_a_pixel_of_the_buffer_is_still_upscaled(self): + self.check_case('near-full') + + def test_ineligible_compositions_keep_the_logical_scene(self): + self.check_case('rejections') + + def test_swapchain_path_uses_the_game_buffer_as_effects_input(self): + self.check_case('render') + + def test_offscreen_pass_uses_the_game_buffer_as_effects_input(self): + self.check_case('pass') + + def test_hdr_and_non_upscaling_effects_keep_the_logical_scene(self): + self.check_case('gates') + + def test_each_scaling_mode_selects_the_correct_input(self): + self.check_case('modes') + + def test_fullscreen_source_occludes_unrelated_background_draws(self): + self.check_case('occlusion') + + def test_foreground_overlays_keep_their_geometry_after_upscaling(self): + self.check_case('overlay') + + def test_failed_intermediate_allocation_draws_all_original_layers(self): + self.check_case('allocation') + + def test_effects_failure_maps_overlays_to_the_returned_image_size(self): + self.check_case('effect-failure') + + def test_offscreen_pass_acquires_foreground_sources_and_restores_result_layout(self): + self.check_case('overlay-barriers') + + def test_postprocessing_keeps_foreground_inside_the_effect_chain(self): + self.check_case('postprocessing') + + +TYPES = r''' +#include +#include +#include +#include +#include +typedef int VkImage, VkDeviceMemory, VkFormat, VkCommandBuffer, VkResult, VkFilter; +typedef int VkImageLayout, VkPipelineStageFlags, VkImageUsageFlags; +typedef uint64_t VkDeviceSize; +typedef struct { unsigned width, height; } VkExtent2D; +typedef struct { int x, y, z; } VkOffset3D; +typedef struct { unsigned aspectMask, mipLevel, baseArrayLayer, layerCount; } VkImageSubresourceLayers; +typedef struct { unsigned aspectMask, baseMipLevel, levelCount, baseArrayLayer, layerCount; } VkImageSubresourceRange; +typedef struct { + VkImageSubresourceLayers srcSubresource; + VkOffset3D srcOffsets[2]; + VkImageSubresourceLayers dstSubresource; + VkOffset3D dstOffsets[2]; +} VkImageBlit; +typedef struct { int sType, flags; } VkCommandBufferBeginInfo; +typedef struct { + int sType, oldLayout, newLayout, srcQueueFamilyIndex, dstQueueFamilyIndex; + VkImage image; + VkImageSubresourceRange subresourceRange; + unsigned srcAccessMask, dstAccessMask; +} VkImageMemoryBarrier; +typedef struct { int sType; unsigned srcAccessMask, dstAccessMask; } VkMemoryBarrier; +typedef union { float float32[4]; } VkClearColorValue; +typedef struct { + int sType; + unsigned waitSemaphoreCount, commandBufferCount, signalSemaphoreCount; + const int *pWaitSemaphores, *pWaitDstStageMask, *pCommandBuffers, *pSignalSemaphores; +} VkSubmitInfo; +typedef struct { + int sType; + unsigned waitSemaphoreCount, swapchainCount; + const int *pWaitSemaphores, *pSwapchains; + const unsigned *pImageIndices; +} VkPresentInfoKHR; +#define SCENE_FMT 100 +#define HDR_FMT 101 +#define FG_HDR_FMT 102 +#define VK_FORMAT_R8G8B8A8_UNORM SCENE_FMT +#define VKP_FG_MAX_GENERATIONS 2 +#define HDRC_OUT_PQ 1 +#define HDRC_OUT_SDR 2 +#define droiddeck_log(...) ((void)0) +#define LOGE(...) ((void)0) +struct droiddeck_color { uint32_t identity; }; +''' + + +STUBS = r''' +static int noop(int handle, ...) { return VK_SUCCESS; } +static VkImageMemoryBarrier recorded_barriers[64]; +static int barrier_count; +static int note_barriers(int cmd, int src_stage, int dst_stage, int flags, + unsigned memory_count, const VkMemoryBarrier *memory, + unsigned buffer_count, const void *buffers, + unsigned image_count, const VkImageMemoryBarrier *images) { + for (unsigned i = 0; i < image_count; i++) { + assert(barrier_count < 64); + recorded_barriers[barrier_count++] = images[i]; + } + return VK_SUCCESS; +} +static struct { + int (*ResetCommandBuffer)(int, ...), (*BeginCommandBuffer)(int, ...); + int (*CmdPipelineBarrier)(int, int, int, int, unsigned, const VkMemoryBarrier *, + unsigned, const void *, unsigned, const VkImageMemoryBarrier *); + int (*CmdClearColorImage)(int, ...); + int (*EndCommandBuffer)(int, ...), (*ResetFences)(int, ...); + int (*QueueSubmit)(int, ...), (*QueuePresentKHR)(int, ...); +} g_vk = {noop, noop, note_barriers, noop, noop, noop, noop, noop}; +static int g_dev_state, g_window = 1, g_swapchain, g_swap_extra; +static int g_colorspace_ext, g_swap_hdr_unavailable, g_swap_is_hdr, g_swap_hdr_want; +static int g_plain_frame, g_first_frame_done, g_base_black; +static int g_qfam, g_queue, g_dev, g_fence, g_swap_fmt = SCENE_FMT; +static int g_cmds[3], g_acqs[3], g_rnds[3], images[1] = {2}, *g_images = images; +static uint32_t g_swap_md_identity; +static VkExtent2D g_extent = {1920, 1080}; +static struct { float kx, ky, off_x, off_y; int rx, ry, rw, rh; } g_map; +static struct { VkImage img; int w, h; } g_scene; +struct vkp_img_slot { VkImage img; int w, h; }; +static struct vkp_img_slot g_hdrscene, g_fgscene; +static struct { int active, rw, rh; VkImage result; } g_pass; +static struct { int64_t present_ns, present_max_ns; unsigned presents; } g_perf; +static int effects_active = 1, framegen, cardboard; +static struct { int scaling; } g_cur = {4}; +static int copy_count, effects_count, screen_count, hdr_count, fail_scene, fail_effects, postprocessing; +static int copied_w, copied_h, target_w, target_h; +static int effects_w, effects_h, output_w, output_h, logical_w, logical_h; +static VkImageBlit copied; +static struct vkp_draw recorded_draws[16]; +static VkImageBlit recorded_blits[16]; +static VkImage recorded_targets[16]; +static int recorded_after_effects[16]; +static void vkp_apply_window_request(void) {} +static void sc_layer_hide_base(void) {} +static void check_surface_changed(void) {} +static int dev_init(void) { return 0; } +static int vkp_framegen_extra_images(void) { return 0; } +static void destroy_swapchain(void) {} +static int acquire_image(int k, int wait, uint32_t *image, VkResult *result) { + *image = 0; *result = VK_SUCCESS; return 0; +} +static void update_map(int w, int h) { + g_map.kx = (float)g_extent.width / w; g_map.ky = (float)g_extent.height / h; + g_map.rw = g_extent.width; g_map.rh = g_extent.height; +} +static int vkp_update_map(int w, int h) { update_map(w, h); return 0; } +static void send_hdr_metadata(const struct droiddeck_color *color) {} +static int vkp_effects_active(void) { return effects_active; } +static int vkp_effects_sync(void) { return 0; } +static int effect_count(const void *settings) { return postprocessing; } +static int vkp_framegen_active(void) { return framegen; } +static int vkp_cardboard_active(void) { return cardboard; } +static void vkp_cardboard_begin_frame(void) {} +static int vkp_framegen_format_ok(VkFormat format) { return 0; } +static int ensure_img(struct vkp_img_slot *slot, int w, int h, int format, int usage, const char *name) { + slot->img = 3; slot->w = w; slot->h = h; return 0; +} +static void vk_format_short(int format, char *out, size_t size) { *out = 0; } +static int ensure_scene_image(int w, int h) { + if (fail_scene) return -1; + g_scene.img = 1; g_scene.w = w; g_scene.h = h; return 0; +} +static VkFilter vkp_effects_blit_filter(void) { return 0; } +static void blendp_begin_frame(void) {} +static int record_bars_clear(int cmd, int target, const VkImageBlit *blit) { return 1; } +static int compose_hdr(int cmd, const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hdr, + int w, int h, int target, int format, int output) { + hdr_count++; return 0; +} +static void record_draw(int cmd, const struct vkp_draw *draw, const VkImageBlit *blit, int target, + int format, int w, int h, int filter) { + assert(copy_count < 16); + recorded_draws[copy_count] = *draw; recorded_blits[copy_count] = *blit; + recorded_targets[copy_count] = target; recorded_after_effects[copy_count] = effects_count > 0; + copy_count++; copied = *blit; + copied_w = draw->dw; copied_h = draw->dh; target_w = w; target_h = h; +} +static void vkp_effects_set_formats(int input, int output) {} +static VkImage vkp_effects_run(int cmd, int source, int w, int h, int ow, int oh, int *rw, int *rh) { + effects_count++; effects_w = w; effects_h = h; output_w = ow; output_h = oh; + if (!hdr_count) assert(g_scene.w == w && g_scene.h == h); + if (fail_effects) { *rw = w; *rh = h; return source; } + *rw = ow; *rh = oh; return 4; +} +static int vkp_framegen_run(int cmd, int result, int depth, int w, int h, int format, int *generated) { return 0; } +static void record_screen_blit(int cmd, int result, int w, int h, int sw, int sh, int image, int filter, int cb) { + screen_count++; logical_w = sw; logical_h = sh; +} +static void device_lost(const char *reason) {} +static int64_t perf_now(void) { return 0; } +static void perf_add(int64_t *sum, int64_t *max, unsigned *count, int64_t duration) {} +static VkResult timed_wait(int fence, uint64_t timeout) { return VK_SUCCESS; } +static void vkp_framegen_presented(int frames) {} +static const char *vk_result_name(int result) { return "success"; } +static void droiddeck_on_first_frame(void) {} +static void vkp_pass_abort(void) { g_pass.active = 0; } +''' + + +CASES = r''' +static struct vkp_image image = {.image = 10, .w = 1280, .h = 720, .sampled = 1}; +static struct vkp_draw fullscreen(void) { + return (struct vkp_draw){.img = &image, .sw = image.w, .sh = image.h, .dw = 1920, .dh = 1080}; +} +static void reset(void) { + copy_count = effects_count = screen_count = hdr_count = barrier_count = 0; + effects_active = 1; g_cur.scaling = 4; + framegen = cardboard = fail_scene = fail_effects = postprocessing = g_plain_frame = 0; + g_pass.active = 0; g_extent = (VkExtent2D){1920, 1080}; + image.w = 1280; image.h = 720; +} +static void check_helper(void) { + struct vkp_draw original = fullscreen(), before = original, selected; + struct vkp_image image_before = image; + assert(effects_source_draw(1920, 1080, &original, 1, &selected)); + assert(memcmp(&original, &before, sizeof(original)) == 0); + assert(memcmp(&image, &image_before, sizeof(image)) == 0); + assert(selected.img == original.img && selected.sw == 1280 && selected.sh == 720); + assert(selected.dw == 1280 && selected.dh == 720); + VkImageBlit blit; + assert(draw_to_scene_blit(&selected, 1280, 720, &blit)); + assert(blit.srcOffsets[0].x == 0 && blit.srcOffsets[0].y == 0); + assert(blit.dstOffsets[0].x == 0 && blit.dstOffsets[0].y == 0); + assert(blit.srcOffsets[1].x == 1280 && blit.srcOffsets[1].y == 720); + assert(blit.dstOffsets[1].x == 1280 && blit.dstOffsets[1].y == 720); + image.w = 1920; image.h = 720; + original = fullscreen(); + assert(effects_source_draw(1920, 1080, &original, 1, &selected)); + assert(selected.dw == 1920 && selected.dh == 720); +} +static void rejected(struct vkp_draw draw, int n) { + struct vkp_draw selected = {0}, before = selected; + assert(!effects_source_draw(1920, 1080, &draw, n, &selected)); + assert(memcmp(&selected, &before, sizeof(selected)) == 0); +} +static void check_rejections(void) { + struct vkp_draw draw = fullscreen(), unused; + assert(!effects_source_draw(1920, 1080, NULL, 1, &unused)); + rejected(draw, 0); rejected(draw, -1); + draw.img = NULL; rejected(draw, 1); + draw = fullscreen(); draw.blend = 1; rejected(draw, 1); + draw = fullscreen(); draw.dx = 1; rejected(draw, 1); + draw = fullscreen(); draw.dy = -1; rejected(draw, 1); + draw = fullscreen(); draw.dw--; rejected(draw, 1); + draw = fullscreen(); draw.dh++; rejected(draw, 1); + draw = fullscreen(); draw.sx = 1; rejected(draw, 1); + draw = fullscreen(); draw.sy = 0.5f; rejected(draw, 1); + draw = fullscreen(); draw.sw--; rejected(draw, 1); + draw = fullscreen(); draw.sh--; rejected(draw, 1); + const int sizes[][2] = {{1920, 1080}, {1921, 720}, {1280, 1081}, {0, 720}, {1280, 0}, {-1, 720}}; + for (unsigned i = 0; i < sizeof(sizes) / sizeof(sizes[0]); i++) { + image.w = sizes[i][0]; image.h = sizes[i][1]; rejected(fullscreen(), 1); + } + reset(); + struct vkp_image native = {.image = 13, .w = 1920, .h = 1080}; + struct vkp_draw layers[] = {fullscreen(), fullscreen()}; + layers[1].img = &native; layers[1].sw = 1920; layers[1].sh = 1080; + assert(!effects_source_draw(1920, 1080, layers, 2, &unused)); + layers[1] = fullscreen(); layers[1].sx = 1; layers[1].sw--; + assert(!effects_source_draw(1920, 1080, layers, 2, &unused)); + struct vkp_image pixel = {.image = 14, .w = 1, .h = 1}; + layers[0] = fullscreen(); layers[0].img = &pixel; layers[0].sw = 1; layers[0].sh = 1; + layers[1] = fullscreen(); layers[1].dx = 240; layers[1].dw = 1440; + assert(!effects_source_draw(1920, 1080, layers, 2, &unused)); + layers[1] = fullscreen(); layers[1].dx = 320; layers[1].dy = 180; layers[1].dw = 1280; layers[1].dh = 720; + assert(!effects_source_draw(1920, 1080, layers, 2, &unused)); + layers[0] = fullscreen(); + layers[1] = fullscreen(); layers[1].dx = 10; layers[1].dy = 10; layers[1].dw = 24; layers[1].dh = 24; + assert(effects_source_draw(1920, 1080, layers, 2, &unused) == 1); +} +static void check_near_full_source(void) { + struct vkp_draw draw = fullscreen(), selected; + draw.sw = 1279.5f; + assert(effects_source_draw(1920, 1080, &draw, 1, &selected)); + assert(selected.dw == 1280 && selected.dh == 720 && selected.sw == 1279.5f); + draw = fullscreen(); draw.sh = 720.5f; + assert(effects_source_draw(1920, 1080, &draw, 1, &selected)); +} +static void run_path(int offscreen, const struct vkp_draw *draw, int n, const struct vkp_hdr_frame *hdr) { + struct vkp_draw before[4]; + assert(n > 0 && n <= 4); + memcpy(before, draw, n * sizeof(*draw)); + int rw = 0, rh = 0; + assert((offscreen ? pass_begin_impl(1920, 1080, draw, n, hdr, &rw, &rh) + : render_impl(1920, 1080, draw, n, hdr, NULL)) == 0); + assert(memcmp(draw, before, n * sizeof(*draw)) == 0); + if (offscreen) assert(rw == (fail_effects ? effects_w : (int)g_extent.width) && + rh == (fail_effects ? effects_h : (int)g_extent.height)); +} +static void check_input(int w, int h) { + assert(effects_count == 1 && effects_w == w && effects_h == h); + assert(output_w == (int)g_extent.width && output_h == (int)g_extent.height); +} +static void check_path(int offscreen) { + struct vkp_draw draw = fullscreen(); + run_path(offscreen, &draw, 1, NULL); + check_input(1280, 720); + assert(copy_count == 1 && copied_w == 1280 && copied_h == 720); + assert(target_w == 1280 && target_h == 720); + assert(copied.srcOffsets[1].x == copied.dstOffsets[1].x); + assert(copied.srcOffsets[1].y == copied.dstOffsets[1].y); + if (!offscreen) assert(screen_count == 1 && logical_w == 1920 && logical_h == 1080); + reset(); image.w = 1920; image.h = 1080; draw = fullscreen(); + run_path(offscreen, &draw, 1, NULL); check_input(1920, 1080); + reset(); g_extent = (VkExtent2D){2560, 1440}; draw = fullscreen(); + run_path(offscreen, &draw, 1, NULL); check_input(1280, 720); + reset(); draw = fullscreen(); draw.dw = 1280; draw.dh = 720; + int rw, rh; + assert((offscreen ? pass_begin_impl(1280, 720, &draw, 1, NULL, &rw, &rh) + : render_impl(1280, 720, &draw, 1, NULL, NULL)) == 0); + check_input(1280, 720); +} +static void check_gates(void) { + for (int offscreen = 0; offscreen < 2; offscreen++) { + reset(); g_cur.scaling = 0; + struct vkp_draw draw = fullscreen(); + run_path(offscreen, &draw, 1, NULL); check_input(1920, 1080); + assert(target_w == 1920 && target_h == 1080); + reset(); + struct vkp_hdr_frame hdr = {0}; + run_path(offscreen, &draw, 1, &hdr); check_input(1920, 1080); + assert(hdr_count == 1 && copy_count == 0); + reset(); + struct vkp_draw desktop[] = {fullscreen(), fullscreen()}; + desktop[0].dw = 960; + desktop[1].dx = 40; desktop[1].dy = 30; desktop[1].dw = 640; desktop[1].dh = 480; + run_path(offscreen, desktop, 2, NULL); check_input(1920, 1080); + reset(); draw = fullscreen(); draw.blend = 1; + run_path(offscreen, &draw, 1, NULL); check_input(1920, 1080); + } + reset(); effects_active = 0; framegen = 1; + struct vkp_draw draw = fullscreen(); + run_path(0, &draw, 1, NULL); + assert(effects_count == 0 && target_w == 1920 && target_h == 1080); + reset(); fail_scene = 1; + run_path(0, &draw, 1, NULL); + assert(effects_count == 0 && copied.dstOffsets[1].x == 1920 && copied.dstOffsets[1].y == 1080); +} +static void check_modes(void) { + for (int mode = 0; mode <= 8; mode++) { + for (int offscreen = 0; offscreen < 2; offscreen++) { + reset(); g_cur.scaling = mode; + int upscale = mode == 3 || mode == 4 || mode == 5 || mode == 7 || mode == 8; + assert(vkp_effects_upscaling() == upscale); + struct vkp_draw draw = fullscreen(); + run_path(offscreen, &draw, 1, NULL); + check_input(upscale ? 1280 : 1920, upscale ? 720 : 1080); + } + } +} +static struct vkp_image background = {.image = 11, .w = 320, .h = 240, .sampled = 1}; +static struct vkp_image cursor = {.image = 12, .w = 24, .h = 24, .dmabuf = 1, .sampled = 1}; +static struct vkp_draw background_draw(void) { + return (struct vkp_draw){.img = &background, .sw = 320, .sh = 240, + .dx = 40, .dy = 30, .dw = 640, .dh = 480, .blend = 1}; +} +static struct vkp_draw cursor_draw(void) { + return (struct vkp_draw){.img = &cursor, .sw = 24, .sh = 24, + .dx = 480, .dy = 270, .dw = 24, .dh = 24, .blend = 1}; +} +static void check_occlusion(void) { + struct vkp_draw layers[] = {background_draw(), fullscreen()}, selected; + struct vkp_draw before[2]; + memcpy(before, layers, sizeof(layers)); + assert(effects_source_draw(1920, 1080, layers, 2, &selected) == 2); + assert(selected.img == &image && selected.dw == 1280 && selected.dh == 720); + assert(memcmp(layers, before, sizeof(layers)) == 0); + for (int offscreen = 0; offscreen < 2; offscreen++) { + reset(); + run_path(offscreen, layers, 2, NULL); check_input(1280, 720); + assert(copy_count == 1 && recorded_draws[0].img == &image); + assert(recorded_draws[0].dw == 1280 && recorded_draws[0].dh == 720); + assert(target_w == 1280 && target_h == 720); + assert(copied.srcOffsets[1].x == 1280 && copied.dstOffsets[1].x == 1280); + assert(copied.srcOffsets[1].y == 720 && copied.dstOffsets[1].y == 720); + if (!offscreen) assert(logical_w == 1920 && logical_h == 1080); + reset(); g_cur.scaling = 6; + run_path(offscreen, layers, 2, NULL); check_input(1920, 1080); + assert(copy_count == 2); + reset(); + struct vkp_hdr_frame hdr = {0}; + run_path(offscreen, layers, 2, &hdr); check_input(1920, 1080); + assert(hdr_count == 1 && copy_count == 0); + } +} +static void check_overlay(void) { + for (int offscreen = 0; offscreen < 2; offscreen++) { + for (int larger_output = 0; larger_output <= 1; larger_output++) { + reset(); + if (larger_output) g_extent = (VkExtent2D){2560, 1440}; + struct vkp_draw layers[] = {background_draw(), fullscreen(), cursor_draw()}, selected; + assert(effects_source_draw(1920, 1080, layers, 3, &selected) == 2); + run_path(offscreen, layers, 3, NULL); check_input(1280, 720); + assert(copy_count == 2 && recorded_draws[0].img == &image); + assert(!recorded_after_effects[0] && recorded_targets[0] == g_scene.img); + assert(recorded_draws[1].img == &cursor && recorded_draws[1].blend); + assert(recorded_after_effects[1] && recorded_targets[1] == 4); + assert(recorded_blits[1].dstOffsets[0].x == (larger_output ? 640 : 480)); + assert(recorded_blits[1].dstOffsets[0].y == (larger_output ? 360 : 270)); + assert(recorded_blits[1].dstOffsets[1].x - recorded_blits[1].dstOffsets[0].x == + (larger_output ? 32 : 24)); + assert(recorded_blits[1].dstOffsets[1].y - recorded_blits[1].dstOffsets[0].y == + (larger_output ? 32 : 24)); + } + for (int blend = 0; blend <= 1; blend++) { + reset(); + struct vkp_draw layers[] = {background_draw(), fullscreen(), background_draw(), cursor_draw()}; + layers[2].blend = blend; + layers[3].sx = 4; layers[3].sy = 2; layers[3].sw = 12; layers[3].sh = 18; + run_path(offscreen, layers, 4, NULL); check_input(1280, 720); + assert(copy_count == 3 && recorded_draws[0].img == &image); + assert(recorded_draws[1].img == &background); + assert(recorded_draws[1].blend == blend && recorded_after_effects[1]); + assert(recorded_draws[2].img == &cursor && recorded_after_effects[2]); + assert(recorded_blits[1].dstOffsets[0].x == 40); + assert(recorded_blits[1].dstOffsets[0].y == 30); + assert(recorded_blits[2].srcOffsets[0].x == 4 && recorded_blits[2].srcOffsets[0].y == 2); + assert(recorded_blits[2].srcOffsets[1].x == 16 && recorded_blits[2].srcOffsets[1].y == 20); + assert(recorded_targets[1] == 4 && recorded_targets[2] == 4); + assert(target_w == 1920 && target_h == 1080); + } + } +} +static void check_effect_failure(void) { + for (int offscreen = 0; offscreen < 2; offscreen++) { + reset(); fail_effects = 1; + struct vkp_draw layers[] = {background_draw(), fullscreen(), cursor_draw()}; + run_path(offscreen, layers, 3, NULL); check_input(1280, 720); + assert(copy_count == 2 && recorded_targets[1] == g_scene.img && recorded_after_effects[1]); + assert(target_w == 1280 && target_h == 720); + assert(recorded_blits[1].dstOffsets[0].x == 320 && recorded_blits[1].dstOffsets[0].y == 180); + assert(recorded_blits[1].dstOffsets[1].x == 336 && recorded_blits[1].dstOffsets[1].y == 196); + } +} +static int find_barrier(VkImage image, int from, int to) { + for (int i = 0; i < barrier_count; i++) + if (recorded_barriers[i].image == image && recorded_barriers[i].oldLayout == from && + recorded_barriers[i].newLayout == to) return i; + return -1; +} +static void check_overlay_barriers(void) { + for (int offscreen = 0; offscreen < 2; offscreen++) { + reset(); + struct vkp_draw layers[] = {background_draw(), fullscreen(), cursor_draw()}; + run_path(offscreen, layers, 3, NULL); check_input(1280, 720); + int acquired = find_barrier(cursor.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + assert(acquired >= 0 && recorded_barriers[acquired].srcQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT); + int writable = find_barrier(4, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + int readable = find_barrier(4, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + assert(writable > acquired && readable > writable); + } +} +static void check_postprocessing(void) { + for (int offscreen = 0; offscreen < 2; offscreen++) { + reset(); postprocessing = 1; + struct vkp_draw layers[] = {background_draw(), fullscreen(), cursor_draw()}, selected; + assert(vkp_effects_postprocessing()); + assert(effects_source_draw(1920, 1080, layers, 2, &selected) == 2); + assert(!effects_source_draw(1920, 1080, layers, 3, &selected)); + run_path(offscreen, layers, 3, NULL); check_input(1920, 1080); + assert(copy_count == 3); + for (int i = 0; i < copy_count; i++) + assert(!recorded_after_effects[i] && recorded_targets[i] == g_scene.img); + } +} +static void check_allocation(void) { + fail_scene = 1; + struct vkp_draw layers[] = {background_draw(), fullscreen()}; + run_path(0, layers, 2, NULL); + assert(effects_count == 0 && copy_count == 2); + assert(recorded_draws[0].img == &background && recorded_draws[1].img == &image); + assert(recorded_draws[0].dw == 640 && recorded_draws[0].dh == 480); + assert(recorded_draws[1].dw == 1920 && recorded_draws[1].dh == 1080); + assert(recorded_blits[0].dstOffsets[0].x == 40 && recorded_blits[0].dstOffsets[0].y == 30); + assert(recorded_blits[1].dstOffsets[1].x == 1920 && recorded_blits[1].dstOffsets[1].y == 1080); + assert(target_w == 1920 && target_h == 1080); +} +int main(int argc, char **argv) { + assert(argc == 2); reset(); + if (!strcmp(argv[1], "helper")) check_helper(); + else if (!strcmp(argv[1], "near-full")) check_near_full_source(); + else if (!strcmp(argv[1], "rejections")) check_rejections(); + else if (!strcmp(argv[1], "render")) check_path(0); + else if (!strcmp(argv[1], "pass")) check_path(1); + else if (!strcmp(argv[1], "gates")) check_gates(); + else if (!strcmp(argv[1], "modes")) check_modes(); + else if (!strcmp(argv[1], "occlusion")) check_occlusion(); + else if (!strcmp(argv[1], "overlay")) check_overlay(); + else if (!strcmp(argv[1], "allocation")) check_allocation(); + else if (!strcmp(argv[1], "effect-failure")) check_effect_failure(); + else if (!strcmp(argv[1], "overlay-barriers")) check_overlay_barriers(); + else if (!strcmp(argv[1], "postprocessing")) check_postprocessing(); + else assert(0); + puts("PASS"); +} +''' + + +if __name__ == '__main__': + unittest.main() From 92a588ea16c6e0c45b5011ca7a371224bd592f4c Mon Sep 17 00:00:00 2001 From: vitamin663-sys Date: Fri, 6 Nov 2026 00:53:15 +0900 Subject: [PATCH 15/85] fix(input): add radial stick dead zone setting --- .../droiddeck/launcher/FrontEndActivity.kt | 1 + .../com/droiddeck/launcher/SessionActivity.kt | 2 + .../droiddeck/launcher/agent/AgentInput.kt | 6 +- .../launcher/input/ControllerPrefs.kt | 12 + .../launcher/input/OnScreenControls.kt | 6 +- .../droiddeck/launcher/input/PadBridge.java | 149 ++++-- .../com/droiddeck/launcher/input/PadMouse.kt | 8 +- .../launcher/ui/ControllerSettings.kt | 2 + .../launcher/ui/DeckControlsPanel.kt | 2 +- app/src/main/res/values-ar/strings.xml | 1 + app/src/main/res/values-b+es+419/strings.xml | 1 + app/src/main/res/values-bg/strings.xml | 1 + app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values-da/strings.xml | 1 + app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-el/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fi/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-hi/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 1 + app/src/main/res/values-in/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-ko/strings.xml | 1 + app/src/main/res/values-ms/strings.xml | 1 + app/src/main/res/values-nb/strings.xml | 1 + app/src/main/res/values-nl/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values-ro/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-th/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values-uk/strings.xml | 1 + app/src/main/res/values-vi/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../launcher/input/PadBridgeQamTest.kt | 70 ++- .../launcher/input/StickDeadZoneTest.kt | 473 ++++++++++++++++++ 44 files changed, 711 insertions(+), 53 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/input/StickDeadZoneTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index a7edaa3692..7bbac41b2f 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -1544,6 +1544,7 @@ class FrontEndActivity : ComponentActivity() { onStickClick = { on -> ControllerPrefs.setStickClick(this, on); refreshController() }, onAdaptiveSticks = { on -> ControllerPrefs.setAdaptiveSticks(this, on); refreshController() }, onRumble = { on -> ControllerPrefs.setRumble(this, on); refreshController() }, + onDeadZone = { v -> ControllerPrefs.setDeadZone(this, v); refreshController() }, onSteamButton = { on -> ControllerPrefs.setSteamButton(this, on); refreshController() }, onQamButton = { on -> ControllerPrefs.setQamButton(this, on); refreshController() }, onKeyboardButton = { on -> ControllerPrefs.setKeyboardButton(this, on); refreshController() }, diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 023679de27..1b4b59df1e 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -675,6 +675,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } val bridge = PadBridge(File(LinuxRuntime.sessionRoot(this), "dev/input")) + bridge.setStickDeadZone(ControllerPrefs.deadZone(this)) bridge.setSelectSteam(ControllerPrefs.read(this).selectSteam) bridge.setBuiltinPad(SessionState.mode != SessionService.MODE_STEAM || SessionPrefs.builtinPad(this)) padBridge = bridge @@ -4328,6 +4329,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } (getSystemService(INPUT_SERVICE) as? InputManager) ?.registerInputDeviceListener(deviceListener, Handler(Looper.getMainLooper())) + padBridge?.setStickDeadZone(ControllerPrefs.deadZone(this)) refreshSecondScreenDisplays() if (SessionState.guestPid > 1) padBridge?.syncConnectedControllers() joyConVr?.refresh() diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentInput.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentInput.kt index 94cf533885..e491b5f9ad 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentInput.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentInput.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.agent +import com.droiddeck.launcher.input.PadBridge import com.droiddeck.launcher.input.PadState import com.droiddeck.launcher.session.SessionState import com.droiddeck.launcher.wayland.WaylandCompositor @@ -143,9 +144,10 @@ object AgentInput { val right = request.optString("stick", "left") == "right" val x = request.optDouble("x", 0.0).toFloat().coerceIn(-1f, 1f) val y = request.optDouble("y", 0.0).toFloat().coerceIn(-1f, 1f) - bridge.applyTouch { if (right) { it.rightX = x; it.rightY = y } else { it.leftX = x; it.leftY = y } } + val stickWrite = if (right) PadBridge.RIGHT_STICK else PadBridge.LEFT_STICK + bridge.applyTouch(stickWrite) { if (right) { it.rightX = x; it.rightY = y } else { it.leftX = x; it.leftY = y } } hold(request, 300) - bridge.applyTouch { if (right) { it.rightX = 0f; it.rightY = 0f } else { it.leftX = 0f; it.leftY = 0f } } + bridge.applyTouch(stickWrite) { if (right) { it.rightX = 0f; it.rightY = 0f } else { it.leftX = 0f; it.leftY = 0f } } return JSONObject().put("stick", if (right) "right" else "left") } diff --git a/app/src/main/java/com/droiddeck/launcher/input/ControllerPrefs.kt b/app/src/main/java/com/droiddeck/launcher/input/ControllerPrefs.kt index c784bc3bf6..bb1705ba68 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/ControllerPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/ControllerPrefs.kt @@ -22,6 +22,9 @@ object ControllerPrefs { val sizes = listOf(80, 90, 100, 110, 125) + val deadZones = listOf(0, 5, 8, 12, 15, 20, 25) + const val DEFAULT_DEAD_ZONE_PERCENT = 12 + val mappable = listOf( "a" to R.string.ctrl_button_a, "b" to R.string.ctrl_button_b, "x" to R.string.ctrl_button_x, "y" to R.string.ctrl_button_y, "lb" to R.string.ctrl_button_lb, "rb" to R.string.ctrl_button_rb, "lt" to R.string.ctrl_button_lt, "rt" to R.string.ctrl_button_rt, @@ -51,6 +54,7 @@ object ControllerPrefs { val snap: Boolean, val customLayout: Boolean, val mapping: Map, + val deadZone: Int, ) internal fun prefs(context: Context) = context.getSharedPreferences("controller", Context.MODE_PRIVATE) @@ -72,6 +76,7 @@ object ControllerPrefs { snap = p.getBoolean("snap", true), customLayout = p.all.keys.any { it.startsWith("layout.") }, mapping = mappable.associate { (id, _) -> id to target(context, id) }, + deadZone = deadZone(context), ) } @@ -109,6 +114,13 @@ object ControllerPrefs { fun rumbleEnabled(context: Context): Boolean = prefs(context).getBoolean("rumble", true) + fun deadZone(context: Context): Int = + prefs(context).getInt("deadZone", DEFAULT_DEAD_ZONE_PERCENT).takeIf { it in deadZones } ?: DEFAULT_DEAD_ZONE_PERCENT + + fun setDeadZone(context: Context, percent: Int) { + prefs(context).edit().putInt("deadZone", percent).apply() + } + fun setRumble(context: Context, on: Boolean) { prefs(context).edit().putBoolean("rumble", on).apply() } diff --git a/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt b/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt index ab275177d1..459d8177a0 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt @@ -549,6 +549,7 @@ class OnScreenControls( control.ax = if (adaptive) event.getX(index) else control.cx control.ay = if (adaptive) event.getY(index) else control.cy control.drag(event.getX(index), event.getY(index)) + control.dirty = true } if (SessionPrefs.lowLatency(context)) requestUnbufferedDispatch(event) apply() @@ -721,7 +722,10 @@ class OnScreenControls( bridge.setSystemButtons(controls.any { it.id == "guide" && it.pressedBy != -1 }, qamHeld) } else { bridge.setSystemButtons(false, qamHeld) - bridge.applyTouch { state -> + val stickWrites = controls.filter { it.stick >= 0 && it.dirty }.fold(0) { mask, control -> + mask or if (control.stick == 0) PadBridge.LEFT_STICK else PadBridge.RIGHT_STICK + } + bridge.applyTouch(stickWrites) { state -> val used = HashSet() val held = HashSet() for (control in controls) { diff --git a/app/src/main/java/com/droiddeck/launcher/input/PadBridge.java b/app/src/main/java/com/droiddeck/launcher/input/PadBridge.java index edb95fbe6e..4bf45e9fee 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/PadBridge.java +++ b/app/src/main/java/com/droiddeck/launcher/input/PadBridge.java @@ -17,7 +17,10 @@ import java.util.concurrent.atomic.AtomicIntegerArray; public final class PadBridge { private static final String TAG = "PadBridge"; public static final int SLOTS = 4; + public static final int LEFT_STICK = 1; + public static final int RIGHT_STICK = 2; private static final float DEAD_ZONE = 0.12f; + private float stickDeadZone = DEAD_ZONE; private static final int[] JOYSTICK_AXES = { MotionEvent.AXIS_X, MotionEvent.AXIS_Y, MotionEvent.AXIS_Z, MotionEvent.AXIS_RZ, MotionEvent.AXIS_RX, MotionEvent.AXIS_RY, @@ -52,6 +55,8 @@ public final class PadBridge { private volatile java.util.function.IntPredicate excluded = id -> false; private final FakeInputWriter[] playerWriters = new FakeInputWriter[SLOTS]; private final PadState[] playerStates = new PadState[SLOTS]; + private final float[][] rawSticks = new float[SLOTS][4]; + private final int[] retainedSticks = new int[SLOTS]; private final PadState effectiveState = new PadState(); private final PadState homeGuideReport = new PadState(); private final Handler mainHandler = new Handler(Looper.getMainLooper()); @@ -150,7 +155,7 @@ public final class PadBridge { chordButtonPressed = false; qamChordGeneration++; chordHandler.removeCallbacksAndMessages(null); - state.clear(); + clearPlayerState(0); publish(); } @@ -177,7 +182,7 @@ public final class PadBridge { playerWriters[slot].destroy(); playerWriters[slot] = null; } - if (playerStates[slot] != null) playerStates[slot].clear(); + clearPlayerState(slot); } systemGuidePressed = false; systemQamPressed = false; @@ -187,7 +192,7 @@ public final class PadBridge { qamTapPressed = false; qamChordGeneration++; if (open) { - state.clear(); + clearPlayerState(0); writer.writePad(state); writer.close(); open = false; @@ -353,6 +358,65 @@ public final class PadBridge { return true; } + public synchronized void setStickDeadZone(int percent) { + float value = Math.max(0, Math.min(25, percent)) / 100f; + if (stickDeadZone == value) return; + stickDeadZone = value; + for (int slot = 0; slot < SLOTS; slot++) { + if (retainedSticks[slot] == 0) continue; + int owner = owners[slot], partner = partners[slot]; + if (owner != NO_CONTROLLER && (InputDevice.getDevice(owner) == null || excluded.test(owner))) leave(slot, owner); + if (partner != NO_CONTROLLER && (InputDevice.getDevice(partner) == null || excluded.test(partner))) leave(slot, partner); + if (retainedSticks[slot] == 0) continue; + projectSticks(slot); + publish(slot); + } + } + + private void retainStick(int slot, int side, float x, float y) { + rawSticks[slot][side * 2] = x; + rawSticks[slot][side * 2 + 1] = y; + retainedSticks[slot] |= 1 << side; + } + + private void projectSticks(int slot) { + PadState pad = stateFor(slot); + for (int side = 0; side < 2; side++) { + if ((retainedSticks[slot] & (1 << side)) == 0) continue; + float x = rawSticks[slot][side * 2]; + float y = rawSticks[slot][side * 2 + 1]; + boolean centred = inStickDeadZone(x, y, stickDeadZone); + if (side == JoyCon.LEFT) { + pad.leftX = centred ? 0f : x; + pad.leftY = centred ? 0f : y; + } else { + pad.rightX = centred ? 0f : x; + pad.rightY = centred ? 0f : y; + } + } + } + + private void clearPlayerState(int slot) { + stateFor(slot).clear(); + retainedSticks[slot] = 0; + Arrays.fill(rawSticks[slot], 0f); + } + + private void mutateState(java.util.function.Consumer mutation) { + float lx = state.leftX, ly = state.leftY, rx = state.rightX, ry = state.rightY; + mutation.accept(state); + if (state.leftX != lx || state.leftY != ly) retainedSticks[0] &= ~1; + if (state.rightX != rx || state.rightY != ry) retainedSticks[0] &= ~2; + } + + static boolean inStickDeadZone(float x, float y, float deadZone) { + return x * x + y * y < deadZone * deadZone; + } + + private static boolean hasChordStickInput(float x, float y) { + return Math.max(Math.abs(x), Math.abs(y)) >= DEAD_ZONE; + } + public synchronized boolean onMotionEvent(MotionEvent event) { if (!isControllerMotionEvent(event) || excluded.test(event.getDeviceId())) return false; if (event.getAction() != MotionEvent.ACTION_MOVE) return false; @@ -366,25 +430,24 @@ public final class PadBridge { int side = JoyCon.side(device); if (side >= 0) { int[] stick = JoyCon.stickAxes(side, device, event.getSource()); - float x = axis(event, stick[0]); - float y = axis(event, stick[1]); - if (side == JoyCon.LEFT) { - pad.leftX = x; - pad.leftY = y; - } else { - pad.rightX = x; - pad.rightY = y; - } - if (x != 0f || y != 0f) noteChordInput(slot); + float x = event.getAxisValue(stick[0]); + float y = event.getAxisValue(stick[1]); + boolean chordStickInput = hasChordStickInput(x, y); + retainStick(slot, side, x, y); + projectSticks(slot); + if (chordStickInput) noteChordInput(slot); if (Math.max(Math.abs(x), Math.abs(y)) > 0.5f) notePlayerInput(); publish(slot); return true; } - pad.leftX = axis(event, MotionEvent.AXIS_X); - pad.leftY = axis(event, MotionEvent.AXIS_Y); + float lx = event.getAxisValue(MotionEvent.AXIS_X); + float ly = event.getAxisValue(MotionEvent.AXIS_Y); boolean wired = wiredXboxLayout(event); - pad.rightX = rightX(event, wired); - pad.rightY = rightY(event, wired); + float rx = event.getAxisValue(wired ? MotionEvent.AXIS_RX : MotionEvent.AXIS_Z); + float ry = event.getAxisValue(wired ? MotionEvent.AXIS_RY : MotionEvent.AXIS_RZ); + retainStick(slot, JoyCon.LEFT, lx, ly); + retainStick(slot, JoyCon.RIGHT, rx, ry); + projectSticks(slot); int source = event.getSource(); float lt = 0f; float rt = 0f; @@ -406,7 +469,7 @@ public final class PadBridge { pad.up = hatY < -0.5f; pad.down = hatY > 0.5f; } - if (pad.leftX != 0f || pad.leftY != 0f || pad.rightX != 0f || pad.rightY != 0f + if (hasChordStickInput(lx, ly) || hasChordStickInput(rx, ry) || lt > 0f || rt > 0f || pad.up || pad.right || pad.down || pad.left) noteChordInput(slot); if (Math.max(Math.max(Math.abs(pad.leftX), Math.abs(pad.leftY)), Math.max(Math.abs(pad.rightX), Math.abs(pad.rightY))) > 0.5f || lt > 0.5f || rt > 0.5f || pad.up || pad.right || pad.down || pad.left) { @@ -434,6 +497,10 @@ public final class PadBridge { } public synchronized void applyTouch(java.util.function.Consumer mutation) { + applyTouch(0, mutation); + } + + public synchronized void applyTouch(int stickWrites, java.util.function.Consumer mutation) { if (!builtinPad) return; if (touchRoute != null && touchRoute.active()) { mutation.accept(routedTouch); @@ -453,7 +520,8 @@ public final class PadBridge { return; } routedTouch.clear(); - mutation.accept(state); + retainedSticks[0] &= ~stickWrites; + mutateState(mutation); activeControllerId = NO_CONTROLLER; slotControllers.set(0, NO_CONTROLLER); notePlayerInput(); @@ -463,7 +531,7 @@ public final class PadBridge { } public synchronized void applyExternal(java.util.function.Consumer mutation, boolean changed) { - mutation.accept(state); + mutateState(mutation); if (changed) { activeControllerId = NO_CONTROLLER; notePlayerInput(); @@ -490,11 +558,11 @@ public final class PadBridge { routedTouch.clear(); backQamPressed = false; releaseBackPaddles(); - state.clear(); + clearPlayerState(0); publish(); for (int slot = 1; slot < SLOTS; slot++) { + clearPlayerState(slot); if (playerWriters[slot] == null) continue; - playerStates[slot].clear(); publish(slot); } } @@ -534,7 +602,7 @@ public final class PadBridge { if (!homeGuidePressed) return; clearBackQamWrites(); homeGuidePressed = false; - state.clear(); + clearPlayerState(0); publish(); } @@ -557,7 +625,7 @@ public final class PadBridge { writeBackQamReport(modifier, modifierAt); } if (!pressed && !backQamPressed && !homeGuidePressed) { - backQamAxesBlocked = hasAxes(state); + backQamAxesBlocked = hasQamAxes(); if (!backQamWrites.isEmpty()) { PadState neutral = new PadState(); neutral.copyFrom(lastWrittenReport); @@ -573,7 +641,7 @@ public final class PadBridge { if (!backQamPressed && backQamWrites.isEmpty()) return; clearBackQamWrites(); backQamPressed = false; - state.clear(); + clearPlayerState(0); publish(); } @@ -609,15 +677,18 @@ public final class PadBridge { } private void writePad(PadState report) { - if (backQamAxesBlocked && !hasAxes(state)) backQamAxesBlocked = false; + if (backQamAxesBlocked && !hasQamAxes()) backQamAxesBlocked = false; long at = android.os.SystemClock.uptimeMillis(); if (backQamPressed || homeGuidePressed || !backQamWrites.isEmpty()) at += backQamDelayMs; writeBackQamReport(report, at); } - private static boolean hasAxes(PadState pad) { - return pad.leftX != 0f || pad.leftY != 0f || pad.rightX != 0f || pad.rightY != 0f - || pad.leftTrigger != 0f || pad.rightTrigger != 0f; + private boolean hasQamAxes() { + boolean left = (retainedSticks[0] & 1) != 0 + ? hasChordStickInput(rawSticks[0][0], rawSticks[0][1]) : state.leftX != 0f || state.leftY != 0f; + boolean right = (retainedSticks[0] & 2) != 0 + ? hasChordStickInput(rawSticks[0][2], rawSticks[0][3]) : state.rightX != 0f || state.rightY != 0f; + return left || right || state.leftTrigger != 0f || state.rightTrigger != 0f; } private static void clearAxes(PadState pad) { @@ -727,7 +798,7 @@ public final class PadBridge { slotJoyCons.set(slot * 2 + 1 - side, owner.getId()); if (slot == firstPlayerSlot()) releaseBackPaddles(); if (slot == 0) clearBackQamWrites(); - stateFor(slot).clear(); + clearPlayerState(slot); if (slot == 0) publish(); Log.i(TAG, "\"" + device.getName() + "\" (id " + id + ") joins \"" + owner.getName() + "\" as player " + (slot + 1)); return slot; @@ -775,7 +846,7 @@ public final class PadBridge { if (slotControllers.get(slot) == id) slotControllers.set(slot, owners[slot]); if (activeControllerId == id) activeControllerId = owners[slot]; if (slot == firstPlayerSlot()) releaseBackPaddles(); - stateFor(slot).clear(); + clearPlayerState(slot); publish(slot); } @@ -793,11 +864,11 @@ public final class PadBridge { if (slot == homeGuideSlot) homeGuideSlot = -1; if (slot == firstPlayerSlot()) releaseBackPaddles(); if (slot == 0) { - state.clear(); + clearPlayerState(0); publish(); return; } - playerStates[slot].clear(); + clearPlayerState(slot); if (playerWriters[slot] != null) { playerWriters[slot].destroy(); playerWriters[slot] = null; @@ -886,14 +957,6 @@ public final class PadBridge { && device.getMotionRange(MotionEvent.AXIS_RZ, event.getSource()) != null; } - public static float rightX(MotionEvent event, boolean wired) { - return axis(event, wired ? MotionEvent.AXIS_RX : MotionEvent.AXIS_Z); - } - - public static float rightY(MotionEvent event, boolean wired) { - return axis(event, wired ? MotionEvent.AXIS_RY : MotionEvent.AXIS_RZ); - } - public static float leftTrigger(MotionEvent event, boolean wired) { if (wired) return Math.max(0f, Math.min(1f, (event.getAxisValue(MotionEvent.AXIS_Z) + 1f) / 2f)); float value = event.getAxisValue(MotionEvent.AXIS_LTRIGGER); @@ -906,8 +969,4 @@ public final class PadBridge { return value != 0f ? value : event.getAxisValue(MotionEvent.AXIS_GAS); } - private static float axis(MotionEvent event, int axis) { - float value = event.getAxisValue(axis); - return Math.abs(value) < DEAD_ZONE ? 0f : value; - } } diff --git a/app/src/main/java/com/droiddeck/launcher/input/PadMouse.kt b/app/src/main/java/com/droiddeck/launcher/input/PadMouse.kt index 77fb4f6fd9..2d71451ccf 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/PadMouse.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/PadMouse.kt @@ -90,8 +90,8 @@ class PadMouse(private val listener: Listener, private val clock: () -> Long = S val wired = wiredLayout.getOrPut(event.deviceId) { PadBridge.wiredXboxLayout(event) } sticks.leftX = event.getAxisValue(MotionEvent.AXIS_X) sticks.leftY = event.getAxisValue(MotionEvent.AXIS_Y) - sticks.rightX = PadBridge.rightX(event, wired) - sticks.rightY = PadBridge.rightY(event, wired) + sticks.rightX = scrollAxis(event, if (wired) MotionEvent.AXIS_RX else MotionEvent.AXIS_Z) + sticks.rightY = scrollAxis(event, if (wired) MotionEvent.AXIS_RY else MotionEvent.AXIS_RZ) if (hasTriggerAxes(event)) { sticks.leftTrigger = PadBridge.leftTrigger(event, wired) sticks.rightTrigger = PadBridge.rightTrigger(event, wired) @@ -295,6 +295,7 @@ class PadMouse(private val listener: Listener, private val clock: () -> Long = S } companion object { + private const val SCROLL_AXIS_DEAD_ZONE = 0.12f private const val DEAD_ZONE = 0.15f private const val STICK_NAVIGATE = 0.5f private const val REPEAT_FIRST_MS = 300L @@ -348,6 +349,9 @@ class PadMouse(private val listener: Listener, private val clock: () -> Long = S return scaled * scaled / length } + private fun scrollAxis(event: MotionEvent, axis: Int): Float = + event.getAxisValue(axis).let { if (abs(it) < SCROLL_AXIS_DEAD_ZONE) 0f else it } + private fun source(deviceId: Int, kind: Int): Int = deviceId * 2 + kind diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ControllerSettings.kt b/app/src/main/java/com/droiddeck/launcher/ui/ControllerSettings.kt index 0fab267984..6c5f7c230e 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ControllerSettings.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ControllerSettings.kt @@ -25,6 +25,7 @@ class ControllerActions( val onStickClick: (Boolean) -> Unit, val onAdaptiveSticks: (Boolean) -> Unit, val onRumble: (Boolean) -> Unit, + val onDeadZone: (Int) -> Unit, val onSteamButton: (Boolean) -> Unit, val onQamButton: (Boolean) -> Unit, val onKeyboardButton: (Boolean) -> Unit, @@ -69,6 +70,7 @@ fun ColumnScope.ControllerRows(host: MenuHost, oscMode: String, c: ControllerPre ToggleRow(host, "controller-stick-click", stringResource(R.string.ctrl_stick_click), stringResource(R.string.ctrl_stick_click_hint), c.stickClick, onChange = a.onStickClick) ToggleRow(host, "controller-adaptive", stringResource(R.string.ctrl_adaptive), stringResource(R.string.ctrl_adaptive_hint), c.adaptiveSticks, onChange = a.onAdaptiveSticks) ToggleRow(host, "controller-rumble", stringResource(R.string.ctrl_rumble), null, c.rumble, onChange = a.onRumble) + ChoiceRow(host, "controller-dead-zone", stringResource(R.string.ctrl_dead_zone), null, ControllerPrefs.deadZones.map { it to stringResource(R.string.ctrl_percent, it) }, c.deadZone, onPick = a.onDeadZone) ToggleRow(host, "controller-steam", stringResource(R.string.ctrl_steam_button), null, c.steamButton, onChange = a.onSteamButton) ToggleRow(host, "controller-qam", stringResource(R.string.ctrl_qam_button), null, c.qamButton, onChange = a.onQamButton) ToggleRow(host, "controller-keyboard", stringResource(R.string.ctrl_keyboard_button), null, c.keyboardButton, onChange = a.onKeyboardButton) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/DeckControlsPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/DeckControlsPanel.kt index a57ca0a957..0193ce3201 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/DeckControlsPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/DeckControlsPanel.kt @@ -479,7 +479,7 @@ class DeckControlsPanel( private fun move(dx: Float, dy: Float, r: Float) { knobX = dx knobY = dy - pad.applyTouch { s -> + pad.applyTouch(if (right) PadBridge.RIGHT_STICK else PadBridge.LEFT_STICK) { s -> if (right) { s.rightX = dx / r; s.rightY = dy / r } else { s.leftX = dx / r; s.leftY = dy / r } } invalidate() diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 20c77a1377..27328cddbf 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -1130,6 +1130,7 @@ انقر مرتين مع الاستمرار على عصا للحصول على L3 أو R3 عصي تكيّفية اهتزاز اللعبة + المنطقة الميتة لعصا التحكم زر Steam زر QAM زر لوحة المفاتيح diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index 73698d9d57..59d19ea263 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -1139,6 +1139,7 @@ Toca dos veces y mantén un stick para L3 o R3 Sticks adaptables Vibración en juegos + Zona muerta de la palanca Botón Steam Botón QAM Botón de teclado diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 678a118f74..929cd0a5fa 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -1106,6 +1106,7 @@ Докоснете двукратно и задръжте стик за L3 или R3 Адаптивни стикове Вибрация от играта + Мъртва зона на стика Бутон Steam Бутон QAM Бутон за клавиатура diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 158be592d8..f185a75ac5 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -1118,6 +1118,7 @@ Dvojitým dotykem a podržením páčky aktivujete L3 nebo R3 Adaptivní páčky Vibrace ve hře + Mrtvá zóna páčky Tlačítko Steam Tlačítko QAM Tlačítko klávesnice diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index b673ffe66b..4835c6c525 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -1106,6 +1106,7 @@ Dobbelttryk og hold en stick nede for L3 eller R3 Adaptive styrepinde Spilvibration + Dødzone for styrepind Steam-knap QAM-knap Tastaturknap diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 6bb4a27a19..e8d3a8187c 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1098,6 +1098,7 @@ Doppeltippen und Stick halten für L3 oder R3 Adaptive Sticks Spielvibration + Stick-Totzone Steam-Taste QAM-Taste Tastatur-Taste diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 17be0c8bce..5c36e43ac2 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -1106,6 +1106,7 @@ Πατήστε δύο φορές και κρατήστε έναν μοχλό για L3 ή R3 Προσαρμοστικοί μοχλοί Κραδασμός παιχνιδιού + Νεκρή ζώνη μοχλού Κουμπί Steam Κουμπί QAM Κουμπί πληκτρολογίου diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index b9ad21bbe0..deb2f0247b 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1112,6 +1112,7 @@ Toca dos veces y mantén un stick para L3 o R3 Sticks adaptables Vibración en juegos + Zona muerta de la palanca Botón Steam Botón QAM Botón de teclado diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 06dd2d1a1e..465cffc012 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -1106,6 +1106,7 @@ Kaksoisnapauta ja pidä sauvaa pohjassa saadaksesi L3:n tai R3:n Mukautuvat sauvat Pelin tärinä + Ohjaussauvan kuollut alue Steam-painike QAM-painike Näppäimistöpainike diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 7a2200fa92..2939b36150 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1112,6 +1112,7 @@ Double-cliquez et maintenez le joystick pour déclencher L3 ou R3 Joystick adaptatif Vibration du jeu + Zone morte du stick Bouton Steam Bouton QAM Bouton clavier diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 0005d2dfad..0724288e56 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -1106,6 +1106,7 @@ L3 या R3 के लिए किसी स्टिक को डबल-टैप करके दबाए रखें एडैप्टिव स्टिक गेम वाइब्रेशन + स्टिक का डेड ज़ोन Steam बटन QAM बटन कीबोर्ड बटन diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 86fe25afa8..1de6bee395 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -1106,6 +1106,7 @@ Koppintson duplán, és tartsa lenyomva a kart az L3 vagy R3 érdekében Adaptív karok Játékvibráció + Kar holtzónája Steam gomb QAM gomb Billentyűzet gomb diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 0aa46114f7..4cb978fb76 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -1100,6 +1100,7 @@ Ketuk dua kali dan tahan sebuah stik untuk L3 atau R3 Stik adaptif Getaran gim + Zona mati stik Tombol Steam Tombol QAM Tombol keyboard diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 4f816b30b9..2bc2f2caa9 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1104,6 +1104,7 @@ Tocca due volte e tieni premuta una levetta per L3 o R3 Levette adattive Vibrazione di gioco + Zona morta dello stick Tasto Steam Tasto QAM Tasto tastiera diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index f72c30c8be..4eeb0f4da9 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -1100,6 +1100,7 @@ スティックをダブルタップして長押しすると、L3またはR3がトリガーされます アダプティブスティック ゲームの振動 + スティックのデッドゾーン Steamボタン QAMボタン キーボードボタン diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 16d3a1e5c3..853f277c7d 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -1100,6 +1100,7 @@ 스틱을 두 번 탭한 후 길게 누르면 L3 또는 R3이 입력됩니다 적응형 스틱 게임 진동 + 스틱 데드존 Steam 버튼 QAM 버튼 키보드 버튼 diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 14dc814a73..05a4715a9e 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -1100,6 +1100,7 @@ Ketik dua kali dan tahan stik untuk L3 atau R3 Stik adaptif Getaran permainan + Zon mati kayu bedik Butang Steam Butang QAM Butang papan kekunci diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 7a644c67e9..f58bbb2a63 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -1106,6 +1106,7 @@ Dobbelttrykk og hold en stikke for L3 eller R3 Adaptive stikker Spillvibrasjon + Dødsone for styrespak Steam-knapp QAM-knapp Tastatur-knapp diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 26caeb73c8..97f508808c 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -1106,6 +1106,7 @@ Dubbeltik en houd een stick ingedrukt voor L3 of R3 Adaptieve sticks Trillen in games + Dode zone van stick Steam-knop QAM-knop Toetsenbordknop diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 2304171da3..726f588736 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -1118,6 +1118,7 @@ Dotknij dwukrotnie i przytrzymaj gałkę, aby uzyskać L3 lub R3 Adaptacyjne gałki Wibracje gry + Martwa strefa drążka Przycisk Steam Przycisk QAM Przycisk klawiatury diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 43cb70df8c..57ec99ea69 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -1104,6 +1104,7 @@ Toque duas vezes num analógico e mantenha para L3 ou R3 Analógicos adaptáveis Vibração do jogo + Zona morta do manípulo Botão Steam Botão QAM Botão do teclado diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index ba5bbf1479..f94154363b 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -1104,6 +1104,7 @@ Toque duas vezes e segure um analógico para L3 ou R3 Analógicos adaptáveis Vibração do jogo + Zona morta do analógico Botão Steam Botão QAM Botão do teclado diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index dd0580d81a..310667e478 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -1112,6 +1112,7 @@ Apasă de două ori și ține apăsată o manșă pentru L3 sau R3 Manșe adaptive Vibrații de joc + Zonă moartă a manetei Butonul Steam Butonul QAM Butonul tastaturii diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 55287bdd9c..b3df2b00a6 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -1118,6 +1118,7 @@ Дважды нажмите и удерживайте стик для L3 или R3 Адаптивные стики Вибрация в играх + Мёртвая зона стика Кнопка Steam Кнопка QAM Кнопка клавиатуры diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 6de4336e33..1f8ccb0482 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -1106,6 +1106,7 @@ Dubbeltryck och håll en spak för L3 eller R3 Adaptiva spakar Spelvibration + Styrspakens dödzon Steam-knappen QAM-knappen Tangentbordsknappen diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 538a3817d0..0292bdfc25 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -1100,6 +1100,7 @@ แตะสองครั้งแล้วกดสติ๊กค้างไว้สำหรับ L3 หรือ R3 สติ๊กแบบปรับอัตโนมัติ การสั่นของเกม + เดดโซนของแอนะล็อกสติ๊ก ปุ่ม Steam ปุ่ม QAM ปุ่มแป้นพิมพ์ diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 8a864ce992..311b9a94f4 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -1098,6 +1098,7 @@ L3 veya R3 için bir çubuğa çift dokunup basılı tutun Uyarlanabilir çubuklar Oyun titreşimi + Çubuk ölü bölgesi Steam düğmesi QAM düğmesi Klavye düğmesi diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index e317a43f64..27730223e6 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -1118,6 +1118,7 @@ Двічі торкніться і затримайте стик, щоб отримати L3 або R3 Адаптивні стики Вібрація гри + Мертва зона стіка Кнопка Steam Кнопка QAM Кнопка клавіатури diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 7af05a293b..d2bd3997dc 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -1100,6 +1100,7 @@ Chạm hai lần và giữ một cần để dùng L3 hoặc R3 Cần thích ứng Rung khi chơi game + Vùng chết của cần điều khiển Nút Steam Nút QAM Nút bàn phím diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 34d9c50231..1919b524c6 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -1184,6 +1184,7 @@ 双击并按住摇杆可触发 L3 或 R3 自适应摇杆 游戏震动 + 摇杆死区 Steam 按钮 QAM 按钮 键盘按钮 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 6df9a2425e..4205bcf0ee 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1100,6 +1100,7 @@ 在搖桿上輕按兩下並按住,即可觸發 L3 或 R3 自動調整搖桿 遊戲震動 + 搖桿死區 Steam 按鈕 QAM 按鈕 鍵盤按鈕 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 9e32ee2b54..0b1b4f1eca 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1100,6 +1100,7 @@ 點兩下並按住搖桿可觸發 L3 或 R3 自適應搖桿 遊戲震動 + 搖桿死區 Steam 按鈕 QAM 按鈕 鍵盤按鈕 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5ea9cf34c7..96766a5bc8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1198,6 +1198,7 @@ Double-tap and hold a stick for L3 or R3 Adaptive sticks Game vibration + Stick dead zone Steam button QAM button Keyboard button diff --git a/app/src/test/java/com/droiddeck/launcher/input/PadBridgeQamTest.kt b/app/src/test/java/com/droiddeck/launcher/input/PadBridgeQamTest.kt index 47bf0719c0..3795c25e0a 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/PadBridgeQamTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/PadBridgeQamTest.kt @@ -440,13 +440,79 @@ class PadBridgeQamTest { assertFalse(pad().isDown(PadState.GUIDE)) } + @Test fun zeroDeadZoneDriftDoesNotKeepAxesBlockedAfterBackRelease() { + val device = controller() + bridge.setStickDeadZone(0) + motion(device, MotionEvent.AXIS_X, 0.01f) + bridge.setBackQamPressed(true) + advanceTime() + bridge.setBackQamPressed(false) + advanceTime() + motion(device, MotionEvent.AXIS_X, 0.5f) + assertEquals(0.5f, pad().leftX) + } + + @Test fun circularDiagonalDriftDoesNotKeepAxesBlockedAfterBackRelease() { + val device = controller() + motion(device, MotionEvent.AXIS_X to 0.09f, MotionEvent.AXIS_Y to 0.09f) + bridge.setBackQamPressed(true) + advanceTime() + bridge.setBackQamPressed(false) + advanceTime() + motion(device, MotionEvent.AXIS_X, 0.5f) + assertEquals(0.5f, pad().leftX) + } + + @Test fun changingPreferenceDoesNotBypassARequiredPhysicalNeutralReturn() { + val device = controller() + bridge.setStickDeadZone(25) + motion(device, MotionEvent.AXIS_X, 0.2f) + bridge.setBackQamPressed(true) + advanceTime() + bridge.setBackQamPressed(false) + advanceTime() + bridge.setStickDeadZone(0) + assertEquals(0f, pad().leftX) + motion(device, MotionEvent.AXIS_X, 0.05f) + motion(device, MotionEvent.AXIS_X, 0.5f) + assertEquals(0.5f, pad().leftX) + } + + @Test fun smallVirtualStickInputStillRequiresItsOriginalNeutralRelease() { + bridge.applyExternal({ it.leftX = 0.01f }, true) + bridge.setBackQamPressed(true) + advanceTime() + bridge.setBackQamPressed(false) + advanceTime() + bridge.applyExternal({ it.leftX = 0.5f }, true) + assertEquals(0f, pad().leftX) + bridge.applyExternal({ it.leftX = 0f }, true) + bridge.applyExternal({ it.leftX = 0.5f }, true) + assertEquals(0.5f, pad().leftX) + } + + @Test fun smallTriggerInputStillRequiresItsOriginalNeutralRelease() { + bridge.applyExternal({ it.leftTrigger = 0.01f }, true) + bridge.setBackQamPressed(true) + advanceTime() + bridge.setBackQamPressed(false) + advanceTime() + bridge.applyExternal({ it.leftTrigger = 0.5f }, true) + assertEquals(0f, pad().leftTrigger) + bridge.applyExternal({ it.leftTrigger = 0f }, true) + bridge.applyExternal({ it.leftTrigger = 0.5f }, true) + assertEquals(0.5f, pad().leftTrigger) + } + private fun key(device: InputDevice, code: Int, action: Int = KeyEvent.ACTION_DOWN, repeat: Int = 0, scan: Int = 0) = KeyEvent(0L, 0L, action, code, repeat, 0, device.id, scan, 0, InputDevice.SOURCE_GAMEPAD) - private fun motion(device: InputDevice, axis: Int, value: Float) { + private fun motion(device: InputDevice, axis: Int, value: Float) = motion(device, axis to value) + + private fun motion(device: InputDevice, vararg values: Pair) { val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 1, arrayOf(MotionEvent.PointerProperties().apply { id = 0 }), - arrayOf(MotionEvent.PointerCoords().apply { setAxisValue(axis, value) }), + arrayOf(MotionEvent.PointerCoords().apply { for ((axis, value) in values) setAxisValue(axis, value) }), 0, 0, 1f, 1f, device.id, 0, InputDevice.SOURCE_JOYSTICK, 0) try { assertTrue(bridge.onMotionEvent(event)) } finally { event.recycle() } } diff --git a/app/src/test/java/com/droiddeck/launcher/input/StickDeadZoneTest.kt b/app/src/test/java/com/droiddeck/launcher/input/StickDeadZoneTest.kt new file mode 100644 index 0000000000..38ebeefca9 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/input/StickDeadZoneTest.kt @@ -0,0 +1,473 @@ +package com.droiddeck.launcher.input + +import android.hardware.input.InputManager +import android.os.Looper +import android.util.SparseArray +import android.view.InputDevice +import android.view.KeyEvent +import android.view.MotionEvent +import java.nio.file.Files +import java.time.Duration +import org.junit.After +import org.junit.Assert.* +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.Shadows.shadowOf +import org.robolectric.annotation.Config +import org.robolectric.shadows.InputDeviceBuilder +import org.robolectric.util.ReflectionHelpers + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34], manifest = Config.NONE, instrumentedPackages = ["com.droiddeck.launcher.input.FakeInputWriter"], + shadows = [PadBridgeRoutingTest.RegisteredKeyEvent::class, PadBridgeRoutingTest.RegisteredMotionEvent::class, + JoyConPadTest.RecordingWriter::class]) +class StickDeadZoneTest { + private val context get() = RuntimeEnvironment.getApplication() + private val directory = Files.createTempDirectory("stick-dead-zone").toFile() + private lateinit var bridge: PadBridge + + @Before fun start() { + ControllerPrefs.prefs(context).edit().clear().commit() + JoyConPadTest.RecordingWriter.pads.clear() + bridge = PadBridge(directory) + assertTrue(bridge.start()) + } + + @After fun stop() { + bridge.stop() + ControllerPrefs.prefs(context).edit().clear().commit() + directory.deleteRecursively() + } + + @Test fun preferencesDefaultToTwelveAndPersistZero() { + assertEquals(12, ControllerPrefs.read(context).deadZone) + assertEquals(listOf(0, 5, 8, 12, 15, 20, 25), ControllerPrefs.deadZones) + ControllerPrefs.setDeadZone(context, 0) + assertEquals(0, ControllerPrefs.read(context).deadZone) + } + + @Test fun invalidPreferencesFallBackAndResetRestoresDefault() { + ControllerPrefs.setDeadZone(context, 99) + assertEquals(12, ControllerPrefs.deadZone(context)) + ControllerPrefs.setDeadZone(context, 25) + ControllerPrefs.resetAll(context) + assertEquals(12, ControllerPrefs.deadZone(context)) + } + + @Test fun changingDeadZonePreservesOfficialShortcutsAndControllerSettings() { + val button = PhysicalShortcuts.Button("test-pad", "Test pad", KeyEvent.KEYCODE_BUTTON_MODE, 0) + val binding = PhysicalShortcuts.Binding(button, PhysicalShortcuts.Action.QAM) + PhysicalShortcuts.assign(context, button, binding.action) + ControllerPrefs.setTarget(context, "a", "b") + ControllerPrefs.setRumble(context, false) + for (percent in ControllerPrefs.deadZones) { + ControllerPrefs.setDeadZone(context, percent) + val settings = ControllerPrefs.read(context) + assertEquals(percent, settings.deadZone) + assertEquals(listOf(binding), PhysicalShortcuts.read(context)) + assertEquals("b", settings.mapping["a"]) + assertFalse(settings.rumble) + } + } + + @Test fun assigningAnOfficialShortcutPreservesDeadZone() { + ControllerPrefs.setDeadZone(context, 25) + PhysicalShortcuts.assign(context, + PhysicalShortcuts.Button("test-pad", "Test pad", KeyEvent.KEYCODE_BUTTON_MODE, 0), + PhysicalShortcuts.Action.STEAM) + assertEquals(25, ControllerPrefs.read(context).deadZone) + } + + @Test fun defaultSuppressesBothAxesInsideTheCircle() { + motion(device(), MotionEvent.AXIS_X to 0.05f, MotionEvent.AXIS_Y to -0.06f) + assertEquals(0f, pad().leftX) + assertEquals(0f, pad().leftY) + } + + @Test fun diagonalOutsideTheCircleIsNotLostToAnAxisCross() { + motion(device(), MotionEvent.AXIS_X to 0.09f, MotionEvent.AXIS_Y to -0.09f) + assertEquals(0.09f, pad().leftX) + assertEquals(-0.09f, pad().leftY) + } + + @Test fun smallCrossAxisMotionSurvivesWhenTheStickIsHeldOver() { + motion(device(), MotionEvent.AXIS_X to 0.6f, MotionEvent.AXIS_Y to 0.02f) + assertEquals(0.6f, pad().leftX) + assertEquals(0.02f, pad().leftY) + } + + @Test fun zeroDisablesFilteringForBothSticks() { + bridge.setStickDeadZone(0) + motion(device(), MotionEvent.AXIS_X to 0.01f, MotionEvent.AXIS_Y to -0.02f, + MotionEvent.AXIS_Z to 0.03f, MotionEvent.AXIS_RZ to -0.04f) + assertEquals(0.01f, pad().leftX) + assertEquals(-0.02f, pad().leftY) + assertEquals(0.03f, pad().rightX) + assertEquals(-0.04f, pad().rightY) + } + + @Test fun changingTheSettingAffectsTheExistingBridge() { + val device = device() + bridge.setStickDeadZone(25) + motion(device, MotionEvent.AXIS_X to 0.2f, MotionEvent.AXIS_Z to 0.4f) + assertEquals(0f, pad().leftX) + assertEquals(0.4f, pad().rightX) + bridge.setStickDeadZone(0) + assertEquals(0.2f, pad().leftX) + assertEquals(0.4f, pad().rightX) + } + + @Test fun changingPreferenceReprojectsAllSticksWithoutAnotherMotionEvent() { + motion(device(), MotionEvent.AXIS_X to 0.2f, MotionEvent.AXIS_Y to 0.02f, + MotionEvent.AXIS_Z to 0.03f, MotionEvent.AXIS_RZ to -0.04f) + bridge.setStickDeadZone(25) + assertEquals(0f, pad().leftX) + assertEquals(0f, pad().rightY) + bridge.setStickDeadZone(0) + assertEquals(0.2f, pad().leftX) + assertEquals(0.02f, pad().leftY) + assertEquals(0.03f, pad().rightX) + assertEquals(-0.04f, pad().rightY) + } + + @Test fun preferenceChangesReprojectEveryPlayer() { + motion(device(id = 61), MotionEvent.AXIS_X to 0.2f) + motion(device(id = 62), MotionEvent.AXIS_Z to -0.2f) + bridge.setStickDeadZone(25) + assertEquals(0f, pad().leftX) + assertEquals(0f, requireNotNull(JoyConPadTest.RecordingWriter.pads[1]).rightX) + bridge.setStickDeadZone(0) + assertEquals(0.2f, pad().leftX) + assertEquals(-0.2f, requireNotNull(JoyConPadTest.RecordingWriter.pads[1]).rightX) + } + + @Test fun preferenceChangesReprojectBothHalvesOfAJoyConPair() { + val left = device(joyCon = true, id = 61) + val right = device(joyCon = true, id = 62, rightJoyCon = true) + motion(left) + motion(right) + motion(left, MotionEvent.AXIS_X to 0.2f) + motion(right, MotionEvent.AXIS_RX to -0.2f) + bridge.setStickDeadZone(25) + assertEquals(0f, pad().leftX) + assertEquals(0f, pad().rightX) + bridge.setStickDeadZone(0) + assertEquals(0.2f, pad().leftX) + assertEquals(-0.2f, pad().rightX) + } + + @Test fun preferenceChangesDoNotReplaceTouchStickInput() { + motion(device(), MotionEvent.AXIS_X to 0.2f, MotionEvent.AXIS_Z to -0.2f) + bridge.applyTouch { it.leftX = 0.8f } + bridge.setStickDeadZone(25) + assertEquals(0.8f, pad().leftX) + assertEquals(0f, pad().rightX) + bridge.setStickDeadZone(0) + assertEquals(0.8f, pad().leftX) + assertEquals(-0.2f, pad().rightX) + } + + @Test fun explicitZeroTouchWriteDiscardsFilteredPhysicalLeftStick() { + motion(device(), MotionEvent.AXIS_X to 0.05f, MotionEvent.AXIS_Z to -0.05f) + bridge.applyTouch(PadBridge.LEFT_STICK) { it.leftX = 0f; it.leftY = 0f } + bridge.setStickDeadZone(0) + assertEquals(0f, pad().leftX) + assertEquals(-0.05f, pad().rightX) + } + + @Test fun explicitZeroTouchWriteDiscardsFilteredPhysicalRightStick() { + motion(device(), MotionEvent.AXIS_X to 0.05f, MotionEvent.AXIS_Z to -0.05f) + bridge.applyTouch(PadBridge.RIGHT_STICK) { it.rightX = 0f; it.rightY = 0f } + bridge.setStickDeadZone(0) + assertEquals(0.05f, pad().leftX) + assertEquals(0f, pad().rightX) + } + + @Test fun routedTouchStickWritesKeepSeparatePhysicalInput() { + motion(device(), MotionEvent.AXIS_X to 0.05f) + bridge.setTouchRoute(object : PadBridge.TouchRoute { + override fun active() = true + override fun accept(state: PadState) { assertEquals(0f, state.leftX) } + }) + bridge.applyTouch(PadBridge.LEFT_STICK) { it.leftX = 0f; it.leftY = 0f } + bridge.setStickDeadZone(0) + assertEquals(0.05f, pad().leftX) + } + + @Test fun touchButtonOnlyWritesKeepFilteredPhysicalSticks() { + motion(device(), MotionEvent.AXIS_X to 0.05f) + bridge.applyTouch { it.press(PadState.A, true) } + bridge.setStickDeadZone(0) + assertEquals(0.05f, pad().leftX) + assertTrue(pad().isDown(PadState.A)) + } + + @Test fun preferenceChangesDoNotReplaceExternalStickInput() { + motion(device(), MotionEvent.AXIS_X to 0.2f, MotionEvent.AXIS_Z to -0.2f) + bridge.applyExternal({ it.rightX = 0.8f }, true) + bridge.setStickDeadZone(25) + assertEquals(0f, pad().leftX) + assertEquals(0.8f, pad().rightX) + } + + @Test fun buttonAndTriggerMutationsKeepPhysicalSticksReprojectable() { + motion(device(), MotionEvent.AXIS_X to 0.2f) + bridge.applyExternal({ it.leftTrigger = 0.7f; it.press(PadState.X, true) }, true) + bridge.setStickDeadZone(25) + assertEquals(0f, pad().leftX) + assertEquals(0.7f, pad().leftTrigger) + assertTrue(pad().isDown(PadState.X)) + bridge.setStickDeadZone(0) + assertEquals(0.2f, pad().leftX) + } + + @Test fun releaseAllDiscardsEvenPreviouslyFilteredRawMotion() { + motion(device(), MotionEvent.AXIS_X to 0.05f) + bridge.releaseAll() + bridge.setStickDeadZone(0) + assertEquals(0f, pad().leftX) + } + + @Test fun aDisconnectedControllerDoesNotReturnOnPreferenceChange() { + val device = device() + motion(device, MotionEvent.AXIS_X to 0.2f) + bridge.onDeviceRemoved(device.id) + bridge.setStickDeadZone(0) + assertEquals(0f, pad().leftX) + } + + @Test fun pairingDoesNotRestoreAnOldJoyConPosition() { + val left = device(joyCon = true, id = 61) + val right = device(joyCon = true, id = 62, rightJoyCon = true) + motion(left, MotionEvent.AXIS_X to 0.2f) + motion(right) + bridge.setStickDeadZone(0) + assertEquals(0f, pad().leftX) + } + + @Test fun aControllerRemovedWhileInactiveDoesNotReturnOnPreferenceChange() { + val device = device() + motion(device, MotionEvent.AXIS_X to 0.05f) + val manager = ReflectionHelpers.callStaticMethod(Class.forName("android.hardware.input.InputManagerGlobal"), "getInstance") + ReflectionHelpers.getField>(manager, "mInputDevices").remove(device.id) + assertNull(InputDevice.getDevice(device.id)) + bridge.setStickDeadZone(0) + assertEquals(0f, pad().leftX) + } + + @Test fun excludedControllerInputIsNotRestoredOnPreferenceChange() { + val device = device() + motion(device, MotionEvent.AXIS_X to 0.2f) + bridge.setExcluded { it == device.id } + bridge.setStickDeadZone(0) + assertEquals(0f, pad().leftX) + } + + @Test fun preferenceChangesDoNotGenerateChordInput() { + motion(device(), MotionEvent.AXIS_X to 0.2f) + var notifications = 0 + bridge.setOnChordInput { notifications++ } + bridge.setStickDeadZone(25) + bridge.setStickDeadZone(0) + assertEquals(0, notifications) + } + + @Test fun aStoppedBridgeDoesNotRepublishOldInput() { + motion(device(), MotionEvent.AXIS_X to 0.2f) + bridge.stop() + JoyConPadTest.RecordingWriter.pads.clear() + bridge.setStickDeadZone(0) + assertTrue(JoyConPadTest.RecordingWriter.pads.isEmpty()) + } + + @Test fun theBoundaryPassesThroughWithoutRescaling() { + assertFalse(PadBridge.inStickDeadZone(0.12f, 0f, 0.12f)) + motion(device(), MotionEvent.AXIS_X to 0.12f) + assertEquals(0.12f, pad().leftX) + } + + @Test fun wiredXboxKeepsItsRightStickAndSignedTriggerAxes() { + bridge.setStickDeadZone(0) + motion(device(wired = true), MotionEvent.AXIS_RX to 0.02f, MotionEvent.AXIS_RY to -0.03f, + MotionEvent.AXIS_Z to -1f, MotionEvent.AXIS_RZ to 1f) + assertEquals(0.02f, pad().rightX) + assertEquals(-0.03f, pad().rightY) + assertEquals(0f, pad().leftTrigger) + assertEquals(1f, pad().rightTrigger) + } + + @Test fun joyConUsesTheSelectedDeadZone() { + bridge.setStickDeadZone(0) + motion(device(joyCon = true), MotionEvent.AXIS_X to 0.01f, MotionEvent.AXIS_Y to -0.02f) + assertEquals(0.01f, pad().leftX) + assertEquals(-0.02f, pad().leftY) + } + + @Test fun stickSettingDoesNotChangeMouseAxisHelpers() { + bridge.setStickDeadZone(0) + for (wired in listOf(false, true)) { + var horizontal = 0f + var vertical = 0f + val mouse = PadMouse(object : PadMouse.Listener { + override fun active() = true + override fun onScrollStart() {} + override fun onScroll(dx: Float, dy: Float) { horizontal += dx; vertical += dy } + override fun onKey(evdev: Int, pressed: Boolean) {} + override fun onKeyboard() {} + override fun onNavigate() {} + override fun scrollSpeed() = 2000f + }) { 1000L } + val event = if (wired) event(device(wired = true, id = 62), MotionEvent.AXIS_RX to 0.02f, + MotionEvent.AXIS_RY to 0.6f, MotionEvent.AXIS_Z to -1f, MotionEvent.AXIS_RZ to -1f) + else event(device(), MotionEvent.AXIS_Z to 0.02f, MotionEvent.AXIS_RZ to 0.6f) + try { + assertTrue(mouse.onMotion(event)) + mouse.step(0.1f) + assertEquals(0f, horizontal) + assertTrue(vertical > 0f) + } finally { event.recycle(); mouse.reset() } + } + } + + @Test fun zeroDeadZoneDriftDoesNotConsumeBackTap() { + val (taps, presses) = backTapWithMotion(device(), MotionEvent.AXIS_X to 0.01f) + assertEquals(0.01f, pad().leftX) + assertEquals(listOf(false), taps) + assertTrue(presses.isEmpty()) + } + + @Test fun zeroDeadZoneJoyConDriftDoesNotConsumeBackTap() { + val (taps, presses) = backTapWithMotion(device(joyCon = true), MotionEvent.AXIS_X to 0.01f) + assertEquals(0.01f, pad().leftX) + assertEquals(listOf(false), taps) + assertTrue(presses.isEmpty()) + } + + @Test fun diagonalInsideTheLegacyChordGuardDoesNotConsumeBackTap() { + val (taps, presses) = backTapWithMotion(device(), MotionEvent.AXIS_X to 0.09f, MotionEvent.AXIS_Y to 0.09f) + assertEquals(0.09f, pad().leftX) + assertEquals(0.09f, pad().leftY) + assertEquals(listOf(false), taps) + assertTrue(presses.isEmpty()) + } + + @Test fun intentionalMotionOnEitherStickStillMakesABackChord() { + val device = device() + for (axis in intArrayOf(MotionEvent.AXIS_X, MotionEvent.AXIS_Z)) { + val (taps, presses) = backTapWithMotion(device, axis to 0.5f) + assertTrue(taps.isEmpty()) + assertEquals(listOf(true, false), presses) + } + } + + @Test fun higherGameDeadZoneDoesNotDisableExistingBackChords() { + val (taps, presses) = backTapWithMotion(device(), MotionEvent.AXIS_X to 0.2f, deadZone = 25) + assertEquals(0f, pad().leftX) + assertTrue(taps.isEmpty()) + assertEquals(listOf(true, false), presses) + } + + @Test fun higherGameDeadZoneDoesNotDisableExistingJoyConBackChords() { + val (taps, presses) = backTapWithMotion(device(joyCon = true), MotionEvent.AXIS_X to 0.2f, deadZone = 25) + assertEquals(0f, pad().leftX) + assertTrue(taps.isEmpty()) + assertEquals(listOf(true, false), presses) + } + + private fun backTapWithMotion(device: InputDevice, vararg axes: Pair, deadZone: Int = 0): Pair, List> { + val taps = mutableListOf() + val presses = mutableListOf() + val input = BackQamInput(presses::add, taps::add) + bridge.setStickDeadZone(deadZone) + bridge.setOnChordInput(input::onChordInput) + assertTrue(input.onKeyEvent(KeyEvent(0, 100, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK, + 0, 0, device.id, 0), true)) + motion(device, *axes) + assertTrue(input.onKeyEvent(KeyEvent(0, 100, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK, + 0, 0, device.id, 0), true)) + shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(500)) + return taps to presses + } + + @Test fun neutralScreenStickPressClearsRetainedPhysicalInput() { + val device = device() + for (adaptive in listOf(false, true)) { + ControllerPrefs.setAdaptiveSticks(context, adaptive) + ControllerPrefs.setLayout(context, 1200, 800, mapOf("ls" to (0.45f to 0.5f), "rs" to (0.55f to 0.5f))) + for (id in listOf("ls", "rs")) { + motion(device, MotionEvent.AXIS_X to 0.6f, MotionEvent.AXIS_Z to 0.7f) + val view = OnScreenControls(context, bridge) + view.layout(0, 0, 1200, 800) + val controls = ReflectionHelpers.getField>(view, "controls") + val control = controls.first { ReflectionHelpers.getField(it, "id") == id } + val x = ReflectionHelpers.getField(control, "cx") + val y = ReflectionHelpers.getField(control, "cy") + val down = MotionEvent.obtain(1000, 1000, MotionEvent.ACTION_DOWN, x, y, 0) + try { assertTrue(view.onTouchEvent(down)) } finally { down.recycle() } + assertFalse(ReflectionHelpers.getField(control, "dirty")) + assertEquals(0f, if (id == "ls") pad().leftX else pad().rightX, 0f) + assertTrue((if (id == "ls") pad().rightX else pad().leftX) > 0f) + bridge.setStickDeadZone(25) + assertEquals(0f, if (id == "ls") pad().leftX else pad().rightX, 0f) + motion(device, MotionEvent.AXIS_X to 0.6f, MotionEvent.AXIS_Z to 0.7f) + val button = controls.first { ReflectionHelpers.getField(it, "id") == "a" } + val bx = ReflectionHelpers.getField(button, "cx") + val by = ReflectionHelpers.getField(button, "cy") + fun buttonTouch(action: Int, time: Long) { + val event = MotionEvent.obtain(1000, time, action or (1 shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, + arrayOf(MotionEvent.PointerProperties().apply { this.id = 0; toolType = MotionEvent.TOOL_TYPE_FINGER }, + MotionEvent.PointerProperties().apply { this.id = 1; toolType = MotionEvent.TOOL_TYPE_FINGER }), + arrayOf(MotionEvent.PointerCoords().apply { this.x = x; this.y = y }, + MotionEvent.PointerCoords().apply { this.x = bx; this.y = by }), + 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0) + try { assertTrue(view.onTouchEvent(event)) } finally { event.recycle() } + } + buttonTouch(MotionEvent.ACTION_POINTER_DOWN, 1030) + assertTrue(pad().isDown(PadState.A)) + assertEquals(0.6f, pad().leftX, 0f) + assertEquals(0.7f, pad().rightX, 0f) + buttonTouch(MotionEvent.ACTION_POINTER_UP, 1060) + assertFalse(pad().isDown(PadState.A)) + bridge.setStickDeadZone(12) + assertEquals(0.6f, pad().leftX, 0f) + assertEquals(0.7f, pad().rightX, 0f) + val up = MotionEvent.obtain(1000, 1100, MotionEvent.ACTION_UP, x, y, 0) + try { assertTrue(view.onTouchEvent(up)) } finally { up.recycle() } + } + } + } + + private fun pad() = requireNotNull(JoyConPadTest.RecordingWriter.pads[0]) + + private fun motion(device: InputDevice, vararg axes: Pair) { + val event = event(device, *axes) + try { assertTrue(bridge.onMotionEvent(event)) } finally { event.recycle() } + } + + private fun event(device: InputDevice, vararg axes: Pair): MotionEvent { + val coords = MotionEvent.PointerCoords().apply { for ((axis, value) in axes) setAxisValue(axis, value) } + return MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 1, + arrayOf(MotionEvent.PointerProperties().apply { id = 0 }), arrayOf(coords), + 0, 0, 1f, 1f, device.id, 0, InputDevice.SOURCE_JOYSTICK, 0) + } + + private fun device(wired: Boolean = false, joyCon: Boolean = false, id: Int = 61, rightJoyCon: Boolean = false): InputDevice { + val builder = InputDeviceBuilder.newBuilder().setId(id) + .setName(if (joyCon) if (rightJoyCon) "Joy-Con (R)" else "Joy-Con (L)" else "dead-zone pad") + .setDescriptor("dead-zone-pad-$id").setExternal(true) + .setSources(InputDevice.SOURCE_GAMEPAD or InputDevice.SOURCE_JOYSTICK) + .setKeyboardType(InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC) + .setVendorId(if (joyCon) 0x057e else if (wired) 0x20d6 else 0) + .setProductId(if (joyCon) if (rightJoyCon) 0x2007 else 0x2006 else if (wired) 0x2063 else 0) + for (axis in intArrayOf(MotionEvent.AXIS_X, MotionEvent.AXIS_Y, MotionEvent.AXIS_Z, + MotionEvent.AXIS_RZ, MotionEvent.AXIS_RX, MotionEvent.AXIS_RY)) { + builder.addMotionRange(axis, InputDevice.SOURCE_JOYSTICK, -1f, 1f, 0f, 0f, 0f) + } + return builder.build().also { + shadowOf(context.getSystemService(InputManager::class.java)).addInputDevice(it) + } + } +} From e72cddccd9a7d003095a0f8268cff55b91090b9d Mon Sep 17 00:00:00 2001 From: dddms <2541684445@qq.com> Date: Thu, 29 Oct 2026 15:27:43 +0800 Subject: [PATCH 16/85] perf(steam): decode requested appinfo records only Avoid decoding every app when Start without Steam resolves one game launch. Use wanted-app selection in the single-game helpers while keeping the existing field decoder and full-reader default for bulk callers. Track partial coverage separately from complete results, share one immutable byte snapshot for incremental queries, and keep timestamp invalidation and warm hits. Preserve the last valid duplicate record and release the raw snapshot after a full decode. Add format/cache/structural-budget and launch-resolution regressions, reuse the existing binary fixture encoder, and document the host-only performance scope. --- docs/development/game-environment.md | 9 + .../usr/local/bin/droiddeck-proton-run | 4 +- .../overlay/usr/local/bin/steam-compatibility | 38 ++- tools/tests/test_appinfo_lookup.py | 248 ++++++++++++++++++ tools/tests/test_droiddeck_fex.py | 3 +- 5 files changed, 290 insertions(+), 12 deletions(-) create mode 100644 tools/tests/test_appinfo_lookup.py diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md index fafc802f9d..456e66cc6a 100644 --- a/docs/development/game-environment.md +++ b/docs/development/game-environment.md @@ -19,6 +19,15 @@ per-app compatibility mapping, including while Steam is running when its live compatibility helper is attached. A newly installed Proton that the running client has not discovered yet applies when Steam next starts. +For **Start without Steam**, `droiddeck-proton-run --app` decodes only the requested +game's `appinfo.vdf` records to choose its executable and arguments. The reader still +supports formats 27-29 and reads the file/string table; this is not a reduction in +disk-read bytes. Repeated queries reuse a process-local cache, with partial coverage +kept distinct from a complete decode. Partial queries share one immutable byte +snapshot; a complete decode drops that byte snapshot, and a file timestamp change +invalidates the cache. Bulk callers still request all entries. Launch selection, +prefix/Proton choices and saved settings are unchanged. + Each game can also override the stored FEX, DXVK and VKD3D-Proton package used by its selected Proton. The launch wrapper applies that game’s component files immediately before Proton starts, removes managed files that are absent from the diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-proton-run b/tools/linuxfs/overlay/usr/local/bin/droiddeck-proton-run index 410f1654d1..237457d947 100644 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-proton-run +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-proton-run @@ -351,7 +351,7 @@ def steam_launch(appid, root): library, install = steam_install(appid, root) if not install or not os.path.isdir(install): return None - entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf")).get(str(appid), {}) + entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf"), wanted={str(appid)}).get(str(appid), {}) options = [option for option in entry.get("launch_options", ()) if not option["betakey"] and (not option["oslist"] or "windows" in option["oslist"])] options.sort(key=lambda option: (option["type"] not in ("", "default", "none"), @@ -376,7 +376,7 @@ def shortcut_target(appid, program, start, root): def steam_launches(target, program, root): if target.kind != "steam": return False - entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf")).get(target.appid, {}) + entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf"), wanted={target.appid}).get(target.appid, {}) return os.path.relpath(program, target.install).replace(os.sep, "/").lower() in entry.get("launch", ()) diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility index 397a19d73d..acacb0e17d 100755 --- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility +++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility @@ -777,20 +777,32 @@ def launch_options(config): return found -def appinfo_entries(path): +def appinfo_entries(path, wanted=None): + """Read metadata for all apps, or only the requested app-id strings.""" import struct + if wanted is not None: + wanted = set(wanted) + if not wanted: + return {} try: stamp = os.stat(path).st_mtime_ns except OSError: return {} cached = APPINFO_CACHE.get(path) if cached and cached[0] == stamp: - return cached[1] - try: - with open(path, "rb") as f: - data = f.read() - except OSError: - return {} + covered = cached[2] + if covered is None or (wanted is not None and wanted <= covered): + return cached[1] if wanted is None else {app: cached[1][app] for app in wanted if app in cached[1]} + data = cached[3] + needed = None if wanted is None else wanted - covered + else: + cached = None + needed = wanted + try: + with open(path, "rb") as f: + data = f.read() + except OSError: + return {} if len(data) < 8: return {} magic = struct.unpack_from("= 0x07564428 else 40) + offset += 8 + size + assert payload is not None + data[payload] = 0xFF + self.path.write_bytes(data) + COMPAT["APPINFO_CACHE"].clear() + full = self.lookup() + COMPAT["APPINFO_CACHE"].clear() + selected = self.lookup({"1"}) + self.assertEqual(selected, {"1": full["1"]}) + self.assertEqual(selected["1"]["launch"][0], "last.exe" if corrupt_last else "final.exe") + + def test_requested_steam_play_manifest_keeps_extended_mappings(self): + manifests = COMPAT["STEAM_PLAY_MANIFESTS"] + record = {"common": {"type": "Tool"}, "extended": {"app_mappings": { + "0": {"appid": "42", "tool": "proton_experimental"}, + }}} + for magic in FORMATS: + with self.subTest(magic=magic): + COMPAT["APPINFO_CACHE"].clear() + self.write({1: entry("One"), manifests: record}, magic) + self.assertEqual(self.lookup({str(manifests)})[str(manifests)]["app_mappings"], + {"42": "proton_experimental"}) + + def test_empty_requests_do_not_read_or_stat_the_file(self): + with mock.patch("builtins.open", side_effect=AssertionError("no file should be read")): + with mock.patch.object(COMPAT["os"], "stat", side_effect=AssertionError("no stat is needed")): + self.assertEqual(self.lookup(set()), {}) + self.assertEqual(COMPAT["APPINFO_CACHE"], {}) + + def test_missing_and_invalid_files_keep_empty_results(self): + self.assertEqual(self.lookup({"1"}), {}) + for data in (b"", b"\x29", struct.pack(" Date: Sun, 1 Nov 2026 10:40:55 +0800 Subject: [PATCH 17/85] fix: quote GPU environment values before writing shell exports --- tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 index 2a97bcb81d..42c68c73dd 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 @@ -720,7 +720,7 @@ if x64_gpu; then echo "export FEX_THUNKCONFIG='$X64_HOME/thunks.json'" echo "unset LIBGL_ALWAYS_SOFTWARE LIBGL_DRI3_DISABLE GALLIUM_DRIVER" for v in $gpu_vars; do - eval "val=\${$v-}"; [ -n "$val" ] && printf "export %s='%s'\n" "$v" "$val" + eval "val=\${$v-}"; [ -n "$val" ] && printf "export %s='%s'\n" "$v" "${val//\'/\'\\\'\'}" done } > "$X64_HOME/game-gpu.env" fi From ef305c93cdc4d2ded0285b95e46992dfff7040a4 Mon Sep 17 00:00:00 2001 From: coffeemeist3r Date: Wed, 4 Nov 2026 19:32:24 -0600 Subject: [PATCH 18/85] fix(mesa): Steam's UI no longer crashes when scrolling the Home shelf fast on PowerVR Zink's rebind_image() and zink_rebind_all_images() refreshed only a sampler view's main image view after the resource got a new backing object. The view's zs_view and cube_array surfaces stayed on the old object and were freed with it, so the next descriptor update wrote a garbage VkImageView. On PowerVR (needs_zs_shader_swizzle) every RGBX/BGRX view has a zs_view, and Steam's web helper segfaulted in vkUpdateDescriptorSetWithTemplate within seconds of fast Right presses on the Home shelf. The new Mesa patch rebuilds all of the view's surfaces with init_sampler_view(). --- ...every-sampler-view-surface-on-rebind.patch | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tools/ubuntu/patches/mesa/0004-zink-recreate-every-sampler-view-surface-on-rebind.patch diff --git a/tools/ubuntu/patches/mesa/0004-zink-recreate-every-sampler-view-surface-on-rebind.patch b/tools/ubuntu/patches/mesa/0004-zink-recreate-every-sampler-view-surface-on-rebind.patch new file mode 100644 index 0000000000..c4f5b3df1d --- /dev/null +++ b/tools/ubuntu/patches/mesa/0004-zink-recreate-every-sampler-view-surface-on-rebind.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: coffeemeist3r +Date: Wed, 4 Nov 2026 19:40:00 -0500 +Subject: [PATCH] zink: recreate every sampler view surface on rebind + +rebind_image() and zink_rebind_all_images() refreshed only +sv->image_view after a resource got a new backing object (for example the +ZINK_BIND_MUTABLE switch that zink_get_surface() itself triggers). The +view's cube_array and zs_view surfaces still belonged to the old object, and +get_imageview_for_binding() hands those out. Once the old object was freed, +its surfaces went with it, and the next descriptor update wrote a garbage +VkImageView. + +Imagination drivers set needs_zs_shader_swizzle, so every view with a +constant-1 swizzle (RGBX/BGRX alpha) gets a zs_view there. Steam's web +helper (Chromium on ANGLE on Zink) hit this within seconds of fast Home +shelf scrolling on a Pixel 10 Pro Fold and segfaulted in the driver's +vkUpdateDescriptorSetWithTemplate. Rebuild all of the view's surfaces with +init_sampler_view() instead. Still present in Mesa main. +--- +diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c +--- a/src/gallium/drivers/zink/zink_context.c ++++ b/src/gallium/drivers/zink/zink_context.c +@@ -5351,8 +5351,8 @@ rebind_image(struct zink_context *ctx, struct zink_resource *res) + struct zink_sampler_view *sv = zink_sampler_view(ctx->sampler_views[i][j]); + if (sv && sv->base.texture == &res->base.b) { + sv->rebind_count = res->rebind_count; +- struct pipe_surface tmpl = pipe_surface_templ_from_sampler_view(&sv->base, &res->base.b, sv->base.target); +- sv->image_view = zink_get_surface(ctx, &tmpl, &sv->ivci); ++ /* recreate every surface of the view: cube_array and zs_view belong to the old object too */ ++ init_sampler_view(ctx, sv); + ctx->invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW, j, 1); + update_descriptor_state_sampler(ctx, i, j, res); + } +@@ -5457,8 +5457,7 @@ zink_rebind_all_images(struct zink_context *ctx) + struct zink_resource *res = zink_resource(sv->base.texture); + if (res->rebind_count != sv->rebind_count) { + sv->rebind_count = res->rebind_count; +- struct pipe_surface tmpl = pipe_surface_templ_from_sampler_view(&sv->base, &res->base.b, sv->base.target); +- sv->image_view = zink_get_surface(ctx, &tmpl, &sv->ivci); ++ init_sampler_view(ctx, sv); + ctx->invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW, j, 1); + update_descriptor_state_sampler(ctx, i, j, res); + } From e1fe6f99cf303121a100c7bc1f936ed50e3921a9 Mon Sep 17 00:00:00 2001 From: uubooster-team Date: Sat, 31 Oct 2026 21:11:59 +0800 Subject: [PATCH 19/85] fix(network): handle gatewayless IPv4 VPN links Provide compatible gateway metadata for IPv4 VPN links without changing VPN routing, and keep text and JSON network snapshots consistent. Add regression tests for gateway selection and network snapshots. --- .../runtime/LinuxNetworkLinkComponent.kt | 38 +++-- .../runtime/LinuxNetworkLinkComponentTest.kt | 158 ++++++++++++++++++ tools/tests/test_netmanager.py | 12 ++ 3 files changed, 197 insertions(+), 11 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponentTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt index 06a0348253..7081d88114 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt @@ -9,6 +9,7 @@ import android.net.ConnectivityManager import android.net.LinkProperties import android.net.Network import android.net.NetworkCapabilities +import android.net.RouteInfo import android.net.wifi.WifiInfo import android.net.wifi.WifiManager import android.os.Build @@ -23,6 +24,7 @@ import java.io.File import java.io.IOException import java.net.Inet4Address import java.net.Inet6Address +import java.net.InetAddress import org.json.JSONArray import org.json.JSONObject @@ -156,7 +158,7 @@ class LinuxNetworkLinkComponent( try { file.parentFile?.mkdirs() val staged = File(file.path + ".staged") - staged.writeText(describe(properties)) + staged.writeText(describe(properties, capabilities)) if (!staged.renameTo(file)) throw IOException("Could not replace $file") } catch (e: IOException) { Log.w(TAG, "Could not publish the network link", e) @@ -210,11 +212,7 @@ class LinuxNetworkLinkComponent( } }) put("gateways", JSONArray().apply { - properties?.routes.orEmpty().filter { it.isDefaultRoute }.forEach { - it.gateway?.takeUnless { address -> address.isAnyLocalAddress }?.let { address -> - put(address.hostAddress?.substringBefore('%')) - } - } + gateways(properties, capabilities).forEach { put(it.hostAddress?.substringBefore('%')) } }) put("dns", JSONArray().apply { properties?.dnsServers.orEmpty().filter { !it.isLinkLocalAddress }.forEach { @@ -301,7 +299,7 @@ class LinuxNetworkLinkComponent( } } - private fun describe(properties: LinkProperties?): String { + internal fun describe(properties: LinkProperties?, capabilities: NetworkCapabilities?): String { val addresses = properties?.linkAddresses.orEmpty() .filter { it.address is Inet4Address || it.address is Inet6Address } val name = properties?.interfaceName?.takeIf { addresses.isNotEmpty() } ?: OFFLINE_NAME @@ -316,10 +314,7 @@ class LinuxNetworkLinkComponent( for (address in addresses) { append("addr ${address.address.hostAddress?.substringBefore('%')} ${address.prefixLength}\n") } - for (family in listOf(Inet4Address::class.java, Inet6Address::class.java)) { - val gateway = properties?.routes.orEmpty() - .firstOrNull { it.isDefaultRoute && family.isInstance(it.gateway) && !it.gateway!!.isAnyLocalAddress } - ?.gateway ?: continue + for (gateway in gateways(properties, capabilities)) { append("gw ${gateway.hostAddress?.substringBefore('%')}\n") } } @@ -329,6 +324,27 @@ class LinuxNetworkLinkComponent( seededMac { Settings.Secure.getString(appContext.contentResolver, Settings.Secure.ANDROID_ID) } companion object { + internal fun gateways(properties: LinkProperties?, capabilities: NetworkCapabilities?): List = + listOf(Inet4Address::class.java, Inet6Address::class.java).mapNotNull { family -> + properties?.routes.orEmpty() + .firstOrNull { it.isDefaultRoute && family.isInstance(it.gateway) && !it.gateway!!.isAnyLocalAddress } + ?.gateway + ?: if (family == Inet4Address::class.java && + capabilities?.hasTransport(NetworkCapabilities.TRANSPORT_VPN) == true && + capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) && + properties?.interfaceName != null && + properties.routes.any { + it.destination.address is Inet4Address && + (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || it.type == RouteInfo.RTN_UNICAST) + } + ) { + properties.linkAddresses.firstOrNull { + it.address is Inet4Address && !it.address.isAnyLocalAddress && + !it.address.isLoopbackAddress && !it.address.isLinkLocalAddress + }?.address + } else null + } + internal fun seededMac(readId: () -> String?): String { val id = runCatching(readId).getOrNull() ?: "bannerlator" val bytes = java.security.MessageDigest.getInstance("SHA-1").digest(id.toByteArray()) diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponentTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponentTest.kt new file mode 100644 index 0000000000..ee745b7d14 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponentTest.kt @@ -0,0 +1,158 @@ +package com.droiddeck.launcher.runtime + +import android.content.Context +import android.net.IpPrefix +import android.net.LinkAddress +import android.net.LinkProperties +import android.net.NetworkCapabilities +import android.net.RouteInfo +import androidx.test.core.app.ApplicationProvider +import java.net.InetAddress +import org.junit.Assert.* +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.robolectric.util.ReflectionHelpers +import org.robolectric.util.ReflectionHelpers.ClassParameter.from + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28, 34], manifest = Config.NONE) +class LinuxNetworkLinkComponentTest { + @get:Rule val temporary = TemporaryFolder() + + private fun capabilities(vpn: Boolean = true, internet: Boolean = true) = NetworkCapabilities().apply { + ReflectionHelpers.callInstanceMethod(this, "addTransportType", + from(Int::class.javaPrimitiveType, if (vpn) NetworkCapabilities.TRANSPORT_VPN else NetworkCapabilities.TRANSPORT_WIFI)) + if (internet) ReflectionHelpers.callInstanceMethod(this, "addCapability", + from(Int::class.javaPrimitiveType, NetworkCapabilities.NET_CAPABILITY_INTERNET)) + } + + private fun properties(vararg addresses: String) = LinkProperties().apply { + interfaceName = "tun0" + addresses.forEach { + val address = ReflectionHelpers.callConstructor(LinkAddress::class.java, + from(InetAddress::class.java, InetAddress.getByName(it.substringBefore('/'))), + from(Int::class.javaPrimitiveType, it.substringAfter('/').toInt())) + ReflectionHelpers.callInstanceMethod(this, "addLinkAddress", from(LinkAddress::class.java, address)) + } + } + + private fun LinkProperties.route(destination: String, prefix: Int, gateway: String = "0.0.0.0", + type: Int = RouteInfo.RTN_UNICAST) = apply { + addRoute(ReflectionHelpers.callConstructor(RouteInfo::class.java, + from(IpPrefix::class.java, IpPrefix(InetAddress.getByName(destination), prefix)), + from(InetAddress::class.java, InetAddress.getByName(gateway)), + from(String::class.java, interfaceName), + from(Int::class.javaPrimitiveType, type))) + } + + private fun gateways(properties: LinkProperties?, capabilities: NetworkCapabilities?) = + LinuxNetworkLinkComponent.gateways(properties, capabilities).map { it.hostAddress } + + @Test fun vpnWithOnLinkDefaultRouteHasNonzeroCompatibilityGateway() { + val link = properties("10.0.0.1/24").route("0.0.0.0", 0) + assertEquals(listOf("10.0.0.1"), gateways(link, capabilities())) + } + + @Test fun vpnWithSplitRoutesHasCompatibilityGatewayWithoutDefaultRoute() { + val link = properties("10.0.0.1/24").route("1.0.0.0", 8).route("128.0.0.0", 1) + assertEquals(listOf("10.0.0.1"), gateways(link, capabilities())) + assertTrue(link.routes.none { it.isDefaultRoute }) + assertTrue(link.routes.all { it.gateway!!.isAnyLocalAddress }) + } + + @Test fun realDefaultGatewayIsPreservedEvenForVpn() { + val link = properties("10.0.0.2/24").route("0.0.0.0", 0, "10.0.0.1") + assertEquals(listOf("10.0.0.1"), gateways(link, capabilities())) + } + + @Test fun wifiDefaultGatewayIsUnchanged() { + val link = properties("192.168.1.2/24").route("0.0.0.0", 0, "192.168.1.1") + assertEquals(listOf("192.168.1.1"), gateways(link, capabilities(vpn = false))) + } + + @Test fun nonVpnLinkWithoutGatewayDoesNotBecomeInternetConnected() { + val link = properties("192.168.1.2/24").route("0.0.0.0", 0) + assertTrue(gateways(link, capabilities(vpn = false)).isEmpty()) + } + + @Test fun vpnWithoutInternetCapabilityDoesNotGetGateway() { + val link = properties("10.0.0.1/24").route("0.0.0.0", 0) + assertTrue(gateways(link, capabilities(internet = false)).isEmpty()) + } + + @Test fun missingNetworkOrCapabilitiesDoesNotGetGateway() { + val link = properties("10.0.0.1/24").route("0.0.0.0", 0) + assertTrue(gateways(null, capabilities()).isEmpty()) + assertTrue(gateways(link, null).isEmpty()) + } + + @Test fun vpnWithoutRoutesDoesNotGetGateway() { + assertTrue(gateways(properties("10.0.0.1/24"), capabilities()).isEmpty()) + } + + @Test fun vpnWithoutIpv4AddressDoesNotGetIpv4Gateway() { + val link = properties("fd00::2/64").route("0.0.0.0", 0) + assertTrue(gateways(link, capabilities()).isEmpty()) + } + + @Test fun vpnWithoutIpv4RoutesDoesNotGetIpv4Gateway() { + val link = properties("10.0.0.1/24").route("::", 0, "::") + assertTrue(gateways(link, capabilities()).isEmpty()) + } + + @Test fun reconnectingVpnWithRetainedAddressDoesNotGetGateway() { + val link = properties("10.0.0.1/24").apply { interfaceName = null } + .route("0.0.0.0", 0, type = RouteInfo.RTN_UNREACHABLE) + .route("128.0.0.0", 1, type = RouteInfo.RTN_UNREACHABLE) + assertTrue(gateways(link, capabilities()).isEmpty()) + val description = LinuxNetworkLinkComponent(ApplicationProvider.getApplicationContext(), temporary.root) + .describe(link, capabilities()) + assertTrue(description.contains("addr 10.0.0.1 24\n")) + assertFalse(description.contains("gw ")) + } + + @Config(sdk = [34]) + @Test fun vpnWithoutUnicastIpv4RouteDoesNotGetGateway() { + val link = properties("10.0.0.1/24") + .route("0.0.0.0", 0, type = RouteInfo.RTN_UNREACHABLE) + .route("10.0.0.0", 8, type = RouteInfo.RTN_THROW) + assertTrue(gateways(link, capabilities()).isEmpty()) + } + + @Test fun unspecifiedLoopbackAndLinkLocalAddressesAreNotGateways() { + val link = properties("0.0.0.0/32", "127.0.0.1/8", "169.254.1.2/16").route("0.0.0.0", 0) + assertTrue(gateways(link, capabilities()).isEmpty()) + } + + @Test fun ipv6DefaultGatewayIsPreservedAlongsideVpnIpv4Gateway() { + val link = properties("10.0.0.1/24", "fd00::2/64") + .route("0.0.0.0", 0).route("::", 0, "fe80::1") + assertEquals(listOf(InetAddress.getByName("10.0.0.1"), InetAddress.getByName("fe80::1")), + LinuxNetworkLinkComponent.gateways(link, capabilities())) + } + + @Test fun publishedLinkContainsGatewayAndKeepsVpnInterfaceAndAddress() { + val context = ApplicationProvider.getApplicationContext() + val component = LinuxNetworkLinkComponent(context, temporary.root) + val link = properties("10.0.0.1/24").route("1.0.0.0", 8).route("128.0.0.0", 1) + val before = ReflectionHelpers.callConstructor(LinkProperties::class.java, from(LinkProperties::class.java, link)) + val description = component.describe(link, capabilities()) + assertTrue(description.contains("if tun0 2 1500\n")) + assertTrue(description.contains("addr 10.0.0.1 24\n")) + assertTrue(description.contains("gw 10.0.0.1\n")) + ReflectionHelpers.callInstanceMethod(component, "write", + from(LinkProperties::class.java, link), from(NetworkCapabilities::class.java, capabilities())) + assertEquals(description, temporary.root.resolve("etc/droiddeck-net").readText()) + val state = org.json.JSONObject(temporary.root.resolve("etc/droiddeck-network.json").readText()) + assertEquals("tun0", state.getString("interface")) + assertEquals("vpn", state.getString("transport")) + assertEquals(listOf("10.0.0.1"), (0 until state.getJSONArray("gateways").length()).map { + state.getJSONArray("gateways").getString(it) + }) + assertEquals(before, link) + } +} diff --git a/tools/tests/test_netmanager.py b/tools/tests/test_netmanager.py index 5f65d97d41..1346f54d2b 100644 --- a/tools/tests/test_netmanager.py +++ b/tools/tests/test_netmanager.py @@ -97,6 +97,18 @@ class NetworkObjectsTest(unittest.TestCase): self.assertEqual(found[nm.device_path(state)][nm.NAME + ".Device"]["DeviceType"].unpack(), device_type) self.assertNotIn(nm.AP, found) + def test_vpn_compatibility_gateway_is_exposed_without_changing_address(self): + state = dict(WIFI, transport="vpn", interface="tun0", + addresses=[{"address": "10.0.0.1", "prefix": 24}], + gateways=["10.0.0.1"]) + found = nm.objects(state) + ipv4 = found[nm.IP4][nm.NAME + ".IP4Config"] + self.assertEqual(ipv4["Gateway"].unpack(), "10.0.0.1") + self.assertEqual(ipv4["AddressData"].unpack(), [{"address": "10.0.0.1", "prefix": 24}]) + self.assertEqual(found[nm.device_path(state)][nm.NAME + ".Device"]["DeviceType"].unpack(), 16) + self.assertTrue(found[nm.ACTIVE][nm.NAME + ".Connection.Active"]["Default"].unpack()) + self.assertEqual(found[nm.ROOT][nm.NAME]["Connectivity"].unpack(), 4) + def test_named_current_and_nearby_access_points(self): current = {"ssid": "Current Wi-Fi", "bssid": "00:11:22:33:44:55", "strength": 75, "capabilities": "[WPA2-PSK-CCMP][RSN-PSK+SAE-CCMP][ESS]"} From d8c1bc605916bd08cd247b2e2a98b91fb40d2ebb Mon Sep 17 00:00:00 2001 From: sanogueralorenzo Date: Fri, 23 Oct 2026 20:58:46 -0700 Subject: [PATCH 20/85] fix: extend left adaptive stick activation to the screen edge --- .../launcher/input/OnScreenControls.kt | 2 +- .../launcher/input/OnScreenControlsTest.kt | 68 ++++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt b/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt index 459d8177a0..4f038c1432 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt @@ -696,7 +696,7 @@ class OnScreenControls( if (x < safe.left || x >= width - safe.right || y < safe.top || y >= height - safe.bottom) return null if (controls.any { it.stick < 0 && isVisible(it) && it.contains(x, y, it.radius, 5f) }) return null return controls.filter { - val dx = x - it.cx + val dx = if (it.stick == 0) max(0f, x - it.cx) else x - it.cx val dy = y - it.cy val reach = it.radius * 1.4f * sqrt(1.5f) it.stick >= 0 && isVisible(it) && it.pressedBy == -1 && dx * dx + dy * dy <= reach * reach diff --git a/app/src/test/java/com/droiddeck/launcher/input/OnScreenControlsTest.kt b/app/src/test/java/com/droiddeck/launcher/input/OnScreenControlsTest.kt index b1096f3f47..f8ada2ea4b 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/OnScreenControlsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/OnScreenControlsTest.kt @@ -5,8 +5,11 @@ import kotlin.math.sqrt import android.content.Context import android.graphics.Bitmap import android.graphics.Canvas +import android.graphics.Rect +import android.view.DisplayCutout import android.view.MotionEvent import android.view.View +import android.view.WindowInsets import android.widget.FrameLayout import org.junit.Assert.* import org.junit.Before @@ -191,6 +194,7 @@ class OnScreenControlsTest { val x = value(left, "cx") val y = value(left, "cy") assertNotEquals(0, pixel(x, y)) + assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (0f to y))) assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (600f to 200f))) touch(MotionEvent.ACTION_DOWN, 1 to (x + 10f to y)) assertEquals(x, value(left, "ax"), 0f) @@ -211,7 +215,7 @@ class OnScreenControlsTest { assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (600f to 200f))) } - @Test fun adaptiveActivationIsLimitedToExpandedSavedCircle() { + @Test fun adaptiveActivationKeepsItsVerticalAndInwardLimits() { val left = control("ls") val x = value(left, "cx") val y = value(left, "cy") @@ -220,10 +224,53 @@ class OnScreenControlsTest { assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (x to y - reach + 1f))) assertEquals(y - reach + 1f, value(left, "ay"), 0.001f) touch(MotionEvent.ACTION_UP, 1 to (x to y - reach + 1f)) - assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (x - reach to y - reach))) + assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (x + reach to y - reach))) assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (600f to 200f))) } + @Test fun leftAdaptiveStickCanStartAtTheLeftEdgeAndReleaseNormally() { + val left = control("ls") + val y = value(left, "cy") + val reach = value(left, "radius") * 1.4f * sqrt(1.5f) + assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (0f to y - reach - 1f))) + assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (0f to y))) + assertEquals(1, field(left, "pressedBy")) + assertEquals(0f, value(left, "ax"), 0f) + assertEquals(0f, value(left, "kx"), 0f) + touch(MotionEvent.ACTION_MOVE, 1 to (30f to y)) + assertEquals(30f, value(left, "kx"), 0f) + touch(MotionEvent.ACTION_CANCEL, 1 to (30f to y)) + assertEquals(-1, field(left, "pressedBy")) + assertEquals(0f, value(left, "kx"), 0f) + assertEquals(-1, field(control("rs"), "pressedBy")) + } + + @Test fun rightAdaptiveStickKeepsItsSavedActivationCircle() { + val right = control("rs") + val x = value(right, "cx") + val y = value(right, "cy") + val reach = value(right, "radius") * 1.4f * sqrt(1.5f) + assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (1199f to y))) + assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (x + reach + 1f to y))) + assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (x + reach - 1f to y))) + assertEquals(1, field(right, "pressedBy")) + } + + @Test + @Config(sdk = [30]) + @Suppress("DEPRECATION") + fun leftActivationStopsAtTheSafeCutoutEdge() { + val insets = WindowInsets.Builder() + .setDisplayCutout(DisplayCutout(Rect(24, 0, 0, 0), listOf(Rect(0, 380, 24, 420)))) + .build() + view.dispatchApplyWindowInsets(insets) + val left = control("ls") + val y = value(left, "cy") + assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (23f to y))) + assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (24f to y))) + assertEquals(1, field(left, "pressedBy")) + } + @Test fun touchesOutsideActivationAreasStayWithTrackpad() { val received = mutableListOf() val trackpad = View(context).apply { @@ -311,6 +358,23 @@ class OnScreenControlsTest { } } + @Test fun leftExtensionKeepsButtonPriorityAndClearance() { + val button = control("left") + val x = value(button, "cx") + val y = value(button, "cy") + val edge = y - value(button, "radius") * 1.25f + val left = control("ls") + left.javaClass.getDeclaredField("cx").apply { isAccessible = true }.setFloat(left, x + 200f) + left.javaClass.getDeclaredField("cy").apply { isAccessible = true }.setFloat(left, y) + assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (x to y))) + assertEquals(1, field(button, "pressedBy")) + assertEquals(-1, field(left, "pressedBy")) + touch(MotionEvent.ACTION_UP, 1 to (x to y)) + assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (x to edge - 4f))) + assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (x to edge - 6f))) + assertEquals(1, field(left, "pressedBy")) + } + private fun control(id: String): Any = (field(view, "controls") as List<*>).first { field(it!!, "id") == id }!! private fun editor() { view = OnScreenControls(context, null, editing = true) From 1c24c600cd6afe9c45d225e621dcc6c1df64e1a8 Mon Sep 17 00:00:00 2001 From: sanogueralorenzo Date: Sat, 31 Oct 2026 07:25:25 -0700 Subject: [PATCH 21/85] refactor: clarify adaptive stick hit testing and test setup --- .../launcher/input/OnScreenControls.kt | 21 +++++++++++-------- .../launcher/input/OnScreenControlsTest.kt | 19 ++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt b/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt index 4f038c1432..cd252c5255 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/OnScreenControls.kt @@ -694,15 +694,18 @@ class OnScreenControls( private fun adaptiveStickAt(x: Float, y: Float): Control? { if (!settings.adaptiveSticks || editing || buttonsOnly || quickHidden) return null if (x < safe.left || x >= width - safe.right || y < safe.top || y >= height - safe.bottom) return null - if (controls.any { it.stick < 0 && isVisible(it) && it.contains(x, y, it.radius, 5f) }) return null - return controls.filter { - val dx = if (it.stick == 0) max(0f, x - it.cx) else x - it.cx - val dy = y - it.cy - val reach = it.radius * 1.4f * sqrt(1.5f) - it.stick >= 0 && isVisible(it) && it.pressedBy == -1 && dx * dx + dy * dy <= reach * reach - }.minByOrNull { - val dx = x - it.cx - val dy = y - it.cy + if (controls.any { control -> + control.stick < 0 && isVisible(control) && control.contains(x, y, control.radius, 5f) + }) return null + return controls.filter { control -> + val dx = if (control.stick == 0) max(0f, x - control.cx) else x - control.cx + val dy = y - control.cy + val reach = control.radius * 1.4f * sqrt(1.5f) + control.stick >= 0 && isVisible(control) && control.pressedBy == -1 && + dx * dx + dy * dy <= reach * reach + }.minByOrNull { control -> + val dx = x - control.cx + val dy = y - control.cy dx * dx + dy * dy } } diff --git a/app/src/test/java/com/droiddeck/launcher/input/OnScreenControlsTest.kt b/app/src/test/java/com/droiddeck/launcher/input/OnScreenControlsTest.kt index f8ada2ea4b..646df7795a 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/OnScreenControlsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/OnScreenControlsTest.kt @@ -219,7 +219,7 @@ class OnScreenControlsTest { val left = control("ls") val x = value(left, "cx") val y = value(left, "cy") - val reach = value(left, "radius") * 1.4f * sqrt(1.5f) + val reach = activationReach(left) assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (x to y - reach - 1f))) assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (x to y - reach + 1f))) assertEquals(y - reach + 1f, value(left, "ay"), 0.001f) @@ -231,7 +231,7 @@ class OnScreenControlsTest { @Test fun leftAdaptiveStickCanStartAtTheLeftEdgeAndReleaseNormally() { val left = control("ls") val y = value(left, "cy") - val reach = value(left, "radius") * 1.4f * sqrt(1.5f) + val reach = activationReach(left) assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (0f to y - reach - 1f))) assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (0f to y))) assertEquals(1, field(left, "pressedBy")) @@ -249,7 +249,7 @@ class OnScreenControlsTest { val right = control("rs") val x = value(right, "cx") val y = value(right, "cy") - val reach = value(right, "radius") * 1.4f * sqrt(1.5f) + val reach = activationReach(right) assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (1199f to y))) assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (x + reach + 1f to y))) assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (x + reach - 1f to y))) @@ -348,8 +348,7 @@ class OnScreenControlsTest { val edge = value(button, "cy") - radius * if (id == "rb") 1.05f else 1.25f val x = value(button, "cx") val left = control("ls") - left.javaClass.getDeclaredField("cx").apply { isAccessible = true }.setFloat(left, x) - left.javaClass.getDeclaredField("cy").apply { isAccessible = true }.setFloat(left, edge - 10f) + moveControl(left, x, edge - 10f) assertFalse(touch(MotionEvent.ACTION_DOWN, 1 to (x to edge - 4f))) assertEquals(-1, field(left, "pressedBy")) assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (x to edge - 6f))) @@ -364,8 +363,7 @@ class OnScreenControlsTest { val y = value(button, "cy") val edge = y - value(button, "radius") * 1.25f val left = control("ls") - left.javaClass.getDeclaredField("cx").apply { isAccessible = true }.setFloat(left, x + 200f) - left.javaClass.getDeclaredField("cy").apply { isAccessible = true }.setFloat(left, y) + moveControl(left, x + 200f, y) assertTrue(touch(MotionEvent.ACTION_DOWN, 1 to (x to y))) assertEquals(1, field(button, "pressedBy")) assertEquals(-1, field(left, "pressedBy")) @@ -448,6 +446,13 @@ class OnScreenControlsTest { private fun nullableFloat(owner: Any, name: String) = owner.javaClass.getDeclaredField(name).apply { isAccessible = true }.get(owner) as Float? private fun value(owner: Any, name: String) = field(owner, name) as Float + private fun activationReach(control: Any) = value(control, "radius") * 1.4f * sqrt(1.5f) + + private fun moveControl(control: Any, x: Float, y: Float) { + control.javaClass.getDeclaredField("cx").apply { isAccessible = true }.setFloat(control, x) + control.javaClass.getDeclaredField("cy").apply { isAccessible = true }.setFloat(control, y) + } + private fun pixel(x: Float, y: Float): Int { val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888) view.draw(Canvas(bitmap)) From 969b7e625f776d40bd06c27c10abcebb6064e57c Mon Sep 17 00:00:00 2001 From: visail Date: Tue, 27 Oct 2026 13:55:32 +0800 Subject: [PATCH 22/85] fix: list Battle.net games installed under Blizzard's China uids Blizzard's China client records some products under a CN uid, so the installs it makes never reach the Library and their Stores card keeps offering Install: Diablo II: Resurrected osic (catalogue had osi) StarCraft II s2_cn (catalogue had s2) Diablo Immortal anbs_cn (catalogue had anbs) title() now resolves those uids to the international title, so the Library, the Stores "installed" state, the cover folder and the launch code all agree, while Game.installUid keeps the uid the Agent recorded for updates and uninstalls. TITLES and STORE are untouched. --- .../droiddeck/launcher/runtime/BattleNet.kt | 7 ++++++- .../launcher/runtime/BattleNetTest.kt | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt b/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt index fa58c26ea5..a98e3d0cfa 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/BattleNet.kt @@ -61,6 +61,9 @@ object BattleNet { val STORE: List get() = TITLES.distinctBy { it.code }.filter { it.uid != "d3cn" && it.code != "WoWC" && it.code != "WoWF" } + // Blizzard's China client installs some products under a CN uid; they are the same games and keep their store identity. + private val CN_UIDS = mapOf("s2_cn" to "s2", "osic" to "osi", "anbs_cn" to "anbs") + fun notInstalled(title: Title, installedIds: Collection<String?>) = installedIds.mapNotNull { id -> id?.let(::title)?.code }.none { it == title.code } @@ -164,8 +167,10 @@ object BattleNet { internal fun title(uid: String): Title? { val id = uid.lowercase() TITLES.firstOrNull { it.uid == id }?.let { return it } + CN_UIDS[id]?.let { alias -> TITLES.firstOrNull { it.uid == alias }?.let { return it } } val base = id.substringBeforeLast('_', "") - return if (base.isNotEmpty() && id.substringAfterLast('_') in LOCALES) TITLES.firstOrNull { it.uid == base } else null + if (base.isEmpty() || id.substringAfterLast('_') !in LOCALES) return null + return TITLES.firstOrNull { it.uid == base } ?: CN_UIDS[base]?.let { alias -> TITLES.firstOrNull { it.uid == alias } } } internal fun titleForProduct(product: String): Title? { diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt index 77800dc1e4..c3d821d07c 100644 --- a/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt @@ -259,6 +259,7 @@ class BattleNetTest { BattleNet.hostFolder(context, "Z:/root/Games/Stores/Battle.net/Hearthstone/")) } + @Test fun wowForeverIsListedBesideRetailInTheSharedWorldOfWarcraftFolder() { val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() } val wow = File(pfx, "drive_c/Program Files (x86)/World of Warcraft").apply { mkdirs() } @@ -329,6 +330,24 @@ class BattleNetTest { assertEquals(listOf(File(wow, "_forever_")), BattleNet.games(context).map { it.folder }) db.writeBytes(message(forever, retail)) assertEquals(listOf(File(wow, "_forever_"), wow), BattleNet.games(context).map { it.folder }) + + @Test fun aGameInstalledUnderBlizzardsChineseUidIsStillListed() { + val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() } + File(pfx, "drive_c/ProgramData/Battle.net/Agent").mkdirs() + File(pfx, "drive_c/ProgramData/Battle.net/Agent/product.db").writeBytes(message( + field(1, message(field(1, "osic"), field(3, message(field(1, "Z:/root/Games/Stores/Battle.net/Diablo II Resurrected"))))), + field(1, message(field(1, "s2_cn"), field(3, message(field(1, "Z:/root/Games/Stores/Battle.net/StarCraft II"))))), + )) + for (folder in listOf("Diablo II Resurrected", "StarCraft II")) { + File(LinuxRuntime.rootDir(context), "root/Games/Stores/Battle.net/$folder").mkdirs() + } + val games = BattleNet.games(context) + assertEquals(listOf("osic", "s2_cn"), games.map { it.installUid }) + assertEquals(listOf("osi", "s2"), games.map { it.uid }) + assertEquals(listOf("Diablo II: Resurrected" to "OSI", "StarCraft II" to "S2"), games.map { it.name to it.code }) + assertFalse(BattleNet.notInstalled(BattleNet.title("osi")!!, listOf("osic"))) + assertFalse(BattleNet.notInstalled(BattleNet.title("s2")!!, games.map { it.installUid })) + } @Test fun aGamesShortcutHasBattleNetLaunchItInItsPrefix() { From fe1dd8ca72af4919b262cca6dd4e5680d4ae48ea Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:33:32 -0500 Subject: [PATCH 23/85] test(battlenet): close the folder scan case --- .../test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt index c3d821d07c..1af73baef4 100644 --- a/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/runtime/BattleNetTest.kt @@ -330,6 +330,7 @@ class BattleNetTest { assertEquals(listOf(File(wow, "_forever_")), BattleNet.games(context).map { it.folder }) db.writeBytes(message(forever, retail)) assertEquals(listOf(File(wow, "_forever_"), wow), BattleNet.games(context).map { it.folder }) + } @Test fun aGameInstalledUnderBlizzardsChineseUidIsStillListed() { val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() } From 0544933abdc028342f5d969b4c9a1e2849790d81 Mon Sep 17 00:00:00 2001 From: HCOOKIELYT <luyaoting114514@gmail.com> Date: Mon, 26 Oct 2026 07:38:46 -0700 Subject: [PATCH 24/85] fix(steam): show progress while applying client updates Forward extraction and installation messages from the x64 bootstrap log and replace stale download percentages with the applying-update state. Add regression coverage for phase ordering and log forwarding. Fixes #812 --- .../launcher/session/LoadingState.kt | 8 ++ app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../session/LoadingStateUpdateTest.kt | 108 ++++++++++++++++++ .../overlay/usr/local/bin/droiddeck-steam-x64 | 2 +- tools/tests/test_steam_update_progress.py | 57 +++++++++ 6 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/session/LoadingStateUpdateTest.kt create mode 100644 tools/tests/test_steam_update_progress.py diff --git a/app/src/main/java/com/droiddeck/launcher/session/LoadingState.kt b/app/src/main/java/com/droiddeck/launcher/session/LoadingState.kt index f69983f0db..7487b98798 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/LoadingState.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/LoadingState.kt @@ -77,6 +77,7 @@ class LoadingState(context: Context, private val steam: Boolean = true) { var stepText: String? = null var downloadAt = -1 var downloadPercent = -1 + var applyingAt = -1 var clientDownloadAt = -1 var clientDownload: String? = null var clientPercent = -1 @@ -99,10 +100,16 @@ class LoadingState(context: Context, private val steam: Boolean = true) { val done = m.groupValues[1].toLong() val total = maxOf(1L, m.groupValues[2].toLong()) downloadPercent = (done * 100 / total).toInt() + } else if (steam && UPDATE_APPLYING.matches(line)) { + applyingAt = at } } } return when { + applyingAt > stepAt && applyingAt > downloadAt -> Line( + context.getString(com.droiddeck.launcher.R.string.loadstate_steam_update_applying), -1, + Topic.STEAM, readable = true, + ) downloadAt > stepAt && downloadPercent >= 0 -> Line( context.getString(com.droiddeck.launcher.R.string.loadstate_steam_update, downloadPercent), downloadPercent, Topic.STEAM, readable = true, @@ -151,6 +158,7 @@ class LoadingState(context: Context, private val steam: Boolean = true) { private const val TAIL_BYTES = 48L * 1024 private val UPDATE_PROGRESS = Regex("""Downloading update \((\d+) of (\d+) KB\)""") + private val UPDATE_APPLYING = Regex("""^\s*(?:\[[^\]]+\]\s*)*(?:Extracting package|Installing update)\.\.\.\s*$""") private val INSTALL_COUNT = Regex("""downloading Steam: (\S+) \((\d+)/(\d+)\)""") private val INSTALL_MEGABYTES = Regex("""^, (\d+) of (\d+) MB""") } diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 1919b524c6..67353fa837 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -2088,6 +2088,7 @@ <string name="loadstate_starting">正在启动会话…</string> <string name="loadstate_elapsed">已用时 %1$d:%2$02d · 仍在处理</string> <string name="loadstate_steam_update">正在下载 Steam 客户端更新 · %1$d%%</string> + <string name="loadstate_steam_update_applying">正在应用 Steam 客户端更新…</string> <string name="loadstate_steam_client">正在下载 Steam 客户端 · %1$s</string> <string name="pextra_busy">已有兼容性工具正在安装</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 96766a5bc8..417dd49465 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2224,6 +2224,7 @@ <string name="loadstate_starting">Starting the session…</string> <string name="loadstate_elapsed">%1$d:%2$02d elapsed · still working</string> <string name="loadstate_steam_update">Downloading the Steam client update · %1$d%%</string> + <string name="loadstate_steam_update_applying">Applying the Steam client update…</string> <string name="loadstate_steam_client">Downloading the Steam client · %1$s</string> <string name="pextra_busy">A compatibility tool install is already running</string> diff --git a/app/src/test/java/com/droiddeck/launcher/session/LoadingStateUpdateTest.kt b/app/src/test/java/com/droiddeck/launcher/session/LoadingStateUpdateTest.kt new file mode 100644 index 0000000000..0ef4ebaeeb --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/LoadingStateUpdateTest.kt @@ -0,0 +1,108 @@ +package com.droiddeck.launcher.session + +import android.app.Application +import java.io.File +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], application = Application::class, qualifiers = "en") +class LoadingStateUpdateTest { + @get:Rule val temp = TemporaryFolder() + + @Test fun extractingReplacesAnIncompleteDownload() { + assertApplying(read("Downloading update (50 of 100 KB)", "Extracting package...")) + } + + @Test fun installingClearsTheCompletedDownloadPercentage() { + assertApplying(read("Downloading update (100 of 100 KB)", "Installing update...")) + } + + @Test fun acceptsForwardedMessagesAndBootstrapPrefixes() { + for (message in listOf( + "Installing update...", + "[2026-10-25 12:00:02] Extracting package...", + "[----] Installing update...\r", + "[2026-10-25 12:00:02] [----] Extracting package...", + )) assertApplying(read(message)) + } + + @Test fun aNewDownloadReplacesAnOlderApplyingStage() { + val state = read("Installing update...", "Downloading update (25 of 100 KB)") + assertEquals(25, state.percent) + assertEquals("Downloading the Steam client update · 25%", state.step) + } + + @Test fun aNewScriptStepReplacesAnOlderApplyingStage() { + val state = read("Installing update...", "== STEP 12:00:03 checking the Linux runtime") + assertEquals("checking the Linux runtime", state.step) + assertEquals(LoadingState.Topic.RUNTIME, state.topic) + assertEquals(-1, state.percent) + } + + @Test fun unrelatedOutputKeepsTheApplyingStage() { + assertApplying(read("Installing update...", "Loading cached metrics", "")) + } + + @Test fun similarlyNamedMessagesDoNotReplaceTheDownload() { + val state = read( + "Downloading update (50 of 100 KB)", + "worker: Installing update...", + "Installing update for Proton...", + "[12:00:02] error: Extracting package...", + ) + assertEquals(50, state.percent) + assertEquals("Downloading the Steam client update · 50%", state.step) + } + + @Test fun anOlderRuntimeCanReturnToItsPartCountAfterApplying() { + val state = read("Installing update...", "== STEP 12:00:03 downloading Steam: a_all (1/2)") + assertEquals(50, state.percent) + assertEquals("Downloading the Steam client · a_all", state.step) + } + + @Test fun desktopStartupDoesNotConsumeSteamApplyingMessages() { + val state = read( + "== STEP 12:00:01 starting the desktop", "Installing update...", steam = false, + ) + assertEquals("starting the desktop", state.step) + assertEquals(LoadingState.Topic.DESKTOP, state.topic) + } + + @Test fun anExistingLoadingStateFollowsUpdatesAcrossPolls() { + val context = RuntimeEnvironment.getApplication() + val log = log("Downloading update (100 of 100 KB)") + val state = LoadingState(context) + state.update(context, log) + assertEquals(100, state.percent) + log.appendText("\n[12:00:02] Installing update...") + state.update(context, log) + assertApplying(state) + log.appendText("\nDownloading update (20 of 100 KB)") + state.update(context, log) + assertEquals(20, state.percent) + } + + private fun read(vararg lines: String, steam: Boolean = true): LoadingState { + val context = RuntimeEnvironment.getApplication() + return LoadingState(context, steam).apply { update(context, log(*lines)) } + } + + private fun log(vararg lines: String): File = temp.newFile().apply { + writeText((listOf("== STEP 12:00:00 starting the Steam client") + lines).joinToString("\n")) + } + + private fun assertApplying(state: LoadingState) { + assertEquals(-1, state.percent) + assertEquals("Applying the Steam client update…", state.step) + assertEquals(LoadingState.Topic.STEAM, state.topic) + assertTrue(state.readable) + } +} diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 index 42c68c73dd..481d25d194 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 @@ -819,7 +819,7 @@ x64_exec() { mkdir -p "$STEAM_X64/logs" touch "$STEAM_X64/logs/bootstrap_log.txt" ( tail -n0 -F --pid=$$ "$STEAM_X64/logs/bootstrap_log.txt" 2>/dev/null | - grep --line-buffered -oE 'Downloading update \([0-9,]+ of [0-9,]+ KB\)' | sed -u 's/,//g' >&2 ) & + grep --line-buffered -oE 'Downloading update \([0-9,]+ of [0-9,]+ KB\)|^[[:space:]]*(\[[^]]+\][[:space:]]*)*(Extracting package|Installing update)\.\.\.[[:space:]]*$' | sed -u 's/,//g' >&2 ) & echo "== x86-64 client: steamrt64 $(x64_manifest_version steamrt64) (the client may update itself)" >&2 x64_webhelper_gpu && { x64_gpu_watch >&2 & } exec "${BL_FEX:-/usr/local/bin/FEX}" "$STEAM_X64/steamrt64/steam" "$@" diff --git a/tools/tests/test_steam_update_progress.py b/tools/tests/test_steam_update_progress.py new file mode 100644 index 0000000000..af55be3976 --- /dev/null +++ b/tools/tests/test_steam_update_progress.py @@ -0,0 +1,57 @@ +from pathlib import Path +import re +import shutil +import subprocess +import unittest + + +SCRIPT = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steam-x64' + + +class SteamUpdateProgressTest(unittest.TestCase): + def forward(self, lines): + matches = re.findall( + r'(?m)^\s*(grep --line-buffered .*\| sed -u .* >&2) \) &$', + SCRIPT.read_text(encoding='utf-8'), + ) + self.assertEqual(1, len(matches), 'Find the production bootstrap forwarding pipeline') + result = subprocess.run( + [shutil.which('bash') or 'bash', '-c', matches[0]], + input='\n'.join(lines) + '\n', text=True, capture_output=True, check=True, timeout=10, + ) + self.assertEqual('', result.stdout) + return result.stderr.splitlines() + + def test_downloads_keep_their_normalized_progress(self): + self.assertEqual(['Downloading update (1250 of 5000 KB)'], self.forward([ + '[2026-10-25 12:00:01] Downloading update (1,250 of 5,000 KB)...', + ])) + + def test_forwards_extracting_and_installing_from_bootstrap_logs(self): + lines = [ + '[2026-10-25 12:00:02] Extracting package...', + '[2026-10-25 12:00:03] Installing update...', + ] + self.assertEqual(lines, self.forward(lines)) + + def test_accepts_plain_and_console_prefixed_messages(self): + lines = [ + 'Extracting package...', '[----] Installing update...', + '[2026-10-25 12:00:02] [----] Extracting package...', + ] + self.assertEqual(lines, self.forward(lines)) + + def test_ignores_unrelated_and_similarly_named_messages(self): + self.assertEqual([], self.forward([ + 'Loading cached metrics', 'worker: Installing update...', + 'Installing update for Proton...', '[12:00:02] error: Extracting package...', + ])) + + def test_preserves_stage_order_when_a_download_restarts(self): + self.assertEqual([ + 'Downloading update (100 of 100 KB)', 'Installing update...', + 'Downloading update (20 of 100 KB)', + ], self.forward([ + 'Downloading update (100 of 100 KB)', 'Installing update...', + 'Downloading update (20 of 100 KB)', + ])) From 5e0f5cb9cd18fa5932d4c32154116781eeffb7e3 Mon Sep 17 00:00:00 2001 From: Boran Miao <84240213+realRurichan@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:20:27 +0800 Subject: [PATCH 25/85] fix: install bundled PPSSPP through the Flatpak helper --- .../overlay/usr/local/bin/droiddeck-emulators | 2 +- tools/tests/test_emulators_install.py | 87 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tools/tests/test_emulators_install.py diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-emulators b/tools/linuxfs/overlay/usr/local/bin/droiddeck-emulators index a937b4e8eb..ec9e8b69d9 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-emulators +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-emulators @@ -11,7 +11,7 @@ install) droiddeck-root /usr/bin/apt-get install -y -q retroarch retroarch-assets $cores || { echo "== FAIL apt-get install"; exit 1; } echo "== STEP PPSSPP" flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo || { echo "== FAIL flathub"; exit 1; } - flatpak install --user -y --noninteractive flathub org.ppsspp.PPSSPP || { echo "== FAIL org.ppsspp.PPSSPP"; exit 1; } + /usr/bin/python3 /usr/local/bin/droiddeck-flatpak install org.ppsspp.PPSSPP || { echo "== FAIL org.ppsspp.PPSSPP"; exit 1; } printf '#!/bin/sh\nexec /usr/local/bin/droiddeck-flatpak-run org.ppsspp.PPSSPP "$@"\n' > /usr/local/bin/PPSSPPSDL.new && chmod 755 /usr/local/bin/PPSSPPSDL.new && mv -f /usr/local/bin/PPSSPPSDL.new /usr/local/bin/PPSSPPSDL || { echo "== FAIL PPSSPPSDL"; exit 1; } ;; diff --git a/tools/tests/test_emulators_install.py b/tools/tests/test_emulators_install.py new file mode 100644 index 0000000000..03d135bda0 --- /dev/null +++ b/tools/tests/test_emulators_install.py @@ -0,0 +1,87 @@ +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + + +SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-emulators" + + +class EmulatorsInstallTest(unittest.TestCase): + def run_install(self, failure=""): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + bin_dir = root / "bin" + bin_dir.mkdir() + calls = root / "calls" + launcher = root / "PPSSPPSDL" + helper = root / "droiddeck-flatpak" + helper.write_text( + "import os, sys\n" + "with open(os.environ['CALLS'], 'a') as f:\n" + " f.write('helper ' + ' '.join(sys.argv[1:]) + '\\n')\n" + "sys.exit(1 if os.environ['FAILURE'] == 'helper' else 0)\n" + ) + stubs = { + "droiddeck-root": + 'echo "apt $*" >> "$CALLS"\n' + '[ "$FAILURE" != "apt-$2" ]', + "flatpak": + 'echo "flatpak $*" >> "$CALLS"\n' + 'if [ "$1" = install ]; then\n' + ' echo "Could not connect: No such file or directory" >&2\n' + ' exit 1\n' + 'fi\n' + '[ "$FAILURE" != remote ]', + } + for name, body in stubs.items(): + path = bin_dir / name + path.write_text("#!/bin/sh\n" + body + "\n") + path.chmod(0o755) + script = root / "install" + script.write_text(SCRIPT.read_text() + .replace("/usr/local/bin/droiddeck-flatpak install", str(helper) + " install") + .replace("/usr/local/bin/PPSSPPSDL", str(launcher))) + env = dict(os.environ, PATH=str(bin_dir) + os.pathsep + os.environ["PATH"], + CALLS=str(calls), FAILURE=failure) + result = subprocess.run(["bash", str(script), "install"], env=env, + capture_output=True, text=True, timeout=30) + return result, calls.read_text(), launcher.read_text() if launcher.exists() else None, \ + os.access(launcher, os.X_OK) + + def test_install_without_a_system_bus_uses_the_helper_and_creates_the_launcher(self): + result, calls, launcher, executable = self.run_install() + self.assertEqual(0, result.returncode, result.stdout + result.stderr) + self.assertIn("helper install org.ppsspp.PPSSPP\n", calls) + self.assertNotIn("flatpak install ", calls) + self.assertIn('exec /usr/local/bin/droiddeck-flatpak-run org.ppsspp.PPSSPP "$@"', launcher) + self.assertTrue(executable) + + def test_helper_failure_does_not_publish_a_launcher(self): + result, calls, launcher, _ = self.run_install("helper") + self.assertNotEqual(0, result.returncode) + self.assertIn("helper install org.ppsspp.PPSSPP\n", calls) + self.assertIn("== FAIL org.ppsspp.PPSSPP", result.stdout) + self.assertIsNone(launcher) + + def test_apt_failure_stops_before_flatpak(self): + for stage in ("update", "install"): + with self.subTest(stage=stage): + result, calls, launcher, _ = self.run_install("apt-" + stage) + self.assertNotEqual(0, result.returncode) + self.assertIn("== FAIL apt-get " + stage, result.stdout) + self.assertNotIn("flatpak ", calls) + self.assertNotIn("helper ", calls) + self.assertIsNone(launcher) + + def test_remote_failure_stops_before_the_helper(self): + result, calls, launcher, _ = self.run_install("remote") + self.assertNotEqual(0, result.returncode) + self.assertIn("== FAIL flathub", result.stdout) + self.assertNotIn("helper ", calls) + self.assertIsNone(launcher) + + +if __name__ == "__main__": + unittest.main() From 17fb80ad51fa1bd60d4c8e9b348839503ee07c35 Mon Sep 17 00:00:00 2001 From: Boran Miao <84240213+realRurichan@users.noreply.github.com> Date: Thu, 5 Nov 2026 17:13:12 +0800 Subject: [PATCH 26/85] test: quote emulator installer paths with spaces --- tools/tests/test_emulators_install.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/tests/test_emulators_install.py b/tools/tests/test_emulators_install.py index 03d135bda0..81dbf10384 100644 --- a/tools/tests/test_emulators_install.py +++ b/tools/tests/test_emulators_install.py @@ -1,5 +1,6 @@ import os from pathlib import Path +import shlex import subprocess import tempfile import unittest @@ -10,7 +11,7 @@ SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/dr class EmulatorsInstallTest(unittest.TestCase): def run_install(self, failure=""): - with tempfile.TemporaryDirectory() as directory: + with tempfile.TemporaryDirectory(prefix="emulator install 'quoted' ") as directory: root = Path(directory) bin_dir = root / "bin" bin_dir.mkdir() @@ -41,8 +42,8 @@ class EmulatorsInstallTest(unittest.TestCase): path.chmod(0o755) script = root / "install" script.write_text(SCRIPT.read_text() - .replace("/usr/local/bin/droiddeck-flatpak install", str(helper) + " install") - .replace("/usr/local/bin/PPSSPPSDL", str(launcher))) + .replace("/usr/local/bin/droiddeck-flatpak install", shlex.quote(str(helper)) + " install") + .replace("/usr/local/bin/PPSSPPSDL", shlex.quote(str(launcher)))) env = dict(os.environ, PATH=str(bin_dir) + os.pathsep + os.environ["PATH"], CALLS=str(calls), FAILURE=failure) result = subprocess.run(["bash", str(script), "install"], env=env, From bae4ecd86731e5a01f93b74af7d5a36787bc0a4e Mon Sep 17 00:00:00 2001 From: Anton <w1novnik@mail.ru> Date: Thu, 29 Oct 2026 13:12:51 +0300 Subject: [PATCH 27/85] fix: leave run-mode apps unpinned when all cores are selected --- .../overlay/usr/local/bin/droiddeck-session | 1 + tools/tests/test_session_cpu.py | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tools/tests/test_session_cpu.py diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 0c037af472..9f7747c6a5 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -298,6 +298,7 @@ program_cores() { [ "${BL_PIN_CORES:-1}" = 0 ] && return 0 command -v taskset >/dev/null 2>&1 || return 0 if [ -n "${BL_GAME_CPUS:-}" ]; then echo "$BL_GAME_CPUS"; return 0; fi + [ "$mode" = run ] && return 0 local f n max min= list= for f in /sys/devices/system/cpu/cpu[0-9]*/cpufreq/cpuinfo_max_freq; do max=$(cat "$f" 2>/dev/null) || continue diff --git a/tools/tests/test_session_cpu.py b/tools/tests/test_session_cpu.py new file mode 100644 index 0000000000..a5d741d16e --- /dev/null +++ b/tools/tests/test_session_cpu.py @@ -0,0 +1,51 @@ +import os +from pathlib import Path +import re +import subprocess +import unittest + + +SESSION = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-session' + + +class SessionCpuTest(unittest.TestCase): + def cores(self, mode, cpus='', pin='1'): + function = re.search(r'^program_cores\(\) \{\n.*?^\}\n', SESSION.read_text(), re.M | re.S).group(0) + script = ''' +set -u +taskset() { echo 'unexpected taskset invocation' >&2; return 1; } +cat() { + case "$1" in + */cpu[0-5]/cpufreq/*) echo 3630000 ;; + */cpu[67]/cpufreq/*) echo 4610000 ;; + *) return 1 ;; + esac +} +''' + paths = ' '.join(f'/sys/devices/system/cpu/cpu{i}/cpufreq/cpuinfo_max_freq' for i in range(8)) + function = function.replace('/sys/devices/system/cpu/cpu[0-9]*/cpufreq/cpuinfo_max_freq', paths) + env = dict(os.environ, mode=mode, BL_GAME_CPUS=cpus, BL_PIN_CORES=pin) + result = subprocess.run(['bash', '-c', script + function + '\nprogram_cores\n'], + env=env, capture_output=True, text=True, timeout=10) + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual('', result.stderr) + return result.stdout.strip() + + def test_run_with_all_cores_leaves_scheduling_unrestricted(self): + self.assertEqual('', self.cores('run')) + + def test_run_preserves_an_explicit_core_selection(self): + self.assertEqual('1,2,3,4,5,6,7', self.cores('run', '1,2,3,4,5,6,7')) + + def test_disabled_pinning_takes_precedence_over_explicit_cores(self): + self.assertEqual('', self.cores('run', '6,7', pin='0')) + + def test_desktop_keeps_its_fast_core_default(self): + self.assertEqual('6,7', self.cores('lxqt')) + + def test_desktop_preserves_an_explicit_core_selection(self): + self.assertEqual('0,1,2', self.cores('lxqt', '0,1,2')) + + +if __name__ == '__main__': + unittest.main() From 57b3623a9a694a38685d5db2f41b0d4eb350897f Mon Sep 17 00:00:00 2001 From: Omar Al Taki <omar.altaki@lau.edu> Date: Sat, 31 Oct 2026 02:21:49 +0400 Subject: [PATCH 28/85] fix(input): mouse right click no longer acts as Back in REDMAGIC cast mode REDMAGIC's cast mode replaces a mouse's right button with a Back key that names no device and lacks the virtual-hard-key flag that the navigation bar and back gesture set. During a session, a Back from a mouse, or that injected form while a mouse is connected, now presses the guest's right button. The navigation bar, back gesture and controller Back still act as Back, and so does a right click while a DroidDeck menu is open. A mouse's Back and Forward buttons no longer also send a left click; Android delivers them as key events. --- .../com/droiddeck/launcher/SessionActivity.kt | 43 ++++--- .../launcher/input/MouseBackInput.kt | 39 +++++++ .../launcher/input/MouseBackInputTest.kt | 107 ++++++++++++++++++ 3 files changed, 172 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 1b4b59df1e..82e692f5f1 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -330,6 +330,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { onCancel = { padBridge?.cancelBackQam() }, holds = { backHold }, ) + private val mouseBackInput = com.droiddeck.launcher.input.MouseBackInput( + sendRight = { down -> sendSceneButton(PointerGestures.BTN_RIGHT, down) }, + mouseAttached = ::mouseAttached, + ) private var drawerDirectionKey = KeyEvent.KEYCODE_UNKNOWN private var drawerDirectionDownTime = 0L private var drawerDirectionDeviceId = -1 @@ -2575,6 +2579,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { return super.dispatchKeyEvent(event) } } + if (event.keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) { + Log.i(TAG, String.format(java.util.Locale.ROOT, "back key device=%d (%s) source=0x%x flags=0x%x", + event.deviceId, event.device?.name, event.source, event.flags)) + } + val mouseToGuest = !pipUi && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && + !(::loading.isInitialized && loading.ended) + if (mouseBackInput.onKeyEvent(event, mouseToGuest)) return true val backToQam = !pipUi && !screenKeyTextFocus && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && SessionState.mode == SessionService.MODE_STEAM && SessionState.running && SessionState.firstFrameSeen && !SessionState.suspended && padBridge?.canHoldQam() == true @@ -3797,14 +3808,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (evdevMouseActive) sendMouseDelta(event.x, event.y) else movePointer(event.x, event.y, fromMouse = true) MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE -> { if (evdevMouseActive) sendMouseDelta(event.x, event.y) else movePointer(event.x, event.y, fromMouse = true) - val button = when (event.actionButton) { - MotionEvent.BUTTON_SECONDARY -> PointerGestures.BTN_RIGHT - MotionEvent.BUTTON_TERTIARY -> PointerGestures.BTN_MIDDLE - MotionEvent.BUTTON_BACK -> BTN_SIDE - MotionEvent.BUTTON_FORWARD -> BTN_EXTRA - else -> PointerGestures.BTN_LEFT - } - sendSceneButton(button, event.actionMasked == MotionEvent.ACTION_BUTTON_PRESS) + guestMouseButton(event.actionButton)?.let { sendSceneButton(it, event.actionMasked == MotionEvent.ACTION_BUTTON_PRESS) } } MotionEvent.ACTION_SCROLL -> { val v = event.getAxisValue(MotionEvent.AXIS_VSCROLL) @@ -3819,7 +3823,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private fun isHardwareMouse(d: InputDevice?): Boolean = d != null && !d.isVirtual && (d.supportsSource(InputDevice.SOURCE_MOUSE) || d.supportsSource(InputDevice.SOURCE_MOUSE_RELATIVE)) - private fun mouseAttached(): Boolean = InputDevice.getDeviceIds().any { isHardwareMouse(InputDevice.getDevice(it)) } + /** Android also sends the Back and Forward buttons as key events, so they are handled as keys. */ + private fun guestMouseButton(actionButton: Int): Int? = when (actionButton) { + MotionEvent.BUTTON_SECONDARY -> PointerGestures.BTN_RIGHT + MotionEvent.BUTTON_TERTIARY -> PointerGestures.BTN_MIDDLE + MotionEvent.BUTTON_BACK, MotionEvent.BUTTON_FORWARD -> null + else -> PointerGestures.BTN_LEFT + } + + private fun mouseAttached(): Boolean = InputDevice.getDeviceIds().any { id -> + val d = InputDevice.getDevice(id) + isHardwareMouse(d) && d?.supportsSource(InputDevice.SOURCE_TOUCHPAD) != true + } private fun relativeMouseAttached(): Boolean = !isInMultiWindowMode && !glassesOutputActive && InputDevice.getDeviceIds().any { id -> val d = InputDevice.getDevice(id) @@ -3917,14 +3932,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { moveCapturedMouse(dx, dy) } } - MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE -> { - val button = when (event.actionButton) { - MotionEvent.BUTTON_SECONDARY -> PointerGestures.BTN_RIGHT - MotionEvent.BUTTON_TERTIARY -> PointerGestures.BTN_MIDDLE - else -> PointerGestures.BTN_LEFT - } - sendSceneButton(button, event.actionMasked == MotionEvent.ACTION_BUTTON_PRESS) - } + MotionEvent.ACTION_BUTTON_PRESS, MotionEvent.ACTION_BUTTON_RELEASE -> + guestMouseButton(event.actionButton)?.let { sendSceneButton(it, event.actionMasked == MotionEvent.ACTION_BUTTON_PRESS) } MotionEvent.ACTION_SCROLL -> { val v = event.getAxisValue(MotionEvent.AXIS_VSCROLL) if (v != 0f) sendSceneWheel(-Math.round(v)) diff --git a/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt b/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt new file mode 100644 index 0000000000..4e2450f1c8 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt @@ -0,0 +1,39 @@ +package com.droiddeck.launcher.input + +import android.view.InputDevice +import android.view.KeyCharacterMap +import android.view.KeyEvent + +/** + * Some firmware turns a mouse's right button into Back. Most report it from the mouse itself; REDMAGIC's + * cast mode injects it from no device and without the virtual-hard-key flag that the navigation bar and + * back gesture set, so that form only counts while a mouse is connected. + */ +class MouseBackInput(private val sendRight: (Boolean) -> Unit, private val mouseAttached: () -> Boolean) { + private val held = mutableSetOf<Int>() + + fun onKeyEvent(event: KeyEvent, toGuest: Boolean): Boolean { + if (event.keyCode != KeyEvent.KEYCODE_BACK) return false + val device = event.deviceId + if (device in held) { + if (event.action == KeyEvent.ACTION_UP) { + held.remove(device) + sendRight(false) + } + return true + } + if (event.action != KeyEvent.ACTION_DOWN || event.repeatCount > 0 || !toGuest) return false + if (!isFromMouse(event) && !(isInjectedBack(event) && mouseAttached())) return false + held.add(device) + sendRight(true) + return true + } + + companion object { + fun isFromMouse(event: KeyEvent): Boolean = + event.isFromSource(InputDevice.SOURCE_MOUSE) || event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE) + + fun isInjectedBack(event: KeyEvent): Boolean = + event.deviceId == KeyCharacterMap.VIRTUAL_KEYBOARD && (event.flags and KeyEvent.FLAG_VIRTUAL_HARD_KEY) == 0 + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt b/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt new file mode 100644 index 0000000000..a955b9db57 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt @@ -0,0 +1,107 @@ +package com.droiddeck.launcher.input + +import android.view.InputDevice +import android.view.KeyCharacterMap +import android.view.KeyEvent +import org.junit.Assert.* +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34], manifest = Config.NONE) +class MouseBackInputTest { + private val presses = mutableListOf<Boolean>() + private var mouse = true + private val input = MouseBackInput(presses::add) { mouse } + + private fun key(action: Int, source: Int = InputDevice.SOURCE_MOUSE, device: Int = 7, repeat: Int = 0, + code: Int = KeyEvent.KEYCODE_BACK, flags: Int = 0) = + KeyEvent(0L, 0L, action, code, repeat, 0, device, 0, flags, source) + + /** What REDMAGIC's cast mode sends for a right click, as logged on an NX789J. */ + private fun injected(action: Int, repeat: Int = 0) = key(action, source = InputDevice.SOURCE_KEYBOARD, + device = KeyCharacterMap.VIRTUAL_KEYBOARD, repeat = repeat, flags = KeyEvent.FLAG_FROM_SYSTEM) + + /** What the navigation bar and back gesture send, as logged on the same phone. */ + private fun navigationBar(action: Int) = key(action, source = InputDevice.SOURCE_KEYBOARD, + device = KeyCharacterMap.VIRTUAL_KEYBOARD, flags = KeyEvent.FLAG_FROM_SYSTEM or KeyEvent.FLAG_VIRTUAL_HARD_KEY) + + @Test fun mouseBackBecomesTheRightButton() { + assertTrue(input.onKeyEvent(key(KeyEvent.ACTION_DOWN), toGuest = true)) + assertTrue(input.onKeyEvent(key(KeyEvent.ACTION_UP), toGuest = true)) + assertEquals(listOf(true, false), presses) + } + + @Test fun holdingTheButtonSwallowsRepeatsWithoutPressingAgain() { + input.onKeyEvent(key(KeyEvent.ACTION_DOWN), toGuest = true) + repeat(3) { assertTrue(input.onKeyEvent(key(KeyEvent.ACTION_DOWN, repeat = it + 1), toGuest = true)) } + input.onKeyEvent(key(KeyEvent.ACTION_UP), toGuest = true) + assertEquals(listOf(true, false), presses) + } + + @Test fun relativeMouseBackAlsoBecomesTheRightButton() { + assertTrue(input.onKeyEvent(key(KeyEvent.ACTION_DOWN, source = InputDevice.SOURCE_MOUSE_RELATIVE), toGuest = true)) + assertEquals(listOf(true), presses) + } + + @Test fun injectedBackBecomesTheRightButtonWhileAMouseIsConnected() { + assertTrue(input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true)) + assertTrue(input.onKeyEvent(injected(KeyEvent.ACTION_DOWN, repeat = 1), toGuest = true)) + assertTrue(input.onKeyEvent(injected(KeyEvent.ACTION_UP), toGuest = true)) + assertEquals(listOf(true, false), presses) + } + + @Test fun injectedBackStaysBackWithoutAMouse() { + mouse = false + assertFalse(input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true)) + assertFalse(input.onKeyEvent(injected(KeyEvent.ACTION_UP), toGuest = true)) + assertTrue(presses.isEmpty()) + } + + @Test fun navigationBarBackStaysBackEvenWithAMouse() { + for (action in listOf(KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP)) { + assertFalse(input.onKeyEvent(navigationBar(action), toGuest = true)) + } + assertTrue(presses.isEmpty()) + } + + @Test fun controllerBackStaysBack() { + val source = InputDevice.SOURCE_GAMEPAD or InputDevice.SOURCE_KEYBOARD + assertFalse(input.onKeyEvent(key(KeyEvent.ACTION_DOWN, source = source), toGuest = true)) + assertFalse(input.onKeyEvent(key(KeyEvent.ACTION_UP, source = source), toGuest = true)) + assertTrue(presses.isEmpty()) + } + + @Test fun otherMouseKeysAreLeftAlone() { + assertFalse(input.onKeyEvent(key(KeyEvent.ACTION_DOWN, code = KeyEvent.KEYCODE_FORWARD), toGuest = true)) + assertTrue(presses.isEmpty()) + } + + @Test fun mouseBackStaysBackWhileAMenuIsOpen() { + assertFalse(input.onKeyEvent(key(KeyEvent.ACTION_DOWN), toGuest = false)) + assertFalse(input.onKeyEvent(key(KeyEvent.ACTION_DOWN, repeat = 1), toGuest = false)) + assertFalse(input.onKeyEvent(key(KeyEvent.ACTION_UP), toGuest = false)) + assertTrue(presses.isEmpty()) + } + + @Test fun aMenuOpeningMidPressStillReleasesTheButton() { + input.onKeyEvent(key(KeyEvent.ACTION_DOWN), toGuest = true) + assertTrue(input.onKeyEvent(key(KeyEvent.ACTION_UP), toGuest = false)) + assertEquals(listOf(true, false), presses) + } + + @Test fun theMouseDisconnectingMidPressStillReleasesTheButton() { + input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true) + mouse = false + assertTrue(input.onKeyEvent(injected(KeyEvent.ACTION_UP), toGuest = true)) + assertEquals(listOf(true, false), presses) + } + + @Test fun aMenuClosingMidPressLeavesTheReleaseToTheMenu() { + input.onKeyEvent(key(KeyEvent.ACTION_DOWN), toGuest = false) + assertFalse(input.onKeyEvent(key(KeyEvent.ACTION_UP), toGuest = true)) + assertTrue(presses.isEmpty()) + } +} From abb28792e85829a59c1ed81ae76e088921948047 Mon Sep 17 00:00:00 2001 From: Omar Al Taki <omar.altaki@lau.edu> Date: Sat, 31 Oct 2026 02:42:15 +0400 Subject: [PATCH 29/85] fix(input): release a mouse Back right click on focus loss and pass nav Back through Address review: a navigation-bar Back that arrives while an injected mouse Back is held now stays Back instead of releasing the right button early. A held right button is released on pause, focus loss and input-device removal, like the other held Back handling. While the session is suspended or still loading, Back is no longer sent to the guest. --- .../com/droiddeck/launcher/SessionActivity.kt | 5 ++++- .../droiddeck/launcher/input/MouseBackInput.kt | 12 ++++++++++-- .../launcher/input/MouseBackInputTest.kt | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 82e692f5f1..dfc0480424 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -588,6 +588,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { Log.i(TAG, "input device $deviceId disconnected") dropMouseCursor() backQamInput.onDeviceRemoved(deviceId) + mouseBackInput.cancel() joyConVr?.refresh() padBridge?.onDeviceRemoved(deviceId) if (::padMouse.isInitialized) padMouse.reset() @@ -2584,7 +2585,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { event.deviceId, event.device?.name, event.source, event.flags)) } val mouseToGuest = !pipUi && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && - !(::loading.isInitialized && loading.ended) + !SessionState.suspended && !(::loading.isInitialized && (loading.visible || loading.ended)) if (mouseBackInput.onKeyEvent(event, mouseToGuest)) return true val backToQam = !pipUi && !screenKeyTextFocus && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && SessionState.mode == SessionService.MODE_STEAM && SessionState.running && SessionState.firstFrameSeen && @@ -4372,6 +4373,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (runtimeRemovalBlocked) { super.onPause(); return } physicalShortcuts.clear() backQamInput.cancel() + mouseBackInput.cancel() capturePausedFrame() sessionClipboard.stop() if (::touchscreenGestures.isInitialized) touchscreenGestures.cancel() @@ -4933,6 +4935,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { super.onWindowFocusChanged(hasFocus) if (!hasFocus) com.droiddeck.launcher.input.HomeButtonShortcuts.cancel(this) if (!hasFocus) backQamInput.cancel() + if (!hasFocus) mouseBackInput.cancel() if (!hasFocus && ::padMouse.isInitialized) padMouse.reset() if (runtimeRemovalBlocked) return if (!hasFocus) { diff --git a/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt b/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt index 4e2450f1c8..959196590a 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt @@ -15,7 +15,9 @@ class MouseBackInput(private val sendRight: (Boolean) -> Unit, private val mouse fun onKeyEvent(event: KeyEvent, toGuest: Boolean): Boolean { if (event.keyCode != KeyEvent.KEYCODE_BACK) return false val device = event.deviceId - if (device in held) { + val fromMouse = isFromMouse(event) + val injected = isInjectedBack(event) + if (device in held && (fromMouse || injected)) { if (event.action == KeyEvent.ACTION_UP) { held.remove(device) sendRight(false) @@ -23,12 +25,18 @@ class MouseBackInput(private val sendRight: (Boolean) -> Unit, private val mouse return true } if (event.action != KeyEvent.ACTION_DOWN || event.repeatCount > 0 || !toGuest) return false - if (!isFromMouse(event) && !(isInjectedBack(event) && mouseAttached())) return false + if (!fromMouse && !(injected && mouseAttached())) return false held.add(device) sendRight(true) return true } + fun cancel() { + if (held.isEmpty()) return + held.clear() + sendRight(false) + } + companion object { fun isFromMouse(event: KeyEvent): Boolean = event.isFromSource(InputDevice.SOURCE_MOUSE) || event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE) diff --git a/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt b/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt index a955b9db57..014bf5cc14 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt @@ -67,6 +67,24 @@ class MouseBackInputTest { assertTrue(presses.isEmpty()) } + @Test fun navigationBarBackWhileAnInjectedBackIsHeldStaysBack() { + input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true) + assertFalse(input.onKeyEvent(navigationBar(KeyEvent.ACTION_DOWN), toGuest = true)) + assertFalse(input.onKeyEvent(navigationBar(KeyEvent.ACTION_UP), toGuest = true)) + assertEquals(listOf(true), presses) + assertTrue(input.onKeyEvent(injected(KeyEvent.ACTION_UP), toGuest = true)) + assertEquals(listOf(true, false), presses) + } + + @Test fun cancelReleasesAHeldPressOnce() { + input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true) + input.cancel() + assertEquals(listOf(true, false), presses) + input.onKeyEvent(injected(KeyEvent.ACTION_UP), toGuest = true) + input.cancel() + assertEquals(listOf(true, false), presses) + } + @Test fun controllerBackStaysBack() { val source = InputDevice.SOURCE_GAMEPAD or InputDevice.SOURCE_KEYBOARD assertFalse(input.onKeyEvent(key(KeyEvent.ACTION_DOWN, source = source), toGuest = true)) From db8c66b107134c9f71c31d61ab6fbd09bb546027 Mon Sep 17 00:00:00 2001 From: Omar Al Taki <omar.altaki@lau.edu> Date: Sat, 31 Oct 2026 03:24:42 +0400 Subject: [PATCH 30/85] fix(input): keep mouse Back routed to screen-key text fields while editing them --- app/src/main/java/com/droiddeck/launcher/SessionActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index dfc0480424..860d3d2478 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -2584,7 +2584,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { Log.i(TAG, String.format(java.util.Locale.ROOT, "back key device=%d (%s) source=0x%x flags=0x%x", event.deviceId, event.device?.name, event.source, event.flags)) } - val mouseToGuest = !pipUi && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && + val mouseToGuest = !pipUi && !screenKeyTextFocus && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && !SessionState.suspended && !(::loading.isInitialized && (loading.visible || loading.ended)) if (mouseBackInput.onKeyEvent(event, mouseToGuest)) return true val backToQam = !pipUi && !screenKeyTextFocus && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && From aad60fef5b47e8b3fd8df4db700b42e3ad6cfca5 Mon Sep 17 00:00:00 2001 From: Omar Al Taki <omar.altaki@lau.edu> Date: Sat, 31 Oct 2026 03:38:47 +0400 Subject: [PATCH 31/85] fix(input): keep the right button down until every overlapping mouse Back is released --- .../java/com/droiddeck/launcher/input/MouseBackInput.kt | 4 ++-- .../com/droiddeck/launcher/input/MouseBackInputTest.kt | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt b/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt index 959196590a..e695db5178 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt @@ -20,14 +20,14 @@ class MouseBackInput(private val sendRight: (Boolean) -> Unit, private val mouse if (device in held && (fromMouse || injected)) { if (event.action == KeyEvent.ACTION_UP) { held.remove(device) - sendRight(false) + if (held.isEmpty()) sendRight(false) } return true } if (event.action != KeyEvent.ACTION_DOWN || event.repeatCount > 0 || !toGuest) return false if (!fromMouse && !(injected && mouseAttached())) return false + if (held.isEmpty()) sendRight(true) held.add(device) - sendRight(true) return true } diff --git a/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt b/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt index 014bf5cc14..8a755f6e9a 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt @@ -76,6 +76,15 @@ class MouseBackInputTest { assertEquals(listOf(true, false), presses) } + @Test fun overlappingPressesHoldTheButtonUntilTheLastRelease() { + input.onKeyEvent(key(KeyEvent.ACTION_DOWN), toGuest = true) + input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true) + input.onKeyEvent(key(KeyEvent.ACTION_UP), toGuest = true) + assertEquals(listOf(true), presses) + input.onKeyEvent(injected(KeyEvent.ACTION_UP), toGuest = true) + assertEquals(listOf(true, false), presses) + } + @Test fun cancelReleasesAHeldPressOnce() { input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true) input.cancel() From 3d1f0f63b927ea20bd9ea141b9b02802b7f72404 Mon Sep 17 00:00:00 2001 From: Omar Al Taki <omar.altaki@lau.edu> Date: Sat, 31 Oct 2026 04:04:42 +0400 Subject: [PATCH 32/85] fix(input): release a held mouse Back only when its own device disconnects --- .../com/droiddeck/launcher/SessionActivity.kt | 2 +- .../launcher/input/MouseBackInput.kt | 7 +++++++ .../launcher/input/MouseBackInputTest.kt | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 860d3d2478..b4968c7110 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -588,7 +588,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { Log.i(TAG, "input device $deviceId disconnected") dropMouseCursor() backQamInput.onDeviceRemoved(deviceId) - mouseBackInput.cancel() + mouseBackInput.onDeviceRemoved(deviceId) joyConVr?.refresh() padBridge?.onDeviceRemoved(deviceId) if (::padMouse.isInitialized) padMouse.reset() diff --git a/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt b/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt index e695db5178..261c88a74b 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/MouseBackInput.kt @@ -37,6 +37,13 @@ class MouseBackInput(private val sendRight: (Boolean) -> Unit, private val mouse sendRight(false) } + fun onDeviceRemoved(deviceId: Int) { + if (held.isEmpty()) return + held.remove(deviceId) + if (!mouseAttached()) held.remove(KeyCharacterMap.VIRTUAL_KEYBOARD) + if (held.isEmpty()) sendRight(false) + } + companion object { fun isFromMouse(event: KeyEvent): Boolean = event.isFromSource(InputDevice.SOURCE_MOUSE) || event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE) diff --git a/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt b/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt index 8a755f6e9a..625f93e7cf 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/MouseBackInputTest.kt @@ -85,6 +85,26 @@ class MouseBackInputTest { assertEquals(listOf(true, false), presses) } + @Test fun anUnrelatedDeviceDisconnectingKeepsTheButtonHeld() { + input.onKeyEvent(key(KeyEvent.ACTION_DOWN), toGuest = true) + input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true) + input.onDeviceRemoved(9) + assertEquals(listOf(true), presses) + } + + @Test fun theMouseDisconnectingReleasesItsPress() { + input.onKeyEvent(key(KeyEvent.ACTION_DOWN), toGuest = true) + input.onDeviceRemoved(7) + assertEquals(listOf(true, false), presses) + } + + @Test fun theLastMouseDisconnectingReleasesAnInjectedPress() { + input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true) + mouse = false + input.onDeviceRemoved(7) + assertEquals(listOf(true, false), presses) + } + @Test fun cancelReleasesAHeldPressOnce() { input.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true) input.cancel() From 6b887c42afe673e79e9ee419a26f6bd34a62a97b Mon Sep 17 00:00:00 2001 From: KeegantheVeganat0r <58369898+KeegantheVeganat0r@users.noreply.github.com> Date: Thu, 5 Nov 2026 17:27:43 +0000 Subject: [PATCH 33/85] feat(hud): add independent 1% and 0.1% low toggles --- .../launcher/hud/DroidDeckHudConfig.kt | 2 +- .../launcher/hud/DroidDeckHudModels.kt | 4 +- .../launcher/hud/DroidDeckHudView.kt | 52 +++++++++++++------ .../launcher/ui/DroidDeckHudSettings.kt | 4 +- app/src/main/res/values/strings.xml | 2 + .../launcher/hud/DroidDeckHudPanelTest.kt | 26 ++++++++++ 6 files changed, 69 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt index 86e9f8f398..8fc38a95f9 100644 --- a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt +++ b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt @@ -9,7 +9,7 @@ internal object DroidDeckHudConfig { "hudOutline" to "40", "hudOutlineAccent" to "1", "showFPS" to "1", "showFPSGraph" to "1", "showCPUUsage" to "1", "showCPULoad" to "1", "showGPULoad" to "1", "showVram" to "1", "showRAM" to "1", "showPower" to "1", "showTemp" to "1", "showBatteryTemp" to "1", - "showGpuTemp" to "0", "showBattery" to "0", "showLow001" to "1", "fpsDecimal" to "1", "showPerCore" to "1", + "showGpuTemp" to "0", "showBattery" to "0", "showLow1" to "1", "showLow01" to "1", "showLow001" to "1", "fpsDecimal" to "1", "showPerCore" to "1", "showSwap" to "1", "showNet" to "1", "showResolution" to "1", "showProton" to "1", "showSession" to "1", "showClock" to "1", "showEngine" to "1", "showRenderer" to "1", "showGpuModel" to "1", "tempUnit" to "c", "tempBands" to "1", "tempAuto" to "1", "tempRedCpu" to "90", "tempRedGpu" to "90", "tempRedBat" to "48", diff --git a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudModels.kt b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudModels.kt index 9f59512e55..b77d69772f 100644 --- a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudModels.kt +++ b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudModels.kt @@ -37,11 +37,11 @@ enum class DroidDeckHudSize(val token: String, val label: String) { fun from(token: String?): DroidDeckHudSize = values().firstOrNull { it.token.equals(token, ignoreCase = true) } ?: FULL - val MINIMAL_CHIPS = setOf("FPS", "FPS graph", "0.01% low", "FPS .1", "Engine", "Clock") + val MINIMAL_CHIPS = setOf("FPS", "FPS graph", "1% low", "0.1% low", "0.01% low", "FPS .1", "Engine", "Clock") val PILL_CHIPS = setOf("FPS", "FPS graph", "GPU", "CPU", "VRAM", "RAM", "Battery", "GPU model", "FPS .1", "Engine", "Clock") val STANDARD_CHIPS = setOf( "FPS", "FPS graph", "GPU", "GPU temp", "CPU", "VRAM", "RAM", "Power", "Temp", - "Battery", "GPU model", "Engine", "0.01% low", "FPS .1", "Clock", + "Battery", "GPU model", "Engine", "1% low", "0.1% low", "0.01% low", "FPS .1", "Clock", ) val MEGA_ONLY = setOf( "Per-core", "Swap", "Network", "Resolution", "Proton", "Wrapper", "DX ver", "Session", diff --git a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt index e78249a1c1..b3b33d8da0 100644 --- a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt +++ b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt @@ -90,6 +90,8 @@ class DroidDeckHudView(context: Context) : View(context) { private var showPower = true private var showBatteryTemp = false private var showGraph = false + private var showLow1 = true + private var showLow01 = true private var showLow001 = true private var fpsDecimal = true private var showClockTime = true @@ -299,6 +301,8 @@ class DroidDeckHudView(context: Context) : View(context) { showPower = cfg.get("showPower", "1") == "1" showBatteryTemp = cfg.get("showBatteryTemp", "0") == "1" showGraph = cfg.get("showFPSGraph", "0") == "1" + showLow1 = cfg.get("showLow1", "1") == "1" + showLow01 = cfg.get("showLow01", "1") == "1" showLow001 = cfg.get("showLow001", "1") == "1" fpsDecimal = cfg.get("fpsDecimal", "1") == "1" showClockTime = cfg.get("showClock", "1") == "1" @@ -750,8 +754,10 @@ class DroidDeckHudView(context: Context) : View(context) { v += gap(unitPx); v += numUnit(fmt1(1000f / max(fpsNow, 1f)), "ms", rowPx, unitPx) rows.add(HudRow(Span(apiLabel(), colFps, rowPx), v)) rows.add(HudRow(Span("AVG", colLo, rowPx), numUnit(fmt1(fpsAvg), "FPS", rowPx, unitPx))) - rows.add(HudRow(Span("1%", colLo, rowPx), numUnit(lowText(lows.low1Fps), "FPS", rowPx, unitPx))) - rows.add(HudRow(Span("0.1%", colLo, rowPx), numUnit(lowText(lows.low01Fps), "FPS", rowPx, unitPx))) + if (showLow1) + rows.add(HudRow(Span("1%", colLo, rowPx), numUnit(lowText(lows.low1Fps), "FPS", rowPx, unitPx))) + if (showLow01) + rows.add(HudRow(Span("0.1%", colLo, rowPx), numUnit(lowText(lows.low01Fps), "FPS", rowPx, unitPx))) if (showLow001) rows.add(HudRow(Span("0.01%", colLo, rowPx), numUnit(lowText(lows.low001Fps), "FPS", rowPx, unitPx))) } @@ -799,7 +805,7 @@ class DroidDeckHudView(context: Context) : View(context) { val tiles = ArrayList<Tile>() if (showFPS) tiles.add(Tile("FPS", colFps, listOf(Span(fpsText(fpsNow), colValue, valPx, glow = true)), - "${fmt1(fpsAvg)} avg · ${lowText(lows.low1Fps) ?: "—"} 1%", false)) + "${fmt1(fpsAvg)} avg" + (if (showLow1) " · ${lowText(lows.low1Fps) ?: "—"} 1%" else ""), false)) if (showFPS) tiles.add(Tile("FRAME", colDim, numUnit(fmt1(1000f / max(fpsNow, 1f)), "ms", valPx, unitPx), "${fmt1(graphMinMs)} – ${fmt1(graphMaxMs)}", false)) if (showGPU && hasGpuStats(s)) tiles.add(Tile("GPU", colGpu, numUnit(s.gpuPercent?.toString(), "%", valPx, unitPx), @@ -963,11 +969,14 @@ class DroidDeckHudView(context: Context) : View(context) { Span(fpsText(fpsNow), colValue, if (minGenerating) bigPx * 0.55f else bigPx), Span("fps", colDim, if (minGenerating) bigUnitPx * 0.8f else bigUnitPx)) val sub = ArrayList<Span>() - sub += Span("1% ", colDim, subPx); sub += Span(lowText(lows.low1Fps) ?: "—", colFps, subPx) - sub += Span(" · 0.1% ", colDim, subPx); sub += Span(lowText(lows.low01Fps) ?: "—", colFps, subPx) - if (showLow001) { - sub += Span(" · 0.01% ", colDim, subPx); sub += Span(lowText(lows.low001Fps) ?: "—", colFps, subPx) + fun low(label: String, value: Float) { + if (sub.isNotEmpty()) sub += Span(" · ", colDim, subPx) + sub += Span("$label ", colDim, subPx) + sub += Span(lowText(value) ?: "—", colFps, subPx) } + if (showLow1) low("1%", lows.low1Fps) + if (showLow01) low("0.1%", lows.low01Fps) + if (showLow001) low("0.01%", lows.low001Fps) val footerLabel = listOf(if (showEngine) engineLabel else "", displayServer) .filter { it.isNotBlank() }.joinToString(" · ") val hdr = if (hdrState != DroidDeckHudHdr.NONE) hdrLine(footPx) else emptyList() @@ -979,11 +988,13 @@ class DroidDeckHudView(context: Context) : View(context) { max(measure(footerLabel, footPx), runWidth(hdr)), if (showGraph) sp(120f) else 0f) val bigBase = headerBottom + sp(8f) + capHeight(big[0].sizePx) placeRun(left - inkLeft(big[0].text, big[0].sizePx), bigBase, big, glow = true) - val subBase = bigBase + sp(10f) + capHeight(subPx) - placeRun(left - inkLeft(sub[0].text, subPx), subBase, sub) - var last = subBase + var last = bigBase + if (sub.isNotEmpty()) { + last += sp(10f) + capHeight(subPx) + placeRun(left - inkLeft(sub[0].text, subPx), last, sub) + } if (showGraph) { - val top = subBase + sp(9f) + val top = last + sp(9f) graphRect = RectF(left, top, left + colW, top + sp(24f)) last = top + sp(24f) } @@ -1042,10 +1053,15 @@ class DroidDeckHudView(context: Context) : View(context) { val groups = ArrayList<List<Span>>() run { val l = ArrayList<Span>() - l += Span("1% ", colDim, rowPx); l += Span(lowText(lows.low1Fps) ?: "—", colFps, rowPx) - l += Span(" 0.1% ", colDim, rowPx); l += Span(lowText(lows.low01Fps) ?: "—", colFps, rowPx) - if (showLow001) { l += Span(" 0.01% ", colDim, rowPx); l += Span(lowText(lows.low001Fps) ?: "—", colFps, rowPx) } - groups += l + fun low(label: String, value: Float) { + if (l.isNotEmpty()) l += Span(" ", colDim, rowPx) + l += Span("$label ", colDim, rowPx) + l += Span(lowText(value) ?: "—", colFps, rowPx) + } + if (showLow1) low("1%", lows.low1Fps) + if (showLow01) low("0.1%", lows.low01Fps) + if (showLow001) low("0.01%", lows.low001Fps) + if (l.isNotEmpty()) groups += l } if (showGPU || showGpuTemp) { val l = arrayListOf(Span("GPU", colGpu, rowPx)) @@ -1208,8 +1224,10 @@ class DroidDeckHudView(context: Context) : View(context) { v += gap(unitPx); v += numUnit(fmt1(1000f / max(fpsNow, 1f)), "ms", rowPx, unitPx) right.add(HudRow(Span(apiLabel(), colFps, rowPx), v)) right.add(HudRow(Span("AVG", colLo, rowPx), numUnit(fmt1(fpsAvg), "FPS", rowPx, unitPx))) - right.add(HudRow(Span("1%", colLo, rowPx), numUnit(lowText(lows.low1Fps), "FPS", rowPx, unitPx))) - right.add(HudRow(Span("0.1%", colLo, rowPx), numUnit(lowText(lows.low01Fps), "FPS", rowPx, unitPx))) + if (showLow1) + right.add(HudRow(Span("1%", colLo, rowPx), numUnit(lowText(lows.low1Fps), "FPS", rowPx, unitPx))) + if (showLow01) + right.add(HudRow(Span("0.1%", colLo, rowPx), numUnit(lowText(lows.low01Fps), "FPS", rowPx, unitPx))) if (showLow001) right.add(HudRow(Span("0.01%", colLo, rowPx), numUnit(lowText(lows.low001Fps), "FPS", rowPx, unitPx))) } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/DroidDeckHudSettings.kt b/app/src/main/java/com/droiddeck/launcher/ui/DroidDeckHudSettings.kt index 95768fb659..4b67d9eea4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/DroidDeckHudSettings.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/DroidDeckHudSettings.kt @@ -153,6 +153,8 @@ private val METRICS = listOf( HudMetric("FPS", "showFPS", R.string.drawer_hud_fps), HudMetric("FPS graph", "showFPSGraph", R.string.hud_metric_graph), HudMetric("FPS .1", "fpsDecimal", R.string.hud_metric_decimal), + HudMetric("1% low", "showLow1", R.string.hud_metric_low1), + HudMetric("0.1% low", "showLow01", R.string.hud_metric_low01), HudMetric("0.01% low", "showLow001", R.string.hud_metric_low001), HudMetric("Engine", "showEngine", R.string.hud_metric_engine), HudMetric("GPU model", "showGpuModel", R.string.hud_metric_gpu_model), @@ -176,6 +178,6 @@ private val METRICS = listOf( private val HIDDEN = mapOf( DroidDeckHudSize.PILL to setOf("FPS", "FPS graph"), DroidDeckHudSize.MINIMAL to setOf("FPS"), - DroidDeckHudSize.TILES to setOf("FPS graph", "0.01% low"), + DroidDeckHudSize.TILES to setOf("FPS graph", "0.1% low", "0.01% low"), DroidDeckHudSize.STRIP to setOf("FPS"), ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 417dd49465..c038b1841d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -717,6 +717,8 @@ <string name="hud_group_metrics">Readings</string> <string name="hud_metric_graph">Frame time graph</string> <string name="hud_metric_decimal">Frame rate with a decimal</string> + <string name="hud_metric_low1">1% low</string> + <string name="hud_metric_low01">0.1% low</string> <string name="hud_metric_low001">0.01% low</string> <string name="hud_metric_engine">Graphics engine</string> <string name="hud_metric_gpu_model">GPU name</string> diff --git a/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt b/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt index 32c58a41f0..6217b6656c 100644 --- a/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt @@ -35,6 +35,32 @@ class DroidDeckHudPanelTest { assertEquals("1", DroidDeckHudConfig.DEFAULTS["hudLocked"]) } + @Test fun lowMetricsCanBeHiddenIndependentlyInEveryLayoutThatShowsThem() { + val metrics = listOf("showLow1" to "1%", "showLow01" to "0.1%", "showLow001" to "0.01%") + for (size in DroidDeckHudSize.values().filter { it != DroidDeckHudSize.PILL }) { + for (mask in 0..7) { + val app = RuntimeEnvironment.getApplication() + val parent = FrameLayout(app) + val view = DroidDeckHudView(app) + parent.addView(view) + parent.layout(0, 0, 4000, 1080) + val settings = metrics.mapIndexed { index, (key, _) -> + key to if (mask and (1 shl index) != 0) "1" else "0" + }.toMap() + view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + + ("hudSize" to size.token) + settings)) + view.showForTest(SNAPSHOT, "DXVK", 0L) + val lines = view.linesForTest().joinToString(" ") + for ((index, metric) in metrics.withIndex()) { + val supported = size != DroidDeckHudSize.TILES || index == 0 + val expected = supported && mask and (1 shl index) != 0 + val label = Regex("(?<![0-9.])${Regex.escape(metric.second)}") + assertEquals("$size, mask=$mask, ${metric.second}: $lines", expected, label.containsMatchIn(lines)) + } + } + } + } + @Test fun everySizeDrawsTheDPanelWithEverythingInsideIt() { val stats = FrameStats() var now = 1_000_000_000L From b563b8d1eba712ca836c7b5da080fe81e1ae2ee9 Mon Sep 17 00:00:00 2001 From: KeegantheVeganat0r <58369898+KeegantheVeganat0r@users.noreply.github.com> Date: Thu, 5 Nov 2026 17:36:45 +0000 Subject: [PATCH 34/85] fix(hud): translate low FPS toggles in all supported locales --- app/src/main/res/values-ar/strings.xml | 2 ++ app/src/main/res/values-b+es+419/strings.xml | 2 ++ app/src/main/res/values-bg/strings.xml | 2 ++ app/src/main/res/values-cs/strings.xml | 2 ++ app/src/main/res/values-da/strings.xml | 2 ++ app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values-el/strings.xml | 2 ++ app/src/main/res/values-es/strings.xml | 2 ++ app/src/main/res/values-fi/strings.xml | 2 ++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-hi/strings.xml | 2 ++ app/src/main/res/values-hu/strings.xml | 2 ++ app/src/main/res/values-in/strings.xml | 2 ++ app/src/main/res/values-it/strings.xml | 2 ++ app/src/main/res/values-ja/strings.xml | 2 ++ app/src/main/res/values-ko/strings.xml | 2 ++ app/src/main/res/values-ms/strings.xml | 2 ++ app/src/main/res/values-nb/strings.xml | 2 ++ app/src/main/res/values-nl/strings.xml | 2 ++ app/src/main/res/values-pl/strings.xml | 2 ++ app/src/main/res/values-pt-rPT/strings.xml | 2 ++ app/src/main/res/values-pt/strings.xml | 2 ++ app/src/main/res/values-ro/strings.xml | 2 ++ app/src/main/res/values-ru/strings.xml | 2 ++ app/src/main/res/values-sv/strings.xml | 2 ++ app/src/main/res/values-th/strings.xml | 2 ++ app/src/main/res/values-tr/strings.xml | 2 ++ app/src/main/res/values-uk/strings.xml | 2 ++ app/src/main/res/values-vi/strings.xml | 2 ++ app/src/main/res/values-zh-rCN/strings.xml | 2 ++ app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ 32 files changed, 64 insertions(+) diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 27328cddbf..7b9a17ca71 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -678,6 +678,8 @@ <string name="hud_group_metrics">القراءات</string> <string name="hud_metric_graph">مخطط زمن الإطار</string> <string name="hud_metric_decimal">معدل الإطارات بخانة عشرية</string> + <string name="hud_metric_low1">أدنى 1%</string> + <string name="hud_metric_low01">أدنى 0.1%</string> <string name="hud_metric_low001">أدنى 0.01%</string> <string name="hud_metric_engine">محرك الرسومات</string> <string name="hud_metric_gpu_model">اسم GPU</string> diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index 59d19ea263..eff6652271 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -672,6 +672,8 @@ <string name="hud_group_metrics">Lecturas</string> <string name="hud_metric_graph">Gráfico de tiempos de fotograma</string> <string name="hud_metric_decimal">Tasa de fotogramas con decimal</string> + <string name="hud_metric_low1">1% más bajo</string> + <string name="hud_metric_low01">0.1% más bajo</string> <string name="hud_metric_low001">0.01% más bajo</string> <string name="hud_metric_engine">Motor gráfico</string> <string name="hud_metric_gpu_model">Nombre de la GPU</string> diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 929cd0a5fa..1b17dcbb18 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Показания</string> <string name="hud_metric_graph">Графика на времето на кадрите</string> <string name="hud_metric_decimal">Честота на кадрите с десетичен знак</string> + <string name="hud_metric_low1">1% най-ниски</string> + <string name="hud_metric_low01">0.1% най-ниски</string> <string name="hud_metric_low001">0.01% най-ниски</string> <string name="hud_metric_engine">Графичен двигател</string> <string name="hud_metric_gpu_model">Име на GPU</string> diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index f185a75ac5..58616db345 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -674,6 +674,8 @@ <string name="hud_group_metrics">Údaje</string> <string name="hud_metric_graph">Graf časů snímků</string> <string name="hud_metric_decimal">Snímková frekvence s desetinným místem</string> + <string name="hud_metric_low1">1% nejnižší</string> + <string name="hud_metric_low01">0.1% nejnižší</string> <string name="hud_metric_low001">0.01% nejnižší</string> <string name="hud_metric_engine">Grafický engine</string> <string name="hud_metric_gpu_model">Název GPU</string> diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 4835c6c525..36e87a79eb 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Målinger</string> <string name="hud_metric_graph">Billedtidsgraf</string> <string name="hud_metric_decimal">Billedhastighed med decimal</string> + <string name="hud_metric_low1">1% laveste</string> + <string name="hud_metric_low01">0.1% laveste</string> <string name="hud_metric_low001">0.01% laveste</string> <string name="hud_metric_engine">Grafikmotor</string> <string name="hud_metric_gpu_model">GPU-navn</string> diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index e8d3a8187c..37c35d3f13 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Messwerte</string> <string name="hud_metric_graph">Frametime-Diagramm</string> <string name="hud_metric_decimal">Bildrate mit Nachkommastelle</string> + <string name="hud_metric_low1">1%-Tiefstwert</string> + <string name="hud_metric_low01">0.1%-Tiefstwert</string> <string name="hud_metric_low001">0.01%-Tiefstwert</string> <string name="hud_metric_engine">Grafik-Engine</string> <string name="hud_metric_gpu_model">GPU-Name</string> diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 5c36e43ac2..25c7c40d78 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Μετρήσεις</string> <string name="hud_metric_graph">Γράφημα χρόνου καρέ</string> <string name="hud_metric_decimal">Ρυθμός καρέ με δεκαδικό</string> + <string name="hud_metric_low1">1% χαμηλότερα</string> + <string name="hud_metric_low01">0.1% χαμηλότερα</string> <string name="hud_metric_low001">0.01% χαμηλότερα</string> <string name="hud_metric_engine">Μηχανή γραφικών</string> <string name="hud_metric_gpu_model">Όνομα GPU</string> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index deb2f0247b..9f09dd2e9e 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -672,6 +672,8 @@ <string name="hud_group_metrics">Lecturas</string> <string name="hud_metric_graph">Gráfico de tiempos de fotograma</string> <string name="hud_metric_decimal">Tasa de fotogramas con decimal</string> + <string name="hud_metric_low1">1% más bajo</string> + <string name="hud_metric_low01">0.1% más bajo</string> <string name="hud_metric_low001">0.01% más bajo</string> <string name="hud_metric_engine">Motor gráfico</string> <string name="hud_metric_gpu_model">Nombre de la GPU</string> diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 465cffc012..2bab8a4f84 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Lukemat</string> <string name="hud_metric_graph">Kuva-aikakäyrä</string> <string name="hud_metric_decimal">Kuvataajuus desimaalilla</string> + <string name="hud_metric_low1">1% alin</string> + <string name="hud_metric_low01">0.1% alin</string> <string name="hud_metric_low001">0.01% alin</string> <string name="hud_metric_engine">Grafiikkamoottori</string> <string name="hud_metric_gpu_model">GPU:n nimi</string> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2939b36150..6b20807dd2 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -672,6 +672,8 @@ <string name="hud_group_metrics">Mesures</string> <string name="hud_metric_graph">Graphique des temps d\'image</string> <string name="hud_metric_decimal">Fréquence d\'images avec une décimale</string> + <string name="hud_metric_low1">1% les plus bas</string> + <string name="hud_metric_low01">0.1% les plus bas</string> <string name="hud_metric_low001">0.01% les plus bas</string> <string name="hud_metric_engine">Moteur graphique</string> <string name="hud_metric_gpu_model">Nom du GPU</string> diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 0724288e56..ad4934b347 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">रीडिंग</string> <string name="hud_metric_graph">फ़्रेम टाइम ग्राफ़</string> <string name="hud_metric_decimal">दशमलव सहित फ़्रेम दर</string> + <string name="hud_metric_low1">1% लो</string> + <string name="hud_metric_low01">0.1% लो</string> <string name="hud_metric_low001">0.01% लो</string> <string name="hud_metric_engine">ग्राफ़िक्स इंजन</string> <string name="hud_metric_gpu_model">GPU का नाम</string> diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 1de6bee395..f1559e0f18 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Mért értékek</string> <string name="hud_metric_graph">Képkockaidő-grafikon</string> <string name="hud_metric_decimal">Képkockasebesség tizedesjeggyel</string> + <string name="hud_metric_low1">1% legalacsonyabb</string> + <string name="hud_metric_low01">0.1% legalacsonyabb</string> <string name="hud_metric_low001">0.01% legalacsonyabb</string> <string name="hud_metric_engine">Grafikus motor</string> <string name="hud_metric_gpu_model">GPU neve</string> diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 4cb978fb76..4f07311840 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -668,6 +668,8 @@ <string name="hud_group_metrics">Pembacaan</string> <string name="hud_metric_graph">Grafik waktu bingkai</string> <string name="hud_metric_decimal">Laju bingkai dengan desimal</string> + <string name="hud_metric_low1">1% terendah</string> + <string name="hud_metric_low01">0.1% terendah</string> <string name="hud_metric_low001">0.01% terendah</string> <string name="hud_metric_engine">Mesin grafis</string> <string name="hud_metric_gpu_model">Nama GPU</string> diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 2bc2f2caa9..0b9fcdd674 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -672,6 +672,8 @@ <string name="hud_group_metrics">Valori</string> <string name="hud_metric_graph">Grafico tempi fotogramma</string> <string name="hud_metric_decimal">Frequenza fotogrammi con decimale</string> + <string name="hud_metric_low1">1% più basso</string> + <string name="hud_metric_low01">0.1% più basso</string> <string name="hud_metric_low001">0.01% più basso</string> <string name="hud_metric_engine">Motore grafico</string> <string name="hud_metric_gpu_model">Nome GPU</string> diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 4eeb0f4da9..23339bd24c 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -668,6 +668,8 @@ <string name="hud_group_metrics">表示項目</string> <string name="hud_metric_graph">フレームタイムグラフ</string> <string name="hud_metric_decimal">フレームレートの小数表示</string> + <string name="hud_metric_low1">1%最低値</string> + <string name="hud_metric_low01">0.1%最低値</string> <string name="hud_metric_low001">0.01%最低値</string> <string name="hud_metric_engine">グラフィックスエンジン</string> <string name="hud_metric_gpu_model">GPU名</string> diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 853f277c7d..3f43a0a1c8 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -668,6 +668,8 @@ <string name="hud_group_metrics">측정값</string> <string name="hud_metric_graph">프레임 타임 그래프</string> <string name="hud_metric_decimal">소수점 프레임 속도</string> + <string name="hud_metric_low1">1% 최저</string> + <string name="hud_metric_low01">0.1% 최저</string> <string name="hud_metric_low001">0.01% 최저</string> <string name="hud_metric_engine">그래픽 엔진</string> <string name="hud_metric_gpu_model">GPU 이름</string> diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 05a4715a9e..b0adb14632 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -668,6 +668,8 @@ <string name="hud_group_metrics">Bacaan</string> <string name="hud_metric_graph">Graf masa bingkai</string> <string name="hud_metric_decimal">Kadar bingkai dengan perpuluhan</string> + <string name="hud_metric_low1">1% terendah</string> + <string name="hud_metric_low01">0.1% terendah</string> <string name="hud_metric_low001">0.01% terendah</string> <string name="hud_metric_engine">Enjin grafik</string> <string name="hud_metric_gpu_model">Nama GPU</string> diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index f58bbb2a63..9cf373f054 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Måleverdier</string> <string name="hud_metric_graph">Bildetidsgraf</string> <string name="hud_metric_decimal">Bildefrekvens med desimal</string> + <string name="hud_metric_low1">1% laveste</string> + <string name="hud_metric_low01">0.1% laveste</string> <string name="hud_metric_low001">0.01% laveste</string> <string name="hud_metric_engine">Grafikkmotor</string> <string name="hud_metric_gpu_model">GPU-navn</string> diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 97f508808c..ee5325cf3e 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Meetwaarden</string> <string name="hud_metric_graph">Frametijdgrafiek</string> <string name="hud_metric_decimal">Beeldsnelheid met decimaal</string> + <string name="hud_metric_low1">1% laagste</string> + <string name="hud_metric_low01">0.1% laagste</string> <string name="hud_metric_low001">0.01% laagste</string> <string name="hud_metric_engine">Grafische engine</string> <string name="hud_metric_gpu_model">GPU-naam</string> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 726f588736..a6b1771595 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -674,6 +674,8 @@ <string name="hud_group_metrics">Odczyty</string> <string name="hud_metric_graph">Wykres czasu klatek</string> <string name="hud_metric_decimal">Liczba klatek z miejscem po przecinku</string> + <string name="hud_metric_low1">1% najniższych</string> + <string name="hud_metric_low01">0.1% najniższych</string> <string name="hud_metric_low001">0.01% najniższych</string> <string name="hud_metric_engine">Silnik graficzny</string> <string name="hud_metric_gpu_model">Nazwa GPU</string> diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 57ec99ea69..543de9b58c 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -672,6 +672,8 @@ <string name="hud_group_metrics">Leituras</string> <string name="hud_metric_graph">Gráfico de tempo de fotograma</string> <string name="hud_metric_decimal">Taxa de fotogramas com decimal</string> + <string name="hud_metric_low1">1% mais baixo</string> + <string name="hud_metric_low01">0.1% mais baixo</string> <string name="hud_metric_low001">0.01% mais baixo</string> <string name="hud_metric_engine">Motor gráfico</string> <string name="hud_metric_gpu_model">Nome da GPU</string> diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index f94154363b..be0368f500 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -672,6 +672,8 @@ <string name="hud_group_metrics">Leituras</string> <string name="hud_metric_graph">Gráfico de tempo de quadro</string> <string name="hud_metric_decimal">Taxa de quadros com decimal</string> + <string name="hud_metric_low1">1% mais baixo</string> + <string name="hud_metric_low01">0.1% mais baixo</string> <string name="hud_metric_low001">0.01% mais baixo</string> <string name="hud_metric_engine">Motor gráfico</string> <string name="hud_metric_gpu_model">Nome da GPU</string> diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index 310667e478..08ecc9183f 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -672,6 +672,8 @@ <string name="hud_group_metrics">Valori</string> <string name="hud_metric_graph">Grafic timp de cadru</string> <string name="hud_metric_decimal">Rată de cadre cu zecimală</string> + <string name="hud_metric_low1">1% cele mai mici</string> + <string name="hud_metric_low01">0.1% cele mai mici</string> <string name="hud_metric_low001">0.01% cele mai mici</string> <string name="hud_metric_engine">Motor grafic</string> <string name="hud_metric_gpu_model">Nume GPU</string> diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index b3df2b00a6..087f9fcccb 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -674,6 +674,8 @@ <string name="hud_group_metrics">Показатели</string> <string name="hud_metric_graph">График времени кадров</string> <string name="hud_metric_decimal">Частота кадров с десятыми</string> + <string name="hud_metric_low1">1% минимальных</string> + <string name="hud_metric_low01">0.1% минимальных</string> <string name="hud_metric_low001">0.01% минимальных</string> <string name="hud_metric_engine">Графический движок</string> <string name="hud_metric_gpu_model">Название GPU</string> diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 1f8ccb0482..5958734aef 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Mätvärden</string> <string name="hud_metric_graph">Bildtidsgraf</string> <string name="hud_metric_decimal">Bildfrekvens med decimal</string> + <string name="hud_metric_low1">1% lägsta</string> + <string name="hud_metric_low01">0.1% lägsta</string> <string name="hud_metric_low001">0.01% lägsta</string> <string name="hud_metric_engine">Grafikmotor</string> <string name="hud_metric_gpu_model">GPU-namn</string> diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 0292bdfc25..e795ca955f 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -668,6 +668,8 @@ <string name="hud_group_metrics">ค่าที่แสดง</string> <string name="hud_metric_graph">กราฟเวลาเฟรม</string> <string name="hud_metric_decimal">อัตราเฟรมแบบทศนิยม</string> + <string name="hud_metric_low1">1% ต่ำสุด</string> + <string name="hud_metric_low01">0.1% ต่ำสุด</string> <string name="hud_metric_low001">0.01% ต่ำสุด</string> <string name="hud_metric_engine">เอนจินกราฟิก</string> <string name="hud_metric_gpu_model">ชื่อ GPU</string> diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 311b9a94f4..19151d434a 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -670,6 +670,8 @@ <string name="hud_group_metrics">Ölçümler</string> <string name="hud_metric_graph">Kare süresi grafiği</string> <string name="hud_metric_decimal">Ondalıklı kare hızı</string> + <string name="hud_metric_low1">1% en düşük</string> + <string name="hud_metric_low01">0.1% en düşük</string> <string name="hud_metric_low001">0.01% en düşük</string> <string name="hud_metric_engine">Grafik motoru</string> <string name="hud_metric_gpu_model">GPU adı</string> diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 27730223e6..03f96a3a0e 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -674,6 +674,8 @@ <string name="hud_group_metrics">Показники</string> <string name="hud_metric_graph">Графік часу кадрів</string> <string name="hud_metric_decimal">Частота кадрів із десятими</string> + <string name="hud_metric_low1">1% мінімальних</string> + <string name="hud_metric_low01">0.1% мінімальних</string> <string name="hud_metric_low001">0.01% мінімальних</string> <string name="hud_metric_engine">Графічний рушій</string> <string name="hud_metric_gpu_model">Назва GPU</string> diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index d2bd3997dc..61910dbbfd 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -668,6 +668,8 @@ <string name="hud_group_metrics">Chỉ số</string> <string name="hud_metric_graph">Biểu đồ thời gian khung hình</string> <string name="hud_metric_decimal">Tốc độ khung hình có số thập phân</string> + <string name="hud_metric_low1">1% thấp nhất</string> + <string name="hud_metric_low01">0.1% thấp nhất</string> <string name="hud_metric_low001">0.01% thấp nhất</string> <string name="hud_metric_engine">Engine đồ họa</string> <string name="hud_metric_gpu_model">Tên GPU</string> diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 67353fa837..83e786d274 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -668,6 +668,8 @@ <string name="hud_group_metrics">读数</string> <string name="hud_metric_graph">帧时间图表</string> <string name="hud_metric_decimal">帧率显示小数</string> + <string name="hud_metric_low1">1% 最低帧</string> + <string name="hud_metric_low01">0.1% 最低帧</string> <string name="hud_metric_low001">0.01% 最低帧</string> <string name="hud_metric_engine">图形引擎</string> <string name="hud_metric_gpu_model">GPU 名称</string> diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 4205bcf0ee..f43523bc5f 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -668,6 +668,8 @@ <string name="hud_group_metrics">讀數</string> <string name="hud_metric_graph">幀時間圖表</string> <string name="hud_metric_decimal">幀率顯示小數</string> + <string name="hud_metric_low1">1% 最低幀</string> + <string name="hud_metric_low01">0.1% 最低幀</string> <string name="hud_metric_low001">0.01% 最低幀</string> <string name="hud_metric_engine">圖形引擎</string> <string name="hud_metric_gpu_model">GPU 名稱</string> diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0b1b4f1eca..f5546b265a 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -668,6 +668,8 @@ <string name="hud_group_metrics">讀數</string> <string name="hud_metric_graph">幀時間圖表</string> <string name="hud_metric_decimal">幀率顯示小數</string> + <string name="hud_metric_low1">1% 最低幀</string> + <string name="hud_metric_low01">0.1% 最低幀</string> <string name="hud_metric_low001">0.01% 最低幀</string> <string name="hud_metric_engine">圖形引擎</string> <string name="hud_metric_gpu_model">GPU 名稱</string> From 5614bd5d5aa1cf1cbb8a98e20ca392500b272819 Mon Sep 17 00:00:00 2001 From: wallentx <william.allentx@gmail.com> Date: Wed, 4 Nov 2026 12:00:14 -0600 Subject: [PATCH 35/85] Add enhanced one-session diagnostic bundles --- .gitattributes | 1 + .../droiddeck/launcher/FrontEndActivity.kt | 48 +- .../com/droiddeck/launcher/SessionActivity.kt | 32 +- .../droiddeck/launcher/core/LogRedactor.kt | 64 +- .../launcher/session/EnhancedDiagnostics.kt | 118 +++ .../session/EnhancedSessionLogShare.kt | 731 ++++++++++++++++++ .../launcher/session/GameEnvironmentStore.kt | 3 +- .../launcher/session/SessionFiles.kt | 1 + .../launcher/session/SessionLogShare.kt | 111 +-- .../launcher/session/SessionPaths.kt | 9 +- .../launcher/session/SessionPrefs.kt | 14 +- .../launcher/session/SessionService.kt | 2 + .../launcher/session/SettingsReset.kt | 2 +- .../droiddeck/launcher/ui/FrontEndScreen.kt | 2 + .../droiddeck/launcher/ui/FrontEndSetup.kt | 4 + app/src/main/res/values/strings.xml | 7 + .../launcher/core/LogRedactorTest.kt | 54 ++ .../session/EnhancedDiagnosticsTest.kt | 140 ++++ .../session/EnhancedSessionLogShareTest.kt | 331 ++++++++ .../launcher/session/SessionLogShareTest.kt | 13 +- .../session/SessionLogShareZipTest.kt | 23 +- .../launcher/session/SettingsResetTest.kt | 2 + docs/development/game-environment.md | 42 + .../0900-enhanced-frame-diagnostics.patch | 333 ++++++++ .../local/bin/droiddeck-diagnostic-inventory | 446 +++++++++++ .../overlay/usr/local/bin/droiddeck-game-env | 60 +- .../overlay/usr/local/bin/droiddeck-session | 25 +- tools/tests/test_diagnostic_inventory.py | 234 ++++++ .../test_diagnostic_session_integration.py | 50 ++ tools/tests/test_game_exit_diagnostics.py | 186 +++++ tools/tests/test_gamescope_diagnostics.py | 133 ++++ tools/tests/test_steam_exit_status.py | 20 +- 32 files changed, 3100 insertions(+), 141 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/session/EnhancedDiagnostics.kt create mode 100644 app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/session/EnhancedDiagnosticsTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt create mode 100644 tools/gamescope/patches/0900-enhanced-frame-diagnostics.patch create mode 100755 tools/linuxfs/overlay/usr/local/bin/droiddeck-diagnostic-inventory create mode 100644 tools/tests/test_diagnostic_inventory.py create mode 100644 tools/tests/test_diagnostic_session_integration.py create mode 100644 tools/tests/test_game_exit_diagnostics.py create mode 100644 tools/tests/test_gamescope_diagnostics.py diff --git a/.gitattributes b/.gitattributes index 4c0a6c3120..940dbb5f13 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,7 @@ tools/linuxfs/** text=auto eol=lf tools/mangoapp/** text=auto eol=lf tools/comet/LICENSE whitespace=-blank-at-eof tools/comet/droiddeck.patch whitespace=-blank-at-eol,-blank-at-eof +tools/gamescope/patches/0900-enhanced-frame-diagnostics.patch whitespace=-blank-at-eol,-blank-at-eof,-space-before-tab tools/linuxfs/overlay/** text eol=lf tools/linuxfs/desktop/** text eol=lf diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 7bbac41b2f..cc9488b094 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -577,6 +577,7 @@ class FrontEndActivity : ComponentActivity() { private var emulatorList by mutableStateOf<List<Library.Emulator>>(emptyList()) private var runningLabel by mutableStateOf<String?>(null) private var logsEnabled by mutableStateOf(true) + private var enhancedDiagnosticsArmed by mutableStateOf(false) private var gameDebugLogsEnabled by mutableStateOf(false) private var gameDebugLogsNeedsRestart by mutableStateOf(false) private var vacDiagnostics by mutableStateOf(false) @@ -1136,6 +1137,7 @@ class FrontEndActivity : ComponentActivity() { desktopInstalled = desktopInstalled, desktopPresent = desktopPresent, offlineAccount = offlineAccount, offline = offline, frameGenLabel = frameGenLabel, romsDir = romsDir, logsEnabled = logsEnabled, + enhancedDiagnosticsArmed = enhancedDiagnosticsArmed, gameDebugLogsEnabled = gameDebugLogsEnabled, gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart, vacDiagnostics = vacDiagnostics, agentCommands = agentCommands, clearCachedApps = clearCachedApps, adbPaired = adbPaired, memoryHud = memoryHud, backgroundAppLimit = backgroundAppLimit, @@ -1327,6 +1329,15 @@ class FrontEndActivity : ComponentActivity() { gameDebugLogsEnabled = SessionPrefs.gameDebugLogsEnabled(this) gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart() }, + onEnhancedDiagnostics = { + val requested = !com.droiddeck.launcher.session.EnhancedDiagnostics.isArmed(this) + if (!com.droiddeck.launcher.session.EnhancedDiagnostics.setArmed(this, requested)) { + android.widget.Toast.makeText( + this, R.string.setup_logging_update_failed, android.widget.Toast.LENGTH_LONG, + ).show() + } + enhancedDiagnosticsArmed = com.droiddeck.launcher.session.EnhancedDiagnostics.isArmed(this) + }, onGameDebugLogs = { val changed = SessionPrefs.setGameDebugLogsEnabled(this, !SessionPrefs.gameDebugLogsEnabled(this)) if (!changed) android.widget.Toast.makeText( @@ -1350,9 +1361,19 @@ class FrontEndActivity : ComponentActivity() { if (limit == com.droiddeck.launcher.core.BackgroundAppLimit.OFF) com.droiddeck.launcher.core.BackgroundAppLimit.restoreAsync(this) }, onShareLogs = { - SessionLogShare.prepare(this, { SessionLogShare.latest(this) }) { zip -> - if (zip == null) android.widget.Toast.makeText(this, R.string.main_no_logs_yet, android.widget.Toast.LENGTH_LONG).show() - else startActivity(SessionLogShare.shareIntent(this, zip)) + val folder = SessionLogShare.latest(this) + if (folder == null) { + android.widget.Toast.makeText(this, R.string.main_no_logs_yet, android.widget.Toast.LENGTH_LONG).show() + } else if (com.droiddeck.launcher.session.EnhancedDiagnostics.isActive(this, folder)) { + SessionLogShare.prepareEnhanced(this, { folder }) { zips -> + if (zips.isEmpty()) android.widget.Toast.makeText(this, R.string.main_no_logs_yet, android.widget.Toast.LENGTH_LONG).show() + else shareEnhancedArchives(zips) + } + } else { + SessionLogShare.prepare(this, { folder }) { zip -> + if (zip == null) android.widget.Toast.makeText(this, R.string.main_no_logs_yet, android.widget.Toast.LENGTH_LONG).show() + else startActivity(SessionLogShare.shareIntent(this, zip)) + } } }, onShareSessionLog = { folder -> @@ -2688,6 +2709,26 @@ class FrontEndActivity : ComponentActivity() { SessionPrefs.logsEnabled(this) && SessionPrefs.gameDebugLogsEnabled(this) && !SessionPaths.currentSessionLogsRetained(this) + private fun shareEnhancedArchives(zips: List<java.io.File>) { + val choices = zips.map { zip -> + val label = when { + zip.name.endsWith("-session.zip") -> getString(R.string.diagnostics_share_session) + zip.name.endsWith("-graphics.zip") -> getString(R.string.diagnostics_share_graphics) + else -> getString(R.string.diagnostics_share_games) + } + label to listOf(zip) + } + (getString(R.string.diagnostics_share_all) to zips) + android.app.AlertDialog.Builder(this) + .setTitle(R.string.diagnostics_share_title) + .setItems(choices.map { it.first }.toTypedArray()) { _, which -> + val selected = choices[which].second + startActivity(if (selected.size == 1) SessionLogShare.shareIntent(this, selected.single()) + else SessionLogShare.shareEnhancedIntent(this, selected)) + } + .setNegativeButton(android.R.string.cancel, null) + .show() + } + private fun refresh() { val listX64 = SessionPrefs.activeSteamClientArch(this) == "x86_64" if (listX64 != steamGamesX64) { @@ -2712,6 +2753,7 @@ class FrontEndActivity : ComponentActivity() { frameGenLabel = FrameGen.label(this) romsDir = SessionPrefs.romsDir(this).takeIf { it.isNotEmpty() } logsEnabled = SessionPrefs.logsEnabled(this) + enhancedDiagnosticsArmed = com.droiddeck.launcher.session.EnhancedDiagnostics.isArmed(this) gameDebugLogsEnabled = SessionPrefs.gameDebugLogsEnabled(this) gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart() vacDiagnostics = SessionPrefs.vacDiagnostics(this) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index b4968c7110..d5c4fe3104 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -1884,7 +1884,17 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { Toast.makeText(this, R.string.session_no_logs, Toast.LENGTH_LONG).show() return } - SessionLogShare.prepare(this, { folder }) { zip -> + if (com.droiddeck.launcher.session.EnhancedDiagnostics.isActive(this, folder)) { + SessionLogShare.prepareEnhanced(this, { folder }) { zips -> + if (zips.isEmpty()) { + Toast.makeText(this, R.string.session_logs_archive_failed, Toast.LENGTH_LONG).show() + } else runCatching { shareEnhancedArchives(zips) } + .onFailure { + Log.w(TAG, "could not share current session logs", it) + Toast.makeText(this, R.string.session_logs_share_failed, Toast.LENGTH_LONG).show() + } + } + } else SessionLogShare.prepare(this, { folder }) { zip -> if (zip == null) { Toast.makeText(this, R.string.session_logs_archive_failed, Toast.LENGTH_LONG).show() } else { @@ -1897,6 +1907,26 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } } + private fun shareEnhancedArchives(zips: List<File>) { + val choices = zips.map { zip -> + val label = when { + zip.name.endsWith("-session.zip") -> getString(R.string.diagnostics_share_session) + zip.name.endsWith("-graphics.zip") -> getString(R.string.diagnostics_share_graphics) + else -> getString(R.string.diagnostics_share_games) + } + label to listOf(zip) + } + (getString(R.string.diagnostics_share_all) to zips) + android.app.AlertDialog.Builder(this) + .setTitle(R.string.diagnostics_share_title) + .setItems(choices.map { it.first }.toTypedArray()) { _, which -> + val selected = choices[which].second + startActivity(if (selected.size == 1) SessionLogShare.shareIntent(this, selected.single()) + else SessionLogShare.shareEnhancedIntent(this, selected)) + } + .setNegativeButton(android.R.string.cancel, null) + .show() + } + private fun readPrefs() { pipAutoEnter = SessionPrefs.pipAutoEnter(this) unfoldedControls = SessionPrefs.unfoldedControls(this) diff --git a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt index 3230e8ea47..19199873f7 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt @@ -131,42 +131,81 @@ object LogRedactor { @Volatile private var accounts: List<Learned> = emptyList() - fun learnAccounts(vararg loginUsers: java.io.File) { + internal const val MAX_LEARN_INPUT_BYTES = 2 * 1024 * 1024 + private const val MAX_LEARNED_ACCOUNTS = 2048 + private const val MAX_LEARNED_ADDRESSES = 1024 + private const val MAX_ACCOUNT_LENGTH = 256 + + private fun boundedText(file: java.io.File): String? = try { + file.inputStream().buffered().use { input -> + val out = java.io.ByteArrayOutputStream() + val buffer = ByteArray(16 * 1024) + var remaining = MAX_LEARN_INPUT_BYTES + while (remaining > 0) { + val read = input.read(buffer, 0, minOf(buffer.size, remaining)) + if (read < 0) return out.toString(Charsets.UTF_8.name()) + if (read == 0) continue + out.write(buffer, 0, read) + remaining -= read + } + if (input.read() != -1) null else out.toString(Charsets.UTF_8.name()) + } + } catch (_: Exception) { + null + } + + fun learnAccounts(vararg loginUsers: java.io.File): Boolean { val names = LinkedHashSet<String>() val kv = Regex("\"(AccountName|PersonaName)\"\\s+\"([^\"]*)\"") var unread = false for (file in loginUsers) { if (!file.isFile) continue - val text = try { file.readText() } catch (e: Exception) { unread = true; continue } - kv.findAll(text).map { it.groupValues[2].trim() }.filter { it.length >= 3 }.forEach { names += it } + val text = boundedText(file) + if (text == null) { + unread = true + continue + } + for (match in kv.findAll(text)) { + val name = match.groupValues[2].trim() + if (name.length < 3) continue + if (name.length > MAX_ACCOUNT_LENGTH || names.size >= MAX_LEARNED_ACCOUNTS) { + unread = true + break + } + names += name + } } val learned = names.map { name -> val needs = name.lowercase().takeIf { name.all { it.code < 0x80 } } Learned(Regex("(?i)(?<![A-Za-z0-9_])" + Regex.escape(name) + "(?![A-Za-z0-9_])"), needs) } - accounts = if (unread) (accounts + learned).distinctBy { it.regex.pattern } else learned + accounts = if (unread) (learned + accounts).distinctBy { it.regex.pattern }.take(MAX_LEARNED_ACCOUNTS) else learned + return !unread } - fun learnFromRuntime(root: java.io.File) { - learnOwnAddresses(java.io.File(root, "etc/droiddeck-net")) - learnAccounts( + fun learnFromRuntime(root: java.io.File): Boolean { + val addressesComplete = learnOwnAddresses(java.io.File(root, "etc/droiddeck-net")) + val accountsComplete = learnAccounts( java.io.File(root, "root/.local/share/Steam/config/loginusers.vdf"), java.io.File(root, "root/.droiddeck-x64/.local/share/Steam/config/loginusers.vdf"), ) matchers.remove() + return addressesComplete && accountsComplete } @Volatile private var own: List<Learned> = emptyList() - fun learnOwnAddresses(linkFile: java.io.File) { + fun learnOwnAddresses(linkFile: java.io.File): Boolean { val found = ArrayList<Learned>() try { - if (linkFile.isFile) linkFile.forEachLine { line -> - val addr = line.trim().takeIf { it.startsWith("addr ") }?.split(Regex("\\s+"))?.getOrNull(1) ?: return@forEachLine + val text = if (linkFile.isFile) boundedText(linkFile) ?: return false else "" + text.lineSequence().forEach { line -> + val addr = line.trim().takeIf { it.startsWith("addr ") }?.split(Regex("\\s+"))?.getOrNull(1) ?: return@forEach + if (found.size >= MAX_LEARNED_ADDRESSES) return false when (kind(addr)) { "public IPv6" -> { - val groups = expand6(addr)?.take(4) ?: return@forEachLine + val groups = expand6(addr)?.take(4) ?: return@forEach val prefix = groups.joinToString(":") { g -> "0{0,3}" + Regex.escape(g.trimStart('0').ifEmpty { "0" }) } found += Learned( Regex("(?i)(?<![0-9A-Fa-f:])$prefix(?::[0-9A-Fa-f]{0,4}){1,4}(?:%[A-Za-z0-9_.]+)?"), @@ -177,9 +216,10 @@ object LogRedactor { } } } catch (e: Exception) { - return + return false } own = found + return true } fun kind(address: String): String? { diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedDiagnostics.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedDiagnostics.kt new file mode 100644 index 0000000000..2dfbacc496 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedDiagnostics.kt @@ -0,0 +1,118 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import android.util.AtomicFile +import android.util.Log +import org.json.JSONArray +import org.json.JSONObject +import java.io.File + +object EnhancedDiagnostics { + const val MANIFEST_FILE = "enhanced-diagnostics.json" + + private const val TAG = "EnhancedDiagnostics" + private const val PREFS = "session" + private const val ARMED = "enhancedDiagnosticsNext" + private const val ACTIVE_RECORDS = "enhancedDiagnosticsActiveSessions" + private const val SCHEMA = 1 + + fun isArmed(context: Context): Boolean = + context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean(ARMED, false) + + fun setArmed(context: Context, armed: Boolean): Boolean = + context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean(ARMED, armed).commit() + + fun isActive(context: Context, folder: File?): Boolean = activeAt(context, folder) != null + + internal fun isCurrentSessionActive(context: Context): Boolean = isActive(context, SessionPaths.current()) + + fun manifest(context: Context, folder: File?): JSONObject? { + val activeAt = activeAt(context, folder) ?: return null + return buildManifest(folder!!, activeAt) + } + + @Synchronized + internal fun consumeInto(context: Context, folder: File): Boolean { + if (!isArmed(context)) return isActive(context, folder) + if (!folder.isDirectory) return false + val activatedAt = System.currentTimeMillis() + if (!activateAndConsume(context, folder, activatedAt)) return false + val marker = AtomicFile(File(folder, MANIFEST_FILE)) + val manifest = buildManifest(folder, activatedAt) + val output = try { + marker.startWrite() + } catch (error: Exception) { + Log.w(TAG, "could not start the informational enhanced diagnostics manifest", error) + return true + } + try { + output.write((manifest.toString() + "\n").toByteArray(Charsets.UTF_8)) + marker.finishWrite(output) + } catch (error: Exception) { + marker.failWrite(output) + Log.w(TAG, "could not write the informational enhanced diagnostics manifest", error) + } + return true + } + + @Synchronized + internal fun clearRecordFor(context: Context, folder: File) { + removeRecord(context, folder) + } + + private fun buildManifest(folder: File, activatedAt: Long) = JSONObject() + .put("schema", SCHEMA) + .put("profile", "enhanced") + .put("sessionId", folder.name) + .put("activatedAtEpochMs", activatedAt) + .put("exportBundlesBounded", true) + .put("rawCaptureByteBounded", false) + .put("rawCaptureLimitation", "Game and component diagnostics may grow until the session ends") + .put("collectorsRequested", JSONArray(listOf( + "session", "graphics", "games", "processes", "audio", "network", "components", + ))) + + private fun activeAt(context: Context, folder: File?): Long? { + val path = trustedPath(context, folder) ?: return null + return records(context).optLong(path, Long.MIN_VALUE).takeIf { it != Long.MIN_VALUE } + } + + private fun activateAndConsume(context: Context, folder: File, activatedAt: Long): Boolean { + val path = trustedPath(context, folder) ?: return false + val records = records(context) + records.keys().asSequence().toList().forEach { known -> + if (!File(known).isDirectory) records.remove(known) + } + records.put(path, activatedAt) + return context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit() + .putString(ACTIVE_RECORDS, records.toString()) + .putBoolean(ARMED, false) + .commit() + } + + private fun removeRecord(context: Context, folder: File) { + val path = runCatching { folder.canonicalPath }.getOrNull() ?: return + val records = records(context) + if (records.has(path)) { + records.remove(path) + saveRecords(context, records) + } + } + + private fun trustedPath(context: Context, folder: File?): String? { + if (folder == null || !SessionPaths.isSessionFolder(folder)) return null + return runCatching { + val canonical = folder.canonicalFile + if (canonical.parentFile != SessionFiles.logDirectory(context).canonicalFile) null else canonical.path + }.getOrNull() + } + + private fun records(context: Context): JSONObject { + val text = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getString(ACTIVE_RECORDS, null) + return runCatching { JSONObject(text ?: "{}") }.getOrDefault(JSONObject()) + } + + private fun saveRecords(context: Context, records: JSONObject): Boolean = + context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit() + .putString(ACTIVE_RECORDS, records.toString()).commit() +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt new file mode 100644 index 0000000000..6d6f357d70 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -0,0 +1,731 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import android.os.ParcelFileDescriptor +import android.system.Os +import android.system.OsConstants +import com.droiddeck.launcher.core.LogRedactor +import com.droiddeck.launcher.runtime.BattleNet +import com.droiddeck.launcher.runtime.LinuxRuntime +import org.json.JSONArray +import org.json.JSONObject +import java.io.ByteArrayOutputStream +import java.io.File +import java.io.FileOutputStream +import java.io.FileInputStream +import java.nio.ByteBuffer +import java.nio.channels.Channels +import java.nio.channels.FileChannel +import java.nio.channels.SeekableByteChannel +import java.nio.file.Files +import java.nio.file.LinkOption +import java.nio.file.Path +import java.security.MessageDigest +import java.util.Locale +import java.util.zip.ZipEntry +import java.util.zip.ZipOutputStream + +internal data class EnhancedShareLimits( + val maxFilesPerArchive: Int = 256, + val maxDiscoveredFiles: Int = 768, + val maxBytesPerFile: Long = 8L * 1024 * 1024, + val maxBytesTotal: Long = 64L * 1024 * 1024, +) + +internal object EnhancedSessionLogShare { + private enum class Category(val suffix: String) { SESSION("session"), GRAPHICS("graphics"), GAMES("games") } + + private data class Candidate( + val file: File, + val anchor: File, + val entry: String, + val origin: String, + val category: Category, + val linePrefix: String? = null, + ) + + private data class Record( + val entry: String, + val origin: String, + val status: String, + val sourceBytes: Long = 0, + val capturedBytes: Long = 0, + val reason: String? = null, + ) + + private data class Snapshot(val file: File, val sourceBytes: Long, val truncated: Boolean) + + private data class CollectionResult(val candidates: List<Candidate>, val truncated: Boolean) + + private data class ScanResult(val files: List<File>, val truncated: Boolean) + + private data class LegacySource(val file: File, val root: File, val entry: String) + + private class Budget(val limit: Long, var remaining: Long = limit) + + fun create( + context: Context, + folder: File, + onProgress: ((Float) -> Unit)? = null, + limits: EnhancedShareLimits = EnhancedShareLimits(), + ): List<File> { + if (!folder.isDirectory || Files.isSymbolicLink(folder.toPath()) || + limits.maxFilesPerArchive < 1 || limits.maxBytesPerFile < 1 || limits.maxBytesTotal < 1) { + return emptyList() + } + val out = SessionLogShare.shareDir(context).apply { deleteRecursively(); mkdirs() } + val stage = File(out, ".diagnostic-stage").apply { mkdirs() } + val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) + val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = false) + val candidates = discovery.candidates + val totalCandidates = candidates.size.coerceAtLeast(1) + val share = limits.maxBytesTotal / Category.values().size + val budgets = Category.values().associateWith { category -> + Budget(if (category == Category.GAMES) limits.maxBytesTotal - share * 2 else share) + } + var completed = 0 + return try { + Category.values().map { category -> + val budget = budgets.getValue(category) + val records = ArrayList<Record>() + val selected = candidates.filter { it.category == category } + val zip = File(out, "DroidDeck-${folder.name}-${category.suffix}.zip") + ZipOutputStream(zip.outputStream().buffered()).use { archive -> + val names = HashSet<String>() + selected.forEachIndexed { index, candidate -> + val safeEntry = safeEntry(candidate.entry) + val record = when { + index >= limits.maxFilesPerArchive -> Record( + safeEntry ?: "<invalid>", candidate.origin, "omitted", reason = "file-count-limit", + ) + safeEntry == null -> Record("<invalid>", candidate.origin, "omitted", reason = "unsafe-entry-name") + !names.add(safeEntry) -> Record(safeEntry, candidate.origin, "omitted", reason = "duplicate-entry") + else -> addCandidate(archive, candidate.copy(entry = safeEntry), stage, budget, limits) + } + records += record + completed++ + onProgress?.invoke((completed.toFloat() / totalCandidates).coerceIn(0f, 1f)) + } + if (category == Category.SESSION) addTrustedActivation(context, folder, archive)?.let(records::add) + if (selected.isEmpty()) records += Record("", category.suffix, "unavailable", reason = "no-matching-artifacts") + if (discovery.truncated) records += Record("", "discovery", "truncated", reason = "candidate-limit") + addManifest( + archive, folder.name, category.suffix, records, limits, budget.limit, redactionLearningComplete, + ) + } + zip + } + } finally { + stage.deleteRecursively() + } + } + + fun createLegacy( + context: Context, + folder: File, + onProgress: ((Float) -> Unit)? = null, + limits: EnhancedShareLimits = EnhancedShareLimits(maxFilesPerArchive = 512), + ): File? { + if (!folder.isDirectory || Files.isSymbolicLink(folder.toPath()) || + limits.maxFilesPerArchive < 1 || limits.maxBytesPerFile < 1 || limits.maxBytesTotal < 1) { + return null + } + val out = SessionLogShare.shareDir(context).apply { deleteRecursively(); mkdirs() } + val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) + val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = true) + val candidates = discovery.candidates.filter { it.linePrefix == null } + if (candidates.isEmpty()) { + out.deleteRecursively() + return null + } + val stage = File(out, ".diagnostic-stage").apply { mkdirs() } + val records = ArrayList<Record>() + val budget = Budget(limits.maxBytesTotal) + val zip = File(out, "DroidDeck-${folder.name}.zip") + return try { + ZipOutputStream(zip.outputStream().buffered()).use { archive -> + val names = HashSet<String>() + candidates.forEachIndexed { index, candidate -> + val safeEntry = safeEntry(candidate.entry) + records += when { + index >= limits.maxFilesPerArchive -> Record( + safeEntry ?: "<invalid>", candidate.origin, "omitted", reason = "file-count-limit", + ) + safeEntry == null -> Record("<invalid>", candidate.origin, "omitted", reason = "unsafe-entry-name") + !names.add(safeEntry) -> Record(safeEntry, candidate.origin, "omitted", reason = "duplicate-entry") + else -> addCandidate(archive, candidate.copy(entry = safeEntry), stage, budget, limits) + } + onProgress?.invoke((index + 1f) / candidates.size) + } + addTrustedActivation(context, folder, archive)?.let(records::add) + if (discovery.truncated) records += Record("", "discovery", "truncated", reason = "candidate-limit") + addManifest(archive, folder.name, "all", records, limits, budget.limit, redactionLearningComplete) + } + zip + } finally { + stage.deleteRecursively() + } + } + + private fun addTrustedActivation( + context: Context, + folder: File, + archive: ZipOutputStream, + ): Record? { + val manifest = EnhancedDiagnostics.manifest(context, folder) ?: return null + val bytes = (manifest.toString(2) + "\n").toByteArray() + val entry = "${folder.name}/${EnhancedDiagnostics.MANIFEST_FILE}" + archive.putNextEntry(ZipEntry(entry)) + archive.write(bytes) + archive.closeEntry() + return Record(entry, "app-private-activation-state", "captured", bytes.size.toLong(), bytes.size.toLong()) + } + + private fun addCandidate( + archive: ZipOutputStream, + candidate: Candidate, + stage: File, + budget: Budget, + limits: EnhancedShareLimits, + ): Record { + if (budget.remaining <= 0) { + return Record(candidate.entry, candidate.origin, "omitted", reason = "bundle-byte-limit") + } + val snapshot = runCatching { + snapshot(candidate, stage, minOf(limits.maxBytesPerFile, budget.remaining)) + }.getOrElse { + return Record(candidate.entry, candidate.origin, "error", reason = it.javaClass.simpleName) + } ?: return Record(candidate.entry, candidate.origin, "omitted", reason = "unsafe-or-unavailable-source") + if (snapshot.file.length() == 0L && candidate.linePrefix != null) { + snapshot.file.delete() + return Record(candidate.entry, candidate.origin, "unavailable", snapshot.sourceBytes, reason = "no-matching-lines") + } + return try { + budget.remaining -= snapshot.file.length() + archive.putNextEntry(ZipEntry(candidate.entry)) + val writer = archive.bufferedWriter() + LogRedactor.scrubForShare(snapshot.file, writer) + writer.flush() + archive.closeEntry() + Record( + candidate.entry, + candidate.origin, + if (snapshot.truncated) "truncated" else "captured", + snapshot.sourceBytes, + snapshot.file.length(), + if (snapshot.truncated) "per-file-or-bundle-byte-limit" else null, + ) + } finally { + snapshot.file.delete() + } + } + + private fun snapshot(candidate: Candidate, stage: File, limit: Long): Snapshot? { + val rootPath = candidate.anchor.toPath().toAbsolutePath().normalize() + val sourcePath = candidate.file.toPath().toAbsolutePath().normalize() + if (!sourcePath.startsWith(rootPath) || sourcePath == rootPath || limit < 1) return null + val target = File.createTempFile("diagnostic-", ".log", stage) + try { + val relative = rootPath.relativize(sourcePath) + return withSecureChannel(rootPath, relative) { input -> + val size = input.size() + candidate.linePrefix?.let { prefix -> + val truncated = filterChannel(input, target, prefix, size, TRACE_SCAN_BYTES, limit) + return@withSecureChannel Snapshot(target, size, truncated) + } + FileOutputStream(target).channel.use { output -> + if (size <= limit) { + copy(input, output, 0, size) + } else { + val marker = "\n<diagnostic file truncated: beginning and tail retained>\n".toByteArray() + val content = (limit - marker.size).coerceAtLeast(0) + copyCompleteHead(input, output, content / 2) + val markerBytes = minOf(marker.size.toLong(), limit - output.position()).toInt() + output.write(ByteBuffer.wrap(marker, 0, markerBytes)) + copyCompleteTail(input, output, size, (limit - output.position()).coerceAtLeast(0)) + } + output.force(false) + } + Snapshot(target, size, size > limit) + } ?: target.delete().let { null } + } catch (e: Exception) { + target.delete() + throw e + } + } + + private fun filterChannel( + channel: SeekableByteChannel, + target: File, + prefix: String, + sourceSize: Long, + scanLimit: Long, + outputLimit: Long, + ): Boolean { + val wanted = prefix.toByteArray() + var written = 0L + var truncated = sourceSize > scanLimit + target.outputStream().buffered().use { output -> + fun scan(start: Long, count: Long, discardPartialFirstLine: Boolean) { + channel.position(start) + val input = Channels.newInputStream(channel) + val line = ByteArrayOutputStream(1024) + var oversized = false + var scanned = 0L + var discard = discardPartialFirstLine + fun emit() { + val bytes = line.toByteArray() + if (!discard && !oversized && bytes.size >= wanted.size && wanted.indices.all { bytes[it] == wanted[it] }) { + if (written + bytes.size + 1 <= outputLimit) { + output.write(bytes) + output.write('\n'.code) + written += bytes.size + 1 + } else truncated = true + } + line.reset() + oversized = false + discard = false + } + while (scanned < count) { + val value = input.read() + if (value < 0) break + scanned++ + if (value == '\n'.code) emit() + else if (!oversized && !discard) { + if (line.size() >= LogRedactor.MAX_LINE_LENGTH) { + oversized = true + line.reset() + } else line.write(value) + } + } + if (start + scanned >= sourceSize && (line.size() > 0 || oversized)) emit() + } + if (sourceSize <= scanLimit) { + scan(0, sourceSize, false) + } else { + val head = scanLimit / 2 + val tail = scanLimit - head + scan(0, head, false) + scan((sourceSize - tail).coerceAtLeast(0), tail, true) + } + } + return truncated + } + + private fun <T> withSecureChannel(root: Path, relative: Path, block: (SeekableByteChannel) -> T): T? { + val opened = ArrayList<ParcelFileDescriptor>() + return try { + val parts = relative.map { it.toString() } + if (parts.isEmpty()) return null + val rootFd = openDescriptor(root.toString()) ?: return null + if (!OsConstants.S_ISDIR(Os.fstat(rootFd).st_mode)) { + Os.close(rootFd) + return null + } + opened += duplicateAndClose(rootFd) + for (part in parts.dropLast(1)) { + val childFd = openDescriptor(procChild(opened.last(), part)) ?: return null + if (!OsConstants.S_ISDIR(Os.fstat(childFd).st_mode)) { + Os.close(childFd) + return null + } + opened += duplicateAndClose(childFd) + } + val leafFd = openDescriptor(procChild(opened.last(), parts.last())) ?: return null + val stat = Os.fstat(leafFd) + if (!OsConstants.S_ISREG(stat.st_mode) || stat.st_nlink != 1L) { + Os.close(leafFd) + return null + } + val stream = try { + FileInputStream(leafFd) + } catch (error: Exception) { + Os.close(leafFd) + throw error + } + stream.use { block(it.channel) } + } catch (_: Exception) { + null + } finally { + opened.asReversed().forEach { runCatching { it.close() } } + } + } + + private fun openDescriptor(path: String): java.io.FileDescriptor? = runCatching { + Os.open( + path, + OsConstants.O_RDONLY or OsConstants.O_CLOEXEC or OsConstants.O_NOFOLLOW or OsConstants.O_NONBLOCK, + 0, + ) + }.getOrNull() + + private fun duplicateAndClose(fd: java.io.FileDescriptor): ParcelFileDescriptor = + try { + ParcelFileDescriptor.dup(fd) + } finally { + Os.close(fd) + } + + private fun procChild(directory: ParcelFileDescriptor, name: String): String = + "/proc/self/fd/${directory.fd}/$name" + + private fun copy(input: SeekableByteChannel, output: FileChannel, start: Long, count: Long) { + input.position(start) + var left = count + val buffer = ByteBuffer.allocate(64 * 1024) + while (left > 0) { + buffer.clear() + buffer.limit(minOf(buffer.capacity().toLong(), left).toInt()) + val read = input.read(buffer) + if (read < 0) break + buffer.flip() + while (buffer.hasRemaining()) output.write(buffer) + left -= read + } + } + + private fun copyCompleteHead(input: SeekableByteChannel, output: FileChannel, limit: Long) { + if (limit <= 0) return + copy(input, output, 0, limit) + val copied = output.position() + input.position(0) + val buffer = ByteBuffer.allocate(64 * 1024) + var scanned = 0L + var lastComplete = 0L + while (scanned < copied) { + buffer.clear() + buffer.limit(minOf(buffer.capacity().toLong(), copied - scanned).toInt()) + val read = input.read(buffer) + if (read < 0) break + buffer.flip() + repeat(read) { index -> + if (buffer.get(index) == '\n'.code.toByte()) lastComplete = scanned + index + 1 + } + scanned += read + } + output.truncate(lastComplete) + output.position(lastComplete) + } + + private fun copyCompleteTail( + input: SeekableByteChannel, + output: FileChannel, + sourceSize: Long, + limit: Long, + ) { + if (limit <= 0 || sourceSize <= 0) return + var start = (sourceSize - limit).coerceAtLeast(0) + if (start > 0) { + input.position(start) + val one = ByteBuffer.allocate(1) + while (start < sourceSize) { + one.clear() + if (input.read(one) < 0) return + start++ + one.flip() + if (one.get() == '\n'.code.toByte()) break + } + } + copy(input, output, start, (sourceSize - start).coerceAtMost(limit)) + } + + private fun addManifest( + archive: ZipOutputStream, + sessionId: String, + category: String, + records: List<Record>, + limits: EnhancedShareLimits, + categoryBudget: Long, + redactionLearningComplete: Boolean, + ) { + val entries = JSONArray() + records.take(MAX_MANIFEST_RECORDS).forEach { record -> + entries.put(JSONObject().apply { + put("entry", record.entry) + put("origin", record.origin) + put("status", record.status) + put("sourceBytes", record.sourceBytes) + put("capturedBytes", record.capturedBytes) + record.reason?.let { put("reason", it) } + }) + } + if (records.size > MAX_MANIFEST_RECORDS) { + entries.put(JSONObject().apply { + put("entry", "") + put("origin", "manifest") + put("status", "omitted") + put("reason", "${records.size - MAX_MANIFEST_RECORDS} additional records") + }) + } + val manifest = JSONObject().apply { + put("schema", 1) + put("sessionId", sessionId) + put("category", category) + put("generatedAtMillis", System.currentTimeMillis()) + put("redactionLearning", if (redactionLearningComplete) "complete" else "incomplete") + put("limits", JSONObject().apply { + put("maxFilesPerArchive", limits.maxFilesPerArchive) + put("maxDiscoveredFiles", limits.maxDiscoveredFiles) + put("maxBytesPerFile", limits.maxBytesPerFile) + put("budgetBasis", "raw-input-snapshot-bytes") + put("maxRawInputBytesTotal", limits.maxBytesTotal) + put("categoryRawInputBudgetBytes", categoryBudget) + }) + put("entries", entries) + }.toString(2) + "\n" + archive.putNextEntry(ZipEntry("diagnostics-manifest.json")) + archive.write(manifest.toByteArray()) + archive.closeEntry() + } + + private fun collect(context: Context, folder: File, maxFiles: Int, legacy: Boolean): CollectionResult { + val out = LinkedHashMap<String, Candidate>() + val categoryCounts = HashMap<Category, Int>() + val perCategory = (maxFiles / Category.values().size).coerceAtLeast(1) + var truncated = false + fun add( + file: File, + root: File, + entry: String, + origin: String, + forcedCategory: Category? = null, + linePrefix: String? = null, + ) { + val safe = safeEntry(entry) ?: return + val category = forcedCategory ?: category(entry) + if (out.size >= maxFiles || (categoryCounts[category] ?: 0) >= perCategory) { + truncated = true + return + } + val anchor = anchorFor(context, root) + if (out.putIfAbsent(safe, Candidate(file, anchor, safe, origin, category, linePrefix)) == null) { + categoryCounts[category] = (categoryCounts[category] ?: 0) + 1 + } + } + CRITICAL_SESSION_FILES.forEach { name -> + File(folder, name).takeIf { it.exists() }?.let { add(it, folder, "${folder.name}/$name", "session-critical") } + } + File(folder, "session.log").takeIf { it.exists() }?.let { file -> + add( + file, folder, "${folder.name}/graphics/frame-trace.log", "guest-frame-trace", + Category.GRAPHICS, "DROIDDECK_FRAME_TRACE ", + ) + add( + file, folder, "${folder.name}/graphics/process-trace.log", "guest-process-trace", + Category.GRAPHICS, "DROIDDECK_PROCESS_TRACE ", + ) + add( + file, folder, "${folder.name}/games/game-lifecycle.log", "guest-game-lifecycle", + Category.GAMES, "DROIDDECK_DIAGNOSTICS event=game_", + ) + } + if (SessionPaths.current()?.canonicalFile == folder.canonicalFile && !File(folder, "steam").exists()) { + val steam = File(SessionPrefs.activeSteamRoot(context), "logs") + val scan = directFiles(steam, remaining(maxFiles, out.size)) + truncated = truncated || scan.truncated + scan.files.forEach { + add(it, steam, "${folder.name}/steam/${it.name}", "live-steam") + } + } + val logs = LinuxRuntime.logDir(context) + for ((name, root) in listOf(SessionLogShare.STORES_DIR to File(logs, SessionLogShare.STORES_DIR), SessionPaths.TOOLS_DIR to File(logs, SessionPaths.TOOLS_DIR))) { + val scan = directFiles(root, remaining(maxFiles, out.size)) + truncated = truncated || scan.truncated + scan.files.asSequence().filter { recent(it) } + .forEach { add(it, root, "$name/${it.name}", name) } + } + if (legacy) { + legacyBattleNet(context).forEach { source -> + add(source.file, source.root, source.entry, "battlenet") + } + } else { + battleNetRoots(context).forEach { (prefix, root) -> + val scan = walk(root, remaining(maxFiles, out.size)) + truncated = truncated || scan.truncated + scan.files.asSequence().filter { recent(it) && it.name.endsWith(".log", true) } + .forEach { file -> + val relative = root.toPath().toAbsolutePath().normalize().relativize(file.toPath().toAbsolutePath().normalize()).joinToString("/") + add(file, root, "battlenet/$prefix/$relative", "battlenet") + } + } + } + val sessionScan = walk(folder, remaining(maxFiles, out.size)) + truncated = truncated || sessionScan.truncated + sessionScan.files.forEach { file -> + val relative = file.toPath().toAbsolutePath().normalize() + .let { folder.toPath().toAbsolutePath().normalize().relativize(it).joinToString("/") } + if (relative == EnhancedDiagnostics.MANIFEST_FILE) return@forEach + add(file, folder, "${folder.name}/$relative", "session") + } + return CollectionResult(out.values.toList(), truncated) + } + + private fun remaining(maxFiles: Int, found: Int): Int = (maxFiles - found + 1).coerceAtLeast(0) + + private fun walk(root: File, limit: Int): ScanResult { + if (limit <= 0 || !root.isDirectory || Files.isSymbolicLink(root.toPath())) return ScanResult(emptyList(), false) + val files = ArrayList<File>(limit) + var truncated = false + Files.walk(root.toPath()).use { paths -> + val iterator = paths.iterator() + var visited = 0 + val visitLimit = (limit * 4).coerceAtLeast(limit).coerceAtMost(MAX_DISCOVERY_VISITS) + while (iterator.hasNext() && files.size < limit && visited < visitLimit) { + val path = iterator.next() + visited++ + if (path != root.toPath() && + (Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS) || Files.isSymbolicLink(path))) { + files += path.toFile() + } + } + truncated = iterator.hasNext() + } + return ScanResult(files, truncated) + } + + private fun directFiles(root: File, limit: Int): ScanResult { + if (limit <= 0 || !root.isDirectory || Files.isSymbolicLink(root.toPath())) return ScanResult(emptyList(), false) + val files = ArrayList<File>(limit) + var truncated = false + Files.newDirectoryStream(root.toPath()).use { entries -> + val iterator = entries.iterator() + while (iterator.hasNext() && files.size < limit) { + val path = iterator.next() + if (Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS) || Files.isSymbolicLink(path)) { + files += path.toFile() + } + } + truncated = iterator.hasNext() + } + return ScanResult(files, truncated) + } + + private fun battleNetRoots(context: Context): List<Pair<String, File>> { + val drive = File(BattleNet.prefix(context), "pfx/drive_c") + val data = File(drive, "ProgramData/Battle.net") + return listOf( + "droiddeck" to File(LinuxRuntime.rootDir(context), "root/.cache/droiddeck/battlenet"), + "client" to File(drive, "users/steamuser/AppData/Local/Battle.net/Logs"), + "agent" to File(data, "Agent"), + "setup" to File(data, "Setup"), + ) + } + + private fun legacyBattleNet(context: Context): List<LegacySource> { + val drive = File(BattleNet.prefix(context), "pfx/drive_c") + val data = File(drive, "ProgramData/Battle.net") + val agent = File(data, "Agent") + val setup = File(data, "Setup") + return legacyNewest( + "droiddeck", + listOf(File(LinuxRuntime.rootDir(context), "root/.cache/droiddeck/battlenet")), + 2, + setOf("battlenet.log", "spawned.log"), + ) + legacyNewest( + "client", listOf(File(drive, "users/steamuser/AppData/Local/Battle.net/Logs")), 6, + ) + legacyNewest( + "agent", + listOf(File(agent, "Logs")) + childDirectories(agent, "Agent.").map { File(it, "Logs") }, + 10, + byDir = true, + ) + legacyNewest( + "setup", childDirectories(setup, "").map { File(it, "Logs") }, 3, byDir = true, + ) + } + + private fun legacyNewest( + folder: String, + roots: List<File>, + count: Int, + names: Set<String>? = null, + byDir: Boolean = false, + ): List<LegacySource> = roots.flatMap { root -> + directFiles(root, MAX_BATTLENET_SCAN).files.asSequence() + .filter { recent(it) && it.name.endsWith(".log") && it.length() <= LEGACY_LOG_MAX_BYTES } + .filter { names == null || it.name in names } + .map { it to root } + .toList() + }.sortedByDescending { it.first.lastModified() }.take(count).map { (file, root) -> + val relative = if (byDir) "$folder/${file.parentFile?.parentFile?.name}/${file.name}" else "$folder/${file.name}" + LegacySource(file, root, "battlenet/$relative") + } + + private fun childDirectories(root: File, prefix: String): List<File> { + if (!root.isDirectory || Files.isSymbolicLink(root.toPath())) return emptyList() + val found = ArrayList<File>() + Files.newDirectoryStream(root.toPath()).use { entries -> + val iterator = entries.iterator() + while (iterator.hasNext() && found.size < MAX_BATTLENET_DIRECTORIES) { + val path = iterator.next() + if (path.fileName.toString().startsWith(prefix) && + Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS) && !Files.isSymbolicLink(path)) found += path.toFile() + } + } + return found + } + + private fun recent(file: File): Boolean = file.lastModified() >= System.currentTimeMillis() - RECENT_MILLIS + + private fun anchorFor(context: Context, root: File): File { + val path = root.toPath().toAbsolutePath().normalize() + for (anchor in listOf(context.filesDir, context.cacheDir)) { + if (path.startsWith(anchor.toPath().toAbsolutePath().normalize())) return anchor + } + return root.parentFile ?: root + } + + private fun safeEntry(name: String): String? { + if (name.any { it.code < 0x20 || it.code == 0x7f }) return null + val normalized = name.replace('\\', '/').trimStart('/') + val parts = normalized.split('/') + if (normalized.isEmpty() || parts.any { it.isEmpty() || it == "." || it == ".." }) return null + return parts.joinToString("/") { safeComponent(it) } + } + + private fun safeComponent(value: String): String { + if (value in KNOWN_COMPONENTS || KNOWN_COMPONENT_PATTERNS.any { it.matches(value) }) return value + val suffix = SAFE_SUFFIX.find(value)?.value.orEmpty().lowercase(Locale.US) + val digest = MessageDigest.getInstance("SHA-256").digest(value.toByteArray()) + .take(8).joinToString("") { "%02x".format(Locale.US, it.toInt() and 0xff) } + return "entry-$digest$suffix" + } + + private fun category(entry: String): Category { + val value = entry.lowercase(Locale.US) + if (value.startsWith("battlenet/") || value.startsWith("stores/") || value.startsWith("tools/") || + value.contains("droiddeck-esync/") || GAME_LOG.matches(value.substringAfterLast('/')) || + listOf("proton", "wine", "dxvk", "vkd3d", "battle.net", "game-debug").any(value::contains)) return Category.GAMES + if (listOf("wayland", "gamescope", "xwayland", "vulkan", "gpu", "mesa", "egl", "glx", "drm", "compositor", "frame-trace").any(value::contains)) return Category.GRAPHICS + return Category.SESSION + } + + private val GAME_LOG = Regex("steam-[0-9]+\\.(log|txt)") + private val KNOWN_COMPONENTS = setOf( + "steam", "graphics", "games", "battlenet", "client", "agent", "setup", "stores", "tools", + "droiddeck", "droiddeck-esync", "session.log", "app.log", "wayland.log", "audio.log", + "device.txt", "network.txt", "events.jsonl", "memory.csv", "capture.json", "crash.log", + "frame-trace.log", "process-trace.log", "game-lifecycle.log", "launches.log", "tools.tsv", "wanted.tsv", "prefixes.json", + "battlenet.log", "spawned.log", "flatpak-install.log", "cef_log.txt", "cef_log.previous.txt", + "console_log.txt", "webhelper_js.txt", "controller_support.txt", "systemperfmanager.txt", + ) + private val KNOWN_COMPONENT_PATTERNS = listOf( + Regex("[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2,}-[a-z0-9-]{1,24}"), + Regex("steam-[0-9]+\\.(?:log|txt)"), + Regex("(?:battle\\.net-[0-9]+|battle\\.net-setup-[0-9]+|Agent-[0-9]+)\\.log"), + Regex("(?:Agent\\.[0-9]+|bna_[0-9]+)"), + Regex("stores-[0-9]{4}-[0-9]{2}-[0-9]{2}\\.log"), + Regex("entry-[0-9a-f]{16}(?:\\.[a-z0-9]{1,8})?"), + ) + private val SAFE_SUFFIX = Regex("\\.[A-Za-z0-9]{1,8}$") + private val CRITICAL_SESSION_FILES = listOf( + "session.log", "app.log", "wayland.log", "audio.log", "device.txt", "network.txt", + "events.jsonl", "memory.csv", "capture.json", "crash.log", + ) + private const val RECENT_MILLIS = 7L * 24 * 60 * 60 * 1000 + private const val TRACE_SCAN_BYTES = 16L * 1024 * 1024 + private const val LEGACY_LOG_MAX_BYTES = 8L * 1024 * 1024 + private const val MAX_BATTLENET_SCAN = 64 + private const val MAX_BATTLENET_DIRECTORIES = 64 + private const val MAX_MANIFEST_RECORDS = 512 + private const val MAX_DISCOVERY_VISITS = 4096 +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt index 27882ebcf1..2a19f39abc 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt @@ -117,8 +117,7 @@ object GameEnvironmentStore { if (gameDxvk.length() > 0) json.put(DXVK_CONFIG_GAMES, gameDxvk) json.put( GAME_DEBUG_LOGS, - gameDebugLogsOverride ?: (SessionPrefs.logsEnabled(context) && - SessionPrefs.gameDebugLogsEnabled(context) && SessionPaths.currentSessionLogsRetained(context)), + gameDebugLogsOverride ?: SessionPrefs.gameDebugLogsEffective(context), ) write(File(LinuxRuntime.rootDir(context), GUEST_FILE), json.toString()) } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index a947bf7e1f..ca9cafcabf 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -40,6 +40,7 @@ object SessionFiles { WinComponents.publish(context) val files = arrayOf( "usr/local/bin/droiddeck-game-env" to "usr/local/bin/droiddeck-game-env", + "usr/local/bin/droiddeck-diagnostic-inventory" to "usr/local/bin/droiddeck-diagnostic-inventory", "usr/local/bin/droiddeck-wincomponents" to "usr/local/bin/droiddeck-wincomponents", "usr/local/bin/droiddeck-msi-install" to "usr/local/bin/droiddeck-msi-install", "usr/local/bin/droiddeck-esync" to "usr/local/bin/droiddeck-esync", diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt index 4cf737c04c..67806c4284 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt @@ -11,12 +11,8 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.core.content.FileProvider import com.droiddeck.launcher.R -import com.droiddeck.launcher.core.LogRedactor -import com.droiddeck.launcher.runtime.BattleNet -import com.droiddeck.launcher.runtime.LinuxRuntime import java.io.File -import java.util.zip.ZipEntry -import java.util.zip.ZipOutputStream +import java.util.ArrayList object SessionLogShare { data class Details(val sizeBytes: Long, val modifiedAt: Long) @@ -62,84 +58,30 @@ object SessionLogShare { return knownSession && folder.isDirectory && folder.deleteRecursively() } + fun prepareEnhanced(context: Context, folder: () -> File?, done: (List<File>) -> Unit) { + if (progress != null) return + progress = 0f + Thread({ + val zips = runCatching { + folder()?.let { dir -> + EnhancedSessionLogShare.create(context, dir, onProgress = { p -> + main.post { if (progress != null) progress = p } + }) + }.orEmpty() + }.onFailure { Log.w("SessionLogShare", "could not package enhanced diagnostics", it) } + .getOrDefault(emptyList()) + main.post { progress = null; done(zips) } + }, "share-diagnostics").start() + } + fun zipFolder(context: Context, folder: File, onProgress: ((Float) -> Unit)? = null): File? { - if (!folder.isDirectory) return null - val files = folder.walkTopDown().filter { it.isFile } - .filterNot { it.parentFile?.name == "steam" && it.length() > STEAM_LOG_MAX_BYTES }.toList() - if (files.isEmpty()) return null - val out = shareDir(context).apply { deleteRecursively(); mkdirs() } - val zip = File(out, "DroidDeck-${folder.name}.zip") - LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) - val live = liveSteamLogs(context, folder) - val logs = LinuxRuntime.logDir(context) - val stores = recent(File(logs, STORES_DIR)) - val tools = recent(File(logs, SessionPaths.TOOLS_DIR)) - val battleNet = battleNetLogs(context) - val total = (files + live + stores + tools + battleNet.map { it.second }).sumOf { it.length() }.coerceAtLeast(1L) - var done = 0L - var shown = -1 - fun advance(f: File) { - done += f.length() - val percent = (done * 100 / total).toInt() - if (percent != shown) { shown = percent; onProgress?.invoke(percent / 100f) } - } - ZipOutputStream(zip.outputStream().buffered()).use { z -> - files.forEach { f -> addEntry(z, folder.name + "/" + f.relativeTo(folder).invariantSeparatorsPath, f); advance(f) } - live.forEach { f -> addEntry(z, folder.name + "/steam/" + f.name, f); advance(f) } - stores.forEach { f -> addEntry(z, "$STORES_DIR/" + f.name, f); advance(f) } - tools.forEach { f -> addEntry(z, SessionPaths.TOOLS_DIR + "/" + f.name, f); advance(f) } - battleNet.forEach { (name, f) -> addEntry(z, "$BATTLENET_DIR/$name", f); advance(f) } - } - return zip + return EnhancedSessionLogShare.createLegacy(context, folder, onProgress) } - private fun addEntry(z: ZipOutputStream, name: String, f: File) { - z.putNextEntry(ZipEntry(name)) - val w = z.bufferedWriter() - LogRedactor.scrubForShare(f, w) - w.flush() - z.closeEntry() - } - - private fun liveSteamLogs(context: Context, folder: File): List<File> { - if (folder != SessionPaths.current() || File(folder, "steam").exists()) return emptyList() - val logs = File(SessionPrefs.activeSteamRoot(context), "logs") - return logs.listFiles()?.filter { it.isFile && it.length() <= STEAM_LOG_MAX_BYTES }.orEmpty() - } - - private const val STEAM_LOG_MAX_BYTES = 8L * 1024 * 1024 - const val STORES_DIR = "stores" - private const val RECENT_DAYS = 7 - private fun shareDir(context: Context): File = File(context.cacheDir, "share") - - private const val BATTLENET_DIR = "battlenet" - - private fun battleNetLogs(context: Context): List<Pair<String, File>> { - val drive = File(BattleNet.prefix(context), "pfx/drive_c") - val data = File(drive, "ProgramData/Battle.net") - fun logsUnder(dir: File, prefix: String) = dir.listFiles { f -> f.isDirectory && f.name.startsWith(prefix) }.orEmpty().map { File(it, "Logs") } - return newest("droiddeck", listOf(File(LinuxRuntime.rootDir(context), "root/.cache/droiddeck/battlenet")), 2, setOf("battlenet.log", "spawned.log")) + - newest("client", listOf(File(drive, "users/steamuser/AppData/Local/Battle.net/Logs")), 6) + - newest("agent", listOf(File(data, "Agent/Logs")) + logsUnder(File(data, "Agent"), "Agent."), 10, byDir = true) + - newest("setup", logsUnder(File(data, "Setup"), ""), 3, byDir = true) - } - - private fun newest(folder: String, dirs: List<File>, count: Int, names: Set<String>? = null, byDir: Boolean = false): List<Pair<String, File>> { - val since = System.currentTimeMillis() - RECENT_DAYS * 86_400_000L - return dirs.flatMap { dir -> - dir.listFiles { f -> f.isFile && f.name.endsWith(".log") && (names == null || f.name in names) && f.lastModified() >= since && f.length() <= STEAM_LOG_MAX_BYTES }.orEmpty().toList() - }.sortedByDescending { it.lastModified() }.take(count).map { f -> - (if (byDir) "$folder/${f.parentFile?.parentFile?.name}/${f.name}" else "$folder/${f.name}") to f - } - } - - private fun recent(dir: File): List<File> { - val since = System.currentTimeMillis() - RECENT_DAYS * 86_400_000L - return dir.listFiles { f -> f.isFile && f.lastModified() >= since }?.sortedBy { it.name }.orEmpty() - } + internal fun shareDir(context: Context): File = File(context.cacheDir, "share") fun clear(context: Context) { shareDir(context).deleteRecursively() @@ -156,4 +98,19 @@ object SessionLogShare { send.clipData = ClipData.newRawUri(zip.name, uri) return Intent.createChooser(send, context.getString(R.string.logshare_chooser)).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) } + + fun shareEnhancedIntent(context: Context, zips: List<File>): Intent { + require(zips.isNotEmpty()) + val uris = ArrayList(zips.map { FileProvider.getUriForFile(context, context.packageName + ".logs", it) }) + val send = Intent(Intent.ACTION_SEND_MULTIPLE) + .setType("application/zip") + .putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris) + .putExtra(Intent.EXTRA_SUBJECT, zips.first().name.substringBeforeLast('-')) + .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + send.clipData = ClipData.newUri(context.contentResolver, zips.first().name, uris.first()).also { clip -> + for (i in 1 until uris.size) clip.addItem(ClipData.Item(uris[i])) + } + return Intent.createChooser(send, context.getString(R.string.logshare_chooser)) + .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + } } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt index 6f335f231c..524271d4a9 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt @@ -26,7 +26,8 @@ object SessionPaths { @Synchronized fun beginOrCurrent(context: Context, label: String? = null): File { dir?.let { if (it.isDirectory) return it } - val parent = if (SessionPrefs.logsEnabled(context)) SessionFiles.logDirectory(context) + val enhanced = EnhancedDiagnostics.isArmed(context) + val parent = if (SessionPrefs.logsEnabled(context) || enhanced) SessionFiles.logDirectory(context) else File(context.cacheDir, "session-logs") val day = SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date()) val last = parent.listFiles()?.mapNotNull { f -> @@ -36,9 +37,13 @@ object SessionPaths { var number = last + 1 var made = File(parent, "$day-${"%02d".format(Locale.US, number)}-$what") while (made.exists()) made = File(parent, "$day-${"%02d".format(Locale.US, ++number)}-$what") + EnhancedDiagnostics.clearRecordFor(context, made) if (!made.isDirectory && !made.mkdirs()) Log.e(TAG, "could not create $made") dir = made - Log.i(TAG, "session logs: $made" + if (SessionPrefs.logsEnabled(context)) "" else " (logs off: discarded at the end)") + if (enhanced && !EnhancedDiagnostics.consumeInto(context, made)) { + Log.e(TAG, "could not activate enhanced diagnostics for $made") + } + Log.i(TAG, "session logs: $made" + if (parent == SessionFiles.logDirectory(context)) "" else " (logs off: discarded at the end)") return made } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 48bdeffdef..2e7f3b6c54 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -824,7 +824,7 @@ object SessionPrefs { key = "logs", oldValue = logsEnabled(context), newValue = on, - newEffective = on && gameDebugLogsEnabled(context) && SessionPaths.currentSessionLogsRetained(context), + newEffective = gameDebugLogsEffective(context, on, gameDebugLogsEnabled(context)), ) } @@ -837,7 +837,7 @@ object SessionPrefs { key = "gameDebugLogsEnabled", oldValue = gameDebugLogsEnabled(context), newValue = on, - newEffective = logsEnabled(context) && on && SessionPaths.currentSessionLogsRetained(context), + newEffective = gameDebugLogsEffective(context, logsEnabled(context), on), ) } @@ -850,8 +850,7 @@ object SessionPrefs { ): Boolean { if (oldValue == newValue) return true val saved = prefs(context) - val oldEffective = logsEnabled(context) && gameDebugLogsEnabled(context) && - SessionPaths.currentSessionLogsRetained(context) + val oldEffective = gameDebugLogsEffective(context) fun publish(value: Boolean) = GameEnvironmentStore.publish(context, gameDebugLogsOverride = value) if (oldEffective == newEffective) { if (saved.edit().putBoolean(key, newValue).commit()) return true @@ -887,6 +886,13 @@ object SessionPrefs { } } + internal fun gameDebugLogsEffective( + context: Context, + logs: Boolean = logsEnabled(context), + gameLogs: Boolean = gameDebugLogsEnabled(context), + ): Boolean = EnhancedDiagnostics.isCurrentSessionActive(context) || + (logs && gameLogs && SessionPaths.currentSessionLogsRetained(context)) + fun battleNetNoSteamSet(context: Context): Boolean = prefs(context).getBoolean("battleNetNoSteamSet", false) fun setBattleNetNoSteamSet(context: Context) { prefs(context).edit().putBoolean("battleNetNoSteamSet", true).apply() } 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 12c848d1cb..29234f1d38 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -540,6 +540,7 @@ class SessionService : Service() { guest.add("BL_REFRESH=" + Math.round(SessionState.refreshHz)) guest.add("BL_LOG=" + sessionLog.path) guest.add("BL_DEBUG_DIR=" + sessionDir.path) + if (EnhancedDiagnostics.isActive(this, sessionDir)) guest.add("DROIDDECK_ENHANCED_DIAGNOSTICS=1") val fakeInputDir = File(sessionRoot, "dev/input").apply { mkdirs() } val controllersOn = !File(Environment.getExternalStorageDirectory(), NO_PAD_SWITCH).exists() @@ -768,6 +769,7 @@ class SessionService : Service() { SessionState.sessionId = sessionDir.name SessionState.eventsFile = File(sessionDir, "events.jsonl") SessionEvents.record("session.logs_ready", mapOf("logDir" to sessionDir.path)) + if (EnhancedDiagnostics.isActive(this, sessionDir)) SessionEvents.record("diagnostics.enhanced", mapOf("schema" to 1)) DeviceReport.write(this, File(sessionDir, "device.txt"), SessionState.mode) NetworkReport.write(this, File(sessionDir, "network.txt")) SessionLogCapture.start(File(sessionDir, "app.log")) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt index c47bdd7986..f315c1e1a6 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt @@ -22,7 +22,7 @@ object SettingsReset { "tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "ramCapMb", "vramCapMb", "zramClient", "directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus", "noXalia", "fastSync", "fsyncFirst", "syncFallback", "prootNoSeccomp", "prootFastPath", "cursorComposite", - "guestHostname", "fexPreset", "forceSsbs", "logs", "gameDebugLogsEnabled", "storageDiagnostics", + "guestHostname", "fexPreset", "forceSsbs", "logs", "gameDebugLogsEnabled", "enhancedDiagnosticsNext", "storageDiagnostics", "upscaler", "upscaleSharpness", "screenEffects", "textureAnisotropy", "textureLodBias", "steamDownloadsInBackground", "steam_offline", "bootMovie", "bootMovieSound", "bootMovieVolume", "bootMovieSeconds", "bootMovieApplyNext", "bootMovieSteamSeen", diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 44f629b348..5881ad715d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -102,6 +102,7 @@ class FrontEndState( val frameGenLabel: String, val romsDir: String?, val logsEnabled: Boolean, + val enhancedDiagnosticsArmed: Boolean = false, val gameDebugLogsEnabled: Boolean = false, val gameDebugLogsNeedsRestart: Boolean = false, val vacDiagnostics: Boolean = false, @@ -227,6 +228,7 @@ class FrontEndActions( val onFiles: () -> Unit, val onBrowseFiles: (File) -> Unit = {}, val onLogs: () -> Unit, + val onEnhancedDiagnostics: () -> Unit = {}, val onGameDebugLogs: () -> Unit = {}, val onVacDiagnostics: () -> Unit = {}, val onAgentCommands: () -> Unit = {}, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 795b1b1c1c..830b68ef35 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -546,6 +546,10 @@ internal fun SetupPanel( 5 -> { SettingsGroup(stringResource(R.string.setup_tab_diagnostics)) { ToggleRow(host, "logs", stringResource(R.string.setup_logs), stringResource(R.string.setup_logs_hint), s.logsEnabled) { a.onLogs() } + ToggleRow( + host, "enhanced-diagnostics", stringResource(R.string.setup_enhanced_diagnostics), + stringResource(R.string.setup_enhanced_diagnostics_hint), s.enhancedDiagnosticsArmed, + ) { a.onEnhancedDiagnostics() } ToggleRow( host, "game-debug-logs", stringResource(R.string.setup_game_debug_logs), stringResource(if (s.gameDebugLogsNeedsRestart) R.string.setup_game_debug_logs_restart else R.string.setup_game_debug_logs_hint), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c038b1841d..56c27ae794 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -915,6 +915,13 @@ <string name="setup_session">Session</string> <string name="setup_logs">Session logs</string> <string name="setup_logs_hint">Saved after each session</string> + <string name="setup_enhanced_diagnostics">Enhanced diagnostics for next session</string> + <string name="setup_enhanced_diagnostics_hint">Captures detailed logs for one session. May reduce performance and use more storage. Turns itself off when the session starts; review logs before sharing.</string> + <string name="diagnostics_share_title">Share diagnostic bundles</string> + <string name="diagnostics_share_session">Session and device</string> + <string name="diagnostics_share_graphics">Graphics</string> + <string name="diagnostics_share_games">Games and compatibility</string> + <string name="diagnostics_share_all">All bundles</string> <string name="setup_game_debug_logs">Game debug logs</string> <string name="setup_game_debug_logs_hint">Include Proton, Wine and graphics diagnostics on the next game launch. Can reduce performance and use more storage.</string> <string name="setup_game_debug_logs_restart">Restart this session to save game debug logs</string> diff --git a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt index b93c439bf2..4a76243bbd 100644 --- a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt @@ -316,6 +316,60 @@ class LogRedactorTest { } } + @Test fun oversizedAccountMetadataIsRejectedWithoutForgettingKnownNames() { + val users = tmp.newFile("known-loginusers.vdf") + val oversized = tmp.newFile("oversized-loginusers.vdf") + users.writeText("\"AccountName\" \"previous_player\"") + java.io.RandomAccessFile(oversized, "rw").use { + it.setLength(LogRedactor.MAX_LEARN_INPUT_BYTES.toLong() + 1) + } + try { + assertTrue(LogRedactor.learnAccounts(users)) + assertFalse(LogRedactor.learnAccounts(oversized)) + assertEquals("<redacted:account>", LogRedactor.redact("previous_player")) + } finally { + LogRedactor.learnAccounts() + } + } + + @Test fun repeatedIncompleteAccountLearningKeepsOnlyABoundedRecentSet() { + val users = tmp.newFile("changing-loginusers.vdf") + val oversized = tmp.newFile("unreadable-loginusers.vdf") + java.io.RandomAccessFile(oversized, "rw").use { + it.setLength(LogRedactor.MAX_LEARN_INPUT_BYTES.toLong() + 1) + } + try { + LogRedactor.learnAccounts() + repeat(3) { batch -> + users.writeText((0 until 1024).joinToString("\n") { + "\"AccountName\" \"round${batch}player${it.toString().padStart(4, '0')}\"" + }) + assertFalse(LogRedactor.learnAccounts(users, oversized)) + } + assertEquals("<redacted:account>", LogRedactor.redact("round2player0000")) + assertEquals("<redacted:account>", LogRedactor.redact("round1player0000")) + assertEquals("round0player0000", LogRedactor.redact("round0player0000")) + } finally { + LogRedactor.learnAccounts() + } + } + + @Test fun oversizedAddressMetadataIsRejectedWithoutForgettingKnownAddresses() { + val link = tmp.newFile("known-network") + val oversized = tmp.newFile("oversized-network") + link.writeText("addr 203.0.113.40 24\n") + java.io.RandomAccessFile(oversized, "rw").use { + it.setLength(LogRedactor.MAX_LEARN_INPUT_BYTES.toLong() + 1) + } + try { + assertTrue(LogRedactor.learnOwnAddresses(link)) + assertFalse(LogRedactor.learnOwnAddresses(oversized)) + assertEquals("<redacted:ip>", LogRedactor.redact("203.0.113.40")) + } finally { + LogRedactor.learnOwnAddresses(tmp.root.resolve("missing-network")) + } + } + @Test fun manyLearnedAddressesKeepOtherAddresses() { val link = tmp.newFile("droiddeck-net") link.writeText((1..40).joinToString("\n") { "addr 203.0.113.$it 24" }) diff --git a/app/src/test/java/com/droiddeck/launcher/session/EnhancedDiagnosticsTest.kt b/app/src/test/java/com/droiddeck/launcher/session/EnhancedDiagnosticsTest.kt new file mode 100644 index 0000000000..f4a85bb8fe --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/EnhancedDiagnosticsTest.kt @@ -0,0 +1,140 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import com.droiddeck.launcher.runtime.LinuxRuntime +import org.json.JSONObject +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], manifest = Config.NONE) +class EnhancedDiagnosticsTest { + private lateinit var context: Context + private lateinit var guest: File + + @Before fun setUp() { + context = RuntimeEnvironment.getApplication() + SessionPaths.take()?.let { SessionPaths.release(context, it) } + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit() + .remove("logs") + .remove("gameDebugLogsEnabled") + .remove("enhancedDiagnosticsNext") + .remove("enhancedDiagnosticsActiveSessions") + .commit() + guest = File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/game-environment.json") + } + + @After fun tearDown() { + SessionPaths.take()?.let { folder -> + SessionPaths.release(context, folder) + folder.deleteRecursively() + } + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit() + .remove("logs") + .remove("gameDebugLogsEnabled") + .remove("enhancedDiagnosticsNext") + .remove("enhancedDiagnosticsActiveSessions") + .commit() + GameEnvironmentStore.publish(context) + } + + @Test fun armedSessionIsRetainedAndConsumesTheOneShotPreference() { + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().putBoolean("logs", false).commit() + assertTrue(EnhancedDiagnostics.setArmed(context, true)) + + val folder = SessionPaths.beginOrCurrent(context, "enhanced-test") + + assertEquals(SessionFiles.logDirectory(context), folder.parentFile) + assertFalse(EnhancedDiagnostics.isArmed(context)) + assertTrue(EnhancedDiagnostics.isActive(context, folder)) + val manifest = JSONObject(File(folder, EnhancedDiagnostics.MANIFEST_FILE).readText()) + assertEquals(1, manifest.getInt("schema")) + assertEquals("enhanced", manifest.getString("profile")) + assertEquals(folder.name, manifest.getString("sessionId")) + assertTrue(manifest.getBoolean("exportBundlesBounded")) + assertFalse(manifest.getBoolean("rawCaptureByteBounded")) + } + + @Test fun activeProfileForcesGameDiagnosticsWithoutChangingUserPreferences() { + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit() + .putBoolean("logs", false) + .putBoolean("gameDebugLogsEnabled", false) + .commit() + assertTrue(EnhancedDiagnostics.setArmed(context, true)) + SessionPaths.beginOrCurrent(context, "enhanced-game-logs") + + GameEnvironmentStore.publish(context) + + assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) + assertFalse(SessionPrefs.logsEnabled(context)) + assertFalse(SessionPrefs.gameDebugLogsEnabled(context)) + } + + @Test fun cancellingTheOneShotLeavesOrdinaryLogRetentionUnchanged() { + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().putBoolean("logs", false).commit() + assertTrue(EnhancedDiagnostics.setArmed(context, true)) + assertTrue(EnhancedDiagnostics.setArmed(context, false)) + + val folder = SessionPaths.beginOrCurrent(context, "ordinary-test") + + assertEquals(File(context.cacheDir, "session-logs"), folder.parentFile) + assertFalse(EnhancedDiagnostics.isActive(context, folder)) + } + + @Test fun guestCannotForgeEnhancedDiagnosticsByWritingAMarker() { + val folder = SessionPaths.beginOrCurrent(context, "forged-marker") + File(folder, EnhancedDiagnostics.MANIFEST_FILE).writeText( + """{"schema":1,"profile":"enhanced"}""", + ) + + assertFalse(EnhancedDiagnostics.isActive(context, folder)) + assertNull(EnhancedDiagnostics.manifest(context, folder)) + } + + @Test fun trustedStateSurvivesGuestMarkerDeletionAndSessionRecovery() { + assertTrue(EnhancedDiagnostics.setArmed(context, true)) + val folder = SessionPaths.beginOrCurrent(context, "deleted-marker") + assertTrue(File(folder, EnhancedDiagnostics.MANIFEST_FILE).delete()) + + assertTrue(EnhancedDiagnostics.isActive(context, File(folder.path))) + assertEquals(folder.name, EnhancedDiagnostics.manifest(context, folder)?.getString("sessionId")) + assertEquals(folder, SessionPaths.take()) + assertTrue(EnhancedDiagnostics.isActive(context, folder)) + } + + @Test fun informationalMarkerFailureDoesNotRearmTheNextSession() { + val parent = SessionFiles.logDirectory(context).apply { mkdirs() } + val folder = File(parent, "2026-11-04-99-marker-failure").apply { mkdirs() } + File(folder, EnhancedDiagnostics.MANIFEST_FILE).mkdirs() + assertTrue(EnhancedDiagnostics.setArmed(context, true)) + + assertTrue(EnhancedDiagnostics.consumeInto(context, folder)) + + assertTrue(EnhancedDiagnostics.isActive(context, folder)) + assertFalse(EnhancedDiagnostics.isArmed(context)) + folder.deleteRecursively() + } + + @Test fun aReusedSessionPathDoesNotInheritTrustedState() { + assertTrue(EnhancedDiagnostics.setArmed(context, true)) + val original = SessionPaths.beginOrCurrent(context, "reused-path") + assertTrue(EnhancedDiagnostics.isActive(context, original)) + assertEquals(original, SessionPaths.take()) + original.deleteRecursively() + + val replacement = SessionPaths.beginOrCurrent(context, "reused-path") + + assertEquals(original.path, replacement.path) + assertFalse(EnhancedDiagnostics.isActive(context, replacement)) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt new file mode 100644 index 0000000000..73dd3f2132 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt @@ -0,0 +1,331 @@ +package com.droiddeck.launcher.session + +import android.content.Intent +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Assume.assumeFalse +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import java.io.RandomAccessFile +import java.nio.file.Files +import java.util.zip.ZipFile + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33]) +class EnhancedSessionLogShareTest { + @get:Rule val tmp = TemporaryFolder() + private val app get() = RuntimeEnvironment.getApplication() + + @Test fun diagnosticsAreSplitIntoManifestedArchivesWithOneSessionIdentity() { + val session = tmp.newFolder("2026-11-04-01-steam") + session.resolve("session.log").writeText("startup ok\n") + session.resolve("wayland.log").writeText("frame import ok\n") + session.resolve("steam-42.log").writeText("dxvk: present ok\n") + + val zips = EnhancedSessionLogShare.create(app, session) + + assertEquals( + setOf("session", "graphics", "games"), + zips.map { it.nameWithoutExtension.substringAfterLast('-') }.toSet(), + ) + val expected = mapOf( + "session" to "${session.name}/session.log", + "graphics" to "${session.name}/wayland.log", + "games" to "${session.name}/steam-42.log", + ) + zips.forEach { zip -> + val category = zip.nameWithoutExtension.substringAfterLast('-') + ZipFile(zip).use { archive -> + assertTrue(archive.getEntry(expected.getValue(category)) != null) + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()) + assertEquals(1, manifest.getInt("schema")) + assertEquals(session.name, manifest.getString("sessionId")) + assertEquals(category, manifest.getString("category")) + assertEquals("captured", manifest.getJSONArray("entries").getJSONObject(0).getString("status")) + } + } + SessionLogShare.clear(app) + } + + @Test fun oversizedFilesKeepBoundedBeginningAndTailAndDeclareTruncation() { + val session = tmp.newFolder("2026-11-04-02-game") + session.resolve("steam-7.log").writeText("begin\n" + "middle\n".repeat(100) + "tail\n") + val limits = EnhancedShareLimits(maxFilesPerArchive = 8, maxBytesPerFile = 96, maxBytesTotal = 512) + + val games = EnhancedSessionLogShare.create(app, session, limits = limits) + .single { it.name.endsWith("-games.zip") } + + ZipFile(games).use { archive -> + val text = archive.getInputStream(archive.getEntry("${session.name}/steam-7.log")).bufferedReader().readText() + assertTrue(text.startsWith("begin")) + assertTrue(text.contains("diagnostic file truncated")) + assertTrue(text.endsWith("tail\n")) + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()) + assertEquals("truncated", manifest.getJSONArray("entries").getJSONObject(0).getString("status")) + assertTrue(manifest.getJSONArray("entries").getJSONObject(0).getLong("capturedBytes") <= 96) + } + SessionLogShare.clear(app) + } + + @Test fun symbolicLinksAreNotReadAndTheirOmissionIsRecorded() { + assumeFalse(System.getProperty("os.name").startsWith("Windows")) + val session = tmp.newFolder("2026-11-04-03-steam") + session.resolve("session.log").writeText("safe\n") + val outside = tmp.newFile("private.log").apply { writeText("do-not-share\n") } + val link = session.toPath().resolve("wayland.log") + runCatching { Files.createSymbolicLink(link, outside.toPath()) }.getOrElse { return } + + val graphics = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-graphics.zip") } + + ZipFile(graphics).use { archive -> + assertFalse(archive.entries().toList().any { it.name.endsWith("wayland.log") }) + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()) + val entries = manifest.getJSONArray("entries") + assertTrue((0 until entries.length()).map { entries.getJSONObject(it) } + .any { it.optString("reason") == "unsafe-or-unavailable-source" }) + } + SessionLogShare.clear(app) + } + + @Test fun enhancedShareUsesOneMultipleAttachmentIntent() { + val session = tmp.newFolder("2026-11-04-04-steam") + session.resolve("session.log").writeText("safe\n") + val zips = EnhancedSessionLogShare.create(app, session) + + val chooser = SessionLogShare.shareEnhancedIntent(app, zips) + val send = chooser.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)!! + + assertEquals(Intent.ACTION_SEND_MULTIPLE, send.action) + assertEquals("application/zip", send.type) + assertEquals(3, send.getParcelableArrayListExtra<android.net.Uri>(Intent.EXTRA_STREAM)!!.size) + assertEquals(3, send.clipData!!.itemCount) + SessionLogShare.clear(app) + } + + @Test fun graphicsArchiveIncludesOnlyBoundedFrameTraceSummariesFromTheSessionLog() { + val session = tmp.newFolder("2026-11-04-05-steam") + session.resolve("session.log").writeText( + "normal startup line\n" + + "DROIDDECK_FRAME_TRACE xdamage=4 commits=2\n" + + "unrelated account=test-user\n" + + "DROIDDECK_FRAME_TRACE xdamage=9 commits=8\n" + + "DROIDDECK_PROCESS_TRACE pid=42 gpuLibs=libvulkan.so\n", + ) + + val graphics = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-graphics.zip") } + + ZipFile(graphics).use { archive -> + val trace = archive.getInputStream(archive.getEntry("${session.name}/graphics/frame-trace.log")) + .bufferedReader().readText() + assertEquals( + "DROIDDECK_FRAME_TRACE xdamage=4 commits=2\n" + + "DROIDDECK_FRAME_TRACE xdamage=9 commits=8\n", + trace, + ) + assertFalse(trace.contains("normal startup")) + assertFalse(trace.contains("test-user")) + val process = archive.getInputStream(archive.getEntry("${session.name}/graphics/process-trace.log")) + .bufferedReader().readText() + assertEquals("DROIDDECK_PROCESS_TRACE pid=42 gpuLibs=libvulkan.so\n", process) + } + SessionLogShare.clear(app) + } + + @Test fun truncationNeverSharesASecretWhoseLabelWasCutOffAtTheBoundary() { + val session = tmp.newFolder("2026-11-04-06-game") + val secret = "abcdef1234567890" + session.resolve("steam-8.log").writeText( + "padding-refresh_token=$secret" + "x".repeat(512) + "\nvisible tail\n", + ) + val limits = EnhancedShareLimits(maxFilesPerArchive = 8, maxBytesPerFile = 128, maxBytesTotal = 512) + + val games = EnhancedSessionLogShare.create(app, session, limits = limits) + .single { it.name.endsWith("-games.zip") } + + val shared = ZipFile(games).use { archive -> + archive.getInputStream(archive.getEntry("${session.name}/steam-8.log")).bufferedReader().readText() + } + assertFalse(shared.contains(secret)) + assertTrue(shared.contains("diagnostic file truncated")) + assertTrue(shared.endsWith("visible tail\n")) + SessionLogShare.clear(app) + } + + @Test fun discoveryStopsAtItsBoundAndDeclaresTheTruncatedInventory() { + val session = tmp.newFolder("2026-11-04-07-steam") + repeat(20) { session.resolve("log-$it.txt").writeText("line $it\n") } + val limits = EnhancedShareLimits( + maxFilesPerArchive = 8, + maxDiscoveredFiles = 2, + maxBytesPerFile = 1024, + maxBytesTotal = 4096, + ) + + val zips = EnhancedSessionLogShare.create(app, session, limits = limits) + + val captured = zips.sumOf { zip -> + ZipFile(zip).use { archive -> archive.entries().toList().count { it.name != "diagnostics-manifest.json" } } + } + assertTrue(captured <= 2) + zips.forEach { zip -> + ZipFile(zip).use { archive -> + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()) + val entries = manifest.getJSONArray("entries") + assertTrue((0 until entries.length()).map { entries.getJSONObject(it) } + .any { it.optString("origin") == "discovery" && it.optString("status") == "truncated" }) + } + } + SessionLogShare.clear(app) + } + + @Test fun aGuestForgedActivationMarkerIsNeverExportedAsTrustedMetadata() { + val session = tmp.newFolder("2026-11-04-08-steam") + session.resolve("session.log").writeText("safe\n") + session.resolve(EnhancedDiagnostics.MANIFEST_FILE).writeText("{\"profile\":\"forged\"}\n") + + val zips = EnhancedSessionLogShare.create(app, session) + + zips.forEach { zip -> + ZipFile(zip).use { archive -> + assertFalse(archive.entries().toList().any { it.name.endsWith(EnhancedDiagnostics.MANIFEST_FILE) }) + } + } + SessionLogShare.clear(app) + } + + @Test fun hardLinksAreRejectedInsteadOfFollowingASecondNameToItsContent() { + assumeFalse(System.getProperty("os.name").startsWith("Windows")) + val session = tmp.newFolder("2026-11-04-09-steam") + session.resolve("session.log").writeText("safe\n") + val outside = tmp.newFile("outside-hardlink.log").apply { writeText("private hard-link content\n") } + runCatching { Files.createLink(session.toPath().resolve("wayland.log"), outside.toPath()) }.getOrElse { return } + + val graphics = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-graphics.zip") } + + ZipFile(graphics).use { archive -> + assertFalse(archive.entries().toList().any { it.name.endsWith("wayland.log") }) + val all = archive.entries().toList().joinToString("\n") { entry -> + archive.getInputStream(entry).bufferedReader().readText() + } + assertFalse(all.contains("private hard-link content")) + } + SessionLogShare.clear(app) + } + + @Test fun guestControlledAndControlCharacterNamesNeverEnterTheArchiveOrManifest() { + val session = tmp.newFolder("2026-11-04-10-steam") + session.resolve("private-window-title.log").writeText("safe diagnostic\n") + session.resolve("wayland\nsecret.log").writeText("must not be named\n") + + val sessionZip = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-session.zip") } + + ZipFile(sessionZip).use { archive -> + val names = archive.entries().toList().map { it.name } + assertTrue(names.any { it.contains("/entry-") && it.endsWith(".log") }) + assertFalse(names.any { it.contains("private-window-title") || it.contains('\n') }) + val manifest = archive.getInputStream(archive.getEntry("diagnostics-manifest.json")).bufferedReader().readText() + assertFalse(manifest.contains("private-window-title")) + assertFalse(manifest.contains("wayland\\nsecret")) + } + SessionLogShare.clear(app) + } + + @Test fun oneCategoryCannotConsumeTheOtherCategoriesByteReservations() { + val session = tmp.newFolder("2026-11-04-11-steam") + session.resolve("session.log").writeText("session\n".repeat(100)) + session.resolve("wayland.log").writeText("graphics\n".repeat(100)) + session.resolve("steam-11.log").writeText("game\n".repeat(100)) + val limits = EnhancedShareLimits(maxBytesPerFile = 1024, maxBytesTotal = 300) + + val zips = EnhancedSessionLogShare.create(app, session, limits = limits) + + zips.forEach { zip -> + ZipFile(zip).use { archive -> + assertTrue(archive.entries().toList().any { it.name != "diagnostics-manifest.json" }) + } + } + SessionLogShare.clear(app) + } + + @Test fun filteredTraceScanFindsLateSummariesAndMarksThePartialSource() { + val session = tmp.newFolder("2026-11-04-12-steam") + val source = session.resolve("session.log") + RandomAccessFile(source, "rw").use { file -> + file.setLength(17L * 1024 * 1024) + file.seek(file.length() - 80) + file.write("\nDROIDDECK_PROCESS_TRACE pid=99 gpuLibs=libGLES.so\n".toByteArray()) + } + + val graphics = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-graphics.zip") } + + ZipFile(graphics).use { archive -> + val trace = archive.getInputStream(archive.getEntry("${session.name}/graphics/process-trace.log")) + .bufferedReader().readText() + assertTrue(trace.contains("pid=99")) + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()) + val entries = manifest.getJSONArray("entries") + assertTrue((0 until entries.length()).map { entries.getJSONObject(it) }.any { + it.optString("origin") == "guest-process-trace" && it.optString("status") == "truncated" + }) + } + SessionLogShare.clear(app) + } + + @Test fun diagnosticLookingGuestNamesCannotExposeEmbeddedSecrets() { + val session = tmp.newFolder("2026-11-04-13-game") + val tokenName = "dxvk-refresh_token_abcdef123456.log" + val accountName = "battle.net-secretvalue.log" + session.resolve(tokenName).writeText("dxvk diagnostic\n") + session.resolve(accountName).writeText("battle net diagnostic\n") + + val games = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-games.zip") } + + ZipFile(games).use { archive -> + val names = archive.entries().toList().map { it.name } + assertFalse(names.any { it.contains("refresh_token") || it.contains("secretvalue") }) + assertTrue(names.count { it.substringAfterLast('/').startsWith("entry-") } >= 2) + val manifest = archive.getInputStream(archive.getEntry("diagnostics-manifest.json")).bufferedReader().readText() + assertFalse(manifest.contains("refresh_token")) + assertFalse(manifest.contains("secretvalue")) + } + SessionLogShare.clear(app) + } + + @Test fun gamesArchiveIncludesOnlyGameLifecycleSummariesFromTheSessionLog() { + val session = tmp.newFolder("2026-11-04-14-game") + session.resolve("session.log").writeText( + "DROIDDECK_DIAGNOSTICS event=game_start appId=42 pid=123\n" + + "unrelated launch detail\n" + + "DROIDDECK_DIAGNOSTICS event=game_exit appId=42 status=139\n", + ) + + val games = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-games.zip") } + + ZipFile(games).use { archive -> + val lifecycle = archive.getInputStream(archive.getEntry("${session.name}/games/game-lifecycle.log")) + .bufferedReader().readText() + assertEquals( + "DROIDDECK_DIAGNOSTICS event=game_start appId=42 pid=123\n" + + "DROIDDECK_DIAGNOSTICS event=game_exit appId=42 status=139\n", + lifecycle, + ) + assertFalse(lifecycle.contains("unrelated launch detail")) + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()) + assertTrue(manifest.toString().contains("guest-game-lifecycle")) + } + SessionLogShare.clear(app) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index 2e00e83c69..678ae876fd 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -86,8 +86,9 @@ class SessionLogShareTest { File(folder, "events.jsonl").writeText("$secret\n") val out = zip(folder) - for (name in listOf("app.log", "session.log", "steam/deep/nested.txt", ".hidden.txt", "events.jsonl")) + for (name in listOf("app.log", "session.log", "events.jsonl")) assertFalse(name, out.getValue(name).contains(leaked)) + assertTrue(out.values.none { it.contains(leaked) }) } @Test fun aRecordUnderOtherRedactorRulesVouchesForNothing() { @@ -187,7 +188,7 @@ class SessionLogShareTest { assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists()) } - @Test fun steamLogsPastTheSizeLimitStayOut() { + @Test fun steamLogsPastTheSizeLimitAreBoundedAndDeclared() { val folder = tmp.newFolder("2026-10-06-07-steam") File(folder, "session.log").writeText("ok\n") File(folder, "steam").mkdirs() @@ -196,9 +197,11 @@ class SessionLogShareTest { val line = ByteArray(1024) { 'x'.code.toByte() }.also { it[it.size - 1] = '\n'.code.toByte() } repeat(9 * 1024) { out.write(line) } } - val names = zip(folder).keys - assertTrue("steam/console_log.txt" in names) - assertFalse("steam/cef_log.previous.txt" in names) + val output = zip(folder) + assertTrue("steam/console_log.txt" in output) + assertTrue("steam/cef_log.previous.txt" in output) + assertTrue(output.getValue("steam/cef_log.previous.txt").contains("diagnostic file truncated")) + assertTrue(output.getValue("diagnostics-manifest.json").contains("\"status\": \"truncated\"")) } @Test fun streamingComparisonPreservesUnchangedFileAndReplacesChangedFile() { diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index ff7fd95108..ecc756553f 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -2,7 +2,6 @@ package com.droiddeck.launcher.session import com.droiddeck.launcher.runtime.LinuxRuntime import java.io.File -import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat import java.util.Date import java.util.Locale @@ -38,23 +37,11 @@ class SessionLogShareZipTest { val zip = SessionLogShare.zipFolder(app, session)!! ZipFile(zip).use { archive -> val entry = archive.getEntry("${session.name}/steam-42.log")!! - archive.getInputStream(entry).use { input -> - val expected = "${com.droiddeck.launcher.core.LogRedactor.OVERSIZED_LINE}\n" - val prefix = ByteArray(expected.toByteArray(StandardCharsets.UTF_8).size) - var offset = 0 - while (offset < prefix.size) { - val count = input.read(prefix, offset, prefix.size - offset) - assertTrue("zip entry ended before its scrubbed prefix", count > 0) - offset += count - } - assertEquals(expected, String(prefix, StandardCharsets.UTF_8)) - input.bufferedReader().use { reader -> - val trailing = requireNotNull(reader.readLine()) - assertFalse("trailing secret survived", trailing.contains(trailingSecret)) - assertEquals("refresh_token=<redacted:token>", trailing) - assertEquals(null, reader.readLine()) - } - } + val shared = archive.getInputStream(entry).bufferedReader().readText() + assertTrue(shared.contains("diagnostic file truncated")) + assertFalse("early secret survived", shared.contains(earlySecret)) + assertFalse("trailing secret survived", shared.contains(trailingSecret)) + assertTrue(shared.contains("refresh_token=<redacted:token>")) } } finally { SessionLogShare.clear(app) diff --git a/app/src/test/java/com/droiddeck/launcher/session/SettingsResetTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SettingsResetTest.kt index 83bba10460..e95a49608a 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SettingsResetTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SettingsResetTest.kt @@ -35,6 +35,7 @@ class SettingsResetTest { SessionPrefs.setResolutionChoice(app, SessionService.MODE_STEAM, "1280x800") SessionPrefs.setGuestHostname(app, "MyDeck") assertTrue(SessionPrefs.setGameDebugLogsEnabled(app, true)) + assertTrue(EnhancedDiagnostics.setArmed(app, true)) SessionPrefs.setHudShowFps(app, false) SessionPrefs.setHudShowBattery(app, false) SessionPrefs.setHudShowGraph(app, false) @@ -58,6 +59,7 @@ class SettingsResetTest { assertFalse(SessionPrefs.resolutionChosen(app, SessionService.MODE_STEAM)) assertEquals(SessionPrefs.DEFAULT_GUEST_HOSTNAME, SessionPrefs.guestHostname(app)) assertFalse(SessionPrefs.gameDebugLogsEnabled(app)) + assertFalse(EnhancedDiagnostics.isArmed(app)) val guest = java.io.File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), "root/.config/droiddeck/game-environment.json") assertFalse(org.json.JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md index 456e66cc6a..e0800784e9 100644 --- a/docs/development/game-environment.md +++ b/docs/development/game-environment.md @@ -116,6 +116,48 @@ logging can reduce performance and consume storage; disable it after collecting the report. If the session log directory is unavailable, the launcher reports that diagnostics were skipped instead of writing uncollected files elsewhere. +## Enhanced diagnostics + +Use **Setup > Diagnostics > Enhanced diagnostics for next session** when normal +session logs are not enough. The setting is one-shot: DroidDeck creates and +retains the next session's log directory, records the diagnostic profile, then +turns the setting off. It also enables the existing game diagnostic environment +for that session without changing the user's saved **Session logs** or **Game +debug logs** preferences. + +After reproducing the problem, use **Latest session logs > Share logs** or the +in-session share action. Enhanced sessions offer separate, correlated archives: + +| Archive | Main contents | +| --- | --- | +| Session and device | Startup timeline, device/component selection, app, audio, network, and exit summaries | +| Graphics | Graphics-related logs plus bounded Gamescope frame and process summaries when their providers are available | +| Games and compatibility | Proton, Wine, DXVK/VKD3D, FEX, store, and game lifecycle logs | + +Choose one archive when an issue calls for a narrow report, or **All bundles** +to share the three archives together. Every archive contains a +`diagnostics-manifest.json` with the common session ID and the state of each +artifact: captured, truncated, unavailable, omitted, or failed. Some captured +logs may themselves explain that a permission-limited source was unavailable. + +Exported archives sample a bounded amount of input. Large text logs retain +complete lines from their beginning and end, and the manifest records partial +scans and input limits. Raw game and component log writers are not yet safely byte-bounded while +the session is running; they can use substantial storage, particularly during a +long Proton game session. Enhanced diagnostics may also change timing because it +keeps the game wrapper alive long enough to record an exit status. Turn it on +only for a reproduction and review the archives before sharing them. + +The bundle does not promise unrestricted Android, kernel, or vendor-driver +logs. If accessible, Android's crash buffer can include reports from other apps; +redaction is best effort. Screen captures, pixels, input contents, memory dumps, +and full system traces are not included automatically. + +The Gamescope frame summary is produced only by a Gamescope build that includes +the enhanced frame-trace provider. An older bundled Gamescope safely ignores the +diagnostic environment setting; the Graphics archive then records no frame-trace +summary rather than inventing one. + A Unity game under FEX (`UnityPlayer.dll` for Windows builds under Proton, `UnityPlayer.so` or `GameAssembly.so` for native Linux builds started by **Linux x86 (FEX)**) keeps FEX's TSO on when the Default profile's FEX preset diff --git a/tools/gamescope/patches/0900-enhanced-frame-diagnostics.patch b/tools/gamescope/patches/0900-enhanced-frame-diagnostics.patch new file mode 100644 index 0000000000..1bd1573559 --- /dev/null +++ b/tools/gamescope/patches/0900-enhanced-frame-diagnostics.patch @@ -0,0 +1,333 @@ +diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp +index 953765a..73ab9cc 100644 +--- a/src/Backends/WaylandBackend.cpp ++++ b/src/Backends/WaylandBackend.cpp +@@ -14,2 +14,3 @@ + #include "Utils/WaylandScaling.h" ++#include "droiddeck_frame_trace.hpp" + +@@ -1002,2 +1003,4 @@ namespace gamescope + ++ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputRelease ); ++ + xdg_log.debugf( "buffer_release: %p", pBuffer ); +@@ -1079,2 +1082,3 @@ namespace gamescope + { ++ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputPresent ); + UpdateFullscreenState(); +@@ -1485,2 +1489,3 @@ namespace gamescope + { ++ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputAttach ); + assert( oState->pBuffer ); +@@ -1633,2 +1638,3 @@ namespace gamescope + { ++ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputDetach ); + wl_surface_attach( m_pSurface, nullptr, 0, 0 ); +@@ -1650,2 +1656,3 @@ namespace gamescope + { ++ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputCommit ); + if ( m_bNeedsDecorCommit ) +diff --git a/src/droiddeck_frame_trace.hpp b/src/droiddeck_frame_trace.hpp +new file mode 100644 +index 0000000..2c57f65 +--- /dev/null ++++ b/src/droiddeck_frame_trace.hpp +@@ -0,0 +1,191 @@ ++#pragma once ++ ++#include <atomic> ++#include <chrono> ++#include <cstdint> ++#include <cstdio> ++#include <cstdlib> ++#include <cstring> ++ ++#ifndef DROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS ++#define DROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS 2000 ++#endif ++#ifndef DROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS ++#define DROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS 15000 ++#endif ++#ifndef DROIDDECK_FRAME_TRACE_FAST_DURATION_MS ++#define DROIDDECK_FRAME_TRACE_FAST_DURATION_MS 120000 ++#endif ++#ifndef DROIDDECK_FRAME_TRACE_DURATION_MS ++#define DROIDDECK_FRAME_TRACE_DURATION_MS 86400000 ++#endif ++ ++namespace droiddeck::frame_trace ++{ ++ ++enum class Event : uint32_t ++{ ++ X11Damage, ++ X11DamageCurrent, ++ X11DamageOther, ++ SurfaceCommit, ++ SurfaceCommitBuffer, ++ SurfaceCommitNoBuffer, ++ CommitDequeued, ++ CommitDequeuedCurrent, ++ CommitDequeuedOther, ++ ImportSucceeded, ++ ImportSucceededCurrent, ++ ImportSucceededOther, ++ ImportFailed, ++ ImportFailedCurrent, ++ ImportFailedOther, ++ FenceReady, ++ FenceWaited, ++ CommitDone, ++ CommitDoneCurrent, ++ CommitDoneOther, ++ BaseLatched, ++ BaseLatchedCurrent, ++ BaseLatchedOther, ++ OutputPresent, ++ OutputAttach, ++ OutputDetach, ++ OutputCommit, ++ OutputRelease, ++ Count, ++}; ++ ++class State ++{ ++public: ++ State() ++ : m_enabled( EnabledByEnvironment() ) ++ { ++ } ++ ++ void Start() ++ { ++ if ( !m_enabled || m_started.exchange( true, std::memory_order_relaxed ) ) ++ return; ++ ++ m_startedAt = std::chrono::steady_clock::now(); ++ m_nextSummaryMs = kFastIntervalMs; ++ std::fprintf( stderr, ++ "DROIDDECK_FRAME_TRACE schema=1 fast_interval_ms=%ld slow_interval_ms=%ld " ++ "fast_duration_ms=%ld duration_ms=%ld\n", ++ kFastIntervalMs, kSlowIntervalMs, kFastDurationMs, kDurationMs ); ++ PrintSummary( 0 ); ++ } ++ ++ void Record( Event event ) ++ { ++ if ( !m_enabled || !m_started.load( std::memory_order_relaxed ) || ++ !m_active.load( std::memory_order_relaxed ) ) ++ return; ++ m_counts[static_cast<uint32_t>( event )].fetch_add( 1, std::memory_order_relaxed ); ++ } ++ ++ void Tick() ++ { ++ if ( !m_enabled || !m_started.load( std::memory_order_relaxed ) || ++ !m_active.load( std::memory_order_relaxed ) ) ++ return; ++ ++ const int64_t elapsed = ElapsedMs(); ++ if ( elapsed >= kDurationMs ) ++ { ++ PrintSummary( kDurationMs ); ++ m_active.store( false, std::memory_order_relaxed ); ++ return; ++ } ++ if ( elapsed < m_nextSummaryMs ) ++ return; ++ ++ PrintSummary( elapsed ); ++ m_nextSummaryMs = elapsed + ( elapsed < kFastDurationMs ? kFastIntervalMs : kSlowIntervalMs ); ++ } ++ ++private: ++ static constexpr int64_t kFastIntervalMs = DROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS; ++ static constexpr int64_t kSlowIntervalMs = DROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS; ++ static constexpr int64_t kFastDurationMs = DROIDDECK_FRAME_TRACE_FAST_DURATION_MS; ++ static constexpr int64_t kDurationMs = DROIDDECK_FRAME_TRACE_DURATION_MS; ++ ++ static bool EnabledByEnvironment() ++ { ++ const char *value = std::getenv( "DROIDDECK_ENHANCED_DIAGNOSTICS" ); ++ return value != nullptr && std::strcmp( value, "1" ) == 0; ++ } ++ ++ int64_t ElapsedMs() const ++ { ++ return std::chrono::duration_cast<std::chrono::milliseconds>( ++ std::chrono::steady_clock::now() - m_startedAt ).count(); ++ } ++ ++ uint64_t Count( Event event ) const ++ { ++ return m_counts[static_cast<uint32_t>( event )].load( std::memory_order_relaxed ); ++ } ++ ++ void PrintSummary( int64_t elapsed ) const ++ { ++ std::fprintf( stderr, ++ "DROIDDECK_FRAME_TRACE t_ms=%ld x11_damage=%lu x11_damage_current=%lu x11_damage_other=%lu " ++ "surface_commit=%lu surface_buffer=%lu surface_no_buffer=%lu dequeued=%lu dequeued_current=%lu " ++ "dequeued_other=%lu import_ok=%lu import_ok_current=%lu import_ok_other=%lu import_failed=%lu " ++ "import_failed_current=%lu import_failed_other=%lu fence_ready=%lu fence_waited=%lu commit_done=%lu " ++ "commit_done_current=%lu commit_done_other=%lu base_latched=%lu base_latched_current=%lu " ++ "base_latched_other=%lu output_present=%lu output_attach=%lu " ++ "output_detach=%lu output_commit=%lu output_release=%lu\n", ++ elapsed, ++ Count( Event::X11Damage ), Count( Event::X11DamageCurrent ), Count( Event::X11DamageOther ), ++ Count( Event::SurfaceCommit ), Count( Event::SurfaceCommitBuffer ), Count( Event::SurfaceCommitNoBuffer ), ++ Count( Event::CommitDequeued ), Count( Event::CommitDequeuedCurrent ), Count( Event::CommitDequeuedOther ), ++ Count( Event::ImportSucceeded ), Count( Event::ImportSucceededCurrent ), Count( Event::ImportSucceededOther ), ++ Count( Event::ImportFailed ), Count( Event::ImportFailedCurrent ), Count( Event::ImportFailedOther ), ++ Count( Event::FenceReady ), Count( Event::FenceWaited ), Count( Event::CommitDone ), ++ Count( Event::CommitDoneCurrent ), Count( Event::CommitDoneOther ), Count( Event::BaseLatched ), ++ Count( Event::BaseLatchedCurrent ), Count( Event::BaseLatchedOther ), Count( Event::OutputPresent ), ++ Count( Event::OutputAttach ), Count( Event::OutputDetach ), Count( Event::OutputCommit ), ++ Count( Event::OutputRelease ) ); ++ std::fflush( stderr ); ++ } ++ ++ bool m_enabled; ++ std::atomic<bool> m_started{ false }; ++ std::atomic<bool> m_active{ true }; ++ std::chrono::steady_clock::time_point m_startedAt{}; ++ int64_t m_nextSummaryMs = 0; ++ std::atomic<uint64_t> m_counts[static_cast<uint32_t>( Event::Count )]{}; ++}; ++ ++inline State &GetState() ++{ ++ static State state; ++ return state; ++} ++ ++inline void Start() ++{ ++ GetState().Start(); ++} ++ ++inline void Record( Event event ) ++{ ++ GetState().Record( event ); ++} ++ ++inline void RecordWindow( Event total, Event focused, Event other, bool isFocused ) ++{ ++ Record( total ); ++ Record( isFocused ? focused : other ); ++} ++ ++inline void Tick() ++{ ++ GetState().Tick(); ++} ++ ++} +diff --git a/src/main.cpp b/src/main.cpp +index eef4264..1d22ba4 100644 +--- a/src/main.cpp ++++ b/src/main.cpp +@@ -35,2 +35,3 @@ + #include "Utils/Version.h" ++#include "droiddeck_frame_trace.hpp" + +@@ -718,2 +719,3 @@ int main(int argc, char **argv) + g_argv = argv; ++ droiddeck::frame_trace::Start(); + +diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp +index b4c6830..46e7a6c 100644 +--- a/src/steamcompmgr.cpp ++++ b/src/steamcompmgr.cpp +@@ -32,2 +32,3 @@ + #include "backend.h" ++#include "droiddeck_frame_trace.hpp" + #include "gamescope_shared.h" +@@ -6419,2 +6420,9 @@ damage_win(xwayland_ctx_t *ctx, XDamageNotifyEvent *de) + ++ global_focus_t *pTraceFocus = GetCurrentFocus(); ++ droiddeck::frame_trace::RecordWindow( ++ droiddeck::frame_trace::Event::X11Damage, ++ droiddeck::frame_trace::Event::X11DamageCurrent, ++ droiddeck::frame_trace::Event::X11DamageOther, ++ pTraceFocus != nullptr && pTraceFocus->focusWindow == w ); ++ + if (w->IsAnyOverlay() && !w->opacity) +@@ -7999,2 +8007,8 @@ bool handle_done_commit( steamcompmgr_win_t *w, xwayland_ctx_t *ctx, uint64_t co + { ++ global_focus_t *pTraceFocus = GetCurrentFocus(); ++ droiddeck::frame_trace::RecordWindow( ++ droiddeck::frame_trace::Event::CommitDone, ++ droiddeck::frame_trace::Event::CommitDoneCurrent, ++ droiddeck::frame_trace::Event::CommitDoneOther, ++ pTraceFocus != nullptr && pTraceFocus->focusWindow == w ); + gpuvis_trace_printf( "commit %lu done", w->commit_queue[ j ]->commitID ); +@@ -8049,3 +8063,10 @@ bool handle_done_commit( steamcompmgr_win_t *w, xwayland_ctx_t *ctx, uint64_t co + if ( !cv_paint_debug_pause_base_plane ) ++ { + pFocus->HeldCommits[ HELD_COMMIT_BASE ] = w->commit_queue[ j ]; ++ droiddeck::frame_trace::RecordWindow( ++ droiddeck::frame_trace::Event::BaseLatched, ++ droiddeck::frame_trace::Event::BaseLatchedCurrent, ++ droiddeck::frame_trace::Event::BaseLatchedOther, ++ pFocus == GetCurrentFocus() ); ++ } + hasRepaint = true; +@@ -8397,2 +8418,4 @@ static void note_commit_fence( bool bReadyAtImport ) + { ++ droiddeck::frame_trace::Record( bReadyAtImport ? droiddeck::frame_trace::Event::FenceReady ++ : droiddeck::frame_trace::Event::FenceWaited ); + static uint64_t s_ulReady = 0, s_ulWaited = 0, s_ulLastLog = 0; +@@ -8412,2 +8435,9 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st + { ++ global_focus_t *pTraceFocus = GetCurrentFocus(); ++ const bool bTraceCurrent = pTraceFocus != nullptr && pTraceFocus->focusWindow == w; ++ droiddeck::frame_trace::RecordWindow( ++ droiddeck::frame_trace::Event::CommitDequeued, ++ droiddeck::frame_trace::Event::CommitDequeuedCurrent, ++ droiddeck::frame_trace::Event::CommitDequeuedOther, ++ bTraceCurrent ); + struct wlr_buffer *buf = reslistentry.buf; +@@ -8501,2 +8531,7 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st + { ++ droiddeck::frame_trace::RecordWindow( ++ droiddeck::frame_trace::Event::ImportFailed, ++ droiddeck::frame_trace::Event::ImportFailedCurrent, ++ droiddeck::frame_trace::Event::ImportFailedOther, ++ bTraceCurrent ); + // Import failed to import, early exit. +@@ -8504,2 +8539,7 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st + } ++ droiddeck::frame_trace::RecordWindow( ++ droiddeck::frame_trace::Event::ImportSucceeded, ++ droiddeck::frame_trace::Event::ImportSucceededCurrent, ++ droiddeck::frame_trace::Event::ImportSucceededOther, ++ bTraceCurrent ); + +@@ -8679,3 +8719,2 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st + } +- + gpuvis_trace_printf( "pushing wait for commit %lu win %lx", newCommit->commitID, w->type == steamcompmgr_win_type_t::XWAYLAND ? w->xwayland().id : 0 ); +@@ -10256,2 +10295,3 @@ steamcompmgr_main(int argc, char **argv) + { ++ droiddeck::frame_trace::Tick(); + { +diff --git a/src/wlserver.cpp b/src/wlserver.cpp +index 5733871..ed4dbc3 100644 +--- a/src/wlserver.cpp ++++ b/src/wlserver.cpp +@@ -24,2 +24,3 @@ + #include "WaylandServer/GamescopeLimiter.h" ++#include "droiddeck_frame_trace.hpp" + +@@ -210,2 +211,8 @@ void xwayland_surface_commit(struct wlr_surface *wlr_surface) { + ++ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::SurfaceCommit ); ++ droiddeck::frame_trace::Record( ++ ( wlr_surface->current.committed & WLR_SURFACE_STATE_BUFFER ) ++ ? droiddeck::frame_trace::Event::SurfaceCommitBuffer ++ : droiddeck::frame_trace::Event::SurfaceCommitNoBuffer ); ++ + wlr_surface->current.committed = 0; + diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-diagnostic-inventory b/tools/linuxfs/overlay/usr/local/bin/droiddeck-diagnostic-inventory new file mode 100755 index 0000000000..947c5bb1c3 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-diagnostic-inventory @@ -0,0 +1,446 @@ +#!/usr/bin/env python3 +import argparse +import hashlib +import json +import os +from pathlib import Path +import re +import sys +import time + + +PREFIX = "DROIDDECK_PROCESS_TRACE " +SCHEMA = 1 +DEFAULT_INTERVAL_MS = 5_000 +DEFAULT_DURATION_MS = 86_400_000 +DEFAULT_MAX_RECORDS = 512 +HEARTBEAT_MS = 300_000 +MAX_PROCESSES = 256 +MAX_MAP_BYTES = 8 * 1024 * 1024 +MAX_MAP_LINES = 65_536 +MAX_LIBRARIES = 128 +MAX_CMDLINE_BYTES = 16 * 1024 +MAX_ENUMERATED_PROCESSES = 4_096 +MAX_CHILDREN_BYTES = 64 * 1024 +SAFE_LIBRARY = re.compile(r"[A-Za-z0-9._+-]{1,128}") +WINDOWS_GRAPHICS_LIBRARIES = { + "d3d8.dll", "d3d9.dll", "d3d10.dll", "d3d10_1.dll", "d3d10core.dll", + "d3d11.dll", "d3d12.dll", "dxgi.dll", "vulkan-1.dll", +} +KNOWN_GRAPHICS_SONAMES = { + "libvulkan.so", "libvulkan_freedreno.so", "libvulkan_panfrost.so", "libvulkan_lvp.so", + "libvulkan_virtio.so", "libvulkan_dzn.so", "libvulkan_broadcom.so", + "libEGL.so", "libEGL_mesa.so", "libGLESv1_CM.so", "libGLESv2.so", "libGLESv3.so", + "libGL.so", "libGLX.so", "libGLX_mesa.so", "libgbm.so", "libwayland-client.so", + "libX11.so", "libX11-xcb.so", "libdrm.so", "libdrm_amdgpu.so", "libdrm_freedreno.so", + "libdrm_intel.so", "libdrm_nouveau.so", "libdrm_radeon.so", "libxcb.so", "libxcb-dri2.so", + "libxcb-dri3.so", "libxcb-glx.so", "libxcb-present.so", "libxcb-randr.so", "libxcb-render.so", + "libxcb-shm.so", "libxcb-sync.so", "libxcb-xfixes.so", "libhybris-vulkan-icd.so", + "libVkLayer_hybris_compat.so", "libVkLayer_DROIDDECK_placed_memory.so", + "libVkLayer_KHRONOS_validation.so", "libVkLayer_FROG_gamescope_wsi_aarch64.so", + "libVkLayer_MESA_device_select.so", "libVkLayer_MESA_overlay.so", "libvkd3d.so", + "libvkd3d-shader.so", "libvkd3d-utils.so", +} + + +def emit(payload, output=sys.stdout): + output.write(PREFIX + json.dumps(payload, separators=(",", ":"), sort_keys=True) + "\n") + output.flush() + + +def process_stat(path): + text = path.read_text(errors="replace") + end = text.rfind(") ") + if end < 0: + raise ValueError("invalid process stat") + fields = text[end + 2:].split() + if len(fields) < 20: + raise ValueError("short process stat") + return int(fields[1]), fields[19] + + +def bounded_bytes(path, limit): + with path.open("rb") as source: + return source.read(limit) + + +def process_role(comm, cmdline): + probe = (comm + "\0" + cmdline.decode("utf-8", "replace")).lower() + if "steamwebhelper" in probe: + return "steam-webhelper" + if "gamescope" in probe: + return "gamescope" + if "xwayland" in probe: + return "xwayland" + if "mangoapp" in probe: + return "mangoapp" + if "pressure-vessel" in probe or "steam-runtime" in probe: + return "steam-runtime" + if "steamrtarm64/steam" in probe or "steamrt64/steam" in probe or comm.lower() == "steam": + return "steam-client" + if "fexinterpreter" in probe or comm.lower() == "fex": + return "fex" + if "wineserver" in probe: + return "wineserver" + if any(name in probe for name in ("wine64", "wine-preloader", "/wine ")): + return "wine" + if "pipewire" in probe or "pulseaudio" in probe: + return "audio-server" + if "dbus-daemon" in probe: + return "dbus" + if "droiddeck-session" in probe: + return "session" + return "game-or-helper" + + +def is_graphics_library(name): + lower = name.lower() + return ( + lower in WINDOWS_GRAPHICS_LIBRARIES or + lower.startswith(("libvulkan", "libvklayer", "vulkan.", "libegl", "libgles", "libglx", + "libgl.so", "libgbm", "libdrm", "libwayland", "libxcb", "libx11")) or + "vkd3d" in lower or "dxvk" in lower or "zink" in lower or "mangohud" in lower + ) + + +def origin_class(path): + lower = path.lower() + if lower.startswith("/vendor/"): + return "android-vendor" + if lower.startswith(("/system/", "/apex/")): + return "android-system" + if "/files/components/" in lower or "/files/system_vulkan/" in lower: + return "droiddeck-component" + if "/steamapps/common/" in lower: + return "steam-tool" + if lower.startswith(("/usr/", "/lib/", "/opt/")): + return "guest-runtime" + if lower.startswith("/tmp/"): + return "temporary" + return "other" + + +def library_identity(name, origin): + if origin in {"android-vendor", "android-system"}: + return name + base = name + while True: + head, separator, tail = base.rpartition(".") + if not separator or not tail.isdigit(): + break + base = head + if name.lower() in WINDOWS_GRAPHICS_LIBRARIES or base in KNOWN_GRAPHICS_SONAMES: + return name + return "sha256:" + hashlib.sha256(name.encode()).hexdigest()[:16] + + +def graphics_libraries(maps_path): + libraries = set() + total = 0 + lines = 0 + with maps_path.open("rb") as source: + while lines < MAX_MAP_LINES and total < MAX_MAP_BYTES: + raw = source.readline(min(64 * 1024, MAX_MAP_BYTES - total + 1)) + if not raw: + break + total += len(raw) + lines += 1 + if total > MAX_MAP_BYTES: + return libraries, "capped" + parts = raw.decode("utf-8", "replace").rstrip("\n").split(None, 5) + if len(parts) < 6 or not parts[5].startswith("/"): + continue + mapped = parts[5].removesuffix(" (deleted)") + name = os.path.basename(mapped) + if SAFE_LIBRARY.fullmatch(name) and is_graphics_library(name): + origin = origin_class(mapped) + libraries.add((library_identity(name, origin), origin)) + if len(libraries) >= MAX_LIBRARIES: + return libraries, "capped" + return libraries, "readable" + + +class Collector: + def __init__(self, proc_root, root_pid): + self.proc_root = Path(proc_root) + self.root_pid = int(root_pid) + self.known = {} + self.tokens = {} + self.next_token = 1 + self.self_pid = os.getpid() + self.root_identity = None + self.last_maps_state = None + self.last_provider_error = None + + def _scan_fallback(self, result): + capped = False + try: + entries = self.proc_root.iterdir() + except OSError: + return capped, "proc-unavailable" + examined = 0 + for entry in entries: + if not entry.name.isdigit(): + continue + examined += 1 + if examined > MAX_ENUMERATED_PROCESSES: + capped = True + break + pid = int(entry.name) + if pid == self.self_pid or pid in result: + continue + try: + result[pid] = process_stat(entry / "stat") + except (OSError, ValueError): + continue + return capped, None + + def _stats(self): + result = {} + capped = False + try: + ppid, start = process_stat(self.proc_root / str(self.root_pid) / "stat") + if self.root_pid != self.self_pid: + result[self.root_pid] = (ppid, start) + except (OSError, ValueError): + return result, capped, "proc-unavailable", "children", True + queue = [self.root_pid] + fallback = False + while queue and len(result) < MAX_PROCESSES: + parent = queue.pop(0) + try: + raw = bounded_bytes( + self.proc_root / str(parent) / "task" / str(parent) / "children", MAX_CHILDREN_BYTES + 1, + ) + except OSError: + fallback = True + continue + if len(raw) > MAX_CHILDREN_BYTES: + capped = True + fallback = True + continue + for value in raw.split(): + if not value.isdigit(): + continue + pid = int(value) + if pid == self.self_pid or pid in result: + continue + if len(result) >= MAX_PROCESSES: + capped = True + break + try: + identity = process_stat(self.proc_root / str(pid) / "stat") + except (OSError, ValueError): + continue + if identity[0] != parent: + continue + result[pid] = identity + queue.append(pid) + if queue: + capped = True + if fallback: + fallback_capped, error = self._scan_fallback(result) + capped = capped or fallback_capped + return result, capped, error, "children+scan-fallback", True + return result, capped, None, "children", capped + + def scan(self): + stats, enumeration_capped, provider_error, scope_method, scope_incomplete = self._stats() + descendants = set() + root = stats.get(self.root_pid) + if self.root_identity is None and root is not None: + self.root_identity = root + if root is not None and self.root_identity != root: + provider_error = "root-reused" + elif root is not None: + descendants.add(self.root_pid) + changed = True + while changed and len(descendants) < MAX_PROCESSES: + changed = False + for pid, (ppid, _) in stats.items(): + if pid not in descendants and ppid in descendants: + descendants.add(pid) + changed = True + if len(descendants) >= MAX_PROCESSES: + break + if provider_error is None and root is None: + provider_error = "root-unavailable" + scope_capped = len(descendants) >= MAX_PROCESSES or enumeration_capped + current = {} + maps_state = {"readable": 0, "unavailable": 0, "capped": 0} + for pid in sorted(descendants): + process = self.proc_root / str(pid) + try: + expected = stats[pid] + if process_stat(process / "stat") != expected: + continue + ppid, start = expected + comm = (process / "comm").read_text(errors="replace")[:128].strip() + cmdline = bounded_bytes(process / "cmdline", MAX_CMDLINE_BYTES) + except (OSError, ValueError): + continue + key = (pid, start) + try: + libraries, state = graphics_libraries(process / "maps") + except (OSError, ValueError): + libraries, state = set(), "unavailable" + maps_state[state] = maps_state.get(state, 0) + 1 + current[key] = { + "ppid": ppid, + "role": process_role(comm, cmdline), + "libraries": libraries, + "identity": expected, + "mapState": state, + } + stable = {} + for key, process in current.items(): + pid = key[0] + try: + if process_stat(self.proc_root / str(pid) / "stat") != process["identity"]: + continue + except (OSError, ValueError): + continue + stable[key] = process + final = {} + valid_pids = {self.root_pid} if any(key[0] == self.root_pid for key in stable) else set() + changed = True + while changed: + changed = False + for key, process in stable.items(): + pid = key[0] + if key not in final and (pid == self.root_pid or process["ppid"] in valid_pids): + final[key] = process + valid_pids.add(pid) + changed = True + current = final + try: + root_final = process_stat(self.proc_root / str(self.root_pid) / "stat") + except (OSError, ValueError): + root_final = None + if root_final is None: + if provider_error is None: + provider_error = "root-unavailable" + current = {} + elif self.root_identity != root_final: + provider_error = "root-reused" + current = {} + maps_state = {"readable": 0, "unavailable": 0, "capped": 0} + for process in current.values(): + state = process["mapState"] + maps_state[state] = maps_state.get(state, 0) + 1 + started = sorted(set(current) - set(self.known)) + exited = sorted(set(self.known) - set(current)) + roles_changed = any( + key in self.known and current[key]["role"] != self.known[key]["role"] for key in current + ) + for key in started: + self.tokens[key] = self.next_token + self.next_token += 1 + state_changed = maps_state != self.last_maps_state or provider_error != self.last_provider_error + payload = self._snapshot( + current, started, exited, maps_state, scope_capped, provider_error, scope_method, scope_incomplete, + ) + for key in exited: + self.tokens.pop(key, None) + self.known = current + self.last_maps_state = maps_state + self.last_provider_error = provider_error + return payload, bool(started or exited or roles_changed or payload["librariesChanged"] or state_changed) + + def _snapshot(self, current, started, exited, maps_state, scope_capped, provider_error, + scope_method, scope_incomplete): + previous_libraries = {item for process in self.known.values() for item in process["libraries"]} + libraries = {item for process in current.values() for item in process["libraries"]} + role_counts = {} + for process in current.values(): + role = process["role"] + role_counts[role] = role_counts.get(role, 0) + 1 + started_rows = [{"token": self.tokens[key], "role": current[key]["role"]} for key in started[:32]] + exited_rows = [{"token": self.tokens.get(key, 0), "role": self.known[key]["role"]} for key in exited[:32]] + library_rows = [{"name": name, "origin": origin} for name, origin in sorted(libraries)[:MAX_LIBRARIES]] + return { + "schema": SCHEMA, + "event": "snapshot", + "scope": "root-descendants", + "scopeMethod": scope_method, + "scopeIncomplete": scope_incomplete, + "procView": "guest-visible", + "alive": len(current), + "roles": role_counts, + "started": started_rows, + "startedOmitted": max(0, len(started) - len(started_rows)), + "exited": exited_rows, + "exitedOmitted": max(0, len(exited) - len(exited_rows)), + "libraries": library_rows, + "librariesOmitted": max(0, len(libraries) - len(library_rows)), + "librariesChanged": libraries != previous_libraries, + "maps": maps_state, + "scopeCapped": scope_capped, + "providerStatus": provider_error or "available", + } + + +def parse_args(argv): + parser = argparse.ArgumentParser() + parser.add_argument("--once", action="store_true") + parser.add_argument("--watch", action="store_true") + parser.add_argument("--root-pid", type=int, default=os.getppid()) + parser.add_argument("--proc-root", default="/proc") + parser.add_argument("--interval-ms", type=int, default=DEFAULT_INTERVAL_MS) + parser.add_argument("--duration-ms", type=int, default=DEFAULT_DURATION_MS) + parser.add_argument("--max-records", type=int, default=DEFAULT_MAX_RECORDS) + args = parser.parse_args(argv) + if args.once == args.watch: + parser.error("choose exactly one of --once or --watch") + if args.root_pid <= 0: + parser.error("--root-pid must be positive") + args.interval_ms = min(60_000, max(250, args.interval_ms)) + args.duration_ms = min(DEFAULT_DURATION_MS, max(0, args.duration_ms)) + args.max_records = min(1_024, max(3, args.max_records)) + return args + + +def main(argv=None, environ=None, output=sys.stdout): + environ = os.environ if environ is None else environ + if environ.get("DROIDDECK_ENHANCED_DIAGNOSTICS") != "1": + return 0 + args = parse_args(sys.argv[1:] if argv is None else argv) + collector = Collector(args.proc_root, args.root_pid) + emit({ + "schema": SCHEMA, + "event": "provider", + "mode": "once" if args.once else "watch", + "intervalMs": args.interval_ms, + "durationMs": 0 if args.once else args.duration_ms, + "maxRecords": args.max_records, + "scope": "root-descendants", + "procView": "guest-visible", + }, output) + records = 1 + started = time.monotonic() + last_heartbeat = started + ended_normally = False + while records < args.max_records - 1: + payload, changed = collector.scan() + now = time.monotonic() + if changed or records == 1 or (now - last_heartbeat) * 1000 >= HEARTBEAT_MS: + if not changed and records > 1: + payload["event"] = "heartbeat" + payload.pop("libraries", None) + payload["librariesUnchanged"] = True + payload["elapsedMs"] = int((now - started) * 1000) + emit(payload, output) + records += 1 + last_heartbeat = now + if args.once or payload["providerStatus"] in {"root-unavailable", "root-reused"} or \ + (now - started) * 1000 >= args.duration_ms: + ended_normally = True + break + time.sleep(args.interval_ms / 1000) + if not ended_normally: + emit({"schema": SCHEMA, "event": "limit", "reason": "max-records"}, output) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index 5624cbc2be..ac7cd5189c 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -970,7 +970,7 @@ def ego_core_plan(command, env): return "%s had no thread plan for %d cores; added a copy of its %s-core plan" % (EGO_RESTRICTIONS, count, source.group(2)) -def wait_forwarding_signals(process): +def wait_forwarding_signals_raw(process): def forward(signum, frame): try: process.send_signal(signum) @@ -983,22 +983,55 @@ def wait_forwarding_signals(process): finally: for signum, handler in previous.items(): signal.signal(signum, handler) + return code + + +def wait_forwarding_signals(process): + code = wait_forwarding_signals_raw(process) return 128 - code if code < 0 else code -def start(launch, launch_env, digest, after=None): +def diagnostic_game_event(event, app_id, values=None): + fields = ["event=" + event, "app_id=" + app_id] + fields.extend("%s=%s" % item for item in (values or {}).items()) + print("DROIDDECK_DIAGNOSTICS " + " ".join(fields), file=sys.stderr, flush=True) + + +def diagnostic_game_exit(app_id, raw_code, source=None, wrapper_status=None): + normalized = 128 - raw_code if raw_code < 0 else raw_code + values = { + "raw_status": raw_code, + "normalized_status": normalized, + "wrapper_status": normalized if wrapper_status is None else wrapper_status, + "signal": -raw_code if raw_code < 0 else 0, + } + if source is not None: + values["source"] = source + diagnostic_game_event("game_exit", app_id, values) + + +def start(launch, launch_env, digest, after=None, diagnostic_app_id=None): if len(launch) > 1 and launch[1] == "waitforexitandrun": ubisoft_composition_off(launch[0], launch_env) - if after: + if after or diagnostic_app_id is not None: process = subprocess.Popen(launch, env=launch_env) + if diagnostic_app_id is not None: + diagnostic_game_event("game_start", diagnostic_app_id) try: - return wait_forwarding_signals(process) + raw_code = wait_forwarding_signals_raw(process) finally: - try: - after() - except OSError as error: - print("droiddeck-game-env: DiRT telemetry fix: prefix ws2_32 not put back (%s); the next launch does it" % error, - file=sys.stderr) + if after: + try: + after() + except OSError as error: + print("droiddeck-game-env: DiRT telemetry fix: prefix ws2_32 not put back (%s); the next launch does it" % error, + file=sys.stderr) + code = 128 - raw_code if raw_code < 0 else raw_code + if digest and after is None and code == 0: + record_install_scripts(digest, launch_env) + if diagnostic_app_id is not None: + diagnostic_game_exit(diagnostic_app_id, raw_code) + return code if digest: code = subprocess.run(launch, env=launch_env, check=False).returncode if code == 0: @@ -1023,10 +1056,11 @@ def main(): except OSError: digest = None app_id = game_id(env) + waiting = bool(app_id and len(command) > 1 and command[1] == "waitforexitandrun") + diagnostic_app_id = app_id if waiting and os.environ.get("DROIDDECK_ENHANCED_DIAGNOSTICS") == "1" else None dirt_prefix = None if app_id: gl_default = gl_vsync(env) - waiting = len(command) > 1 and command[1] == "waitforexitandrun" if waiting: game_images(env) fixes = {} @@ -1104,6 +1138,8 @@ def main(): print("droiddeck-game-env: Xbox launch could not start (%s)" % error, file=sys.stderr) return 1 if xbox_result is not None: + if diagnostic_app_id is not None and isinstance(xbox_result, int): + diagnostic_game_exit(diagnostic_app_id, xbox_result, "xbox", xbox_result % 256) return xbox_result after = None prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/") @@ -1129,13 +1165,13 @@ def main(): launch, launch_env = select_sync(command, env, sync) if launch[0] != command[0]: try: - return start(launch, launch_env, digest, after) + return start(launch, launch_env, digest, after, diagnostic_app_id) except OSError as error: print("droiddeck-game-env: %s could not start (%s); stock launch" % (launch[0], error), file=sys.stderr) launch, launch_env = command, without_pack(launch_env, env) record_stock(sync, launch, launch_env) try: - return start(launch, launch_env, digest, after) + return start(launch, launch_env, digest, after, diagnostic_app_id) except OSError: if after: try: diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 9f7747c6a5..4ebfbc00ea 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -22,6 +22,19 @@ if [ -n "${BL_LOG:-}" ] && [ -z "${BL_INSIDE:-}" ]; then echo "== rootfs: $(cat /.version 2>/dev/null || echo unversioned)" fi +start_diagnostic_inventory() { + [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ] || return 0 + [ -z "${BL_INSIDE:-}" ] || return 0 + if ! command -v droiddeck-diagnostic-inventory >/dev/null 2>&1; then + printf '%s\n' 'DROIDDECK_PROCESS_TRACE {"schema":1,"event":"provider","status":"unavailable"}' + return 0 + fi + droiddeck-diagnostic-inventory --watch --root-pid "$$" & + _bl_diagnostic_inventory=$! + trap 'kill "$_bl_diagnostic_inventory" 2>/dev/null || true; wait "$_bl_diagnostic_inventory" 2>/dev/null || true' EXIT +} +start_diagnostic_inventory + sync_timezone() { local zone=${TZ:-} case "$zone" in ''|/*|*..*) return 0 ;; esac @@ -141,8 +154,13 @@ run_gamescope() ( BL_STEAM_EXIT_FILE="$status_file" gamescope "$@" compositor_status=$? if read -r child_status < "$status_file" && [[ $child_status =~ ^[0-9]{1,3}$ ]] \ - && [ "$child_status" -gt 0 ] && [ "$child_status" -le 255 ]; then - exit "$child_status" + && [ "$child_status" -le 255 ]; then + if [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ]; then + printf 'DROIDDECK_DIAGNOSTICS event=session_exit compositor_status=%s steam_status=%s\n' "$compositor_status" "$child_status" + fi + [ "$child_status" -eq 0 ] || exit "$child_status" + elif [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ]; then + printf 'DROIDDECK_DIAGNOSTICS event=session_exit compositor_status=%s steam_status=unavailable\n' "$compositor_status" fi exit "$compositor_status" ) @@ -1489,6 +1507,9 @@ case $mode in wait "$desktop_ui_pid" 2>/dev/null || true fi echo "== steam exited rc=$rc" + if [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ]; then + printf 'DROIDDECK_DIAGNOSTICS event=steam_exit shell_status=%s elapsed_seconds=%s\n' "$rc" "$steam_ran" + fi collect_steam_logs if [ -f "$HOME/.config/droiddeck/fex-wanted" ] && [ -x /usr/local/bin/droiddeck-fex ]; then /usr/local/bin/droiddeck-fex status >/dev/null 2>&1 || true diff --git a/tools/tests/test_diagnostic_inventory.py b/tools/tests/test_diagnostic_inventory.py new file mode 100644 index 0000000000..9283f064ec --- /dev/null +++ b/tools/tests/test_diagnostic_inventory.py @@ -0,0 +1,234 @@ +import io +import json +import os +from pathlib import Path +import runpy +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[2] +SCRIPT = ROOT / "tools/linuxfs/overlay/usr/local/bin/droiddeck-diagnostic-inventory" +MODULE = runpy.run_path(str(SCRIPT), run_name="droiddeck_diagnostic_inventory") + + +def write_process(root, pid, ppid, start, comm, cmdline, maps=None): + process = root / str(pid) + process.mkdir(parents=True) + children = process / "task" / str(pid) / "children" + children.parent.mkdir(parents=True) + children.write_text("") + fields = ["S", str(ppid)] + ["0"] * 17 + [str(start)] + (process / "stat").write_text(f"{pid} ({comm}) " + " ".join(fields) + "\n") + (process / "comm").write_text(comm + "\n") + (process / "cmdline").write_bytes(cmdline.replace(" ", "\0").encode() + b"\0") + if maps is not None: + (process / "maps").write_text("".join( + f"1000-2000 r-xp 00000000 00:00 0 {path}\n" for path in maps + )) + parent_children = root / str(ppid) / "task" / str(ppid) / "children" + if parent_children.is_file(): + existing = parent_children.read_text().split() + if str(pid) not in existing: + parent_children.write_text(" ".join(existing + [str(pid)]) + "\n") + return process + + +def rows(text): + prefix = MODULE["PREFIX"] + return [json.loads(line.removeprefix(prefix)) for line in text.splitlines() if line.startswith(prefix)] + + +class DiagnosticInventoryTest(unittest.TestCase): + def test_default_off_produces_no_output(self): + with tempfile.TemporaryDirectory() as directory: + output = io.StringIO() + result = MODULE["main"]( + ["--once", "--root-pid", "100", "--proc-root", directory], {}, output, + ) + self.assertEqual(result, 0) + self.assertEqual(output.getvalue(), "") + + def test_once_scopes_processes_and_reports_only_safe_graphics_identity(self): + with tempfile.TemporaryDirectory() as directory: + proc = Path(directory) + write_process(proc, 100, 1, 10, "droiddeck-session", "/usr/local/bin/droiddeck-session steam", [ + "/usr/lib/libvulkan.so.1", + ]) + write_process(proc, 101, 100, 11, "steam", "/secret/account/steam -login private-token", [ + "/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libVkLayer_hybris_compat.so", + "/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libvulkan-private-account.so", + "/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libdrm_accountSecret.so", + "/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libxcb-sessionSecret.so", + "/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libvkd3d-userSecret.so", + "/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libdrm_amdgpu.so.1.0.0", + "/home/private-user/not-graphics-secret.so", + "/home/private-user/libvulkan-private-user.so", + ]) + write_process(proc, 102, 101, 12, "steamwebhelper", "steamwebhelper --user-data-dir=/secret/profile", [ + "/vendor/lib64/hw/vulkan.samsung.so", + "/tmp/libvulkan-secret with spaces.so", + ]) + write_process(proc, 103, 101, 13, "private-game-title", "private-game-title --token=child-secret", []) + write_process(proc, 200, 1, 20, "unrelated", "unrelated --password=hunter2", [ + "/vendor/lib64/hw/vulkan.unrelated.so", + ]) + output = io.StringIO() + MODULE["main"]( + ["--once", "--root-pid", "100", "--proc-root", directory], + {"DROIDDECK_ENHANCED_DIAGNOSTICS": "1"}, output, + ) + payloads = rows(output.getvalue()) + self.assertEqual(payloads[0]["event"], "provider") + snapshot = payloads[1] + self.assertEqual(snapshot["alive"], 4) + self.assertEqual(snapshot["roles"], { + "game-or-helper": 1, "session": 1, "steam-client": 1, "steam-webhelper": 1, + }) + self.assertEqual(snapshot["providerStatus"], "available") + self.assertEqual(snapshot["scopeMethod"], "children") + self.assertFalse(snapshot["scopeIncomplete"]) + libraries = {(item["name"], item["origin"]) for item in snapshot["libraries"]} + self.assertIn(("libvulkan.so.1", "guest-runtime"), libraries) + self.assertIn(("libVkLayer_hybris_compat.so", "droiddeck-component"), libraries) + self.assertIn(("libdrm_amdgpu.so.1.0.0", "droiddeck-component"), libraries) + self.assertIn(("vulkan.samsung.so", "android-vendor"), libraries) + self.assertTrue(any(name.startswith("sha256:") and origin == "other" for name, origin in libraries)) + self.assertGreaterEqual(sum(name.startswith("sha256:") and origin == "droiddeck-component" + for name, origin in libraries), 4) + text = output.getvalue() + for secret in ("private-token", "private-user", "child-secret", "private-game-title", "hunter2", + "accountSecret", "sessionSecret", "userSecret", "unrelated", "/vendor/", "/data/user/"): + self.assertNotIn(secret, text) + + def test_missing_maps_and_proc_are_explicit(self): + with tempfile.TemporaryDirectory() as directory: + proc = Path(directory) + write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session") + collector = MODULE["Collector"](proc, 100) + snapshot, _ = collector.scan() + self.assertEqual(snapshot["maps"]["unavailable"], 1) + self.assertEqual(snapshot["providerStatus"], "available") + missing = MODULE["Collector"](proc / "missing", 100) + snapshot, _ = missing.scan() + self.assertEqual(snapshot["providerStatus"], "proc-unavailable") + + def test_children_fallback_is_explicitly_incomplete(self): + with tempfile.TemporaryDirectory() as directory: + proc = Path(directory) + process = write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", []) + write_process(proc, 101, 100, 11, "steam", "steam", []) + (process / "task" / "100" / "children").unlink() + collector = MODULE["Collector"](proc, 100) + snapshot, _ = collector.scan() + self.assertEqual(snapshot["alive"], 2) + self.assertEqual(snapshot["scopeMethod"], "children+scan-fallback") + self.assertTrue(snapshot["scopeIncomplete"]) + + def test_pid_reuse_is_an_exit_and_a_new_process(self): + with tempfile.TemporaryDirectory() as directory: + proc = Path(directory) + write_process(proc, 99, 1, 9, "droiddeck-session", "droiddeck-session", []) + process = write_process(proc, 100, 99, 10, "steam", "steam", []) + collector = MODULE["Collector"](proc, 99) + first, _ = collector.scan() + first_token = next(row["token"] for row in first["started"] if row["role"] == "steam-client") + fields = ["S", "99"] + ["0"] * 17 + ["20"] + (process / "stat").write_text("100 (steam) " + " ".join(fields) + "\n") + second, changed = collector.scan() + self.assertTrue(changed) + self.assertEqual(next(row["token"] for row in second["exited"] if row["role"] == "steam-client"), first_token) + self.assertNotEqual( + next(row["token"] for row in second["started"] if row["role"] == "steam-client"), first_token, + ) + + def test_exec_role_change_is_reported_without_pid_reuse(self): + with tempfile.TemporaryDirectory() as directory: + proc = Path(directory) + process = write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", []) + collector = MODULE["Collector"](proc, 100) + collector.scan() + (process / "comm").write_text("gamescope\n") + (process / "cmdline").write_bytes(b"gamescope\0--backend\0wayland\0") + snapshot, changed = collector.scan() + self.assertTrue(changed) + self.assertEqual(snapshot["roles"], {"gamescope": 1}) + + def test_process_scope_is_bounded(self): + with tempfile.TemporaryDirectory() as directory: + proc = Path(directory) + write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", []) + for pid in range(101, 370): + write_process(proc, pid, 100, pid, "helper", "helper", []) + collector = MODULE["Collector"](proc, 100) + snapshot, _ = collector.scan() + self.assertLessEqual(snapshot["alive"], MODULE["MAX_PROCESSES"]) + self.assertTrue(snapshot["scopeCapped"]) + + def test_reused_root_pid_is_not_adopted(self): + with tempfile.TemporaryDirectory() as directory: + proc = Path(directory) + process = write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", []) + collector = MODULE["Collector"](proc, 100) + collector.scan() + fields = ["S", "1"] + ["0"] * 17 + ["20"] + (process / "stat").write_text("100 (unrelated-app) " + " ".join(fields) + "\n") + snapshot, _ = collector.scan() + self.assertEqual(snapshot["providerStatus"], "root-reused") + self.assertEqual(snapshot["alive"], 0) + self.assertNotIn("unrelated-app", json.dumps(snapshot)) + + def test_reparented_child_is_rejected_after_process_reads(self): + with tempfile.TemporaryDirectory() as directory: + proc = Path(directory) + write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", []) + child = write_process(proc, 101, 100, 11, "steam", "steam", []) + globals_ = MODULE["Collector"].scan.__globals__ + original = globals_["process_stat"] + calls = 0 + + def racing(path): + nonlocal calls + if path == child / "stat": + calls += 1 + if calls == 3: + fields = ["S", "1"] + ["0"] * 17 + ["11"] + path.write_text("101 (steam) " + " ".join(fields) + "\n") + return original(path) + + globals_["process_stat"] = racing + try: + collector = MODULE["Collector"](proc, 100) + snapshot, _ = collector.scan() + finally: + globals_["process_stat"] = original + self.assertEqual(snapshot["roles"], {"session": 1}) + self.assertEqual(snapshot["alive"], 1) + + def test_watch_is_bounded_and_emits_heartbeats_without_process_changes(self): + globals_ = MODULE["main"].__globals__ + original = globals_["HEARTBEAT_MS"] + globals_["HEARTBEAT_MS"] = 40 + try: + with tempfile.TemporaryDirectory() as directory: + proc = Path(directory) + write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", []) + output = io.StringIO() + MODULE["main"]( + ["--watch", "--root-pid", "100", "--proc-root", directory, + "--interval-ms", "250", "--duration-ms", "520", "--max-records", "4"], + {"DROIDDECK_ENHANCED_DIAGNOSTICS": "1"}, output, + ) + payloads = rows(output.getvalue()) + self.assertEqual(payloads[0]["event"], "provider") + self.assertEqual(payloads[1]["event"], "snapshot") + self.assertEqual(payloads[2]["event"], "heartbeat") + self.assertNotIn("libraries", payloads[2]) + self.assertTrue(payloads[2]["librariesUnchanged"]) + self.assertLessEqual(len(payloads), 4) + finally: + globals_["HEARTBEAT_MS"] = original + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_diagnostic_session_integration.py b/tools/tests/test_diagnostic_session_integration.py new file mode 100644 index 0000000000..2b55199092 --- /dev/null +++ b/tools/tests/test_diagnostic_session_integration.py @@ -0,0 +1,50 @@ +import os +from pathlib import Path +import re +import subprocess +import tempfile +import unittest + + +SESSION = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-session' + + +class DiagnosticSessionIntegrationTest(unittest.TestCase): + def run_inventory(self, enabled, inside=False, installed=True): + source = SESSION.read_text() + match = re.search(r'^start_diagnostic_inventory\(\) \{\n.*?^\}\n', source, re.M | re.S) + self.assertIsNotNone(match) + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + marker = root / 'called' + if installed: + helper = root / 'droiddeck-diagnostic-inventory' + helper.write_text('#!/bin/bash\nprintf "%s\\n" "$@" > "$MARKER"\n') + helper.chmod(0o755) + env = dict(os.environ, PATH=str(root) + os.pathsep + os.environ['PATH'], + MARKER=str(marker), DROIDDECK_ENHANCED_DIAGNOSTICS='1' if enabled else '0') + env['BL_INSIDE'] = '1' if inside else '' + script = match.group() + '\nstart_diagnostic_inventory\n' + if installed and enabled and not inside: + script += 'wait "$_bl_diagnostic_inventory"\n' + result = subprocess.run(['bash', '-c', script], env=env, capture_output=True, text=True, timeout=10) + self.assertEqual(result.returncode, 0, result.stderr) + return marker.read_text().splitlines() if marker.exists() else [], result.stdout + + def test_starts_for_an_enhanced_outer_session(self): + arguments, _ = self.run_inventory(True) + self.assertEqual(arguments[:2], ['--watch', '--root-pid']) + self.assertTrue(arguments[2].isdigit()) + + def test_does_not_start_when_disabled_or_inside_gamescope(self): + self.assertEqual(self.run_inventory(False)[0], []) + self.assertEqual(self.run_inventory(True, inside=True)[0], []) + + def test_reports_when_the_provider_is_not_installed(self): + _, output = self.run_inventory(True, installed=False) + self.assertIn('DROIDDECK_PROCESS_TRACE', output) + self.assertIn('"status":"unavailable"', output) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/tests/test_game_exit_diagnostics.py b/tools/tests/test_game_exit_diagnostics.py new file mode 100644 index 0000000000..262366b5e6 --- /dev/null +++ b/tools/tests/test_game_exit_diagnostics.py @@ -0,0 +1,186 @@ +import contextlib +import io +import os +from pathlib import Path +import runpy +import signal +import subprocess +import sys +import tempfile +from unittest import mock +import unittest + + +BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin" +GAME_ENV = BIN / "droiddeck-game-env" +MODULE = runpy.run_path(str(GAME_ENV)) + + +class GameExitDiagnosticsTest(unittest.TestCase): + def run_child(self, body, app_id="42"): + with contextlib.redirect_stderr(io.StringIO()) as said: + status = MODULE["start"]( + [sys.executable, "-c", body], os.environ.copy(), None, + diagnostic_app_id=app_id, + ) + return status, said.getvalue() + + def test_clean_and_nonzero_exits_are_authoritative(self): + for child_status in (0, 7): + with self.subTest(status=child_status): + status, said = self.run_child("import sys; sys.exit(%d)" % child_status) + self.assertEqual(status, child_status) + self.assertIn("event=game_start app_id=42", said) + self.assertIn( + "event=game_exit app_id=42 raw_status=%d normalized_status=%d wrapper_status=%d signal=0" % + (child_status, child_status, child_status), said, + ) + + def test_signal_exit_is_normalized_and_records_the_signal(self): + status, said = self.run_child("import os, signal; os.kill(os.getpid(), signal.SIGTERM)") + self.assertEqual(status, 128 + signal.SIGTERM) + self.assertIn( + "event=game_exit app_id=42 raw_status=-15 normalized_status=143 wrapper_status=143 signal=15", said, + ) + + def test_xbox_exit_is_recorded_without_inventing_a_start(self): + with contextlib.redirect_stderr(io.StringIO()) as said: + MODULE["diagnostic_game_exit"]("42", -signal.SIGTERM, "xbox", 241) + self.assertNotIn("event=game_start", said.getvalue()) + self.assertIn( + "event=game_exit app_id=42 raw_status=-15 normalized_status=143 wrapper_status=241 signal=15 source=xbox", + said.getvalue(), + ) + + def test_signal_handler_forwards_to_the_child(self): + class Process: + def __init__(self): + self.forwarded = [] + + def send_signal(self, signum): + self.forwarded.append(signum) + + def wait(self): + os.kill(os.getpid(), signal.SIGTERM) + return -signal.SIGTERM + + process = Process() + self.assertEqual(MODULE["wait_forwarding_signals"](process), 128 + signal.SIGTERM) + self.assertEqual(process.forwarded, [signal.SIGTERM]) + + def test_default_path_still_execs_in_place_without_diagnostic_output(self): + called = [] + with mock.patch("os.execvpe", side_effect=lambda *args: called.append(args)), \ + contextlib.redirect_stderr(io.StringIO()) as said: + MODULE["start"](["/game", "arg"], {"A": "B"}, None) + self.assertEqual(called, [("/game", ["/game", "arg"], {"A": "B"})]) + self.assertNotIn("DROIDDECK_DIAGNOSTICS", said.getvalue()) + + def test_failed_selected_launch_does_not_invent_a_start_or_exit(self): + with mock.patch("subprocess.Popen", side_effect=FileNotFoundError("missing")), \ + contextlib.redirect_stderr(io.StringIO()) as said: + with self.assertRaises(FileNotFoundError): + MODULE["start"](["/missing"], {}, None, diagnostic_app_id="42") + self.assertNotIn("DROIDDECK_DIAGNOSTICS", said.getvalue()) + + def test_cleanup_runs_after_a_diagnostic_child(self): + cleaned = [] + with contextlib.redirect_stderr(io.StringIO()): + status = MODULE["start"]( + [sys.executable, "-c", "pass"], os.environ.copy(), None, + after=lambda: cleaned.append(True), diagnostic_app_id="42", + ) + self.assertEqual(status, 0) + self.assertEqual(cleaned, [True]) + + def test_diagnostic_install_script_keeps_success_recording(self): + recorded = [] + with mock.patch.dict(MODULE["start"].__globals__, record_install_scripts=lambda digest, env: recorded.append((digest, env))), \ + contextlib.redirect_stderr(io.StringIO()): + status = MODULE["start"]( + [sys.executable, "-c", "pass"], {"CUSTOM": "kept"}, "digest", + diagnostic_app_id="42", + ) + self.assertEqual(status, 0) + self.assertEqual(recorded, [("digest", {"CUSTOM": "kept"})]) + + def test_cleanup_path_keeps_the_original_install_recording_precedence(self): + recorded = [] + with mock.patch.dict(MODULE["start"].__globals__, record_install_scripts=lambda digest, env: recorded.append((digest, env))): + status = MODULE["start"]( + [sys.executable, "-c", "pass"], {"CUSTOM": "kept"}, "digest", + after=lambda: None, + ) + self.assertEqual(status, 0) + self.assertEqual(recorded, []) + + def test_main_only_traces_valid_waitforexitandrun_games(self): + with tempfile.TemporaryDirectory(prefix="game-exit-diagnostics-") as directory: + root = Path(directory) + probe = root / "probe" + probe.write_text("#!" + sys.executable + "\nimport sys\nsys.exit(7)\n") + probe.chmod(0o755) + base = dict(os.environ, HOME=directory, PATH=os.defpath, + DROIDDECK_ENHANCED_DIAGNOSTICS="1") + valid = subprocess.run( + [sys.executable, str(GAME_ENV), str(probe), "waitforexitandrun"], + env={**base, "STEAM_COMPAT_DATA_PATH": "/compatdata/42"}, + capture_output=True, text=True, timeout=15, + ) + self.assertEqual(valid.returncode, 7, valid.stderr) + self.assertIn("event=game_start app_id=42", valid.stderr) + self.assertIn( + "event=game_exit app_id=42 raw_status=7 normalized_status=7 wrapper_status=7 signal=0", valid.stderr, + ) + + for verb, prefix in (("run", "/compatdata/42"), ("waitforexitandrun", "/compatdata/not-a-game")): + result = subprocess.run( + [sys.executable, str(GAME_ENV), str(probe), verb], + env={**base, "STEAM_COMPAT_DATA_PATH": prefix}, + capture_output=True, text=True, timeout=15, + ) + self.assertEqual(result.returncode, 7, result.stderr) + self.assertNotIn("DROIDDECK_DIAGNOSTICS", result.stderr) + + def test_main_records_xbox_result_without_changing_it(self): + launch = lambda command, env: 23 + with tempfile.TemporaryDirectory(prefix="xbox-exit-diagnostics-") as directory, \ + mock.patch.dict(os.environ, { + "HOME": directory, + "PATH": os.defpath, + "STEAM_COMPAT_DATA_PATH": "/compatdata/42", + "DROIDDECK_ENHANCED_DIAGNOSTICS": "1", + }, clear=True), \ + mock.patch("sys.argv", ["droiddeck-game-env", "/proton", "waitforexitandrun", "game.exe"]), \ + mock.patch("runpy.run_path", return_value={"launch": launch}), \ + contextlib.redirect_stderr(io.StringIO()) as said: + status = MODULE["main"]() + self.assertEqual(status, 23) + self.assertNotIn("event=game_start", said.getvalue()) + self.assertIn( + "event=game_exit app_id=42 raw_status=23 normalized_status=23 wrapper_status=23 signal=0 source=xbox", + said.getvalue(), + ) + + def test_main_preserves_negative_xbox_result_and_reports_wrapper_status(self): + launch = lambda command, env: -signal.SIGTERM + with tempfile.TemporaryDirectory(prefix="xbox-signal-diagnostics-") as directory, \ + mock.patch.dict(os.environ, { + "HOME": directory, + "PATH": os.defpath, + "STEAM_COMPAT_DATA_PATH": "/compatdata/42", + "DROIDDECK_ENHANCED_DIAGNOSTICS": "1", + }, clear=True), \ + mock.patch("sys.argv", ["droiddeck-game-env", "/proton", "waitforexitandrun", "game.exe"]), \ + mock.patch("runpy.run_path", return_value={"launch": launch}), \ + contextlib.redirect_stderr(io.StringIO()) as said: + status = MODULE["main"]() + self.assertEqual(status, -signal.SIGTERM) + self.assertIn( + "event=game_exit app_id=42 raw_status=-15 normalized_status=143 wrapper_status=241 signal=15 source=xbox", + said.getvalue(), + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_gamescope_diagnostics.py b/tools/tests/test_gamescope_diagnostics.py new file mode 100644 index 0000000000..80f639b0d0 --- /dev/null +++ b/tools/tests/test_gamescope_diagnostics.py @@ -0,0 +1,133 @@ +import os +from pathlib import Path +import re +import shutil +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[2] +PATCH = ROOT / "tools/gamescope/patches/0900-enhanced-frame-diagnostics.patch" + + +def added_file(patch, name): + lines = patch.read_text().splitlines() + marker = f"diff --git a/{name} b/{name}" + start = lines.index(marker) + output = [] + in_hunk = False + for line in lines[start + 1:]: + if line.startswith("diff --git "): + break + if line.startswith("@@"): + in_hunk = True + elif in_hunk and line.startswith("+") and not line.startswith("+++"): + output.append(line[1:]) + return "\n".join(output) + "\n" + + +class GamescopeDiagnosticsTest(unittest.TestCase): + def test_patch_covers_each_frame_boundary_without_payload_logging(self): + text = PATCH.read_text() + for path in ("src/wlserver.cpp", "src/steamcompmgr.cpp", "src/Backends/WaylandBackend.cpp"): + self.assertIn(f"diff --git a/{path} b/{path}", text) + self.assertIn("diff --git a/src/main.cpp b/src/main.cpp", text) + self.assertIn("droiddeck::frame_trace::Start();", text) + self.assertIn("droiddeck::frame_trace::Tick();", text) + self.assertIn("pTraceFocus->focusWindow == w", text) + self.assertNotIn("GetFocusForWindow( w ) != nullptr", text) + for event in ( + "X11Damage", "X11DamageCurrent", "X11DamageOther", "SurfaceCommit", + "SurfaceCommitBuffer", "SurfaceCommitNoBuffer", "CommitDequeued", + "CommitDequeuedCurrent", "CommitDequeuedOther", "ImportSucceeded", + "ImportSucceededCurrent", "ImportSucceededOther", "ImportFailed", + "ImportFailedCurrent", "ImportFailedOther", "FenceReady", "FenceWaited", + "CommitDone", "CommitDoneCurrent", "CommitDoneOther", "BaseLatched", + "BaseLatchedCurrent", "BaseLatchedOther", + "OutputPresent", "OutputAttach", "OutputDetach", + "OutputCommit", "OutputRelease", + ): + self.assertIn(f"Event::{event}", text) + header = added_file(PATCH, "src/droiddeck_frame_trace.hpp") + self.assertIn('std::getenv( "DROIDDECK_ENHANCED_DIAGNOSTICS" )', header) + self.assertIn("DROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS 2000", header) + self.assertIn("DROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS 15000", header) + self.assertIn("DROIDDECK_FRAME_TRACE_DURATION_MS 86400000", header) + self.assertNotRegex(header, re.compile(r"title|pixel|address|argv", re.I)) + + def test_collector_is_default_off_bounded_and_thread_safe(self): + compiler = shutil.which(os.environ.get("CXX", "c++")) + if not compiler: + self.skipTest("a C++ compiler is required") + with tempfile.TemporaryDirectory(prefix="gamescope-frame-trace-") as directory: + work = Path(directory) + (work / "droiddeck_frame_trace.hpp").write_text( + added_file(PATCH, "src/droiddeck_frame_trace.hpp")) + (work / "trace.cpp").write_text(r''' +#include "droiddeck_frame_trace.hpp" +#include <chrono> +#include <thread> +#include <vector> +int main() { + droiddeck::frame_trace::Start(); + std::vector<std::thread> threads; + for (int i = 0; i < 4; ++i) + threads.emplace_back([] { for (int n = 0; n < 1000; ++n) + droiddeck::frame_trace::RecordWindow( + droiddeck::frame_trace::Event::X11Damage, + droiddeck::frame_trace::Event::X11DamageCurrent, + droiddeck::frame_trace::Event::X11DamageOther, + false); }); + for (auto &thread : threads) thread.join(); + std::this_thread::sleep_for(std::chrono::milliseconds(60)); + droiddeck::frame_trace::Tick(); + std::this_thread::sleep_for(std::chrono::milliseconds(70)); + droiddeck::frame_trace::Tick(); + droiddeck::frame_trace::Record(droiddeck::frame_trace::Event::SurfaceCommit); + droiddeck::frame_trace::RecordWindow( + droiddeck::frame_trace::Event::ImportSucceeded, + droiddeck::frame_trace::Event::ImportSucceededCurrent, + droiddeck::frame_trace::Event::ImportSucceededOther, + true); + std::this_thread::sleep_for(std::chrono::milliseconds(70)); + droiddeck::frame_trace::Tick(); + std::this_thread::sleep_for(std::chrono::milliseconds(120)); + droiddeck::frame_trace::Tick(); + droiddeck::frame_trace::Record(droiddeck::frame_trace::Event::OutputPresent); + droiddeck::frame_trace::Tick(); +} +''') + program = work / "trace" + built = subprocess.run([ + compiler, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-pthread", + "-DDROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS=50", + "-DDROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS=60", + "-DDROIDDECK_FRAME_TRACE_FAST_DURATION_MS=100", + "-DDROIDDECK_FRAME_TRACE_DURATION_MS=300", + str(work / "trace.cpp"), "-o", str(program), + ], capture_output=True, text=True) + self.assertEqual(0, built.returncode, built.stdout + built.stderr) + quiet = subprocess.run([str(program)], capture_output=True, text=True, timeout=10) + self.assertEqual(0, quiet.returncode, quiet.stdout + quiet.stderr) + self.assertEqual("", quiet.stderr) + env = os.environ.copy() + env["DROIDDECK_ENHANCED_DIAGNOSTICS"] = "1" + traced = subprocess.run([str(program)], env=env, capture_output=True, text=True, timeout=10) + self.assertEqual(0, traced.returncode, traced.stdout + traced.stderr) + self.assertEqual(1, traced.stderr.count("schema=1")) + summaries = [line for line in traced.stderr.splitlines() if "t_ms=" in line] + self.assertIn("t_ms=0 x11_damage=0", summaries[0]) + self.assertTrue(any("x11_damage=4000" in line and "x11_damage_current=0" in line and + "x11_damage_other=4000" in line and "surface_commit=0" in line + for line in summaries[1:])) + self.assertTrue(any("surface_commit=1" in line for line in summaries[1:])) + self.assertTrue(any("import_ok=1" in line and "import_ok_current=1" in line and + "import_ok_other=0" in line for line in summaries[1:])) + self.assertIn("t_ms=300", summaries[-1]) + self.assertIn("output_present=0", summaries[-1]) + self.assertLessEqual(len(summaries), 5) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_steam_exit_status.py b/tools/tests/test_steam_exit_status.py index e66341febe..8cfc218ab3 100644 --- a/tools/tests/test_steam_exit_status.py +++ b/tools/tests/test_steam_exit_status.py @@ -11,7 +11,7 @@ SESSION = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/d class SteamExitStatusTest(unittest.TestCase): def run_session(self, child_status, compositor_status=0, report=True, report_value=None, - stale_status=None): + stale_status=None, diagnostics=False, output=False): source = SESSION.read_text() function = re.search(r'^run_gamescope\(\) \(\n.*?^\)\n', source, re.M | re.S) self.assertIsNotNone(function) @@ -31,6 +31,7 @@ class SteamExitStatusTest(unittest.TestCase): child.chmod(0o755) env = dict(os.environ, PATH=str(root) + os.pathsep + os.environ['PATH'], XDG_RUNTIME_DIR=str(root)) + env['DROIDDECK_ENHANCED_DIAGNOSTICS'] = '1' if diagnostics else '0' result = subprocess.run(['bash', '-c', function.group() + '\nrun_gamescope "$@"', 'session', str(child), str(child_status), str(report_value) if report_value is not None else ''], env=env, @@ -38,7 +39,7 @@ class SteamExitStatusTest(unittest.TestCase): self.assertEqual(list(root.glob('droiddeck-steam-exit.??????')), []) if stale_status is not None: self.assertEqual(stale_file.read_text(), str(stale_status) + '\n') - return result.returncode + return result if output else result.returncode def test_steam_crash_survives_successful_compositor_shutdown(self): self.assertEqual(self.run_session(139), 139) @@ -64,6 +65,21 @@ class SteamExitStatusTest(unittest.TestCase): def test_stale_marker_does_not_affect_a_new_launch(self): self.assertEqual(self.run_session(0, report=False, stale_status=139), 0) + def test_diagnostics_preserve_separate_steam_and_compositor_statuses(self): + result = self.run_session(139, diagnostics=True, output=True) + self.assertEqual(result.returncode, 139) + self.assertIn('event=session_exit compositor_status=0 steam_status=139', result.stdout) + + def test_diagnostics_report_an_unavailable_child_status(self): + result = self.run_session(0, compositor_status=1, report=False, diagnostics=True, output=True) + self.assertEqual(result.returncode, 1) + self.assertIn('event=session_exit compositor_status=1 steam_status=unavailable', result.stdout) + + def test_diagnostics_are_disabled_by_default(self): + result = self.run_session(0, output=True) + self.assertEqual(result.returncode, 0) + self.assertNotIn('DROIDDECK_DIAGNOSTICS', result.stdout) + if __name__ == '__main__': unittest.main() From 3c6447528a2b1d6e419f0f0fa6fde0e7889481a6 Mon Sep 17 00:00:00 2001 From: wallentx <william.allentx@gmail.com> Date: Wed, 4 Nov 2026 12:35:48 -0600 Subject: [PATCH 36/85] Make secure log export testable under Robolectric --- .../session/EnhancedSessionLogShare.kt | 19 +++++ .../session/EnhancedSessionLogShareTest.kt | 31 ++++++++ .../session/SecureSourceOpenerTestSupport.kt | 72 +++++++++++++++++++ .../launcher/session/SessionLogShareTest.kt | 6 ++ .../session/SessionLogShareZipTest.kt | 6 ++ 5 files changed, 134 insertions(+) create mode 100644 app/src/test/java/com/droiddeck/launcher/session/SecureSourceOpenerTestSupport.kt diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index 6d6f357d70..914e8c7b40 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -32,6 +32,10 @@ internal data class EnhancedShareLimits( val maxBytesTotal: Long = 64L * 1024 * 1024, ) +internal interface SecureSourceOpener { + fun <T> withChannel(root: Path, relative: Path, block: (SeekableByteChannel) -> T): T? +} + internal object EnhancedSessionLogShare { private enum class Category(val suffix: String) { SESSION("session"), GRAPHICS("graphics"), GAMES("games") } @@ -63,6 +67,16 @@ internal object EnhancedSessionLogShare { private class Budget(val limit: Long, var remaining: Long = limit) + private val sourceOpenerOverride = object : ThreadLocal<SecureSourceOpener?>() { + override fun initialValue(): SecureSourceOpener? = null + } + + internal fun setSourceOpenerForTest(opener: SecureSourceOpener?) { + if (opener == null) sourceOpenerOverride.remove() else sourceOpenerOverride.set(opener) + } + + internal fun hasSourceOpenerForTest(): Boolean = sourceOpenerOverride.get() != null + fun create( context: Context, folder: File, @@ -313,6 +327,11 @@ internal object EnhancedSessionLogShare { } private fun <T> withSecureChannel(root: Path, relative: Path, block: (SeekableByteChannel) -> T): T? { + sourceOpenerOverride.get()?.let { return it.withChannel(root, relative, block) } + return withAndroidSecureChannel(root, relative, block) + } + + private fun <T> withAndroidSecureChannel(root: Path, relative: Path, block: (SeekableByteChannel) -> T): T? { val opened = ArrayList<ParcelFileDescriptor>() return try { val parts = relative.map { it.toString() } diff --git a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt index 73dd3f2132..b87649d5a8 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt @@ -16,6 +16,8 @@ import org.robolectric.annotation.Config import java.io.RandomAccessFile import java.nio.file.Files import java.util.zip.ZipFile +import org.junit.After +import org.junit.Before @RunWith(RobolectricTestRunner::class) @Config(sdk = [33]) @@ -23,6 +25,10 @@ class EnhancedSessionLogShareTest { @get:Rule val tmp = TemporaryFolder() private val app get() = RuntimeEnvironment.getApplication() + @Before fun installSecureSourceOpener() = installJvmSecureSourceOpener() + + @After fun resetSourceOpener() = resetSecureSourceOpener() + @Test fun diagnosticsAreSplitIntoManifestedArchivesWithOneSessionIdentity() { val session = tmp.newFolder("2026-11-04-01-steam") session.resolve("session.log").writeText("startup ok\n") @@ -328,4 +334,29 @@ class EnhancedSessionLogShareTest { } SessionLogShare.clear(app) } + + @Test fun injectedSecureOpenFailureFailsClosedAndTheOverrideCanBeReset() { + val session = tmp.newFolder("2026-11-04-15-steam") + session.resolve("session.log").writeText("must not be shared\n") + EnhancedSessionLogShare.setSourceOpenerForTest(object : SecureSourceOpener { + override fun <T> withChannel( + root: java.nio.file.Path, + relative: java.nio.file.Path, + block: (java.nio.channels.SeekableByteChannel) -> T, + ): T? = null + }) + try { + val sessionZip = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-session.zip") } + ZipFile(sessionZip).use { archive -> + assertFalse(archive.entries().toList().any { it.name.endsWith("session.log") }) + val manifest = archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText() + assertTrue(manifest.contains("unsafe-or-unavailable-source")) + } + } finally { + resetSecureSourceOpener() + } + assertFalse(EnhancedSessionLogShare.hasSourceOpenerForTest()) + SessionLogShare.clear(app) + } } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SecureSourceOpenerTestSupport.kt b/app/src/test/java/com/droiddeck/launcher/session/SecureSourceOpenerTestSupport.kt new file mode 100644 index 0000000000..7eeba41b71 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/SecureSourceOpenerTestSupport.kt @@ -0,0 +1,72 @@ +package com.droiddeck.launcher.session + +import java.nio.channels.SeekableByteChannel +import java.nio.file.DirectoryStream +import java.nio.file.Files +import java.nio.file.LinkOption +import java.nio.file.Path +import java.nio.file.Paths +import java.nio.file.SecureDirectoryStream +import java.nio.file.StandardOpenOption +import java.nio.file.attribute.BasicFileAttributeView +import java.nio.file.attribute.BasicFileAttributes + +internal object JvmSecureSourceOpener : SecureSourceOpener { + override fun <T> withChannel(root: Path, relative: Path, block: (SeekableByteChannel) -> T): T? { + val expected = root.resolve(relative).normalize() + if (!expected.startsWith(root.normalize())) return null + val initial = runCatching { + Files.readAttributes(expected, BasicFileAttributes::class.java, LinkOption.NOFOLLOW_LINKS) + }.getOrNull() ?: return null + val links = runCatching { + (Files.getAttribute(expected, "unix:nlink", LinkOption.NOFOLLOW_LINKS) as Number).toLong() + }.getOrNull() ?: return null + val expectedKey = initial.fileKey() ?: return null + if (!initial.isRegularFile || initial.isSymbolicLink || links != 1L) return null + val first = Files.newDirectoryStream(root) + if (first !is SecureDirectoryStream<*>) { + first.close() + return null + } + @Suppress("UNCHECKED_CAST") + val secureFirst = first as SecureDirectoryStream<Path> + val opened = ArrayList<DirectoryStream<Path>>() + opened += first + var current = secureFirst + return try { + val parts = relative.map { it.toString() } + if (parts.isEmpty()) return null + for (part in parts.dropLast(1)) { + val child = Paths.get(part) + val attrs = current.getFileAttributeView( + child, BasicFileAttributeView::class.java, LinkOption.NOFOLLOW_LINKS, + ).readAttributes() + if (!attrs.isDirectory || attrs.isSymbolicLink) return null + val next = current.newDirectoryStream(child, LinkOption.NOFOLLOW_LINKS) + opened += next + current = next + } + val leaf = Paths.get(parts.last()) + val attrs = current.getFileAttributeView( + leaf, BasicFileAttributeView::class.java, LinkOption.NOFOLLOW_LINKS, + ).readAttributes() + if (!attrs.isRegularFile || attrs.isSymbolicLink || attrs.fileKey() != expectedKey) return null + current.newByteChannel(leaf, setOf(StandardOpenOption.READ, LinkOption.NOFOLLOW_LINKS)).use { channel -> + val after = current.getFileAttributeView( + leaf, BasicFileAttributeView::class.java, LinkOption.NOFOLLOW_LINKS, + ).readAttributes() + if (after.fileKey() != expectedKey) null else block(channel) + } + } finally { + opened.asReversed().forEach { runCatching { it.close() } } + } + } +} + +internal fun installJvmSecureSourceOpener() { + EnhancedSessionLogShare.setSourceOpenerForTest(JvmSecureSourceOpener) +} + +internal fun resetSecureSourceOpener() { + EnhancedSessionLogShare.setSourceOpenerForTest(null) +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index 678ae876fd..d451abc9de 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -8,6 +8,8 @@ import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test +import org.junit.After +import org.junit.Before import org.junit.rules.TemporaryFolder import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner @@ -24,6 +26,10 @@ import java.util.zip.ZipFile class SessionLogShareTest { @get:Rule val tmp = TemporaryFolder() + @Before fun installSecureSourceOpener() = installJvmSecureSourceOpener() + + @After fun resetSourceOpener() = resetSecureSourceOpener() + private val secret = "GET /x?sessionid=abcdef123456 200" private val leaked = "abcdef123456" diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index ecc756553f..d02e616c20 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -9,6 +9,8 @@ import java.util.zip.ZipFile import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue +import org.junit.After +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner @@ -20,6 +22,10 @@ import org.robolectric.annotation.Config class SessionLogShareZipTest { private val app get() = RuntimeEnvironment.getApplication() + @Before fun installSecureSourceOpener() = installJvmSecureSourceOpener() + + @After fun resetSourceOpener() = resetSecureSourceOpener() + @Test fun aLargeSteamLogIsRedactedInTheSharedArchive() { val session = File(LinuxRuntime.logDir(app), "2026-10-08-02-steam").apply { mkdirs() } val raw = File(session, "steam-42.log") From 44f8d5de70ba00b3e9636d8d9de7e9c78fde5bef Mon Sep 17 00:00:00 2001 From: wallentx <william.allentx@gmail.com> Date: Wed, 4 Nov 2026 13:00:32 -0600 Subject: [PATCH 37/85] Check the matching diagnostic manifest entry --- .../launcher/session/EnhancedSessionLogShareTest.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt index b87649d5a8..cd2157cad1 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt @@ -55,7 +55,10 @@ class EnhancedSessionLogShareTest { assertEquals(1, manifest.getInt("schema")) assertEquals(session.name, manifest.getString("sessionId")) assertEquals(category, manifest.getString("category")) - assertEquals("captured", manifest.getJSONArray("entries").getJSONObject(0).getString("status")) + val entries = manifest.getJSONArray("entries") + val record = (0 until entries.length()).map { entries.getJSONObject(it) } + .single { it.optString("entry") == expected.getValue(category) } + assertEquals("captured", record.getString("status")) } } SessionLogShare.clear(app) From 7053058db640d5757a6cf07ca2534fc9ca87b976 Mon Sep 17 00:00:00 2001 From: wallentx <william.allentx@gmail.com> Date: Thu, 5 Nov 2026 00:34:11 -0600 Subject: [PATCH 38/85] Harden enhanced diagnostics collection and sharing --- .../droiddeck/launcher/FrontEndActivity.kt | 1 + .../session/EnhancedSessionLogShare.kt | 266 ++++++++++++------ .../session/EnhancedSessionLogShareTest.kt | 131 +++++++++ docs/development/game-environment.md | 2 +- 4 files changed, 307 insertions(+), 93 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index cc9488b094..9e69cc974a 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -2710,6 +2710,7 @@ class FrontEndActivity : ComponentActivity() { !SessionPaths.currentSessionLogsRetained(this) private fun shareEnhancedArchives(zips: List<java.io.File>) { + if (isFinishing || isDestroyed) return val choices = zips.map { zip -> val label = when { zip.name.endsWith("-session.zip") -> getString(R.string.diagnostics_share_session) diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index 914e8c7b40..0317c4e2dc 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -9,17 +9,22 @@ import com.droiddeck.launcher.runtime.BattleNet import com.droiddeck.launcher.runtime.LinuxRuntime import org.json.JSONArray import org.json.JSONObject +import java.io.BufferedInputStream import java.io.ByteArrayOutputStream import java.io.File import java.io.FileOutputStream import java.io.FileInputStream +import java.io.IOException import java.nio.ByteBuffer import java.nio.channels.Channels import java.nio.channels.FileChannel import java.nio.channels.SeekableByteChannel +import java.nio.file.FileVisitResult import java.nio.file.Files import java.nio.file.LinkOption import java.nio.file.Path +import java.nio.file.SimpleFileVisitor +import java.nio.file.attribute.BasicFileAttributes import java.security.MessageDigest import java.util.Locale import java.util.zip.ZipEntry @@ -59,12 +64,26 @@ internal object EnhancedSessionLogShare { private data class Snapshot(val file: File, val sourceBytes: Long, val truncated: Boolean) - private data class CollectionResult(val candidates: List<Candidate>, val truncated: Boolean) + private data class CollectionResult( + val candidates: List<Candidate>, + val truncated: Boolean, + val partial: Boolean, + ) - private data class ScanResult(val files: List<File>, val truncated: Boolean) + private data class ScanResult( + val files: List<File>, + val truncated: Boolean, + val partial: Boolean = false, + ) private data class LegacySource(val file: File, val root: File, val entry: String) + private data class LegacyDiscovery( + val sources: List<LegacySource>, + val truncated: Boolean, + val partial: Boolean, + ) + private class Budget(val limit: Long, var remaining: Long = limit) private val sourceOpenerOverride = object : ThreadLocal<SecureSourceOpener?>() { @@ -123,6 +142,7 @@ internal object EnhancedSessionLogShare { if (category == Category.SESSION) addTrustedActivation(context, folder, archive)?.let(records::add) if (selected.isEmpty()) records += Record("", category.suffix, "unavailable", reason = "no-matching-artifacts") if (discovery.truncated) records += Record("", "discovery", "truncated", reason = "candidate-limit") + if (discovery.partial) records += Record("", "discovery", "truncated", reason = "filesystem-error") addManifest( archive, folder.name, category.suffix, records, limits, budget.limit, redactionLearningComplete, ) @@ -173,6 +193,7 @@ internal object EnhancedSessionLogShare { } addTrustedActivation(context, folder, archive)?.let(records::add) if (discovery.truncated) records += Record("", "discovery", "truncated", reason = "candidate-limit") + if (discovery.partial) records += Record("", "discovery", "truncated", reason = "filesystem-error") addManifest(archive, folder.name, "all", records, limits, budget.limit, redactionLearningComplete) } zip @@ -212,7 +233,13 @@ internal object EnhancedSessionLogShare { } ?: return Record(candidate.entry, candidate.origin, "omitted", reason = "unsafe-or-unavailable-source") if (snapshot.file.length() == 0L && candidate.linePrefix != null) { snapshot.file.delete() - return Record(candidate.entry, candidate.origin, "unavailable", snapshot.sourceBytes, reason = "no-matching-lines") + return Record( + candidate.entry, + candidate.origin, + if (snapshot.truncated) "truncated" else "unavailable", + snapshot.sourceBytes, + reason = if (snapshot.truncated) "no-matching-lines-in-bounded-scan" else "no-matching-lines", + ) } return try { budget.remaining -= snapshot.file.length() @@ -282,7 +309,7 @@ internal object EnhancedSessionLogShare { target.outputStream().buffered().use { output -> fun scan(start: Long, count: Long, discardPartialFirstLine: Boolean) { channel.position(start) - val input = Channels.newInputStream(channel) + val input = BufferedInputStream(Channels.newInputStream(channel), COPY_BUFFER_BYTES) val line = ByteArrayOutputStream(1024) var oversized = false var scanned = 0L @@ -336,33 +363,19 @@ internal object EnhancedSessionLogShare { return try { val parts = relative.map { it.toString() } if (parts.isEmpty()) return null - val rootFd = openDescriptor(root.toString()) ?: return null - if (!OsConstants.S_ISDIR(Os.fstat(rootFd).st_mode)) { - Os.close(rootFd) - return null - } - opened += duplicateAndClose(rootFd) + opened += openDirectoryDescriptor(root.toString()) ?: return null for (part in parts.dropLast(1)) { - val childFd = openDescriptor(procChild(opened.last(), part)) ?: return null - if (!OsConstants.S_ISDIR(Os.fstat(childFd).st_mode)) { - Os.close(childFd) - return null - } - opened += duplicateAndClose(childFd) + opened += openDirectoryDescriptor(procChild(opened.last(), part)) ?: return null } val leafFd = openDescriptor(procChild(opened.last(), parts.last())) ?: return null - val stat = Os.fstat(leafFd) - if (!OsConstants.S_ISREG(stat.st_mode) || stat.st_nlink != 1L) { - Os.close(leafFd) - return null + try { + val stat = Os.fstat(leafFd) + if (!OsConstants.S_ISREG(stat.st_mode) || stat.st_nlink != 1L) return null + // Android's FileInputStream(FileDescriptor) is deliberately not the descriptor owner. + FileInputStream(leafFd).use { stream -> block(stream.channel) } + } finally { + runCatching { Os.close(leafFd) } } - val stream = try { - FileInputStream(leafFd) - } catch (error: Exception) { - Os.close(leafFd) - throw error - } - stream.use { block(it.channel) } } catch (_: Exception) { null } finally { @@ -378,12 +391,15 @@ internal object EnhancedSessionLogShare { ) }.getOrNull() - private fun duplicateAndClose(fd: java.io.FileDescriptor): ParcelFileDescriptor = - try { + private fun openDirectoryDescriptor(path: String): ParcelFileDescriptor? { + val fd = openDescriptor(path) ?: return null + return try { + if (!OsConstants.S_ISDIR(Os.fstat(fd).st_mode)) return null ParcelFileDescriptor.dup(fd) } finally { - Os.close(fd) + runCatching { Os.close(fd) } } + } private fun procChild(directory: ParcelFileDescriptor, name: String): String = "/proc/self/fd/${directory.fd}/$name" @@ -436,13 +452,12 @@ internal object EnhancedSessionLogShare { var start = (sourceSize - limit).coerceAtLeast(0) if (start > 0) { input.position(start) - val one = ByteBuffer.allocate(1) + val buffered = BufferedInputStream(Channels.newInputStream(input), COPY_BUFFER_BYTES) while (start < sourceSize) { - one.clear() - if (input.read(one) < 0) return + val value = buffered.read() + if (value < 0) return start++ - one.flip() - if (one.get() == '\n'.code.toByte()) break + if (value == '\n'.code) break } } copy(input, output, start, (sourceSize - start).coerceAtMost(limit)) @@ -502,6 +517,7 @@ internal object EnhancedSessionLogShare { val categoryCounts = HashMap<Category, Int>() val perCategory = (maxFiles / Category.values().size).coerceAtLeast(1) var truncated = false + var partial = false fun add( file: File, root: File, @@ -511,7 +527,7 @@ internal object EnhancedSessionLogShare { linePrefix: String? = null, ) { val safe = safeEntry(entry) ?: return - val category = forcedCategory ?: category(entry) + val category = forcedCategory ?: category(entry.removePrefix("${folder.name}/")) if (out.size >= maxFiles || (categoryCounts[category] ?: 0) >= perCategory) { truncated = true return @@ -542,6 +558,7 @@ internal object EnhancedSessionLogShare { val steam = File(SessionPrefs.activeSteamRoot(context), "logs") val scan = directFiles(steam, remaining(maxFiles, out.size)) truncated = truncated || scan.truncated + partial = partial || scan.partial scan.files.forEach { add(it, steam, "${folder.name}/steam/${it.name}", "live-steam") } @@ -550,17 +567,22 @@ internal object EnhancedSessionLogShare { for ((name, root) in listOf(SessionLogShare.STORES_DIR to File(logs, SessionLogShare.STORES_DIR), SessionPaths.TOOLS_DIR to File(logs, SessionPaths.TOOLS_DIR))) { val scan = directFiles(root, remaining(maxFiles, out.size)) truncated = truncated || scan.truncated + partial = partial || scan.partial scan.files.asSequence().filter { recent(it) } .forEach { add(it, root, "$name/${it.name}", name) } } if (legacy) { - legacyBattleNet(context).forEach { source -> + val scan = legacyBattleNet(context) + truncated = truncated || scan.truncated + partial = partial || scan.partial + scan.sources.forEach { source -> add(source.file, source.root, source.entry, "battlenet") } } else { battleNetRoots(context).forEach { (prefix, root) -> val scan = walk(root, remaining(maxFiles, out.size)) truncated = truncated || scan.truncated + partial = partial || scan.partial scan.files.asSequence().filter { recent(it) && it.name.endsWith(".log", true) } .forEach { file -> val relative = root.toPath().toAbsolutePath().normalize().relativize(file.toPath().toAbsolutePath().normalize()).joinToString("/") @@ -570,13 +592,14 @@ internal object EnhancedSessionLogShare { } val sessionScan = walk(folder, remaining(maxFiles, out.size)) truncated = truncated || sessionScan.truncated + partial = partial || sessionScan.partial sessionScan.files.forEach { file -> val relative = file.toPath().toAbsolutePath().normalize() .let { folder.toPath().toAbsolutePath().normalize().relativize(it).joinToString("/") } if (relative == EnhancedDiagnostics.MANIFEST_FILE) return@forEach add(file, folder, "${folder.name}/$relative", "session") } - return CollectionResult(out.values.toList(), truncated) + return CollectionResult(out.values.toList(), truncated, partial) } private fun remaining(maxFiles: Int, found: Int): Int = (maxFiles - found + 1).coerceAtLeast(0) @@ -585,38 +608,69 @@ internal object EnhancedSessionLogShare { if (limit <= 0 || !root.isDirectory || Files.isSymbolicLink(root.toPath())) return ScanResult(emptyList(), false) val files = ArrayList<File>(limit) var truncated = false - Files.walk(root.toPath()).use { paths -> - val iterator = paths.iterator() - var visited = 0 - val visitLimit = (limit * 4).coerceAtLeast(limit).coerceAtMost(MAX_DISCOVERY_VISITS) - while (iterator.hasNext() && files.size < limit && visited < visitLimit) { - val path = iterator.next() - visited++ - if (path != root.toPath() && - (Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS) || Files.isSymbolicLink(path))) { - files += path.toFile() + var partial = false + var visited = 0 + val rootPath = root.toPath() + val visitLimit = (limit * 4).coerceAtLeast(limit).coerceAtMost(MAX_DISCOVERY_VISITS) + try { + Files.walkFileTree(rootPath, object : SimpleFileVisitor<Path>() { + private fun countVisit(): FileVisitResult { + visited++ + return if (visited > visitLimit) { + truncated = true + FileVisitResult.TERMINATE + } else FileVisitResult.CONTINUE } - } - truncated = iterator.hasNext() + + override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult = + if (dir == rootPath) FileVisitResult.CONTINUE else countVisit() + + override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult { + if (countVisit() == FileVisitResult.TERMINATE) return FileVisitResult.TERMINATE + if (files.size >= limit) { + truncated = true + return FileVisitResult.TERMINATE + } + if (attrs.isRegularFile || Files.isSymbolicLink(file)) files += file.toFile() + return FileVisitResult.CONTINUE + } + + override fun visitFileFailed(file: Path, exc: IOException): FileVisitResult { + partial = true + return countVisit() + } + + override fun postVisitDirectory(dir: Path, exc: IOException?): FileVisitResult { + if (exc != null) partial = true + return FileVisitResult.CONTINUE + } + }) + } catch (_: Exception) { + partial = true } - return ScanResult(files, truncated) + return ScanResult(files, truncated, partial) } private fun directFiles(root: File, limit: Int): ScanResult { if (limit <= 0 || !root.isDirectory || Files.isSymbolicLink(root.toPath())) return ScanResult(emptyList(), false) val files = ArrayList<File>(limit) var truncated = false - Files.newDirectoryStream(root.toPath()).use { entries -> - val iterator = entries.iterator() - while (iterator.hasNext() && files.size < limit) { - val path = iterator.next() - if (Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS) || Files.isSymbolicLink(path)) { - files += path.toFile() + var partial = false + try { + Files.newDirectoryStream(root.toPath()).use { entries -> + val iterator = entries.iterator() + while (iterator.hasNext() && files.size < limit) { + val path = iterator.next() + if (Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS) || Files.isSymbolicLink(path)) { + files += path.toFile() + } } + truncated = iterator.hasNext() } - truncated = iterator.hasNext() + } catch (_: Exception) { + partial = true } - return ScanResult(files, truncated) + return ScanResult(files, truncated, partial) } private fun battleNetRoots(context: Context): List<Pair<String, File>> { @@ -630,25 +684,31 @@ internal object EnhancedSessionLogShare { ) } - private fun legacyBattleNet(context: Context): List<LegacySource> { + private fun legacyBattleNet(context: Context): LegacyDiscovery { val drive = File(BattleNet.prefix(context), "pfx/drive_c") val data = File(drive, "ProgramData/Battle.net") val agent = File(data, "Agent") val setup = File(data, "Setup") - return legacyNewest( - "droiddeck", - listOf(File(LinuxRuntime.rootDir(context), "root/.cache/droiddeck/battlenet")), - 2, - setOf("battlenet.log", "spawned.log"), - ) + legacyNewest( - "client", listOf(File(drive, "users/steamuser/AppData/Local/Battle.net/Logs")), 6, - ) + legacyNewest( - "agent", - listOf(File(agent, "Logs")) + childDirectories(agent, "Agent.").map { File(it, "Logs") }, - 10, - byDir = true, - ) + legacyNewest( - "setup", childDirectories(setup, "").map { File(it, "Logs") }, 3, byDir = true, + val agentChildren = childDirectories(agent, "Agent.") + val setupChildren = childDirectories(setup, "") + val scans = listOf( + legacyNewest( + "droiddeck", + listOf(File(LinuxRuntime.rootDir(context), "root/.cache/droiddeck/battlenet")), + 2, + setOf("battlenet.log", "spawned.log"), + ), + legacyNewest("client", listOf(File(drive, "users/steamuser/AppData/Local/Battle.net/Logs")), 6), + legacyNewest( + "agent", listOf(File(agent, "Logs")) + agentChildren.files.map { File(it, "Logs") }, 10, + byDir = true, + ), + legacyNewest("setup", setupChildren.files.map { File(it, "Logs") }, 3, byDir = true), + ) + return LegacyDiscovery( + scans.flatMap { it.sources }, + scans.any { it.truncated } || agentChildren.truncated || setupChildren.truncated, + scans.any { it.partial } || agentChildren.partial || setupChildren.partial, ) } @@ -658,29 +718,50 @@ internal object EnhancedSessionLogShare { count: Int, names: Set<String>? = null, byDir: Boolean = false, - ): List<LegacySource> = roots.flatMap { root -> - directFiles(root, MAX_BATTLENET_SCAN).files.asSequence() - .filter { recent(it) && it.name.endsWith(".log") && it.length() <= LEGACY_LOG_MAX_BYTES } - .filter { names == null || it.name in names } - .map { it to root } - .toList() - }.sortedByDescending { it.first.lastModified() }.take(count).map { (file, root) -> - val relative = if (byDir) "$folder/${file.parentFile?.parentFile?.name}/${file.name}" else "$folder/${file.name}" - LegacySource(file, root, "battlenet/$relative") + ): LegacyDiscovery { + val found = ArrayList<Pair<File, File>>() + var truncated = false + var partial = false + roots.forEach { root -> + val scan = directFiles(root, MAX_BATTLENET_SCAN) + truncated = truncated || scan.truncated + partial = partial || scan.partial + found += scan.files.asSequence() + .filter { recent(it) && it.name.endsWith(".log") && it.length() <= LEGACY_LOG_MAX_BYTES } + .filter { names == null || it.name in names } + .map { it to root } + .toList() + } + val ordered = found.sortedByDescending { it.first.lastModified() } + return LegacyDiscovery( + ordered.take(count).map { (file, root) -> + val relative = if (byDir) "$folder/${file.parentFile?.parentFile?.name}/${file.name}" else "$folder/${file.name}" + LegacySource(file, root, "battlenet/$relative") + }, + truncated || ordered.size > count, + partial, + ) } - private fun childDirectories(root: File, prefix: String): List<File> { - if (!root.isDirectory || Files.isSymbolicLink(root.toPath())) return emptyList() + private fun childDirectories(root: File, prefix: String): ScanResult { + if (!root.isDirectory || Files.isSymbolicLink(root.toPath())) return ScanResult(emptyList(), false) val found = ArrayList<File>() - Files.newDirectoryStream(root.toPath()).use { entries -> - val iterator = entries.iterator() - while (iterator.hasNext() && found.size < MAX_BATTLENET_DIRECTORIES) { - val path = iterator.next() - if (path.fileName.toString().startsWith(prefix) && - Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS) && !Files.isSymbolicLink(path)) found += path.toFile() + var truncated = false + var partial = false + try { + Files.newDirectoryStream(root.toPath()).use { entries -> + val iterator = entries.iterator() + while (iterator.hasNext() && found.size < MAX_BATTLENET_DIRECTORIES) { + val path = iterator.next() + if (path.fileName.toString().startsWith(prefix) && + Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS) && !Files.isSymbolicLink(path)) found += path.toFile() + } + truncated = iterator.hasNext() } + } catch (_: Exception) { + partial = true } - return found + return ScanResult(found, truncated, partial) } private fun recent(file: File): Boolean = file.lastModified() >= System.currentTimeMillis() - RECENT_MILLIS @@ -741,6 +822,7 @@ internal object EnhancedSessionLogShare { "events.jsonl", "memory.csv", "capture.json", "crash.log", ) private const val RECENT_MILLIS = 7L * 24 * 60 * 60 * 1000 + private const val COPY_BUFFER_BYTES = 64 * 1024 private const val TRACE_SCAN_BYTES = 16L * 1024 * 1024 private const val LEGACY_LOG_MAX_BYTES = 8L * 1024 * 1024 private const val MAX_BATTLENET_SCAN = 64 diff --git a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt index cd2157cad1..1c15db119b 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt @@ -14,7 +14,13 @@ import org.robolectric.RobolectricTestRunner import org.robolectric.RuntimeEnvironment import org.robolectric.annotation.Config import java.io.RandomAccessFile +import java.nio.ByteBuffer +import java.nio.channels.FileChannel +import java.nio.channels.SeekableByteChannel import java.nio.file.Files +import java.nio.file.StandardOpenOption +import java.nio.file.attribute.PosixFilePermissions +import java.util.concurrent.atomic.AtomicInteger import java.util.zip.ZipFile import org.junit.After import org.junit.Before @@ -29,6 +35,32 @@ class EnhancedSessionLogShareTest { @After fun resetSourceOpener() = resetSecureSourceOpener() + private class CountingChannel( + private val delegate: SeekableByteChannel, + private val reads: AtomicInteger, + ) : SeekableByteChannel by delegate { + override fun read(dst: ByteBuffer): Int { + reads.incrementAndGet() + return delegate.read(dst) + } + } + + private fun installCountingSourceOpener(reads: AtomicInteger) { + EnhancedSessionLogShare.setSourceOpenerForTest(object : SecureSourceOpener { + override fun <T> withChannel( + root: java.nio.file.Path, + relative: java.nio.file.Path, + block: (SeekableByteChannel) -> T, + ): T? { + val source = root.resolve(relative).normalize() + if (!source.startsWith(root) || Files.isSymbolicLink(source)) return null + return FileChannel.open(source, StandardOpenOption.READ).use { channel -> + block(CountingChannel(channel, reads)) + } + } + }) + } + @Test fun diagnosticsAreSplitIntoManifestedArchivesWithOneSessionIdentity() { val session = tmp.newFolder("2026-11-04-01-steam") session.resolve("session.log").writeText("startup ok\n") @@ -150,6 +182,32 @@ class EnhancedSessionLogShareTest { SessionLogShare.clear(app) } + @Test fun byteOrientedTraceAndTailScansUseBufferedChannelReads() { + val traceSession = tmp.newFolder("2026-11-04-05-buffered-trace") + traceSession.resolve("session.log").writeText("x".repeat(1024 * 1024)) + val traceReads = AtomicInteger() + installCountingSourceOpener(traceReads) + + EnhancedSessionLogShare.create(app, traceSession) + + assertTrue("trace scan used ${traceReads.get()} channel reads", traceReads.get() < 200) + SessionLogShare.clear(app) + + val tailSession = tmp.newFolder("2026-11-04-05-buffered-tail") + tailSession.resolve("steam-7.log").writeText("x".repeat(1024 * 1024)) + val tailReads = AtomicInteger() + installCountingSourceOpener(tailReads) + + EnhancedSessionLogShare.create( + app, + tailSession, + limits = EnhancedShareLimits(maxBytesPerFile = 64 * 1024L, maxBytesTotal = 512 * 1024L), + ) + + assertTrue("tail scan used ${tailReads.get()} channel reads", tailReads.get() < 100) + SessionLogShare.clear(app) + } + @Test fun truncationNeverSharesASecretWhoseLabelWasCutOffAtTheBoundary() { val session = tmp.newFolder("2026-11-04-06-game") val secret = "abcdef1234567890" @@ -292,6 +350,79 @@ class EnhancedSessionLogShareTest { SessionLogShare.clear(app) } + @Test fun filteredTraceWithMatchesOnlyOutsideTheScannedRangesStaysTruncated() { + val session = tmp.newFolder("2026-11-04-12-partial-empty") + val source = session.resolve("session.log") + RandomAccessFile(source, "rw").use { file -> + file.setLength(17L * 1024 * 1024) + file.seek(8L * 1024 * 1024 + 256 * 1024) + file.write("DROIDDECK_FRAME_TRACE hidden-in-middle=1\n".toByteArray()) + } + + val graphics = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-graphics.zip") } + + ZipFile(graphics).use { archive -> + assertTrue(archive.getEntry("${session.name}/graphics/frame-trace.log") == null) + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()) + val entries = manifest.getJSONArray("entries") + val record = (0 until entries.length()).map { entries.getJSONObject(it) } + .single { it.optString("origin") == "guest-frame-trace" } + assertEquals("truncated", record.getString("status")) + assertEquals("no-matching-lines-in-bounded-scan", record.getString("reason")) + } + SessionLogShare.clear(app) + } + + @Test fun sessionNameCannotMisclassifyPrimarySessionAndGraphicsLogs() { + val session = tmp.newFolder("2026-11-04-12-wine") + session.resolve("session.log").writeText("session\n") + session.resolve("wayland.log").writeText("graphics\n") + + val zips = EnhancedSessionLogShare.create(app, session) + val sessionEntries = ZipFile(zips.single { it.name.endsWith("-session.zip") }).use { archive -> + archive.entries().toList().map { it.name } + } + val graphicsEntries = ZipFile(zips.single { it.name.endsWith("-graphics.zip") }).use { archive -> + archive.entries().toList().map { it.name } + } + val gameEntries = ZipFile(zips.single { it.name.endsWith("-games.zip") }).use { archive -> + archive.entries().toList().map { it.name } + } + + assertTrue(sessionEntries.contains("${session.name}/session.log")) + assertTrue(graphicsEntries.contains("${session.name}/wayland.log")) + assertFalse(gameEntries.contains("${session.name}/session.log")) + assertFalse(gameEntries.contains("${session.name}/wayland.log")) + SessionLogShare.clear(app) + } + + @Test fun unreadableDiscoverySubtreeKeepsOtherLogsAndMarksTheManifestPartial() { + assumeFalse(System.getProperty("os.name").startsWith("Windows")) + val session = tmp.newFolder("2026-11-04-12-partial-discovery") + session.resolve("session.log").writeText("safe\n") + val blocked = session.resolve("blocked").apply { mkdir(); resolve("hidden.log").writeText("hidden\n") } + val original = Files.getPosixFilePermissions(blocked.toPath()) + Files.setPosixFilePermissions(blocked.toPath(), PosixFilePermissions.fromString("---------")) + val sessionZip = try { + EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-session.zip") } + } finally { + Files.setPosixFilePermissions(blocked.toPath(), original) + } + + ZipFile(sessionZip).use { archive -> + assertTrue(archive.getEntry("${session.name}/session.log") != null) + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()) + val entries = manifest.getJSONArray("entries") + assertTrue((0 until entries.length()).map { entries.getJSONObject(it) }.any { + it.optString("origin") == "discovery" && it.optString("status") == "truncated" && + it.optString("reason") == "filesystem-error" + }) + } + SessionLogShare.clear(app) + } + @Test fun diagnosticLookingGuestNamesCannotExposeEmbeddedSecrets() { val session = tmp.newFolder("2026-11-04-13-game") val tokenName = "dxvk-refresh_token_abcdef123456.log" diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md index e0800784e9..e7c7ca210b 100644 --- a/docs/development/game-environment.md +++ b/docs/development/game-environment.md @@ -137,7 +137,7 @@ in-session share action. Enhanced sessions offer separate, correlated archives: Choose one archive when an issue calls for a narrow report, or **All bundles** to share the three archives together. Every archive contains a `diagnostics-manifest.json` with the common session ID and the state of each -artifact: captured, truncated, unavailable, omitted, or failed. Some captured +artifact: captured, truncated, unavailable, omitted, or error. Some captured logs may themselves explain that a permission-limited source was unavailable. Exported archives sample a bounded amount of input. Large text logs retain From 2ab8a1bac3e047a089af15e5caa2962dd419dadc Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:58:39 -0500 Subject: [PATCH 39/85] test: validate enhanced log share descriptor reads --- .../launcher/session/EnhancedSessionLogShareTest.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt index 1c15db119b..c1e2e8a211 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt @@ -148,8 +148,12 @@ class EnhancedSessionLogShareTest { assertEquals(Intent.ACTION_SEND_MULTIPLE, send.action) assertEquals("application/zip", send.type) - assertEquals(3, send.getParcelableArrayListExtra<android.net.Uri>(Intent.EXTRA_STREAM)!!.size) + val uris = send.getParcelableArrayListExtra<android.net.Uri>(Intent.EXTRA_STREAM)!! + assertEquals(3, uris.size) assertEquals(3, send.clipData!!.itemCount) + assertTrue(send.flags and Intent.FLAG_GRANT_READ_URI_PERMISSION != 0) + val header = app.contentResolver.openInputStream(uris.first())!!.use { it.readNBytes(4) } + assertEquals("PK\u0003\u0004", String(header, Charsets.ISO_8859_1)) SessionLogShare.clear(app) } From a28ff0598167e958cb7e65134822c15104379a3a Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:14:08 -0500 Subject: [PATCH 40/85] fix: handle enhanced log chooser launch failures --- .../main/java/com/droiddeck/launcher/FrontEndActivity.kt | 9 +++++++-- .../main/java/com/droiddeck/launcher/SessionActivity.kt | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 9e69cc974a..eee09c03bc 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -2723,8 +2723,13 @@ class FrontEndActivity : ComponentActivity() { .setTitle(R.string.diagnostics_share_title) .setItems(choices.map { it.first }.toTypedArray()) { _, which -> val selected = choices[which].second - startActivity(if (selected.size == 1) SessionLogShare.shareIntent(this, selected.single()) - else SessionLogShare.shareEnhancedIntent(this, selected)) + runCatching { + startActivity(if (selected.size == 1) SessionLogShare.shareIntent(this, selected.single()) + else SessionLogShare.shareEnhancedIntent(this, selected)) + }.onFailure { + android.util.Log.w("SessionLogShare", "could not share latest session logs", it) + android.widget.Toast.makeText(this, R.string.session_logs_share_failed, android.widget.Toast.LENGTH_LONG).show() + } } .setNegativeButton(android.R.string.cancel, null) .show() diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index d5c4fe3104..c5e36438e7 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -1920,8 +1920,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { .setTitle(R.string.diagnostics_share_title) .setItems(choices.map { it.first }.toTypedArray()) { _, which -> val selected = choices[which].second - startActivity(if (selected.size == 1) SessionLogShare.shareIntent(this, selected.single()) - else SessionLogShare.shareEnhancedIntent(this, selected)) + runCatching { + startActivity(if (selected.size == 1) SessionLogShare.shareIntent(this, selected.single()) + else SessionLogShare.shareEnhancedIntent(this, selected)) + }.onFailure { + Log.w(TAG, "could not share current session logs", it) + Toast.makeText(this, R.string.session_logs_share_failed, Toast.LENGTH_LONG).show() + } } .setNegativeButton(android.R.string.cancel, null) .show() From 4f831fbd34dcebb5c1a3a9d2e68207b42910e716 Mon Sep 17 00:00:00 2001 From: flexeykinDev <booby1546@gmail.com> Date: Thu, 5 Nov 2026 11:05:06 +0100 Subject: [PATCH 41/85] l10n(ru): translate strings added since the last translation pass Adds the 83 Russian strings that showed in English: extra Steam libraries, session logs, dual screen launcher and sessions, PC keyboard options, the bottom screen desktop, screen swap, the stats HUD and the Mali bridge GPU info. --- app/src/main/res/values-ru/strings.xml | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 087f9fcccb..a3b1bf4ae2 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -402,6 +402,9 @@ <string name="wincomp_unsupported">Здесь пока не поддерживается</string> <string name="wincomp_loading">Загрузка компонентов…</string> <string name="wincomp_failed">Не удалось установить: %1$s</string> + <string name="wincomp_repair_required">Эту загрузку нужно обновить.</string> + <string name="wincomp_repair_queued">Обновление в очереди.</string> + <string name="wincomp_retry">Повторить обновление</string> <string name="wincomp_downloaded">Скачано</string> <string name="wincomp_downloading">Загрузка %1$s</string> <string name="wincomp_installing">Установка: %1$s</string> @@ -432,6 +435,22 @@ <string name="mode_storage_internal">Только внутреннее хранилище</string> <string name="mode_storage_folder">Папка: %1$s</string> <string name="mode_second_library">Вторая библиотека</string> + <string name="libraries_title">Другие библиотеки Steam</string> + <string name="libraries_hint">Папки, в которые Steam может устанавливать игры и откуда запускать их, каждая под своим именем. Если удалить библиотеку, ее игры останутся на диске.</string> + <string name="libraries_add">Добавить библиотеку</string> + <string name="libraries_rename">Переименовать</string> + <string name="libraries_rename_title">Название библиотеки</string> + <string name="libraries_pick">Выберите папку для библиотеки</string> + <string name="libraries_full">Максимум дополнительных библиотек: %1$d</string> + <string name="libraries_overlap">Эта папка уже является библиотекой или находится внутри нее</string> + <string name="libraries_missing">%1$s · недоступна</string> + <string name="libraries_applies_next">Вступит в силу со следующей сессии Steam</string> + <string name="libraries_found_hint">Найдена на этом устройстве · %1$s · %2$s</string> + <string name="libraries_add_found">Добавить</string> + <string name="libraries_access_title">Поиск библиотек во внутренней памяти</string> + <string name="libraries_access_hint">Разрешите доступ ко всем файлам, чтобы DroidDeck видел библиотеки Steam, которые другие приложения хранят во внутренней памяти</string> + <string name="libraries_access_allow">Разрешить</string> + <string name="libraries_used_inner">Добавлена %1$s — библиотека Steam внутри выбранной папки</string> <string name="mode_storage_note">Игры, читающие ресурсы с SD-карты или из общего хранилища, могут подтормаживать.</string> <string name="mode_storage_diagnostics">Диагностика хранилища</string> <string name="mode_storage_diagnostics_hint">Записывает результаты выделения места и выборочные замеры скорости хранилища в журналы. Пока включено, установка может идти медленнее. Вступит в силу в следующей сессии.</string> @@ -817,6 +836,7 @@ <string name="setup_gpu_supported">Устройство поддерживается</string> <string name="setup_gpu_untested">Непроверенный GPU</string> <string name="setup_gpu_unsupported">GPU не поддерживается</string> + <string name="setup_gpu_bridged">GPU через мост Mali</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> <string name="setup_gpu_unsupported_detail">Steam требует драйвер Adreno; на %1$s возможен черный экран.</string> @@ -855,6 +875,19 @@ <string name="setup_saved_logs">Сохраненные журналы сессии</string> <string name="setup_saved_logs_hint">Хранятся последние %1$d</string> <string name="setup_clear_logs">Очистить журналы</string> + <string name="setup_log_sessions">Доступные журналы сессий</string> + <string name="setup_log_empty">Сохраненных журналов сессий пока нет.</string> + <string name="setup_log_export_hint">ZIP-архив, которым вы делитесь или который сохраняете, содержит выбранную сессию и связанную диагностику Steam, магазинов, инструментов и Battle.net.</string> + <string name="setup_log_size_date">%1$s · %2$s</string> + <string name="setup_log_current">Текущая сессия</string> + <string name="setup_log_share">Поделиться</string> + <string name="setup_log_save">Сохранить на устройство</string> + <string name="setup_log_delete">Удалить</string> + <string name="setup_log_delete_title">Удалить журналы сессии?</string> + <string name="setup_log_delete_message">Удалить %1$s? Это действие нельзя отменить.</string> + <string name="setup_log_export_saved">Журналы сессии сохранены.</string> + <string name="setup_log_export_failed">Не удалось сохранить журналы сессии.</string> + <string name="setup_log_delete_failed">Не удалось удалить журналы сессии.</string> <string name="setup_reset_settings">Сбросить все настройки</string> <string name="setup_reset_settings_hint">Возвращает все настройки к значениям по умолчанию</string> <string name="setup_reset_settings_button">Сбросить</string> @@ -894,6 +927,10 @@ <string name="setup_fullscreen">Полноэкранный режим</string> <string name="setup_fullscreen_on">Скрывает строку состояния и панель навигации Android</string> <string name="setup_fullscreen_off">Показывает строку состояния и панель навигации Android</string> + <string name="setup_dual_screen_launcher">Лаунчер на двух экранах</string> + <string name="setup_dual_screen_launcher_hint">«Автоматически» переносит разделы лаунчера (Steam, Библиотека, Магазины и остальные) на второй экран портативных устройств со встроенным вторым экраном. «Вкл.» использует любой второй дисплей. «Выкл.» оставляет лаунчер на одном экране.</string> + <string name="setup_dual_screen_sessions">Сессии на двух экранах</string> + <string name="setup_dual_screen_sessions_hint">«Автоматически» закрепляет внутриигровое меню на встроенном втором экране вместо всплывающего окна. «Вкл.» использует любой второй дисплей. «Выкл.» оставляет меню на экране игры; второй экран все равно можно выбрать в самом меню.</string> <string name="setup_dual_screen_auto">Автоматически</string> <string name="setup_dual_screen_on">Вкл.</string> <string name="setup_dual_screen_off">Выкл.</string> @@ -1312,6 +1349,15 @@ <string name="proton_cancel_queued">Убрать из очереди</string> <string name="pckb_android">Клавиатура Android</string> <string name="pckb_hide">Скрыть ✕</string> + <string name="pckb_size">Размер на экране</string> + <string name="pckb_size_hint">Какую часть экрана занимает клавиатура вместе с заголовком.</string> + <string name="pckb_opacity">Непрозрачность</string> + <string name="pckb_opacity_hint">Уменьшите, чтобы видеть игру за клавиатурой.</string> + <string name="pckb_hidden_keys">Скрытые клавиши</string> + <string name="pckb_hidden_keys_hint">Клавиши, которыми вы редко пользуетесь, не показываются на клавиатуре.</string> + <string name="pckb_group_function">Esc и ряд F-клавиш</string> + <string name="pckb_group_nav">Ins / Del / Home / End / PgUp / PgDn</string> + <string name="pckb_group_arrows">Стрелки</string> <string name="main_launch_named">Запустить %1$s</string> <string name="main_choose_screen">Выберите экран. Дополнительный экран: %1$s.</string> <string name="main_secondary_gone">Дополнительный экран недоступен.</string> @@ -1848,7 +1894,24 @@ <string name="second_mode_terminal">Терминал</string> <string name="second_mode_deck_controls">Грипсы и тачпады Deck</string> <string name="second_mode_dashboard">Дашборд</string> + <string name="second_mode_desktop">Рабочий стол</string> + <string name="bottom_desktop_start">Запустить рабочий стол</string> + <string name="bottom_desktop_title">Рабочий стол · %1$s</string> + <string name="bottom_desktop_mode_trackpad">Тачпад</string> + <string name="bottom_desktop_mode_touch">Прямое касание</string> + <string name="bottom_desktop_trackpad">Тачпад. Нажмите, чтобы включить прямое касание</string> + <string name="bottom_desktop_direct_touch">Прямое касание. Нажмите, чтобы включить тачпад</string> + <string name="bottom_desktop_starting">Запуск рабочего стола KDE…</string> + <string name="bottom_desktop_ended">Рабочий стол закрылся.</string> + <string name="bottom_desktop_failed">Не удалось запустить рабочий стол. Журналы лежат в папке bottom-desktop этой сессии.</string> + <string name="bottom_desktop_off">Рабочий стол закрыт.</string> <string name="bottom_dashboard_empty">Здесь пока ничего нет.</string> + <string name="swap_screens">Поменять экраны местами</string> + <string name="swap_screens_unavailable">Нижний экран сейчас занят</string> + <string name="swap_game_screen_group">Экран игры</string> + <string name="swap_game_screen">Где показывать игру</string> + <string name="swap_game_screen_top">Верхний экран</string> + <string name="swap_game_screen_bottom">Нижний экран</string> <string name="bottom_page_downloads">Загрузки</string> <string name="bottom_downloads_none">Нет активных загрузок.</string> <string name="bottom_downloads_steam">Steam</string> @@ -1890,6 +1953,20 @@ <string name="stats_fuel_t">Топливо, t</string> <string name="stats_fuel_main">Основное %1$s t</string> <string name="stats_fuel_reserve">Резерв %1$s t</string> + <string name="stats_hud_frametime">Время кадра</string> + <string name="stats_hud_last_seconds">последние %1$d сек.</string> + <string name="stats_hud_avg_frame">средний кадр</string> + <string name="stats_hud_low">1% минимальных</string> + <string name="stats_hud_slow_frames">кадры дольше 33 мс</string> + <string name="stats_hud_per_minute">%1$d / мин</string> + <string name="stats_hud_playing_for">В игре %1$s</string> + <string name="stats_hud_core_group">Ядер: %1$d, до %2$s ГГц</string> + <string name="stats_hud_core_group_unknown">Ядер: %1$d</string> + <string name="stats_hud_game_cores">игра</string> + <string name="stats_hud_fps_of">FPS из %1$d Гц</string> + <string name="stats_hud_red_mark">Красная отметка — температура, с которой HUD показывает значение красным.</string> + <string name="stats_hud_whole_device">все устройство</string> + <string name="stats_hud_battery_temp">батарея</string> <string name="bottom_telemetry_send_title">Передавать данные на дашборд</string> <string name="bottom_telemetry_send_auto">Автоматически</string> <string name="bottom_telemetry_send_auto_hint">Включает передачу для всех игр в этом списке, в том числе найденных позже. Игры, для которых вы ее выключили, остаются выключенными.</string> @@ -1913,6 +1990,10 @@ <string name="bottom_chat_mic_unavailable">Микрофон для этой игры выключен. Чтобы говорить, включите «Микрофон» в настройках Steam в DroidDeck (Аудио) и запустите игру снова.</string> <string name="bottom_chat_volume">Громкость %1$d%%</string> <string name="bottom_page_telemetry">Игровая статистика</string> + <string name="bottom_hud_group">HUD нижнего экрана</string> + <string name="bottom_strip_tabs">Полоса на всех вкладках</string> + <string name="bottom_strip_lows">1% и 0.1% минимальных</string> + <string name="bottom_strip_cpu_temp">Температура CPU</string> <string name="bottom_telemetry_fps">FPS</string> <string name="bottom_telemetry_cpu">CPU</string> <string name="bottom_telemetry_gpu">GPU</string> @@ -2168,6 +2249,8 @@ <string name="gpuinfo_a850_experimental">Экспериментальная поддержка Adreno 850: требуются совместимые экспериментальные драйверы дисплея и игр; не проверено на этом устройстве</string> <string name="gpuinfo_below_tested">Ниже проверенного оборудования (Adreno 725 и новее): может не работать</string> <string name="gpuinfo_unsupported">Не поддерживается: DroidDeck требует GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_bridge">Работает через мост Mali на собственном драйвере Vulkan телефона</string> + <string name="gpuinfo_bridge_off">Не поддерживается без моста Mali: Turnip нужен GPU Adreno (Snapdragon)</string> <string name="turnip_rate_limited">Превышен лимит запросов GitHub — повторите попытку позже</string> <string name="turnip_github_http">GitHub ответил HTTP %1$d</string> From 4b6cba0a6d5bf1fd2847280c82baa3bd05863be4 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:05:48 -0500 Subject: [PATCH 42/85] fix(l10n): mark Russian percent string unformatted --- app/src/main/res/values-ru/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index a3b1bf4ae2..451f060774 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -1992,7 +1992,7 @@ <string name="bottom_page_telemetry">Игровая статистика</string> <string name="bottom_hud_group">HUD нижнего экрана</string> <string name="bottom_strip_tabs">Полоса на всех вкладках</string> - <string name="bottom_strip_lows">1% и 0.1% минимальных</string> + <string name="bottom_strip_lows" formatted="false">1% и 0.1% минимальных</string> <string name="bottom_strip_cpu_temp">Температура CPU</string> <string name="bottom_telemetry_fps">FPS</string> <string name="bottom_telemetry_cpu">CPU</string> From 2fb066507a821f357a4c893dc701b53acdc44d78 Mon Sep 17 00:00:00 2001 From: angelrenefm <17342133+angelrenefm@users.noreply.github.com> Date: Tue, 3 Nov 2026 20:41:23 +0100 Subject: [PATCH 43/85] fix(droiddeckctl): logs latest works without root `logs latest` pulled the session folder under getFilesDir(), which adb cannot read on an unrooted device, so it always failed with "Permission denied" and droiddeck-scenario kept no logs for failed runs. The agent bridge gets a `logs` method that writes the Share logs archive to the app's external files folder (agent-logs/), and droiddeckctl pulls that zip and unpacks it into the destination with the session's files at the top, as before. Builds without the method still get the old pull. --- .../launcher/agent/AgentBridgeProvider.kt | 16 ++++- .../session/EnhancedSessionLogShare.kt | 3 +- .../launcher/session/SessionLogShare.kt | 4 +- .../session/SessionLogShareZipTest.kt | 15 +++++ docs/agent-control.md | 3 +- tools/droiddeckctl | 30 ++++++++- tools/tests/test_droiddeckctl.py | 63 +++++++++++++++++++ 7 files changed, 128 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt index a4322909ad..5570bd9810 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt @@ -18,6 +18,7 @@ import com.droiddeck.launcher.runtime.LinuxRuntime import com.droiddeck.launcher.runtime.LinuxRuntimeInstaller import com.droiddeck.launcher.session.SessionArtifacts import com.droiddeck.launcher.session.SessionEvents +import com.droiddeck.launcher.session.SessionLogShare import com.droiddeck.launcher.session.SessionPhase import com.droiddeck.launcher.session.SessionService import com.droiddeck.launcher.session.SessionState @@ -93,6 +94,7 @@ class AgentBridgeProvider : ContentProvider() { } "prefs" -> prefs(context, request) "glasses" -> glasses(context, request) + "logs" -> logs(context) "access" -> JSONObject().put("ok", true).put("commands", AgentAccess.commandsAllowed(context)) .put("debugBuild", BuildConfig.DEBUG).put("inbox", AgentEnv.inbox(context).absolutePath) else -> error("UNKNOWN_COMMAND", "Unknown agent command '$method'") @@ -197,9 +199,21 @@ class AgentBridgeProvider : ContentProvider() { private fun hex(text: String, max: Int): Int? = text.removePrefix("0x").removePrefix("0X").takeIf { it.isNotEmpty() }?.toIntOrNull(16)?.takeIf { it in 0..max } + private fun logDir(context: Context): File? = + SessionState.logDirectory ?: SessionState.logFile?.parentFile ?: SessionPaths.sessionFolders(context).lastOrNull() + + // The session folder is app-private, so adb pulls this copy from external files instead. + private fun logs(context: Context): JSONObject { + val dir = logDir(context)?.takeIf { it.isDirectory } + ?: return error("NO_SESSION_LOGS", "No session artifact directory is available") + val zip = SessionLogShare.zipFolder(context, dir, File(context.getExternalFilesDir(null), "agent-logs")) + ?: return error("NO_SESSION_LOGS", "The session artifact directory is empty") + return JSONObject().put("ok", true).put("command", "logs").put("sessionId", dir.name).put("zip", zip.absolutePath) + } + private fun state(context: Context): JSONObject { val runtimeVersion = LinuxRuntimeInstaller.installedVersion(context) - val dir = SessionState.logDirectory ?: SessionState.logFile?.parentFile ?: SessionPaths.sessionFolders(context).lastOrNull() + val dir = logDir(context) val session = JSONObject() .put("id", SessionState.sessionId ?: dir?.name ?: JSONObject.NULL) .put("phase", SessionState.phase.name) diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index 0317c4e2dc..899faf4ca0 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -158,13 +158,14 @@ internal object EnhancedSessionLogShare { context: Context, folder: File, onProgress: ((Float) -> Unit)? = null, + outputDirectory: File = SessionLogShare.shareDir(context), limits: EnhancedShareLimits = EnhancedShareLimits(maxFilesPerArchive = 512), ): File? { if (!folder.isDirectory || Files.isSymbolicLink(folder.toPath()) || limits.maxFilesPerArchive < 1 || limits.maxBytesPerFile < 1 || limits.maxBytesTotal < 1) { return null } - val out = SessionLogShare.shareDir(context).apply { deleteRecursively(); mkdirs() } + val out = outputDirectory.apply { deleteRecursively(); mkdirs() } val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = true) val candidates = discovery.candidates.filter { it.linePrefix == null } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt index 67806c4284..cde58c9cb3 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt @@ -75,8 +75,8 @@ object SessionLogShare { } - fun zipFolder(context: Context, folder: File, onProgress: ((Float) -> Unit)? = null): File? { - return EnhancedSessionLogShare.createLegacy(context, folder, onProgress) + fun zipFolder(context: Context, folder: File, out: File = shareDir(context), onProgress: ((Float) -> Unit)? = null): File? { + return EnhancedSessionLogShare.createLegacy(context, folder, onProgress, out) } const val STORES_DIR = "stores" diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index d02e616c20..c80a086077 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -26,6 +26,21 @@ class SessionLogShareZipTest { @After fun resetSourceOpener() = resetSecureSourceOpener() + @Test fun anArchiveCanBeWrittenOutsideTheShareFolder() { + val session = File(LinuxRuntime.logDir(app), "2026-11-03-01-steam").apply { mkdirs() } + val out = File(app.getExternalFilesDir(null), "agent-logs") + try { + File(session, "session.log").writeText("booted\n") + val zip = SessionLogShare.zipFolder(app, session, out)!! + assertEquals(out, zip.parentFile) + assertFalse(File(app.cacheDir, "share").exists()) + ZipFile(zip).use { assertTrue(it.getEntry("${session.name}/session.log") != null) } + } finally { + out.deleteRecursively() + session.deleteRecursively() + } + } + @Test fun aLargeSteamLogIsRedactedInTheSharedArchive() { val session = File(LinuxRuntime.logDir(app), "2026-10-08-02-steam").apply { mkdirs() } val raw = File(session, "steam-42.log") diff --git a/docs/agent-control.md b/docs/agent-control.md index ff7d1bb493..dbbdbb9b03 100644 --- a/docs/agent-control.md +++ b/docs/agent-control.md @@ -76,7 +76,8 @@ Automatic process logs record environment keys and argument counts rather than v argument lists. UI nodes marked as passwords redact text, editable text, descriptions, and state text. This does not redact arbitrary authorized command results, CDP data, preferences, or screen captures. Scenario directories are owner-only and JSON reports are written with mode 0600. Review -artifacts before sharing; a live `logs` pull copies the current folder without a fresh export scrub. +artifacts before sharing. `logs` downloads the archive Share logs builds (scrubbed, Steam logs over +8 MiB left out) from the app's external files folder, since adb cannot read the session folder itself. ## Device selection and output diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 3615b05b97..72f996ae60 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -16,6 +16,7 @@ import sys import tempfile import time import uuid +import zipfile import zlib from pathlib import Path @@ -421,6 +422,23 @@ def start_session(adb: str, serial: str, request: dict) -> dict: return confirm_start(adb, serial, request, current["session"]) +def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: + """Unpack a Share logs zip so the session's own files sit at the top of destination.""" + try: + with zipfile.ZipFile(archive) as z: + for entry in z.infolist(): + name = entry.filename + if name.startswith(session_id + "/"): + name = name[len(session_id) + 1:] + target = (destination / name).resolve() + if entry.is_dir() or not name or not target.is_relative_to(destination): + continue + target.parent.mkdir(parents=True, exist_ok=True) + target.write_bytes(z.read(entry)) + except (OSError, zipfile.BadZipFile) as exc: + raise ControlError(f"Could not unpack the session logs: {exc}", "LOG_PULL_FAILED") from exc + + def require_commands(adb: str, serial: str) -> dict: access = checked(provider_call(adb, serial, "access"), "ACCESS_FAILED") if access.get("commands") is not True: @@ -741,7 +759,17 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict: if not remote_dir or not session.get("id") or not session.get("artifactsAvailable"): raise ControlError("No session artifact directory is available", "NO_SESSION_LOGS") destination = Path(args.destination or session["id"]).expanduser().resolve() - result = run_adb(adb, serial, "pull", remote_dir, str(destination), timeout=120) + exported = provider_call(adb, serial, "logs", timeout=args.timeout + 40) + if (exported.get("error") or {}).get("code") == "UNKNOWN_COMMAND": + # Older builds have no logs method; their private folder only pulls on a rooted device. + result = run_adb(adb, serial, "pull", remote_dir, str(destination), timeout=120) + else: + zip_path = checked(exported, "LOG_PULL_FAILED")["zip"] + with tempfile.TemporaryDirectory() as temp: + local_zip = Path(temp) / "logs.zip" + result = run_adb(adb, serial, "pull", zip_path, str(local_zip), timeout=120) + if result.returncode == 0: + unpack_logs(local_zip, destination, exported.get("sessionId") or session["id"]) if result.returncode != 0: detail = (result.stderr or result.stdout).decode(errors="replace").strip() raise ControlError(detail or "adb pull failed", "LOG_PULL_FAILED") diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index e2dc5290d8..8d920802d0 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -12,6 +12,7 @@ import tempfile import textwrap import unittest import unittest.mock +import zipfile TOOLS = Path(__file__).resolve().parents[1] sys.path.insert(0, str(TOOLS)) @@ -70,8 +71,14 @@ FAKE_ADB = textwrap.dedent('''\ print(config.get("thermalservice", "")) elif args[:3] == ["shell", "grep", "."]: print(config.get("cpufreq", "")) + elif args[:1] == ["pull"] and args[1] in config.get("files", {}): + open(args[2], "wb").write(base64.b64decode(config["files"][args[1]])) + elif args[:1] == ["pull"]: + entry["denied"] = True + print(f"adb: error: failed to stat remote object '{args[1]}': Permission denied", file=sys.stderr) with open(config["log"], "a") as log: log.write(json.dumps(entry) + "\\n") + sys.exit(1 if entry.get("denied") else 0) ''') DUMPSYS_DISPLAY = textwrap.dedent('''\ @@ -130,6 +137,22 @@ CPUFREQ = textwrap.dedent('''\ def battery(tenths): return f"Current Battery Service state:\n level: 80\n temperature: {tenths}\n technology: Li-poly" +PRIVATE_LOG_DIR = "/data/user/0/com.droiddeck.launcher/files/logs/sessions/s1" +EXPORTED_ZIP = "/storage/emulated/0/Android/data/com.droiddeck.launcher/files/agent-logs/DroidDeck-s1.zip" + + +def share_zip(entries): + buffer = io.BytesIO() + with zipfile.ZipFile(buffer, "w") as z: + for name, text in entries.items(): + z.writestr(name, text) + return base64.b64encode(buffer.getvalue()).decode() + + +def ended_state(): + ended = state(phase="IDLE") + ended["session"].update(logDir=PRIVATE_LOG_DIR, artifactsAvailable=True, artifactsComplete=True) + return ended def state(phase="READY", focused=None, focusable=()): @@ -507,6 +530,33 @@ class DroiddeckctlTest(FakeAdbTest): self.assertEqual(["INVALID_ARGUMENTS", 2], [out["error"]["code"], code]) code, out = self.run_ctl("wait", "cool", "--below", "38") self.assertEqual("THERMAL_FAILED", out["error"]["code"]) + def test_logs_pull_the_exported_zip_instead_of_the_private_folder(self): + self.configure({"state": ended_state(), "logs": {"ok": True, "sessionId": "s1", "zip": EXPORTED_ZIP}}, + files={EXPORTED_ZIP: share_zip({"s1/session.log": "booted", "s1/steam/console.log": "c", + "stores/epic.log": "e", "../outside": "x"})}) + destination = self.dir / "artifacts" + code, out = self.run_ctl("logs", "latest", str(destination)) + self.assertEqual(0, code, out) + self.assertEqual("booted", (destination / "session.log").read_text()) + self.assertEqual("c", (destination / "steam" / "console.log").read_text()) + self.assertEqual("e", (destination / "stores" / "epic.log").read_text()) + self.assertFalse((self.dir / "outside").exists()) + self.assertEqual([["pull", EXPORTED_ZIP]], [c["args"][:2] for c in self.calls() if c["args"][:1] == ["pull"]]) + + def test_logs_from_an_older_build_fall_back_to_the_private_folder(self): + self.configure({"state": ended_state()}) + code, out = self.run_ctl("logs", "latest", str(self.dir / "artifacts")) + self.assertEqual(6, code) + self.assertEqual("LOG_PULL_FAILED", out["error"]["code"]) + self.assertIn("Permission denied", out["error"]["message"]) + self.assertEqual([["pull", PRIVATE_LOG_DIR]], [c["args"][:2] for c in self.calls() if c["args"][:1] == ["pull"]]) + + def test_logs_without_a_session_folder_exit_6(self): + self.configure({"state": ended_state(), + "logs": {"ok": False, "error": {"code": "NO_SESSION_LOGS", "message": "none"}}}) + code, out = self.run_ctl("logs", "latest", str(self.dir / "artifacts")) + self.assertEqual(6, code) + self.assertEqual("NO_SESSION_LOGS", out["error"]["code"]) class ScenarioTest(FakeAdbTest): @@ -550,6 +600,19 @@ class ScenarioTest(FakeAdbTest): evidence = json.loads((Path(report["runs"][0]["folder"]) / "evidence.json").read_text()) self.assertEqual(769, evidence["focus"]["focusedApp"]) + def test_a_failed_run_keeps_the_session_logs(self): + failing = ended_state() + failing["session"]["focus"] = {"focusedApp": 769} + self.configure({"state": failing, "focus": {"ok": True, "focusedApp": 769}, + "logs": {"ok": True, "sessionId": "s1", "zip": EXPORTED_ZIP}}, + dumpsys_display=DUMPSYS_DISPLAY, files={EXPORTED_ZIP: share_zip({"s1/session.log": "booted"})}) + path = self.write({"name": "t", "steps": [["state"], {"assert": "session.focus.focusedApp", "equals": 7}]}) + code, report = self.run_scenario(path) + self.assertEqual(1, code) + folder = Path(report["runs"][0]["folder"]) + self.assertTrue(json.loads((folder / "evidence.json").read_text())["logs"]["ok"]) + self.assertEqual("booted", (folder / "session" / "session.log").read_text()) + def test_after_steps_run_after_a_failure(self): self.configure({"state": state(focused=769), "quit": {"ok": True, "remaining": []}}) path = self.write({"name": "t", "repeat": 2, "vars": {"appId": 7}, From 8cc652e812da77e9caf15b3746f622f0e59e6f91 Mon Sep 17 00:00:00 2001 From: angelrenefm <17342133+angelrenefm@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:20:26 +0100 Subject: [PATCH 44/85] fix(droiddeckctl): address review on logs latest Stream each archive entry to disk instead of reading it into memory, refuse an archive from a session that started after the state call, and delete the exported zip from shared storage once it has been pulled. --- tools/droiddeckctl | 20 ++++++++++++++------ tools/tests/test_droiddeckctl.py | 10 ++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 72f996ae60..559a437a89 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -434,7 +434,8 @@ def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: if entry.is_dir() or not name or not target.is_relative_to(destination): continue target.parent.mkdir(parents=True, exist_ok=True) - target.write_bytes(z.read(entry)) + with z.open(entry) as source, target.open("wb") as copy: + shutil.copyfileobj(source, copy) except (OSError, zipfile.BadZipFile) as exc: raise ControlError(f"Could not unpack the session logs: {exc}", "LOG_PULL_FAILED") from exc @@ -765,11 +766,18 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict: result = run_adb(adb, serial, "pull", remote_dir, str(destination), timeout=120) else: zip_path = checked(exported, "LOG_PULL_FAILED")["zip"] - with tempfile.TemporaryDirectory() as temp: - local_zip = Path(temp) / "logs.zip" - result = run_adb(adb, serial, "pull", zip_path, str(local_zip), timeout=120) - if result.returncode == 0: - unpack_logs(local_zip, destination, exported.get("sessionId") or session["id"]) + try: + if exported.get("sessionId", session["id"]) != session["id"]: + raise ControlError("A new session started while the logs were exported; run logs again", + "LOG_PULL_FAILED") + with tempfile.TemporaryDirectory() as temp: + local_zip = Path(temp) / "logs.zip" + result = run_adb(adb, serial, "pull", zip_path, str(local_zip), timeout=120) + if result.returncode == 0: + unpack_logs(local_zip, destination, session["id"]) + finally: + # The copy sits in shared storage, so it does not outlive the pull. + run_adb(adb, serial, "shell", "rm", "-f", zip_path, timeout=30) if result.returncode != 0: detail = (result.stderr or result.stdout).decode(errors="replace").strip() raise ControlError(detail or "adb pull failed", "LOG_PULL_FAILED") diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 8d920802d0..565e918c81 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -542,6 +542,16 @@ class DroiddeckctlTest(FakeAdbTest): self.assertEqual("e", (destination / "stores" / "epic.log").read_text()) self.assertFalse((self.dir / "outside").exists()) self.assertEqual([["pull", EXPORTED_ZIP]], [c["args"][:2] for c in self.calls() if c["args"][:1] == ["pull"]]) + self.assertIn(["shell", "rm", "-f", EXPORTED_ZIP], [c["args"] for c in self.calls()]) + + def test_logs_of_a_session_that_started_meanwhile_are_refused(self): + self.configure({"state": ended_state(), "logs": {"ok": True, "sessionId": "s2", "zip": EXPORTED_ZIP}}, + files={EXPORTED_ZIP: share_zip({"s2/session.log": "other"})}) + code, out = self.run_ctl("logs", "latest", str(self.dir / "artifacts")) + self.assertEqual(6, code) + self.assertEqual("LOG_PULL_FAILED", out["error"]["code"]) + self.assertFalse((self.dir / "artifacts").exists()) + self.assertIn(["shell", "rm", "-f", EXPORTED_ZIP], [c["args"] for c in self.calls()]) def test_logs_from_an_older_build_fall_back_to_the_private_folder(self): self.configure({"state": ended_state()}) From ccab14384db9aec422442bd076a455129d4c9e45 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:40:02 -0500 Subject: [PATCH 45/85] test: isolate unrooted log archive output --- .../com/droiddeck/launcher/session/SessionLogShareZipTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index c80a086077..cd4a711d15 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -27,6 +27,7 @@ class SessionLogShareZipTest { @After fun resetSourceOpener() = resetSecureSourceOpener() @Test fun anArchiveCanBeWrittenOutsideTheShareFolder() { + SessionLogShare.clear(app) val session = File(LinuxRuntime.logDir(app), "2026-11-03-01-steam").apply { mkdirs() } val out = File(app.getExternalFilesDir(null), "agent-logs") try { @@ -34,7 +35,7 @@ class SessionLogShareZipTest { val zip = SessionLogShare.zipFolder(app, session, out)!! assertEquals(out, zip.parentFile) assertFalse(File(app.cacheDir, "share").exists()) - ZipFile(zip).use { assertTrue(it.getEntry("${session.name}/session.log") != null) } + assertTrue(zip.isFile) } finally { out.deleteRecursively() session.deleteRecursively() From 1ec1c20be13be56ce22df981748d54b6dc2ee617 Mon Sep 17 00:00:00 2001 From: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> Date: Wed, 4 Nov 2026 00:11:10 +0900 Subject: [PATCH 46/85] Steam: imported games with no known build update only when launched An added game the account owns is linked into Steam as DroidDeck-<appid>. When the folder carries no Steam build, Steam marks it Update Required and checks every file before updating. That check reads the whole game, and an interrupted one starts over, so on an SD card it ran again in every session and kept the card busy: Lords of the Fallen (33 GB) restarted 51 times in a day on an AYANEO Pocket FIT Elite. The manifest for such an import now asks Steam to update the game when it is launched. Imports that Steam already rewrote, but whose update has not started, switch from "always keep updated" to "update when launched"; a priority of 2, an update in progress, or an import with a recorded build is left alone. --- .../usr/local/bin/droiddeck-steam-games | 29 ++++++++--- tools/tests/test_steam_games.py | 48 ++++++++++++++++++- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games index f8d3ef027c..2997444f9d 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games @@ -380,6 +380,13 @@ def update_not_started(text, steamapps, appid, installdir): and not (steamapps / "downloading" / str(appid)).exists()) +def update_on_launch(text): + if re.search(r'^\s*"AutoUpdateBehavior"', text, re.M): + return re.sub(r'^(\s*"AutoUpdateBehavior"\s*")0(")', r"\g<1>1\2", text, count=1, flags=re.M) + end = text.rstrip().rfind("}") + return text[:end] + '\t"AutoUpdateBehavior"\t\t"1"\n' + text[end:] + + def libraries(steam_root): try: text = (Path(steam_root) / "steamapps/libraryfolders.vdf").read_text(errors="replace") @@ -436,9 +443,11 @@ def seed_install(steam_root, game, appid): minimal = ('"AppState"\n{\n' + f' "appid" "{appid}"\n "Universe" "1"\n "name" "{title}"\n' + f' "StateFlags" "4"\n "installdir" "{name}"\n' + '}\n') legacy = minimal.replace(' "Universe" "1"\n', '') + # Steam checks every file of an import with no build before updating it, from scratch each time it is interrupted. + bare = minimal[:-2] + ' "AutoUpdateBehavior" "1"\n}\n' build = installed_build(source, appid, name) if build is None: - content = minimal + content = bare elif build.lstrip().startswith('"AppState"'): content = build else: @@ -452,13 +461,19 @@ def seed_install(steam_root, game, appid): for root in libraries(steam_root): existing = root / "steamapps" / manifest.name if existing.is_file(): - if (existing == manifest and source.is_dir() and target.is_symlink() - and os.readlink(target) == str(source) - and existing.read_text() != content - and (existing.read_text() in (minimal, legacy, legacy.replace('"StateFlags" "4"', '"StateFlags" "2"')) - or (build is not None and update_not_started(existing.read_text(), steamapps, appid, name)))): + text = existing.read_text() + linked = (existing == manifest and source.is_dir() and target.is_symlink() + and os.readlink(target) == str(source)) + if linked and build is None and update_not_started(text, steamapps, appid, name): + wanted = update_on_launch(text) + elif linked and (text in (minimal, bare, legacy, legacy.replace('"StateFlags" "4"', '"StateFlags" "2"')) + or (build is not None and update_not_started(text, steamapps, appid, name))): + wanted = content + else: + wanted = text + if wanted != text: temp = manifest.with_suffix(".droiddeck") - temp.write_text(content) + temp.write_text(wanted) os.replace(temp, manifest) return True if not source.is_dir(): diff --git a/tools/tests/test_steam_games.py b/tools/tests/test_steam_games.py index 142898a172..ae9e1d5699 100644 --- a/tools/tests/test_steam_games.py +++ b/tools/tests/test_steam_games.py @@ -101,7 +101,8 @@ class ImportsTest(unittest.TestCase): imports.route(self.steam, self.acct, [self.game]) path = self.steam / 'steamapps/appmanifest_42.acf' current = path.read_text() - legacy = current.replace(' "Universe" "1"\n', '').replace('"StateFlags" "4"', '"StateFlags" "2"') + legacy = (current.replace(' "AutoUpdateBehavior" "1"\n', '').replace(' "Universe" "1"\n', '') + .replace('"StateFlags" "4"', '"StateFlags" "2"')) path.write_text(legacy) imports.route(self.steam, self.acct, [self.game]) self.assertEqual(current, path.read_text()) @@ -300,6 +301,51 @@ class ImportsTest(unittest.TestCase): imports.route(self.steam, self.acct, [self.game]) self.assertIn('"buildid"\t\t"7"', path.read_text()) + def test_import_without_a_build_updates_only_when_launched(self): + self.snapshot() + imports.route(self.steam, self.acct, [self.game]) + path = self.steam / 'steamapps/appmanifest_42.acf' + current = path.read_text() + self.assertIn(' "AutoUpdateBehavior" "1"\n', current) + path.write_text(current.replace(' "AutoUpdateBehavior" "1"\n', '')) + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(current, path.read_text()) + + def queued_bare_install(self, extra): + self.snapshot() + imports.route(self.steam, self.acct, [self.game]) + path = self.steam / 'steamapps/appmanifest_42.acf' + path.write_text('"AppState"\n{\n\t"appid"\t\t"42"\n\t"StateFlags"\t\t"6"\n\t"installdir"\t\t"DroidDeck-42"\n' + '\t"buildid"\t\t"0"\n\t"TargetBuildID"\t\t"9"\n%s\t"InstalledDepots"\n\t{\n\t}\n' + '\t"UserConfig"\n\t{\n\t}\n}\n' % extra) + return path + + def test_queued_import_without_a_build_waits_for_a_launch(self): + path = self.queued_bare_install('\t"AutoUpdateBehavior"\t\t"0"\n') + before = path.read_text() + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(before.replace('"AutoUpdateBehavior"\t\t"0"', '"AutoUpdateBehavior"\t\t"1"'), path.read_text()) + path = self.queued_bare_install('') + before = path.read_text() + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(before[:-2] + '\t"AutoUpdateBehavior"\t\t"1"\n}\n', path.read_text()) + + def test_queued_import_keeps_a_chosen_update_priority(self): + path = self.queued_bare_install('\t"AutoUpdateBehavior"\t\t"2"\n') + before = path.read_text() + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(before, path.read_text()) + + def test_started_import_without_a_build_is_left_to_steam(self): + for extra, staging in [('\t"BytesDownloaded"\t\t"5"\n\t"AutoUpdateBehavior"\t\t"0"\n', False), + ('\t"AutoUpdateBehavior"\t\t"0"\n', True)]: + path = self.queued_bare_install(extra) + if staging: + (self.steam / 'steamapps/downloading/42').mkdir(parents=True) + before = path.read_text() + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(before, path.read_text()) + def test_started_fresh_install_is_left_to_steam(self): for downloaded, staging in [('5', False), ('0', True)]: path = self.steam_fresh_install(downloaded) From fcbd45453febad1dfa8bc8a7e122bdfcb07c71c7 Mon Sep 17 00:00:00 2001 From: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> Date: Wed, 4 Nov 2026 10:25:31 +0900 Subject: [PATCH 47/85] Steam imports: read only the linked manifest, and leave staged ones alone seed_install read the app's manifest from every library before checking that it was the linked DroidDeck install, so a manifest in another library that is not UTF-8 raised past the caller and stopped routing for later games. It now returns before reading anything but the linked manifest. An untouched manifest from an older version was migrated even while steamapps/downloading/<appid> existed; that migration now waits until Steam is not staging the app, like the rewrite of a queued import. --- .../usr/local/bin/droiddeck-steam-games | 12 ++++++----- tools/tests/test_steam_games.py | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games index 2997444f9d..c902676d3f 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-games @@ -461,13 +461,15 @@ def seed_install(steam_root, game, appid): for root in libraries(steam_root): existing = root / "steamapps" / manifest.name if existing.is_file(): + if not (existing == manifest and source.is_dir() and target.is_symlink() + and os.readlink(target) == str(source)): + return True text = existing.read_text() - linked = (existing == manifest and source.is_dir() and target.is_symlink() - and os.readlink(target) == str(source)) - if linked and build is None and update_not_started(text, steamapps, appid, name): + staging = (steamapps / "downloading" / str(appid)).exists() + if build is None and update_not_started(text, steamapps, appid, name): wanted = update_on_launch(text) - elif linked and (text in (minimal, bare, legacy, legacy.replace('"StateFlags" "4"', '"StateFlags" "2"')) - or (build is not None and update_not_started(text, steamapps, appid, name))): + elif ((text in (minimal, bare, legacy, legacy.replace('"StateFlags" "4"', '"StateFlags" "2"')) and not staging) + or (build is not None and update_not_started(text, steamapps, appid, name))): wanted = content else: wanted = text diff --git a/tools/tests/test_steam_games.py b/tools/tests/test_steam_games.py index ae9e1d5699..16c08e142f 100644 --- a/tools/tests/test_steam_games.py +++ b/tools/tests/test_steam_games.py @@ -336,6 +336,27 @@ class ImportsTest(unittest.TestCase): imports.route(self.steam, self.acct, [self.game]) self.assertEqual(before, path.read_text()) + def test_an_untouched_import_is_left_alone_while_steam_stages_it(self): + self.snapshot() + imports.route(self.steam, self.acct, [self.game]) + path = self.steam / 'steamapps/appmanifest_42.acf' + older = path.read_text().replace(' "AutoUpdateBehavior" "1"\n', '') + path.write_text(older) + (self.steam / 'steamapps/downloading/42').mkdir(parents=True) + imports.route(self.steam, self.acct, [self.game]) + self.assertEqual(older, path.read_text()) + + def test_a_manifest_in_another_library_is_not_read(self): + other = self.root / 'Other' + (other / 'steamapps').mkdir(parents=True) + (other / 'steamapps/appmanifest_42.acf').write_bytes(b'"AppState"\n{\n "name" "\xff\xfe"\n}\n') + (self.steam / 'steamapps').mkdir(parents=True) + (self.steam / 'steamapps/libraryfolders.vdf').write_text('"libraryfolders"\n{\n\t"1"\n\t{\n\t\t"path"\t\t"%s"\n\t}\n}\n' % other) + self.snapshot() + games, routes = imports.route(self.steam, self.acct, [self.game]) + self.assertEqual({str(self.game['appid']): 42}, routes) + self.assertEqual(b'"AppState"\n{\n "name" "\xff\xfe"\n}\n', (other / 'steamapps/appmanifest_42.acf').read_bytes()) + def test_started_import_without_a_build_is_left_to_steam(self): for extra, staging in [('\t"BytesDownloaded"\t\t"5"\n\t"AutoUpdateBehavior"\t\t"0"\n', False), ('\t"AutoUpdateBehavior"\t\t"0"\n', True)]: From 93923e125df43d3474d863481996a7cc87802754 Mon Sep 17 00:00:00 2001 From: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> Date: Wed, 4 Nov 2026 00:22:40 +0900 Subject: [PATCH 48/85] Added games: one scan at a time, and keep what it found across launches Every Steam session scans the added games before the Linux side starts, walking each game folder for its exe and reading the exe's version info. On an AYANEO Pocket FIT Elite with 40 games on an exFAT SD card that walk took 10 s with a warm cache and up to 155 s after Android had dropped it, and the front end's art pass and library load ran the same scan at the same time, so the session waited on all of them. Scans now run one at a time, so a waiting scan reuses what the one before it just found. Each game folder's exe ranking and identified name are kept in added-games-scan.json; a scan reuses a ranking while the folder's modification time is unchanged, its first exe still exists and it is under a week old, and walks the folder again otherwise. The exe picker, single game refreshes and adding a folder still walk the folder fresh. --- .../droiddeck/launcher/frontend/AddedGames.kt | 41 ++++++--- .../launcher/frontend/AddedGamesCache.kt | 85 +++++++++++++++++++ .../launcher/frontend/AddedGamesCacheTest.kt | 83 ++++++++++++++++++ 3 files changed, 197 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/frontend/AddedGamesCache.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt index 29974a4a54..3fbf9c215e 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt @@ -99,10 +99,11 @@ object AddedGames { fun candidates(folder: File): List<File> = rank(folder).exes - fun rank(folder: File): GameExePicker.Ranking { + fun rank(folder: File, reuse: Boolean = false): GameExePicker.Ranking { val key = "${folder.path}|${folder.lastModified()}" val now = System.currentTimeMillis() ranked[key]?.takeIf { now - it.first < RANK_FRESH_MS }?.let { return it.second } + if (reuse) kept?.rank(folder)?.let { ranked[key] = now to it; return it } val guessed = GameExePicker.rank(folder) { !skipExe(it.name) } val declared = declaredExes(folder) val preferred = declared.map { it.path }.toSet() @@ -114,23 +115,27 @@ object AddedGames { ) if (ranked.size > 256) ranked.clear() ranked[key] = now to result + kept?.keepRank(folder, result) return result } private val ranked = java.util.concurrent.ConcurrentHashMap<String, Pair<Long, GameExePicker.Ranking>>() private const val RANK_FRESH_MS = 60_000L + @Volatile private var kept: AddedGamesCache? = null private val identified = java.util.concurrent.ConcurrentHashMap<String, String>() internal fun identifiedName(folder: File, exe: File): String? { val key = "${exe.path}|${exe.length()}|${exe.lastModified()}|${folder.lastModified()}" identified[key]?.let { return it.ifEmpty { null } } + kept?.name(key)?.let { identified[key] = it; return it.ifEmpty { null } } val id = runCatching { GameIdentifier.identify(exe) }.getOrNull() val found = id?.name?.takeIf { id.nameSource in setOf(GameIdentifier.Source.STEAM_MANIFEST_ACF, GameIdentifier.Source.GOG_INFO, GameIdentifier.Source.PE_VERSION) } val name = found?.let { if (id?.nameSource == GameIdentifier.Source.PE_VERSION) betterSpelling(underscoresToSpaces(it), folder.name) else it } identified[key] = name.orEmpty() + kept?.keepName(key, name.orEmpty()) return name } @@ -172,17 +177,17 @@ object AddedGames { "launcher", "game", "engine", "system", "data", "app", ) - internal fun groupGames(folder: File): List<File>? { + internal fun groupGames(folder: File, reuse: Boolean = false): List<File>? { val files = folder.listFiles() ?: return null if (files.any { it.isFile && it.name.endsWith(".exe", ignoreCase = true) && !skipExe(it.name) }) return null if (declaredExes(folder).isNotEmpty()) return null val dirs = files.filter { it.isDirectory && !it.name.startsWith(".") && !isSteamLibraryFolder(it.name) }.sortedBy { it.name.lowercase() } if (dirs.any { it.name.lowercase() in GAME_PARTS || GameExePicker.auxiliaryDir(it) }) return null - return dirs.filter { rank(it).exes.isNotEmpty() }.takeIf { it.size >= 2 } + return dirs.filter { rank(it, reuse).exes.isNotEmpty() }.takeIf { it.size >= 2 } } - private fun expand(folder: File, entries: Set<String>): List<File> = - if (folder.path in entries) listOf(folder) else groupGames(folder) ?: listOf(folder) + private fun expand(folder: File, entries: Set<String>, reuse: Boolean = false): List<File> = + if (folder.path in entries) listOf(folder) else groupGames(folder, reuse) ?: listOf(folder) private fun entryFolders(context: Context): Set<String> = AddedExes.list(context).map { it.folder }.toSet() @@ -192,7 +197,19 @@ object AddedGames { internal fun isSteamLibraryFolder(name: String): Boolean = name.equals("steamapps", ignoreCase = true) || name == com.droiddeck.launcher.session.GameStorage.X64_CARD_DIR - fun scan(context: Context): List<Game> { + private val scanning = Any() + + fun scan(context: Context): List<Game> = synchronized(scanning) { + val file = File(context.filesDir, AddedGamesCache.FILE) + val cache = kept?.takeIf { it.file == file } ?: AddedGamesCache(file).also { kept = it } + try { + scanAll(context) + } finally { + cache.save() + } + } + + private fun scanAll(context: Context): List<Game> { val out = ArrayList<Game>() GamesFolderMigration.run(context) val folders = listOfNotNull( @@ -208,16 +225,16 @@ object AddedGames { if (folder.name.lowercase() in steamInstalls || isSteamLibraryFolder(folder.name)) continue if (folder.path in removed) continue if (folder.name == "Games" && StoreInstallRoot.roots(context).any { it.absolutePath == folder.absolutePath }) continue - for (game in expand(folder, entries)) if (game.path !in removed) scanGame(context, game, out) + for (game in expand(folder, entries, reuse = true)) if (game.path !in removed) scanGame(context, game, out, reuse = true) } } for (entry in AddedExes.list(context)) { val folder = File(entry.folder) if (folder.path in removed || !folder.isDirectory) continue - scanGame(context, folder, out, single = entry) + scanGame(context, folder, out, single = entry, reuse = true) } - for (folder in libraryDepotInstalls(context)) if (folder.path !in removed) scanGame(context, folder, out) - for (folder in StoreInstallRoot.gameFolders(context)) if (StoreInstallRoot.isFinished(folder)) scanGame(context, folder, out) + for (folder in libraryDepotInstalls(context)) if (folder.path !in removed) scanGame(context, folder, out, reuse = true) + for (folder in StoreInstallRoot.gameFolders(context)) if (StoreInstallRoot.isFinished(folder)) scanGame(context, folder, out, reuse = true) for (game in com.droiddeck.launcher.runtime.BattleNet.games(context)) { if (game.folder.path !in removed) com.droiddeck.launcher.runtime.BattleNet.shortcut(context, game)?.let(out::add) } @@ -398,11 +415,11 @@ object AddedGames { private val INSTALL_DIR = Regex("\"installdir\"\\s*\"([^\"]*)\"", RegexOption.IGNORE_CASE) - private fun scanGame(context: Context, folder: File, out: MutableList<Game>, single: AddedExes.Entry? = null) { + private fun scanGame(context: Context, folder: File, out: MutableList<Game>, single: AddedExes.Entry? = null, reuse: Boolean = false) { run { val sidecar = StoreGameSidecar.read(folder) sidecar?.takeIf { it.id.isNotEmpty() }?.let { SessionPrefs.followStoreGame(context, "${it.store.id}:${it.id}", folder.path) { old -> !File(old).exists() } } - val ranking = rank(folder) + val ranking = rank(folder, reuse) val candidates = ranking.exes val picked = SessionPrefs.addedGameExe(context, folder.path) val chosen = picked.takeIf { it.isNotEmpty() }?.let { File(it) }?.takeIf { it.isFile } diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGamesCache.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGamesCache.kt new file mode 100644 index 0000000000..0f5b08b117 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGamesCache.kt @@ -0,0 +1,85 @@ +package com.droiddeck.launcher.frontend + +import android.util.AtomicFile +import org.json.JSONArray +import org.json.JSONObject +import java.io.File +import java.util.concurrent.ConcurrentHashMap + +internal class AddedGamesCache(val file: File) { + private class Rank(val modified: Long, val at: Long, val ranking: GameExePicker.Ranking) + private class Name(val name: String, val at: Long) + + private val ranks = ConcurrentHashMap<String, Rank>() + private val names = ConcurrentHashMap<String, Name>() + @Volatile private var changed = false + + init { + val json = runCatching { JSONObject(AtomicFile(file).readFully().toString(Charsets.UTF_8)) }.getOrNull() + json?.optJSONObject("ranks")?.let { all -> + for (path in all.keys()) { + val o = all.optJSONObject(path) ?: continue + val exes = o.optJSONArray("exes") ?: continue + val scores = o.optJSONArray("scores") ?: continue + if (exes.length() == 0 || exes.length() != scores.length()) continue + ranks[path] = Rank(o.optLong("modified"), o.optLong("at"), GameExePicker.Ranking( + List(exes.length()) { File(exes.getString(it)) }, List(scores.length()) { scores.getInt(it) }, o.optBoolean("uncertain"), + )) + } + } + json?.optJSONObject("names")?.let { all -> + for (key in all.keys()) all.optJSONObject(key)?.let { names[key] = Name(it.optString("name"), it.optLong("at")) } + } + } + + fun rank(folder: File): GameExePicker.Ranking? { + val kept = ranks[folder.path] ?: return null + val age = System.currentTimeMillis() - kept.at + val top = kept.ranking.exes.first() + return kept.ranking.takeIf { kept.modified == folder.lastModified() && age in 0 until KEEP_MS && top.isFile } + } + + fun keepRank(folder: File, ranking: GameExePicker.Ranking) { + if (ranking.exes.isEmpty()) { + if (ranks.remove(folder.path) != null) changed = true + return + } + ranks[folder.path] = Rank(folder.lastModified(), System.currentTimeMillis(), ranking) + changed = true + } + + fun name(key: String): String? = names[key]?.name + + fun keepName(key: String, name: String) { + names[key] = Name(name, System.currentTimeMillis()) + changed = true + } + + @Synchronized + fun save() { + if (!changed) return + changed = false + val oldest = System.currentTimeMillis() - KEEP_MS + val keptRanks = JSONObject() + ranks.forEach { (path, r) -> + if (r.at >= oldest) keptRanks.put(path, JSONObject().put("modified", r.modified).put("at", r.at) + .put("exes", JSONArray(r.ranking.exes.map { it.path })).put("scores", JSONArray(r.ranking.scores)) + .put("uncertain", r.ranking.uncertain)) + } + val keptNames = JSONObject() + names.forEach { (key, n) -> if (n.at >= oldest) keptNames.put(key, JSONObject().put("name", n.name).put("at", n.at)) } + val atomic = AtomicFile(file) + val out = atomic.startWrite() + try { + out.write(JSONObject().put("ranks", keptRanks).put("names", keptNames).toString().toByteArray()) + atomic.finishWrite(out) + } catch (e: Exception) { + atomic.failWrite(out) + } + } + + companion object { + const val FILE = "added-games-scan.json" + const val KEEP_MS = 7L * 24 * 3600 * 1000 + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt new file mode 100644 index 0000000000..753deb24ea --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt @@ -0,0 +1,83 @@ +package com.droiddeck.launcher.frontend + +import java.io.File +import org.json.JSONArray +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33]) +class AddedGamesCacheTest { + private val app get() = RuntimeEnvironment.getApplication() + @get:Rule val tmp = TemporaryFolder() + + private fun game(name: String = "Example"): Pair<File, File> { + val folder = tmp.newFolder(name) + val exe = File(folder, "bin/$name.exe").apply { parentFile!!.mkdirs(); writeText("game") } + return folder to exe + } + + private fun store() = File(tmp.root, "scan.json") + + @Test fun aRankingIsReusedAfterARestartWhileItsFolderIsUnchanged() { + val (folder, exe) = game() + AddedGamesCache(store()).apply { keepRank(folder, GameExePicker.Ranking(listOf(exe), listOf(72), uncertain = true)); save() } + val kept = AddedGamesCache(store()).rank(folder) + assertEquals(listOf(exe), kept?.exes) + assertEquals(listOf(72), kept?.scores) + assertEquals(true, kept?.uncertain) + } + + @Test fun aChangedFolderOrAMissingExecutableIsWalkedAgain() { + val (folder, exe) = game() + AddedGamesCache(store()).apply { keepRank(folder, GameExePicker.Ranking(listOf(exe), listOf(72), false)); save() } + val modified = folder.lastModified() + folder.setLastModified(modified + 60_000) + assertNull(AddedGamesCache(store()).rank(folder)) + folder.setLastModified(modified) + assertNotNull(AddedGamesCache(store()).rank(folder)) + exe.delete() + assertNull(AddedGamesCache(store()).rank(folder)) + } + + @Test fun aRankingOlderThanAWeekIsWalkedAgain() { + val (folder, exe) = game() + val walked = System.currentTimeMillis() - AddedGamesCache.KEEP_MS - 1 + store().writeText(JSONObject().put("ranks", JSONObject().put(folder.path, JSONObject() + .put("modified", folder.lastModified()).put("at", walked) + .put("exes", JSONArray(listOf(exe.path))).put("scores", JSONArray(listOf(72))))).toString()) + assertNull(AddedGamesCache(store()).rank(folder)) + } + + @Test fun aFolderWithNoExecutableIsNotKept() { + val folder = tmp.newFolder("Empty") + AddedGamesCache(store()).apply { keepRank(folder, GameExePicker.Ranking(emptyList(), emptyList(), false)); save() } + assertFalse(store().exists()) + assertNull(AddedGamesCache(store()).rank(folder)) + } + + @Test fun anIdentifiedNameIsReusedAfterARestart() { + AddedGamesCache(store()).apply { keepName("named", "God of War"); keepName("unnamed", ""); save() } + val kept = AddedGamesCache(store()) + assertEquals("God of War", kept.name("named")) + assertEquals("", kept.name("unnamed")) + assertNull(kept.name("unknown")) + } + + @Test fun aScanKeepsEachGamesRankingForTheNextLaunch() { + val (folder, exe) = game("Card Game") + AddedExes.put(app, AddedExes.Entry(folder.path, exe.path, picked = false)) + AddedGames.scan(app) + assertEquals(listOf(exe.path), AddedGamesCache(File(app.filesDir, AddedGamesCache.FILE)).rank(folder)?.exes?.map { it.path }) + } +} From df60fdb194b0b24effbec68f27af9704c139909c Mon Sep 17 00:00:00 2001 From: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> Date: Wed, 4 Nov 2026 10:34:32 +0900 Subject: [PATCH 49/85] Added games cache: skip bad records, expire names on read, retry failed saves A record whose fields could not be decoded threw while the cache loaded, and since every scan loads it first, one bad record blocked every scan; each record is now decoded on its own and skipped if it is malformed. name() returned names older than a week that were still in memory; it now applies the same age limit as rank(). save() cleared its dirty flag before writing and called startWrite outside its try, so a write that failed was never retried and could replace the scan's result with an exception; a failed write now leaves the cache dirty and is tried again on the next save. --- .../launcher/frontend/AddedGamesCache.kt | 22 ++++++----- .../launcher/frontend/AddedGamesCacheTest.kt | 37 +++++++++++++++++++ 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGamesCache.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGamesCache.kt index 0f5b08b117..c27764dfbd 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGamesCache.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGamesCache.kt @@ -17,18 +17,18 @@ internal class AddedGamesCache(val file: File) { init { val json = runCatching { JSONObject(AtomicFile(file).readFully().toString(Charsets.UTF_8)) }.getOrNull() json?.optJSONObject("ranks")?.let { all -> - for (path in all.keys()) { - val o = all.optJSONObject(path) ?: continue - val exes = o.optJSONArray("exes") ?: continue - val scores = o.optJSONArray("scores") ?: continue - if (exes.length() == 0 || exes.length() != scores.length()) continue - ranks[path] = Rank(o.optLong("modified"), o.optLong("at"), GameExePicker.Ranking( + for (path in all.keys()) runCatching { + val o = all.getJSONObject(path) + val exes = o.getJSONArray("exes") + val scores = o.getJSONArray("scores") + require(exes.length() > 0 && exes.length() == scores.length()) + ranks[path] = Rank(o.getLong("modified"), o.getLong("at"), GameExePicker.Ranking( List(exes.length()) { File(exes.getString(it)) }, List(scores.length()) { scores.getInt(it) }, o.optBoolean("uncertain"), )) } } json?.optJSONObject("names")?.let { all -> - for (key in all.keys()) all.optJSONObject(key)?.let { names[key] = Name(it.optString("name"), it.optLong("at")) } + for (key in all.keys()) runCatching { all.getJSONObject(key).let { names[key] = Name(it.getString("name"), it.getLong("at")) } } } } @@ -48,7 +48,7 @@ internal class AddedGamesCache(val file: File) { changed = true } - fun name(key: String): String? = names[key]?.name + fun name(key: String): String? = names[key]?.takeIf { System.currentTimeMillis() - it.at in 0 until KEEP_MS }?.name fun keepName(key: String, name: String) { names[key] = Name(name, System.currentTimeMillis()) @@ -69,12 +69,14 @@ internal class AddedGamesCache(val file: File) { val keptNames = JSONObject() names.forEach { (key, n) -> if (n.at >= oldest) keptNames.put(key, JSONObject().put("name", n.name).put("at", n.at)) } val atomic = AtomicFile(file) - val out = atomic.startWrite() + var out: java.io.FileOutputStream? = null try { + out = atomic.startWrite() out.write(JSONObject().put("ranks", keptRanks).put("names", keptNames).toString().toByteArray()) atomic.finishWrite(out) } catch (e: Exception) { - atomic.failWrite(out) + out?.let(atomic::failWrite) + changed = true } } diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt index 753deb24ea..804223911e 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt @@ -74,6 +74,43 @@ class AddedGamesCacheTest { assertNull(kept.name("unknown")) } + @Test fun aMalformedRecordIsSkippedAndTheOthersStillLoad() { + val (folder, exe) = game() + val (other, _) = game("Other") + val now = System.currentTimeMillis() + val good = JSONObject().put("modified", folder.lastModified()).put("at", now) + .put("exes", JSONArray(listOf(exe.path))).put("scores", JSONArray(listOf(72))) + val bad = JSONObject().put("modified", other.lastModified()).put("at", now) + .put("exes", JSONArray(listOf("bin/Other.exe"))).put("scores", JSONArray(listOf("bad"))) + store().writeText(JSONObject() + .put("ranks", JSONObject().put(folder.path, good).put(other.path, bad)) + .put("names", JSONObject().put("broken", "not a record").put("named", JSONObject().put("name", "Bastion").put("at", now))) + .toString()) + val kept = AddedGamesCache(store()) + assertEquals(listOf(exe), kept.rank(folder)?.exes) + assertNull(kept.rank(other)) + assertEquals("Bastion", kept.name("named")) + assertNull(kept.name("broken")) + } + + @Test fun aNameOlderThanAWeekIsIdentifiedAgain() { + store().writeText(JSONObject().put("names", JSONObject().put("named", JSONObject().put("name", "Bastion") + .put("at", System.currentTimeMillis() - AddedGamesCache.KEEP_MS - 1))).toString()) + assertNull(AddedGamesCache(store()).name("named")) + } + + @Test fun aSaveThatCannotBeWrittenIsTriedAgainNextTime() { + val blocked = File(tmp.root, "blocked").apply { writeText("a file where the cache folder should be") } + val file = File(blocked, "scan.json") + val cache = AddedGamesCache(file).apply { keepName("named", "Bastion") } + cache.save() + assertFalse(file.exists()) + blocked.delete() + blocked.mkdirs() + cache.save() + assertEquals("Bastion", AddedGamesCache(file).name("named")) + } + @Test fun aScanKeepsEachGamesRankingForTheNextLaunch() { val (folder, exe) = game("Card Game") AddedExes.put(app, AddedExes.Entry(folder.path, exe.path, picked = false)) From cb3c3cb2c96055fc9deb595a57a424ea6f79312e Mon Sep 17 00:00:00 2001 From: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> Date: Wed, 4 Nov 2026 10:50:23 +0900 Subject: [PATCH 50/85] Added games: a reused ranking is not remembered as a fresh walk A ranking a scan took from added-games-scan.json was also put in the 60-second in-memory cache with the current time, so for the next minute single(), addFolder() and the exe picker, which ask for a fresh walk, got a ranking that could be a week old. Kept rankings are now returned without entering that cache, so it only ever holds rankings from real walks. --- .../droiddeck/launcher/frontend/AddedGames.kt | 2 +- .../launcher/frontend/AddedGamesCacheTest.kt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt index 3fbf9c215e..7057cadd39 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt @@ -103,7 +103,7 @@ object AddedGames { val key = "${folder.path}|${folder.lastModified()}" val now = System.currentTimeMillis() ranked[key]?.takeIf { now - it.first < RANK_FRESH_MS }?.let { return it.second } - if (reuse) kept?.rank(folder)?.let { ranked[key] = now to it; return it } + if (reuse) kept?.rank(folder)?.let { return it } val guessed = GameExePicker.rank(folder) { !skipExe(it.name) } val declared = declaredExes(folder) val preferred = declared.map { it.path }.toSet() diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt index 804223911e..7ef43d7b3c 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesCacheTest.kt @@ -111,6 +111,23 @@ class AddedGamesCacheTest { assertEquals("Bastion", AddedGamesCache(file).name("named")) } + @Test fun aRankingAScanReusedIsNotHandedToAFreshLookup() { + val folder = tmp.newFolder("Game") + val walked = File(folder, "Game.exe").apply { writeText("game") } + val kept = File(folder, "Other.exe").apply { writeText("other") } + val files = tmp.newFolder("files") + val context = object : android.content.ContextWrapper(app) { + override fun getFilesDir() = files + } + AddedGamesCache(File(files, AddedGamesCache.FILE)).apply { + keepRank(folder, GameExePicker.Ranking(listOf(kept), listOf(10), false)) + save() + } + AddedGames.scan(context) + assertEquals(listOf(kept), AddedGames.rank(folder, reuse = true).exes) + assertEquals(walked, AddedGames.candidates(folder).first()) + } + @Test fun aScanKeepsEachGamesRankingForTheNextLaunch() { val (folder, exe) = game("Card Game") AddedExes.put(app, AddedExes.Entry(folder.path, exe.path, picked = false)) From baf7d90df99fdd8ba1c0d6530016339d9ba2ca22 Mon Sep 17 00:00:00 2001 From: K <steobase@gmail.com> Date: Fri, 30 Oct 2026 08:09:43 +0700 Subject: [PATCH 51/85] build: drop the unused androidTest variant so the VS Code Kotlin import works The project has no instrumented tests. The Kotlin extension's Gradle import reads the debugAndroidTest outputs without running their tasks and fails. --- app/build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 736d728ba2..65353df279 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -249,6 +249,12 @@ android { } } +// No instrumented tests; the unused androidTest variant breaks the VS Code Kotlin import. +androidComponents { + beforeVariants(selector().all()) { it.androidTest.enable = false } +} + +// Vendor binaries remain in the user's SDK directory; never vendor them into Git. if (vitureSdkDir) { android.sourceSets.main.jniLibs.srcDir(new File(vitureSdkDir, 'android')) def stageVitureNotices = tasks.register('stageVitureNotices', Copy) { From 5805631be54ce2e12c803839919797e3bf01bc2a Mon Sep 17 00:00:00 2001 From: angelrenefm <17342133+angelrenefm@users.noreply.github.com> Date: Tue, 3 Nov 2026 20:43:05 +0100 Subject: [PATCH 52/85] Session logs: record clocks, thermal status and battery temperature in every session ClockLogComponent was only created inside startVkBridge(), so it never ran on Adreno. Create it for every session (clocks.log, was vkbridge-clocks.log) and append the battery temperature from ACTION_BATTERY_CHANGED to each sample. Part 1 of #1837. --- .../launcher/gpu/ClockLogComponent.kt | 8 +++++ .../launcher/session/SessionService.kt | 8 ++--- .../launcher/gpu/ClockLogComponentTest.kt | 33 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/gpu/ClockLogComponentTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/ClockLogComponent.kt b/app/src/main/java/com/droiddeck/launcher/gpu/ClockLogComponent.kt index 8385deaafa..d268823464 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/ClockLogComponent.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/ClockLogComponent.kt @@ -1,6 +1,9 @@ package com.droiddeck.launcher.gpu import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.os.BatteryManager import android.os.Build import android.os.PowerManager import android.util.Log @@ -65,6 +68,7 @@ class ClockLogComponent(private val logFile: File) : SessionPart() { if (!h.isNaN()) line.append(String.format(Locale.US, " headroom %.2f", h)) } } + batteryTenths()?.let { line.append(String.format(Locale.US, " | battery %.1f C", it / 10.0)) } w.write(line.append('\n').toString()) w.flush() try { Thread.sleep(PERIOD_MS) } catch (e: InterruptedException) { break } @@ -75,6 +79,10 @@ class ClockLogComponent(private val logFile: File) : SessionPart() { } } + private fun batteryTenths(): Int? = + app().registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED)) + ?.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, Int.MIN_VALUE)?.takeIf { it != Int.MIN_VALUE } + companion object { private const val TAG = "SessionService" private const val PERIOD_MS = 2000L 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 29234f1d38..1a6e00bcf0 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -524,6 +524,10 @@ class SessionService : Service() { guest.add("BL_VENC_SOCKET=" + encoder.socket.absolutePath) } startVkBridge(guest, sessionDir) + com.droiddeck.launcher.gpu.ClockLogComponent(File(sessionDir, "clocks.log")).let { + it.attach(this) + components.add(it) + } guest.add("BL_WIDTH=" + size.first) guest.add("BL_HEIGHT=" + size.second) @@ -883,10 +887,6 @@ class SessionService : Service() { 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) diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/ClockLogComponentTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/ClockLogComponentTest.kt new file mode 100644 index 0000000000..33db9e10f4 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/gpu/ClockLogComponentTest.kt @@ -0,0 +1,33 @@ +package com.droiddeck.launcher.gpu + +import android.content.Intent +import android.os.BatteryManager +import org.junit.After +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], manifest = Config.NONE) +class ClockLogComponentTest { + @get:Rule val tmp = TemporaryFolder() + private var clocks: ClockLogComponent? = null + + @After fun stop() { clocks?.stop() } + + @Test fun everySampleCarriesTheBatteryTemperature() { + val context = RuntimeEnvironment.getApplication() + context.sendStickyBroadcast(Intent(Intent.ACTION_BATTERY_CHANGED).putExtra(BatteryManager.EXTRA_TEMPERATURE, 412)) + val log = tmp.newFile("clocks.log") + clocks = ClockLogComponent(log).also { it.attach(context); it.start() } + val deadline = System.currentTimeMillis() + 5_000 + while (!log.readText().contains("| battery") && System.currentTimeMillis() < deadline) Thread.sleep(20) + val sample = log.readLines().last() + assertTrue(sample, sample.endsWith("| battery 41.2 C")) + } +} From ee0d8d99975aa28294af4448f7cc10382199e66d Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:27:27 -0500 Subject: [PATCH 53/85] fix: guard session clock logger lifecycle --- .../droiddeck/launcher/gpu/ClockLogComponent.kt | 14 +++++++++++--- .../launcher/gpu/ClockLogComponentTest.kt | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/ClockLogComponent.kt b/app/src/main/java/com/droiddeck/launcher/gpu/ClockLogComponent.kt index d268823464..6f6827ad0a 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/ClockLogComponent.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/ClockLogComponent.kt @@ -16,14 +16,17 @@ import java.util.Locale class ClockLogComponent(private val logFile: File) : SessionPart() { @Volatile private var running = false + private var stopped = false private var thread: Thread? = null - override fun start() { + @Synchronized override fun start() { + if (stopped || running) return running = true thread = Thread({ run() }, "clock-log").apply { isDaemon = true; start() } } - override fun stop() { + @Synchronized override fun stop() { + stopped = true running = false thread?.interrupt() thread = null @@ -93,8 +96,13 @@ class ClockLogComponent(private val logFile: File) : SessionPart() { "/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", + "/sys/class/misc/mali0/device/clock", "/sys/class/kgsl/kgsl-3d0/clock_mhz", + "/sys/class/kgsl/kgsl-3d0/gpu_clock", "/sys/class/kgsl/kgsl-3d0/gpuclk", + "/sys/class/kgsl/kgsl-3d0/devfreq/cur_freq", "/sys/kernel/gpu/gpu_clock", + "/sys/devices/platform/soc@0/3d00000.gpu/devfreq/3d00000.gpu/cur_freq", ) + listOf("kgsl-3d0", "3d00000.qcom,kgsl-3d0", "2c00000.qcom,kgsl-3d0", "5000000.qcom,kgsl-3d0", "5900000.qcom,kgsl-3d0") + .forEach { list.add("/sys/class/devfreq/$it/cur_freq") } 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") } diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/ClockLogComponentTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/ClockLogComponentTest.kt index 33db9e10f4..1dc1d6b6af 100644 --- a/app/src/test/java/com/droiddeck/launcher/gpu/ClockLogComponentTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/gpu/ClockLogComponentTest.kt @@ -27,7 +27,17 @@ class ClockLogComponentTest { clocks = ClockLogComponent(log).also { it.attach(context); it.start() } val deadline = System.currentTimeMillis() + 5_000 while (!log.readText().contains("| battery") && System.currentTimeMillis() < deadline) Thread.sleep(20) - val sample = log.readLines().last() - assertTrue(sample, sample.endsWith("| battery 41.2 C")) + assertTrue(log.readText(), log.readText().contains("| battery 41.2 C")) + context.sendStickyBroadcast(Intent(Intent.ACTION_BATTERY_CHANGED).putExtra(BatteryManager.EXTRA_TEMPERATURE, 423)) + val updatedDeadline = System.currentTimeMillis() + 5_000 + while (!log.readText().contains("| battery 42.3 C") && System.currentTimeMillis() < updatedDeadline) Thread.sleep(20) + assertTrue(log.readText(), log.readText().contains("| battery 42.3 C")) + } + + @Test fun stoppedComponentCannotStartFromAnEarlierSnapshot() { + val context = RuntimeEnvironment.getApplication() + val log = tmp.newFile("stopped-clocks.log") + clocks = ClockLogComponent(log).also { it.attach(context); it.stop(); it.start() } + assertTrue(log.readText(), log.length() == 0L) } } From 28d4f58f33da0a7a390e7c6d2cde22e6717c67cc Mon Sep 17 00:00:00 2001 From: phj1081 <5908832+phj1081@users.noreply.github.com> Date: Fri, 6 Nov 2026 02:05:26 +0900 Subject: [PATCH 54/85] fix(steam): default listed titles with a bundled arm64 Linux build to FEX Steamworks has no arm64 launch-option architecture, so a title that ships x64 and arm64 Linux builds side by side still reads as osarch 64 and gets the Proton ARM64 default. List such titles in FEX_DEFAULT_APPS so they default to Linux x86 (FEX), whose launch runs the bundled arm64 build. A player's own pick is kept, and unlisted titles are unchanged. Refs #1774 --- .../overlay/usr/local/bin/steam-compatibility | 5 +++- tools/tests/test_game_environment.py | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility index acacb0e17d..f3181b608e 100755 --- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility +++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility @@ -24,6 +24,9 @@ SNIPER_APPID = "1628350" SLR4_APPID = "4183110" FEX_DEPENDENCIES = (FEX_APPID, SNIPER_APPID, SLR4_APPID) REQUIRED_TOOLS = (PROTON_ARM64_APPID,) + FEX_DEPENDENCIES +# Linux builds that bundle an arm64 binary their launcher starts; Steamworks offers no arm64 +# launch-option architecture, so appinfo cannot say so (#1774). +FEX_DEFAULT_APPS = frozenset({"4385780"}) FULLY_INSTALLED = 4 UPDATE_REQUIRED = 2 REQUEST_HANDOFF_SECONDS = 30 @@ -930,7 +933,7 @@ def native_targets(steam_root, apps): if "arm64" in osarch or "aarch64" in osarch: targets[app] = None continue - if "windows" in oslist: + if "windows" in oslist and app not in FEX_DEFAULT_APPS: targets[app] = NATIVE_CHOICE continue targets[app] = FEX_TOOL diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index 55387436b9..36178ab610 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -1658,6 +1658,30 @@ class ProtonDefaultTest(unittest.TestCase): finally: globals_["native_targets"] = original_native_targets + def test_a_listed_title_with_a_bundled_arm64_linux_build_defaults_to_fex(self): + globals_ = COMPAT["native_targets"].__globals__ + original_platforms = globals_["appinfo_platforms"] + globals_["appinfo_platforms"] = lambda _path, wanted: { + app: ({"linux", "windows"}, "64", "game") for app in ("4385780", "42") if app in wanted + } + try: + native = COMPAT["native_targets"]("/nonexistent", ["4385780", "42"]) + finally: + globals_["appinfo_platforms"] = original_platforms + self.assertEqual(native["4385780"], COMPAT["FEX_TOOL"]) + self.assertIs(native["42"], COMPAT["NATIVE_CHOICE"]) + + changes, auto = COMPAT["plan_mapping"]( + {"0": self.TOOL}, ["4385780"], self.NAMES, self.TOOL, {}, native) + self.assertEqual(changes, {"4385780": COMPAT["FEX_TOOL"]}) + self.assertEqual(auto, {"4385780": COMPAT["FEX_TOOL"]}) + + for choice in (self.TOOL, "GE-Proton11-7"): + changes, auto = COMPAT["plan_mapping"]( + {"0": self.TOOL, "4385780": choice}, ["4385780"], self.NAMES, self.TOOL, {}, native) + self.assertEqual(changes, {}) + self.assertEqual(auto, {}) + def test_factorio_preserves_an_observed_native_choice_despite_ambiguous_metadata(self): with tempfile.TemporaryDirectory() as tmp: steam = Path(tmp) / "Steam" From 7e0859872baaea2b56f5c3df1f3aab20556c015e Mon Sep 17 00:00:00 2001 From: phj1081 <5908832+phj1081@users.noreply.github.com> Date: Fri, 6 Nov 2026 04:03:20 +0900 Subject: [PATCH 55/85] fix(steam): keep a cleared FEX default for a listed title as a native choice A listed title whose automatic FEX mapping the player clears now records the empty mapping as a native choice, as titles with NATIVE_CHOICE do, instead of getting FEX again on the next run. --- .../overlay/usr/local/bin/steam-compatibility | 2 +- tools/tests/test_game_environment.py | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility index f3181b608e..e37cddfbf6 100755 --- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility +++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility @@ -1084,7 +1084,7 @@ def plan_mapping(current, installed, runnable, default, auto, native=None, picks continue mine = auto.get(app) target = native.get(app, default) - if not name and app in native_choices: + if not name and (app in native_choices or (app in current and app in FEX_DEFAULT_APPS)): target = NATIVE_CHOICE stale = unrunnable(name, runnable) if name and not stale and (mine is None or name != mine): diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index 36178ab610..c48e5ab1b2 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -1682,6 +1682,46 @@ class ProtonDefaultTest(unittest.TestCase): self.assertEqual(changes, {}) self.assertEqual(auto, {}) + def test_a_cleared_fex_default_for_a_listed_title_is_kept_as_a_native_choice(self): + app = "4385780" + fex = COMPAT["FEX_TOOL"] + with tempfile.TemporaryDirectory() as tmp: + steam = Path(tmp) / "Steam" + config = steam / "config/config.vdf" + config.parent.mkdir(parents=True) + config.write_text(config_text([("0", self.TOOL)])) + (Path(tmp) / "state.json").write_text(json.dumps({"default": self.TOOL, "auto": {}})) + + globals_ = COMPAT["native_targets"].__globals__ + original_platforms = globals_["appinfo_platforms"] + globals_["appinfo_platforms"] = lambda _path, wanted: { + app: ({"linux", "windows"}, "64", "game") + } if app in wanted else {} + try: + def run(): + COMPAT["register_default"](str(config), [app], catalog=self.CATALOG, directory=tmp) + return json.loads((Path(tmp) / "state.json").read_text()) + + state = run() + self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, app: fex}) + self.assertEqual(state["auto"], {app: fex}) + + config.write_text(config_text([("0", self.TOOL), (app, "")])) + state = run() + cleared = config.read_bytes() + self.assertEqual(mapping_of(cleared.decode()), {"0": self.TOOL, app: ""}) + self.assertEqual(state["auto"], {}) + self.assertEqual(state["native_choices"], [app]) + run() + self.assertEqual(config.read_bytes(), cleared) + + config.write_text(config_text([("0", self.TOOL), (app, fex)])) + state = run() + self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, app: fex}) + self.assertEqual(state["native_choices"], []) + finally: + globals_["appinfo_platforms"] = original_platforms + def test_factorio_preserves_an_observed_native_choice_despite_ambiguous_metadata(self): with tempfile.TemporaryDirectory() as tmp: steam = Path(tmp) / "Steam" From 718712eb0132fe0b7a1390eaa12187c672b84233 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:57:05 -0500 Subject: [PATCH 56/85] fix: secure and refresh unrooted log exports --- .../launcher/agent/AgentBridgeProvider.kt | 9 +++- .../session/EnhancedSessionLogShare.kt | 5 ++- .../session/SessionLogShareZipTest.kt | 7 +++- docs/agent-control.md | 2 + tools/droiddeckctl | 41 +++++++++++++++++-- tools/tests/test_droiddeckctl.py | 25 +++++++++-- 6 files changed, 78 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt index 5570bd9810..a7a9306808 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt @@ -25,6 +25,7 @@ import com.droiddeck.launcher.session.SessionState import org.json.JSONArray import org.json.JSONObject import java.io.File +import java.util.UUID import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit @@ -206,7 +207,13 @@ class AgentBridgeProvider : ContentProvider() { private fun logs(context: Context): JSONObject { val dir = logDir(context)?.takeIf { it.isDirectory } ?: return error("NO_SESSION_LOGS", "No session artifact directory is available") - val zip = SessionLogShare.zipFolder(context, dir, File(context.getExternalFilesDir(null), "agent-logs")) + val output = File(context.getExternalFilesDir(null), "agent-logs/${UUID.randomUUID()}") + val zip = try { + SessionLogShare.zipFolder(context, dir, output) + } catch (error: Exception) { + output.deleteRecursively() + throw error + } ?: return error("NO_SESSION_LOGS", "The session artifact directory is empty") return JSONObject().put("ok", true).put("command", "logs").put("sessionId", dir.name).put("zip", zip.absolutePath) } diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index 899faf4ca0..d20da13d62 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -27,6 +27,7 @@ import java.nio.file.SimpleFileVisitor import java.nio.file.attribute.BasicFileAttributes import java.security.MessageDigest import java.util.Locale +import java.util.UUID import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream @@ -107,7 +108,7 @@ internal object EnhancedSessionLogShare { return emptyList() } val out = SessionLogShare.shareDir(context).apply { deleteRecursively(); mkdirs() } - val stage = File(out, ".diagnostic-stage").apply { mkdirs() } + val stage = File(context.cacheDir, "${out.name}-${UUID.randomUUID()}.diagnostic-stage").apply { mkdirs() } val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = false) val candidates = discovery.candidates @@ -173,7 +174,7 @@ internal object EnhancedSessionLogShare { out.deleteRecursively() return null } - val stage = File(out, ".diagnostic-stage").apply { mkdirs() } + val stage = File(context.cacheDir, "${out.name}-${UUID.randomUUID()}.diagnostic-stage").apply { mkdirs() } val records = ArrayList<Record>() val budget = Budget(limits.maxBytesTotal) val zip = File(out, "DroidDeck-${folder.name}.zip") diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index cd4a711d15..0779a378cb 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -29,15 +29,20 @@ class SessionLogShareZipTest { @Test fun anArchiveCanBeWrittenOutsideTheShareFolder() { SessionLogShare.clear(app) val session = File(LinuxRuntime.logDir(app), "2026-11-03-01-steam").apply { mkdirs() } - val out = File(app.getExternalFilesDir(null), "agent-logs") + val out = File(app.getExternalFilesDir(null), "agent-logs/request-1") + val secondOut = File(app.getExternalFilesDir(null), "agent-logs/request-2") try { File(session, "session.log").writeText("booted\n") val zip = SessionLogShare.zipFolder(app, session, out)!! + val secondZip = SessionLogShare.zipFolder(app, session, secondOut)!! assertEquals(out, zip.parentFile) assertFalse(File(app.cacheDir, "share").exists()) assertTrue(zip.isFile) + assertTrue(secondZip.isFile) + assertTrue(zip.isFile) } finally { out.deleteRecursively() + secondOut.deleteRecursively() session.deleteRecursively() } } diff --git a/docs/agent-control.md b/docs/agent-control.md index dbbdbb9b03..eba6ca7735 100644 --- a/docs/agent-control.md +++ b/docs/agent-control.md @@ -78,6 +78,8 @@ text. This does not redact arbitrary authorized command results, CDP data, prefe captures. Scenario directories are owner-only and JSON reports are written with mode 0600. Review artifacts before sharing. `logs` downloads the archive Share logs builds (scrubbed, Steam logs over 8 MiB left out) from the app's external files folder, since adb cannot read the session folder itself. +When the installed app predates archive export, the CLI falls back to pulling the private session folder; +that legacy path is available only with root and is not scrubbed before download. ## Device selection and output diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 559a437a89..14676771f5 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -424,8 +424,20 @@ def start_session(adb: str, serial: str, request: dict) -> dict: def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: """Unpack a Share logs zip so the session's own files sit at the top of destination.""" + destination = destination.resolve() + destination.mkdir(parents=True, exist_ok=True) + manifest = destination / ".droiddeckctl-managed-logs.json" try: - with zipfile.ZipFile(archive) as z: + previous = json.loads(manifest.read_text(encoding="utf-8")) + if not isinstance(previous, list) or any(not isinstance(name, str) for name in previous): + previous = [] + except (OSError, ValueError): + previous = [] + previous = set(previous) + extracted = set() + try: + with tempfile.TemporaryDirectory(prefix="droiddeckctl-logs-") as temp, zipfile.ZipFile(archive) as z: + staged = Path(temp) for entry in z.infolist(): name = entry.filename if name.startswith(session_id + "/"): @@ -433,9 +445,29 @@ def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: target = (destination / name).resolve() if entry.is_dir() or not name or not target.is_relative_to(destination): continue - target.parent.mkdir(parents=True, exist_ok=True) - with z.open(entry) as source, target.open("wb") as copy: + relative = target.relative_to(destination).as_posix() + if relative == manifest.name: + continue + staged_file = staged / relative + staged_file.parent.mkdir(parents=True, exist_ok=True) + with z.open(entry) as source, staged_file.open("wb") as copy: shutil.copyfileobj(source, copy) + extracted.add(relative) + for name in extracted - previous: + target = destination / name + if target.exists() or target.is_symlink(): + raise ControlError(f"Refusing to overwrite an unrelated file: {target}", "LOG_PULL_FAILED") + for name in previous - extracted: + target = (destination / name).resolve() + if target.is_relative_to(destination) and target.is_file() and not target.is_symlink(): + target.unlink() + for name in extracted: + target = destination / name + target.parent.mkdir(parents=True, exist_ok=True) + os.replace(staged / name, target) + temp_manifest = manifest.with_name(manifest.name + ".tmp") + temp_manifest.write_text(json.dumps(sorted(extracted), indent=2) + "\n", encoding="utf-8") + os.replace(temp_manifest, manifest) except (OSError, zipfile.BadZipFile) as exc: raise ControlError(f"Could not unpack the session logs: {exc}", "LOG_PULL_FAILED") from exc @@ -766,6 +798,7 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict: result = run_adb(adb, serial, "pull", remote_dir, str(destination), timeout=120) else: zip_path = checked(exported, "LOG_PULL_FAILED")["zip"] + cleanup_dir = str(Path(zip_path).parent) try: if exported.get("sessionId", session["id"]) != session["id"]: raise ControlError("A new session started while the logs were exported; run logs again", @@ -777,7 +810,7 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict: unpack_logs(local_zip, destination, session["id"]) finally: # The copy sits in shared storage, so it does not outlive the pull. - run_adb(adb, serial, "shell", "rm", "-f", zip_path, timeout=30) + run_adb(adb, serial, "shell", "rm", "-rf", cleanup_dir, timeout=30) if result.returncode != 0: detail = (result.stderr or result.stdout).decode(errors="replace").strip() raise ControlError(detail or "adb pull failed", "LOG_PULL_FAILED") diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 565e918c81..0b521b5a05 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -138,7 +138,7 @@ CPUFREQ = textwrap.dedent('''\ def battery(tenths): return f"Current Battery Service state:\n level: 80\n temperature: {tenths}\n technology: Li-poly" PRIVATE_LOG_DIR = "/data/user/0/com.droiddeck.launcher/files/logs/sessions/s1" -EXPORTED_ZIP = "/storage/emulated/0/Android/data/com.droiddeck.launcher/files/agent-logs/DroidDeck-s1.zip" +EXPORTED_ZIP = "/storage/emulated/0/Android/data/com.droiddeck.launcher/files/agent-logs/request-1/DroidDeck-s1.zip" def share_zip(entries): @@ -542,7 +542,7 @@ class DroiddeckctlTest(FakeAdbTest): self.assertEqual("e", (destination / "stores" / "epic.log").read_text()) self.assertFalse((self.dir / "outside").exists()) self.assertEqual([["pull", EXPORTED_ZIP]], [c["args"][:2] for c in self.calls() if c["args"][:1] == ["pull"]]) - self.assertIn(["shell", "rm", "-f", EXPORTED_ZIP], [c["args"] for c in self.calls()]) + self.assertIn(["shell", "rm", "-rf", str(Path(EXPORTED_ZIP).parent)], [c["args"] for c in self.calls()]) def test_logs_of_a_session_that_started_meanwhile_are_refused(self): self.configure({"state": ended_state(), "logs": {"ok": True, "sessionId": "s2", "zip": EXPORTED_ZIP}}, @@ -551,7 +551,26 @@ class DroiddeckctlTest(FakeAdbTest): self.assertEqual(6, code) self.assertEqual("LOG_PULL_FAILED", out["error"]["code"]) self.assertFalse((self.dir / "artifacts").exists()) - self.assertIn(["shell", "rm", "-f", EXPORTED_ZIP], [c["args"] for c in self.calls()]) + self.assertIn(["shell", "rm", "-rf", str(Path(EXPORTED_ZIP).parent)], [c["args"] for c in self.calls()]) + + def test_logs_replace_the_previous_snapshot_and_preserve_unrelated_files(self): + destination = self.dir / "artifacts" + destination.mkdir() + (destination / "notes.txt").write_text("keep me") + first = self.dir / "first.zip" + with zipfile.ZipFile(first, "w") as archive: + archive.writestr("s1/session.log", "first") + archive.writestr("s1/steam/console.log", "old") + ctl.unpack_logs(first, destination, "s1") + self.assertEqual("old", (destination / "steam/console.log").read_text()) + + second = self.dir / "second.zip" + with zipfile.ZipFile(second, "w") as archive: + archive.writestr("s1/session.log", "second") + ctl.unpack_logs(second, destination, "s1") + self.assertEqual("second", (destination / "session.log").read_text()) + self.assertFalse((destination / "steam/console.log").exists()) + self.assertEqual("keep me", (destination / "notes.txt").read_text()) def test_logs_from_an_older_build_fall_back_to_the_private_folder(self): self.configure({"state": ended_state()}) From 4765644451ebee3ab2fd489724b73f546c9d7cf4 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:09:06 -0500 Subject: [PATCH 57/85] fix: harden log export transactions --- .../launcher/agent/AgentBridgeProvider.kt | 3 +- tools/droiddeckctl | 107 ++++++++++++++---- tools/tests/test_droiddeckctl.py | 95 +++++++++++++++- 3 files changed, 176 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt index a7a9306808..7d16029634 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt @@ -215,7 +215,8 @@ class AgentBridgeProvider : ContentProvider() { throw error } ?: return error("NO_SESSION_LOGS", "The session artifact directory is empty") - return JSONObject().put("ok", true).put("command", "logs").put("sessionId", dir.name).put("zip", zip.absolutePath) + return JSONObject().put("ok", true).put("command", "logs").put("sessionId", dir.name) + .put("zip", zip.absolutePath).put("cleanupDir", output.absolutePath) } private fun state(context: Context): JSONObject { diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 14676771f5..270cb7b807 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -18,7 +18,7 @@ import time import uuid import zipfile import zlib -from pathlib import Path +from pathlib import Path, PurePosixPath sys.path.insert(0, str(Path(__file__).resolve().parent)) from adb_device import DeviceResolutionError, resolve_serial @@ -434,40 +434,84 @@ def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: except (OSError, ValueError): previous = [] previous = set(previous) + previous.discard(manifest.name) extracted = set() + + def managed_target(name: str) -> Path | None: + relative = Path(name) + if relative.is_absolute() or not relative.parts or any(part in {".", ".."} for part in relative.parts): + return None + target = destination + for part in relative.parts: + target = target / part + if target.is_symlink(): + return None + return target if target.resolve().is_relative_to(destination) else None + try: - with tempfile.TemporaryDirectory(prefix="droiddeckctl-logs-") as temp, zipfile.ZipFile(archive) as z: + with tempfile.TemporaryDirectory(prefix=".droiddeckctl-logs-", dir=destination) as temp, zipfile.ZipFile(archive) as z: staged = Path(temp) + staged_files = staged / "new" + backups = staged / "old" + staged_files.mkdir() for entry in z.infolist(): name = entry.filename if name.startswith(session_id + "/"): name = name[len(session_id) + 1:] - target = (destination / name).resolve() - if entry.is_dir() or not name or not target.is_relative_to(destination): + target = managed_target(name) + if entry.is_dir() or target is None or target == manifest: continue relative = target.relative_to(destination).as_posix() - if relative == manifest.name: - continue - staged_file = staged / relative + staged_file = staged_files / relative staged_file.parent.mkdir(parents=True, exist_ok=True) with z.open(entry) as source, staged_file.open("wb") as copy: shutil.copyfileobj(source, copy) extracted.add(relative) for name in extracted - previous: - target = destination / name - if target.exists() or target.is_symlink(): + target = managed_target(name) + if target is None or target.exists(): raise ControlError(f"Refusing to overwrite an unrelated file: {target}", "LOG_PULL_FAILED") - for name in previous - extracted: - target = (destination / name).resolve() - if target.is_relative_to(destination) and target.is_file() and not target.is_symlink(): - target.unlink() - for name in extracted: - target = destination / name - target.parent.mkdir(parents=True, exist_ok=True) - os.replace(staged / name, target) - temp_manifest = manifest.with_name(manifest.name + ".tmp") - temp_manifest.write_text(json.dumps(sorted(extracted), indent=2) + "\n", encoding="utf-8") - os.replace(temp_manifest, manifest) + if manifest.is_symlink() or (manifest.exists() and not manifest.is_file()): + raise ControlError("The managed log list is not a regular file", "LOG_PULL_FAILED") + backed_up = {} + installed = set() + manifest_backup = backups / manifest.name + try: + for name in sorted(previous): + target = managed_target(name) + if target is not None and target.is_file(): + backup = backups / name + backup.parent.mkdir(parents=True, exist_ok=True) + os.replace(target, backup) + backed_up[name] = backup + if manifest.is_file(): + manifest_backup.parent.mkdir(parents=True, exist_ok=True) + os.replace(manifest, manifest_backup) + for name in sorted(extracted): + target = managed_target(name) + if target is None: + raise ControlError(f"A log destination became unsafe: {name}", "LOG_PULL_FAILED") + target.parent.mkdir(parents=True, exist_ok=True) + os.replace(staged_files / name, target) + installed.add(name) + temp_manifest = staged / "managed-logs.json" + temp_manifest.write_text(json.dumps(sorted(extracted), indent=2) + "\n", encoding="utf-8") + os.replace(temp_manifest, manifest) + except Exception: + for name in installed: + target = managed_target(name) + if target is not None and target.is_file(): + target.unlink() + if manifest.exists() and not manifest.is_symlink(): + manifest.unlink() + for name, backup in backed_up.items(): + target = managed_target(name) + if target is not None: + target.parent.mkdir(parents=True, exist_ok=True) + os.replace(backup, target) + if manifest_backup.is_file(): + os.replace(manifest_backup, manifest) + raise except (OSError, zipfile.BadZipFile) as exc: raise ControlError(f"Could not unpack the session logs: {exc}", "LOG_PULL_FAILED") from exc @@ -798,7 +842,17 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict: result = run_adb(adb, serial, "pull", remote_dir, str(destination), timeout=120) else: zip_path = checked(exported, "LOG_PULL_FAILED")["zip"] - cleanup_dir = str(Path(zip_path).parent) + remote_zip = PurePosixPath(zip_path) + if (not remote_zip.is_absolute() or ".." in remote_zip.parts or + not re.fullmatch(r"/[A-Za-z0-9_./-]+", zip_path)): + raise ControlError("The exported logs path is invalid", "LOG_PULL_FAILED") + requested_dir = exported.get("cleanupDir") + request_dir = PurePosixPath(requested_dir) if isinstance(requested_dir, str) else None + cleanup = ["shell", "rm", "-f", zip_path] + if (request_dir and request_dir.is_absolute() and ".." not in request_dir.parts and + request_dir == remote_zip.parent and request_dir.parent.name == "agent-logs" and + re.fullmatch(r"[0-9a-fA-F-]{36}", request_dir.name)): + cleanup = ["shell", "rm", "-rf", str(request_dir)] try: if exported.get("sessionId", session["id"]) != session["id"]: raise ControlError("A new session started while the logs were exported; run logs again", @@ -810,7 +864,14 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict: unpack_logs(local_zip, destination, session["id"]) finally: # The copy sits in shared storage, so it does not outlive the pull. - run_adb(adb, serial, "shell", "rm", "-rf", cleanup_dir, timeout=30) + cleaned = run_adb(adb, serial, *cleanup, timeout=30) + if cleaned.returncode != 0: + detail = (cleaned.stderr or cleaned.stdout).decode(errors="replace").strip() + raise ControlError( + "Could not remove the exported log archive; it may remain in shared storage" + + (f": {detail}" if detail else ""), + "LOG_CLEANUP_FAILED", + ) if result.returncode != 0: detail = (result.stderr or result.stdout).decode(errors="replace").strip() raise ControlError(detail or "adb pull failed", "LOG_PULL_FAILED") @@ -1044,7 +1105,7 @@ EXIT_SESSION = { "NO_STEAM_SESSION", "SESSION_NOT_READY", "AGENT_UNAVAILABLE", "LAUNCH_REJECTED", "NO_PAD", "NO_FRAMES", } EXIT_TIMEOUT = {"TIMEOUT", "ARTIFACT_TIMEOUT"} -EXIT_FILE = {"NO_SESSION_LOGS", "LOG_PULL_FAILED", "SCREENSHOT_FAILED", "FILE_IO", "RECORD_FAILED", "PUSH_FAILED", +EXIT_FILE = {"NO_SESSION_LOGS", "LOG_PULL_FAILED", "LOG_CLEANUP_FAILED", "SCREENSHOT_FAILED", "FILE_IO", "RECORD_FAILED", "PUSH_FAILED", "PACING_FAILED", "XR_CAPTURE_FAILED"} EXIT_DENIED = {"AGENT_COMMANDS_DISABLED", "PROTECTED_PREFS", "PROTECTED_CONTROL"} diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 0b521b5a05..4197f721b8 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -76,6 +76,9 @@ FAKE_ADB = textwrap.dedent('''\ elif args[:1] == ["pull"]: entry["denied"] = True print(f"adb: error: failed to stat remote object '{args[1]}': Permission denied", file=sys.stderr) + elif args[:2] == ["shell", "rm"] and config.get("fail_cleanup"): + entry["denied"] = True + print("adb: error: cleanup denied", file=sys.stderr) with open(config["log"], "a") as log: log.write(json.dumps(entry) + "\\n") sys.exit(1 if entry.get("denied") else 0) @@ -138,7 +141,9 @@ CPUFREQ = textwrap.dedent('''\ def battery(tenths): return f"Current Battery Service state:\n level: 80\n temperature: {tenths}\n technology: Li-poly" PRIVATE_LOG_DIR = "/data/user/0/com.droiddeck.launcher/files/logs/sessions/s1" -EXPORTED_ZIP = "/storage/emulated/0/Android/data/com.droiddeck.launcher/files/agent-logs/request-1/DroidDeck-s1.zip" +AGENT_LOGS_DIR = "/storage/emulated/0/Android/data/com.droiddeck.launcher/files/agent-logs" +EXPORTED_DIR = AGENT_LOGS_DIR + "/123e4567-e89b-12d3-a456-426614174000" +EXPORTED_ZIP = EXPORTED_DIR + "/DroidDeck-s1.zip" def share_zip(entries): @@ -531,7 +536,8 @@ class DroiddeckctlTest(FakeAdbTest): code, out = self.run_ctl("wait", "cool", "--below", "38") self.assertEqual("THERMAL_FAILED", out["error"]["code"]) def test_logs_pull_the_exported_zip_instead_of_the_private_folder(self): - self.configure({"state": ended_state(), "logs": {"ok": True, "sessionId": "s1", "zip": EXPORTED_ZIP}}, + self.configure({"state": ended_state(), "logs": {"ok": True, "sessionId": "s1", "zip": EXPORTED_ZIP, + "cleanupDir": EXPORTED_DIR}}, files={EXPORTED_ZIP: share_zip({"s1/session.log": "booted", "s1/steam/console.log": "c", "stores/epic.log": "e", "../outside": "x"})}) destination = self.dir / "artifacts" @@ -542,16 +548,38 @@ class DroiddeckctlTest(FakeAdbTest): self.assertEqual("e", (destination / "stores" / "epic.log").read_text()) self.assertFalse((self.dir / "outside").exists()) self.assertEqual([["pull", EXPORTED_ZIP]], [c["args"][:2] for c in self.calls() if c["args"][:1] == ["pull"]]) - self.assertIn(["shell", "rm", "-rf", str(Path(EXPORTED_ZIP).parent)], [c["args"] for c in self.calls()]) + self.assertIn(["shell", "rm", "-rf", EXPORTED_DIR], [c["args"] for c in self.calls()]) def test_logs_of_a_session_that_started_meanwhile_are_refused(self): - self.configure({"state": ended_state(), "logs": {"ok": True, "sessionId": "s2", "zip": EXPORTED_ZIP}}, + self.configure({"state": ended_state(), "logs": {"ok": True, "sessionId": "s2", "zip": EXPORTED_ZIP, + "cleanupDir": EXPORTED_DIR}}, files={EXPORTED_ZIP: share_zip({"s2/session.log": "other"})}) code, out = self.run_ctl("logs", "latest", str(self.dir / "artifacts")) self.assertEqual(6, code) self.assertEqual("LOG_PULL_FAILED", out["error"]["code"]) self.assertFalse((self.dir / "artifacts").exists()) - self.assertIn(["shell", "rm", "-rf", str(Path(EXPORTED_ZIP).parent)], [c["args"] for c in self.calls()]) + self.assertIn(["shell", "rm", "-rf", EXPORTED_DIR], [c["args"] for c in self.calls()]) + + def test_logs_from_a_legacy_provider_remove_only_the_export_zip(self): + legacy_zip = AGENT_LOGS_DIR + "/DroidDeck-s1.zip" + self.configure({"state": ended_state(), + "logs": {"ok": True, "sessionId": "s1", "zip": legacy_zip}}, + files={legacy_zip: share_zip({"s1/session.log": "booted"})}) + code, out = self.run_ctl("logs", "latest", str(self.dir / "artifacts")) + self.assertEqual(0, code, out) + commands = [c["args"] for c in self.calls()] + self.assertIn(["shell", "rm", "-f", legacy_zip], commands) + self.assertNotIn(["shell", "rm", "-rf", AGENT_LOGS_DIR], commands) + + def test_logs_report_when_remote_export_cleanup_fails(self): + self.configure({"state": ended_state(), + "logs": {"ok": True, "sessionId": "s1", "zip": EXPORTED_ZIP, + "cleanupDir": EXPORTED_DIR}}, + fail_cleanup=True, files={EXPORTED_ZIP: share_zip({"s1/session.log": "booted"})}) + code, out = self.run_ctl("logs", "latest", str(self.dir / "artifacts")) + self.assertEqual(6, code, out) + self.assertEqual("LOG_CLEANUP_FAILED", out["error"]["code"]) + self.assertIn("may remain in shared storage", out["error"]["message"]) def test_logs_replace_the_previous_snapshot_and_preserve_unrelated_files(self): destination = self.dir / "artifacts" @@ -572,6 +600,63 @@ class DroiddeckctlTest(FakeAdbTest): self.assertFalse((destination / "steam/console.log").exists()) self.assertEqual("keep me", (destination / "notes.txt").read_text()) + def test_logs_do_not_follow_a_stale_managed_symlink(self): + if os.name == "nt": + self.skipTest("symlink creation is unavailable on this Windows host") + destination = self.dir / "artifacts" + destination.mkdir() + victim = destination / "notes.txt" + victim.write_text("keep me") + (destination / ".droiddeckctl-managed-logs.json").write_text(json.dumps(["old.log"])) + (destination / "old.log").symlink_to(victim) + archive = self.dir / "logs.zip" + with zipfile.ZipFile(archive, "w") as z: + z.writestr("s1/session.log", "current") + + ctl.unpack_logs(archive, destination, "s1") + + self.assertEqual("keep me", victim.read_text()) + self.assertTrue((destination / "old.log").is_symlink()) + self.assertEqual("current", (destination / "session.log").read_text()) + + def test_logs_roll_back_a_failed_manifest_commit_and_can_retry(self): + destination = self.dir / "artifacts" + destination.mkdir() + (destination / "notes.txt").write_text("keep me") + first = self.dir / "first.zip" + with zipfile.ZipFile(first, "w") as z: + z.writestr("s1/session.log", "first") + z.writestr("s1/steam/console.log", "old") + ctl.unpack_logs(first, destination, "s1") + old_manifest = (destination / ".droiddeckctl-managed-logs.json").read_bytes() + second = self.dir / "second.zip" + with zipfile.ZipFile(second, "w") as z: + z.writestr("s1/session.log", "second") + z.writestr("s1/new.log", "new") + + real_replace = ctl.os.replace + failed = False + def fail_manifest_once(source, target): + nonlocal failed + if Path(target) == destination / ".droiddeckctl-managed-logs.json" and not failed: + failed = True + raise OSError("injected manifest failure") + return real_replace(source, target) + + with unittest.mock.patch.object(ctl.os, "replace", side_effect=fail_manifest_once): + with self.assertRaises(ctl.ControlError): + ctl.unpack_logs(second, destination, "s1") + + self.assertEqual("first", (destination / "session.log").read_text()) + self.assertEqual("old", (destination / "steam/console.log").read_text()) + self.assertFalse((destination / "new.log").exists()) + self.assertEqual(old_manifest, (destination / ".droiddeckctl-managed-logs.json").read_bytes()) + ctl.unpack_logs(second, destination, "s1") + self.assertEqual("second", (destination / "session.log").read_text()) + self.assertEqual("new", (destination / "new.log").read_text()) + self.assertFalse((destination / "steam/console.log").exists()) + self.assertEqual("keep me", (destination / "notes.txt").read_text()) + def test_logs_from_an_older_build_fall_back_to_the_private_folder(self): self.configure({"state": ended_state()}) code, out = self.run_ctl("logs", "latest", str(self.dir / "artifacts")) From ff686d7c3bd38a3b73891f7a93e7f3ba586328e5 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:16:48 -0500 Subject: [PATCH 58/85] fix: expire stale log exports safely --- .../launcher/agent/AgentBridgeProvider.kt | 22 ++++++++++++++++++- tools/droiddeckctl | 13 +++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt index 7d16029634..f41b342507 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt @@ -25,6 +25,7 @@ import com.droiddeck.launcher.session.SessionState import org.json.JSONArray import org.json.JSONObject import java.io.File +import java.nio.file.Files import java.util.UUID import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit @@ -203,11 +204,29 @@ class AgentBridgeProvider : ContentProvider() { private fun logDir(context: Context): File? = SessionState.logDirectory ?: SessionState.logFile?.parentFile ?: SessionPaths.sessionFolders(context).lastOrNull() + private fun cleanupExpiredLogExports(exports: File) { + val now = System.currentTimeMillis() + val canonicalRoot = exports.canonicalFile + exports.listFiles()?.forEach { candidate -> + val isUuid = runCatching { UUID.fromString(candidate.name).toString() == candidate.name }.getOrDefault(false) + if (!isUuid || !candidate.isDirectory || Files.isSymbolicLink(candidate.toPath())) return@forEach + if (candidate.canonicalFile.parentFile != canonicalRoot) return@forEach + if (now - candidate.lastModified() >= LOG_EXPORT_RETENTION_MS) candidate.deleteRecursively() + } + } + // The session folder is app-private, so adb pulls this copy from external files instead. private fun logs(context: Context): JSONObject { val dir = logDir(context)?.takeIf { it.isDirectory } ?: return error("NO_SESSION_LOGS", "No session artifact directory is available") - val output = File(context.getExternalFilesDir(null), "agent-logs/${UUID.randomUUID()}") + val externalFiles = context.getExternalFilesDir(null) + ?: return error("NO_SESSION_LOGS", "External app storage is unavailable") + val exports = File(externalFiles, "agent-logs") + if (!exports.exists() && !exports.mkdirs()) { + return error("NO_SESSION_LOGS", "Could not create the session export directory") + } + cleanupExpiredLogExports(exports) + val output = File(exports, UUID.randomUUID().toString()) val zip = try { SessionLogShare.zipFolder(context, dir, output) } catch (error: Exception) { @@ -373,6 +392,7 @@ class AgentBridgeProvider : ContentProvider() { const val RESULT_JSON = "json" const val EXTRA_REQUEST = "request" const val SCHEMA = 2 + private const val LOG_EXPORT_RETENTION_MS = 24 * 60 * 60 * 1000L private val recoveryComplete = CountDownLatch(1) fun awaitRecovery() { diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 270cb7b807..2279bd12f1 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -476,6 +476,16 @@ def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: backed_up = {} installed = set() manifest_backup = backups / manifest.name + manifest_fd, manifest_path = tempfile.mkstemp( + prefix=".droiddeckctl-managed-logs-", suffix=".tmp", dir=destination + ) + temp_manifest = Path(manifest_path) + try: + with os.fdopen(manifest_fd, "w", encoding="utf-8") as manifest_file: + manifest_file.write(json.dumps(sorted(extracted), indent=2) + "\n") + except Exception: + temp_manifest.unlink(missing_ok=True) + raise try: for name in sorted(previous): target = managed_target(name) @@ -494,10 +504,9 @@ def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: target.parent.mkdir(parents=True, exist_ok=True) os.replace(staged_files / name, target) installed.add(name) - temp_manifest = staged / "managed-logs.json" - temp_manifest.write_text(json.dumps(sorted(extracted), indent=2) + "\n", encoding="utf-8") os.replace(temp_manifest, manifest) except Exception: + temp_manifest.unlink(missing_ok=True) for name in installed: target = managed_target(name) if target is not None and target.is_file(): From 11c0763fbae7c22b7da7e42b3007163a422fbccd Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:30:59 -0500 Subject: [PATCH 59/85] fix: preserve log cleanup failures --- .../launcher/agent/AgentBridgeProvider.kt | 2 +- tools/droiddeckctl | 43 +++++++++++++------ tools/tests/test_droiddeckctl.py | 33 +++++++++++++- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt index f41b342507..c1955caa05 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt @@ -222,7 +222,7 @@ class AgentBridgeProvider : ContentProvider() { val externalFiles = context.getExternalFilesDir(null) ?: return error("NO_SESSION_LOGS", "External app storage is unavailable") val exports = File(externalFiles, "agent-logs") - if (!exports.exists() && !exports.mkdirs()) { + if ((!exports.exists() && !exports.mkdirs()) || !exports.isDirectory) { return error("NO_SESSION_LOGS", "Could not create the session export directory") } cleanupExpiredLogExports(exports) diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 2279bd12f1..02fe7020c8 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -470,7 +470,7 @@ def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: for name in extracted - previous: target = managed_target(name) if target is None or target.exists(): - raise ControlError(f"Refusing to overwrite an unrelated file: {target}", "LOG_PULL_FAILED") + raise ControlError(f"Refusing to overwrite an unrelated file: {name}", "LOG_PULL_FAILED") if manifest.is_symlink() or (manifest.exists() and not manifest.is_file()): raise ControlError("The managed log list is not a regular file", "LOG_PULL_FAILED") backed_up = {} @@ -511,7 +511,7 @@ def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: target = managed_target(name) if target is not None and target.is_file(): target.unlink() - if manifest.exists() and not manifest.is_symlink(): + if manifest_backup.is_file() and manifest.exists() and not manifest.is_symlink(): manifest.unlink() for name, backup in backed_up.items(): target = managed_target(name) @@ -846,6 +846,7 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict: raise ControlError("No session artifact directory is available", "NO_SESSION_LOGS") destination = Path(args.destination or session["id"]).expanduser().resolve() exported = provider_call(adb, serial, "logs", timeout=args.timeout + 40) + cleanup_error = None if (exported.get("error") or {}).get("code") == "UNKNOWN_COMMAND": # Older builds have no logs method; their private folder only pulls on a rooted device. result = run_adb(adb, serial, "pull", remote_dir, str(destination), timeout=120) @@ -862,6 +863,20 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict: request_dir == remote_zip.parent and request_dir.parent.name == "agent-logs" and re.fullmatch(r"[0-9a-fA-F-]{36}", request_dir.name)): cleanup = ["shell", "rm", "-rf", str(request_dir)] + def cleanup_export(): + try: + cleaned = run_adb(adb, serial, *cleanup, timeout=30) + if cleaned.returncode == 0: + return None + detail = (cleaned.stderr or cleaned.stdout).decode(errors="replace").strip() + except Exception as error: + detail = str(error) + return ControlError( + "Could not remove the exported log archive; it may remain in shared storage" + + (f": {detail}" if detail else ""), + "LOG_CLEANUP_FAILED", + ) + try: if exported.get("sessionId", session["id"]) != session["id"]: raise ControlError("A new session started while the logs were exported; run logs again", @@ -869,21 +884,23 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict: with tempfile.TemporaryDirectory() as temp: local_zip = Path(temp) / "logs.zip" result = run_adb(adb, serial, "pull", zip_path, str(local_zip), timeout=120) - if result.returncode == 0: - unpack_logs(local_zip, destination, session["id"]) - finally: + if result.returncode != 0: + detail = (result.stderr or result.stdout).decode(errors="replace").strip() + raise ControlError(detail or "adb pull failed", "LOG_PULL_FAILED") + unpack_logs(local_zip, destination, session["id"]) + except Exception: + cleanup_error = cleanup_export() + if cleanup_error: + print(cleanup_error, file=sys.stderr) + raise + else: # The copy sits in shared storage, so it does not outlive the pull. - cleaned = run_adb(adb, serial, *cleanup, timeout=30) - if cleaned.returncode != 0: - detail = (cleaned.stderr or cleaned.stdout).decode(errors="replace").strip() - raise ControlError( - "Could not remove the exported log archive; it may remain in shared storage" + - (f": {detail}" if detail else ""), - "LOG_CLEANUP_FAILED", - ) + cleanup_error = cleanup_export() if result.returncode != 0: detail = (result.stderr or result.stdout).decode(errors="replace").strip() raise ControlError(detail or "adb pull failed", "LOG_PULL_FAILED") + if cleanup_error: + raise cleanup_error return add_serial({"ok": True, "command": "logs", "sessionId": session["id"], "path": str(destination)}, serial) if command == "screenshot": diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 4197f721b8..3598dea36e 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -581,6 +581,15 @@ class DroiddeckctlTest(FakeAdbTest): self.assertEqual("LOG_CLEANUP_FAILED", out["error"]["code"]) self.assertIn("may remain in shared storage", out["error"]["message"]) + def test_logs_keep_pull_failure_primary_when_remote_cleanup_fails(self): + self.configure({"state": ended_state(), + "logs": {"ok": True, "sessionId": "s1", "zip": EXPORTED_ZIP, + "cleanupDir": EXPORTED_DIR}}, fail_cleanup=True) + code, out = self.run_ctl("logs", "latest", str(self.dir / "artifacts")) + self.assertEqual(6, code) + self.assertEqual("LOG_PULL_FAILED", out["error"]["code"]) + self.assertIn("Permission denied", out["error"]["message"]) + def test_logs_replace_the_previous_snapshot_and_preserve_unrelated_files(self): destination = self.dir / "artifacts" destination.mkdir() @@ -620,7 +629,7 @@ class DroiddeckctlTest(FakeAdbTest): self.assertEqual("current", (destination / "session.log").read_text()) def test_logs_roll_back_a_failed_manifest_commit_and_can_retry(self): - destination = self.dir / "artifacts" + destination = (self.dir / "artifacts").resolve() destination.mkdir() (destination / "notes.txt").write_text("keep me") first = self.dir / "first.zip" @@ -657,6 +666,28 @@ class DroiddeckctlTest(FakeAdbTest): self.assertFalse((destination / "steam/console.log").exists()) self.assertEqual("keep me", (destination / "notes.txt").read_text()) + def test_logs_preserve_the_old_manifest_when_its_backup_fails(self): + destination = self.dir / "artifacts" + destination.mkdir() + archive = self.dir / "logs.zip" + with zipfile.ZipFile(archive, "w") as z: + z.writestr("s1/session.log", "current") + manifest = destination / ".droiddeckctl-managed-logs.json" + manifest.write_text(json.dumps(["old.log"])) + original = manifest.read_bytes() + real_replace = ctl.os.replace + + def fail_manifest_backup(source, target): + if Path(source) == manifest: + raise OSError("injected manifest backup failure") + return real_replace(source, target) + + with unittest.mock.patch.object(ctl.os, "replace", side_effect=fail_manifest_backup): + with self.assertRaises(ctl.ControlError): + ctl.unpack_logs(archive, destination, "s1") + + self.assertEqual(original, manifest.read_bytes()) + def test_logs_from_an_older_build_fall_back_to_the_private_folder(self): self.configure({"state": ended_state()}) code, out = self.run_ctl("logs", "latest", str(self.dir / "artifacts")) From dfc0fd4340eb1be8799329343b952f9972b8edf5 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:49:11 -0500 Subject: [PATCH 60/85] fix: harden diagnostic staging lifecycle --- .../main/java/com/droiddeck/launcher/App.kt | 2 + .../session/EnhancedSessionLogShare.kt | 133 +++++++++++++++--- .../session/SessionLogShareZipTest.kt | 13 ++ tools/tests/test_droiddeckctl.py | 2 +- 4 files changed, 132 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/App.kt b/app/src/main/java/com/droiddeck/launcher/App.kt index 0d099cbf0b..311dc00824 100644 --- a/app/src/main/java/com/droiddeck/launcher/App.kt +++ b/app/src/main/java/com/droiddeck/launcher/App.kt @@ -3,6 +3,7 @@ package com.droiddeck.launcher import android.app.Application import com.droiddeck.launcher.runtime.BwrapSpawner import com.droiddeck.launcher.session.CrashHandler +import com.droiddeck.launcher.session.EnhancedSessionLogShare import com.droiddeck.launcher.session.GpuClockPin class App : Application() { @@ -16,6 +17,7 @@ class App : Application() { override fun onCreate() { super.onCreate() + runCatching { EnhancedSessionLogShare.cleanupAbandonedStages(this) } com.droiddeck.launcher.ui.Themes.loadGradient(this) com.droiddeck.launcher.ui.BuildWatermark.install(this) HomeApp.trackRecents(this) diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index d20da13d62..9c19489a26 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -11,6 +11,7 @@ import org.json.JSONArray import org.json.JSONObject import java.io.BufferedInputStream import java.io.ByteArrayOutputStream +import java.io.Closeable import java.io.File import java.io.FileOutputStream import java.io.FileInputStream @@ -18,12 +19,15 @@ import java.io.IOException import java.nio.ByteBuffer import java.nio.channels.Channels import java.nio.channels.FileChannel +import java.nio.channels.FileLock +import java.nio.channels.OverlappingFileLockException import java.nio.channels.SeekableByteChannel import java.nio.file.FileVisitResult import java.nio.file.Files import java.nio.file.LinkOption import java.nio.file.Path import java.nio.file.SimpleFileVisitor +import java.nio.file.StandardOpenOption import java.nio.file.attribute.BasicFileAttributes import java.security.MessageDigest import java.util.Locale @@ -45,6 +49,24 @@ internal interface SecureSourceOpener { internal object EnhancedSessionLogShare { private enum class Category(val suffix: String) { SESSION("session"), GRAPHICS("graphics"), GAMES("games") } + internal class DiagnosticStageLease internal constructor( + val directory: File, + private val channel: FileChannel, + private val lock: FileLock, + ) : Closeable { + override fun close() { + try { + lock.release() + } finally { + try { + channel.close() + } finally { + directory.deleteRecursively() + } + } + } + } + private data class Candidate( val file: File, val anchor: File, @@ -65,6 +87,8 @@ internal object EnhancedSessionLogShare { private data class Snapshot(val file: File, val sourceBytes: Long, val truncated: Boolean) + private class StageUnavailableException(cause: Throwable) : IOException("Diagnostic staging directory is unavailable", cause) + private data class CollectionResult( val candidates: List<Candidate>, val truncated: Boolean, @@ -90,6 +114,70 @@ internal object EnhancedSessionLogShare { private val sourceOpenerOverride = object : ThreadLocal<SecureSourceOpener?>() { override fun initialValue(): SecureSourceOpener? = null } + private val stageLifecycleMonitor = Any() + + internal fun acquireDiagnosticStage(context: Context, outputName: String): DiagnosticStageLease { + val cache = context.cacheDir + require(outputName.isNotBlank() && File(outputName).name == outputName) + return withStageLifecycleLock(cache) { + val stage = File(cache, "$outputName-${UUID.randomUUID()}.diagnostic-stage") + if (!stage.mkdir()) throw IOException("Could not create the diagnostic staging directory") + val channel = try { + FileChannel.open(File(stage, ".active").toPath(), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE) + } catch (error: Exception) { + stage.deleteRecursively() + throw IOException("Could not create the diagnostic staging lock", error) + } + try { + val lock = channel.tryLock() + ?: throw IOException("Could not lock the diagnostic staging directory") + DiagnosticStageLease(stage, channel, lock) + } catch (error: Exception) { + channel.close() + stage.deleteRecursively() + throw IOException("Could not lock the diagnostic staging directory", error) + } + } + } + + internal fun cleanupAbandonedStages(context: Context) { + val cache = context.cacheDir + val canonicalCache = cache.canonicalFile + withStageLifecycleLock(cache) { + cache.listFiles()?.forEach { stage -> + if (!stage.isDirectory || Files.isSymbolicLink(stage.toPath()) || + stage.canonicalFile.parentFile != canonicalCache || !isDiagnosticStage(stage.name)) return@forEach + val active = File(stage, ".active") + if (Files.isSymbolicLink(active.toPath())) return@forEach + val channel = runCatching { + FileChannel.open(active.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE) + }.getOrNull() ?: return@forEach + val abandoned = try { + channel.tryLock()?.let { lock -> lock.release(); true } ?: false + } catch (_: OverlappingFileLockException) { + false + } finally { + channel.close() + } + if (abandoned) stage.deleteRecursively() + } + } + } + + private fun isDiagnosticStage(name: String): Boolean { + val suffix = ".diagnostic-stage" + if (!name.endsWith(suffix)) return false + val base = name.removeSuffix(suffix) + val uuidStart = base.length - 36 + if (uuidStart < 2 || base[uuidStart - 1] != '-') return false + return runCatching { UUID.fromString(base.substring(uuidStart)).toString() == base.substring(uuidStart) } + .getOrDefault(false) + } + + private fun <T> withStageLifecycleLock(cache: File, block: () -> T): T = synchronized(stageLifecycleMonitor) { + FileChannel.open(File(cache, ".diagnostic-stages.lock").toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE) + .use { channel -> channel.lock().use { block() } } + } internal fun setSourceOpenerForTest(opener: SecureSourceOpener?) { if (opener == null) sourceOpenerOverride.remove() else sourceOpenerOverride.set(opener) @@ -108,17 +196,18 @@ internal object EnhancedSessionLogShare { return emptyList() } val out = SessionLogShare.shareDir(context).apply { deleteRecursively(); mkdirs() } - val stage = File(context.cacheDir, "${out.name}-${UUID.randomUUID()}.diagnostic-stage").apply { mkdirs() } - val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) - val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = false) - val candidates = discovery.candidates - val totalCandidates = candidates.size.coerceAtLeast(1) - val share = limits.maxBytesTotal / Category.values().size - val budgets = Category.values().associateWith { category -> - Budget(if (category == Category.GAMES) limits.maxBytesTotal - share * 2 else share) - } - var completed = 0 + val stageLease = acquireDiagnosticStage(context, out.name) + val stage = stageLease.directory return try { + val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) + val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = false) + val candidates = discovery.candidates + val totalCandidates = candidates.size.coerceAtLeast(1) + val share = limits.maxBytesTotal / Category.values().size + val budgets = Category.values().associateWith { category -> + Budget(if (category == Category.GAMES) limits.maxBytesTotal - share * 2 else share) + } + var completed = 0 Category.values().map { category -> val budget = budgets.getValue(category) val records = ArrayList<Record>() @@ -151,7 +240,7 @@ internal object EnhancedSessionLogShare { zip } } finally { - stage.deleteRecursively() + stageLease.close() } } @@ -174,7 +263,8 @@ internal object EnhancedSessionLogShare { out.deleteRecursively() return null } - val stage = File(context.cacheDir, "${out.name}-${UUID.randomUUID()}.diagnostic-stage").apply { mkdirs() } + val stageLease = acquireDiagnosticStage(context, out.name) + val stage = stageLease.directory val records = ArrayList<Record>() val budget = Budget(limits.maxBytesTotal) val zip = File(out, "DroidDeck-${folder.name}.zip") @@ -200,7 +290,7 @@ internal object EnhancedSessionLogShare { } zip } finally { - stage.deleteRecursively() + stageLease.close() } } @@ -228,10 +318,14 @@ internal object EnhancedSessionLogShare { if (budget.remaining <= 0) { return Record(candidate.entry, candidate.origin, "omitted", reason = "bundle-byte-limit") } - val snapshot = runCatching { + if (!stage.isDirectory || !stage.canWrite()) throw StageUnavailableException(IOException("staging path is not writable")) + val snapshot = try { snapshot(candidate, stage, minOf(limits.maxBytesPerFile, budget.remaining)) - }.getOrElse { - return Record(candidate.entry, candidate.origin, "error", reason = it.javaClass.simpleName) + } catch (error: StageUnavailableException) { + throw error + } catch (error: Exception) { + if (!stage.isDirectory || !stage.canWrite()) throw StageUnavailableException(error) + return Record(candidate.entry, candidate.origin, "error", reason = error.javaClass.simpleName) } ?: return Record(candidate.entry, candidate.origin, "omitted", reason = "unsafe-or-unavailable-source") if (snapshot.file.length() == 0L && candidate.linePrefix != null) { snapshot.file.delete() @@ -267,7 +361,11 @@ internal object EnhancedSessionLogShare { val rootPath = candidate.anchor.toPath().toAbsolutePath().normalize() val sourcePath = candidate.file.toPath().toAbsolutePath().normalize() if (!sourcePath.startsWith(rootPath) || sourcePath == rootPath || limit < 1) return null - val target = File.createTempFile("diagnostic-", ".log", stage) + val target = try { + File.createTempFile("diagnostic-", ".log", stage) + } catch (error: Exception) { + throw StageUnavailableException(error) + } try { val relative = rootPath.relativize(sourcePath) return withSecureChannel(rootPath, relative) { input -> @@ -293,6 +391,7 @@ internal object EnhancedSessionLogShare { } ?: target.delete().let { null } } catch (e: Exception) { target.delete() + if (!stage.isDirectory || !stage.canWrite() || !target.exists()) throw StageUnavailableException(e) throw e } } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index 0779a378cb..ddf8909a89 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -3,6 +3,7 @@ package com.droiddeck.launcher.session import com.droiddeck.launcher.runtime.LinuxRuntime import java.io.File import java.text.SimpleDateFormat +import java.util.UUID import java.util.Date import java.util.Locale import java.util.zip.ZipFile @@ -26,6 +27,18 @@ class SessionLogShareZipTest { @After fun resetSourceOpener() = resetSecureSourceOpener() + @Test fun startupRemovesAbandonedDiagnosticStagesAndPreservesActiveSnapshots() { + val abandoned = File(app.cacheDir, "share-${UUID.randomUUID()}.diagnostic-stage").apply { mkdirs() } + val active = EnhancedSessionLogShare.acquireDiagnosticStage(app, "share") + try { + EnhancedSessionLogShare.cleanupAbandonedStages(app) + assertFalse(abandoned.exists()) + assertTrue(active.directory.isDirectory) + } finally { + active.close() + } + } + @Test fun anArchiveCanBeWrittenOutsideTheShareFolder() { SessionLogShare.clear(app) val session = File(LinuxRuntime.logDir(app), "2026-11-03-01-steam").apply { mkdirs() } diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 3598dea36e..0c4bdbce3f 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -667,7 +667,7 @@ class DroiddeckctlTest(FakeAdbTest): self.assertEqual("keep me", (destination / "notes.txt").read_text()) def test_logs_preserve_the_old_manifest_when_its_backup_fails(self): - destination = self.dir / "artifacts" + destination = (self.dir / "artifacts").resolve() destination.mkdir() archive = self.dir / "logs.zip" with zipfile.ZipFile(archive, "w") as z: From 671c4a623fb92bd61ef30981b9f71495a63ee6c5 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:51:17 -0500 Subject: [PATCH 61/85] test: assert cleanup after failed log pull --- tools/tests/test_droiddeckctl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 0c4bdbce3f..531bcd8913 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -589,6 +589,7 @@ class DroiddeckctlTest(FakeAdbTest): self.assertEqual(6, code) self.assertEqual("LOG_PULL_FAILED", out["error"]["code"]) self.assertIn("Permission denied", out["error"]["message"]) + self.assertIn(["shell", "rm", "-rf", EXPORTED_DIR], [call["args"] for call in self.calls()]) def test_logs_replace_the_previous_snapshot_and_preserve_unrelated_files(self): destination = self.dir / "artifacts" From 0bb8384c76ffa12683f0ea09392576cd08ad0bd0 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:53:15 -0500 Subject: [PATCH 62/85] fix: avoid unsupported ray tracing on Stellar Blade startup --- .../overlay/usr/local/bin/droiddeck-game-env | 9 +++++++ tools/tests/test_game_environment.py | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index ac7cd5189c..d85b1bc510 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -171,6 +171,15 @@ def reskate_feature_level(game): return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "ReSkate (skate.): D3D12 feature level 12_1" +@fix +def stellar_blade_feature_level(game): + if game.stem == "sb-win64-shipping" or ( + "sb.exe" in game.files + and os.path.isfile(os.path.join(os.path.dirname(game.exe), "SB", "Binaries", "Win64", "SB-Win64-Shipping.exe")) + ): + return {"VKD3D_FEATURE_LEVEL": None}, [], "Stellar Blade: use the driver's D3D12 feature level (12_2 advertises unsupported ray tracing)" + + @fix def cyberpunk_feature_level(game): if game.stem == "cyberpunk2077" or ( diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index c48e5ab1b2..093c5e8430 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -1190,6 +1190,31 @@ class GameEnvironmentTest(unittest.TestCase): (skate / name).touch() self.assertEqual(MODULE["engine_fixes"](str(skate / "EAAntiCheat.GameServiceLauncher.exe"), [])[:2], ({}, [])) + def test_stellar_blade_uses_detected_feature_level_without_overriding_game_settings(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) / "StellarBlade" + shipping = root / "SB/Binaries/Win64/SB-Win64-Shipping.exe" + shipping.parent.mkdir(parents=True) + shipping.touch() + (root / "SB.exe").touch() + config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2"}} + for exe in (root / "SB.exe", root / ".droiddeck-launch.bat", shipping): + env, extra, notes = MODULE["engine_fixes"](str(exe), []) + self.assertEqual((env, extra), ({"VKD3D_FEATURE_LEVEL": None}, []), exe) + self.assertTrue(notes) + inherited = {"VKD3D_FEATURE_LEVEL": "12_2", "KEEP": "unchanged"} + effective = MODULE["apply_config"](inherited, config, "3489700", env) + self.assertNotIn("VKD3D_FEATURE_LEVEL", effective) + self.assertEqual(effective["KEEP"], "unchanged") + for value in ("12_1", "12_2", None): + explicit = dict(config, games={"3489700": {"VKD3D_FEATURE_LEVEL": value}}) + actual = MODULE["apply_config"](inherited, explicit, "3489700", env) + self.assertEqual(actual.get("VKD3D_FEATURE_LEVEL"), value) + other = Path(tmp) / "Other" + other.mkdir() + (other / "SB.exe").touch() + self.assertEqual(MODULE["engine_fixes"](str(other / "SB.exe"), []), ({}, [], [])) + def test_caravan_sandwitch_robocop_and_cyberpunk_run_at_feature_level_12_1(self): with tempfile.TemporaryDirectory() as tmp: caravan = Path(tmp) / "Caravan SandWitch" From 9f22f63222744a58501a53b1a3fa38b76b4fc544 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:59:37 -0500 Subject: [PATCH 63/85] test: verify independent log export paths --- .../com/droiddeck/launcher/session/SessionLogShareZipTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index ddf8909a89..6af039ade9 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -51,8 +51,8 @@ class SessionLogShareZipTest { assertEquals(out, zip.parentFile) assertFalse(File(app.cacheDir, "share").exists()) assertTrue(zip.isFile) + assertEquals(secondOut, secondZip.parentFile) assertTrue(secondZip.isFile) - assertTrue(zip.isFile) } finally { out.deleteRecursively() secondOut.deleteRecursively() From 64f114c96f2e556f0ded7dcde37e5acbe901beb1 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 15:03:08 -0500 Subject: [PATCH 64/85] fix: detect graphics capabilities and drop redundant title overrides --- .../launcher/core/GameEnvironment.kt | 2 - .../launcher/core/GameEnvironmentTest.kt | 10 +- .../session/GameEnvironmentStoreTest.kt | 15 ++- docs/development/game-environment.md | 17 ++- .../overlay/usr/local/bin/droiddeck-game-env | 35 ------ tools/tests/test_game_environment.py | 106 +++++------------- 6 files changed, 55 insertions(+), 130 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt index 4672cc651b..26ffb499cc 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt @@ -30,8 +30,6 @@ object GameEnvironment { fun defaults(preset: String, forceSsbs: Boolean = false): Map<String, String?> = linkedMapOf<String, String?>( "MESA_SHADER_CACHE_DISABLE" to "false", "DROIDDECK_ANTICHEAT_OFFLINE" to "1", - "VKD3D_FEATURE_LEVEL" to "12_2", - "VKD3D_SHADER_MODEL" to "6_9", "DOTNET_GCRegionRange" to "800000000", "DOTNET_EnableWriteXorExecute" to "0", ).apply { diff --git a/app/src/test/java/com/droiddeck/launcher/core/GameEnvironmentTest.kt b/app/src/test/java/com/droiddeck/launcher/core/GameEnvironmentTest.kt index 281a782246..cd9d785d8c 100644 --- a/app/src/test/java/com/droiddeck/launcher/core/GameEnvironmentTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/core/GameEnvironmentTest.kt @@ -4,12 +4,12 @@ import org.junit.Assert.* import org.junit.Test class GameEnvironmentTest { - @Test fun defaultsIncludeRequestedGraphicsLevelsAndKeepCaching() { + @Test fun defaultsDetectGraphicsCapabilitiesAndKeepCaching() { val values = GameEnvironment.defaults("") assertEquals("false", values["MESA_SHADER_CACHE_DISABLE"]) assertEquals("1", values["DROIDDECK_ANTICHEAT_OFFLINE"]) - assertEquals("12_2", values["VKD3D_FEATURE_LEVEL"]) - assertEquals("6_9", values["VKD3D_SHADER_MODEL"]) + assertFalse(values.containsKey("VKD3D_FEATURE_LEVEL")) + assertFalse(values.containsKey("VKD3D_SHADER_MODEL")) } @Test fun forceSsbsIsADefaultAGameCanTurnOff() { @@ -35,14 +35,14 @@ class GameEnvironmentTest { } @Test fun graphicsDefaultsRespectExistingEditsAndRemovals() { - val config = GameEnvironment.Config(shared = mapOf("VKD3D_FEATURE_LEVEL" to "12_0")) + val config = GameEnvironment.Config(shared = mapOf("VKD3D_FEATURE_LEVEL" to "12_0", "VKD3D_SHADER_MODEL" to "6_5")) .withEntries("42", mapOf("VKD3D_SHADER_MODEL" to null)) val game = GameEnvironment.effective(config, "", "42") assertEquals("12_0", game["VKD3D_FEATURE_LEVEL"]) assertTrue(game.containsKey("VKD3D_SHADER_MODEL")) assertNull(game["VKD3D_SHADER_MODEL"]) val restored = GameEnvironment.effective(config.withEntries("42", emptyMap()), "", "42") - assertEquals("6_9", restored["VKD3D_SHADER_MODEL"]) + assertEquals("6_5", restored["VKD3D_SHADER_MODEL"]) } @Test fun dotnetRuntimeFitsAndroidAddressSpaceForEveryGame() { diff --git a/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt b/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt index 197512e5be..da16928da6 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt @@ -164,13 +164,24 @@ class GameEnvironmentStoreTest { assertEquals(config, GameEnvironmentStore.read(context)) val published = GameEnvironmentStore.decode(JSONObject(guest.readText())) assertEquals("false", published.shared["MESA_SHADER_CACHE_DISABLE"]) - assertEquals("12_2", published.shared["VKD3D_FEATURE_LEVEL"]) - assertEquals("6_9", published.shared["VKD3D_SHADER_MODEL"]) + assertFalse(published.shared.containsKey("VKD3D_FEATURE_LEVEL")) + assertFalse(published.shared.containsKey("VKD3D_SHADER_MODEL")) assertEquals(config.games, published.games) assertEquals(config.shared["LITERAL"], published.shared["LITERAL"]) assertEquals("", published.shared["EMPTY"]) } + @Test fun publishingPreservesExplicitSharedGraphicsCapabilities() { + val config = GameEnvironment.Config(shared = mapOf( + "VKD3D_FEATURE_LEVEL" to "12_1", "VKD3D_SHADER_MODEL" to "6_6", + )) + GameEnvironmentStore.save(context, config) + val published = GameEnvironmentStore.decode(JSONObject(guest.readText())) + assertEquals(config, GameEnvironmentStore.read(context)) + assertEquals("12_1", published.shared["VKD3D_FEATURE_LEVEL"]) + assertEquals("6_6", published.shared["VKD3D_SHADER_MODEL"]) + } + @Test fun changingFexPresetPublishesForNextGameLaunch() { GameEnvironmentStore.save(context, GameEnvironment.Config()) SessionPrefs.setFexPreset(context, "EXTREME") diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md index e7c7ca210b..c1607ec5fb 100644 --- a/docs/development/game-environment.md +++ b/docs/development/game-environment.md @@ -191,9 +191,10 @@ per-game value in the environment editor still wins. ## Defaults and available suggestions The initial configuration enables Mesa shader caching with -`MESA_SHADER_CACHE_DISABLE=false`, sets `VKD3D_FEATURE_LEVEL=12_2` and -`VKD3D_SHADER_MODEL=6_9`, and preserves the selected FEX preset. Existing edits -and explicit removals take precedence over these defaults. FEX's own default +`MESA_SHADER_CACHE_DISABLE=false` and preserves the selected FEX preset. +`VKD3D_FEATURE_LEVEL` and `VKD3D_SHADER_MODEL` are unset by default, so VKD3D +detects capabilities from the active Vulkan driver. Existing shared and per-game +overrides, including explicit removals, are preserved. FEX's own default remains the default preset. Shader caching in VKD3D/DXVK, synchronization, ray tracing and diagnostic logging otherwise retain the runtime's defaults. @@ -209,8 +210,8 @@ values. Custom variables have editable names and literal values. | Variable | Use | | --- | --- | -| `VKD3D_FEATURE_LEVEL` | D3D12 capability override; defaults to `12_2`. | -| `VKD3D_SHADER_MODEL` | Shader-model override; defaults to `6_9`. | +| `VKD3D_FEATURE_LEVEL` | Optional D3D12 capability override; automatic detection by default. | +| `VKD3D_SHADER_MODEL` | Optional shader-model override; automatic detection by default. | | `VKD3D_CONFIG` | Per-game workarounds such as `nodxr`; not a universal performance preset. | | `MESA_SHADER_CACHE_MAX_SIZE` | Storage budget for Mesa's shader cache, for example `1G`. | | `mesa_glthread` | OpenGL threading; test with the affected game. | @@ -221,7 +222,11 @@ values. Custom variables have editable names and literal values. | `PROTON_USE_XALIA` | Proton's gamepad-navigation helper toggle. | Forcing `12_2` or `6_9` changes reported capabilities; it cannot implement a missing -Vulkan feature. Remove either entry to use automatic detection for that capability. +Vulkan feature. Remove or unset either entry to use automatic detection for that capability. +The former feature-level rules for Caravan SandWitch, RoboCop: Rogue City, +ReSkate and Cyberpunk 2077 compensated for the global `12_2` override and are +removed. Stellar Blade also uses automatic detection. The separate Deep Rock +Galactic GDK ray-tracing opt-out and Mali bridge capability cap remain. Other picker suggestions are editable starting values and are enabled only when added and saved. Older or custom components can support a different set of options. Android Wine wrapper, diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index d85b1bc510..886bf10bd6 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -153,41 +153,6 @@ def little_nightmares_threads(game): return {"PROTONFIXES_DISABLE": "1"}, [], "Little Nightmares: umu-protonfixes off (its -onethread puts the game and renderer on one thread)" -@fix -def caravan_sandwitch_feature_level(game): - if "caravansandwitch.exe" in game.files or game.stem == "caravansandwitch-win64-shipping": - return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Caravan SandWitch: D3D12 feature level 12_1 (12_2 hands it mesh shader pipelines vkd3d-proton cannot build)" - - -@fix -def robocop_rogue_city_feature_level(game): - if "robocop.exe" in game.files or game.stem == "robocop-win64-shipping": - return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "RoboCop: Rogue City: D3D12 feature level 12_1" - - -@fix -def reskate_feature_level(game): - if "skate.exe" in game.files and "reskate.dll" in game.files: - return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "ReSkate (skate.): D3D12 feature level 12_1" - - -@fix -def stellar_blade_feature_level(game): - if game.stem == "sb-win64-shipping" or ( - "sb.exe" in game.files - and os.path.isfile(os.path.join(os.path.dirname(game.exe), "SB", "Binaries", "Win64", "SB-Win64-Shipping.exe")) - ): - return {"VKD3D_FEATURE_LEVEL": None}, [], "Stellar Blade: use the driver's D3D12 feature level (12_2 advertises unsupported ray tracing)" - - -@fix -def cyberpunk_feature_level(game): - if game.stem == "cyberpunk2077" or ( - game.stem == "redprelauncher" - and os.path.isfile(os.path.join(os.path.dirname(game.exe), "bin", "x64", "Cyberpunk2077.exe")) - ): - return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Cyberpunk 2077: D3D12 feature level 12_1" - def skip_red_launcher(command): if len(command) > 2 and os.path.basename(command[2]).lower() == "redprelauncher.exe": game = os.path.join(os.path.dirname(command[2]), "bin", "x64", "Cyberpunk2077.exe") diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index 093c5e8430..cd58fba4d6 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -1170,87 +1170,33 @@ class GameEnvironmentTest(unittest.TestCase): self.assertEqual(speeds([0, 1], tmp), {0: 2265600, 1: 3302400}) self.assertIsNone(speeds([0, 2], tmp)) - def test_reskate_runs_at_feature_level_12_1(self): + def test_titles_with_former_feature_level_workarounds_keep_detected_capabilities(self): with tempfile.TemporaryDirectory() as tmp: - reskate = Path(tmp) / "ReSkate" - reskate.mkdir() - for name in ("Skate.exe", "ReSkate.dll", "ReSkateLauncher.exe", "EAAntiCheat.GameServiceLauncher.exe"): - (reskate / name).touch() - for exe in ("ReSkateLauncher.exe", "Skate.exe"): - env, extra, notes = MODULE["engine_fixes"](str(reskate / exe), []) - self.assertEqual((env, extra), ({"VKD3D_FEATURE_LEVEL": "12_1"}, []), exe) - self.assertTrue(notes) - config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2"}} - self.assertEqual(MODULE["apply_config"]({}, config, "3354750", env)["VKD3D_FEATURE_LEVEL"], "12_1") - config["games"] = {"3354750": {"VKD3D_FEATURE_LEVEL": "12_2"}} - self.assertEqual(MODULE["apply_config"]({}, config, "3354750", env)["VKD3D_FEATURE_LEVEL"], "12_2") - skate = Path(tmp) / "Skate" - skate.mkdir() - for name in ("Skate.exe", "EAAntiCheat.GameServiceLauncher.exe"): - (skate / name).touch() - self.assertEqual(MODULE["engine_fixes"](str(skate / "EAAntiCheat.GameServiceLauncher.exe"), [])[:2], ({}, [])) - - def test_stellar_blade_uses_detected_feature_level_without_overriding_game_settings(self): - with tempfile.TemporaryDirectory() as tmp: - root = Path(tmp) / "StellarBlade" - shipping = root / "SB/Binaries/Win64/SB-Win64-Shipping.exe" - shipping.parent.mkdir(parents=True) - shipping.touch() - (root / "SB.exe").touch() - config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2"}} - for exe in (root / "SB.exe", root / ".droiddeck-launch.bat", shipping): - env, extra, notes = MODULE["engine_fixes"](str(exe), []) - self.assertEqual((env, extra), ({"VKD3D_FEATURE_LEVEL": None}, []), exe) - self.assertTrue(notes) - inherited = {"VKD3D_FEATURE_LEVEL": "12_2", "KEEP": "unchanged"} - effective = MODULE["apply_config"](inherited, config, "3489700", env) - self.assertNotIn("VKD3D_FEATURE_LEVEL", effective) - self.assertEqual(effective["KEEP"], "unchanged") - for value in ("12_1", "12_2", None): - explicit = dict(config, games={"3489700": {"VKD3D_FEATURE_LEVEL": value}}) - actual = MODULE["apply_config"](inherited, explicit, "3489700", env) - self.assertEqual(actual.get("VKD3D_FEATURE_LEVEL"), value) - other = Path(tmp) / "Other" - other.mkdir() - (other / "SB.exe").touch() - self.assertEqual(MODULE["engine_fixes"](str(other / "SB.exe"), []), ({}, [], [])) - - def test_caravan_sandwitch_robocop_and_cyberpunk_run_at_feature_level_12_1(self): - with tempfile.TemporaryDirectory() as tmp: - caravan = Path(tmp) / "Caravan SandWitch" - shipping = caravan / "CaravanSandWitch/Binaries/Win64" - shipping.mkdir(parents=True) - for name in ("CaravanSandWitch.exe", ".droiddeck-launch.bat"): - (caravan / name).touch() - (shipping / "CaravanSandWitch-Win64-Shipping.exe").touch() - cyberpunk = Path(tmp) / "Cyberpunk 2077" - (cyberpunk / "bin/x64").mkdir(parents=True) - for name in ("REDprelauncher.exe", "bin/x64/Cyberpunk2077.exe"): - (cyberpunk / name).touch() - robocop = Path(tmp) / "RoboCop Rogue City" - (robocop / "RoboCop/Binaries/Win64").mkdir(parents=True) - for name in ("RoboCop.exe", "RoboCop/Binaries/Win64/RoboCop-Win64-Shipping.exe"): - (robocop / name).touch() - games = [caravan / "CaravanSandWitch.exe", caravan / ".droiddeck-launch.bat", - shipping / "CaravanSandWitch-Win64-Shipping.exe", - robocop / "RoboCop.exe", robocop / "RoboCop/Binaries/Win64/RoboCop-Win64-Shipping.exe", - cyberpunk / "REDprelauncher.exe", cyberpunk / "bin/x64/Cyberpunk2077.exe"] - for exe in games: - env, extra, notes = MODULE["engine_fixes"](str(exe), []) - self.assertEqual((env, extra), ({"VKD3D_FEATURE_LEVEL": "12_1"}, []), exe) - self.assertTrue(notes) - config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2"}} - self.assertEqual(MODULE["apply_config"]({}, config, "1582650", env)["VKD3D_FEATURE_LEVEL"], "12_1") - config["games"] = {"1582650": {"VKD3D_FEATURE_LEVEL": "12_2"}} - self.assertEqual(MODULE["apply_config"]({}, config, "1582650", env)["VKD3D_FEATURE_LEVEL"], "12_2") - other = Path(tmp) / "Other/Binaries/Win64" - other.mkdir(parents=True) - (other / "Other-Win64-Shipping.exe").touch() - self.assertEqual(MODULE["engine_fixes"](str(other / "Other-Win64-Shipping.exe"), []), ({}, [], [])) - witcher = Path(tmp) / "The Witcher 3" - witcher.mkdir() - (witcher / "REDprelauncher.exe").touch() - self.assertNotIn("VKD3D_FEATURE_LEVEL", MODULE["engine_fixes"](str(witcher / "REDprelauncher.exe"), [])[0]) + root = Path(tmp) + names = ( + "StellarBlade/SB.exe", "StellarBlade/.droiddeck-launch.bat", + "StellarBlade/SB/Binaries/Win64/SB-Win64-Shipping.exe", + "Caravan/CaravanSandWitch.exe", "Caravan/.droiddeck-launch.bat", + "Caravan/CaravanSandWitch/Binaries/Win64/CaravanSandWitch-Win64-Shipping.exe", + "RoboCop/RoboCop.exe", "RoboCop/RoboCop/Binaries/Win64/RoboCop-Win64-Shipping.exe", + "ReSkate/Skate.exe", "ReSkate/ReSkate.dll", "ReSkate/ReSkateLauncher.exe", + "Cyberpunk/REDprelauncher.exe", "Cyberpunk/bin/x64/Cyberpunk2077.exe", + ) + for name in names: + p = root / name + p.parent.mkdir(parents=True, exist_ok=True) + p.touch() + for name in names: + if name.endswith(".dll"): + continue + env, extra, notes = MODULE["engine_fixes"](str(root / name), []) + self.assertNotIn("VKD3D_FEATURE_LEVEL", env, name) + self.assertNotIn("VKD3D_SHADER_MODEL", env, name) + for values in ({}, {"VKD3D_FEATURE_LEVEL": "12_2", "VKD3D_SHADER_MODEL": "6_9"}): + config = {"version": 1, "shared": values} + self.assertEqual(MODULE["apply_config"]({}, config, "42", env), values, name) + config = {"version": 1, "shared": {}, "games": {"42": values}} + self.assertEqual(MODULE["apply_config"]({}, config, "42", env), values, name) def test_unity_players_keep_tso_over_the_preset(self): with tempfile.TemporaryDirectory() as tmp: From 285ff7956bbcd1fcd7326071d63b8aa2d9e860aa Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 15:09:04 -0500 Subject: [PATCH 65/85] test: cover independent agent log exports --- .../launcher/agent/AgentLogExportTest.kt | 65 +++++++++++++++++++ docs/agent-control.md | 4 ++ 2 files changed, 69 insertions(+) create mode 100644 app/src/test/java/com/droiddeck/launcher/agent/AgentLogExportTest.kt diff --git a/app/src/test/java/com/droiddeck/launcher/agent/AgentLogExportTest.kt b/app/src/test/java/com/droiddeck/launcher/agent/AgentLogExportTest.kt new file mode 100644 index 0000000000..babdec83b6 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/agent/AgentLogExportTest.kt @@ -0,0 +1,65 @@ +package com.droiddeck.launcher.agent + +import android.os.Bundle +import com.droiddeck.launcher.session.SessionState +import com.droiddeck.launcher.session.installJvmSecureSourceOpener +import com.droiddeck.launcher.session.resetSecureSourceOpener +import org.json.JSONObject +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotEquals +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.Robolectric +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33], manifest = Config.NONE) +class AgentLogExportTest { + private val context get() = RuntimeEnvironment.getApplication() + private var previousLogDirectory: File? = null + + @Before fun prepare() { + previousLogDirectory = SessionState.logDirectory + installJvmSecureSourceOpener() + } + + @After fun cleanup() { + SessionState.logDirectory = previousLogDirectory + resetSecureSourceOpener() + } + + @Test fun independentLogRequestsKeepBothExportDirectories() { + val session = File(context.cacheDir, "agent-session").apply { mkdirs() } + File(session, "session.log").writeText("booted\n") + SessionState.logDirectory = session + val provider = Robolectric.buildContentProvider(AgentBridgeProvider::class.java).create().get() + var firstDir: File? = null + var secondDir: File? = null + + try { + fun requestLogs() = JSONObject(provider.call("logs", null, Bundle()).getString("json")!!) + val first = requestLogs() + val second = requestLogs() + firstDir = File(first.getString("cleanupDir")) + secondDir = File(second.getString("cleanupDir")) + val firstZip = File(first.getString("zip")) + val secondZip = File(second.getString("zip")) + + assertNotEquals(firstDir, secondDir) + assertEquals(firstDir, firstZip.parentFile) + assertEquals(secondDir, secondZip.parentFile) + assertTrue(firstZip.isFile) + assertTrue(secondZip.isFile) + } finally { + firstDir?.deleteRecursively() + secondDir?.deleteRecursively() + session.deleteRecursively() + } + } +} diff --git a/docs/agent-control.md b/docs/agent-control.md index eba6ca7735..7a1fed1d0e 100644 --- a/docs/agent-control.md +++ b/docs/agent-control.md @@ -92,6 +92,10 @@ Every command writes one JSON object to stdout and its resolved serial to stderr success, 2 invalid or rejected command, 3 ADB or device error, 4 session error, 5 timeout, 6 artifact or file error, 7 debugging tools disabled. +When upgrading the CLI, use a new destination for the first pull if the old destination contains +archives created by an older CLI without a `.droiddeckctl-managed-logs.json` manifest and their +filenames overlap. The upgraded CLI refuses to overwrite those files to preserve unrelated data. + ## Commands ```sh From a431c40b1b2dc80d784ce5769482b1793da19fe0 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 15:14:23 -0500 Subject: [PATCH 66/85] fix: preserve per-file diagnostic failures --- .../session/EnhancedSessionLogShare.kt | 3 +- .../session/EnhancedSessionLogShareTest.kt | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index 9c19489a26..17acd5f83c 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -390,8 +390,9 @@ internal object EnhancedSessionLogShare { Snapshot(target, size, size > limit) } ?: target.delete().let { null } } catch (e: Exception) { + val targetWasPresent = target.exists() target.delete() - if (!stage.isDirectory || !stage.canWrite() || !target.exists()) throw StageUnavailableException(e) + if (!stage.isDirectory || !stage.canWrite() || !targetWasPresent) throw StageUnavailableException(e) throw e } } diff --git a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt index c1e2e8a211..4a90858070 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt @@ -13,6 +13,7 @@ import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.RuntimeEnvironment import org.robolectric.annotation.Config +import java.io.IOException import java.io.RandomAccessFile import java.nio.ByteBuffer import java.nio.channels.FileChannel @@ -497,4 +498,31 @@ class EnhancedSessionLogShareTest { assertFalse(EnhancedSessionLogShare.hasSourceOpenerForTest()) SessionLogShare.clear(app) } + + @Test fun sourceReadFailureIsRecordedWithoutFailingTheArchive() { + val session = tmp.newFolder("2026-11-04-16-steam") + session.resolve("session.log").writeText("must not be shared\n") + EnhancedSessionLogShare.setSourceOpenerForTest(object : SecureSourceOpener { + override fun <T> withChannel( + root: java.nio.file.Path, + relative: java.nio.file.Path, + block: (java.nio.channels.SeekableByteChannel) -> T, + ): T? = throw IOException("injected source read failure") + }) + try { + val sessionZip = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-session.zip") } + ZipFile(sessionZip).use { archive -> + assertFalse(archive.entries().toList().any { it.name.endsWith("session.log") }) + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()).getJSONArray("entries") + val record = (0 until manifest.length()).map { manifest.getJSONObject(it) } + .single { it.optString("entry").endsWith("session.log") } + assertEquals("error", record.getString("status")) + assertEquals("IOException", record.getString("reason")) + } + } finally { + resetSecureSourceOpener() + } + SessionLogShare.clear(app) + } } From 1ae37055c951c509f224f2d522c13e61766eb4a2 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 15:30:21 -0500 Subject: [PATCH 67/85] fix: preserve diagnostic staging failures --- .../session/EnhancedSessionLogShare.kt | 159 +++++++++++------- .../session/EnhancedSessionLogShareTest.kt | 6 +- 2 files changed, 101 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index 17acd5f83c..f838e71ac6 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -89,6 +89,8 @@ internal object EnhancedSessionLogShare { private class StageUnavailableException(cause: Throwable) : IOException("Diagnostic staging directory is unavailable", cause) + private class SourceReadException(cause: Throwable) : IOException("Could not read diagnostic source", cause) + private data class CollectionResult( val candidates: List<Candidate>, val truncated: Boolean, @@ -325,7 +327,8 @@ internal object EnhancedSessionLogShare { throw error } catch (error: Exception) { if (!stage.isDirectory || !stage.canWrite()) throw StageUnavailableException(error) - return Record(candidate.entry, candidate.origin, "error", reason = error.javaClass.simpleName) + val reportedError = (error as? SourceReadException)?.cause ?: error + return Record(candidate.entry, candidate.origin, "error", reason = reportedError.javaClass.simpleName) } ?: return Record(candidate.entry, candidate.origin, "omitted", reason = "unsafe-or-unavailable-source") if (snapshot.file.length() == 0L && candidate.linePrefix != null) { snapshot.file.delete() @@ -369,27 +372,33 @@ internal object EnhancedSessionLogShare { try { val relative = rootPath.relativize(sourcePath) return withSecureChannel(rootPath, relative) { input -> - val size = input.size() + val size = readSource { input.size() } candidate.linePrefix?.let { prefix -> val truncated = filterChannel(input, target, prefix, size, TRACE_SCAN_BYTES, limit) return@withSecureChannel Snapshot(target, size, truncated) } - FileOutputStream(target).channel.use { output -> - if (size <= limit) { - copy(input, output, 0, size) - } else { - val marker = "\n<diagnostic file truncated: beginning and tail retained>\n".toByteArray() - val content = (limit - marker.size).coerceAtLeast(0) - copyCompleteHead(input, output, content / 2) - val markerBytes = minOf(marker.size.toLong(), limit - output.position()).toInt() - output.write(ByteBuffer.wrap(marker, 0, markerBytes)) - copyCompleteTail(input, output, size, (limit - output.position()).coerceAtLeast(0)) + writeStage { + FileOutputStream(target).channel.use { output -> + if (size <= limit) { + copy(input, output, 0, size) + } else { + val marker = "\n<diagnostic file truncated: beginning and tail retained>\n".toByteArray() + val content = (limit - marker.size).coerceAtLeast(0) + copyCompleteHead(input, output, content / 2) + val markerBytes = minOf(marker.size.toLong(), limit - output.position()).toInt() + output.write(ByteBuffer.wrap(marker, 0, markerBytes)) + copyCompleteTail(input, output, size, (limit - output.position()).coerceAtLeast(0)) + } + output.force(false) } - output.force(false) } Snapshot(target, size, size > limit) } ?: target.delete().let { null } } catch (e: Exception) { + if (e is StageUnavailableException) { + target.delete() + throw e + } val targetWasPresent = target.exists() target.delete() if (!stage.isDirectory || !stage.canWrite() || !targetWasPresent) throw StageUnavailableException(e) @@ -408,48 +417,51 @@ internal object EnhancedSessionLogShare { val wanted = prefix.toByteArray() var written = 0L var truncated = sourceSize > scanLimit - target.outputStream().buffered().use { output -> - fun scan(start: Long, count: Long, discardPartialFirstLine: Boolean) { - channel.position(start) - val input = BufferedInputStream(Channels.newInputStream(channel), COPY_BUFFER_BYTES) - val line = ByteArrayOutputStream(1024) - var oversized = false - var scanned = 0L - var discard = discardPartialFirstLine - fun emit() { - val bytes = line.toByteArray() - if (!discard && !oversized && bytes.size >= wanted.size && wanted.indices.all { bytes[it] == wanted[it] }) { - if (written + bytes.size + 1 <= outputLimit) { - output.write(bytes) - output.write('\n'.code) - written += bytes.size + 1 - } else truncated = true + writeStage { + target.outputStream().buffered().use { output -> + fun scan(start: Long, count: Long, discardPartialFirstLine: Boolean) { + readSource { channel.position(start) } + val input = BufferedInputStream(Channels.newInputStream(channel), COPY_BUFFER_BYTES) + val line = ByteArrayOutputStream(1024) + var oversized = false + var scanned = 0L + var discard = discardPartialFirstLine + fun emit() { + val bytes = line.toByteArray() + if (!discard && !oversized && bytes.size >= wanted.size && wanted.indices.all { bytes[it] == wanted[it] }) { + if (written + bytes.size + 1 <= outputLimit) { + output.write(bytes) + output.write('\n'.code) + written += bytes.size + 1 + } else truncated = true + } + line.reset() + oversized = false + discard = false } - line.reset() - oversized = false - discard = false - } - while (scanned < count) { - val value = input.read() - if (value < 0) break - scanned++ - if (value == '\n'.code) emit() - else if (!oversized && !discard) { - if (line.size() >= LogRedactor.MAX_LINE_LENGTH) { - oversized = true - line.reset() - } else line.write(value) + while (scanned < count) { + val value = readSource { input.read() } + if (value < 0) break + scanned++ + if (value == '\n'.code) emit() + else if (!oversized && !discard) { + if (line.size() >= LogRedactor.MAX_LINE_LENGTH) { + oversized = true + line.reset() + } else line.write(value) + } } + if (start + scanned >= sourceSize && (line.size() > 0 || oversized)) emit() + } + + if (sourceSize <= scanLimit) { + scan(0, sourceSize, false) + } else { + val head = scanLimit / 2 + val tail = scanLimit - head + scan(0, head, false) + scan((sourceSize - tail).coerceAtLeast(0), tail, true) } - if (start + scanned >= sourceSize && (line.size() > 0 || oversized)) emit() - } - if (sourceSize <= scanLimit) { - scan(0, sourceSize, false) - } else { - val head = scanLimit / 2 - val tail = scanLimit - head - scan(0, head, false) - scan((sourceSize - tail).coerceAtLeast(0), tail, true) } } return truncated @@ -462,6 +474,7 @@ internal object EnhancedSessionLogShare { private fun <T> withAndroidSecureChannel(root: Path, relative: Path, block: (SeekableByteChannel) -> T): T? { val opened = ArrayList<ParcelFileDescriptor>() + var invokingBlock = false return try { val parts = relative.map { it.toString() } if (parts.isEmpty()) return null @@ -474,11 +487,15 @@ internal object EnhancedSessionLogShare { val stat = Os.fstat(leafFd) if (!OsConstants.S_ISREG(stat.st_mode) || stat.st_nlink != 1L) return null // Android's FileInputStream(FileDescriptor) is deliberately not the descriptor owner. - FileInputStream(leafFd).use { stream -> block(stream.channel) } + FileInputStream(leafFd).use { stream -> + invokingBlock = true + block(stream.channel) + } } finally { runCatching { Os.close(leafFd) } } - } catch (_: Exception) { + } catch (error: Exception) { + if (invokingBlock) throw error null } finally { opened.asReversed().forEach { runCatching { it.close() } } @@ -507,16 +524,16 @@ internal object EnhancedSessionLogShare { "/proc/self/fd/${directory.fd}/$name" private fun copy(input: SeekableByteChannel, output: FileChannel, start: Long, count: Long) { - input.position(start) + readSource { input.position(start) } var left = count val buffer = ByteBuffer.allocate(64 * 1024) while (left > 0) { buffer.clear() buffer.limit(minOf(buffer.capacity().toLong(), left).toInt()) - val read = input.read(buffer) + val read = readSource { input.read(buffer) } if (read < 0) break buffer.flip() - while (buffer.hasRemaining()) output.write(buffer) + while (buffer.hasRemaining()) writeStage { output.write(buffer) } left -= read } } @@ -525,14 +542,14 @@ internal object EnhancedSessionLogShare { if (limit <= 0) return copy(input, output, 0, limit) val copied = output.position() - input.position(0) + readSource { input.position(0) } val buffer = ByteBuffer.allocate(64 * 1024) var scanned = 0L var lastComplete = 0L while (scanned < copied) { buffer.clear() buffer.limit(minOf(buffer.capacity().toLong(), copied - scanned).toInt()) - val read = input.read(buffer) + val read = readSource { input.read(buffer) } if (read < 0) break buffer.flip() repeat(read) { index -> @@ -540,8 +557,8 @@ internal object EnhancedSessionLogShare { } scanned += read } - output.truncate(lastComplete) - output.position(lastComplete) + writeStage { output.truncate(lastComplete) } + writeStage { output.position(lastComplete) } } private fun copyCompleteTail( @@ -553,10 +570,10 @@ internal object EnhancedSessionLogShare { if (limit <= 0 || sourceSize <= 0) return var start = (sourceSize - limit).coerceAtLeast(0) if (start > 0) { - input.position(start) + readSource { input.position(start) } val buffered = BufferedInputStream(Channels.newInputStream(input), COPY_BUFFER_BYTES) while (start < sourceSize) { - val value = buffered.read() + val value = readSource { buffered.read() } if (value < 0) return start++ if (value == '\n'.code) break @@ -565,6 +582,22 @@ internal object EnhancedSessionLogShare { copy(input, output, start, (sourceSize - start).coerceAtMost(limit)) } + private inline fun <T> readSource(block: () -> T): T = try { + block() + } catch (error: Exception) { + throw SourceReadException(error) + } + + private inline fun <T> writeStage(block: () -> T): T = try { + block() + } catch (error: SourceReadException) { + throw error + } catch (error: StageUnavailableException) { + throw error + } catch (error: Exception) { + throw StageUnavailableException(error) + } + private fun addManifest( archive: ZipOutputStream, sessionId: String, diff --git a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt index 4a90858070..f9fea7c9b0 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt @@ -507,7 +507,11 @@ class EnhancedSessionLogShareTest { root: java.nio.file.Path, relative: java.nio.file.Path, block: (java.nio.channels.SeekableByteChannel) -> T, - ): T? = throw IOException("injected source read failure") + ): T? = FileChannel.open(root.resolve(relative), StandardOpenOption.READ).use { channel -> + block(object : SeekableByteChannel by channel { + override fun read(dst: ByteBuffer): Int = throw IOException("injected source read failure") + }) + } }) try { val sessionZip = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-session.zip") } From 604a01d3539b0bab1b57c15c1386b15e8fc7ce4e Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 15:41:47 -0500 Subject: [PATCH 68/85] fix: map log destination errors --- tools/droiddeckctl | 5 ++++- tools/tests/test_droiddeckctl.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 02fe7020c8..65fb274cef 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -425,7 +425,10 @@ def start_session(adb: str, serial: str, request: dict) -> dict: def unpack_logs(archive: Path, destination: Path, session_id: str) -> None: """Unpack a Share logs zip so the session's own files sit at the top of destination.""" destination = destination.resolve() - destination.mkdir(parents=True, exist_ok=True) + try: + destination.mkdir(parents=True, exist_ok=True) + except OSError as exc: + raise ControlError(f"Could not unpack the session logs: {exc}", "LOG_PULL_FAILED") from exc manifest = destination / ".droiddeckctl-managed-logs.json" try: previous = json.loads(manifest.read_text(encoding="utf-8")) diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 531bcd8913..731e3aa38c 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -610,6 +610,23 @@ class DroiddeckctlTest(FakeAdbTest): self.assertFalse((destination / "steam/console.log").exists()) self.assertEqual("keep me", (destination / "notes.txt").read_text()) + def test_logs_map_destination_creation_failure_to_pull_error(self): + destination = (self.dir / "artifacts").resolve() + archive = self.dir / "logs.zip" + real_mkdir = Path.mkdir + + def fail_destination(path, *args, **kwargs): + if path == destination: + raise PermissionError("injected destination failure") + return real_mkdir(path, *args, **kwargs) + + with unittest.mock.patch.object(Path, "mkdir", new=fail_destination): + with self.assertRaises(ctl.ControlError) as raised: + ctl.unpack_logs(archive, destination, "s1") + + self.assertEqual("LOG_PULL_FAILED", raised.exception.code) + self.assertIn("injected destination failure", str(raised.exception)) + def test_logs_do_not_follow_a_stale_managed_symlink(self): if os.name == "nt": self.skipTest("symlink creation is unavailable on this Windows host") From da851dae22475c0e3c4acc63f29f86c9823a12bd Mon Sep 17 00:00:00 2001 From: MaxsTechReview <maxjividen@gmail.com> Date: Thu, 5 Nov 2026 16:29:19 -0500 Subject: [PATCH 69/85] fix(input): taps land where touched while a game holds the pointer (#2133) * fix(input): taps land where touched while a game holds the pointer Games that hide the system cursor and draw their own, such as Stardew Valley, hold the pointer the same way first-person games do. Every touch on the default touch mode then went through the touchpad, so a tap clicked wherever the cursor already was: tapping New opened Load, and a tap after Back could press Exit. A touch now stays a direct touch while the pointer is held. A tap clicks where the finger is, and once a swipe moves past the touch slop it turns the camera with relative motion as before. Touchpad mode is unchanged. * fix(input): keep the swipe anchor when the first finger lifts When the first finger of a locked-pointer swipe lifts and another stays down, the next move is reported for the remaining finger. The anchor now moves to that finger, so the camera does not jump. --- .../com/droiddeck/launcher/SessionActivity.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index c5e36438e7..01206389c3 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -740,6 +740,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { .also { root.addView(it) } touchpad = TouchpadGestures(PointerGestures.slop(this), pointerListener) directTouchHold = DirectTouchHold(PointerGestures.slop(this), pointerListener, directTouchSink) + touchSlop = PointerGestures.slop(this) threeFingerTap = com.droiddeck.launcher.input.ThreeFingerTap(PointerGestures.slop(this) * 2) twoFingerGestures = com.droiddeck.launcher.input.TwoFingerGestures(PointerGestures.slop(this) * 2, object : com.droiddeck.launcher.input.TwoFingerGestures.Listener { @@ -3694,9 +3695,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } private var ignoreGameTouch = false - private var lockedTouchTurns = false private var touchEditorOpen by mutableStateOf(false) private var lockedSwipeUsed = false + private var touchSlop = 0f private var lockedSwipeX = 0f private var lockedSwipeY = 0f private var dismissTouch = false @@ -3741,15 +3742,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } com.droiddeck.launcher.input.TouchRouter.Route.SCROLL -> scrollTouch.onTouch(event) else -> { - if (event.actionMasked == MotionEvent.ACTION_DOWN) { - val inPicture = drawnRect()?.let { !topPictureMapped || it.contains(event.x, event.y) } ?: false - lockedTouchTurns = programLocksPointer() && inPicture && route != com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD - } if (com.droiddeck.launcher.input.TouchRouter.steamKeyboardZone(snapshot)) { val wasActive = threeFingerTap.active if (threeFingerTap.onTouch(event)) padBridge?.triggerSteamKeyboard() if (threeFingerTap.active && !wasActive) { - if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD || lockedTouchTurns) touchpad.cancel() + if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD) touchpad.cancel() else { directTouchHold.cancel() WaylandCompositor.nativeSendTouch(3, -1, 0, 0) @@ -3757,7 +3754,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } if (threeFingerTap.active || wasActive) return true } - if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD || lockedTouchTurns) { + if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD) { val rect = drawnRect() ?: return false if (touchpad.bounds != rect) { val fresh = touchpad.bounds.width() <= 1f @@ -3811,8 +3808,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private fun forwardTouch(event: MotionEvent, rect: android.graphics.RectF): Boolean { val swipeX = lockedSwipeX val swipeY = lockedSwipeY - lockedSwipeX = event.x - lockedSwipeY = event.y + if (programLocksPointer() && event.actionMasked == MotionEvent.ACTION_MOVE && !lockedSwipeUsed && + abs(event.x - swipeX) <= touchSlop && abs(event.y - swipeY) <= touchSlop) return true + val anchor = if (event.actionMasked == MotionEvent.ACTION_POINTER_UP && event.actionIndex == 0 && event.pointerCount > 1) 1 else 0 + lockedSwipeX = event.getX(anchor) + lockedSwipeY = event.getY(anchor) if ((event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) && lockedSwipeUsed) { lockedSwipeUsed = false directTouchHold.cancel() From d64205ba5ba83e3a15865283f2a8f5ed62a89686 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 17:25:54 -0500 Subject: [PATCH 70/85] fix: report Vulkan memory budgets without rejecting allocations (#2014) Extend the VRAM setting to Vulkan memory-budget reports for DXVK and D3D12 while preserving real heap capacity and allocation results, removing the hard rejection that caused game crashes in FIT and Discord tests. --- .../launcher/session/SessionFiles.kt | 2 + app/src/main/res/values-ar/strings.xml | 2 +- app/src/main/res/values-b+es+419/strings.xml | 2 +- app/src/main/res/values-bg/strings.xml | 2 +- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values-da/strings.xml | 2 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-el/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fi/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-hi/strings.xml | 2 +- app/src/main/res/values-hu/strings.xml | 2 +- app/src/main/res/values-in/strings.xml | 2 +- app/src/main/res/values-ja/strings.xml | 2 +- app/src/main/res/values-ko/strings.xml | 2 +- app/src/main/res/values-ms/strings.xml | 2 +- app/src/main/res/values-nb/strings.xml | 2 +- app/src/main/res/values-nl/strings.xml | 2 +- app/src/main/res/values-pl/strings.xml | 2 +- app/src/main/res/values-pt-rPT/strings.xml | 2 +- app/src/main/res/values-pt/strings.xml | 2 +- app/src/main/res/values-ro/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values-sv/strings.xml | 2 +- app/src/main/res/values-th/strings.xml | 2 +- app/src/main/res/values-tr/strings.xml | 2 +- app/src/main/res/values-uk/strings.xml | 2 +- app/src/main/res/values-vi/strings.xml | 2 +- app/src/main/res/values-zh-rCN/strings.xml | 2 +- app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- docs/development/vram-budget.md | 20 ++ tools/components/recipes.json | 3 +- tools/gpuload/build.sh | 14 +- .../layer/VK_LAYER_DROIDDECK_vram_cap.json | 20 ++ .../gpuload/src/vk_layer_droiddeck_vramcap.c | 206 ++++++++++++++++++ tools/gpuload/src/vramcap_budget.h | 32 +++ tools/gpuload/tests/test_vramcap_budget.c | 154 +++++++++++++ .../overlay/usr/local/bin/droiddeck-game-env | 2 + tools/release/runtime_inputs.py | 3 +- tools/tests/test_game_environment.py | 6 + 43 files changed, 488 insertions(+), 38 deletions(-) create mode 100644 docs/development/vram-budget.md create mode 100644 tools/gpuload/layer/VK_LAYER_DROIDDECK_vram_cap.json create mode 100644 tools/gpuload/src/vk_layer_droiddeck_vramcap.c create mode 100644 tools/gpuload/src/vramcap_budget.h create mode 100644 tools/gpuload/tests/test_vramcap_budget.c diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index ca9cafcabf..b65f3ac725 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -165,6 +165,8 @@ object SessionFiles { val gpuLoad = listOf( "usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_gpuload.so" to "usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_gpuload.so", "usr/local/lib/droiddeck-gpuload/VK_LAYER_DROIDDECK_gpu_load.json" to "usr/share/vulkan/implicit_layer.d/droiddeck_gpu_load.json", + "usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_vramcap.so" to "usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_vramcap.so", + "usr/local/lib/droiddeck-gpuload/VK_LAYER_DROIDDECK_vram_cap.json" to "usr/share/vulkan/implicit_layer.d/droiddeck_vram_cap.json", ) val fexPreloads = listOf("x86_64", "i386").flatMap { arch -> listOf("libblsession.so", "libfakeinput.so", "libfaultreport.so").map { "$arch/$it" to "usr/local/lib/droiddeck-fex/$arch/$it" } diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 7b9a17ca71..d0222536cd 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -593,7 +593,7 @@ <string name="perf_ram_cap_hint">يُطبَّق أثناء تشغيل عميل Steam، في جلسة Steam أو من سطح المكتب. عندما تستخدم الجلسة أكثر من هذا الحد، يُضغط Steam ثم عمليات الجلسة المدعومة الأخرى في zRAM. حد مرن: لا يُغلَق شيء، لكن قد تتقطّع الألعاب أثناء استعادة الصفحات.</string> <string name="perf_ram_cap_unavailable">يتطلب مساحة تبديل zRAM، وهي غير متوفرة على هذا الجهاز.</string> <string name="perf_vram_cap">حد VRAM</string> - <string name="perf_vram_cap_hint">ذاكرة الفيديو التي يُبلغ بها DXVK ألعاب Direct3D، فتخصّص للأنسجة مساحة أقل. تظل إعدادات DXVK الخاصة باللعبة هي الأولى. يسري في الجلسة التالية.</string> + <string name="perf_vram_cap_hint">يُبلّغ ألعاب Direct3D من 9 إلى 12 بميزانية ذاكرة الفيديو هذه لتشجيع تقليل استخدامها. قد تتجاوزها الألعاب؛ لا يضيف هذا ترحيل ذاكرة GPU ولا يضمن منع الانهيار بسبب نفاد الذاكرة. يسري في الجلسة التالية.</string> <string name="perf_gpuclock">تثبيت GPU على أعلى تردد له</string> <string name="perf_gpuclock_hint">لـ Adreno فقط. تقطّع أقل، مع استهلاك أكبر للبطارية والحرارة.</string> <string name="perf_fixes">إصلاحات الجلسة</string> diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index eff6652271..e89919b32b 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -587,7 +587,7 @@ <string name="perf_ram_cap_hint">Se aplica mientras se ejecuta el cliente de Steam, en modo Steam o desde el escritorio. Cuando la sesión usa más de esto, Steam y luego los demás procesos compatibles de la sesión se comprimen en zRAM. Es un límite flexible: no se cierra nada, pero los juegos pueden tener microcortes mientras se recuperan las páginas.</string> <string name="perf_ram_cap_unavailable">Requiere swap de zRAM, y este dispositivo no lo tiene.</string> <string name="perf_vram_cap">Límite de VRAM</string> - <string name="perf_vram_cap_hint">La memoria de video que DXVK informa a los juegos Direct3D, para que calculen sus texturas con menos. Los ajustes de DXVK propios de un juego siguen teniendo prioridad. Se aplica en la próxima sesión.</string> + <string name="perf_vram_cap_hint">Informa a los juegos Direct3D 9 a 12 de este presupuesto de memoria de video para reducir su uso. Los juegos pueden superarlo; no agrega paginación de GPU ni garantiza evitar fallos por falta de memoria. Se aplica en la próxima sesión.</string> <string name="perf_gpuclock">Mantener la GPU a su reloj máximo</string> <string name="perf_gpuclock_hint">Solo Adreno. Menos microcortes, más consumo de batería y calor.</string> <string name="perf_fixes">Correcciones de sesión</string> diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 1b17dcbb18..3087a2ccaf 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Прилага се, докато клиентът на Steam работи, в режим Steam или от работния плот. Когато сесията използва повече от това, Steam и след това другите поддържани процеси на сесията се компресират в zRAM. Меко ограничение: нищо не се затваря, но игрите може да засичат, докато страниците се връщат.</string> <string name="perf_ram_cap_unavailable">Изисква zRAM swap, който това устройство няма.</string> <string name="perf_vram_cap">Ограничение на VRAM</string> - <string name="perf_vram_cap_hint">Видеопаметта, която DXVK отчита на игрите с Direct3D, за да планират текстури за по-малко. Собствените настройки на DXVK на играта имат предимство. Прилага се от следващата сесия.</string> + <string name="perf_vram_cap_hint">Съобщава този бюджет за видео памет на игри с Direct3D 9 до 12, за да намали използването на памет. Игрите може да го надвишат; това не добавя странициране на GPU и не гарантира защита от сривове при недостиг на памет. Прилага се от следващата сесия.</string> <string name="perf_gpuclock">Задръжте GPU на максималната му честота</string> <string name="perf_gpuclock_hint">Само за Adreno. По-малко засечки, по-голямо използване на батерията и повече топлина.</string> <string name="perf_fixes">Корекции на сесията</string> diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 58616db345..6d60588137 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -589,7 +589,7 @@ <string name="perf_ram_cap_hint">Platí, když běží klient Steam, v režimu Steam nebo z Plochy. Když relace použije víc, zkomprimuje se do zRAM Steam a poté další podporované procesy relace. Měkký limit: nic se nezavře, ale hry mohou trhat, než se stránky načtou zpět.</string> <string name="perf_ram_cap_unavailable">Vyžaduje swap zRAM, který toto zařízení nemá.</string> <string name="perf_vram_cap">Limit VRAM</string> - <string name="perf_vram_cap_hint">Video paměť, kterou DXVK hlásí hrám Direct3D, aby počítaly s menším rozpočtem na textury. Vlastní nastavení DXVK hry mají přednost. Použije se od příští relace.</string> + <string name="perf_vram_cap_hint">Hlásí hrám s Direct3D 9 až 12 tento rozpočet videopaměti, aby snížily její využití. Hry jej mohou překročit; nepřidává stránkování GPU ani nezaručuje ochranu před pády kvůli nedostatku paměti. Platí od příští relace.</string> <string name="perf_gpuclock">Udržet GPU na nejvyšších taktech</string> <string name="perf_gpuclock_hint">Jen Adreno. Méně zadrhávání, více spotřeby baterie a tepla.</string> <string name="perf_fixes">Opravy relace</string> diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 36e87a79eb..191c15c7b9 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Gælder, mens Steam-klienten kører, i Steam-tilstand eller fra skrivebordet. Når sessionen bruger mere end dette, komprimeres Steam og derefter sessionens andre understøttede processer i zRAM. En blød grænse: intet lukkes, men spil kan hakke, mens sider hentes tilbage.</string> <string name="perf_ram_cap_unavailable">Kræver zRAM-swap, som denne enhed ikke har.</string> <string name="perf_vram_cap">VRAM-grænse</string> - <string name="perf_vram_cap_hint">Den videohukommelse, DXVK rapporterer til Direct3D-spil, så de budgetterer teksturer til mindre. Et spils egne DXVK-indstillinger har forrang. Træder i kraft ved næste session.</string> + <string name="perf_vram_cap_hint">Rapporterer dette videohukommelsesbudget til Direct3D 9 til 12-spil for at mindske hukommelsesforbruget. Spil kan overskride det; dette tilføjer ikke GPU-paging og garanterer ikke beskyttelse mod nedbrud ved hukommelsesmangel. Gælder fra næste session.</string> <string name="perf_gpuclock">Hold GPU’en på dens højeste clock</string> <string name="perf_gpuclock_hint">Kun Adreno. Færre hak, mere batteribrug og varme.</string> <string name="perf_fixes">Sessionsrettelser</string> diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 37c35d3f13..200e8e242a 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Gilt, solange der Steam-Client läuft, im Steam-Modus oder vom Desktop aus. Verbraucht die Sitzung mehr als diesen Wert, werden Steam und danach die übrigen unterstützten Prozesse der Sitzung in zRAM komprimiert. Ein weiches Limit: Nichts wird geschlossen, aber Spiele können ruckeln, während Seiten zurückgeladen werden.</string> <string name="perf_ram_cap_unavailable">Benötigt zRAM-Swap, den dieses Gerät nicht hat.</string> <string name="perf_vram_cap">VRAM-Limit</string> - <string name="perf_vram_cap_hint">Der Grafikspeicher, den DXVK an Direct3D-Spiele meldet, damit sie weniger für Texturen einplanen. Eigene DXVK-Einstellungen eines Spiels haben Vorrang. Gilt ab der nächsten Sitzung.</string> + <string name="perf_vram_cap_hint">Meldet Direct3D-9-bis-12-Spielen dieses Videospeicherbudget, um den Speicherverbrauch zu senken. Spiele können es überschreiten; dies fügt kein GPU-Paging hinzu und garantiert keinen Schutz vor Abstürzen durch Speichermangel. Gilt ab der nächsten Sitzung.</string> <string name="perf_gpuclock">GPU auf höchstem Takt halten</string> <string name="perf_gpuclock_hint">Nur Adreno. Weniger Ruckler, mehr Akkuverbrauch und Wärme.</string> <string name="perf_fixes">Sitzungskorrekturen</string> diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 25c7c40d78..d8a9e8d13a 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Ισχύει όσο τρέχει ο πελάτης Steam, σε λειτουργία Steam ή από την επιφάνεια εργασίας. Όταν η συνεδρία χρησιμοποιεί περισσότερη, το Steam και έπειτα οι άλλες υποστηριζόμενες διεργασίες της συνεδρίας συμπιέζονται στη zRAM. Ήπιο όριο: τίποτα δεν κλείνει, αλλά τα παιχνίδια μπορεί να κολλάνε όσο επιστρέφουν οι σελίδες.</string> <string name="perf_ram_cap_unavailable">Απαιτεί zRAM swap, που δεν υπάρχει σε αυτή τη συσκευή.</string> <string name="perf_vram_cap">Όριο VRAM</string> - <string name="perf_vram_cap_hint">Η μνήμη βίντεο που αναφέρει το DXVK στα παιχνίδια Direct3D, ώστε να προγραμματίζουν υφές για λιγότερη. Οι δικές ρυθμίσεις DXVK του παιχνιδιού υπερισχύουν. Εφαρμόζεται στην επόμενη συνεδρία.</string> + <string name="perf_vram_cap_hint">Αναφέρει αυτόν τον προϋπολογισμό μνήμης βίντεο σε παιχνίδια Direct3D 9 έως 12 για να μειωθεί η χρήση μνήμης. Τα παιχνίδια μπορεί να τον υπερβούν· δεν προσθέτει σελιδοποίηση GPU ούτε εγγυάται προστασία από σφάλματα έλλειψης μνήμης. Ισχύει από την επόμενη συνεδρία.</string> <string name="perf_gpuclock">Διατήρηση της GPU στη μέγιστη συχνότητά της</string> <string name="perf_gpuclock_hint">Μόνο Adreno. Λιγότερα κολλήματα, μεγαλύτερη χρήση μπαταρίας και θερμότητα.</string> <string name="perf_fixes">Διορθώσεις συνεδρίας</string> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 9f09dd2e9e..ae6cda5572 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -587,7 +587,7 @@ <string name="perf_ram_cap_hint">Se aplica mientras se ejecuta el cliente de Steam, en modo Steam o desde el escritorio. Cuando la sesión usa más de esto, Steam y luego los demás procesos compatibles de la sesión se comprimen en zRAM. Es un límite flexible: no se cierra nada, pero los juegos pueden tener tirones mientras se recuperan las páginas.</string> <string name="perf_ram_cap_unavailable">Requiere swap de zRAM, y este dispositivo no lo tiene.</string> <string name="perf_vram_cap">Límite de VRAM</string> - <string name="perf_vram_cap_hint">La memoria de vídeo que DXVK indica a los juegos Direct3D, para que calculen sus texturas con menos. Los ajustes de DXVK propios de un juego siguen teniendo prioridad. Se aplica en la próxima sesión.</string> + <string name="perf_vram_cap_hint">Informa a los juegos Direct3D 9 a 12 de este presupuesto de memoria de vídeo para reducir su uso. Los juegos pueden superarlo; no añade paginación de GPU ni garantiza evitar fallos por falta de memoria. Se aplica en la próxima sesión.</string> <string name="perf_gpuclock">Mantener la GPU a su reloj máximo</string> <string name="perf_gpuclock_hint">Solo Adreno. Menos tirones, más consumo de batería y calor.</string> <string name="perf_fixes">Correcciones de sesión</string> diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 2bab8a4f84..b96591b1cf 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Koskee aikaa, jolloin Steam-asiakasohjelma on käynnissä, Steam-tilassa tai työpöydältä. Kun istunto käyttää tätä enemmän, Steam ja sen jälkeen istunnon muut tuetut prosessit pakataan zRAMiin. Pehmeä raja: mitään ei suljeta, mutta pelit voivat nykiä, kun sivuja luetaan takaisin.</string> <string name="perf_ram_cap_unavailable">Vaatii zRAM-swapin, jota tässä laitteessa ei ole.</string> <string name="perf_vram_cap">VRAM-raja</string> - <string name="perf_vram_cap_hint">Videomuisti, jonka DXVK ilmoittaa Direct3D-peleille, jotta ne mitoittavat tekstuurit pienemmälle. Pelin omat DXVK-asetukset menevät edelle. Tulee voimaan seuraavassa istunnossa.</string> + <string name="perf_vram_cap_hint">Ilmoittaa tämän videomuistibudjetin Direct3D 9–12 -peleille muistin käytön vähentämiseksi. Pelit voivat ylittää sen; tämä ei lisää GPU-sivutusta eikä takaa suojaa muistin loppumisesta johtuvilta kaatumisilta. Tulee voimaan seuraavassa istunnossa.</string> <string name="perf_gpuclock">Pidä GPU huippukellotaajuudessaan</string> <string name="perf_gpuclock_hint">Vain Adreno. Vähemmän nykäyksiä, enemmän akun kulutusta ja lämpöä.</string> <string name="perf_fixes">Istunnon korjaukset</string> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 6b20807dd2..2b71aeadd4 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -587,7 +587,7 @@ <string name="perf_ram_cap_hint">S\'applique tant que le client Steam fonctionne, en mode Steam ou depuis le bureau. Lorsque la session dépasse cette valeur, Steam puis les autres processus pris en charge de la session sont compressés dans zRAM. Limite souple : rien n\'est fermé, mais les jeux peuvent saccader pendant le rechargement des pages.</string> <string name="perf_ram_cap_unavailable">Nécessite un swap zRAM, dont cet appareil ne dispose pas.</string> <string name="perf_vram_cap">Limite de VRAM</string> - <string name="perf_vram_cap_hint">La mémoire vidéo que DXVK signale aux jeux Direct3D, pour qu\'ils prévoient moins de textures. Les paramètres DXVK propres à un jeu restent prioritaires. Prendra effet à la prochaine session.</string> + <string name="perf_vram_cap_hint">Signale ce budget de mémoire vidéo aux jeux Direct3D 9 à 12 pour réduire leur consommation. Les jeux peuvent le dépasser ; cela ne fournit pas de pagination GPU et ne garantit pas une protection contre les plantages par manque de mémoire. Prend effet à la prochaine session.</string> <string name="perf_gpuclock">Maintenir le GPU à sa fréquence maximale</string> <string name="perf_gpuclock_hint">Uniquement pour Adreno. Moins de saccades, mais plus de consommation d\'énergie et de chaleur.</string> <string name="perf_fixes">Correctifs de session</string> diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index ad4934b347..f039dd0221 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Steam क्लाइंट चलते समय लागू होती है, Steam मोड में या डेस्कटॉप से। जब सेशन इससे ज़्यादा इस्तेमाल करता है, तो Steam और फिर सेशन की दूसरी समर्थित प्रोसेस zRAM में कंप्रेस होती हैं। यह सॉफ़्ट सीमा है: कुछ बंद नहीं होता, लेकिन पेज वापस आते समय गेम अटक सकते हैं।</string> <string name="perf_ram_cap_unavailable">zRAM स्वैप चाहिए, जो इस डिवाइस में नहीं है।</string> <string name="perf_vram_cap">VRAM सीमा</string> - <string name="perf_vram_cap_hint">वह वीडियो मेमोरी जो DXVK, Direct3D गेम को बताता है, ताकि वे टेक्सचर के लिए कम बजट रखें। गेम की अपनी DXVK सेटिंग को प्राथमिकता मिलती है। अगले सेशन से लागू होता है।</string> + <string name="perf_vram_cap_hint">मेमोरी का उपयोग कम करने के लिए Direct3D 9 से 12 गेम को यह वीडियो मेमोरी बजट बताता है। गेम इसे पार कर सकते हैं; यह GPU पेजिंग नहीं जोड़ता और मेमोरी खत्म होने से क्रैश रोकने की गारंटी नहीं देता। अगले सत्र से लागू होगा।</string> <string name="perf_gpuclock">GPU को उसकी टॉप क्लॉक पर बनाए रखें</string> <string name="perf_gpuclock_hint">सिर्फ़ Adreno के लिए। कम हिचकोले, लेकिन ज़्यादा बैटरी खर्च और गर्मी।</string> <string name="perf_fixes">सेशन फ़िक्स</string> diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index f1559e0f18..bfa3f5f5a6 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Akkor érvényes, amikor a Steam-kliens fut, Steam módban vagy az asztalról. Ha a munkamenet ennél többet használ, a Steam, majd a munkamenet többi támogatott folyamata a zRAM-ba tömörül. Puha korlát: semmi sem zárul be, de a játékok akadhatnak, amíg a lapok visszatöltődnek.</string> <string name="perf_ram_cap_unavailable">zRAM swap szükséges, amely ezen az eszközön nincs.</string> <string name="perf_vram_cap">VRAM-korlát</string> - <string name="perf_vram_cap_hint">A DXVK által a Direct3D-játékoknak jelentett videomemória, így azok kevesebbel számolnak a textúráknál. A játék saját DXVK-beállításai elsőbbséget élveznek. A következő munkamenettől érvényes.</string> + <string name="perf_vram_cap_hint">Ezt a videomemória-keretet jelzi a Direct3D 9–12 játékoknak a memóriahasználat csökkentésére. A játékok túlléphetik; nem biztosít GPU-lapozást, és nem garantál védelmet a memóriahiány miatti összeomlás ellen. A következő munkamenettől érvényes.</string> <string name="perf_gpuclock">A GPU legmagasabb órajelen tartása</string> <string name="perf_gpuclock_hint">Csak Adreno. Kevesebb akadás, nagyobb akkumulátorhasználat és hőtermelés.</string> <string name="perf_fixes">Munkamenet-javítások</string> diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 4f07311840..9027200239 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -583,7 +583,7 @@ <string name="perf_ram_cap_hint">Berlaku saat klien Steam berjalan, di mode Steam atau dari desktop. Saat sesi menggunakan lebih dari ini, Steam lalu proses lain yang didukung dalam sesi dikompres ke zRAM. Batas lunak: tidak ada yang ditutup, tetapi gim dapat tersendat saat halaman dimuat kembali.</string> <string name="perf_ram_cap_unavailable">Memerlukan swap zRAM, yang tidak dimiliki perangkat ini.</string> <string name="perf_vram_cap">Batas VRAM</string> - <string name="perf_vram_cap_hint">Memori video yang dilaporkan DXVK ke gim Direct3D, sehingga gim menganggarkan tekstur lebih sedikit. Setelan DXVK milik gim tetap diutamakan. Berlaku pada sesi berikutnya.</string> + <string name="perf_vram_cap_hint">Melaporkan anggaran memori video ini ke game Direct3D 9 hingga 12 untuk mengurangi penggunaan memori. Game dapat melampauinya; ini tidak menambahkan paging GPU atau menjamin perlindungan dari crash akibat kehabisan memori. Berlaku pada sesi berikutnya.</string> <string name="perf_gpuclock">Pertahankan GPU pada clock tertingginya</string> <string name="perf_gpuclock_hint">Hanya Adreno. Lebih sedikit tersendat, lebih banyak penggunaan baterai dan panas.</string> <string name="perf_fixes">Perbaikan sesi</string> diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 23339bd24c..1015207fe9 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -583,7 +583,7 @@ <string name="perf_ram_cap_hint">Steamモードでもデスクトップからでも、Steamクライアントの実行中に適用されます。セッションの使用量がこの値を超えると、Steam、次にセッション内の対応する他のプロセスがzRAMに圧縮されます。ソフトな上限のため何も終了されませんが、ページの読み戻し中にゲームがカクつくことがあります。</string> <string name="perf_ram_cap_unavailable">zRAMスワップが必要ですが、このデバイスにはありません。</string> <string name="perf_vram_cap">VRAM上限</string> - <string name="perf_vram_cap_hint">DXVKがDirect3Dゲームに報告するビデオメモリ量です。ゲームはこれに合わせてテクスチャ量を抑えます。ゲーム独自のDXVK設定が優先されます。次回のセッションから有効になります。</string> + <string name="perf_vram_cap_hint">Direct3D 9~12のゲームにこのビデオメモリ予算を通知し、メモリ使用量の削減を促します。ゲームは予算を超える場合があります。GPUのページングを追加するものではなく、メモリ不足によるクラッシュの防止は保証されません。次のセッションから有効になります。</string> <string name="perf_gpuclock">GPUを最高クロックに保つ</string> <string name="perf_gpuclock_hint">Adrenoのみ。スタッターは減りますが、消費電力と発熱が増えます。</string> <string name="perf_fixes">セッション修正</string> diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 3f43a0a1c8..09b4273562 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -583,7 +583,7 @@ <string name="perf_ram_cap_hint">Steam 모드나 데스크톱에서 Steam 클라이언트가 실행되는 동안 적용됩니다. 세션이 이 값보다 많이 사용하면 Steam과 세션의 다른 지원 프로세스를 차례로 zRAM으로 압축합니다. 소프트 제한이므로 종료되는 것은 없지만, 페이지를 다시 읽어 들이는 동안 게임이 끊길 수 있습니다.</string> <string name="perf_ram_cap_unavailable">zRAM 스왑이 필요하지만 이 기기에는 없습니다.</string> <string name="perf_vram_cap">VRAM 제한</string> - <string name="perf_vram_cap_hint">DXVK가 Direct3D 게임에 보고하는 비디오 메모리로, 게임이 더 적은 양에 맞춰 텍스처를 할당합니다. 게임 자체의 DXVK 설정이 우선합니다. 다음 세션에 적용됩니다.</string> + <string name="perf_vram_cap_hint">메모리 사용량을 줄이도록 Direct3D 9~12 게임에 이 비디오 메모리 예산을 알립니다. 게임은 예산을 초과할 수 있으며, GPU 페이징을 추가하거나 메모리 부족으로 인한 충돌 방지를 보장하지 않습니다. 다음 세션부터 적용됩니다.</string> <string name="perf_gpuclock">GPU를 최고 클럭으로 유지</string> <string name="perf_gpuclock_hint">Adreno에만 해당됩니다. 끊김이 줄어들지만 전력 소모와 발열이 증가합니다.</string> <string name="perf_fixes">세션 수정</string> diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index b0adb14632..f39b732126 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -583,7 +583,7 @@ <string name="perf_ram_cap_hint">Berkuat kuasa semasa klien Steam berjalan, dalam mod Steam atau dari desktop. Apabila sesi menggunakan lebih daripada ini, Steam dan kemudian proses lain sesi yang disokong dimampatkan ke dalam zRAM. Had lembut: tiada apa yang ditutup, tetapi permainan mungkin tersekat-sekat semasa halaman dibaca semula.</string> <string name="perf_ram_cap_unavailable">Memerlukan swap zRAM, yang tiada pada peranti ini.</string> <string name="perf_vram_cap">Had VRAM</string> - <string name="perf_vram_cap_hint">Memori video yang dilaporkan DXVK kepada permainan Direct3D, supaya ia memperuntukkan tekstur untuk jumlah yang lebih kecil. Tetapan DXVK permainan itu sendiri tetap diutamakan. Berkuat kuasa pada sesi seterusnya.</string> + <string name="perf_vram_cap_hint">Melaporkan bajet memori video ini kepada permainan Direct3D 9 hingga 12 untuk mengurangkan penggunaan memori. Permainan boleh melebihinya; ini tidak menambah paging GPU atau menjamin perlindungan daripada ranap akibat kehabisan memori. Berkuat kuasa pada sesi seterusnya.</string> <string name="perf_gpuclock">Kekalkan GPU pada kelajuan tertinggi</string> <string name="perf_gpuclock_hint">Adreno sahaja. Kurang tersekat-sekat, lebih penggunaan bateri dan haba.</string> <string name="perf_fixes">Pembetulan sesi</string> diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 9cf373f054..6efdff9927 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Gjelder mens Steam-klienten kjører, i Steam-modus eller fra skrivebordet. Når sesjonen bruker mer enn dette, komprimeres Steam og deretter sesjonens andre støttede prosesser til zRAM. En myk grense: ingenting lukkes, men spill kan hakke mens sider hentes tilbake.</string> <string name="perf_ram_cap_unavailable">Krever zRAM-swap, som denne enheten ikke har.</string> <string name="perf_vram_cap">VRAM-grense</string> - <string name="perf_vram_cap_hint">Videominnet DXVK rapporterer til Direct3D-spill, slik at de beregner teksturer for mindre. Spillets egne DXVK-innstillinger har forrang. Trer i kraft fra neste sesjon.</string> + <string name="perf_vram_cap_hint">Rapporterer dette videominnebudsjettet til Direct3D 9 til 12-spill for å redusere minnebruken. Spill kan overskride det; dette legger ikke til GPU-sideveksling og garanterer ikke beskyttelse mot krasj ved minnemangel. Gjelder fra neste økt.</string> <string name="perf_gpuclock">Hold GPU-en på toppfrekvens</string> <string name="perf_gpuclock_hint">Bare Adreno. Færre hikk, mer batteribruk og varme.</string> <string name="perf_fixes">Sesjonsfikser</string> diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index ee5325cf3e..40e6503caf 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Geldt terwijl de Steam-client draait, in de Steam-modus of vanaf de desktop. Als de sessie meer gebruikt dan dit, worden Steam en daarna de andere ondersteunde processen van de sessie in zRAM gecomprimeerd. Een zachte limiet: er wordt niets gesloten, maar games kunnen haperen terwijl pagina’s terugkomen.</string> <string name="perf_ram_cap_unavailable">Vereist zRAM-swap, die dit apparaat niet heeft.</string> <string name="perf_vram_cap">VRAM-limiet</string> - <string name="perf_vram_cap_hint">Het videogeheugen dat DXVK aan Direct3D-games meldt, zodat ze minder ruimte voor texturen plannen. De eigen DXVK-instellingen van een game gaan voor. Geldt vanaf de volgende sessie.</string> + <string name="perf_vram_cap_hint">Meldt dit videogeheugenbudget aan Direct3D 9- tot 12-games om het geheugengebruik te verlagen. Games kunnen het overschrijden; dit voegt geen GPU-paging toe en garandeert geen bescherming tegen crashes door geheugentekort. Geldt vanaf de volgende sessie.</string> <string name="perf_gpuclock">GPU op hoogste kloksnelheid houden</string> <string name="perf_gpuclock_hint">Alleen Adreno. Minder haperingen, meer batterijverbruik en warmte.</string> <string name="perf_fixes">Sessiefixes</string> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index a6b1771595..0265a3ab81 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -589,7 +589,7 @@ <string name="perf_ram_cap_hint">Działa, gdy działa klient Steam, w trybie Steam lub z pulpitu. Gdy sesja używa więcej, Steam, a następnie inne obsługiwane procesy sesji są kompresowane do zRAM. Miękki limit: nic nie jest zamykane, ale gry mogą się zacinać podczas wczytywania stron z powrotem.</string> <string name="perf_ram_cap_unavailable">Wymaga swapu zRAM, którego to urządzenie nie ma.</string> <string name="perf_vram_cap">Limit VRAM</string> - <string name="perf_vram_cap_hint">Pamięć wideo, którą DXVK zgłasza grom Direct3D, aby planowały tekstury na mniej. Własne ustawienia DXVK gry mają pierwszeństwo. Działa od następnej sesji.</string> + <string name="perf_vram_cap_hint">Zgłasza ten budżet pamięci wideo grom Direct3D od 9 do 12, aby ograniczyć zużycie pamięci. Gry mogą go przekroczyć; nie dodaje to stronicowania GPU ani nie gwarantuje ochrony przed awariami z powodu braku pamięci. Działa od następnej sesji.</string> <string name="perf_gpuclock">Utrzymuj GPU na najwyższym taktowaniu</string> <string name="perf_gpuclock_hint">Tylko Adreno. Mniej przycięć, większe zużycie baterii i więcej ciepła.</string> <string name="perf_fixes">Poprawki sesji</string> diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 543de9b58c..aaff56fc08 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -587,7 +587,7 @@ <string name="perf_ram_cap_hint">Aplica-se enquanto o cliente Steam está em execução, no modo Steam ou a partir do ambiente de trabalho. Quando a sessão utiliza mais do que isto, o Steam e depois os outros processos suportados da sessão são comprimidos na zRAM. Um limite flexível: nada é fechado, mas os jogos podem ter soluços enquanto as páginas são repostas.</string> <string name="perf_ram_cap_unavailable">Requer swap em zRAM, que este dispositivo não tem.</string> <string name="perf_vram_cap">Limite de VRAM</string> - <string name="perf_vram_cap_hint">A memória de vídeo que o DXVK indica aos jogos Direct3D, para que reservem menos para texturas. As definições de DXVK do próprio jogo têm prioridade. Aplica-se na próxima sessão.</string> + <string name="perf_vram_cap_hint">Comunica este orçamento de memória de vídeo aos jogos Direct3D 9 a 12 para reduzir a utilização de memória. Os jogos podem excedê-lo; isto não adiciona paginação da GPU nem garante proteção contra falhas por falta de memória. Aplica-se na próxima sessão.</string> <string name="perf_gpuclock">Manter a GPU na frequência máxima</string> <string name="perf_gpuclock_hint">Apenas Adreno. Menos soluços, mais consumo de bateria e mais calor.</string> <string name="perf_fixes">Correções da sessão</string> diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index be0368f500..31ea84d9d8 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -587,7 +587,7 @@ <string name="perf_ram_cap_hint">Vale enquanto o cliente Steam está em execução, no modo Steam ou pela área de trabalho. Quando a sessão usa mais que isso, a Steam e depois os outros processos compatíveis da sessão são comprimidos na zRAM. Um limite flexível: nada é fechado, mas os jogos podem travar enquanto as páginas voltam.</string> <string name="perf_ram_cap_unavailable">Requer swap em zRAM, que este dispositivo não tem.</string> <string name="perf_vram_cap">Limite de VRAM</string> - <string name="perf_vram_cap_hint">A memória de vídeo que o DXVK informa aos jogos Direct3D, para que reservem menos para texturas. As configurações de DXVK do próprio jogo têm prioridade. Vale a partir da próxima sessão.</string> + <string name="perf_vram_cap_hint">Informa este orçamento de memória de vídeo aos jogos Direct3D 9 a 12 para reduzir o uso de memória. Os jogos podem excedê-lo; isso não adiciona paginação de GPU nem garante proteção contra falhas por falta de memória. Entra em vigor na próxima sessão.</string> <string name="perf_gpuclock">Manter a GPU no clock máximo</string> <string name="perf_gpuclock_hint">Só em Adreno. Menos engasgos, mais gasto de bateria e mais calor.</string> <string name="perf_fixes">Correções da sessão</string> diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index 08ecc9183f..859638f0fa 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -587,7 +587,7 @@ <string name="perf_ram_cap_hint">Se aplică cât rulează clientul Steam, în modul Steam sau de pe desktop. Când sesiunea folosește mai mult de atât, Steam și apoi celelalte procese acceptate ale sesiunii sunt comprimate în zRAM. O limită flexibilă: nimic nu se închide, dar jocurile pot sacada cât paginile revin.</string> <string name="perf_ram_cap_unavailable">Necesită swap zRAM, pe care acest dispozitiv nu îl are.</string> <string name="perf_vram_cap">Limită VRAM</string> - <string name="perf_vram_cap_hint">Memoria video pe care DXVK o raportează jocurilor Direct3D, ca acestea să aloce mai puțin pentru texturi. Setările DXVK proprii ale unui joc au prioritate. Intră în vigoare la sesiunea următoare.</string> + <string name="perf_vram_cap_hint">Raportează acest buget de memorie video jocurilor Direct3D 9 până la 12 pentru a reduce utilizarea memoriei. Jocurile îl pot depăși; nu adaugă paginare GPU și nu garantează protecție împotriva blocărilor cauzate de lipsa memoriei. Se aplică din sesiunea următoare.</string> <string name="perf_gpuclock">Fixează GPU-ul la frecvența maximă</string> <string name="perf_gpuclock_hint">Doar Adreno. Mai puține întreruperi, consum mai mare de baterie și căldură.</string> <string name="perf_fixes">Remedieri de sesiune</string> diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 451f060774..a710de9258 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -608,7 +608,7 @@ <string name="perf_ram_cap_hint">Действует, пока работает клиент Steam, в режиме Steam или с рабочего стола. Когда сессия использует больше этого значения, Steam, а затем другие поддерживаемые процессы сессии сжимаются в zRAM. Мягкий лимит: ничего не закрывается, но игры могут подтормаживать, пока страницы возвращаются.</string> <string name="perf_ram_cap_unavailable">Нужен своп zRAM, которого на этом устройстве нет.</string> <string name="perf_vram_cap">Лимит VRAM</string> - <string name="perf_vram_cap_hint">Объём видеопамяти, который DXVK сообщает играм Direct3D, чтобы они рассчитывали текстуры на меньший объём. Собственные настройки DXVK игры имеют приоритет. Вступит в силу в следующей сессии.</string> + <string name="perf_vram_cap_hint">Сообщает играм Direct3D 9–12 этот бюджет видеопамяти для снижения её использования. Игры могут его превысить; это не добавляет подкачку памяти GPU и не гарантирует защиту от сбоев из-за нехватки памяти. Действует со следующего сеанса.</string> <string name="perf_gpuclock">Поддерживать максимальную частоту GPU</string> <string name="perf_gpuclock_hint">Только для Adreno. Меньше подтормаживаний, но больше энергопотребления и нагрева.</string> <string name="perf_fixes">Исправления сессии</string> diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 5958734aef..b1546f900d 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Gäller medan Steam-klienten körs, i Steam-läge eller från skrivbordet. När sessionen använder mer än detta komprimeras Steam och sedan sessionens övriga processer som stöds till zRAM. En mjuk gräns: inget stängs, men spel kan hacka medan sidor läses tillbaka.</string> <string name="perf_ram_cap_unavailable">Kräver zRAM-swap, vilket den här enheten saknar.</string> <string name="perf_vram_cap">VRAM-gräns</string> - <string name="perf_vram_cap_hint">Videominnet som DXVK rapporterar till Direct3D-spel, så att de budgeterar texturer för mindre. Ett spels egna DXVK-inställningar har företräde. Börjar gälla vid nästa session.</string> + <string name="perf_vram_cap_hint">Rapporterar denna videominnesbudget till Direct3D 9 till 12-spel för att minska minnesanvändningen. Spel kan överskrida den; detta lägger inte till sidväxling av GPU-minne och garanterar inte skydd mot krascher vid minnesbrist. Gäller från nästa session.</string> <string name="perf_gpuclock">Håll GPU:n på dess högsta klockfrekvens</string> <string name="perf_gpuclock_hint">Bara Adreno. Färre hack, högre batteriförbrukning och mer värme.</string> <string name="perf_fixes">Sessionsfixar</string> diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index e795ca955f..a28cdeeaf4 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -583,7 +583,7 @@ <string name="perf_ram_cap_hint">มีผลขณะไคลเอนต์ Steam ทำงาน ทั้งในโหมด Steam หรือจากเดสก์ท็อป เมื่อเซสชันใช้เกินค่านี้ Steam และโปรเซสอื่นที่รองรับของเซสชันจะถูกบีบอัดลงใน zRAM ตามลำดับ เป็นขีดจำกัดแบบอ่อน: ไม่มีอะไรถูกปิด แต่เกมอาจกระตุกขณะดึงหน้าหน่วยความจำกลับมา</string> <string name="perf_ram_cap_unavailable">ต้องใช้ zRAM swap ซึ่งอุปกรณ์นี้ไม่มี</string> <string name="perf_vram_cap">ขีดจำกัด VRAM</string> - <string name="perf_vram_cap_hint">หน่วยความจำวิดีโอที่ DXVK รายงานต่อเกม Direct3D เพื่อให้เกมจัดสรรเท็กซ์เจอร์น้อยลง การตั้งค่า DXVK ของเกมเองยังมีผลเหนือกว่า มีผลในเซสชันถัดไป</string> + <string name="perf_vram_cap_hint">แจ้งงบประมาณหน่วยความจำวิดีโอนี้ให้เกม Direct3D 9 ถึง 12 เพื่อลดการใช้หน่วยความจำ เกมอาจใช้เกินงบได้ ฟีเจอร์นี้ไม่ได้เพิ่มการสลับหน้าหน่วยความจำ GPU และไม่รับประกันว่าจะป้องกันการแครชเมื่อหน่วยความจำหมด มีผลในเซสชันถัดไป</string> <string name="perf_gpuclock">ตรึง GPU ไว้ที่ความเร็วสัญญาณนาฬิกาสูงสุด</string> <string name="perf_gpuclock_hint">สำหรับ Adreno เท่านั้น สะดุดน้อยลง แต่ใช้แบตเตอรี่และเกิดความร้อนมากขึ้น</string> <string name="perf_fixes">การแก้ไขเซสชัน</string> diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 19151d434a..794f7225e8 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -585,7 +585,7 @@ <string name="perf_ram_cap_hint">Steam istemcisi Steam oturumunda veya masaüstünden çalışırken uygulanır. Oturum bundan fazlasını kullandığında önce Steam, ardından oturumun desteklenen diğer işlemleri zRAM\'e sıkıştırılır. Yumuşak bir sınırdır: hiçbir şey kapatılmaz, ancak sayfalar geri yüklenirken oyunlar takılabilir.</string> <string name="perf_ram_cap_unavailable">Bu cihazda olmayan zRAM takası gerekir.</string> <string name="perf_vram_cap">VRAM sınırı</string> - <string name="perf_vram_cap_hint">DXVK\'nin Direct3D oyunlarına bildirdiği video belleği; böylece oyunlar dokuları daha az belleğe göre ayarlar. Oyunun kendi DXVK ayarları yine önceliklidir. Sonraki oturumda geçerli olur.</string> + <string name="perf_vram_cap_hint">Bellek kullanımını azaltmak için Direct3D 9–12 oyunlarına bu video belleği bütçesini bildirir. Oyunlar bütçeyi aşabilir; GPU sayfalaması eklemez veya bellek yetersizliğinden kaynaklanan çökmeleri önlemeyi garanti etmez. Sonraki oturumda geçerli olur.</string> <string name="perf_gpuclock">GPU\'yu en yüksek saat hızında tut</string> <string name="perf_gpuclock_hint">Yalnızca Adreno. Daha az takılma, daha fazla pil tüketimi ve ısınma.</string> <string name="perf_fixes">Oturum düzeltmeleri</string> diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 03f96a3a0e..90cb9d7e76 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -589,7 +589,7 @@ <string name="perf_ram_cap_hint">Діє, поки працює клієнт Steam, у режимі Steam або з робочого столу. Коли сеанс використовує більше цього значення, Steam, а потім інші підтримувані процеси сеансу стискаються в zRAM. Мʼякий ліміт: нічого не закривається, але ігри можуть підвисати, поки сторінки повертаються.</string> <string name="perf_ram_cap_unavailable">Потрібен своп zRAM, якого на цьому пристрої немає.</string> <string name="perf_vram_cap">Ліміт VRAM</string> - <string name="perf_vram_cap_hint">Обсяг відеопамʼяті, який DXVK повідомляє іграм Direct3D, щоб вони розраховували текстури на менше. Власні налаштування DXVK гри мають пріоритет. Набуде чинності в наступному сеансі.</string> + <string name="perf_vram_cap_hint">Повідомляє іграм Direct3D 9–12 цей бюджет відеопам’яті для зменшення її використання. Ігри можуть його перевищити; це не додає підкачку пам’яті GPU й не гарантує захисту від збоїв через нестачу пам’яті. Діє з наступного сеансу.</string> <string name="perf_gpuclock">Тримати GPU на максимальній частоті</string> <string name="perf_gpuclock_hint">Лише Adreno. Менше запинок, вища витрата заряду та нагрів.</string> <string name="perf_fixes">Виправлення сеансу</string> diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 61910dbbfd..b4c2c9ec6c 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -583,7 +583,7 @@ <string name="perf_ram_cap_hint">Áp dụng khi client Steam đang chạy, ở chế độ Steam hoặc từ desktop. Khi phiên dùng nhiều hơn mức này, Steam rồi đến các tiến trình được hỗ trợ khác của phiên sẽ bị nén vào zRAM. Giới hạn mềm: không có gì bị đóng, nhưng game có thể giật khi các trang được nạp lại.</string> <string name="perf_ram_cap_unavailable">Cần swap zRAM, thiết bị này không có.</string> <string name="perf_vram_cap">Giới hạn VRAM</string> - <string name="perf_vram_cap_hint">Bộ nhớ video mà DXVK báo cho game Direct3D, để chúng dùng ít texture hơn. Thiết lập DXVK riêng của game vẫn được ưu tiên. Có hiệu lực từ phiên sau.</string> + <string name="perf_vram_cap_hint">Báo ngân sách bộ nhớ video này cho các trò chơi Direct3D 9 đến 12 để giảm mức dùng bộ nhớ. Trò chơi có thể vượt ngân sách; tính năng này không bổ sung phân trang GPU hay bảo đảm tránh lỗi do hết bộ nhớ. Có hiệu lực ở phiên tiếp theo.</string> <string name="perf_gpuclock">Giữ GPU ở xung nhịp cao nhất</string> <string name="perf_gpuclock_hint">Chỉ dành cho Adreno. Ít giật hơn, dùng nhiều pin và nhiệt hơn.</string> <string name="perf_fixes">Các bản sửa phiên</string> diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 83e786d274..ab4ea52424 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -583,7 +583,7 @@ <string name="perf_ram_cap_hint">在 Steam 客户端运行时生效,无论是 Steam 模式还是从桌面启动。会话使用量超过此值时,会先将 Steam、再将会话中其他受支持的进程压缩到 zRAM。这是软上限:不会关闭任何进程,但在页面读回时游戏可能卡顿。</string> <string name="perf_ram_cap_unavailable">需要 zRAM 交换空间,但此设备不支持。</string> <string name="perf_vram_cap">VRAM 上限</string> - <string name="perf_vram_cap_hint">DXVK 向 Direct3D 游戏报告的显存大小,使游戏按更少的显存分配纹理。游戏自身的 DXVK 设置仍然优先。下次会话时生效。</string> + <string name="perf_vram_cap_hint">向 Direct3D 9 至 12 游戏报告此显存预算,以促使游戏减少内存使用。游戏可能超出预算;此功能不提供 GPU 分页,也不保证避免内存不足导致的崩溃。下次会话生效。</string> <string name="perf_gpuclock">把 GPU 锁定在最高频率</string> <string name="perf_gpuclock_hint">仅限 Adreno。卡顿更少,但更耗电、更发热。</string> <string name="perf_fixes">会话修复</string> diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index f43523bc5f..f555a538c3 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -583,7 +583,7 @@ <string name="perf_ram_cap_hint">在 Steam 用戶端執行時生效,無論是 Steam 模式或從桌面啟動。當會話的用量超過此值時,會先將 Steam、再將會話中其他受支援的程序壓縮到 zRAM。這是軟性上限:不會關閉任何程式,但在分頁讀回時遊戲可能會卡頓。</string> <string name="perf_ram_cap_unavailable">需要 zRAM 交換空間,但此裝置沒有。</string> <string name="perf_vram_cap">VRAM 上限</string> - <string name="perf_vram_cap_hint">DXVK 向 Direct3D 遊戲回報的顯示記憶體,讓遊戲以較少的量規劃紋理。遊戲本身的 DXVK 設定仍優先。下次會話生效。</string> + <string name="perf_vram_cap_hint">向 Direct3D 9 至 12 遊戲報告此顯存預算,以促使遊戲減少記憶體用量。遊戲可能超出預算;此功能不提供 GPU 分頁,也不保證避免因記憶體不足而崩潰。下次工作階段生效。</string> <string name="perf_gpuclock">讓 GPU 保持最高頻率</string> <string name="perf_gpuclock_hint">只限 Adreno。減少卡頓,但更耗電、更發熱。</string> <string name="perf_fixes">會話修正</string> diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index f5546b265a..6fe964d7f0 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -583,7 +583,7 @@ <string name="perf_ram_cap_hint">在 Steam 用戶端執行時生效,無論是 Steam 模式或從桌面啟動。當工作階段的用量超過此值時,會先將 Steam、再將工作階段中其他受支援的程序壓縮到 zRAM。這是軟性上限:不會關閉任何程式,但在分頁讀回時遊戲可能會卡頓。</string> <string name="perf_ram_cap_unavailable">需要 zRAM 交換空間,但這部裝置沒有。</string> <string name="perf_vram_cap">VRAM 上限</string> - <string name="perf_vram_cap_hint">DXVK 向 Direct3D 遊戲回報的顯示記憶體,讓遊戲以較少的量規劃紋理。遊戲本身的 DXVK 設定仍優先。下次工作階段生效。</string> + <string name="perf_vram_cap_hint">向 Direct3D 9 至 12 遊戲回報此顯示記憶體預算,以促使遊戲減少記憶體使用量。遊戲可能超出預算;此功能不提供 GPU 分頁,也不保證避免記憶體不足造成的當機。下次工作階段生效。</string> <string name="perf_gpuclock">讓 GPU 保持最高頻率</string> <string name="perf_gpuclock_hint">僅適用於 Adreno。卡頓更少,但耗電和發熱更多。</string> <string name="perf_fixes">工作階段修復</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 56c27ae794..df5cf9ac28 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -632,7 +632,7 @@ <string name="perf_ram_cap_hint">Applies while the Steam client runs, in Steam mode or from the desktop. When the session uses more than this, Steam and then the session\'s other supported processes are compressed into zRAM. A soft cap: nothing is closed, but games may stutter while pages come back.</string> <string name="perf_ram_cap_unavailable">Needs zRAM swap, which this device does not have.</string> <string name="perf_vram_cap">VRAM cap</string> - <string name="perf_vram_cap_hint">The video memory DXVK reports to Direct3D games, so they budget textures for less. A game\'s own DXVK settings still win. Takes effect at the next session.</string> + <string name="perf_vram_cap_hint">Reports this video memory budget to Direct3D 9 to 12 games to encourage lower memory use. Games may exceed it; this does not add GPU paging or guarantee protection from out-of-memory crashes. Takes effect at the next session.</string> <string name="perf_gpuclock">Hold the GPU at its top clock</string> <string name="perf_gpuclock_hint">Adreno only. Fewer hitches, more battery use and heat.</string> <string name="perf_fixes">Session fixes</string> diff --git a/docs/development/vram-budget.md b/docs/development/vram-budget.md new file mode 100644 index 0000000000..fe790f9aca --- /dev/null +++ b/docs/development/vram-budget.md @@ -0,0 +1,20 @@ +# Reported video memory budget + +The Performance VRAM setting enables `VK_LAYER_DROIDDECK_vram_cap` for games and reports smaller device-local `VK_EXT_memory_budget` budgets. DXVK and vkd3d-proton can use these reports when choosing memory pools. The driver still supplies real heap sizes, usage figures, memory types, and actual allocation results. DXVK also receives its existing `dxgi.maxDeviceMemory` setting. A lower driver budget remains lower; the layer never increases it. + +This is a budget hint, not a physical reservation or a GPU paging implementation. Games may exceed it. On UMA hardware, host-visible Vulkan allocations can share the same device-local heap as textures. Rejecting every allocation above a fixed total can therefore break required upload buffers and other allocations, rather than make a game reduce its texture pool. The layer does not intercept `vkAllocateMemory` or `vkFreeMemory`, and preserves the real heap size so individual allocations larger than the budget remain Vulkan-valid. + +The layer activates only with `DROIDDECK_VRAM_CAP=1` and a positive `DROIDDECK_VRAM_CAP_MB`. With the Performance setting on Auto, the game environment does not enable it. Explicit DXVK configuration remains available, while the Vulkan layer also covers D3D12 and games that replace their DXVK configuration. + +## Physical investigation + +On an 8 GB Pocket FIT Elite with DD Turnip 0.4.0, Proton 11-12.1, and Caravan SandWitch build 25301828: + +- A native Vulkan probe reported a device-local heap of 5,650,776,064 bytes. All exposed memory types used the same device-local UMA heap. The initial implementation clamped both heap and budget to 2048 MiB; the revised layer preserves heap capacity and clamps only the budget. +- The initial hard allocation cap caused the existing save to fail a required 603,979,776-byte D3D12 allocation. Android survived, but the game crashed. Discord testers also reported crashes after reaching the cap in Fallout 76. +- In the initial test with allocation rejection disabled, vkd3d-proton logged the smaller 2048 MiB heap and budget. Caravan still exhausted system memory while loading the save. A reported budget alone does not solve this workload. +- DX11 loaded the same save and supported movement around the station at approximately 60 FPS for more than five minutes, both with and without the reported budget layer. Graphics settings were unchanged. This establishes a renderer workaround, not proof that the layer solved Caravan's OOM. + +Native regression coverage exercises core and KHR memory-property queries, chained budget structures, unchanged real usage above the budget, separate heap types, disabled behavior, device lifecycle dispatch, and successful driver allocations whose individual and combined sizes exceed the reported budget. + +The Vulkan specification describes [`heapBudget` as a guideline](https://docs.vulkan.org/refpages/latest/refpages/source/VkPhysicalDeviceMemoryBudgetPropertiesEXT.html). Transparent movement between device-local and host-local memory requires driver and operating-system support for [pageable device-local memory](https://docs.vulkan.org/refpages/latest/refpages/source/vkAllocateMemory.html). diff --git a/tools/components/recipes.json b/tools/components/recipes.json index 88ae5b79d6..8278e966f3 100644 --- a/tools/components/recipes.json +++ b/tools/components/recipes.json @@ -23,7 +23,8 @@ "outputs": [ "app/src/main/assets/linuxfs/usr/local/bin/gamescope", "app/src/main/assets/linuxfs/usr/local/lib/droiddeck-vr/droiddeck/bin/linuxarm64/driver_droiddeck.so", - "app/src/main/assets/linuxfs/usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_gpuload.so" + "app/src/main/assets/linuxfs/usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_gpuload.so", + "app/src/main/assets/linuxfs/usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_vramcap.so" ], "ndk": true, "packages": [ diff --git a/tools/gpuload/build.sh b/tools/gpuload/build.sh index b2729de7fe..683057c382 100755 --- a/tools/gpuload/build.sh +++ b/tools/gpuload/build.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Builds VK_LAYER_DROIDDECK_gpu_load for the arm64 guest: tools/gpuload/build.sh [--native] OUT -# OUT gets libVkLayer_droiddeck_gpuload.so and its implicit-layer manifest. +# OUT gets libVkLayer_droiddeck_gpuload.so, libVkLayer_droiddeck_vramcap.so and their implicit-layer manifests. set -euo pipefail here=$(cd "$(dirname "$0")" && pwd) repo=$(cd "$here/../.." && pwd) @@ -36,10 +36,15 @@ cmd=(sh -c ' build/gpuload/test_gpuload_busy cc -std=c11 -O2 -Wall -Wextra -Werror -Ibuild/gpuload/include -Itools/gpuload/src -o build/gpuload/test_gpuload_ring tools/gpuload/tests/test_gpuload_ring.c build/gpuload/test_gpuload_ring + cc -std=c11 -O2 -Wall -Wextra -Werror -Ibuild/gpuload/include -Itools/gpuload/src -pthread -Wno-unused-parameter -Wno-missing-field-initializers -o build/gpuload/test_vramcap_budget tools/gpuload/tests/test_vramcap_budget.c + build/gpuload/test_vramcap_budget aarch64-linux-gnu-gcc -std=c11 -shared -fPIC -O2 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers \ -fvisibility=hidden -pthread -Wl,-z,defs -Ibuild/gpuload/include -Itools/gpuload/src \ -o build/gpuload/out/libVkLayer_droiddeck_gpuload.so tools/gpuload/src/vk_layer_droiddeck_gpuload.c - aarch64-linux-gnu-strip --strip-unneeded build/gpuload/out/libVkLayer_droiddeck_gpuload.so') + aarch64-linux-gnu-gcc -std=c11 -shared -fPIC -O2 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers \ + -fvisibility=hidden -pthread -Wl,-z,defs -Ibuild/gpuload/include -Itools/gpuload/src \ + -o build/gpuload/out/libVkLayer_droiddeck_vramcap.so tools/gpuload/src/vk_layer_droiddeck_vramcap.c + aarch64-linux-gnu-strip --strip-unneeded build/gpuload/out/libVkLayer_droiddeck_gpuload.so build/gpuload/out/libVkLayer_droiddeck_vramcap.so') if [ "$native" = 1 ]; then (cd "$repo" && "${cmd[@]}") else @@ -47,7 +52,8 @@ else "${DROIDDECK_BUILD_IMAGE:-droiddeck-local-cross:24.04-v3}" "${cmd[@]}" fi -cp "$here/layer/VK_LAYER_DROIDDECK_gpu_load.json" "$work/out/" +cp "$here/layer/VK_LAYER_DROIDDECK_gpu_load.json" "$here/layer/VK_LAYER_DROIDDECK_vram_cap.json" "$work/out/" mkdir -p "$out" -cp "$work/out/libVkLayer_droiddeck_gpuload.so" "$work/out/VK_LAYER_DROIDDECK_gpu_load.json" "$out/" +cp "$work/out/libVkLayer_droiddeck_gpuload.so" "$work/out/libVkLayer_droiddeck_vramcap.so" \ + "$work/out/VK_LAYER_DROIDDECK_gpu_load.json" "$work/out/VK_LAYER_DROIDDECK_vram_cap.json" "$out/" echo "built $out" diff --git a/tools/gpuload/layer/VK_LAYER_DROIDDECK_vram_cap.json b/tools/gpuload/layer/VK_LAYER_DROIDDECK_vram_cap.json new file mode 100644 index 0000000000..9bff13fe76 --- /dev/null +++ b/tools/gpuload/layer/VK_LAYER_DROIDDECK_vram_cap.json @@ -0,0 +1,20 @@ +{ + "file_format_version": "1.2.0", + "layer": { + "name": "VK_LAYER_DROIDDECK_vram_cap", + "type": "GLOBAL", + "library_path": "/usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_vramcap.so", + "api_version": "1.3.0", + "implementation_version": "1", + "description": "Reports a smaller video memory budget to DXVK and vkd3d-proton", + "functions": { + "vkNegotiateLoaderLayerInterfaceVersion": "DroidDeckVramCap_NegotiateLoaderLayerInterfaceVersion" + }, + "enable_environment": { + "DROIDDECK_VRAM_CAP": "1" + }, + "disable_environment": { + "DROIDDECK_VRAM_CAP_DISABLE": "1" + } + } +} diff --git a/tools/gpuload/src/vk_layer_droiddeck_vramcap.c b/tools/gpuload/src/vk_layer_droiddeck_vramcap.c new file mode 100644 index 0000000000..eefa5608d3 --- /dev/null +++ b/tools/gpuload/src/vk_layer_droiddeck_vramcap.c @@ -0,0 +1,206 @@ +#define _GNU_SOURCE +#include <vulkan/vulkan.h> +#include <vulkan/vk_layer.h> + +#include <pthread.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "vramcap_budget.h" + +#define EXPORT __attribute__((visibility("default"))) + +static uint64_t g_cap; + +__attribute__((constructor)) static void init(void) { + g_cap = vramcap_parse_mb(getenv("DROIDDECK_VRAM_CAP_MB")); +} + +struct inst { + struct inst *next_in_list; + VkInstance handle; + PFN_vkGetInstanceProcAddr gipa; + PFN_vkDestroyInstance destroy; + PFN_vkGetPhysicalDeviceMemoryProperties2 mem2; + PFN_vkGetPhysicalDeviceMemoryProperties2 mem2_khr; +}; + +struct dev { + struct dev *next_in_list; + VkDevice handle; + PFN_vkGetDeviceProcAddr gdpa; + PFN_vkDestroyDevice destroy; +}; + +static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; +static struct inst *g_insts; +static struct dev *g_devs; +static int g_announced; + +static void *key(const void *obj) { return *(void *const *)obj; } + +static struct inst *inst_for(const void *obj) { + struct inst *r; + pthread_mutex_lock(&g_lock); + for (r = g_insts; r && key(r->handle) != key(obj); r = r->next_in_list) {} + pthread_mutex_unlock(&g_lock); + return r; +} + +static struct dev *dev_for(const void *obj) { + struct dev *r; + pthread_mutex_lock(&g_lock); + for (r = g_devs; r && key(r->handle) != key(obj); r = r->next_in_list) {} + pthread_mutex_unlock(&g_lock); + return r; +} + +static void say(const char *what) { + fprintf(stderr, "[droiddeck-vram-cap] pid %d: %s\n", (int)getpid(), what); +} + +static void announce(void) { + if (__atomic_exchange_n(&g_announced, 1, __ATOMIC_RELAXED)) return; + char line[96]; + snprintf(line, sizeof(line), "reported device memory budget %llu MB", (unsigned long long)(g_cap >> 20)); + say(line); +} + +static void clamp_properties2(PFN_vkGetPhysicalDeviceMemoryProperties2 next, VkPhysicalDevice pd, + VkPhysicalDeviceMemoryProperties2 *out) { + next(pd, out); + for (VkBaseOutStructure *s = out->pNext; s; s = s->pNext) + if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT) { + vramcap_budget(&out->memoryProperties, (VkPhysicalDeviceMemoryBudgetPropertiesEXT *)s, g_cap); + if (g_cap) announce(); + } +} + +static void VKAPI_CALL GetMemoryProperties2(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties2 *out) { + struct inst *in = inst_for(pd); + if (in) clamp_properties2(in->mem2, pd, out); +} + +static void VKAPI_CALL GetMemoryProperties2KHR(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties2 *out) { + struct inst *in = inst_for(pd); + if (in) clamp_properties2(in->mem2_khr, pd, out); +} + +static VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *ci, const VkAllocationCallbacks *alloc, VkInstance *out) { + VkLayerInstanceCreateInfo *link = (VkLayerInstanceCreateInfo *)ci->pNext; + while (link && !(link->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && link->function == VK_LAYER_LINK_INFO)) + link = (VkLayerInstanceCreateInfo *)link->pNext; + if (!link) return VK_ERROR_INITIALIZATION_FAILED; + PFN_vkGetInstanceProcAddr next_gipa = link->u.pLayerInfo->pfnNextGetInstanceProcAddr; + link->u.pLayerInfo = link->u.pLayerInfo->pNext; + PFN_vkCreateInstance create = (PFN_vkCreateInstance)next_gipa(VK_NULL_HANDLE, "vkCreateInstance"); + if (!create) return VK_ERROR_INITIALIZATION_FAILED; + struct inst *in = calloc(1, sizeof(*in)); + if (!in) return VK_ERROR_OUT_OF_HOST_MEMORY; + VkResult r = create(ci, alloc, out); + if (r != VK_SUCCESS) { free(in); return r; } + in->handle = *out; + in->gipa = next_gipa; + in->destroy = (PFN_vkDestroyInstance)next_gipa(*out, "vkDestroyInstance"); + in->mem2 = (PFN_vkGetPhysicalDeviceMemoryProperties2)next_gipa(*out, "vkGetPhysicalDeviceMemoryProperties2"); + in->mem2_khr = (PFN_vkGetPhysicalDeviceMemoryProperties2)next_gipa(*out, "vkGetPhysicalDeviceMemoryProperties2KHR"); + pthread_mutex_lock(&g_lock); + in->next_in_list = g_insts; + g_insts = in; + pthread_mutex_unlock(&g_lock); + return VK_SUCCESS; +} + +static void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *alloc) { + struct inst *in = inst_for(instance); + if (!in) return; + PFN_vkDestroyInstance destroy = in->destroy; + pthread_mutex_lock(&g_lock); + for (struct inst **p = &g_insts; *p; p = &(*p)->next_in_list) + if (*p == in) { *p = in->next_in_list; break; } + pthread_mutex_unlock(&g_lock); + free(in); + if (destroy) destroy(instance, alloc); +} + +static VkLayerDeviceCreateInfo *device_chain(const VkDeviceCreateInfo *ci, VkLayerFunction function) { + VkLayerDeviceCreateInfo *c = (VkLayerDeviceCreateInfo *)ci->pNext; + while (c && !(c->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && c->function == function)) + c = (VkLayerDeviceCreateInfo *)c->pNext; + return c; +} + +static VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice pd, const VkDeviceCreateInfo *ci, const VkAllocationCallbacks *alloc, + VkDevice *out) { + VkLayerDeviceCreateInfo *link = device_chain(ci, VK_LAYER_LINK_INFO); + if (!link) return VK_ERROR_INITIALIZATION_FAILED; + PFN_vkGetInstanceProcAddr next_gipa = link->u.pLayerInfo->pfnNextGetInstanceProcAddr; + PFN_vkGetDeviceProcAddr next_gdpa = link->u.pLayerInfo->pfnNextGetDeviceProcAddr; + link->u.pLayerInfo = link->u.pLayerInfo->pNext; + struct inst *in = inst_for(pd); + PFN_vkCreateDevice create = (PFN_vkCreateDevice)next_gipa(in ? in->handle : VK_NULL_HANDLE, "vkCreateDevice"); + if (!create) return VK_ERROR_INITIALIZATION_FAILED; + struct dev *d = calloc(1, sizeof(*d)); + if (!d) return VK_ERROR_OUT_OF_HOST_MEMORY; + VkResult r = create(pd, ci, alloc, out); + if (r != VK_SUCCESS) { free(d); return r; } + d->handle = *out; + d->gdpa = next_gdpa; + d->destroy = (PFN_vkDestroyDevice)next_gdpa(*out, "vkDestroyDevice"); + pthread_mutex_lock(&g_lock); + d->next_in_list = g_devs; + g_devs = d; + pthread_mutex_unlock(&g_lock); + return VK_SUCCESS; +} + +static void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *alloc) { + struct dev *d = dev_for(device); + if (!d) return; + pthread_mutex_lock(&g_lock); + for (struct dev **p = &g_devs; *p; p = &(*p)->next_in_list) + if (*p == d) { *p = d->next_in_list; break; } + pthread_mutex_unlock(&g_lock); + PFN_vkDestroyDevice destroy = d->destroy; + free(d); + if (destroy) destroy(device, alloc); +} + +EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DroidDeckVramCap_GetDeviceProcAddr(VkDevice device, const char *name); + +EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DroidDeckVramCap_GetInstanceProcAddr(VkInstance instance, const char *name) { + if (!strcmp(name, "vkCreateInstance")) return (PFN_vkVoidFunction)CreateInstance; + if (!strcmp(name, "vkDestroyInstance")) return (PFN_vkVoidFunction)DestroyInstance; + if (!strcmp(name, "vkCreateDevice")) return (PFN_vkVoidFunction)CreateDevice; + if (!strcmp(name, "vkDestroyDevice")) return (PFN_vkVoidFunction)DestroyDevice; + if (!strcmp(name, "vkGetInstanceProcAddr")) return (PFN_vkVoidFunction)DroidDeckVramCap_GetInstanceProcAddr; + if (!strcmp(name, "vkGetDeviceProcAddr")) return (PFN_vkVoidFunction)DroidDeckVramCap_GetDeviceProcAddr; + if (!instance) return NULL; + struct inst *in = inst_for(instance); + if (!in) return NULL; + if (g_cap) { + if (!strcmp(name, "vkGetPhysicalDeviceMemoryProperties2") && in->mem2) return (PFN_vkVoidFunction)GetMemoryProperties2; + if (!strcmp(name, "vkGetPhysicalDeviceMemoryProperties2KHR") && in->mem2_khr) + return (PFN_vkVoidFunction)GetMemoryProperties2KHR; + } + return in->gipa(instance, name); +} + +EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DroidDeckVramCap_GetDeviceProcAddr(VkDevice device, const char *name) { + if (!strcmp(name, "vkGetDeviceProcAddr")) return (PFN_vkVoidFunction)DroidDeckVramCap_GetDeviceProcAddr; + if (!strcmp(name, "vkDestroyDevice")) return (PFN_vkVoidFunction)DestroyDevice; + struct dev *d = dev_for(device); + if (!d) return NULL; + return d->gdpa(device, name); +} + +EXPORT VKAPI_ATTR VkResult VKAPI_CALL DroidDeckVramCap_NegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *v) { + if (v->loaderLayerInterfaceVersion > 2) v->loaderLayerInterfaceVersion = 2; + v->pfnGetInstanceProcAddr = DroidDeckVramCap_GetInstanceProcAddr; + v->pfnGetDeviceProcAddr = DroidDeckVramCap_GetDeviceProcAddr; + v->pfnGetPhysicalDeviceProcAddr = NULL; + return VK_SUCCESS; +} diff --git a/tools/gpuload/src/vramcap_budget.h b/tools/gpuload/src/vramcap_budget.h new file mode 100644 index 0000000000..3d77b1c951 --- /dev/null +++ b/tools/gpuload/src/vramcap_budget.h @@ -0,0 +1,32 @@ +#ifndef VRAMCAP_BUDGET_H +#define VRAMCAP_BUDGET_H + +#include <stdint.h> +#include <vulkan/vulkan.h> + +static inline uint64_t vramcap_parse_mb(const char *text) { + if (!text || !*text) return 0; + uint64_t value = 0, limit = UINT64_MAX >> 20; + for (; *text; text++) { + if (*text < '0' || *text > '9') return 0; + unsigned digit = (unsigned)(*text - '0'); + if (value > (limit - digit) / 10) return 0; + value = value * 10 + digit; + } + return value << 20; +} + +static inline VkDeviceSize vramcap_clamp(VkDeviceSize value, uint64_t cap) { + return cap && value > cap ? cap : value; +} + +static inline void vramcap_budget(const VkPhysicalDeviceMemoryProperties *p, + VkPhysicalDeviceMemoryBudgetPropertiesEXT *budget, uint64_t cap) { + for (uint32_t i = 0; i < p->memoryHeapCount && i < VK_MAX_MEMORY_HEAPS; i++) + if (p->memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) { + budget->heapBudget[i] = vramcap_clamp(budget->heapBudget[i], cap); + budget->heapBudget[i] = vramcap_clamp(budget->heapBudget[i], p->memoryHeaps[i].size); + } +} + +#endif diff --git a/tools/gpuload/tests/test_vramcap_budget.c b/tools/gpuload/tests/test_vramcap_budget.c new file mode 100644 index 0000000000..40c6f9d8c2 --- /dev/null +++ b/tools/gpuload/tests/test_vramcap_budget.c @@ -0,0 +1,154 @@ +#include <assert.h> +#include <inttypes.h> +#include "../src/vk_layer_droiddeck_vramcap.c" + +static int instance_dispatch, device_dispatch; +static void *instance_object = &instance_dispatch, *physical_object = &instance_dispatch; +static void *device_object = &device_dispatch; +static VkInstance instance; +static VkPhysicalDevice physical; +static VkDevice device; +static unsigned allocations, frees, destroyed_devices, destroyed_instances; + +static void VKAPI_CALL memory_properties(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties *out) { + assert(pd == physical); + *out = (VkPhysicalDeviceMemoryProperties){ + .memoryHeapCount = 3, + .memoryHeaps = {{8ULL << 30, VK_MEMORY_HEAP_DEVICE_LOCAL_BIT}, {4ULL << 30, 0}, + {512ULL << 20, VK_MEMORY_HEAP_DEVICE_LOCAL_BIT}}, + .memoryTypeCount = 1, + .memoryTypes = {{VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, 0}}, + }; +} + +static void VKAPI_CALL memory_properties2(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties2 *out) { + memory_properties(pd, &out->memoryProperties); + for (VkBaseOutStructure *p = out->pNext; p; p = p->pNext) + if (p->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT) { + VkPhysicalDeviceMemoryBudgetPropertiesEXT *b = (void *)p; + b->heapBudget[0] = 6ULL << 30; + b->heapBudget[1] = 3ULL << 30; + b->heapBudget[2] = 256ULL << 20; + b->heapUsage[0] = 3ULL << 30; + } +} + +static VkResult VKAPI_CALL allocate(VkDevice d, const VkMemoryAllocateInfo *info, + const VkAllocationCallbacks *a, VkDeviceMemory *out) { + assert(d == device && info->allocationSize == (3ULL << 30)); + *out = (VkDeviceMemory)(uintptr_t)++allocations; + return VK_SUCCESS; +} + +static void VKAPI_CALL release(VkDevice d, VkDeviceMemory m, const VkAllocationCallbacks *a) { + assert(d == device && m); + frees++; +} + +static void VKAPI_CALL destroy_device(VkDevice d, const VkAllocationCallbacks *a) { + assert(d == device); + destroyed_devices++; +} + +static void VKAPI_CALL destroy_instance(VkInstance in, const VkAllocationCallbacks *a) { + assert(in == instance); + destroyed_instances++; +} + +static PFN_vkVoidFunction VKAPI_CALL gdpa(VkDevice d, const char *name) { + assert(d == device); + if (!strcmp(name, "vkAllocateMemory")) return (PFN_vkVoidFunction)allocate; + if (!strcmp(name, "vkFreeMemory")) return (PFN_vkVoidFunction)release; + if (!strcmp(name, "vkDestroyDevice")) return (PFN_vkVoidFunction)destroy_device; + return NULL; +} + +static VkResult VKAPI_CALL create_device(VkPhysicalDevice pd, const VkDeviceCreateInfo *ci, + const VkAllocationCallbacks *a, VkDevice *out) { + assert(pd == physical); + *out = device; + return VK_SUCCESS; +} + +static VkResult VKAPI_CALL create_instance(const VkInstanceCreateInfo *ci, const VkAllocationCallbacks *a, VkInstance *out) { + *out = instance; + return VK_SUCCESS; +} + +static PFN_vkVoidFunction VKAPI_CALL gipa(VkInstance in, const char *name) { + assert(in == instance || in == VK_NULL_HANDLE); + if (!strcmp(name, "vkCreateInstance")) return (PFN_vkVoidFunction)create_instance; + if (!strcmp(name, "vkDestroyInstance")) return (PFN_vkVoidFunction)destroy_instance; + if (!strcmp(name, "vkCreateDevice")) return (PFN_vkVoidFunction)create_device; + if (!strcmp(name, "vkGetPhysicalDeviceMemoryProperties")) return (PFN_vkVoidFunction)memory_properties; + if (!strcmp(name, "vkGetPhysicalDeviceMemoryProperties2") || !strcmp(name, "vkGetPhysicalDeviceMemoryProperties2KHR")) + return (PFN_vkVoidFunction)memory_properties2; + return NULL; +} + +int main(void) { + assert(vramcap_parse_mb("2048") == (2ULL << 30)); + assert(vramcap_parse_mb(NULL) == 0 && vramcap_parse_mb("") == 0 && vramcap_parse_mb("0") == 0); + const char *bad[] = {"-1", "+1", " 1024", "1024 ", "1GB", "18446744073709551616", "17592186044416"}; + for (size_t i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) assert(vramcap_parse_mb(bad[i]) == 0); + assert(vramcap_parse_mb("17592186044415") == ((UINT64_MAX >> 20) << 20)); + + instance = (VkInstance)&instance_object; + physical = (VkPhysicalDevice)&physical_object; + device = (VkDevice)&device_object; + g_cap = 2ULL << 30; + VkLayerInstanceLink il = {.pfnNextGetInstanceProcAddr = gipa}; + VkLayerInstanceCreateInfo ic = {.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO, + .function = VK_LAYER_LINK_INFO, .u.pLayerInfo = &il}; + VkInstanceCreateInfo ici = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pNext = &ic}; + VkInstance got_instance; + assert(CreateInstance(&ici, NULL, &got_instance) == VK_SUCCESS && got_instance == instance); + VkPhysicalDeviceMemoryProperties p; + PFN_vkGetPhysicalDeviceMemoryProperties get = (void *)DroidDeckVramCap_GetInstanceProcAddr(instance, "vkGetPhysicalDeviceMemoryProperties"); + assert(get == memory_properties); + get(physical, &p); + assert(p.memoryHeaps[0].size == (8ULL << 30) && p.memoryHeaps[1].size == (4ULL << 30)); + assert(p.memoryHeaps[2].size == (512ULL << 20)); + assert(p.memoryTypes[0].propertyFlags == (VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)); + + const char *names[] = {"vkGetPhysicalDeviceMemoryProperties2", "vkGetPhysicalDeviceMemoryProperties2KHR"}; + for (size_t i = 0; i < 2; i++) { + VkPhysicalDeviceMemoryBudgetPropertiesEXT b = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT}; + VkPhysicalDeviceIDProperties id = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES, .pNext = &b}; + VkPhysicalDeviceMemoryProperties2 p2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2, .pNext = &id}; + PFN_vkGetPhysicalDeviceMemoryProperties2 get2 = (void *)DroidDeckVramCap_GetInstanceProcAddr(instance, names[i]); + get2(physical, &p2); + assert(p2.memoryProperties.memoryHeaps[0].size == (8ULL << 30)); + assert(b.heapBudget[0] == g_cap && b.heapBudget[1] == (3ULL << 30)); + assert(b.heapBudget[2] == (256ULL << 20)); + assert(b.heapUsage[0] == (3ULL << 30)); + assert(p2.pNext == &id && id.pNext == &b); + } + + VkLayerDeviceLink dl = {.pfnNextGetInstanceProcAddr = gipa, .pfnNextGetDeviceProcAddr = gdpa}; + VkLayerDeviceCreateInfo dc = {.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO, + .function = VK_LAYER_LINK_INFO, .u.pLayerInfo = &dl}; + VkDeviceCreateInfo dci = {.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .pNext = &dc}; + VkDevice got_device; + assert(CreateDevice(physical, &dci, NULL, &got_device) == VK_SUCCESS && got_device == device); + PFN_vkAllocateMemory next_allocate = (void *)DroidDeckVramCap_GetDeviceProcAddr(device, "vkAllocateMemory"); + PFN_vkFreeMemory next_free = (void *)DroidDeckVramCap_GetDeviceProcAddr(device, "vkFreeMemory"); + assert(next_allocate == allocate && next_free == release); + VkMemoryAllocateInfo ai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = 3ULL << 30}; + VkDeviceMemory blocks[2]; + for (unsigned i = 0; i < 2; i++) assert(next_allocate(device, &ai, NULL, &blocks[i]) == VK_SUCCESS); + assert(allocations == 2); + for (unsigned i = 0; i < 2; i++) next_free(device, blocks[i], NULL); + assert(frees == 2); + + g_cap = 0; + assert(DroidDeckVramCap_GetInstanceProcAddr(instance, names[0]) == (PFN_vkVoidFunction)memory_properties2); + assert(DroidDeckVramCap_GetInstanceProcAddr(instance, "vkGetPhysicalDeviceMemoryProperties") == (PFN_vkVoidFunction)memory_properties); + PFN_vkDestroyDevice destroy = (void *)DroidDeckVramCap_GetInstanceProcAddr(instance, "vkDestroyDevice"); + assert(destroy == DestroyDevice); + destroy(device, NULL); + DestroyInstance(instance, NULL); + assert(destroyed_devices == 1 && destroyed_instances == 1 && !g_devs && !g_insts); + puts("test_vramcap_budget: ok"); + return 0; +} diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index 886bf10bd6..dfa5681f36 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -360,6 +360,8 @@ def vram_cap(env): cap = "dxgi.maxDeviceMemory = %d" % int(value) own = result.get("DXVK_CONFIG", "").strip().strip(";").strip() result["DXVK_CONFIG"] = cap + "; " + own if own else cap + result["DROIDDECK_VRAM_CAP"] = "1" + result["DROIDDECK_VRAM_CAP_MB"] = value return result diff --git a/tools/release/runtime_inputs.py b/tools/release/runtime_inputs.py index 9682ef46ab..b03f5235dd 100644 --- a/tools/release/runtime_inputs.py +++ b/tools/release/runtime_inputs.py @@ -92,7 +92,8 @@ def required(): 'layer/VK_LAYER_DROIDDECK_vr.json', 'layer/VK_LAYER_DROIDDECK_vr_implicit.json', 'layer/libdroiddeck_vr_scheduling.so']] paths += ['assets/linuxfs/usr/local/lib/droiddeck-gpuload/' + name for name in - ['libVkLayer_droiddeck_gpuload.so', 'VK_LAYER_DROIDDECK_gpu_load.json']] + ['libVkLayer_droiddeck_gpuload.so', 'VK_LAYER_DROIDDECK_gpu_load.json', + 'libVkLayer_droiddeck_vramcap.so', 'VK_LAYER_DROIDDECK_vram_cap.json']] for side in ['left', 'right']: paths += [f'assets/linuxfs/usr/local/lib/droiddeck-vr/droiddeck/resources/rendermodels/droiddeck_hand_{side}/{name}' for name in [f'droiddeck_hand_{side}.json', 'hand.mtl', 'hand.png', 'hand_open.obj', 'hand_fist.obj', diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index cd58fba4d6..fcbb10357c 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -747,6 +747,12 @@ class GameEnvironmentTest(unittest.TestCase): "dxgi.maxDeviceMemory = 2048; dxvk.maxFrameRate = 60") for off in ({}, {"BL_VRAM_MB": "0"}, {"BL_VRAM_MB": "lots"}, {"BL_VRAM_MB": "²"}, {"BL_VRAM_MB": "-1"}): self.assertNotIn("DXVK_CONFIG", cap(off)) + self.assertNotIn("DROIDDECK_VRAM_CAP", cap(off)) + self.assertNotIn("DROIDDECK_VRAM_CAP_MB", cap(off)) + + def test_the_vram_cap_also_turns_on_the_vulkan_layer_that_holds_the_game_to_it(self): + env = MODULE["vram_cap"]({"BL_VRAM_MB": "3072", "DXVK_CONFIG": "dxgi.maxDeviceMemory = 16384"}) + self.assertEqual((env["DROIDDECK_VRAM_CAP"], env["DROIDDECK_VRAM_CAP_MB"]), ("1", "3072")) def test_a_games_wine_sync_choice_also_reaches_its_setup_runs(self): env = {"BL_SYNC": "1", "BL_SYNC_FALLBACK": "1", "BL_FSYNC_FIRST": "0", "OTHER": "kept"} From 5624b483fb65c2c2179e2ec46d5f7d9e68f91d6d Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 17:53:15 -0500 Subject: [PATCH 71/85] fix(input): reach full guest screen with glasses pointer (#2145) fix: the glasses pointer reaches the whole guest screen Absolute input was clamped to the letterboxed picture rect computed for the phone view, while the compositor reads the input space against the glasses output. With different shapes that limited the guest pointer to a middle band of the scene, so the bottom and top edges were unreachable. Send absolute pointer positions as the full-view fraction (the compositor already clamps to the scene) and use the whole view for the touchpad bounds and relative scale while the glasses own the output. Fixes #2055 Co-authored-by: Moroni Granja <moronigranja@gmail.com> --- .../com/droiddeck/launcher/SessionActivity.kt | 35 ++++++++++++------- .../droiddeck/launcher/input/PointerSpace.kt | 20 +++++++++++ .../launcher/input/PointerSpaceTest.kt | 30 ++++++++++++++++ 3 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/input/PointerSpace.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/input/PointerSpaceTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 01206389c3..540c7ed986 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -85,6 +85,7 @@ import com.droiddeck.launcher.input.SteamControllerBle import com.droiddeck.launcher.input.DirectTouchHold import com.droiddeck.launcher.input.GestureTouchStreamGate import com.droiddeck.launcher.input.PointerGestures +import com.droiddeck.launcher.input.PointerSpace import com.droiddeck.launcher.input.SecondScreenDisplay import com.droiddeck.launcher.input.SecondScreenDisplays import com.droiddeck.launcher.input.SecondScreenMode @@ -2980,7 +2981,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private val gestureOutput = object : TouchscreenGestures.Output { override fun moveTo(x: Float, y: Float) { - val rect = drawnRect() ?: return + val rect = pointerSurfaceRect() ?: return if (pointerLocked) { if (gesturePointerReady) moveBy(x - gesturePointerX, y - gesturePointerY, true) } else movePointer(x, y) @@ -2990,7 +2991,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { cursorVisible = false } override fun moveBy(dx: Float, dy: Float, relative: Boolean) { - val rect = drawnRect() ?: return + val rect = (if (pointerLocked) drawnRect() else pointerSurfaceRect()) ?: return if (relative || pointerLocked) { val scale = sceneScale(rect) sendSceneDelta(dx * scale, dy * scale) @@ -3001,7 +3002,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } override fun prepareRelativePan() { if (pointerLocked) return - val rect = drawnRect() ?: return + val rect = pointerSurfaceRect() ?: return moveTo(rect.centerX(), rect.centerY()) } override fun key(code: Int, down: Boolean) { @@ -3045,7 +3046,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private val scrollListener = object : ScrollTouchGestures.Listener { override fun onMove(x: Float, y: Float) { - val rect = drawnRect() ?: return + val rect = pointerSurfaceRect() ?: return val cx = x.coerceIn(rect.left, rect.right) val cy = y.coerceIn(rect.top, rect.bottom) WaylandCompositor.nativeSendPointer(1, InputSpace.x(cx, outputView().width), InputSpace.y(cy, outputView().height)) @@ -3055,7 +3056,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0) } override fun onScroll(dx: Float, dy: Float) { - val rect = drawnRect() ?: return + val rect = pointerSurfaceRect() ?: return val out = SessionState.outputSize scrollRestX += dx * out.first / rect.width() scrollRestY += dy * out.second / rect.height() @@ -3074,7 +3075,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { override fun onScrollStart() { scrollRestX = 0f scrollRestY = 0f - val rect = drawnRect() ?: return + val rect = pointerSurfaceRect() ?: return val x = rect.left + rect.width() * PAD_SCROLL_POINTER_X WaylandCompositor.nativeSendPointer(1, InputSpace.x(x, outputView().width), InputSpace.y(rect.centerY(), outputView().height)) cursorVisible = false @@ -3087,7 +3088,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { override fun onNavigate() { cursorVisible = false } - override fun scrollSpeed(): Float = (drawnRect()?.height() ?: 0f) * PAD_SCROLL_HEIGHTS_PER_S + override fun scrollSpeed(): Float = (pointerSurfaceRect()?.height() ?: 0f) * PAD_SCROLL_HEIGHTS_PER_S } private fun padMouseMode(): Boolean { @@ -3105,7 +3106,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { (routedTouchMode == SessionPrefs.TOUCH_AUTO || routedTouchMode == SessionPrefs.TOUCH_DIRECT) && padMouseMode() private fun fingerScroll(dx: Float, dy: Float) { - val rect = drawnRect() ?: return + val rect = pointerSurfaceRect() ?: return val out = SessionState.outputSize scrollRestX += dx * out.first / rect.width() * AXIS_UNITS_PER_PIXEL scrollRestY += dy * out.second / rect.height() * AXIS_UNITS_PER_PIXEL @@ -3128,7 +3129,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (!WaylandCompositor.nativeCursorInputPos(cursorPosBuf)) return val x = cursorPosBuf[0] / InputSpace.WIDTH.toFloat() * outputView().width val y = cursorPosBuf[1] / InputSpace.HEIGHT.toFloat() * outputView().height - if (rect.contains(x, y)) touchpad.place(x, y) + touchpad.place(x.coerceIn(rect.left, rect.right), y.coerceIn(rect.top, rect.bottom)) } private fun moveLockedPointer(x: Float, y: Float) { @@ -3140,7 +3141,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } private fun movePointer(x: Float, y: Float, fromMouse: Boolean = false) { - val rect = drawnRect() ?: return + val rect = pointerSurfaceRect() ?: return val cx = x.coerceIn(rect.left, rect.right) val cy = y.coerceIn(rect.top, rect.bottom) WaylandCompositor.nativeSendPointer(1, InputSpace.x(cx, outputView().width), InputSpace.y(cy, outputView().height)) @@ -3511,7 +3512,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (width <= 0f || height <= 0f) return val nx = (x / width).coerceIn(0f, 1f) val ny = (y / height).coerceIn(0f, 1f) - val rect = drawnRect() ?: return + val rect = pointerSurfaceRect() ?: return val px = rect.left + nx * rect.width() val py = rect.top + ny * rect.height() WaylandCompositor.nativeSendPointer(1, InputSpace.x(px, outputView().width), InputSpace.y(py, outputView().height)) @@ -3694,6 +3695,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { return android.graphics.RectF(left, top, left + drawnW, top + drawnH) } + /** + * Where the pointer can travel on this view. With the glasses owning the output the view is + * not showing the picture, so the whole view is the touchpad; using the letterboxed picture + * rect there would leave the pointer unable to reach the scene edges. + */ + private fun pointerSurfaceRect(): android.graphics.RectF? { + val view = outputView() + return PointerSpace.area(view.width, view.height, glassesOutputActive, drawnRect()) + } + private var ignoreGameTouch = false private var touchEditorOpen by mutableStateOf(false) private var lockedSwipeUsed = false @@ -3755,7 +3766,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (threeFingerTap.active || wasActive) return true } if (route == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD) { - val rect = drawnRect() ?: return false + val rect = (if (pointerLocked) drawnRect() else pointerSurfaceRect()) ?: return false if (touchpad.bounds != rect) { val fresh = touchpad.bounds.width() <= 1f touchpad.bounds = rect diff --git a/app/src/main/java/com/droiddeck/launcher/input/PointerSpace.kt b/app/src/main/java/com/droiddeck/launcher/input/PointerSpace.kt new file mode 100644 index 0000000000..4e0a9b988b --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/input/PointerSpace.kt @@ -0,0 +1,20 @@ +package com.droiddeck.launcher.input + +import android.graphics.RectF + +/** + * The area of the session view that drives the guest pointer. + * + * The view is also the compositor output only while it shows the picture: the phone, or the + * bottom screen. With the glasses owning the output the view is a touchpad for a scene drawn + * elsewhere, so the whole view has to drive the pointer. Using the picture rect there would + * confine it to the letterboxed band the scene would occupy on the phone, and the pointer could + * not reach the scene edges. + */ +object PointerSpace { + fun area(viewWidth: Int, viewHeight: Int, glassesOwnOutput: Boolean, picture: RectF?): RectF? { + if (viewWidth <= 0 || viewHeight <= 0) return null + if (glassesOwnOutput) return RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat()) + return picture + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/input/PointerSpaceTest.kt b/app/src/test/java/com/droiddeck/launcher/input/PointerSpaceTest.kt new file mode 100644 index 0000000000..7ab117b82c --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/input/PointerSpaceTest.kt @@ -0,0 +1,30 @@ +package com.droiddeck.launcher.input + +import android.graphics.RectF +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertSame +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], manifest = Config.NONE) +class PointerSpaceTest { + private val phonePicture = RectF(0f, 896f, 1080f, 1503f) + + @Test fun theGlassesMakeTheWholeViewThePointerArea() { + assertEquals(RectF(0f, 0f, 1080f, 2400f), + PointerSpace.area(1080, 2400, glassesOwnOutput = true, phonePicture)) + } + + @Test fun theViewThatShowsThePictureUsesItsPictureRect() { + assertSame(phonePicture, PointerSpace.area(2400, 1504, glassesOwnOutput = false, phonePicture)) + } + + @Test fun aViewWithoutSizeHasNoPointerArea() { + assertNull(PointerSpace.area(0, 2400, glassesOwnOutput = true, phonePicture)) + assertNull(PointerSpace.area(1080, 0, glassesOwnOutput = false, phonePicture)) + } +} From 8ac5652131022db632fd8a98afe0d24d438e9dfa Mon Sep 17 00:00:00 2001 From: MaxsTechReview <maxjividen@gmail.com> Date: Thu, 5 Nov 2026 18:00:38 -0500 Subject: [PATCH 72/85] fix(components): a native-only override falls back to builtin when the prefix has no native DLL (#2142) * fix(components): a native-only override falls back to builtin when the prefix has no native DLL A component that asks for a DLL native-only (for example .NET 4.8's mscoree=n) left the DLL unloadable when its native copy never reached the prefix. On ARM64 prefixes the .NET installer leaves Wine's builtin mscoree in system32, so every program that needs .NET exited at launch with 'mscoree.dll not found'. At launch, an override of n for a DLL whose system32 or syswow64 copy is missing or is Wine's own (a link into the Proton build, or a builtin or placeholder stub) becomes n,b, and the session log says so. A real native copy is still loaded first, and the saved component state is unchanged, so the override returns to n once the native DLL is there. * Treat any prefix symlink as builtin when checking native overrides * Treat an unreadable prefix DLL as missing for native overrides --- .../usr/local/bin/droiddeck-wincomponents | 22 ++++++++ tools/tests/test_wincomponents.py | 54 ++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-wincomponents b/tools/linuxfs/overlay/usr/local/bin/droiddeck-wincomponents index e09a5e8d80..393f971024 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-wincomponents +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-wincomponents @@ -600,6 +600,8 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING written, registry_notes = apply_registry(pfx, values, new_state, held) notes += registry_notes save_state(compat, new_state) + overrides, fallback = reachable_overrides(pfx, overrides) + notes += fallback if copied or removed or restored or written: note = "components %s: %d file(s) placed, %d removed" % (",".join(ids) or "none", copied, removed) note += ", %d put back as they were" % restored if restored else "" @@ -607,6 +609,26 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING return overrides, notes +def native_dll(pfx, name): + for arch in ARCH_DIRS: + path = existing(pfx / "drive_c/windows" / arch / (name + ".dll")) + if path is None or builtin(path) or not os.access(path, os.R_OK): + return False + return True + + +def reachable_overrides(pfx, names): + kept, notes = [], [] + for entry in names: + name, sep, mode = entry.partition("=") + name = name.strip().lower() + if sep and mode.strip().lower() == "n" and not native_dll(pfx, name): + entry = name + "=n,b" + notes.append("%s=n has no native DLL in the prefix; using n,b" % name) + kept.append(entry) + return kept, notes + + def overrides_value(names): modes = {} for entry in names: diff --git a/tools/tests/test_wincomponents.py b/tools/tests/test_wincomponents.py index 8e88e00f9c..51c555b9bb 100644 --- a/tools/tests/test_wincomponents.py +++ b/tools/tests/test_wincomponents.py @@ -25,6 +25,7 @@ class WinComponentsTest(unittest.TestCase): def component(self, cid, overrides, files): folder = self.store / cid + folder.mkdir(parents=True, exist_ok=True) for rel, data in files.items(): path = folder / rel path.parent.mkdir(parents=True, exist_ok=True) @@ -248,7 +249,7 @@ class WinComponentsTest(unittest.TestCase): self.component("xaudio2.7", ["xaudio2_7"], {"system32/xaudio2_7.dll": b"xa"}) self.pick("directmusic", "xaudio2.7") names, _ = self.apply() - self.assertEqual(MODULE["overrides_value"](names), "dmband=n,b;dsound=n;xaudio2_7=n,b") + self.assertEqual(MODULE["overrides_value"](names), "dmband=n,b;dsound=n,b;xaudio2_7=n,b") self.assertEqual((self.pfx / "syswow64/dmband.dll").read_bytes(), b"band") self.assertEqual(json.loads((self.compat / ".droiddeck-wincomponents.json").read_text())["components"], ["dmband", "dsound", "directmusic", "xaudio2.7"]) @@ -263,6 +264,57 @@ class WinComponentsTest(unittest.TestCase): self.assertEqual(MODULE["overrides_value"](["a", "b=n", "a=b", "bad;name", "c=x"]), "b=n;a=b") + def prefix_dll(self, arch, name, data=None, link=None): + path = self.pfx / arch / name + path.parent.mkdir(parents=True, exist_ok=True) + if link is not None: + link.parent.mkdir(parents=True, exist_ok=True) + link.write_bytes(b"MZ" + b"\0" * 126) + path.symlink_to(link) + else: + path.write_bytes(data) + + def test_a_native_only_override_without_a_native_dll_falls_back_to_builtin(self): + self.component("dotnet48", ["mscoree=n"], {"drive_c/windows/Microsoft.NET/Framework64/clr.dll": b"clr"}) + dist = Path(self.tmp.name) / "proton/lib/wine" + self.prefix_dll("system32", "mscoree.dll", link=dist / "aarch64-windows/mscoree.dll") + self.prefix_dll("syswow64", "mscoree.dll", link=dist / "i386-windows/mscoree.dll") + self.pick("dotnet48") + names, notes = self.apply() + self.assertEqual(MODULE["overrides_value"](names), "mscoree=n,b") + self.assertIn("mscoree=n has no native DLL in the prefix; using n,b", notes) + + def test_a_wine_placeholder_file_is_not_a_native_dll(self): + self.component("dotnet48", ["mscoree=n"], {}) + for arch in ("system32", "syswow64"): + self.prefix_dll(arch, "MSCOREE.DLL", b"MZ" + b"\0" * 62 + b"Wine placeholder DLL") + self.pick("dotnet48") + names, _ = self.apply() + self.assertEqual(MODULE["overrides_value"](names), "mscoree=n,b") + + def test_a_native_only_override_stays_native_when_the_native_dll_is_there(self): + self.component("dotnet48", ["mscoree=n"], {}) + for arch in ("system32", "syswow64"): + self.prefix_dll(arch, "mscoree.dll", b"MZ" + b"\0" * 62 + b"Microsoft .NET runtime") + self.pick("dotnet48") + names, notes = self.apply() + self.assertEqual(MODULE["overrides_value"](names), "mscoree=n") + self.assertFalse([n for n in notes if "has no native DLL" in n]) + + def test_a_native_only_override_with_one_architecture_missing_keeps_the_other_native(self): + self.component("physx", ["physxloader=n"], {"system32/PhysXLoader.dll": b"MZ native64"}) + self.pick("physx") + names, _ = self.apply() + self.assertEqual(MODULE["overrides_value"](names), "physxloader=n,b") + + def test_other_override_modes_are_left_alone(self): + self.component("mix", ["openal32", "xinput1_3=b", "d3dx9_43=n,b"], {}) + self.pick("mix") + names, notes = self.apply() + self.assertEqual(MODULE["overrides_value"](names), "openal32=n,b;xinput1_3=b;d3dx9_43=n,b") + self.assertFalse([n for n in notes if "has no native DLL" in n]) + + class PendingWaitTest(unittest.TestCase): def setUp(self): self.tmp = tempfile.TemporaryDirectory() From ecedf131e06186aea483acdd3aac743c619a5e3f Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:04:16 -0500 Subject: [PATCH 73/85] fix(game-env): allow Supergiant mscoree fallback (#2143) * fix(game-env): allow the builtin mscoree for Supergiant .NET crash reporter * test(game-env): cover Supergiant mscoree fallback --------- Co-authored-by: xor <31260844+randornot@users.noreply.github.com> --- .../overlay/usr/local/bin/droiddeck-game-env | 6 ++++++ tools/tests/test_game_environment.py | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index dfa5681f36..a9dab23a7e 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -111,6 +111,12 @@ def d3dgear_hook(game): return {"WINEDLLOVERRIDES": "d3dgear64=d"}, [], "D3DGear capture hook off (it stops the game drawing)" +@fix +def supergiant_dotnet_reporter(game): + if "basecampbugreporter.native.dll" in game.files: + return {"WINEDLLOVERRIDES": "mscoree=n,b"}, [], "Supergiant: allow the builtin mscoree" + + @fix def deep_rock_gdk_raytracing(game): if game.stem == "fsd-wingdk-shipping" and not any(game.has_arg(arg) for arg in ("-raytracing", "-noraytracing")): diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index fcbb10357c..4a9eb32fad 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -19,6 +19,19 @@ STATE = tempfile.TemporaryDirectory() COMPAT["main"].__globals__["COMPAT_DIR"] = STATE.name +class SupergiantDotnetReporterTest(unittest.TestCase): + def test_allows_the_builtin_mscoree_for_supergiant_reporter(self): + game = mock.Mock(files={"basecampbugreporter.native.dll"}) + self.assertEqual( + ({"WINEDLLOVERRIDES": "mscoree=n,b"}, [], "Supergiant: allow the builtin mscoree"), + MODULE["supergiant_dotnet_reporter"](game), + ) + + def test_ignores_games_without_the_supergiant_reporter(self): + game = mock.Mock(files={"enginewin64s.dll"}) + self.assertIsNone(MODULE["supergiant_dotnet_reporter"](game)) + + def mapping_of(text): tokens = COMPAT["tokenize"](text) return COMPAT["read_mapping"](tokens, COMPAT["mapping_block"](tokens)) From b875b39905c435040990845b1902bafdad25fdd1 Mon Sep 17 00:00:00 2001 From: MaxsTechReview <maxjividen@gmail.com> Date: Thu, 5 Nov 2026 18:26:38 -0500 Subject: [PATCH 74/85] fix(input): release held mouse buttons and keys when the session loses focus (#2139) * fix(input): release held mouse buttons and keys when the session loses focus A mouse button or key held in the guest stayed down when another window took focus or pointer capture ended before the release, because the release went to that window. A game that hides the cursor while a button is held, such as mouselook in World of Warcraft, then kept turning the camera with the cursor gone until the button was pressed again. Buttons sent to the guest are now tracked like keys, and every held button and key is released when the session window loses focus or pointer capture, and when picture-in-picture opens. * fix(input): release a held button where it was pressed A button pressed through the compositor was released through the raw mouse channel if that channel turned on while it was held, and the reverse, so the guest kept it down. Each held button now remembers where it was pressed. A scroll-touch drag is also cancelled when the session loses focus. * fix(input): release trackpad buttons on focus loss --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> --- .../com/droiddeck/launcher/SessionActivity.kt | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 540c7ed986..f8e11d2891 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -164,6 +164,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private var unfoldedPanel: com.droiddeck.launcher.ui.DeckControlsPanel? = null private lateinit var sessionRoot: FrameLayout private val guestKeysDown = mutableSetOf<Int>() + private val guestButtonsDown = mutableMapOf<Int, Boolean>() + private val trackpadButtonsDown = mutableSetOf<Int>() private lateinit var surfaceView: SurfaceView private lateinit var sessionOverlay: ComposeView private lateinit var loading: LoadingState @@ -669,7 +671,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { override fun dispatchPointerCaptureChanged(hasCapture: Boolean) { super.dispatchPointerCaptureChanged(hasCapture) Log.i(TAG, "pointer capture " + if (hasCapture) "on" else "off") - if (!hasCapture) uiHandler.postDelayed(::updatePointerCapture, 250) + if (!hasCapture) { + releaseHeldGuestInput() + uiHandler.postDelayed(::updatePointerCapture, 250) + } } } sessionRoot = root @@ -3321,9 +3326,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private fun secondScreenPresentation(target: Display) = SecondScreenPresentation( this, target, sendPointer = ::moveSecondScreenPointer, - sendButton = { button, pressed -> - WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0) - }, + sendButton = ::sendTrackpadButton, sendWheel = { steps -> WaylandCompositor.nativeSendSceneInput(4, steps, 0) }, onSteamMenu = ::tapSteamButton, onQam = ::tapQam, @@ -3657,11 +3660,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } private fun sendSceneButton(code: Int, down: Boolean) { - val writer = if (evdevMouseActive) mouseWriter else null + val raw = if (down) evdevMouseActive.also { guestButtonsDown[code] = it } + else guestButtonsDown.remove(code) ?: evdevMouseActive + val writer = if (raw) mouseWriter else null if (writer != null) writer.writeMouseButton(code.toShort(), down) else WaylandCompositor.nativeSendSceneInput(3, code, if (down) 1 else 0) } + private fun sendTrackpadButton(button: Int, pressed: Boolean) { + if (pressed) trackpadButtonsDown.add(button) else trackpadButtonsDown.remove(button) + WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0) + } + private fun sendSceneWheel(steps: Int) { val writer = if (evdevMouseActive) mouseWriter else null if (writer != null) writer.writeMouseWheel(-steps, 0, 120) @@ -4166,6 +4176,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private fun keyboardCoversPad() = SessionState.mode == SessionService.MODE_STEAM && AgentGuest.steamKeyboard + private fun releaseHeldGuestInput() { + guestButtonsDown.keys.toList().forEach { sendSceneButton(it, false) } + trackpadButtonsDown.toList().forEach { WaylandCompositor.nativeSendSceneInput(3, it, 0) } + trackpadButtonsDown.clear() + guestKeysDown.toList().forEach { sendGuestKey(it, false) } + } + private fun sendGuestKey(key: Int, down: Boolean) { if (down && pipUi) return val code = if (key == KEY_RIGHTCTRL && SessionState.mode == SessionService.MODE_DESKTOP) KEY_LEFTCTRL else key @@ -4251,7 +4268,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { scrollTouch.cancel() directTouchHold.cancel() twoFingerGestures.cancel() - guestKeysDown.toList().forEach { sendGuestKey(it, false) } + releaseHeldGuestInput() keyboard?.hide() sessionClipboard.stop() padMotion?.stop() @@ -4822,7 +4839,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { androidx.compose.ui.viewinterop.AndroidView( factory = { context -> com.droiddeck.launcher.ui.SessionTrackpadView(context, ::moveSecondScreenPointer, - { button, pressed -> WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0) }, + ::sendTrackpadButton, { steps -> WaylandCompositor.nativeSendSceneInput(4, steps, 0) }) }, modifier = Modifier.fillMaxWidth().weight(1f), @@ -4987,6 +5004,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (!hasFocus) { if (::touchscreenGestures.isInitialized) touchscreenGestures.cancel() if (::touchpad.isInitialized) touchpad.cancel() + if (::scrollTouch.isInitialized) scrollTouch.cancel() + releaseHeldGuestInput() } if (hasFocus && !pipUi) { goFullscreen() From 6a5722c6d1d8b761204cc8f041e7e82c492a4137 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:27:08 -0500 Subject: [PATCH 75/85] fix(preload): answer NETLINK_ROUTE queries inside a session (#2141) * fix(preload): answer NETLINK_ROUTE queries inside a session ip(8) could not run in a session: the app's SELinux domain has no netlink_route_socket bind permission, so iproute2 failed at bind and never saw the link that getifaddrs() and /proc/net already expose. Serve NETLINK_ROUTE from the same etc/droiddeck-net snapshot: an AF_UNIX socketpair backs the netlink fd, link/addr/route dumps and route get are synthesised, writes return EPERM, and multicast subscriptions keep failing with EACCES so consumers that wait for link events keep their fallback. Replies carry the port id reported by getsockname() and recvmsg() rewrites the source address to AF_NETLINK/pid 0. iproute2's dump loop requires both before it accepts a message or NLMSG_DONE; when either is missing every message is skipped silently and the process blocks in recvmsg(). * fix(preload): keep socket() and send() semantics for emulated netlink * fix(preload): deliver netlink replies with the caller's blocking mode * fix(preload): preserve NETLINK_ROUTE protocol and fd semantics - Send ACKs for successful queries and honor NETLINK_CAP_ACK - Reject unsupported subscriptions and apply socket timeouts - Track socket identity and shared references across dup and close - Support kernel connect and rewrite recvfrom source addresses - Resolve local and connected routes before default gateways - Add netlink and iproute2 regression tests * fix(preload): handle netlink request limits and socket lifecycle - Collect large sendmsg requests without falling back to UNIX sockets - Reject oversized replies explicitly instead of returning partial results - Allocate unique port IDs and reject duplicate bindings - Honor socket flags and restore inherited sockets across exec - Validate socket types and report netlink socket identity - Replace the fixed socket table with a dynamic registry - Add regression tests for batching, port conflicts and exec inheritance * fix(preload): optimize netlink tracking and support link name queries - Add lock-free fd tracking to bypass netlink locks on ordinary sockets - Move descriptor restoration to initialization and explicit discovery paths - Support RTM_GETLINK lookups via IFLA_IFNAME with correct error codes - Add regression coverage for hot-path overhead and name-based queries * fix(preload): accept unterminated netlink interface names - Copy IFLA_IFNAME into a bounded, NUL-terminated buffer before lookup - Match kernel string length validation and ERANGE errors - Add regression coverage for unterminated names and boundary cases * fix(preload): pin peers for netlink replies * fix(preload): make autobind idempotent * fix(preload): isolate forked netlink cleanup * fix(preload): avoid interposed fd scans * perf(preload): skip PID checks for untracked fds * fix(preload): verify peer before replay --------- Co-authored-by: uubooster-team <uu.booster@service.netease.com> --- tools/linuxfs/preload/lock.c | 7 + tools/linuxfs/preload/net.c | 8 + tools/linuxfs/preload/netif.c | 1533 +++++++++++++++++++++++++++ tools/linuxfs/preload/ntsync.c | 37 +- tools/linuxfs/preload/udevmon.c | 50 +- tools/tests/netlink_stubs.c | 59 ++ tools/tests/test_binfmt_preload.py | 3 +- tools/tests/test_cdp_guard.py | 3 +- tools/tests/test_netlink_preload.py | 1238 +++++++++++++++++++++ 9 files changed, 2927 insertions(+), 11 deletions(-) create mode 100644 tools/tests/netlink_stubs.c create mode 100644 tools/tests/test_netlink_preload.py diff --git a/tools/linuxfs/preload/lock.c b/tools/linuxfs/preload/lock.c index b802fded6e..c3a272f139 100644 --- a/tools/linuxfs/preload/lock.c +++ b/tools/linuxfs/preload/lock.c @@ -54,6 +54,9 @@ static int is_lock_query(int cmd) { } } +int bl_nl_before_dup(int fd, void **state) __attribute__((visibility("hidden"))); +void bl_nl_after_dup(void *state, int fd) __attribute__((visibility("hidden"))); + int fcntl(int fd, int cmd, ...) { static int (*real_fcntl)(int, int, ...); va_list ap; @@ -69,7 +72,11 @@ int fcntl(int fd, int cmd, ...) { errno = ENOSYS; return -1; } + void *nl_state = NULL; + int duplicate = cmd == F_DUPFD || cmd == F_DUPFD_CLOEXEC; + if (duplicate && bl_nl_before_dup(fd, &nl_state) != 0) return -1; result = real_fcntl(fd, cmd, arg); + if (duplicate) bl_nl_after_dup(nl_state, result); if (result >= 0 || !unsupported(errno)) return result; if (is_lock_command(cmd)) return 0; if (is_lock_query(cmd) && arg != NULL) { diff --git a/tools/linuxfs/preload/net.c b/tools/linuxfs/preload/net.c index 73b8c9c8b1..4946db7f9c 100644 --- a/tools/linuxfs/preload/net.c +++ b/tools/linuxfs/preload/net.c @@ -111,10 +111,16 @@ typedef int (*accept4_fn)(int, struct sockaddr *, socklen_t *, int); static unsigned guarded_port(void); __attribute__((visibility("hidden"))) int bl_udevmon_stand_in(int fd); +__attribute__((visibility("hidden"))) int bl_nl_bind(int fd, const struct sockaddr *addr, + socklen_t len, int *rc); +__attribute__((visibility("hidden"))) int bl_nl_connect(int fd, const struct sockaddr *addr, + socklen_t len, int *rc); int bind(int fd, const struct sockaddr *addr, socklen_t len) { static bind_fn real; + int nl_rc; if (!real) real = (bind_fn)dlsym(RTLD_NEXT, "bind"); + if (bl_nl_bind(fd, addr, len, &nl_rc)) return nl_rc; if (bl_udevmon_stand_in(fd)) { if (addr == NULL || len < sizeof(struct sockaddr_nl) || addr->sa_family != AF_NETLINK) { errno = EINVAL; @@ -223,6 +229,8 @@ static int guest_peer(int fd) { int connect(int fd, const struct sockaddr *addr, socklen_t len) { static connect_fn real; + int nl_rc; + if (bl_nl_connect(fd, addr, len, &nl_rc)) return nl_rc; if (!real) real = (connect_fn)dlsym(RTLD_NEXT, "connect"); bind_before_loopback_connect(fd, addr, len); unsigned peer = loopback_family(addr, len) ? addr_port(addr, len) : 0; diff --git a/tools/linuxfs/preload/netif.c b/tools/linuxfs/preload/netif.c index 308af34437..55da3c21e1 100644 --- a/tools/linuxfs/preload/netif.c +++ b/tools/linuxfs/preload/netif.c @@ -5,21 +5,31 @@ #define _GNU_SOURCE 1 #include <arpa/inet.h> #include <dlfcn.h> +#include <dirent.h> #include <errno.h> #include <fcntl.h> #include <ifaddrs.h> +#include <linux/if_addr.h> +#include <linux/if_link.h> +#include <linux/netlink.h> +#include <linux/rtnetlink.h> +#include <limits.h> #include <net/if.h> #include <net/if_arp.h> #include <netpacket/packet.h> #include <netinet/in.h> #include <pthread.h> #include <stdarg.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/socket.h> +#include <sys/stat.h> +#include <sys/syscall.h> +#include <sys/un.h> #include <time.h> #include <unistd.h> @@ -619,3 +629,1526 @@ FILE *fopen64(const char *path, const char *mode) { if (real == NULL) real = (fopen_fn) dlsym(RTLD_NEXT, "fopen64"); return open_stream(real, path, mode, __builtin_return_address(0)); } + +#define NL_REQUEST_MAX 1024 +#define NL_REPLY_MAX 4096 + +#ifndef IFF_LOWER_UP +#define IFF_LOWER_UP 0x10000 +#endif + +#ifndef IF_OPER_UP +#define IF_OPER_UP 6 +#endif + +#ifndef SO_DOMAIN +#define SO_DOMAIN 39 +#endif + +#ifndef SO_PROTOCOL +#define SO_PROTOCOL 38 +#endif + +struct nl_socket { + int peer; + int reservation; + dev_t device; + ino_t inode; + ino_t peer_inode; + ino_t reservation_inode; + unsigned port; + unsigned references; + int type; + int cap_ack; + struct nl_socket *next; +}; + +struct nl_fd { + int fd; + struct nl_socket *socket; + struct nl_fd *next; +}; + +#define NL_FD_PAGE_SIZE 1024 +#define NL_FD_BUCKETS 256 +#define NL_FD_WORD_BITS (sizeof(unsigned long) * CHAR_BIT) + +struct nl_fd_page { + unsigned number; + unsigned long bits[NL_FD_PAGE_SIZE / NL_FD_WORD_BITS]; + struct nl_fd_page *next; +}; + +struct nl_metadata { + uint64_t nonce; + uint32_t port; + uint32_t type; + uint32_t cap_ack; + char magic[12]; +}; + +_Static_assert(sizeof(struct nl_metadata) == 32, "netlink socket metadata ABI"); + +struct nl_packet { + struct nl_packet *next; + size_t len; + unsigned char data[]; +}; + +struct nl_reply { + unsigned char data[NL_REPLY_MAX]; + size_t len; + int overflow; +}; + +static const char nl_client_magic[12] = "bl-nl-c-v1"; +static const char nl_peer_magic[12] = "bl-nl-p-v1"; +static const char nl_reservation_magic[12] = "bl-nl-r-v1"; +static struct nl_socket *nl_sockets; +static struct nl_fd *nl_fds; +static struct nl_fd_page *nl_fd_pages[NL_FD_BUCKETS]; +static unsigned nl_fd_count; +static int nl_fd_index_incomplete; +static unsigned nl_next_port = 0x80000000u; +static pthread_mutex_t nl_sockets_lock = PTHREAD_MUTEX_INITIALIZER; +static pid_t nl_owner; +static __thread unsigned nl_reply_port; +static __thread int nl_reply_capped; + +static void nl_lock_before_fork(void) { pthread_mutex_lock(&nl_sockets_lock); } +static void nl_unlock_after_fork(void) { pthread_mutex_unlock(&nl_sockets_lock); } +static void nl_reset_after_fork(void) { + pthread_mutex_init(&nl_sockets_lock, NULL); + nl_owner = getpid(); +} +static int nl_foreign(void) { return getpid() != nl_owner; } +static void nl_restore_inherited(void); + +__attribute__((constructor)) static void nl_sockets_init(void) { + nl_owner = getpid(); + pthread_atfork(nl_lock_before_fork, nl_unlock_after_fork, nl_reset_after_fork); + nl_restore_inherited(); +} + +static struct nl_fd_page *nl_fd_page_of(int fd) { + unsigned number = (unsigned) fd / NL_FD_PAGE_SIZE; + struct nl_fd_page *page = + __atomic_load_n(&nl_fd_pages[number % NL_FD_BUCKETS], __ATOMIC_ACQUIRE); + for (; page; page = page->next) { + if (page->number == number) return page; + } + return NULL; +} + +static int nl_tracked(int fd) { + if (fd < 0 || __atomic_load_n(&nl_fd_count, __ATOMIC_ACQUIRE) == 0) return 0; + struct nl_fd_page *page = nl_fd_page_of(fd); + unsigned offset = (unsigned) fd % NL_FD_PAGE_SIZE; + if (page && (__atomic_load_n(&page->bits[offset / NL_FD_WORD_BITS], __ATOMIC_ACQUIRE) + & (1ul << (offset % NL_FD_WORD_BITS)))) return 1; + return __atomic_load_n(&nl_fd_index_incomplete, __ATOMIC_ACQUIRE); +} + +static void nl_register(struct nl_fd *entry) { + struct nl_fd_page *page = nl_fd_page_of(entry->fd); + if (page == NULL) { + page = calloc(1, sizeof(*page)); + if (page) { + page->number = (unsigned) entry->fd / NL_FD_PAGE_SIZE; + unsigned bucket = page->number % NL_FD_BUCKETS; + page->next = nl_fd_pages[bucket]; + __atomic_store_n(&nl_fd_pages[bucket], page, __ATOMIC_RELEASE); + } else { + __atomic_store_n(&nl_fd_index_incomplete, 1, __ATOMIC_RELEASE); + } + } + entry->next = nl_fds; + nl_fds = entry; + if (page) { + unsigned offset = (unsigned) entry->fd % NL_FD_PAGE_SIZE; + __atomic_fetch_or(&page->bits[offset / NL_FD_WORD_BITS], + 1ul << (offset % NL_FD_WORD_BITS), __ATOMIC_RELEASE); + } + __atomic_fetch_add(&nl_fd_count, 1, __ATOMIC_RELEASE); +} + +static int nl_identity(int fd, dev_t device, ino_t inode) { + struct stat status; + return fstat(fd, &status) == 0 && S_ISSOCK(status.st_mode) + && status.st_dev == device && status.st_ino == inode; +} + +static int nl_address(int fd, int peer, struct sockaddr_un *addr, struct nl_metadata *metadata, + const char *magic) { + static int (*real_name)(int, struct sockaddr *, socklen_t *); + static int (*real_peer)(int, struct sockaddr *, socklen_t *); + if (real_name == NULL) real_name = (int (*)(int, struct sockaddr *, socklen_t *)) + dlsym(RTLD_NEXT, "getsockname"); + if (real_peer == NULL) real_peer = (int (*)(int, struct sockaddr *, socklen_t *)) + dlsym(RTLD_NEXT, "getpeername"); + socklen_t len = sizeof(*addr); + memset(addr, 0, sizeof(*addr)); + int result = (peer ? real_peer : real_name)(fd, (struct sockaddr *) addr, &len); + if (result != 0 || len != offsetof(struct sockaddr_un, sun_path) + 1 + sizeof(*metadata) + || addr->sun_family != AF_UNIX || addr->sun_path[0] != '\0') return 0; + memcpy(metadata, addr->sun_path + 1, sizeof(*metadata)); + return memcmp(metadata->magic, magic, sizeof(metadata->magic)) == 0; +} + +static int nl_bind_address(int fd, struct nl_metadata *metadata, struct sockaddr_un *addr) { + static int (*real_bind)(int, const struct sockaddr *, socklen_t); + if (real_bind == NULL) real_bind = (int (*)(int, const struct sockaddr *, socklen_t)) + dlsym(RTLD_NEXT, "bind"); + memset(addr, 0, sizeof(*addr)); + addr->sun_family = AF_UNIX; + memcpy(addr->sun_path + 1, metadata, sizeof(*metadata)); + return real_bind(fd, (const struct sockaddr *) addr, + offsetof(struct sockaddr_un, sun_path) + 1 + sizeof(*metadata)); +} + +static int nl_connect_address(int fd, const struct sockaddr_un *addr) { + static int (*real_connect)(int, const struct sockaddr *, socklen_t); + if (real_connect == NULL) real_connect = (int (*)(int, const struct sockaddr *, socklen_t)) + dlsym(RTLD_NEXT, "connect"); + return real_connect(fd, (const struct sockaddr *) addr, + offsetof(struct sockaddr_un, sun_path) + 1 + sizeof(struct nl_metadata)); +} + +static void nl_close_peer(struct nl_socket *socket) { + if (socket->peer < 0) return; + if (!nl_identity(socket->peer, socket->device, socket->peer_inode)) return; + static int (*real_close)(int); + if (real_close == NULL) real_close = (int (*)(int)) dlsym(RTLD_NEXT, "close"); + if (real_close) real_close(socket->peer); +} + +static int nl_reserve_port(struct nl_socket *socket, unsigned port) { + static int (*real_socket)(int, int, int); + static int (*real_close)(int); + if (real_socket == NULL) real_socket = (int (*)(int, int, int)) dlsym(RTLD_NEXT, "socket"); + if (real_close == NULL) real_close = (int (*)(int)) dlsym(RTLD_NEXT, "close"); + int descriptor = real_socket(AF_UNIX, SOCK_DGRAM, 0); + if (descriptor < 0) return -1; + struct nl_metadata metadata = { .port = port }; + struct sockaddr_un addr; + struct stat status; + memcpy(metadata.magic, nl_reservation_magic, sizeof(metadata.magic)); + if (nl_bind_address(descriptor, &metadata, &addr) != 0 || fstat(descriptor, &status) != 0) { + int saved = errno; + real_close(descriptor); + errno = saved; + return -1; + } + socket->reservation = descriptor; + socket->reservation_inode = status.st_ino; + return 0; +} + +static void nl_close_reservation(struct nl_socket *socket) { + if (socket->reservation < 0 + || !nl_identity(socket->reservation, socket->device, socket->reservation_inode)) return; + static int (*real_close)(int); + if (real_close == NULL) real_close = (int (*)(int)) dlsym(RTLD_NEXT, "close"); + if (real_close) real_close(socket->reservation); + socket->reservation = -1; +} + +static int nl_replay_packets(int peer, struct nl_packet *packets) { + static ssize_t (*real_send)(int, const void *, size_t, int); + if (real_send == NULL) real_send = (ssize_t (*)(int, const void *, size_t, int)) + dlsym(RTLD_NEXT, "send"); + int error = 0; + while (packets) { + struct nl_packet *packet = packets; + packets = packet->next; + if (real_send(peer, packet->data, packet->len, MSG_DONTWAIT | MSG_NOSIGNAL) < 0 && error == 0) + error = errno; + free(packet); + } + if (error) errno = error; + return error ? -1 : 0; +} + +static void nl_discard_packets(struct nl_packet *packets) { + while (packets) { + struct nl_packet *next = packets->next; + free(packets); + packets = next; + } +} + +static int nl_save_packets(int fd, struct nl_packet **packets) { + static ssize_t (*real_recv)(int, void *, size_t, int); + if (real_recv == NULL) real_recv = (ssize_t (*)(int, void *, size_t, int)) + dlsym(RTLD_NEXT, "recv"); + struct nl_packet **tail = packets; + *packets = NULL; + for (;;) { + ssize_t len = real_recv(fd, NULL, 0, MSG_PEEK | MSG_TRUNC | MSG_DONTWAIT); + if (len < 0) return errno == EAGAIN || errno == EWOULDBLOCK ? 0 : -1; + if ((size_t) len > SIZE_MAX - sizeof(struct nl_packet)) { + errno = EMSGSIZE; + return -1; + } + struct nl_packet *packet = malloc(sizeof(*packet) + (size_t) len); + if (packet == NULL) return -1; + ssize_t received = real_recv(fd, packet->data, (size_t) len, MSG_DONTWAIT); + if (received < 0) { + int saved = errno; + free(packet); + errno = saved; + return -1; + } + packet->len = (size_t) received; + packet->next = NULL; + *tail = packet; + tail = &packet->next; + } +} + +static int nl_replace_peer(int fd, struct nl_socket *socket, unsigned port, int capped) { + static int (*real_socket)(int, int, int); + static int (*real_close)(int); + if (real_socket == NULL) real_socket = (int (*)(int, int, int)) dlsym(RTLD_NEXT, "socket"); + if (real_close == NULL) real_close = (int (*)(int)) dlsym(RTLD_NEXT, "close"); + struct sockaddr_un client_addr, peer_addr; + struct nl_metadata client, peer = { .port = port, .type = socket->type, .cap_ack = capped }; + if (!nl_address(fd, 0, &client_addr, &client, nl_client_magic)) { + errno = EINVAL; + return -1; + } + int descriptor = real_socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (descriptor < 0) return -1; + struct nl_packet *packets = NULL; + struct stat status; + if (fstat(descriptor, &status) != 0) goto failed; + peer.nonce = status.st_ino; + memcpy(peer.magic, nl_peer_magic, sizeof(peer.magic)); + if (nl_bind_address(descriptor, &peer, &peer_addr) != 0 + || nl_save_packets(fd, &packets) != 0) goto failed; + if (nl_connect_address(fd, &peer_addr) != 0 + || nl_connect_address(descriptor, &client_addr) != 0) goto failed; + struct timeval timeout; + socklen_t timeout_len = sizeof(timeout); + static int (*real_getopt)(int, int, int, void *, socklen_t *); + static int (*real_setopt)(int, int, int, const void *, socklen_t); + if (real_getopt == NULL) real_getopt = (int (*)(int, int, int, void *, socklen_t *)) + dlsym(RTLD_NEXT, "getsockopt"); + if (real_setopt == NULL) real_setopt = (int (*)(int, int, int, const void *, socklen_t)) + dlsym(RTLD_NEXT, "setsockopt"); + if (real_getopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, &timeout_len) == 0) + real_setopt(descriptor, SOL_SOCKET, SO_SNDTIMEO, &timeout, timeout_len); + int send_buffer; + socklen_t buffer_len = sizeof(send_buffer); + if (real_getopt(fd, SOL_SOCKET, SO_SNDBUF, &send_buffer, &buffer_len) == 0) { + send_buffer /= 2; + real_setopt(descriptor, SOL_SOCKET, SO_SNDBUF, &send_buffer, sizeof(send_buffer)); + } + int replayed = nl_replay_packets(descriptor, packets); + int saved = errno; + nl_close_peer(socket); + socket->peer = descriptor; + socket->peer_inode = status.st_ino; + socket->port = port; + socket->cap_ack = capped; + errno = saved; + return replayed; +failed: { + int saved = errno; + if (socket->peer >= 0 && nl_identity(socket->peer, socket->device, socket->peer_inode)) + nl_replay_packets(socket->peer, packets); + else + nl_discard_packets(packets); + real_close(descriptor); + errno = saved; + return -1; +} +} + +static void nl_release(struct nl_socket *socket) { + if (--socket->references != 0) return; + for (struct nl_socket **entry = &nl_sockets; *entry; entry = &(*entry)->next) { + if (*entry != socket) continue; + *entry = socket->next; + break; + } + nl_close_peer(socket); + nl_close_reservation(socket); + free(socket); +} + +static void nl_remove(struct nl_fd **entry) { + struct nl_fd *removed = *entry; + *entry = removed->next; + struct nl_fd *alias; + for (alias = nl_fds; alias; alias = alias->next) { + if (alias->fd == removed->fd) break; + } + struct nl_fd_page *page = nl_fd_page_of(removed->fd); + if (alias == NULL && page) { + unsigned offset = (unsigned) removed->fd % NL_FD_PAGE_SIZE; + __atomic_fetch_and(&page->bits[offset / NL_FD_WORD_BITS], + ~(1ul << (offset % NL_FD_WORD_BITS)), __ATOMIC_RELEASE); + } + __atomic_fetch_sub(&nl_fd_count, 1, __ATOMIC_RELEASE); + nl_release(removed->socket); + free(removed); +} + +static struct nl_fd *nl_restore(int fd) { + struct sockaddr_un client_addr, peer_addr; + struct nl_metadata client, peer; + struct stat status; + if (!nl_address(fd, 0, &client_addr, &client, nl_client_magic) + || !nl_address(fd, 1, &peer_addr, &peer, nl_peer_magic) + || (peer.type != SOCK_RAW && peer.type != SOCK_DGRAM) + || client.type != peer.type || peer.cap_ack > 1 + || fstat(fd, &status) != 0 || client.nonce != (uint64_t) status.st_ino) return NULL; + struct nl_fd *entry = malloc(sizeof(*entry)); + if (entry == NULL) return NULL; + struct nl_socket *socket; + for (socket = nl_sockets; socket; socket = socket->next) { + if (socket->device == status.st_dev && socket->inode == status.st_ino) break; + } + if (socket == NULL) { + socket = calloc(1, sizeof(*socket)); + if (socket == NULL) { + free(entry); + return NULL; + } + socket->peer = -1; + socket->reservation = -1; + socket->device = status.st_dev; + socket->inode = status.st_ino; + socket->type = peer.type; + if (nl_replace_peer(fd, socket, peer.port, peer.cap_ack) != 0) { + free(socket); + free(entry); + return NULL; + } + socket->next = nl_sockets; + nl_sockets = socket; + } + socket->references++; + entry->fd = fd; + entry->socket = socket; + nl_register(entry); + return entry; +} + +static struct nl_fd *nl_find(int fd) { + if (fd < 0) return NULL; + for (struct nl_fd **entry = &nl_fds; *entry; entry = &(*entry)->next) { + if ((*entry)->fd != fd) continue; + struct nl_socket *socket = (*entry)->socket; + if (nl_identity(fd, socket->device, socket->inode)) return *entry; + nl_remove(entry); + break; + } + return NULL; +} + +static void nl_discover(int fd) { + int saved = errno; + if (nl_tracked(fd)) { + pthread_mutex_lock(&nl_sockets_lock); + int found = nl_find(fd) != NULL; + pthread_mutex_unlock(&nl_sockets_lock); + if (found) { + errno = saved; + return; + } + } + struct sockaddr_un addr; + struct nl_metadata metadata; + if (nl_address(fd, 0, &addr, &metadata, nl_client_magic)) { + pthread_mutex_lock(&nl_sockets_lock); + if (nl_find(fd) == NULL) nl_restore(fd); + pthread_mutex_unlock(&nl_sockets_lock); + } + errno = saved; +} + +static void nl_restore_inherited(void) { + int directory = (int) syscall(SYS_openat, AT_FDCWD, "/proc/self/fd", + O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (directory < 0) return; + int *descriptors = NULL; + size_t count = 0, capacity = 0; + union { + max_align_t alignment; + unsigned char bytes[4096]; + } buffer; + long length; + while ((length = syscall(SYS_getdents64, directory, buffer.bytes, sizeof(buffer.bytes))) > 0) { + size_t offset = 0; + while (offset < (size_t) length) { + struct dirent *entry = (struct dirent *) (buffer.bytes + offset); + size_t minimum = offsetof(struct dirent, d_name) + 1; + if (entry->d_reclen < minimum || entry->d_reclen > (size_t) length - offset) break; + char *end; + long descriptor = strtol(entry->d_name, &end, 10); + if (end != entry->d_name && !*end && descriptor >= 0 && descriptor <= INT_MAX && + descriptor != directory) { + if (count == capacity) { + size_t enlarged = capacity ? capacity * 2 : 16; + int *allocated = realloc(descriptors, enlarged * sizeof(*descriptors)); + if (allocated == NULL) { + offset = (size_t) length; + break; + } + descriptors = allocated; + capacity = enlarged; + } + descriptors[count++] = (int) descriptor; + } + offset += entry->d_reclen; + } + } + int saved = errno; + syscall(SYS_close, directory); + errno = saved; + for (size_t index = 0; index < count; index++) { + nl_discover(descriptors[index]); + } + for (size_t index = 0; index < count; index++) { + int descriptor = descriptors[index]; + struct sockaddr_un addr; + struct nl_metadata metadata; + if (!nl_address(descriptor, 0, &addr, &metadata, nl_reservation_magic)) continue; + struct stat status; + if (fstat(descriptor, &status) != 0) continue; + struct nl_socket *socket; + for (socket = nl_sockets; socket; socket = socket->next) { + if (socket->port == metadata.port) break; + } + if (socket) { + socket->reservation = descriptor; + socket->reservation_inode = status.st_ino; + } else { + static int (*real_close)(int); + if (real_close == NULL) real_close = (int (*)(int)) dlsym(RTLD_NEXT, "close"); + real_close(descriptor); + } + } + free(descriptors); +} + +static int nl_nonblocking(int fd) { + static int (*real_fcntl)(int, int, ...); + int flags; + if (real_fcntl == NULL) real_fcntl = (int (*)(int, int, ...)) dlsym(RTLD_NEXT, "fcntl"); + if (real_fcntl == NULL) return 0; + flags = real_fcntl(fd, F_GETFL); + return flags >= 0 && (flags & O_NONBLOCK) != 0; +} + +static int nl_peer_of(int fd) { + int peer = -1; + if (!nl_tracked(fd)) return peer; + pthread_mutex_lock(&nl_sockets_lock); + struct nl_fd *entry = nl_find(fd); + if (entry) { + struct sockaddr_un addr; + struct nl_metadata metadata; + struct nl_socket *socket = entry->socket; + if (nl_address(fd, 1, &addr, &metadata, nl_peer_magic)) { + if ((metadata.nonce == socket->peer_inode + && nl_identity(socket->peer, socket->device, socket->peer_inode)) + || nl_replace_peer(fd, socket, metadata.port, metadata.cap_ack) == 0) { + if (socket->port != 0 && (socket->reservation < 0 + || !nl_identity(socket->reservation, socket->device, socket->reservation_inode))) + nl_reserve_port(socket, socket->port); + peer = socket->peer; + } + } + } + pthread_mutex_unlock(&nl_sockets_lock); + return peer; +} + +static int nl_dup_peer_of(int fd, unsigned *port, int *capped) { + static int (*real_fcntl)(int, int, ...); + int peer = -1; + if (!nl_tracked(fd)) return peer; + pthread_mutex_lock(&nl_sockets_lock); + struct nl_fd *entry = nl_find(fd); + if (entry) { + if (real_fcntl == NULL) + real_fcntl = (int (*)(int, int, ...)) dlsym(RTLD_NEXT, "fcntl"); + if (real_fcntl == NULL) { + errno = ENOSYS; + } else { + peer = real_fcntl(entry->socket->peer, F_DUPFD_CLOEXEC, 0); + if (peer >= 0) { + if (port) *port = entry->socket->port; + if (capped) *capped = entry->socket->cap_ack; + } + } + } else { + errno = EBADF; + } + pthread_mutex_unlock(&nl_sockets_lock); + return peer; +} + +static unsigned nl_port_of(int fd) { + unsigned port = 0; + if (!nl_tracked(fd)) return port; + pthread_mutex_lock(&nl_sockets_lock); + struct nl_fd *entry = nl_find(fd); + if (entry) port = entry->socket->port; + pthread_mutex_unlock(&nl_sockets_lock); + return port; +} + +__attribute__((visibility("hidden"))) int bl_nl_socket(int type, int *fd); +__attribute__((visibility("hidden"))) int bl_nl_bind(int fd, const struct sockaddr *addr, + socklen_t len, int *rc); +__attribute__((visibility("hidden"))) int bl_nl_getsockname(int fd, struct sockaddr *addr, + socklen_t *len, int *rc); +__attribute__((visibility("hidden"))) int bl_nl_owns(int fd); +__attribute__((visibility("hidden"))) void bl_nl_closed(int fd); +__attribute__((visibility("hidden"))) void bl_nl_range_closed(unsigned int first, unsigned int last); +__attribute__((visibility("hidden"))) int bl_nl_before_dup(int fd, void **state); +__attribute__((visibility("hidden"))) void bl_nl_after_dup(void *state, int fd); +__attribute__((visibility("hidden"))) int bl_nl_connect(int fd, const struct sockaddr *addr, + socklen_t len, int *rc); +__attribute__((visibility("hidden"))) int bl_nl_getpeername(int fd, struct sockaddr *addr, + socklen_t *len, int *rc); +__attribute__((visibility("hidden"))) int bl_nl_setsockopt(int fd, int level, int option, + const void *value, socklen_t len, + int (*real)(int, int, int, const void *, socklen_t), + int *rc); +__attribute__((visibility("hidden"))) int bl_nl_getsockopt(int fd, int level, int option, + void *value, socklen_t *len, + int (*real)(int, int, int, void *, socklen_t *), + int *rc); +__attribute__((visibility("hidden"))) void bl_nl_received(struct msghdr *msg); +__attribute__((visibility("hidden"))) int bl_nl_recvmsg(int fd, struct msghdr *msg, int flags, + ssize_t (*real)(int, struct msghdr *, int), + ssize_t *rc); + +int bl_nl_owns(int fd) { return nl_peer_of(fd) >= 0; } + +int bl_nl_socket(int type, int *fd) { + int kind = type & 0xf; + *fd = -1; + if (type & ~(0xf | SOCK_CLOEXEC | SOCK_NONBLOCK)) { + errno = EINVAL; + return 1; + } + if (kind != SOCK_RAW && kind != SOCK_DGRAM) { + errno = kind >= 11 ? EINVAL : ESOCKTNOSUPPORT; + return 1; + } + int pair[2]; + struct stat client_status, peer_status; + struct nl_fd *entry = malloc(sizeof(*entry)); + struct nl_socket *socket = calloc(1, sizeof(*socket)); + if (entry == NULL || socket == NULL) { + free(entry); + free(socket); + errno = ENOMEM; + return 1; + } + int flags = type & (SOCK_CLOEXEC | SOCK_NONBLOCK); + if (socketpair(AF_UNIX, SOCK_DGRAM | flags, 0, pair) != 0) { + free(entry); + free(socket); + return 1; + } + if (fcntl(pair[1], F_SETFD, FD_CLOEXEC) != 0 || fcntl(pair[1], F_SETFL, 0) != 0 + || fstat(pair[0], &client_status) != 0 || fstat(pair[1], &peer_status) != 0) + goto failed; + struct nl_metadata client = { .nonce = client_status.st_ino, .type = kind }; + struct nl_metadata peer = { .nonce = peer_status.st_ino, .type = kind }; + struct sockaddr_un addr; + memcpy(client.magic, nl_client_magic, sizeof(client.magic)); + memcpy(peer.magic, nl_peer_magic, sizeof(peer.magic)); + if (nl_bind_address(pair[0], &client, &addr) != 0 + || nl_bind_address(pair[1], &peer, &addr) != 0) goto failed; + socket->peer = pair[1]; + socket->reservation = -1; + socket->device = client_status.st_dev; + socket->inode = client_status.st_ino; + socket->peer_inode = peer_status.st_ino; + socket->type = kind; + socket->references = 1; + entry->fd = pair[0]; + entry->socket = socket; + pthread_mutex_lock(&nl_sockets_lock); + socket->next = nl_sockets; + nl_sockets = socket; + nl_register(entry); + pthread_mutex_unlock(&nl_sockets_lock); + *fd = pair[0]; + return 1; +failed: { + int saved = errno; + close(pair[0]); + close(pair[1]); + free(entry); + free(socket); + errno = saved; + return 1; + } +} + +static int nl_bind_port(int fd, unsigned requested, int automatic) { + int result = -1; + pthread_mutex_lock(&nl_sockets_lock); + struct nl_fd *entry = nl_find(fd); + if (entry) { + struct nl_socket *socket = entry->socket; + if (socket->port != 0) { + if (automatic || requested == socket->port) result = 0; + else errno = EINVAL; + } else { + unsigned port = requested ? requested : (unsigned) getpid(); + for (;;) { + struct nl_socket *other; + for (other = nl_sockets; other; other = other->next) { + if (other != socket && other->port == port) break; + } + if (other == NULL) { + if (nl_reserve_port(socket, port) == 0) { + result = nl_replace_peer(fd, socket, port, socket->cap_ack); + if (result != 0) nl_close_reservation(socket); + break; + } + if (errno != EADDRINUSE || requested != 0) break; + } + if (requested != 0) { + errno = EADDRINUSE; + break; + } + port = nl_next_port++; + if (port == 0) port = nl_next_port++; + } + } + } else { + errno = EBADF; + } + pthread_mutex_unlock(&nl_sockets_lock); + return result; +} + +static int nl_autobind(int fd) { + return nl_bind_port(fd, 0, 1); +} + +int bl_nl_bind(int fd, const struct sockaddr *addr, socklen_t len, int *rc) { + const struct sockaddr_nl *nl; + if (addr && len >= sizeof(sa_family_t) && addr->sa_family == AF_NETLINK) nl_discover(fd); + if (!bl_nl_owns(fd)) return 0; + if (addr == NULL || len < sizeof(struct sockaddr_nl) || addr->sa_family != AF_NETLINK) { + errno = EINVAL; + *rc = -1; + return 1; + } + nl = (const struct sockaddr_nl *) addr; + if (nl->nl_groups != 0) { + errno = EACCES; + *rc = -1; + return 1; + } + *rc = nl_bind_port(fd, nl->nl_pid, 0); + return 1; +} + +int bl_nl_getsockname(int fd, struct sockaddr *addr, socklen_t *len, int *rc) { + struct sockaddr_nl nl; + socklen_t size; + if (!bl_nl_owns(fd)) return 0; + if (addr == NULL || len == NULL) { + errno = EFAULT; + *rc = -1; + return 1; + } + memset(&nl, 0, sizeof(nl)); + nl.nl_family = AF_NETLINK; + nl.nl_pid = nl_port_of(fd); + size = *len < sizeof(nl) ? *len : (socklen_t) sizeof(nl); + memcpy(addr, &nl, size); + *len = sizeof(nl); + *rc = 0; + return 1; +} + +void bl_nl_closed(int fd) { + if (!nl_tracked(fd)) return; + if (nl_foreign()) return; + bl_nl_range_closed((unsigned int) fd, (unsigned int) fd); +} + +void bl_nl_range_closed(unsigned int first, unsigned int last) { + if (__atomic_load_n(&nl_fd_count, __ATOMIC_ACQUIRE) == 0) return; + if (nl_foreign()) return; + pthread_mutex_lock(&nl_sockets_lock); + struct nl_fd **entry = &nl_fds; + while (*entry) { + if ((unsigned int) (*entry)->fd >= first && (unsigned int) (*entry)->fd <= last) + nl_remove(entry); + else + entry = &(*entry)->next; + } + pthread_mutex_unlock(&nl_sockets_lock); +} + +int bl_nl_before_dup(int fd, void **state) { + *state = NULL; + if (!nl_tracked(fd)) return 0; + if (nl_foreign()) return 0; + pthread_mutex_lock(&nl_sockets_lock); + struct nl_fd *entry = nl_find(fd); + if (entry) { + struct nl_fd *reserved = malloc(sizeof(*reserved)); + if (reserved == NULL) { + pthread_mutex_unlock(&nl_sockets_lock); + errno = ENOMEM; + return -1; + } + reserved->socket = entry->socket; + entry->socket->references++; + *state = reserved; + } + pthread_mutex_unlock(&nl_sockets_lock); + return 0; +} + +void bl_nl_after_dup(void *state, int fd) { + int saved = errno; + struct nl_fd *reserved = state; + if (reserved == NULL && !nl_tracked(fd)) { + errno = saved; + return; + } + if (nl_foreign()) { + errno = saved; + return; + } + pthread_mutex_lock(&nl_sockets_lock); + if (reserved && fd >= 0) { + reserved->fd = fd; + nl_register(reserved); + } + if (fd >= 0) { + for (struct nl_fd **entry = &nl_fds; *entry; entry = &(*entry)->next) { + if ((*entry)->fd != fd || *entry == reserved) continue; + nl_remove(entry); + break; + } + } + if (reserved && fd < 0) { + nl_release(reserved->socket); + free(reserved); + } + pthread_mutex_unlock(&nl_sockets_lock); + errno = saved; +} + +int dup(int fd) { + static int (*real)(int); + void *state; + if (real == NULL) real = (int (*)(int)) dlsym(RTLD_NEXT, "dup"); + if (bl_nl_before_dup(fd, &state) != 0) return -1; + int result = real(fd); + bl_nl_after_dup(state, result); + return result; +} + +static int nl_destination(const struct sockaddr *addr, socklen_t len) { + if (addr == NULL || len < sizeof(struct sockaddr_nl)) return -EINVAL; + if (addr->sa_family != AF_NETLINK) return -EAFNOSUPPORT; + const struct sockaddr_nl *destination = (const struct sockaddr_nl *) addr; + if (destination->nl_groups != 0) return -EACCES; + return destination->nl_pid == 0 ? 0 : -ECONNREFUSED; +} + +int bl_nl_connect(int fd, const struct sockaddr *addr, socklen_t len, int *rc) { + if (addr && len >= sizeof(sa_family_t) && addr->sa_family == AF_NETLINK) nl_discover(fd); + if (!bl_nl_owns(fd)) return 0; + int disconnect = addr && len >= sizeof(sa_family_t) && addr->sa_family == AF_UNSPEC; + int error = disconnect ? 0 : nl_destination(addr, len); + if (error) { + errno = addr == NULL ? EFAULT : -error; + *rc = -1; + return 1; + } + *rc = disconnect ? 0 : nl_autobind(fd); + return 1; +} + +static void nl_source_name(struct sockaddr *addr, socklen_t *len) { + struct sockaddr_nl source; + memset(&source, 0, sizeof(source)); + source.nl_family = AF_NETLINK; + socklen_t capacity = *len < sizeof(source) ? *len : (socklen_t) sizeof(source); + if (capacity > 0) memcpy(addr, &source, capacity); + *len = sizeof(source); +} + +int bl_nl_getpeername(int fd, struct sockaddr *addr, socklen_t *len, int *rc) { + if (!bl_nl_owns(fd)) return 0; + if (addr == NULL || len == NULL) { + errno = EFAULT; + *rc = -1; + } else { + nl_source_name(addr, len); + *rc = 0; + } + return 1; +} + +int bl_nl_setsockopt(int fd, int level, int option, const void *value, socklen_t len, + int (*real)(int, int, int, const void *, socklen_t), int *rc) { + if (level == SOL_NETLINK) nl_discover(fd); + int peer = nl_peer_of(fd); + if (peer < 0) return 0; + if (level != SOL_NETLINK) { + *rc = real(fd, level, option, value, len); + if (*rc == 0 && level == SOL_SOCKET + && (option == SO_SNDTIMEO || option == SO_SNDBUF)) + *rc = real(peer, level, option, value, len); + return 1; + } + if (option != NETLINK_CAP_ACK && option != NETLINK_EXT_ACK) { + errno = option == NETLINK_ADD_MEMBERSHIP || option == NETLINK_DROP_MEMBERSHIP + ? EACCES : ENOPROTOOPT; + *rc = -1; + } else if (value == NULL || len < sizeof(int)) { + errno = value == NULL ? EFAULT : EINVAL; + *rc = -1; + } else { + if (option == NETLINK_CAP_ACK) { + int enabled; + memcpy(&enabled, value, sizeof(enabled)); + pthread_mutex_lock(&nl_sockets_lock); + struct nl_fd *entry = nl_find(fd); + if (entry && nl_replace_peer(fd, entry->socket, entry->socket->port, enabled != 0) != 0) { + pthread_mutex_unlock(&nl_sockets_lock); + *rc = -1; + return 1; + } + pthread_mutex_unlock(&nl_sockets_lock); + } + *rc = 0; + } + return 1; +} + +int bl_nl_getsockopt(int fd, int level, int option, void *value, socklen_t *len, + int (*real)(int, int, int, void *, socklen_t *), int *rc) { + if (level != SOL_SOCKET || (option != SO_TYPE && option != SO_DOMAIN && option != SO_PROTOCOL)) + return 0; + if (!nl_tracked(fd)) { + if (option != SO_DOMAIN) return 0; + *rc = real(fd, level, option, value, len); + if (*rc != 0) return 1; + int domain = AF_UNIX; + if (value && len && *len >= sizeof(domain)) memcpy(&domain, value, sizeof(domain)); + if (domain != AF_UNIX) return 1; + nl_discover(fd); + if (!nl_tracked(fd)) return 1; + } + pthread_mutex_lock(&nl_sockets_lock); + struct nl_fd *entry = nl_find(fd); + if (entry == NULL) { + pthread_mutex_unlock(&nl_sockets_lock); + return 0; + } + int result = option == SO_TYPE ? entry->socket->type : + option == SO_DOMAIN ? AF_NETLINK : NETLINK_ROUTE; + pthread_mutex_unlock(&nl_sockets_lock); + if (len == NULL || (value == NULL && *len > 0)) { + errno = EFAULT; + *rc = -1; + } else if (*len > INT_MAX) { + errno = EINVAL; + *rc = -1; + } else { + socklen_t capacity = *len < sizeof(result) ? *len : (socklen_t) sizeof(result); + if (capacity) memcpy(value, &result, capacity); + *len = capacity; + *rc = 0; + } + return 1; +} + +void bl_nl_received(struct msghdr *msg) { + for (struct cmsghdr *control = CMSG_FIRSTHDR(msg); control; control = CMSG_NXTHDR(msg, control)) { + if (control->cmsg_len < CMSG_LEN(0)) break; + if (control->cmsg_level != SOL_SOCKET || control->cmsg_type != SCM_RIGHTS) continue; + size_t count = (control->cmsg_len - CMSG_LEN(0)) / sizeof(int); + for (size_t index = 0; index < count; index++) { + int descriptor; + memcpy(&descriptor, CMSG_DATA(control) + index * sizeof(descriptor), sizeof(descriptor)); + nl_discover(descriptor); + } + } +} + +int bl_nl_recvmsg(int fd, struct msghdr *msg, int flags, + ssize_t (*real)(int, struct msghdr *, int), ssize_t *rc) { + ssize_t result; + socklen_t capacity = 0; + if (!bl_nl_owns(fd)) return 0; + if (msg && msg->msg_name) capacity = msg->msg_namelen; + result = real(fd, msg, flags); + if (result >= 0 && msg && msg->msg_name) { + msg->msg_namelen = capacity; + nl_source_name(msg->msg_name, &msg->msg_namelen); + } + *rc = result; + return 1; +} + +ssize_t recvfrom(int fd, void *buffer, size_t length, int flags, + struct sockaddr *addr, socklen_t *addrlen) { + static ssize_t (*real)(int, void *, size_t, int, struct sockaddr *, socklen_t *); + if (real == NULL) + real = (ssize_t (*)(int, void *, size_t, int, struct sockaddr *, socklen_t *)) + dlsym(RTLD_NEXT, "recvfrom"); + int owned = bl_nl_owns(fd); + socklen_t capacity = owned && addr && addrlen ? *addrlen : 0; + ssize_t result = real(fd, buffer, length, flags, addr, addrlen); + if (result >= 0 && owned && addr && addrlen) { + *addrlen = capacity; + nl_source_name(addr, addrlen); + } + return result; +} + +static unsigned char *reply_start(struct nl_reply *out, uint16_t type, uint16_t flags, + uint32_t seq, size_t payload) { + size_t offset = NLMSG_ALIGN(out->len); + struct nlmsghdr *header; + if (payload > sizeof(out->data) + || offset + NLMSG_SPACE(payload) > sizeof(out->data)) { + out->overflow = 1; + return NULL; + } + header = (struct nlmsghdr *) (out->data + offset); + memset(header, 0, NLMSG_SPACE(payload)); + header->nlmsg_len = NLMSG_LENGTH(payload); + header->nlmsg_type = type; + header->nlmsg_flags = flags; + header->nlmsg_seq = seq; + header->nlmsg_pid = nl_reply_port; + out->len = offset + NLMSG_ALIGN(header->nlmsg_len); + return (unsigned char *) header; +} + +static void reply_attr(struct nl_reply *out, unsigned char *message, int type, + const void *data, size_t len) { + struct nlmsghdr *header = (struct nlmsghdr *) message; + size_t base = (size_t) (message - out->data); + size_t offset = NLMSG_ALIGN(header->nlmsg_len); + size_t total = RTA_ALIGN(RTA_LENGTH(len)); + struct rtattr *attr; + if (base + offset + total > sizeof(out->data)) { + out->overflow = 1; + return; + } + attr = (struct rtattr *) (message + offset); + attr->rta_type = (unsigned short) type; + attr->rta_len = (unsigned short) RTA_LENGTH(len); + if (len > 0) memcpy(RTA_DATA(attr), data, len); + header->nlmsg_len = (unsigned) (offset + total); + out->len = base + NLMSG_ALIGN(header->nlmsg_len); +} + +static void reply_done(struct nl_reply *out, uint32_t seq) { + unsigned char *message = reply_start(out, NLMSG_DONE, NLM_F_MULTI, seq, sizeof(int)); + int code = 0; + if (message == NULL) return; + memcpy(NLMSG_DATA((struct nlmsghdr *) message), &code, sizeof(code)); +} + +static void reply_error(struct nl_reply *out, const struct nlmsghdr *request, int error) { + int capped = error == 0 || nl_reply_capped; + size_t extra = capped ? 0 : request->nlmsg_len - NLMSG_HDRLEN; + unsigned char *message = reply_start(out, NLMSG_ERROR, capped ? NLM_F_CAPPED : 0, + request->nlmsg_seq, sizeof(struct nlmsgerr) + extra); + struct nlmsgerr *reply; + if (message == NULL) return; + reply = (struct nlmsgerr *) NLMSG_DATA((struct nlmsghdr *) message); + memset(reply, 0, sizeof(*reply)); + reply->error = error; + reply->msg = *request; + if (extra) memcpy(reply + 1, NLMSG_DATA(request), extra); +} + +static void network_of(const struct link_addr *addr, unsigned char *out) { + unsigned char mask[16]; + int len = addr->family == AF_INET ? 4 : 16; + prefix_mask(addr->family, addr->prefix, mask); + for (int i = 0; i < len; i++) out[i] = (unsigned char) (addr->bytes[i] & mask[i]); +} + +static void broadcast_of(const struct link_addr *addr, unsigned char *out) { + unsigned char mask[16]; + prefix_mask(AF_INET, addr->prefix, mask); + for (int i = 0; i < 4; i++) out[i] = (unsigned char) (addr->bytes[i] | (unsigned char) ~mask[i]); +} + +static const struct link_addr *first_addr(const struct link *link, int family) { + for (int i = 0; i < link->addr_count; i++) { + if (link->addrs[i].family == family) return &link->addrs[i]; + } + return NULL; +} + +static void reply_link(struct nl_reply *out, const struct link *link, int loopback, + uint32_t seq, uint16_t flags) { + struct ifinfomsg info; + const char *name; + unsigned mtu; + unsigned char state = IF_OPER_UP; + unsigned char *message; + memset(&info, 0, sizeof(info)); + info.ifi_family = AF_UNSPEC; + info.ifi_type = loopback ? ARPHRD_LOOPBACK : ARPHRD_ETHER; + info.ifi_index = loopback ? LO_INDEX : (link ? (int) link->index : 2); + info.ifi_flags = IFF_UP | IFF_RUNNING | IFF_LOWER_UP + | (loopback ? IFF_LOOPBACK : (IFF_BROADCAST | IFF_MULTICAST)); + info.ifi_change = 0xffffffff; + message = reply_start(out, RTM_NEWLINK, flags, seq, sizeof(info)); + if (message == NULL) return; + memcpy(NLMSG_DATA((struct nlmsghdr *) message), &info, sizeof(info)); + name = loopback ? LO_NAME : (link ? link->name : "eth0"); + mtu = loopback ? LO_MTU : (unsigned) (link ? link->mtu : 1500); + reply_attr(out, message, IFLA_IFNAME, name, strlen(name) + 1); + reply_attr(out, message, IFLA_MTU, &mtu, sizeof(mtu)); + reply_attr(out, message, IFLA_OPERSTATE, &state, sizeof(state)); + if (!loopback && link && (link->mac[0] | link->mac[1] | link->mac[2] + | link->mac[3] | link->mac[4] | link->mac[5])) { + reply_attr(out, message, IFLA_ADDRESS, link->mac, 6); + } +} + +static void reply_addr(struct nl_reply *out, const struct link_addr *addr, unsigned index, + int loopback, uint32_t seq, uint16_t flags) { + struct ifaddrmsg info; + int size = addr->family == AF_INET ? 4 : 16; + unsigned char *message; + memset(&info, 0, sizeof(info)); + info.ifa_family = (unsigned char) addr->family; + info.ifa_prefixlen = (unsigned char) addr->prefix; + info.ifa_flags = IFA_F_PERMANENT; + info.ifa_scope = (unsigned char) (loopback ? RT_SCOPE_HOST + : (is_link_local(addr) ? RT_SCOPE_LINK : RT_SCOPE_UNIVERSE)); + info.ifa_index = index; + message = reply_start(out, RTM_NEWADDR, flags, seq, sizeof(info)); + if (message == NULL) return; + memcpy(NLMSG_DATA((struct nlmsghdr *) message), &info, sizeof(info)); + reply_attr(out, message, IFA_LOCAL, addr->bytes, size); + reply_attr(out, message, IFA_ADDRESS, addr->bytes, size); + if (!loopback && addr->family == AF_INET && addr->prefix <= 30) { + unsigned char broadcast[4]; + broadcast_of(addr, broadcast); + reply_attr(out, message, IFA_BROADCAST, broadcast, 4); + } +} + +static void reply_route(struct nl_reply *out, int family, int destination_length, + const unsigned char *destination, const unsigned char *gateway, + const unsigned char *source, unsigned index, int protocol, int scope, + int type, uint32_t seq, uint16_t flags) { + struct rtmsg info; + int size = family == AF_INET ? 4 : 16; + unsigned char *message; + memset(&info, 0, sizeof(info)); + info.rtm_family = (unsigned char) family; + info.rtm_dst_len = (unsigned char) destination_length; + info.rtm_table = type == RTN_LOCAL ? RT_TABLE_LOCAL : RT_TABLE_MAIN; + info.rtm_protocol = (unsigned char) protocol; + info.rtm_scope = (unsigned char) scope; + info.rtm_type = (unsigned char) type; + message = reply_start(out, RTM_NEWROUTE, flags, seq, sizeof(info)); + if (message == NULL) return; + memcpy(NLMSG_DATA((struct nlmsghdr *) message), &info, sizeof(info)); + if (destination_length > 0 && destination) reply_attr(out, message, RTA_DST, destination, size); + if (gateway) reply_attr(out, message, RTA_GATEWAY, gateway, size); + if (source) reply_attr(out, message, RTA_PREFSRC, source, size); + reply_attr(out, message, RTA_OIF, &index, sizeof(index)); +} + +static void reply_addrs(struct nl_reply *out, const struct link *link, int family, uint32_t seq) { + if (family == AF_UNSPEC || family == AF_INET) + reply_addr(out, &LO_V4, LO_INDEX, 1, seq, NLM_F_MULTI); + if (family == AF_UNSPEC || family == AF_INET6) + reply_addr(out, &LO_V6, LO_INDEX, 1, seq, NLM_F_MULTI); + if (link == NULL) return; + for (int i = 0; i < link->addr_count; i++) { + if (family != AF_UNSPEC && link->addrs[i].family != family) continue; + reply_addr(out, &link->addrs[i], link->index, 0, seq, NLM_F_MULTI); + } +} + +static void reply_routes(struct nl_reply *out, const struct link *link, int family, uint32_t seq) { + if (link == NULL) return; + for (int pass = 0; pass < 2; pass++) { + int current = pass == 0 ? AF_INET : AF_INET6; + const struct link_addr *source; + if (family != AF_UNSPEC && family != current) continue; + source = first_addr(link, current); + for (int i = 0; i < link->gateway_count; i++) { + if (link->gateways[i].family != current) continue; + reply_route(out, current, 0, NULL, link->gateways[i].bytes, + source ? source->bytes : NULL, link->index, RTPROT_STATIC, + RT_SCOPE_UNIVERSE, RTN_UNICAST, seq, NLM_F_MULTI); + } + for (int i = 0; i < link->addr_count; i++) { + unsigned char network[16]; + if (link->addrs[i].family != current) continue; + network_of(&link->addrs[i], network); + reply_route(out, current, link->addrs[i].prefix, network, NULL, + link->addrs[i].bytes, link->index, RTPROT_KERNEL, + RT_SCOPE_LINK, RTN_UNICAST, seq, NLM_F_MULTI); + } + } +} + +static const struct rtattr *request_attr(const struct nlmsghdr *request, size_t offset, int type) { + int length; + const struct rtattr *attr; + if (request->nlmsg_len < NLMSG_HDRLEN + offset) return NULL; + length = (int) (request->nlmsg_len - NLMSG_HDRLEN - offset); + attr = (const struct rtattr *) ((const unsigned char *) NLMSG_DATA(request) + offset); + for (; RTA_OK(attr, length); attr = RTA_NEXT(attr, length)) { + if ((int) attr->rta_type == type) return attr; + } + return NULL; +} + +static int address_matches(const unsigned char *destination, const struct link_addr *addr) { + unsigned char mask[16]; + int size = addr->family == AF_INET ? 4 : 16; + prefix_mask(addr->family, addr->prefix, mask); + for (int index = 0; index < size; index++) { + if ((destination[index] & mask[index]) != (addr->bytes[index] & mask[index])) return 0; + } + return 1; +} + +static int reply_route_get(struct nl_reply *out, const struct link *link, + const struct nlmsghdr *request) { + if (request->nlmsg_len < NLMSG_LENGTH(sizeof(struct rtmsg))) return -EINVAL; + const struct rtmsg *info = (const struct rtmsg *) NLMSG_DATA(request); + int family = info->rtm_family; + if (family != AF_INET && family != AF_INET6) return -EAFNOSUPPORT; + int size = family == AF_INET ? 4 : 16; + const struct rtattr *destination_attr = request_attr(request, sizeof(struct rtmsg), RTA_DST); + unsigned char zero[16] = { 0 }; + if (destination_attr && RTA_PAYLOAD(destination_attr) < (size_t) size) return -EINVAL; + const unsigned char *destination = destination_attr ? RTA_DATA(destination_attr) : zero; + const struct link_addr *loopback = family == AF_INET ? &LO_V4 : &LO_V6; + const struct link_addr *source = NULL; + const struct link_addr *gateway = NULL; + int local = address_matches(destination, loopback); + if (local) source = loopback; + for (int index = 0; link && !local && index < link->addr_count; index++) { + const struct link_addr *addr = &link->addrs[index]; + if (addr->family != family) continue; + if (memcmp(destination, addr->bytes, size) == 0) { + source = addr; + local = 1; + break; + } + if (address_matches(destination, addr) && (!source || addr->prefix > source->prefix)) + source = addr; + } + if (source) { + reply_route(out, family, size * 8, destination, NULL, source->bytes, + local ? LO_INDEX : link->index, RTPROT_KERNEL, + local ? RT_SCOPE_HOST : RT_SCOPE_LINK, + local ? RTN_LOCAL : RTN_UNICAST, request->nlmsg_seq, 0); + return 0; + } + for (int i = 0; link && i < link->gateway_count; i++) { + if (link->gateways[i].family == family) { + gateway = &link->gateways[i]; + break; + } + } + if (gateway == NULL) return -ENETUNREACH; + source = first_addr(link, family); + for (int index = 0; index < link->addr_count; index++) { + if (link->addrs[index].family == family && !is_link_local(&link->addrs[index])) { + source = &link->addrs[index]; + break; + } + } + reply_route(out, family, size * 8, destination, + gateway->bytes, source ? source->bytes : NULL, link->index, RTPROT_STATIC, + RT_SCOPE_UNIVERSE, RTN_UNICAST, request->nlmsg_seq, 0); + return 0; +} + +static void reply_request(const struct nlmsghdr *request, const struct link *link, + struct nl_reply *out) { + int dump = (request->nlmsg_flags & NLM_F_DUMP) != 0; + int error = 0; + uint16_t flags = dump ? NLM_F_MULTI : 0; + switch (request->nlmsg_type) { + case RTM_GETLINK: { + int index = 0; + if (request->nlmsg_len >= NLMSG_LENGTH(sizeof(struct ifinfomsg))) + index = ((const struct ifinfomsg *) NLMSG_DATA(request))->ifi_index; + if (!dump && index == 0) { + const struct rtattr *name_attr = request_attr(request, sizeof(struct ifinfomsg), IFLA_IFNAME); + size_t payload = name_attr ? RTA_PAYLOAD(name_attr) : 0; + const char *data = name_attr ? RTA_DATA(name_attr) : NULL; + size_t length = payload; + if (length && data[length - 1] == '\0') length--; + if (name_attr == NULL) { + error = -EINVAL; + } else if (payload == 0 || length >= IFNAMSIZ) { + error = -ERANGE; + } else { + char name[IFNAMSIZ]; + memcpy(name, data, length); + name[length] = '\0'; + if (strcmp(name, LO_NAME) == 0) + index = LO_INDEX; + else if (link && strcmp(name, link->name) == 0) + index = (int) link->index; + else + error = -ENODEV; + } + } + if (dump) { + reply_link(out, NULL, 1, request->nlmsg_seq, flags); + if (link) reply_link(out, link, 0, request->nlmsg_seq, flags); + reply_done(out, request->nlmsg_seq); + } else if (!error && (index == LO_INDEX || (link && index == (int) link->index))) { + reply_link(out, link, index == LO_INDEX, request->nlmsg_seq, 0); + } else if (!error) { + error = -ENODEV; + } + break; + } + case RTM_GETADDR: { + int family = AF_UNSPEC; + if (request->nlmsg_len >= NLMSG_LENGTH(sizeof(struct ifaddrmsg))) + family = ((const struct ifaddrmsg *) NLMSG_DATA(request))->ifa_family; + if (dump) { + reply_addrs(out, link, family, request->nlmsg_seq); + reply_done(out, request->nlmsg_seq); + } else { + error = -EOPNOTSUPP; + } + break; + } + case RTM_GETROUTE: { + int family = AF_UNSPEC; + if (request->nlmsg_len >= NLMSG_LENGTH(sizeof(struct rtmsg))) + family = ((const struct rtmsg *) NLMSG_DATA(request))->rtm_family; + if (dump) { + reply_routes(out, link, family, request->nlmsg_seq); + reply_done(out, request->nlmsg_seq); + } else { + error = reply_route_get(out, link, request); + } + break; + } + case RTM_GETNEIGH: + if (dump) reply_done(out, request->nlmsg_seq); + else error = -EOPNOTSUPP; + break; + default: + error = -EPERM; + break; + } + if (error || (!dump && (request->nlmsg_flags & NLM_F_ACK))) + reply_error(out, request, error); +} + +static void build_reply(const void *data, size_t len, struct nl_reply *out) { + struct link link; + int have = load_link(&link); + size_t offset = 0; + out->len = 0; + out->overflow = 0; + while (offset + sizeof(struct nlmsghdr) <= len) { + const struct nlmsghdr *request = + (const struct nlmsghdr *) ((const unsigned char *) data + offset); + if (request->nlmsg_len < sizeof(struct nlmsghdr) || offset + request->nlmsg_len > len) + break; + reply_request(request, have ? &link : NULL, out); + offset += NLMSG_ALIGN(request->nlmsg_len); + } +} + +static ssize_t send_raw(int fd, const void *data, size_t len, int extra) { + static ssize_t (*real)(int, const void *, size_t, int); + if (real == NULL) real = (ssize_t (*)(int, const void *, size_t, int)) dlsym(RTLD_NEXT, "send"); + if (real == NULL) { + errno = ENOSYS; + return -1; + } + return real(fd, data, len, MSG_NOSIGNAL | extra); +} + +static int deliver(int fd, const void *data, size_t len, int flags, ssize_t *rc) { + struct nl_reply reply; + int peer; + int extra = 0; + if (nl_peer_of(fd) < 0) return 0; + if (nl_autobind(fd) != 0) { + *rc = -1; + return 1; + } + if (nl_peer_of(fd) < 0) { + errno = EBADF; + *rc = -1; + return 1; + } + peer = nl_dup_peer_of(fd, &nl_reply_port, &nl_reply_capped); + if (peer < 0) { + *rc = -1; + return 1; + } + build_reply(data, len, &reply); + if (reply.overflow) { + int saved = EMSGSIZE; + close(peer); + errno = saved; + *rc = -1; + return 1; + } + if (reply.len == 0) { + struct nlmsghdr *request = (struct nlmsghdr *) data; + if (len < sizeof(struct nlmsghdr)) { + int saved = EINVAL; + close(peer); + errno = saved; + *rc = -1; + return 1; + } + reply.len = 0; + nl_reply_capped = 1; + reply_error(&reply, request, -EOPNOTSUPP); + } + if ((flags & MSG_DONTWAIT) || nl_nonblocking(fd)) extra = MSG_DONTWAIT; + *rc = send_raw(peer, reply.data, reply.len, extra) < 0 ? -1 : (ssize_t) len; + int saved = errno; + close(peer); + errno = saved; + return 1; +} + +static int collect(const struct msghdr *msg, unsigned char *small, size_t capacity, + unsigned char **buffer, size_t *length) { + size_t used = 0; + if (msg == NULL || (msg->msg_iovlen && msg->msg_iov == NULL)) { + errno = EFAULT; + return 0; + } + if (msg->msg_iovlen > IOV_MAX) { + errno = EMSGSIZE; + return 0; + } + for (size_t index = 0; index < msg->msg_iovlen; index++) { + const struct iovec *part = &msg->msg_iov[index]; + if (part->iov_len && part->iov_base == NULL) { + errno = EFAULT; + return 0; + } + if (part->iov_len > (size_t) SSIZE_MAX - used) { + errno = EMSGSIZE; + return 0; + } + used += part->iov_len; + } + if (used == 0) { + errno = EINVAL; + return 0; + } + *buffer = used <= capacity ? small : malloc(used); + if (*buffer == NULL) { + errno = ENOMEM; + return 0; + } + *length = used; + used = 0; + for (size_t index = 0; index < msg->msg_iovlen; index++) { + const struct iovec *part = &msg->msg_iov[index]; + if (part->iov_len) memcpy(*buffer + used, part->iov_base, part->iov_len); + used += part->iov_len; + } + return 1; +} + +static ssize_t sendmsg_request(int fd, const struct msghdr *msg, int flags) { + unsigned char small[NL_REQUEST_MAX]; + unsigned char *buffer; + size_t length = 0; + if (!collect(msg, small, sizeof(small), &buffer, &length)) { + return -1; + } + ssize_t result; + int handled = deliver(fd, buffer, length, flags, &result); + int saved = errno; + if (buffer != small) free(buffer); + if (!handled) { + saved = EBADF; + result = -1; + } + errno = saved; + return result; +} + +ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) { + static ssize_t (*real)(int, const struct msghdr *, int); + if (bl_nl_owns(fd)) { + int error = msg && msg->msg_name ? nl_destination(msg->msg_name, msg->msg_namelen) : 0; + if (error) { + errno = -error; + return -1; + } + return sendmsg_request(fd, msg, flags); + } + if (real == NULL) real = (ssize_t (*)(int, const struct msghdr *, int)) dlsym(RTLD_NEXT, "sendmsg"); + if (real == NULL) { + errno = ENOSYS; + return -1; + } + return real(fd, msg, flags); +} + +ssize_t sendto(int fd, const void *buffer, size_t length, int flags, + const struct sockaddr *addr, socklen_t addrlen) { + static ssize_t (*real)(int, const void *, size_t, int, const struct sockaddr *, socklen_t); + ssize_t rc; + if (bl_nl_owns(fd)) { + int error = addr ? nl_destination(addr, addrlen) : 0; + if (error) { + errno = -error; + return -1; + } + if (deliver(fd, buffer, length, flags, &rc)) return rc; + } + if (real == NULL) + real = (ssize_t (*)(int, const void *, size_t, int, const struct sockaddr *, socklen_t)) + dlsym(RTLD_NEXT, "sendto"); + if (real == NULL) { + errno = ENOSYS; + return -1; + } + return real(fd, buffer, length, flags, addr, addrlen); +} + +ssize_t send(int fd, const void *buffer, size_t length, int flags) { + static ssize_t (*real)(int, const void *, size_t, int); + ssize_t rc; + if (bl_nl_owns(fd) && deliver(fd, buffer, length, flags, &rc)) return rc; + if (real == NULL) real = (ssize_t (*)(int, const void *, size_t, int)) dlsym(RTLD_NEXT, "send"); + if (real == NULL) { + errno = ENOSYS; + return -1; + } + return real(fd, buffer, length, flags); +} diff --git a/tools/linuxfs/preload/ntsync.c b/tools/linuxfs/preload/ntsync.c index 7454ce15d6..6e012e3b6b 100644 --- a/tools/linuxfs/preload/ntsync.c +++ b/tools/linuxfs/preload/ntsync.c @@ -1442,16 +1442,25 @@ static void ns_received(struct msghdr *msg) { int bl_udevmon_recvmsg(int fd, struct msghdr *msg, int flags, ssize_t (*real_recvmsg)(int, struct msghdr *, int), ssize_t *result) __attribute__((visibility("hidden"))); +int bl_nl_recvmsg(int fd, struct msghdr *msg, int flags, ssize_t (*real_recvmsg)(int, struct msghdr *, int), + ssize_t *result) __attribute__((visibility("hidden"))); +void bl_nl_received(struct msghdr *msg) __attribute__((visibility("hidden"))); +void bl_nl_closed(int fd) __attribute__((visibility("hidden"))); +void bl_nl_range_closed(unsigned int first, unsigned int last) __attribute__((visibility("hidden"))); +int bl_nl_before_dup(int fd, void **state) __attribute__((visibility("hidden"))); +void bl_nl_after_dup(void *state, int fd) __attribute__((visibility("hidden"))); ssize_t recvmsg(int fd, struct msghdr *msg, int flags) { static ssize_t (*real)(int, struct msghdr *, int); if (!real) real = (ssize_t (*)(int, struct msghdr *, int))dlsym(RTLD_NEXT, "recvmsg"); ssize_t answered; + if (msg && bl_nl_recvmsg(fd, msg, flags, real, &answered)) return answered; if (msg && bl_udevmon_recvmsg(fd, msg, flags, real, &answered)) return answered; ssize_t r = real(fd, msg, flags); - if (r >= 0 && msg && msg->msg_control && msg->msg_controllen && ns_on()) { + if (r >= 0 && msg && msg->msg_control && msg->msg_controllen) { int saved = errno; - ns_received(msg); + bl_nl_received(msg); + if (ns_on()) ns_received(msg); errno = saved; } return r; @@ -1465,6 +1474,7 @@ int close(int fd) { if (fd >= 0) bl_fsync_fds_closed((unsigned int)fd, (unsigned int)fd); bl_venc_closed(fd); bl_vdec_closed(fd); + bl_nl_closed(fd); uint64_t *t = __atomic_load_n(&ns_fdt, __ATOMIC_ACQUIRE); if (t && fd >= 0 && fd < NS_FDS && __atomic_load_n(&t[fd], __ATOMIC_ACQUIRE)) ns_forget(fd); int saved = errno; @@ -1480,19 +1490,29 @@ int close(int fd) { int dup2(int oldfd, int newfd) { static int (*real)(int, int); if (!real) real = (int (*)(int, int))dlsym(RTLD_NEXT, "dup2"); + if (oldfd == newfd) return real(oldfd, newfd); + void *nl_state; + if (bl_nl_before_dup(oldfd, &nl_state) != 0) return -1; if (oldfd != newfd && newfd >= 0) bl_fsync_fds_closed((unsigned int)newfd, (unsigned int)newfd); uint64_t *t = __atomic_load_n(&ns_fdt, __ATOMIC_ACQUIRE); if (t && oldfd != newfd && newfd >= 0 && newfd < NS_FDS && __atomic_load_n(&t[newfd], __ATOMIC_ACQUIRE)) ns_forget(newfd); - return real(oldfd, newfd); + int result = real(oldfd, newfd); + bl_nl_after_dup(nl_state, result); + return result; } int dup3(int oldfd, int newfd, int flags) { static int (*real)(int, int, int); if (!real) real = (int (*)(int, int, int))dlsym(RTLD_NEXT, "dup3"); + if (oldfd == newfd) return real(oldfd, newfd, flags); + void *nl_state; + if (bl_nl_before_dup(oldfd, &nl_state) != 0) return -1; if (oldfd != newfd && newfd >= 0) bl_fsync_fds_closed((unsigned int)newfd, (unsigned int)newfd); uint64_t *t = __atomic_load_n(&ns_fdt, __ATOMIC_ACQUIRE); if (t && oldfd != newfd && newfd >= 0 && newfd < NS_FDS && __atomic_load_n(&t[newfd], __ATOMIC_ACQUIRE)) ns_forget(newfd); - return real(oldfd, newfd, flags); + int result = real(oldfd, newfd, flags); + bl_nl_after_dup(nl_state, result); + return result; } static void ns_forget_range(unsigned int first, unsigned int last) { @@ -1513,7 +1533,9 @@ int close_range(unsigned int first, unsigned int last, int flags) { errno = ENOSYS; return -1; } - return real(first, last, flags); + int result = real(first, last, flags); + if (result == 0 && !(flags & CLOSE_RANGE_CLOEXEC)) bl_nl_range_closed(first, last); + return result; } void closefrom(int lowfd) { @@ -1523,7 +1545,10 @@ void closefrom(int lowfd) { bl_fsync_fds_closed((unsigned int)lowfd, ~0u); ns_forget_range((unsigned int)lowfd, ~0u); } - if (real) real(lowfd); + if (real) { + real(lowfd); + if (lowfd >= 0) bl_nl_range_closed((unsigned int)lowfd, ~0u); + } } static void ns_fork_prepare(void) { diff --git a/tools/linuxfs/preload/udevmon.c b/tools/linuxfs/preload/udevmon.c index f0e171a863..2d4e9bf70d 100644 --- a/tools/linuxfs/preload/udevmon.c +++ b/tools/linuxfs/preload/udevmon.c @@ -102,6 +102,21 @@ static int make_stand_in(int type) { return -1; } +__attribute__((visibility("hidden"))) int bl_nl_socket(int type, int *fd); +__attribute__((visibility("hidden"))) int bl_nl_owns(int fd); +__attribute__((visibility("hidden"))) int bl_nl_getsockname(int fd, struct sockaddr *addr, + socklen_t *len, int *rc); +__attribute__((visibility("hidden"))) int bl_nl_getpeername(int fd, struct sockaddr *addr, + socklen_t *len, int *rc); +__attribute__((visibility("hidden"))) int bl_nl_setsockopt(int fd, int level, int option, + const void *value, socklen_t len, + int (*real)(int, int, int, const void *, socklen_t), + int *rc); +__attribute__((visibility("hidden"))) int bl_nl_getsockopt(int fd, int level, int option, + void *value, socklen_t *len, + int (*real)(int, int, int, void *, socklen_t *), + int *rc); + int socket(int domain, int type, int protocol) { static int (*real_socket)(int, int, int); int fd; @@ -111,6 +126,11 @@ int socket(int domain, int type, int protocol) { errno = ENOSYS; return -1; } + if (domain == AF_NETLINK && protocol == NETLINK_ROUTE) { + int route_fd; + bl_nl_socket(type, &route_fd); + return route_fd; + } fd = real_socket(domain, type, protocol); if (fd >= 0 || domain != AF_NETLINK || protocol != NETLINK_KOBJECT_UEVENT) return fd; @@ -129,7 +149,9 @@ __attribute__((visibility("hidden"))) int bl_udevmon_stand_in(int fd) { int getsockname(int fd, struct sockaddr *addr, socklen_t *len) { static int (*real_getsockname)(int, struct sockaddr *, socklen_t *); struct sockaddr_nl nl; + int route_rc; + if (bl_nl_getsockname(fd, addr, len, &route_rc)) return route_rc; if (is_stand_in(fd)) { if (addr == NULL || len == NULL) { errno = EFAULT; @@ -150,21 +172,43 @@ int getsockname(int fd, struct sockaddr *addr, socklen_t *len) { return real_getsockname(fd, addr, len); } +int getpeername(int fd, struct sockaddr *addr, socklen_t *len) { + static int (*real)(int, struct sockaddr *, socklen_t *); + int route_rc; + if (bl_nl_getpeername(fd, addr, len, &route_rc)) return route_rc; + if (real == NULL) real = dlsym(RTLD_NEXT, "getpeername"); + return real(fd, addr, len); +} + int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) { static int (*real_setsockopt)(int, int, int, const void *, socklen_t); + int route_rc; + if (real_setsockopt == NULL) real_setsockopt = dlsym(RTLD_NEXT, "setsockopt"); + if (real_setsockopt == NULL) { + errno = ENOSYS; + return -1; + } + if (bl_nl_setsockopt(fd, level, optname, optval, optlen, real_setsockopt, &route_rc)) return route_rc; if (is_stand_in(fd)) { if (level == SOL_NETLINK) return 0; if (level == SOL_SOCKET && (optname == SO_ATTACH_FILTER || optname == SO_DETACH_FILTER)) return 0; } - if (real_setsockopt == NULL) real_setsockopt = dlsym(RTLD_NEXT, "setsockopt"); - if (real_setsockopt == NULL) { + return real_setsockopt(fd, level, optname, optval, optlen); +} + +int getsockopt(int fd, int level, int option, void *value, socklen_t *len) { + static int (*real)(int, int, int, void *, socklen_t *); + int route_rc; + if (real == NULL) real = dlsym(RTLD_NEXT, "getsockopt"); + if (real == NULL) { errno = ENOSYS; return -1; } - return real_setsockopt(fd, level, optname, optval, optlen); + if (bl_nl_getsockopt(fd, level, option, value, len, real, &route_rc)) return route_rc; + return real(fd, level, option, value, len); } struct monitor_netlink_header { diff --git a/tools/tests/netlink_stubs.c b/tools/tests/netlink_stubs.c new file mode 100644 index 0000000000..58ba3bc61c --- /dev/null +++ b/tools/tests/netlink_stubs.c @@ -0,0 +1,59 @@ +#include <errno.h> +#include <sys/socket.h> + +int bl_nl_socket(int type, int *fd) { + (void)type; + *fd = -1; + errno = ENOSYS; + return 1; +} + +int bl_nl_owns(int fd) { + (void)fd; + return 0; +} + +int bl_nl_bind(int fd, const struct sockaddr *addr, socklen_t len, int *rc) { + (void)fd; + (void)addr; + (void)len; + (void)rc; + return 0; +} + +int bl_nl_connect(int fd, const struct sockaddr *addr, socklen_t len, int *rc) { + return bl_nl_bind(fd, addr, len, rc); +} + +int bl_nl_getsockname(int fd, struct sockaddr *addr, socklen_t *len, int *rc) { + (void)len; + return bl_nl_bind(fd, addr, 0, rc); +} + +int bl_nl_getpeername(int fd, struct sockaddr *addr, socklen_t *len, int *rc) { + return bl_nl_getsockname(fd, addr, len, rc); +} + +int bl_nl_setsockopt(int fd, int level, int option, const void *value, socklen_t len, + int (*real)(int, int, int, const void *, socklen_t), int *rc) { + (void)fd; + (void)level; + (void)option; + (void)value; + (void)len; + (void)real; + (void)rc; + return 0; +} + +int bl_nl_getsockopt(int fd, int level, int option, void *value, socklen_t *len, + int (*real)(int, int, int, void *, socklen_t *), int *rc) { + (void)fd; + (void)level; + (void)option; + (void)value; + (void)len; + (void)real; + (void)rc; + return 0; +} diff --git a/tools/tests/test_binfmt_preload.py b/tools/tests/test_binfmt_preload.py index 2a7ed72769..063345edb2 100644 --- a/tools/tests/test_binfmt_preload.py +++ b/tools/tests/test_binfmt_preload.py @@ -60,7 +60,8 @@ class BinfmtPreloadTest(unittest.TestCase): cls.library = cls.tmp / "libbinfmt.so" subprocess.run(["gcc", "-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror", "-DBINFMT_TEST", '-DBINFMT_HANDLER="%s"' % cls.handler, "-o", str(cls.library), - "-pthread"] + [str(PRELOAD / name) for name in ("binfmt.c", "net.c", "udevmon.c", "pathcache.c", "perms.c", "webhelper.c")] + ["-ldl"], + "-pthread"] + [str(PRELOAD / name) for name in ("binfmt.c", "net.c", "udevmon.c", "pathcache.c", "perms.c", "webhelper.c")] + + [str(Path(__file__).with_name("netlink_stubs.c")), "-ldl"], check=True) source = cls.tmp / "program.c" source.write_text(PROGRAM) diff --git a/tools/tests/test_cdp_guard.py b/tools/tests/test_cdp_guard.py index 48196c1679..8185abed8a 100644 --- a/tools/tests/test_cdp_guard.py +++ b/tools/tests/test_cdp_guard.py @@ -16,7 +16,8 @@ class CdpGuardTest(unittest.TestCase): def setUpClass(cls): cls.build = tempfile.TemporaryDirectory() cls.library = Path(cls.build.name) / "net.so" - subprocess.run(["cc", "-shared", "-fPIC", "-O2", str(SOURCE), str(SOURCE.parent / "binfmt.c"), str(SOURCE.parent / "webhelper.c"), "-x", "c", "-", "-ldl", + subprocess.run(["cc", "-shared", "-fPIC", "-O2", str(SOURCE), str(SOURCE.parent / "binfmt.c"), str(SOURCE.parent / "webhelper.c"), + str(Path(__file__).with_name("netlink_stubs.c")), "-x", "c", "-", "-ldl", "-o", str(cls.library)], input=b"int bl_udevmon_stand_in(int fd) { return 0; }", check=True, capture_output=True) diff --git a/tools/tests/test_netlink_preload.py b/tools/tests/test_netlink_preload.py new file mode 100644 index 0000000000..64c3b9c97a --- /dev/null +++ b/tools/tests/test_netlink_preload.py @@ -0,0 +1,1238 @@ +import errno +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + +PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload" + +SHIM = r""" +#define _GNU_SOURCE +#include <dlfcn.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <sys/syscall.h> +#include <unistd.h> + +#ifndef SYS_close_range +#define SYS_close_range 436 +#endif + +static pthread_mutex_t *netlink_mutex; +static __thread int probe_mode; +static __thread unsigned probe_counts[5]; + +void test_probe_begin(int capture) { + memset(probe_counts, 0, sizeof(probe_counts)); + probe_mode = capture ? 1 : 2; +} + +void test_probe_end(unsigned *counts) { + probe_mode = 0; + memcpy(counts, probe_counts, sizeof(probe_counts)); +} + +int pthread_mutex_lock(pthread_mutex_t *mutex) { + static int (*real)(pthread_mutex_t *); + if (!real) real = dlsym(RTLD_NEXT, "pthread_mutex_lock"); + if (probe_mode == 1) netlink_mutex = mutex; + if (probe_mode == 2 && mutex == netlink_mutex) probe_counts[0]++; + return real(mutex); +} + +int getsockname(int fd, struct sockaddr *addr, socklen_t *len) { + static int (*real)(int, struct sockaddr *, socklen_t *); + if (!real) real = dlsym(RTLD_NEXT, "getsockname"); + if (probe_mode == 2) probe_counts[1]++; + return real(fd, addr, len); +} + +int getpeername(int fd, struct sockaddr *addr, socklen_t *len) { + static int (*real)(int, struct sockaddr *, socklen_t *); + if (!real) real = dlsym(RTLD_NEXT, "getpeername"); + if (probe_mode == 2) probe_counts[2]++; + return real(fd, addr, len); +} + +int fstat(int fd, struct stat *status) { + static int (*real)(int, struct stat *); + if (!real) real = dlsym(RTLD_NEXT, "fstat"); + if (probe_mode == 2) probe_counts[3]++; + return real(fd, status); +} + +#ifdef __GLIBC__ +int __fxstat(int version, int fd, struct stat *status) { + static int (*real)(int, int, struct stat *); + if (!real) real = dlsym(RTLD_NEXT, "__fxstat"); + if (probe_mode == 2) probe_counts[3]++; + return real(version, fd, status); +} +#endif + +int getsockopt(int fd, int level, int option, void *value, socklen_t *len) { + static int (*real)(int, int, int, void *, socklen_t *); + if (!real) real = dlsym(RTLD_NEXT, "getsockopt"); + if (probe_mode == 2) probe_counts[4]++; + return real(fd, level, option, value, len); +} + +FILE *fopen(const char *path, const char *mode) { + static FILE *(*real)(const char *, const char *); + if (!real) real = dlsym(RTLD_NEXT, "fopen"); + const char *snapshot = getenv("NETLINK_TEST_SNAPSHOT"); + if (snapshot && !strcmp(path, "/etc/droiddeck-net")) path = snapshot; + return real(path, mode); +} + +int close_range(unsigned int first, unsigned int last, int flags) { + return syscall(SYS_close_range, (long)first, (long)last, (long)flags, 0L, 0L, 0L); +} + +void closefrom(int first) { + syscall(SYS_close_range, (long)first, (long)~0u, 0L, 0L, 0L, 0L); +} +""" + +PROGRAM = r""" +#define _GNU_SOURCE +#include <arpa/inet.h> +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <linux/netlink.h> +#include <linux/rtnetlink.h> +#include <net/if.h> +#include <pthread.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/resource.h> +#include <sys/socket.h> +#include <sys/syscall.h> +#include <sys/wait.h> +#include <unistd.h> + +static void require(int condition, const char *label) { + if (!condition) { + fprintf(stderr, "%s: errno=%d\n", label, errno); + exit(1); + } +} + +static int route_socket(void) { + int descriptor = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + struct sockaddr_nl address = {.nl_family = AF_NETLINK}; + require(descriptor >= 0, "socket"); + require(bind(descriptor, (struct sockaddr *)&address, sizeof(address)) == 0, "bind"); + return descriptor; +} + +static unsigned port_of(int descriptor) { + struct sockaddr_nl address; + socklen_t length = sizeof(address); + require(getsockname(descriptor, (struct sockaddr *)&address, &length) == 0, "getsockname"); + require(length == sizeof(address) && address.nl_family == AF_NETLINK, "socket identity"); + return address.nl_pid; +} + +static void send_link(int descriptor, int index, unsigned flags) { + struct { + struct nlmsghdr header; + struct ifinfomsg info; + } query = { + .header = {.nlmsg_len = sizeof(query), .nlmsg_type = RTM_GETLINK, + .nlmsg_flags = NLM_F_REQUEST | flags, .nlmsg_seq = 42}, + .info = {.ifi_index = index} + }; + struct sockaddr_nl destination = {.nl_family = AF_NETLINK}; + require(sendto(descriptor, &query, sizeof(query), 0, + (struct sockaddr *)&destination, sizeof(destination)) == sizeof(query), "send link"); +} + +struct autobind_sender { + int descriptor; + pthread_barrier_t *barrier; +}; + +static ssize_t receive(int descriptor, unsigned char *buffer, size_t capacity); + +static void *send_after_barrier(void *argument) { + struct autobind_sender *sender = argument; + int result = pthread_barrier_wait(sender->barrier); + require(result == 0 || result == PTHREAD_BARRIER_SERIAL_THREAD, "autobind barrier"); + send_link(sender->descriptor, 1, NLM_F_ACK); + return NULL; +} + +static void autobind_race_test(void) { + for (int round = 0; round < 50; round++) { + int descriptor = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + require(descriptor >= 0 && port_of(descriptor) == 0, "unbound netlink socket"); + pthread_barrier_t barrier; + require(pthread_barrier_init(&barrier, NULL, 2) == 0, "autobind barrier init"); + struct autobind_sender sender = {.descriptor = descriptor, .barrier = &barrier}; + pthread_t first, second; + require(pthread_create(&first, NULL, send_after_barrier, &sender) == 0, "autobind first thread"); + require(pthread_create(&second, NULL, send_after_barrier, &sender) == 0, "autobind second thread"); + require(pthread_join(first, NULL) == 0 && pthread_join(second, NULL) == 0, "autobind threads"); + require(pthread_barrier_destroy(&barrier) == 0, "autobind barrier destroy"); + require(port_of(descriptor) != 0, "concurrent autobind assigned one port"); + close(descriptor); + } +} + +static void vfork_close_range_test(void) { + int descriptor = route_socket(); + pid_t child = vfork(); + require(child >= 0, "vfork"); + if (child == 0) { + _exit(close_range(3, ~0u, 0) == 0 ? 0 : 1); + } + int status; + require(waitpid(child, &status, 0) == child && WIFEXITED(status) && WEXITSTATUS(status) == 0, + "vfork close range child"); + send_link(descriptor, 1, NLM_F_ACK); + unsigned char buffer[4096]; + ssize_t received = receive(descriptor, buffer, sizeof(buffer)); + require(received > 0 && ((struct nlmsghdr *) buffer)->nlmsg_type == RTM_NEWLINK, + "netlink bookkeeping survives vfork close range"); + close(descriptor); +} + +static void named_link_test(const char *name, const char *mode) { + int descriptor = route_socket(); + struct { + struct nlmsghdr header; + struct ifinfomsg info; + struct rtattr attr; + char name[IFNAMSIZ + 1]; + } query = { + .header = {.nlmsg_type = RTM_GETLINK, .nlmsg_flags = NLM_F_REQUEST, .nlmsg_seq = 42}, + .attr = {.rta_type = IFLA_IFNAME} + }; + size_t length = strlen(name) + 1; + require(length <= sizeof(query.name), "name length"); + memcpy(query.name, name, length); + if (!strcmp(mode, "unterminated")) length--; + if (!strcmp(mode, "oversized")) { + memset(query.name, 'x', sizeof(query.name)); + query.name[sizeof(query.name) - 1] = '\0'; + length = sizeof(query.name); + } + query.attr.rta_len = RTA_LENGTH(length); + query.header.nlmsg_len = NLMSG_LENGTH(sizeof(query.info)) + RTA_SPACE(length); + if (!strcmp(mode, "missing")) query.header.nlmsg_len = NLMSG_LENGTH(sizeof(query.info)); + if (!strcmp(mode, "index")) query.info.ifi_index = 1; + struct sockaddr_nl destination = {.nl_family = AF_NETLINK}; + require(sendto(descriptor, &query, query.header.nlmsg_len, 0, + (struct sockaddr *)&destination, sizeof(destination)) == query.header.nlmsg_len, + "send named link"); + unsigned char buffer[4096]; + require(recv(descriptor, buffer, sizeof(buffer), MSG_DONTWAIT) > 0, "receive named link"); + struct nlmsghdr *header = (struct nlmsghdr *)buffer; + require(header->nlmsg_seq == 42, "named link sequence"); + if (header->nlmsg_type == NLMSG_ERROR) { + printf("error %d\n", ((struct nlmsgerr *)NLMSG_DATA(header))->error); + } else { + require(header->nlmsg_type == RTM_NEWLINK, "named link reply"); + struct ifinfomsg *info = NLMSG_DATA(header); + int remaining = IFLA_PAYLOAD(header); + const char *reply_name = NULL; + for (struct rtattr *attr = IFLA_RTA(info); RTA_OK(attr, remaining); + attr = RTA_NEXT(attr, remaining)) { + if (attr->rta_type == IFLA_IFNAME) reply_name = RTA_DATA(attr); + } + require(reply_name != NULL, "reply interface name"); + printf("link %d %s\n", info->ifi_index, reply_name); + } + close(descriptor); +} + +static ssize_t receive(int descriptor, unsigned char *buffer, size_t capacity) { + struct sockaddr_nl address; + memset(&address, 0xff, sizeof(address)); + socklen_t length = sizeof(address); + ssize_t received = recvfrom(descriptor, buffer, capacity, MSG_DONTWAIT, + (struct sockaddr *)&address, &length); + require(received > 0, "recvfrom"); + require(length == sizeof(address) && address.nl_family == AF_NETLINK && address.nl_pid == 0, + "kernel source"); + return received; +} + +static void usable(int descriptor) { + send_link(descriptor, 1, 0); + unsigned port = port_of(descriptor); + unsigned char buffer[4096]; + receive(descriptor, buffer, sizeof(buffer)); + struct nlmsghdr *header = (struct nlmsghdr *)buffer; + require(header->nlmsg_type == RTM_NEWLINK && header->nlmsg_pid == port, "usable socket"); +} + +static void socket_info(int descriptor, int kind) { + int value; + socklen_t length = sizeof(value); + require(getsockopt(descriptor, SOL_SOCKET, SO_TYPE, &value, &length) == 0 + && length == sizeof(value) && value == kind, "reported socket type"); + length = sizeof(value); + require(getsockopt(descriptor, SOL_SOCKET, SO_DOMAIN, &value, &length) == 0 + && value == AF_NETLINK, "reported socket domain"); + length = sizeof(value); + require(getsockopt(descriptor, SOL_SOCKET, SO_PROTOCOL, &value, &length) == 0 + && value == NETLINK_ROUTE, "reported socket protocol"); + length = 1; + require(getsockopt(descriptor, SOL_SOCKET, SO_TYPE, &value, &length) == 0 + && length == 1, "short socket option"); + require(getsockopt(descriptor, SOL_SOCKET, SO_TYPE, NULL, &length) == -1 + && errno == EFAULT, "invalid socket option buffer"); +} + +static void (*probe_begin)(int); +static void (*probe_end)(unsigned *); + +static void *ordinary_traffic(void *argument) { + int kind = (int)(uintptr_t)argument; + unsigned counts[5]; + probe_begin(0); + int listener = socket(AF_INET, kind, 0); + int client = socket(AF_INET, kind, 0); + require(listener >= 0 && client >= 0, "ordinary sockets"); + struct sockaddr_in address = {.sin_family = AF_INET, .sin_addr.s_addr = htonl(INADDR_LOOPBACK)}; + require(bind(listener, (struct sockaddr *)&address, sizeof(address)) == 0, "ordinary bind"); + socklen_t length = sizeof(address); + require(getsockname(listener, (struct sockaddr *)&address, &length) == 0, "ordinary address"); + if (kind == SOCK_STREAM) require(listen(listener, 1) == 0, "ordinary listen"); + require(connect(client, (struct sockaddr *)&address, sizeof(address)) == 0, "ordinary connect"); + int server = kind == SOCK_STREAM ? accept(listener, NULL, NULL) : listener; + require(server >= 0, "ordinary server"); + probe_end(counts); + require(counts[0] == 0, "ordinary setup avoids netlink lock"); + + probe_begin(0); + const int rounds = 32; + for (int round = 0; round < rounds; round++) { + char buffer; + require(send(client, "x", 1, 0) == 1, "ordinary send"); + require(recv(server, &buffer, 1, 0) == 1 && buffer == 'x', "ordinary recv"); + struct sockaddr *destination = kind == SOCK_DGRAM ? (struct sockaddr *)&address : NULL; + socklen_t destination_length = destination ? sizeof(address) : 0; + require(sendto(client, "y", 1, 0, destination, destination_length) == 1, "ordinary sendto"); + struct sockaddr_storage source; + length = sizeof(source); + require(recvfrom(server, &buffer, 1, 0, (struct sockaddr *)&source, &length) == 1 + && buffer == 'y', "ordinary recvfrom"); + struct iovec part = {.iov_base = "z", .iov_len = 1}; + struct msghdr message = {.msg_name = destination, .msg_namelen = destination_length, + .msg_iov = &part, .msg_iovlen = 1}; + require(sendmsg(client, &message, 0) == 1, "ordinary sendmsg"); + part.iov_base = &buffer; + message.msg_name = &source; + message.msg_namelen = sizeof(source); + require(recvmsg(server, &message, 0) == 1 && buffer == 'z', "ordinary recvmsg"); + length = sizeof(source); + require(getpeername(client, (struct sockaddr *)&source, &length) == 0, "ordinary peer"); + const int options[] = {SO_TYPE, SO_DOMAIN, SO_PROTOCOL}; + const int expected[] = {kind, AF_INET, kind == SOCK_DGRAM ? IPPROTO_UDP : IPPROTO_TCP}; + for (size_t index = 0; index < sizeof(options) / sizeof(options[0]); index++) { + int value; + length = sizeof(value); + require(getsockopt(client, SOL_SOCKET, options[index], &value, &length) == 0 + && value == expected[index], "ordinary socket option"); + } + int enabled = 1; + require(setsockopt(client, SOL_SOCKET, SO_KEEPALIVE, &enabled, sizeof(enabled)) == 0, + "ordinary setsockopt"); + int alias = dup(client); + require(alias >= 0 && dup2(client, alias) == alias + && dup3(client, alias, O_CLOEXEC) == alias, "ordinary duplicates"); + close(alias); + alias = fcntl(client, F_DUPFD, 0); + require(alias >= 0, "ordinary fcntl duplicate"); + close(alias); + alias = fcntl(client, F_DUPFD_CLOEXEC, 0); + require(alias >= 0, "ordinary cloexec duplicate"); + close(alias); + } + probe_end(counts); + require(counts[0] == 0, "ordinary traffic avoids netlink lock"); + require(counts[1] == 0, "ordinary traffic avoids restoration getsockname"); + require(counts[2] == (unsigned)rounds, "ordinary traffic has only requested getpeername"); + require(counts[3] == 0, "ordinary traffic avoids restoration fstat"); + require(counts[4] == (unsigned)rounds * 3, "ordinary socket options use one syscall each"); + close(client); + close(server); + if (server != listener) close(listener); + return NULL; +} + +static void hotpath_test(int active) { + probe_begin = dlsym(RTLD_DEFAULT, "test_probe_begin"); + probe_end = dlsym(RTLD_DEFAULT, "test_probe_end"); + require(probe_begin && probe_end, "probe symbols"); + unsigned counts[5]; + probe_begin(1); + int descriptor = route_socket(); + probe_end(counts); + if (!active) close(descriptor); + pthread_t threads[4]; + for (size_t index = 0; index < sizeof(threads) / sizeof(threads[0]); index++) { + int kind = index % 2 ? SOCK_STREAM : SOCK_DGRAM; + require(pthread_create(&threads[index], NULL, ordinary_traffic, (void *)(uintptr_t)kind) == 0, + "traffic thread"); + } + for (size_t index = 0; index < sizeof(threads) / sizeof(threads[0]); index++) + require(pthread_join(threads[index], NULL) == 0, "join traffic thread"); + if (active) { + usable(descriptor); + close(descriptor); + } +} + +static void transferred_test(const char *mode) { + int transport[2]; + require(socketpair(AF_UNIX, SOCK_DGRAM, 0, transport) == 0, "rights transport"); + pid_t child = fork(); + require(child >= 0, "rights fork"); + if (child == 0) { + close(transport[0]); + unsigned port; + struct iovec part = {.iov_base = &port, .iov_len = sizeof(port)}; + union { + struct cmsghdr align; + unsigned char bytes[CMSG_SPACE(sizeof(int))]; + } control; + struct msghdr message = {.msg_iov = &part, .msg_iovlen = 1, + .msg_control = control.bytes, .msg_controllen = sizeof(control.bytes)}; + ssize_t received = !strcmp(mode, "received") ? recvmsg(transport[1], &message, 0) : + syscall(SYS_recvmsg, (long)transport[1], &message, 0L, 0L, 0L, 0L); + require(received == sizeof(port), "rights receive"); + struct cmsghdr *header = CMSG_FIRSTHDR(&message); + require(header && header->cmsg_level == SOL_SOCKET && header->cmsg_type == SCM_RIGHTS + && header->cmsg_len == CMSG_LEN(sizeof(int)), "rights header"); + int descriptor; + memcpy(&descriptor, CMSG_DATA(header), sizeof(descriptor)); + struct sockaddr_nl address = {.nl_family = AF_NETLINK}; + if (!strcmp(mode, "domain")) { + int domain; + socklen_t length = sizeof(domain); + require(getsockopt(descriptor, SOL_SOCKET, SO_DOMAIN, &domain, &length) == 0 + && domain == AF_NETLINK, "rights domain discovery"); + } else if (!strcmp(mode, "bind")) { + address.nl_pid = port; + require(bind(descriptor, (struct sockaddr *)&address, sizeof(address)) == 0, + "rights bind discovery"); + } else if (!strcmp(mode, "connect")) { + require(connect(descriptor, (struct sockaddr *)&address, sizeof(address)) == 0, + "rights connect discovery"); + } else if (!strcmp(mode, "option")) { + int enabled = 1; + require(setsockopt(descriptor, SOL_NETLINK, NETLINK_EXT_ACK, &enabled, sizeof(enabled)) == 0, + "rights option discovery"); + } + usable(descriptor); + require(port_of(descriptor) == port, "rights port retained"); + socket_info(descriptor, SOCK_RAW); + close(descriptor); + close(transport[1]); + _exit(0); + } + close(transport[1]); + int descriptor = route_socket(); + unsigned port = port_of(descriptor); + struct iovec part = {.iov_base = &port, .iov_len = sizeof(port)}; + union { + struct cmsghdr align; + unsigned char bytes[CMSG_SPACE(sizeof(int))]; + } control = {0}; + struct msghdr message = {.msg_iov = &part, .msg_iovlen = 1, + .msg_control = control.bytes, .msg_controllen = sizeof(control.bytes)}; + struct cmsghdr *header = CMSG_FIRSTHDR(&message); + header->cmsg_level = SOL_SOCKET; + header->cmsg_type = SCM_RIGHTS; + header->cmsg_len = CMSG_LEN(sizeof(descriptor)); + memcpy(CMSG_DATA(header), &descriptor, sizeof(descriptor)); + require(sendmsg(transport[0], &message, 0) == sizeof(port), "rights send"); + int status; + require(waitpid(child, &status, 0) == child && WIFEXITED(status) && WEXITSTATUS(status) == 0, + "rights child"); + usable(descriptor); + close(descriptor); + close(transport[0]); +} + +static void socket_types_test(void) { + const int kinds[] = {SOCK_RAW, SOCK_DGRAM}; + for (size_t index = 0; index < sizeof(kinds) / sizeof(kinds[0]); index++) { + int descriptor = socket(AF_NETLINK, kinds[index], NETLINK_ROUTE); + require(descriptor >= 0, "supported socket type"); + require(port_of(descriptor) == 0, "unbound port"); + require((fcntl(descriptor, F_GETFD) & FD_CLOEXEC) == 0, "caller cloexec flag"); + socket_info(descriptor, kinds[index]); + usable(descriptor); + close(descriptor); + descriptor = socket(AF_NETLINK, kinds[index] | SOCK_CLOEXEC | SOCK_NONBLOCK, NETLINK_ROUTE); + require(descriptor >= 0 && (fcntl(descriptor, F_GETFD) & FD_CLOEXEC) + && (fcntl(descriptor, F_GETFL) & O_NONBLOCK), "requested socket flags"); + socket_info(descriptor, kinds[index]); + close(descriptor); + } + require(socket(AF_NETLINK, SOCK_STREAM, NETLINK_ROUTE) == -1 + && errno == ESOCKTNOSUPPORT, "stream rejected"); + require(socket(AF_NETLINK, SOCK_SEQPACKET, NETLINK_ROUTE) == -1 + && errno == ESOCKTNOSUPPORT, "seqpacket rejected"); + require(socket(AF_NETLINK, SOCK_RAW | 0x40000000, NETLINK_ROUTE) == -1 + && errno == EINVAL, "unknown socket flag rejected"); + require(socket(AF_NETLINK, 15, NETLINK_ROUTE) == -1 && errno == EINVAL, "invalid socket type"); +} + +static void ports_test(int forked) { + int descriptors[32]; + unsigned ports[32]; + for (int index = 0; index < 32; index++) { + descriptors[index] = route_socket(); + ports[index] = port_of(descriptors[index]); + require(ports[index] != 0, "bound port"); + for (int previous = 0; previous < index; previous++) + require(ports[index] != ports[previous], "unique automatic port"); + } + int duplicate = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); + require(duplicate >= 0, "explicit bind socket"); + struct sockaddr_nl address = {.nl_family = AF_NETLINK, .nl_pid = ports[0]}; + require(bind(duplicate, (struct sockaddr *)&address, sizeof(address)) == -1 + && errno == EADDRINUSE && port_of(duplicate) == 0, "duplicate explicit port"); + if (forked) { + pid_t child = fork(); + require(child >= 0, "port fork"); + if (child == 0) { + for (int index = 0; index < 32; index++) close(descriptors[index]); + require(bind(duplicate, (struct sockaddr *)&address, sizeof(address)) == -1 + && errno == EADDRINUSE, "cross process duplicate port"); + close(duplicate); + _exit(0); + } + int status; + require(waitpid(child, &status, 0) == child && WIFEXITED(status) && WEXITSTATUS(status) == 0, + "port child"); + } + int alias = dup(descriptors[0]); + close(descriptors[0]); + require(bind(duplicate, (struct sockaddr *)&address, sizeof(address)) == -1 + && errno == EADDRINUSE, "alias keeps port reserved"); + close(alias); + require(bind(duplicate, (struct sockaddr *)&address, sizeof(address)) == 0 + && port_of(duplicate) == ports[0], "closed port reused"); + require(bind(duplicate, (struct sockaddr *)&address, sizeof(address)) == 0, "same port rebind"); + address.nl_pid = 0; + require(bind(duplicate, (struct sockaddr *)&address, sizeof(address)) == -1 && errno == EINVAL, + "explicit zero port rebind denied"); + address.nl_pid = ports[0] + 1; + require(bind(duplicate, (struct sockaddr *)&address, sizeof(address)) == -1 + && errno == EINVAL && port_of(duplicate) == ports[0], "different port rebind denied"); + usable(duplicate); + close(duplicate); + for (int index = 1; index < 32; index++) { + usable(descriptors[index]); + close(descriptors[index]); + } +} + +static void batch_test(int oversized) { + int descriptor = route_socket(); + struct query { + struct nlmsghdr header; + struct ifinfomsg info; + } queries[128]; + int count = oversized ? 128 : 40; + for (int index = 0; index < count; index++) { + memset(&queries[index], 0, sizeof(queries[index])); + queries[index].header.nlmsg_len = sizeof(queries[index]); + queries[index].header.nlmsg_type = RTM_GETLINK; + queries[index].header.nlmsg_flags = NLM_F_REQUEST; + queries[index].header.nlmsg_seq = index + 1; + queries[index].info.ifi_index = 1; + } + struct iovec parts[2] = { + {.iov_base = queries, .iov_len = 256}, + {.iov_base = (unsigned char *)queries + 256, .iov_len = count * sizeof(queries[0]) - 256} + }; + struct sockaddr_nl address = {.nl_family = AF_NETLINK}; + struct msghdr message = {.msg_name = &address, .msg_namelen = sizeof(address), + .msg_iov = parts, .msg_iovlen = 2}; + ssize_t sent = sendmsg(descriptor, &message, 0); + unsigned char buffer[8192]; + if (oversized) { + require(sent == -1 && errno == EMSGSIZE, "oversized reply rejected"); + require(recv(descriptor, buffer, sizeof(buffer), MSG_DONTWAIT) == -1 && errno == EAGAIN, + "no partial batch reply"); + } else { + require(sent == count * sizeof(queries[0]), "large scatter gather request"); + int remaining = (int)receive(descriptor, buffer, sizeof(buffer)); + int replies = 0; + for (struct nlmsghdr *header = (struct nlmsghdr *)buffer; + NLMSG_OK(header, remaining); header = NLMSG_NEXT(header, remaining)) { + require(header->nlmsg_type == RTM_NEWLINK && header->nlmsg_seq == (unsigned)replies + 1, + "batch reply sequence"); + replies++; + } + require(replies == count, "complete batch"); + } + parts[0].iov_base = NULL; + require(sendmsg(descriptor, &message, 0) == -1 && errno == EFAULT, "invalid iov base"); + parts[0].iov_base = queries; + parts[0].iov_len = SIZE_MAX; + require(sendmsg(descriptor, &message, 0) == -1 && errno == EMSGSIZE, "iov length overflow"); + require(sendmsg(descriptor, NULL, 0) == -1 && errno == EFAULT, "invalid message"); + usable(descriptor); + close(descriptor); +} + +static void inherited_test(int argc, char **argv) { + require(argc == 6, "inherited arguments"); + int descriptor = atoi(argv[2]), closed = atoi(argv[4]), datagram = atoi(argv[5]); + unsigned port = (unsigned)strtoul(argv[3], NULL, 10); + require(fcntl(closed, F_GETFD) == -1 && errno == EBADF, "cloexec descriptor closed"); + require(port_of(descriptor) == port && !(fcntl(descriptor, F_GETFD) & FD_CLOEXEC), + "inherited bound port"); + socket_info(descriptor, SOCK_RAW); + socket_info(datagram, SOCK_DGRAM); + require(fcntl(datagram, F_GETFL) & O_NONBLOCK, "inherited nonblocking flag"); + unsigned char buffer[4096]; + receive(descriptor, buffer, sizeof(buffer)); + require(((struct nlmsghdr *)buffer)->nlmsg_type == RTM_NEWLINK, "queued reply survives exec"); + send_link(descriptor, 9999, NLM_F_ACK); + receive(descriptor, buffer, sizeof(buffer)); + require(((struct nlmsghdr *)buffer)->nlmsg_type == NLMSG_ERROR + && (((struct nlmsghdr *)buffer)->nlmsg_flags & NLM_F_CAPPED), "cap ack survives exec"); + usable(descriptor); + usable(datagram); + int fresh = route_socket(); + require(port_of(fresh) != port && port_of(fresh) != port_of(datagram), "ports after exec"); + close(fresh); + close(descriptor); + close(datagram); +} + +static void exec_test(const char *program, int forked) { + int descriptor = route_socket(); + int enabled = 1; + require(setsockopt(descriptor, SOL_NETLINK, NETLINK_CAP_ACK, &enabled, sizeof(enabled)) == 0, + "inherited cap ack"); + unsigned port = port_of(descriptor); + int alias = fcntl(descriptor, F_DUPFD, 100); + int closed = fcntl(descriptor, F_DUPFD_CLOEXEC, 200); + require(alias >= 100 && closed >= 200, "exec aliases"); + close(descriptor); + int datagram = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE); + require(datagram >= 0, "exec datagram"); + send_link(alias, 1, 0); + char descriptor_arg[32], port_arg[32], closed_arg[32], datagram_arg[32]; + snprintf(descriptor_arg, sizeof(descriptor_arg), "%d", alias); + snprintf(port_arg, sizeof(port_arg), "%u", port); + snprintf(closed_arg, sizeof(closed_arg), "%d", closed); + snprintf(datagram_arg, sizeof(datagram_arg), "%d", datagram); + char *arguments[] = {(char *)program, "inherited", descriptor_arg, port_arg, closed_arg, datagram_arg, NULL}; + if (forked) { + pid_t child = fork(); + require(child >= 0, "exec fork"); + if (child > 0) { + int status; + require(waitpid(child, &status, 0) == child && WIFEXITED(status) && WEXITSTATUS(status) == 0, + "exec child"); + usable(alias); + usable(datagram); + close(alias); + close(closed); + close(datagram); + return; + } + } + execv(program, arguments); + require(0, "exec"); +} + +static void cloexec_test(const char *program) { + int descriptor = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE); + require(descriptor >= 0, "cloexec socket"); + struct sockaddr_nl address = {.nl_family = AF_NETLINK, .nl_pid = (unsigned)getpid()}; + require(bind(descriptor, (struct sockaddr *)&address, sizeof(address)) == 0, "cloexec bind"); + char port_arg[32]; + snprintf(port_arg, sizeof(port_arg), "%u", address.nl_pid); + char *arguments[] = {(char *)program, "rebind_after_exec", port_arg, NULL}; + execv(program, arguments); + require(0, "cloexec exec"); +} + +static void ack_test(const char *mode) { + int descriptor = route_socket(); + int capped = !strcmp(mode, "capped"); + if (capped) { + int enabled = 1; + require(setsockopt(descriptor, SOL_NETLINK, NETLINK_CAP_ACK, &enabled, sizeof(enabled)) == 0, + "cap ack"); + } + int rejected = !strcmp(mode, "error") || capped; + send_link(descriptor, rejected ? 9999 : 1, NLM_F_ACK); + unsigned char buffer[4096]; + int remaining = (int)receive(descriptor, buffer, sizeof(buffer)); + int acknowledgements = 0, links = 0; + for (struct nlmsghdr *header = (struct nlmsghdr *)buffer; + NLMSG_OK(header, remaining); header = NLMSG_NEXT(header, remaining)) { + require(header->nlmsg_seq == 42 && header->nlmsg_pid == port_of(descriptor), "ack identity"); + if (header->nlmsg_type == RTM_NEWLINK) links++; + if (header->nlmsg_type != NLMSG_ERROR) continue; + struct nlmsgerr *reply = NLMSG_DATA(header); + require(reply->error == (rejected ? -ENODEV : 0), "ack error"); + require(reply->msg.nlmsg_type == RTM_GETLINK && reply->msg.nlmsg_seq == 42, "ack request"); + require(!!(header->nlmsg_flags & NLM_F_CAPPED) == (!rejected || capped), "ack capped flag"); + size_t extra = rejected && !capped ? sizeof(struct ifinfomsg) : 0; + require(header->nlmsg_len == NLMSG_LENGTH(sizeof(*reply) + extra), "ack payload length"); + acknowledgements++; + } + require(acknowledgements == 1 && links == !rejected, "one acknowledgement"); + close(descriptor); +} + +static void options_test(void) { + int descriptor = route_socket(); + int group = RTNLGRP_LINK; + require(setsockopt(descriptor, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &group, sizeof(group)) == -1 + && errno == EACCES, "membership denied"); + require(setsockopt(descriptor, SOL_NETLINK, NETLINK_PKTINFO, &group, sizeof(group)) == -1 + && errno == ENOPROTOOPT, "unsupported option"); + require(setsockopt(descriptor, SOL_NETLINK, NETLINK_EXT_ACK, &group, sizeof(group)) == 0, "ext ack"); + struct timeval timeout = {.tv_usec = 30000}; + require(setsockopt(descriptor, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == 0, "receive timeout"); + memset(&timeout, 0, sizeof(timeout)); + socklen_t length = sizeof(timeout); + require(getsockopt(descriptor, SOL_SOCKET, SO_RCVTIMEO, &timeout, &length) == 0 + && timeout.tv_usec > 0, "timeout retained"); + unsigned char buffer[4096]; + require(recv(descriptor, buffer, sizeof(buffer), 0) == -1 + && (errno == EAGAIN || errno == EWOULDBLOCK), "receive times out"); + close(descriptor); +} + +static void dump_test(void) { + int descriptor = route_socket(); + send_link(descriptor, 0, NLM_F_DUMP | NLM_F_ACK); + unsigned char buffer[4096]; + int remaining = (int)receive(descriptor, buffer, sizeof(buffer)); + int links = 0, done = 0; + for (struct nlmsghdr *header = (struct nlmsghdr *)buffer; + NLMSG_OK(header, remaining); header = NLMSG_NEXT(header, remaining)) { + require(header->nlmsg_seq == 42 && (header->nlmsg_flags & NLM_F_MULTI), "dump header"); + if (header->nlmsg_type == RTM_NEWLINK) links++; + else { + require(header->nlmsg_type == NLMSG_DONE && *(int *)NLMSG_DATA(header) == 0, + "dump completion"); + done++; + } + } + require(links == 2 && done == 1, "dump results"); + close(descriptor); +} + +static void send_timeout_test(int nonblocking) { + int descriptor = route_socket(); + if (nonblocking) { + require(fcntl(descriptor, F_SETFL, O_NONBLOCK) == 0, "nonblocking"); + } else { + struct timeval timeout = {.tv_usec = 30000}; + require(setsockopt(descriptor, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) == 0, + "send timeout"); + } + struct { + struct nlmsghdr header; + struct ifinfomsg info; + } query = { + .header = {.nlmsg_len = sizeof(query), .nlmsg_type = RTM_GETLINK, + .nlmsg_flags = NLM_F_REQUEST, .nlmsg_seq = 42}, + .info = {.ifi_index = 1} + }; + for (int count = 0; count < 10000; count++) { + ssize_t result = send(descriptor, &query, sizeof(query), 0); + if (result == -1) { + require(errno == EAGAIN || errno == EWOULDBLOCK, "full queue would block"); + close(descriptor); + return; + } + require(result == sizeof(query), "queued send"); + } + require(0, "queue filled"); +} + +static void connect_test(void) { + int descriptor = route_socket(); + struct sockaddr_nl address = {.nl_family = AF_NETLINK}; + socklen_t length = sizeof(address); + require(getpeername(descriptor, (struct sockaddr *)&address, &length) == 0 + && address.nl_family == AF_NETLINK && address.nl_pid == 0, "default kernel peer"); + require(connect(descriptor, (struct sockaddr *)&address, sizeof(address)) == 0, "connect kernel"); + memset(&address, 0xff, sizeof(address)); + length = sizeof(address); + require(getpeername(descriptor, (struct sockaddr *)&address, &length) == 0 + && length == sizeof(address) && address.nl_family == AF_NETLINK + && address.nl_pid == 0 && address.nl_groups == 0, "kernel peer"); + usable(descriptor); + address.nl_pid = 1234; + require(connect(descriptor, (struct sockaddr *)&address, sizeof(address)) == -1 + && errno == ECONNREFUSED, "userspace peer refused"); + address.nl_pid = 0; + address.nl_groups = 1; + require(connect(descriptor, (struct sockaddr *)&address, sizeof(address)) == -1 + && errno == EACCES, "multicast peer denied"); + struct sockaddr disconnect = {.sa_family = AF_UNSPEC}; + require(connect(descriptor, &disconnect, sizeof(disconnect)) == 0, "disconnect"); + length = sizeof(address); + require(getpeername(descriptor, (struct sockaddr *)&address, &length) == 0 + && address.nl_family == AF_NETLINK && address.nl_pid == 0, "disconnected default peer"); + close(descriptor); +} + +static void receive_test(void) { + int descriptor = route_socket(); + send_link(descriptor, 1, 0); + unsigned char buffer[4096]; + struct sockaddr_nl address; + memset(&address, 0xff, sizeof(address)); + socklen_t length = sizeof(sa_family_t); + require(recvfrom(descriptor, buffer, sizeof(buffer), MSG_PEEK, + (struct sockaddr *)&address, &length) > 0 + && length == sizeof(address) && address.nl_family == AF_NETLINK + && address.nl_pid == (unsigned)-1, "truncated source"); + struct iovec part = {.iov_base = buffer, .iov_len = sizeof(buffer)}; + struct msghdr message = {.msg_name = &address, .msg_namelen = sizeof(address), + .msg_iov = &part, .msg_iovlen = 1}; + require(recvmsg(descriptor, &message, 0) > 0 && message.msg_namelen == sizeof(address) + && address.nl_family == AF_NETLINK && address.nl_pid == 0, "recvmsg source"); + memset(&address, 0xff, sizeof(address)); + length = sizeof(address); + require(recvfrom(descriptor, buffer, sizeof(buffer), MSG_DONTWAIT, + (struct sockaddr *)&address, &length) == -1 && errno == EAGAIN + && address.nl_family == (unsigned short)-1, "failed receive preserves source"); + close(descriptor); +} + +static void duplicate_test(const char *mode) { + int descriptor = route_socket(); + unsigned port = port_of(descriptor); + int duplicate; + if (!strcmp(mode, "dup")) duplicate = dup(descriptor); + else if (!strcmp(mode, "high_dup")) { + struct rlimit limit; + require(getrlimit(RLIMIT_NOFILE, &limit) == 0, "descriptor limit"); + int minimum = limit.rlim_cur > 262144 ? 262144 : (int)(limit.rlim_cur / 2); + duplicate = fcntl(descriptor, F_DUPFD, minimum); + require(duplicate >= minimum, "high descriptor duplicate"); + } + else if (!strcmp(mode, "fcntl")) duplicate = fcntl(descriptor, F_DUPFD, 20); + else if (!strcmp(mode, "fcntl_cloexec")) duplicate = fcntl(descriptor, F_DUPFD_CLOEXEC, 20); + else { + int target = open("/dev/null", O_RDONLY); + require(target >= 0, "dup target"); + duplicate = !strcmp(mode, "dup2") ? dup2(descriptor, target) : + dup3(descriptor, target, O_CLOEXEC); + } + require(duplicate >= 0 && port_of(duplicate) == port, "duplicate identity"); + require(dup2(descriptor, descriptor) == descriptor, "dup2 same fd"); + require(dup2(-1, descriptor) == -1 && errno == EBADF, "failed replacement"); + usable(descriptor); + close(descriptor); + usable(duplicate); + close(duplicate); + for (int pass = 0; pass < 16; pass++) { + descriptor = route_socket(); + usable(descriptor); + close(descriptor); + } +} + +static void replacement_test(int raw) { + int descriptor = route_socket(); + int pair[2]; + require(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) == 0, "unix pair"); + int result = raw ? (int)syscall(SYS_dup3, (long)pair[0], (long)descriptor, 0L, 0L, 0L, 0L) : + dup2(pair[0], descriptor); + require(result == descriptor, "replace descriptor"); + struct sockaddr_storage address; + socklen_t length = sizeof(address); + require(getsockname(descriptor, (struct sockaddr *)&address, &length) == 0 + && address.ss_family == AF_UNIX, "replacement identity"); + const char payload[] = "unix payload"; + require(send(descriptor, payload, sizeof(payload), MSG_DONTWAIT) == sizeof(payload), "unix send"); + char buffer[64]; + require(recv(pair[1], buffer, sizeof(buffer), MSG_DONTWAIT) == sizeof(payload) + && !memcmp(buffer, payload, sizeof(payload)), "unix receive"); + close(descriptor); + close(pair[0]); + close(pair[1]); +} + +static void shared_test(int forked) { + int descriptor = route_socket(); + if (forked) { + pid_t child = fork(); + require(child >= 0, "fork"); + if (child == 0) { + usable(descriptor); + close(descriptor); + _exit(0); + } + int status; + require(waitpid(child, &status, 0) == child && WIFEXITED(status) && WEXITSTATUS(status) == 0, + "child socket"); + usable(descriptor); + } else { + int alias = dup(descriptor); + require(alias >= 0 && dup2(descriptor, alias) == alias, "replace same socket alias"); + int other = route_socket(); + require(dup2(descriptor, other) == other, "replace other socket"); + close(descriptor); + usable(alias); + close(alias); + usable(other); + close(other); + return; + } + close(descriptor); +} + +static void close_range_test(const char *mode) { + int descriptor = route_socket(); + if (!strcmp(mode, "closefrom")) { + void (*close_from)(int) = dlsym(RTLD_DEFAULT, "closefrom"); + require(close_from != NULL, "closefrom symbol"); + close_from(descriptor); + } else { + int (*close_range_fn)(unsigned int, unsigned int, int) = dlsym(RTLD_DEFAULT, "close_range"); + require(close_range_fn != NULL, "close_range symbol"); + if (!strcmp(mode, "cloexec")) { + require(close_range_fn(descriptor, descriptor, 4) == 0, "close_range cloexec"); + usable(descriptor); + close(descriptor); + } else { + require(close_range_fn(descriptor, descriptor, 1) == -1 && errno == EINVAL, + "invalid close_range"); + usable(descriptor); + require(close_range_fn(descriptor, descriptor, 0) == 0, "close_range"); + } + } + for (int pass = 0; pass < 16; pass++) { + descriptor = route_socket(); + usable(descriptor); + close(descriptor); + } +} + +static void route_test(const char *destination) { + int descriptor = route_socket(); + int family = strchr(destination, ':') ? AF_INET6 : AF_INET; + int size = family == AF_INET ? 4 : 16; + struct { + struct nlmsghdr header; + struct rtmsg info; + struct rtattr attr; + unsigned char destination[16]; + } query = { + .header = {.nlmsg_type = RTM_GETROUTE, .nlmsg_flags = NLM_F_REQUEST, .nlmsg_seq = 42}, + .info = {.rtm_family = family, .rtm_dst_len = size * 8}, + .attr = {.rta_type = RTA_DST, .rta_len = RTA_LENGTH(size)} + }; + query.header.nlmsg_len = NLMSG_LENGTH(sizeof(query.info)) + RTA_SPACE(size); + require(inet_pton(family, destination, query.destination) == 1, "destination"); + struct sockaddr_nl address = {.nl_family = AF_NETLINK}; + require(sendto(descriptor, &query, query.header.nlmsg_len, 0, + (struct sockaddr *)&address, sizeof(address)) == query.header.nlmsg_len, "route send"); + unsigned char buffer[4096]; + receive(descriptor, buffer, sizeof(buffer)); + struct nlmsghdr *header = (struct nlmsghdr *)buffer; + if (header->nlmsg_type == NLMSG_ERROR) { + printf("error %d\n", ((struct nlmsgerr *)NLMSG_DATA(header))->error); + } else { + require(header->nlmsg_type == RTM_NEWROUTE, "route reply"); + struct rtmsg *info = NLMSG_DATA(header); + int remaining = RTM_PAYLOAD(header); + unsigned interface = 0; + char gateway[INET6_ADDRSTRLEN] = "-", source[INET6_ADDRSTRLEN] = "-"; + for (struct rtattr *attr = RTM_RTA(info); RTA_OK(attr, remaining); + attr = RTA_NEXT(attr, remaining)) { + if (attr->rta_type == RTA_OIF) memcpy(&interface, RTA_DATA(attr), sizeof(interface)); + if (attr->rta_type == RTA_GATEWAY) inet_ntop(family, RTA_DATA(attr), gateway, sizeof(gateway)); + if (attr->rta_type == RTA_PREFSRC) inet_ntop(family, RTA_DATA(attr), source, sizeof(source)); + } + printf("route %u %u %u %u %s %s\n", info->rtm_type, info->rtm_scope, + info->rtm_table, interface, gateway, source); + } + close(descriptor); +} + +int main(int argc, char **argv) { + require(argc >= 2, "mode"); + if (!strcmp(argv[1], "ack") || !strcmp(argv[1], "error") || !strcmp(argv[1], "capped")) + ack_test(argv[1]); + else if (!strcmp(argv[1], "options")) options_test(); + else if (!strcmp(argv[1], "dump")) dump_test(); + else if (!strcmp(argv[1], "send_timeout")) send_timeout_test(0); + else if (!strcmp(argv[1], "nonblocking")) send_timeout_test(1); + else if (!strcmp(argv[1], "connect")) connect_test(); + else if (!strcmp(argv[1], "receive")) receive_test(); + else if (!strcmp(argv[1], "replace")) replacement_test(0); + else if (!strcmp(argv[1], "raw_replace")) replacement_test(1); + else if (!strcmp(argv[1], "shared")) shared_test(0); + else if (!strcmp(argv[1], "fork")) shared_test(1); + else if (!strcmp(argv[1], "socket_types")) socket_types_test(); + else if (!strcmp(argv[1], "hotpath")) { + require(argc == 3, "hotpath arguments"); + hotpath_test(atoi(argv[2])); + } + else if (!strcmp(argv[1], "transferred")) { + require(argc == 3, "transfer arguments"); + transferred_test(argv[2]); + } + else if (!strcmp(argv[1], "named_link")) { + require(argc == 4, "named link arguments"); + named_link_test(argv[2], argv[3]); + } + else if (!strcmp(argv[1], "autobind_race")) autobind_race_test(); + else if (!strcmp(argv[1], "vfork_close_range")) vfork_close_range_test(); + else if (!strcmp(argv[1], "ports")) ports_test(0); + else if (!strcmp(argv[1], "cross_process_ports")) ports_test(1); + else if (!strcmp(argv[1], "batch")) batch_test(0); + else if (!strcmp(argv[1], "oversized_batch")) batch_test(1); + else if (!strcmp(argv[1], "exec")) exec_test(argv[0], 0); + else if (!strcmp(argv[1], "fork_exec")) exec_test(argv[0], 1); + else if (!strcmp(argv[1], "inherited")) inherited_test(argc, argv); + else if (!strcmp(argv[1], "all_cloexec")) cloexec_test(argv[0]); + else if (!strcmp(argv[1], "rebind_after_exec")) { + require(argc == 3, "rebind arguments"); + int descriptor = route_socket(); + require(port_of(descriptor) == (unsigned)strtoul(argv[2], NULL, 10), "exec releases closed ports"); + usable(descriptor); + close(descriptor); + } + else if (!strcmp(argv[1], "range") || !strcmp(argv[1], "cloexec") || !strcmp(argv[1], "closefrom")) + close_range_test(argv[1]); + else if (!strcmp(argv[1], "route")) { + require(argc >= 3, "route destination"); + route_test(argv[2]); + } else duplicate_test(argv[1]); + return 0; +} +""" + +SNAPSHOT = """if wlan0 2 1500 +mac 02:11:22:33:44:55 +addr 192.168.1.10 24 +addr 192.168.1.130 25 +addr fe80::10 64 +addr 2001:db8::10 64 +gw 192.168.1.1 +gw 2001:db8::1 +""" + + +@unittest.skipUnless(sys.platform.startswith("linux") and shutil.which("cc"), "needs Linux and a C compiler") +class NetlinkPreloadTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.temp = tempfile.TemporaryDirectory() + cls.directory = Path(cls.temp.name) + cls.preload = cls.directory / "libblsession.so" + cls.shim = cls.directory / "libshim.so" + cls.program = cls.directory / "program" + (cls.directory / "shim.c").write_text(SHIM) + (cls.directory / "program.c").write_text(PROGRAM) + subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-Wall", "-pthread", + "-o", str(cls.preload), *map(str, sorted(PRELOAD.glob("*.c"))), "-ldl"], check=True) + subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-Wall", "-pthread", "-o", str(cls.shim), + str(cls.directory / "shim.c"), "-ldl"], check=True) + subprocess.run(["cc", "-O2", "-Wall", "-pthread", "-o", str(cls.program), + str(cls.directory / "program.c"), "-ldl"], check=True) + cls.snapshot = cls.directory / "snapshot" + cls.snapshot.write_text(SNAPSHOT) + cls.direct = cls.directory / "direct" + cls.direct.write_text("\n".join(line for line in SNAPSHOT.splitlines() if not line.startswith("gw ")) + "\n") + cls.offline = cls.directory / "offline" + cls.offline.write_text("") + + @classmethod + def tearDownClass(cls): + cls.temp.cleanup() + + def run_program(self, mode, *arguments, snapshot=None): + env = dict(os.environ, LD_PRELOAD=f"{self.preload}:{self.shim}", + NETLINK_TEST_SNAPSHOT=str(snapshot or self.snapshot), + BL_SYSV_DIR=str(self.directory / "sysv")) + result = subprocess.run([str(self.program), mode, *arguments], env=env, + capture_output=True, text=True, timeout=5) + self.assertEqual(0, result.returncode, result.stdout + result.stderr) + return result.stdout.strip().split() + + def test_successful_queries_acknowledge_requests(self): + self.run_program("ack") + + def test_failed_queries_return_only_one_error(self): + self.run_program("error") + + def test_cap_ack_omits_the_request_payload(self): + self.run_program("capped") + + def test_socket_types_flags_and_identity_match_netlink(self): + self.run_program("socket_types") + + def test_ordinary_socket_paths_do_not_lock_or_probe_for_netlink(self): + for active in ("0", "1"): + with self.subTest(netlink_active=active): + self.run_program("hotpath", active) + + def test_transferred_sockets_restore_on_receipt_or_netlink_specific_operations(self): + for mode in ("received", "domain", "bind", "connect", "option"): + with self.subTest(discovery=mode): + self.run_program("transferred", mode) + + def test_getlink_resolves_names_and_prefers_a_nonzero_index(self): + for name, mode, expected in (("wlan0", "name", ["link", "2", "wlan0"]), + ("lo", "name", ["link", "1", "lo"]), + ("unknown", "index", ["link", "1", "lo"]), + ("unknown", "name", ["error", str(-errno.ENODEV)]), + ("wlan0", "missing", ["error", str(-errno.EINVAL)]), + ("wlan0", "unterminated", ["link", "2", "wlan0"]), + ("lo", "unterminated", ["link", "1", "lo"]), + ("unknown", "unterminated", ["error", str(-errno.ENODEV)]), + ("x" * 15, "name", ["error", str(-errno.ENODEV)]), + ("x" * 15, "unterminated", ["error", str(-errno.ENODEV)]), + ("x" * 16, "unterminated", ["error", str(-errno.ERANGE)]), + ("", "name", ["error", str(-errno.ENODEV)]), + ("", "unterminated", ["error", str(-errno.ERANGE)]), + ("wlan0", "oversized", ["error", str(-errno.ERANGE)])): + with self.subTest(name=name, mode=mode): + self.assertEqual(expected, self.run_program("named_link", name, mode)) + self.assertEqual(["error", str(-errno.ENODEV)], + self.run_program("named_link", "wlan0", "name", snapshot=self.offline)) + + def test_more_than_eight_sockets_get_unique_ports_and_release_them(self): + self.run_program("ports") + + def test_concurrent_implicit_binds_are_idempotent(self): + self.run_program("autobind_race") + + def test_vfork_close_range_does_not_mutate_parent_bookkeeping(self): + self.run_program("vfork_close_range") + + def test_explicit_ports_cannot_collide_across_processes(self): + self.run_program("cross_process_ports") + + def test_large_scatter_gather_requests_receive_all_their_replies(self): + self.run_program("batch") + + def test_reply_overflow_and_invalid_iovecs_fail_without_unix_fallback(self): + self.run_program("oversized_batch") + + def test_non_cloexec_sockets_and_queued_replies_survive_exec(self): + self.run_program("exec") + + def test_fork_exec_does_not_break_the_parents_socket(self): + self.run_program("fork_exec") + + def test_cloexec_sockets_release_their_ports_after_exec(self): + self.run_program("all_cloexec") + + def test_subscription_is_denied_and_receive_timeout_is_applied(self): + self.run_program("options") + + def test_dump_keeps_multipart_completion(self): + self.run_program("dump") + + def test_full_reply_queues_respect_send_timeout_and_nonblocking_mode(self): + for mode in ("send_timeout", "nonblocking"): + with self.subTest(mode=mode): + self.run_program(mode) + + def test_kernel_connect_and_disconnect(self): + self.run_program("connect") + + def test_receive_sources_and_truncation(self): + self.run_program("receive") + + def test_duplicates_share_the_socket_until_the_last_close(self): + for mode in ("dup", "dup2", "dup3", "fcntl", "fcntl_cloexec", "high_dup"): + with self.subTest(mode=mode): + self.run_program(mode) + + def test_replacing_a_route_fd_does_not_intercept_unix_traffic(self): + self.run_program("replace") + + def test_untracked_replacement_is_detected_by_socket_identity(self): + self.run_program("raw_replace") + + def test_replacing_other_netlink_descriptors_preserves_shared_state(self): + self.run_program("shared") + + def test_forked_sockets_remain_usable_in_both_processes(self): + self.run_program("fork") + + def test_range_closes_release_slots_but_failures_and_cloexec_do_not(self): + for mode in ("range", "cloexec", "closefrom"): + with self.subTest(mode=mode): + self.run_program(mode) + + def test_loopback_and_own_addresses_are_local_routes(self): + for destination, source in (("127.0.0.2", "127.0.0.1"), ("::1", "::1"), + ("192.168.1.10", "192.168.1.10"), ("2001:db8::10", "2001:db8::10")): + with self.subTest(destination=destination): + self.assertEqual(["route", "2", "254", "255", "1", "-", source], + self.run_program("route", destination)) + + def test_connected_routes_choose_the_longest_prefix_without_a_gateway(self): + for destination, source in (("192.168.1.11", "192.168.1.10"), + ("192.168.1.131", "192.168.1.130"), + ("fe80::11", "fe80::10"), ("2001:db8::11", "2001:db8::10")): + with self.subTest(destination=destination): + self.assertEqual(["route", "1", "253", "254", "2", "-", source], + self.run_program("route", destination, snapshot=self.direct)) + + def test_other_destinations_use_a_default_gateway(self): + self.assertEqual(["route", "1", "0", "254", "2", "192.168.1.1", "192.168.1.10"], + self.run_program("route", "8.8.8.8")) + self.assertEqual(["route", "1", "0", "254", "2", "2001:db8::1", "2001:db8::10"], + self.run_program("route", "2001:db9::1")) + + def test_without_a_gateway_only_off_link_destinations_are_unreachable(self): + self.assertEqual(["error", str(-errno.ENETUNREACH)], + self.run_program("route", "8.8.8.8", snapshot=self.direct)) + self.assertEqual(["route", "2", "254", "255", "1", "-", "127.0.0.1"], + self.run_program("route", "127.0.0.1", snapshot=self.offline)) + + @unittest.skipUnless(shutil.which("ip"), "needs iproute2") + def test_iproute2_dumps_and_lookups_accept_the_replies(self): + env = dict(os.environ, LD_PRELOAD=f"{self.preload}:{self.shim}", + NETLINK_TEST_SNAPSHOT=str(self.snapshot), + BL_SYSV_DIR=str(self.directory / "sysv")) + queries = ((["link", "show"], "wlan0"), + (["link", "show", "wlan0"], "wlan0"), + (["-d", "link", "show", "dev", "wlan0"], "wlan0"), + (["link", "show", "lo"], "lo"), + (["addr", "show"], "192.168.1.10/24"), + (["route", "show"], "default via 192.168.1.1 dev wlan0"), + (["route", "get", "127.0.0.1"], "local 127.0.0.1 dev lo"), + (["route", "get", "192.168.1.11"], "192.168.1.11 dev wlan0"), + (["-6", "route", "get", "fe80::11"], "fe80::11 dev wlan0")) + for arguments, expected in queries: + with self.subTest(arguments=arguments): + result = subprocess.run([shutil.which("ip"), *arguments], env=env, + capture_output=True, text=True, timeout=5) + self.assertEqual(0, result.returncode, result.stdout + result.stderr) + self.assertIn(expected, result.stdout) + + +if __name__ == "__main__": + unittest.main() From 9d2580d502ba901a09909dcb2df5554e0f760a14 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:27:35 -0500 Subject: [PATCH 76/85] perf: reclaim launcher memory earlier under pressure (#2138) * perf: reclaim launcher memory under system pressure * docs: record Caravan save-load OOM with spare swap * fix: wait for completed reclaim before increasing backoff --- app/src/main/res/values/strings.xml | 2 +- docs/development/low-memory.md | 86 ++++++++ tools/experiments/anonymous-memory-pager.c | 202 ++++++++++++++++++ .../overlay/usr/local/bin/droiddeck-session | 88 +++++++- tools/tests/test_client_zram_focus.py | 27 ++- tools/tests/test_memory_pressure.py | 141 ++++++++++++ 6 files changed, 535 insertions(+), 11 deletions(-) create mode 100644 docs/development/low-memory.md create mode 100644 tools/experiments/anonymous-memory-pager.c create mode 100644 tools/tests/test_memory_pressure.py diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index df5cf9ac28..f82841a888 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -627,7 +627,7 @@ <string name="perf_cap_off">Off</string> <string name="perf_cap_auto">Driver default</string> <string name="perf_zram_client">Compress Steam while a game runs</string> - <string name="perf_zram_client_hint">20 s after a game starts, the Steam client is compressed into zRAM to leave the game more memory, and read back when the game closes. Turn this off if the session closes shortly after games start. A RAM cap above still compresses Steam when the session goes over it.</string> + <string name="perf_zram_client_hint">Compresses Steam while a game runs, starting sooner when memory is tight. Steam is read back after the game closes once enough RAM is available. Turn this off if the session closes shortly after games start. A RAM cap above still compresses Steam when the session goes over it.</string> <string name="perf_ram_cap">RAM cap</string> <string name="perf_ram_cap_hint">Applies while the Steam client runs, in Steam mode or from the desktop. When the session uses more than this, Steam and then the session\'s other supported processes are compressed into zRAM. A soft cap: nothing is closed, but games may stutter while pages come back.</string> <string name="perf_ram_cap_unavailable">Needs zRAM swap, which this device does not have.</string> diff --git a/docs/development/low-memory.md b/docs/development/low-memory.md new file mode 100644 index 0000000000..398dbf9132 --- /dev/null +++ b/docs/development/low-memory.md @@ -0,0 +1,86 @@ +# Low-memory reclaim and userspace compression + +The Steam session monitor uses the existing `libblsession.so` page-out request to reclaim +private anonymous launcher memory. The default remains a request 20 seconds after game focus, +with five minutes between requests. With client compression enabled, low system headroom can +also trigger a request while a game is loading, before its first focused window. + +Every five seconds the monitor reads `MemAvailable`, swap headroom and memory PSI. Low +headroom means less than one fifth of total RAM (bounded to 512–1536 MiB), or at least 1% +`some avg10` memory stall with less than one third of RAM available. Pressure requests target +only the launcher processes already recognized by the monitor, never the game. They require +at least 128 MiB launcher RSS and enough free swap to cover its entire RSS while leaving +one fifth of swap (at least 256 MiB) free. The regular automatic client request uses the +same swap guard. An explicit session RAM cap retains its existing behavior. + +Pressure requests are at least 30 seconds apart. Reclaiming less than 16 MiB doubles the +retry delay, up to five minutes. After game exit, speculative launcher readback is deferred +until the session is under any explicit RAM cap, pressure has subsided, and available RAM +can cover twice the launcher's swap while leaving the headroom reserve. Normal demand paging +continues while readback is deferred; Steam does not have to wait for the monitor to recover. +Missing memory counters disable automatic pressure reclaim and speculative readback. Missing +PSI alone still permits the `MemAvailable` fallback. No root settings, swap sizes, compression +algorithms, Android process priorities or game-specific settings are changed. + +A bounded live test of the pressure helper on the FIT during Caravan SandWitch loading +requested page-out at 20:52:37 UTC, 18 seconds before the installed timed reclaimer. Aggregate +launcher RSS fell from 608 to 283 MiB across that request; this is summed process RSS, not a +measurement of net physical RAM saved. The game reached its main menu at 60 FPS. The test ran +the candidate monitor functions alongside the old APK's monitor, not a newly built APK; +the old monitor's later request is visible separately at 20:52:55 in the session log. This +does not establish gameplay performance or resolve Stellar Blade's larger memory failure. + +Continuing an existing Caravan save reproduced a whole-session low-memory kill with the +pressure helper running. Android recorded `ApplicationExitInfo` reason `LOW_MEMORY`, and +`lmkd` killed the foreground app with `oom_score_adj=0` because the device was not responding. +The last half-second sample before the kill still had 2,172,612 KiB swap free. Over the +captured interval, system unevictable memory grew from 1,955,932 to 3,236,276 KiB and shmem +from 1,690,276 to 2,965,900 KiB, while the game's private swap reached 1,916,136 KiB. The +pressure helper found the launcher already largely reclaimed: its first request at Continue +reduced aggregate launcher RSS only from 263 to 255 MiB and backed off. Thus launcher reclaim +does not resolve this load failure, and this run did not exhaust swap. The unevictable/shmem +growth needs allocation attribution before treating it as a driver or GPU-memory diagnosis. + +## CRAM and the bounded pager experiment + +[Meta's CRAM proposal](https://lpc.events/event/20/contributions/2424/) uses memory compression +hardware to allow byte/cacheline reads without software decompression faults. A userspace +software pager cannot reproduce that hardware property. This is separate from Valve's device +memory cgroup prioritization work. + +`tools/experiments/anonymous-memory-pager.c` is an opt-in feasibility probe, not a preload or +runtime component. Build it for the guest architecture with a Linux compiler: + +```sh +cc -O2 -Wall -Wextra -Werror -pthread tools/experiments/anonymous-memory-pager.c -ldl -o /tmp/anonymous-memory-pager +/tmp/anonymous-memory-pager 64 +``` + +It requires `liblz4.so.1` and `UFFD_USER_MODE_ONLY`. The requested arena is bounded to +1–256 MiB. Half its pages contain a repeating byte and half contain pseudorandom bytes; +these are synthetic data, not a game-memory compression estimate. The probe registers only +its own arena, packs compressed or incompressible pages into a separate store, discards the +original physical pages, then restores them on demand with `UFFDIO_COPY`. It checks the full +checksum and subsequent writes. A separate child checks kernel access to an evicted buffer. +The compressed store is retained until the probe ends; this is one eviction/restore cycle, +without hot/cold selection, concurrent eviction, lifecycle hooks or game integration. + +On the Pocket FIT Elite's Android 6.6.82 kernel, tested from DroidDeck's unprivileged guest: + +| Measurement | Result | +| --- | --- | +| unrestricted `userfaultfd` | `EPERM` | +| userspace-only creation and API negotiation | available | +| arena / compressed payload | 64 MiB / 33,767,424 bytes | +| process RSS before / after eviction | 68,864 / 36,340 KiB | +| restored pages / checksum / writes | 16,384 / intact / intact | +| resident scan / compress and evict / faulted scan | 46.851 / 17.289 / 446.524 ms | +| kernel pipe write from evicted buffer | `EFAULT` | + +These timings include the full checksum scan and are one synthetic run, not a comparison +against zram or a game-performance result. The normal unrestricted pager interface was denied; +`/dev/userfaultfd` was also inaccessible. The kernel-access result is a hard integration +constraint: a transparent heap-wide pager cannot assume every access comes from userspace. +Wine/FEX signal handling, syscall buffers, shared and GPU memory, mapping changes, concurrent +writes and allocation overhead would all need a correctness design before enabling such a +pager in a real game. The experiment is deliberately excluded from runtime builds. diff --git a/tools/experiments/anonymous-memory-pager.c b/tools/experiments/anonymous-memory-pager.c new file mode 100644 index 0000000000..f363e91d81 --- /dev/null +++ b/tools/experiments/anonymous-memory-pager.c @@ -0,0 +1,202 @@ +#define _GNU_SOURCE +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <linux/userfaultfd.h> +#include <poll.h> +#include <pthread.h> +#include <signal.h> +#include <stdatomic.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <sys/syscall.h> +#include <sys/wait.h> +#include <time.h> +#include <unistd.h> + +#ifndef UFFD_USER_MODE_ONLY +#define UFFD_USER_MODE_ONLY 1 +#endif + +static unsigned char *arena, *store; +static size_t page, size, *offsets; +static int *lengths, uffd; +static atomic_int finished; +static unsigned faults; +static int (*decode)(const char *, char *, int, int); + +static void fail(const char *name) { + perror(name); + exit(1); +} + +static double milliseconds(void) { + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); + return t.tv_sec * 1000.0 + t.tv_nsec / 1000000.0; +} + +static long resident_kb(void) { + FILE *f = fopen("/proc/self/status", "r"); + if (!f) fail("status"); + char line[256]; + long value = -1; + while (fgets(line, sizeof(line), f)) { + if (sscanf(line, "VmRSS: %ld", &value) == 1) break; + } + fclose(f); + return value; +} + +static int open_pager(void) { + int fd = (int)syscall(SYS_userfaultfd, O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY); + if (fd < 0) fail("userfaultfd"); + struct uffdio_api api = {.api = UFFD_API}; + if (ioctl(fd, UFFDIO_API, &api)) fail("UFFDIO_API"); + return fd; +} + +static void register_range(int fd, void *address, size_t bytes) { + struct uffdio_register range = { + .range = {.start = (uintptr_t)address, .len = bytes}, + .mode = UFFDIO_REGISTER_MODE_MISSING, + }; + if (ioctl(fd, UFFDIO_REGISTER, &range)) fail("UFFDIO_REGISTER"); +} + +static void *serve(void *unused) { + (void)unused; + unsigned char *scratch = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (scratch == MAP_FAILED) fail("scratch"); + struct pollfd p = {.fd = uffd, .events = POLLIN}; + while (!atomic_load(&finished)) { + int ready = poll(&p, 1, 100); + if (ready < 0 && errno == EINTR) continue; + if (ready < 0 || (p.revents & (POLLERR | POLLHUP | POLLNVAL))) fail("pager poll"); + if (!ready) continue; + struct uffd_msg msg; + ssize_t n = read(uffd, &msg, sizeof(msg)); + if (n < 0 && errno == EAGAIN) continue; + if (n != sizeof(msg) || msg.event != UFFD_EVENT_PAGEFAULT) fail("pager event"); + uintptr_t address = msg.arg.pagefault.address & ~(page - 1); + if (address < (uintptr_t)arena || address >= (uintptr_t)arena + size) fail("pager address"); + size_t index = (address - (uintptr_t)arena) / page; + if (lengths[index] == 0) memcpy(scratch, store + offsets[index], page); + else if (decode((char *)store + offsets[index], (char *)scratch, lengths[index], (int)page) != (int)page) + fail("decompression"); + struct uffdio_copy copy = {.dst = address, .src = (uintptr_t)scratch, .len = page}; + if (ioctl(uffd, UFFDIO_COPY, ©)) fail("UFFDIO_COPY"); + faults++; + } + munmap(scratch, page); + return NULL; +} + +static uint64_t checksum(void) { + uint64_t sum = 0; + for (size_t i = 0; i < size; i++) sum = sum * 31 + arena[i]; + return sum; +} + +static void kernel_access_probe(void) { + pid_t child = fork(); + if (child < 0) fail("fork"); + if (!child) { + alarm(2); + int fd = open_pager(), pipefd[2]; + unsigned char *buffer = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (buffer == MAP_FAILED || pipe(pipefd)) _exit(1); + memset(buffer, 0x5a, page); + register_range(fd, buffer, page); + if (madvise(buffer, page, MADV_DONTNEED)) _exit(1); + errno = 0; + ssize_t n = write(pipefd[1], buffer, page); + _exit(n < 0 && errno == EFAULT ? 42 : 1); + } + int status; + if (waitpid(child, &status, 0) < 0) fail("waitpid"); + if (WIFSIGNALED(status)) printf("kernel_access_signal=%d\n", WTERMSIG(status)); + else printf("kernel_access_exit=%d (42=EFAULT)\n", WEXITSTATUS(status)); +} + +int main(int argc, char **argv) { + if (argc > 2) return 2; + char *end = NULL; + long mb = argc == 2 ? strtol(argv[1], &end, 10) : 64; + if (mb < 1 || mb > 256 || (end && (*end || end == argv[1]))) return 2; + alarm(30); + page = (size_t)sysconf(_SC_PAGESIZE); + size = (size_t)mb << 20; + if (!page || size % page) return 2; + void *codec = dlopen("liblz4.so.1", RTLD_NOW | RTLD_LOCAL); + if (!codec) { fprintf(stderr, "%s\n", dlerror()); return 1; } + int (*encode)(const char *, char *, int, int) = dlsym(codec, "LZ4_compress_default"); + int (*bound)(int) = dlsym(codec, "LZ4_compressBound"); + decode = dlsym(codec, "LZ4_decompress_safe"); + if (!encode || !decode || !bound) return 1; + arena = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + store = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (arena == MAP_FAILED || store == MAP_FAILED) fail("arena"); + size_t count = size / page; + offsets = calloc(count, sizeof(*offsets)); + lengths = calloc(count, sizeof(*lengths)); + char *scratch = malloc((size_t)bound((int)page)); + if (!offsets || !lengths || !scratch) fail("metadata"); + uint32_t random = 123456789; + for (size_t i = 0; i < size; i++) { + if ((i / page) % 2) { + random ^= random << 13; random ^= random >> 17; random ^= random << 5; + arena[i] = (unsigned char)random; + } else arena[i] = (unsigned char)(i / page); + } + double start = milliseconds(); + uint64_t before = checksum(); + double baseline_ms = milliseconds() - start; + long before_kb = resident_kb(); + uffd = open_pager(); + register_range(uffd, arena, size); + start = milliseconds(); + size_t used = 0; + for (size_t i = 0; i < count; i++) { + int n = encode((char *)arena + i * page, scratch, (int)page, bound((int)page)); + if (n <= 0) fail("compression"); + offsets[i] = used; + if ((size_t)n >= page) { + memcpy(store + used, arena + i * page, page); + used += page; + } else { + lengths[i] = n; + memcpy(store + used, scratch, (size_t)n); + used += (size_t)n; + } + } + if (madvise(arena, size, MADV_DONTNEED)) fail("eviction"); + double compress_ms = milliseconds() - start; + long compressed_kb = resident_kb(); + pthread_t pager; + if (pthread_create(&pager, NULL, serve, NULL)) fail("pthread_create"); + start = milliseconds(); + uint64_t after = checksum(); + double restore_ms = milliseconds() - start; + int writable = 1; + for (size_t i = 0; i < size; i += page) { + unsigned char value = arena[i] ^ 0xff; + arena[i] = value; + if (*(volatile unsigned char *)(arena + i) != value) writable = 0; + } + atomic_store(&finished, 1); + pthread_join(pager, NULL); + printf("arena_mb=%ld compressed_bytes=%zu rss_before_kb=%ld rss_compressed_kb=%ld faults=%u intact=%d writable=%d\n", + mb, used, before_kb, compressed_kb, faults, before == after, writable); + printf("baseline_scan_ms=%.3f compress_ms=%.3f restore_scan_ms=%.3f\n", baseline_ms, compress_ms, restore_ms); + close(uffd); + munmap(arena, size); munmap(store, size); + free(offsets); free(lengths); free(scratch); + dlclose(codec); + kernel_access_probe(); + return before == after && writable && faults == count ? 0 : 1; +} diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 4ebfbc00ea..3edc114c8f 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -707,8 +707,75 @@ case $mode in done 2>/dev/null < "/proc/$_p/status" done _bl_rss=$_rss + _bl_swap=$_swap echo "$# processes, resident $((_rss / 1024)) MB, in zram $((_swap / 1024)) MB" } + bl_memory_read() { + local _k _v _u _kind _fields _avg + _bl_mem_total=0 _bl_available=-1 _bl_swap_total=0 _bl_swap_free=-1 _bl_psi=0 + while read -r _k _v _u; do + case $_v in ''|*[!0-9]*) continue ;; esac + case $_k in + MemTotal:) _bl_mem_total=$_v ;; + MemAvailable:) _bl_available=$_v ;; + SwapTotal:) _bl_swap_total=$_v ;; + SwapFree:) _bl_swap_free=$_v ;; + esac + done 2>/dev/null < /proc/meminfo + if [ -r /proc/pressure/memory ]; then + while read -r _kind _fields; do + [ "$_kind" = some ] || continue + _avg=${_fields#avg10=} _avg=${_avg%% *} _avg=${_avg%%.*} + case $_avg in ''|*[!0-9]*) ;; *) _bl_psi=$((10#$_avg)) ;; esac + done 2>/dev/null < /proc/pressure/memory + fi + _bl_headroom=$((_bl_mem_total / 5)) + [ "$_bl_headroom" -ge $((512 * 1024)) ] || _bl_headroom=$((512 * 1024)) + [ "$_bl_headroom" -le $((1536 * 1024)) ] || _bl_headroom=$((1536 * 1024)) + _bl_swap_reserve=$((_bl_swap_total / 5)) + [ "$_bl_swap_reserve" -ge $((256 * 1024)) ] || _bl_swap_reserve=$((256 * 1024)) + } + bl_memory_tight() { + [ "$_bl_mem_total" -gt 0 ] && [ "$_bl_available" -ge 0 ] && + { [ "$_bl_available" -lt "$_bl_headroom" ] || + { [ "$_bl_psi" -ge 1 ] && [ "$_bl_available" -lt $((_bl_mem_total / 3)) ]; }; } + } + bl_client_can_pageout() { + bl_memory_read + bl_zram_usage "${_bl_pids[@]}" > /dev/null + [ "$_bl_mem_total" -gt 0 ] && [ "$_bl_swap_total" -gt 0 ] && + [ $((_bl_swap_free - _bl_rss)) -ge "$_bl_swap_reserve" ] + } + bl_client_can_readback() { + bl_memory_read + bl_zram_usage "${_bl_pids[@]}" > /dev/null + [ "$_bl_mem_total" -gt 0 ] && ! bl_memory_tight && + [ "$_bl_available" -ge $((_bl_swap * 2)) ] && + [ $((_bl_available - _bl_swap)) -ge "$_bl_headroom" ] + } + bl_client_pressure() { + [ "${BL_ZRAM_CLIENT:-1}" = 1 ] && [ "$_bl_game" = 1 ] && + [ "${#_bl_pids[@]}" -gt 0 ] && bl_memory_tight || return 0 + [ "$_bl_pressure_at" -lt 0 ] || + [ $((SECONDS - _bl_pressure_at)) -ge "$_bl_pressure_backoff" ] || return 0 + [ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 30 ] || return 0 + _bl_pressure_at=$SECONDS + if ! bl_client_can_pageout; then + step "zRAM: pressure reclaim skipped, swap headroom too small ($((_bl_swap_free / 1024)) MB free)" + return 0 + fi + [ "$_bl_rss" -ge $((128 * 1024)) ] || return 0 + local _before=$_bl_rss + bl_zram_send 1 "memory pressure, compressing the client (available $((_bl_available / 1024)) MB, swap free $((_bl_swap_free / 1024)) MB)" client + _bl_packed=$SECONDS + [ "${_bl_pageout_complete:-0}" = 1 ] || return 0 + bl_zram_usage "${_bl_pids[@]}" > /dev/null + if [ $((_before - _bl_rss)) -lt $((16 * 1024)) ]; then + _bl_pressure_backoff=$((_bl_pressure_backoff * 2 > 300 ? 300 : _bl_pressure_backoff * 2)) + else + _bl_pressure_backoff=30 + fi + } bl_session_others() { local _p _bl_session=() @@ -737,7 +804,11 @@ case $mode in [ "$_left" = 1 ] || break nap 0.2 done - for _p in "$@"; do rm -f "/tmp/.bl-zram.ack.$_p"; done + _bl_pageout_complete=1 + for _p in "$@"; do + if [ -d "/proc/$_p" ] && [ ! -s "/tmp/.bl-zram.ack.$_p" ]; then _bl_pageout_complete=0; fi + rm -f "/tmp/.bl-zram.ack.$_p" + done } bl_zram_send() { local _mode=$1 _what=$2 _which=$3 _pids _p @@ -775,8 +846,10 @@ case $mode in [ "$_bl_ram_cap" -gt 0 ] && { [ "$_bl_measured" -lt 0 ] || [ $((SECONDS - _bl_measured)) -ge 30 ]; } } _bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30 + _bl_pressure_at=-1 _bl_pressure_backoff=30 while kill -0 $$ 2>/dev/null; do bl_zram_scan + bl_memory_read if bl_cap_due; then if bl_over_cap; then if [ "$_bl_capped" -lt 0 ] || [ $((SECONDS - _bl_capped)) -ge "$_bl_backoff" ]; then @@ -798,29 +871,30 @@ case $mode in fi else _bl_backoff=30 - if [ "$_bl_unpack" = 1 ] && [ "$_bl_game" = 0 ]; then - bl_zram_send 0 "back under the RAM cap, reading the client back" client - _bl_unpack=0 - fi fi fi + bl_client_pressure if [ "$_bl_game" = 1 ] && bl_game_focused; then if [ "$_bl_since" -lt 0 ] || [ "$_bl_since_apps" != "$_bl_apps" ]; then _bl_since=$SECONDS _bl_since_apps=$_bl_apps fi if [ "${BL_ZRAM_CLIENT:-1}" = 1 ] && [ $((SECONDS - _bl_since)) -ge 20 ] && [ "${#_bl_pids[@]}" -gt 0 ] && - { [ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 300 ]; }; then + { [ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 300 ]; } && bl_client_can_pageout; then bl_zram_send 1 "compressing the client" client _bl_packed=$SECONDS fi elif [ "$_bl_game" != 1 ]; then if [ "$_bl_packed" -ge 0 ]; then - if bl_over_cap; then _bl_unpack=1; else bl_zram_send 0 "game closed, reading the client back" client; _bl_unpack=0; fi + _bl_unpack=1 fi _bl_since=-1 _bl_packed=-1 else _bl_since=-1 fi + if [ "$_bl_unpack" = 1 ] && [ "$_bl_game" = 0 ] && ! bl_over_cap && bl_client_can_readback; then + bl_zram_send 0 "memory recovered, reading the client back" client + _bl_unpack=0 + fi nap 5 done ) & diff --git a/tools/tests/test_client_zram_focus.py b/tools/tests/test_client_zram_focus.py index dda4e5b6ee..62bb89d372 100644 --- a/tools/tests/test_client_zram_focus.py +++ b/tools/tests/test_client_zram_focus.py @@ -84,10 +84,12 @@ class ClientZramFocusTest(unittest.TestCase): stop = source.index(' nap 5', start) body = source[start:stop] harness = ''' -_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_apps=" 413150" +_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_unpack=0 _bl_apps=" 413150" _bl_pids=(123) bl_game_focused() { [ "$focused" = 1 ]; } bl_over_cap() { return 1; } +bl_client_can_pageout() { return 0; } +bl_client_can_readback() { return 0; } bl_zram_send() { echo "send:$1"; } tick() { SECONDS=$1 _bl_game=$2 focused=$3 @@ -109,7 +111,7 @@ tick 60 0 0 def monitor_harness(self): source = SCRIPT.read_text() - start = source.index(' bl_zram_scan\n if bl_cap_due; then') + start = source.index(' bl_zram_scan\n bl_memory_read\n') stop = source.index(' nap 5', start) return ''' _bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30 @@ -117,6 +119,10 @@ _bl_apps=" 413150" _bl_pids=(123) step() { :; } bl_zram_scan() { :; } +bl_memory_read() { :; } +bl_client_pressure() { :; } +bl_client_can_pageout() { return 0; } +bl_client_can_readback() { [ "${readback:-1}" = 1 ]; } bl_game_focused() { [ "$focused" = 1 ]; } bl_cap_due() { [ "$cap_due" = 1 ]; } bl_over_cap() { [ "$over_cap" = 1 ]; } @@ -169,13 +175,28 @@ tick 20 1 1 0 0 tick 25 1 0 0 0 tick 30 0 0 1 0 echo "deferred:$_bl_unpack:$_bl_packed" -tick 35 0 0 0 1 +tick 35 0 0 0 0 echo "restored:$_bl_unpack" ''') self.assertEqual(0, result.returncode, result.stderr) self.assertEqual('', result.stderr) self.assertEqual(['send:1:client', 'deferred:1:-1', 'send:0:client', 'restored:0'], result.stdout.splitlines()) + def test_game_exit_defers_readback_under_pressure_even_without_a_ram_cap(self): + result = run_bash(self.monitor_harness() + """ +tick 0 1 1 0 0 +tick 20 1 1 0 0 +readback=0 +tick 25 0 0 0 0 +echo "deferred:$_bl_unpack" +readback=1 +tick 30 0 0 0 0 +echo "restored:$_bl_unpack" +""") + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual('', result.stderr) + self.assertEqual(['send:1:client', 'deferred:1', 'send:0:client', 'restored:0'], result.stdout.splitlines()) + def test_scan_keeps_the_running_game_and_ignores_steams_own_reaper(self): temp = tempfile.TemporaryDirectory() self.addCleanup(temp.cleanup) diff --git a/tools/tests/test_memory_pressure.py b/tools/tests/test_memory_pressure.py new file mode 100644 index 0000000000..96c16ec158 --- /dev/null +++ b/tools/tests/test_memory_pressure.py @@ -0,0 +1,141 @@ +from pathlib import Path +import tempfile +import unittest + +from tools.tests.test_client_zram_focus import function_source, run_bash + + +class MemoryPressureTest(unittest.TestCase): + def setUp(self): + self.directory = tempfile.TemporaryDirectory() + self.addCleanup(self.directory.cleanup) + self.root = Path(self.directory.name) + self.memory() + + def memory(self, available=1024, swap_free=4096, total=7168, swap_total=6144, psi='0.00'): + (self.root / 'meminfo').write_text( + f'MemTotal: {total * 1024} kB\nMemAvailable: {available * 1024} kB\n' + f'SwapTotal: {swap_total * 1024} kB\nSwapFree: {swap_free * 1024} kB\n') + (self.root / 'pressure').write_text(f'some avg10={psi} avg60=0.00 avg300=0.00 total=1234\n') + + def run_policy(self, body): + functions = '\n'.join(function_source(name) for name in ( + 'bl_memory_read', 'bl_memory_tight', 'bl_client_can_pageout', + 'bl_client_can_readback', 'bl_client_pressure')) + functions = functions.replace('/proc/meminfo', str(self.root / 'meminfo')) + functions = functions.replace('/proc/pressure/memory', str(self.root / 'pressure')) + harness = ''' +set -u +_bl_pids=(123) _bl_game=1 _bl_packed=-1 _bl_pressure_at=-1 _bl_pressure_backoff=30 +rss=$((384 * 1024)) client_swap=$((512 * 1024)) reclaimed=$((128 * 1024)) +step() { :; } +bl_zram_usage() { _bl_rss=$rss _bl_swap=$client_swap; } +bl_zram_send() { echo "send:$1:$3"; rss=$((rss - reclaimed)); _bl_pageout_complete=${pageout_complete:-1}; } +''' + functions + '\nbl_memory_read\n' + body + result = run_bash(harness) + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual('', result.stderr) + return result.stdout.splitlines() + + def test_pressure_reclaims_before_the_focus_delay_and_respects_cooldown(self): + self.assertEqual(['send:1:client', 'send:1:client'], self.run_policy(''' +SECONDS=0; bl_client_pressure +SECONDS=5; bl_client_pressure +SECONDS=29; bl_client_pressure +SECONDS=30; bl_client_pressure +''')) + + def test_no_game_or_disabled_client_compression_does_not_reclaim(self): + self.assertEqual([], self.run_policy(''' +_bl_game=0; bl_client_pressure +_bl_game=1 BL_ZRAM_CLIENT=0; bl_client_pressure +''')) + + def test_high_available_memory_does_not_reclaim_even_with_stalls(self): + self.memory(available=4096, psi='12.34') + self.assertEqual([], self.run_policy('bl_client_pressure')) + + def test_psi_reclaims_with_moderate_headroom(self): + self.memory(available=2048, psi='01.23') + self.assertEqual(['send:1:client'], self.run_policy('bl_client_pressure')) + + def test_missing_psi_still_uses_memory_headroom(self): + (self.root / 'pressure').unlink() + self.assertEqual(['send:1:client'], self.run_policy('bl_client_pressure')) + + def test_missing_meminfo_never_reclaims_or_prefetches(self): + (self.root / 'meminfo').write_text('SwapTotal: 6291456 kB\nSwapFree: 4194304 kB\n') + self.assertEqual(['no'], self.run_policy(''' +bl_client_pressure +if bl_client_can_readback; then echo yes; else echo no; fi +''')) + + def test_missing_available_memory_does_not_trigger_pressure(self): + p = self.root / 'meminfo' + p.write_text('\n'.join(line for line in p.read_text().splitlines() if not line.startswith('MemAvailable:'))) + self.assertEqual([], self.run_policy('bl_client_pressure')) + + def test_swap_reserve_includes_the_clients_resident_memory(self): + self.memory(swap_free=1536) + self.assertEqual(['no'], self.run_policy(''' +bl_client_pressure +if bl_client_can_pageout; then echo yes; else echo no; fi +''')) + + def test_without_swap_automatic_pageout_is_disabled(self): + self.memory(swap_total=0, swap_free=0) + self.assertEqual([], self.run_policy('bl_client_pressure')) + + def test_recent_periodic_pageout_prevents_an_immediate_pressure_repeat(self): + self.assertEqual([], self.run_policy('_bl_packed=$SECONDS; bl_client_pressure')) + + def test_ineffective_reclaim_backs_off_and_success_resets_it(self): + self.assertEqual(['send:1:client', 'backoff:60', 'send:1:client', 'backoff:30'], self.run_policy(''' +reclaimed=0 +SECONDS=0; bl_client_pressure +echo "backoff:$_bl_pressure_backoff" +SECONDS=30; bl_client_pressure +reclaimed=$((128 * 1024)) +SECONDS=60; bl_client_pressure +echo "backoff:$_bl_pressure_backoff" +''')) + + def test_readback_requires_room_for_the_swapped_client_plus_headroom(self): + self.memory(available=2048) + self.assertEqual(['yes', 'no'], self.run_policy(''' +if bl_client_can_readback; then echo yes; else echo no; fi +client_swap=$((1024 * 1024)) +if bl_client_can_readback; then echo yes; else echo no; fi +''')) + + def test_unfinished_pageout_does_not_increase_the_ineffective_reclaim_backoff(self): + self.assertEqual(['send:1:client', 'backoff:30'], self.run_policy(''' +reclaimed=0 pageout_complete=0 +SECONDS=0; bl_client_pressure +echo "backoff:$_bl_pressure_backoff" +''')) + + def test_pageout_completion_requires_a_finished_ack_from_every_live_target(self): + proc = self.root / 'proc' + proc.mkdir() + for pid in (123, 456): + (proc / str(pid)).mkdir() + source = function_source('bl_zram_wait').replace('/proc/', str(proc) + '/') + source = source.replace('/tmp/.bl-zram.ack.', str(self.root / 'ack.')) + for pending in ('done', 'running', 'not_started'): + with self.subTest(pending=pending): + (self.root / 'ack.123').write_text('1') + if pending != 'not_started': + (self.root / 'ack.456').write_text('1' if pending == 'done' else '') + result = run_bash('nap() { SECONDS=$((SECONDS + 1)); }\n' + source + + '\nSECONDS=0; bl_zram_wait 123 456; echo "$_bl_pageout_complete"') + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual('1' if pending == 'done' else '0', result.stdout.strip()) + + def test_pressure_prevents_prefetch_even_if_the_client_would_fit(self): + self.memory(available=2048, psi='2.00') + self.assertEqual(['no'], self.run_policy('if bl_client_can_readback; then echo yes; else echo no; fi')) + + +if __name__ == '__main__': + unittest.main() From 906e60a042fc632e3d07dadc464b9f1ecbec9aeb Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:33:15 -0500 Subject: [PATCH 77/85] feat(desktop): show programs installed by Windows installers (#2146) * Desktop: programs a Windows installer adds get a menu entry and desktop icon Opening a Windows installer on the desktop runs it with Proton in a prefix of its own (droiddeck-proton-run's "own" prefix). Proton's menu builder turns the installer's Start Menu links into .desktop files, but keeps them in the prefix's drive_c/proton_shortcuts with a Windows .lnk path as Exec, and nothing outside the prefix pointed at the installed program: Nexon Launcher installed fine on an AYANEO Pocket FIT Elite and could only be found by browsing the hidden compatdata folder. droiddeck-desktop-programs reads proton_shortcuts in every prefix that is neither a Steam game's nor a current Steam shortcut's, resolves each link to its program inside the prefix, and writes a menu entry that opens it with droiddeck-open, so it runs in that same prefix, with the icon Proton extracted. A program whose installer also put a link on the Windows desktop gets a desktop icon once; one the user deletes is not put back. Entries go away with their program; uninstallers get none. It runs when the desktop starts and after droiddeck-open finishes a Windows program. * Desktop programs: only programs that run in their prefix, Windows argument rules, one refresh at a time A link resolved through Proton's Z: mapping could name a program outside the scanned prefix, and droiddeck-open would then run it in another one. A program is now listed only when droiddeck-proton-run's prefix_of puts it in the prefix it was found in. Shortcut arguments were split with shlex, so a Windows argument with an apostrophe raised and stopped the whole refresh; they are now split by the Windows command-line rules. The desktop start and the end of a Windows program can refresh at the same time and race on the same temporary files; refreshes now take turns on a lock beside the placement record. * Desktop programs: extract the script at session start SessionFiles lists the overlay scripts the app copies into the runtime; droiddeck-desktop-programs was missing, so a real build would never have installed it and check_session_assets failed the build. * Desktop programs: a compatdata folder it cannot read changes nothing Any error listing steamapps/compatdata made the refresh see no prefixes, so it removed every program entry and forgot which desktop icons it had placed; the next good run then put back icons the user had deleted. Only a missing compatdata now means there is nothing installed; any other read error leaves the menu, the desktop and the placement record as they were. * Desktop programs: an unreadable shortcut or desktop folder changes nothing os.path.isdir and glob read an unreadable proton_shortcuts or Windows desktop folder as empty, so the refresh dropped that prefix's entries and placement records and a later run put back icons the user had deleted. Those folders are now listed directly: a missing one is still empty, and any other error leaves the menu, the desktop and the record as they were. * Desktop programs: only a missing file reads as absent read(), link_target() and host_path()'s letter-case lookup turned any error into "absent", so an unreadable placement record read as empty and brought back icons the user had deleted, and an unreadable shortcut or link dropped its program's entry. A missing file, a wrong file type and a malformed link still read as absent; any other error now reaches main(), which leaves the menu, the desktop and the record as they were. * Desktop programs: keep the placement record true when a run fails part way The placement record was read after the menu was already rewritten, so an unreadable record changed the menu although the run reported it had not. It is now read first. When writing desktop icons failed part way, the icons already written were not recorded, and the next run recreated any of them the user had deleted. The record is now written from the icons that exist after the attempt, icons are written in a fixed order, and a failed write leaves no temporary file on the desktop. os.path.exists and isfile also read a program whose path cannot be reached as missing; a stat that fails only because the file is absent now counts as missing, and any other error leaves everything as it was. * Desktop programs: leave the menu alone when Steam's shortcuts cannot be read The list of Steam shortcuts comes from a reader that treats an unreadable or damaged shortcuts.vdf as having no shortcuts, so a Steam shortcut's prefix could get a menu entry and a desktop icon of its own. The file is now checked first: a missing one still means no shortcuts, and any other read or parse failure leaves the menu and the desktop as they were. * Desktop programs: an unreadable Steam account or empty shortcuts file also stops the refresh account_dir takes an unreadable loginusers.vdf or userdata folder as missing, so the shortcuts check could be skipped and a Steam shortcut's prefix still get its own entry. Both are now read first, and an access error leaves the menu as it was. An empty shortcuts.vdf is now parsed like any other, so it stops the refresh too, the same way droiddeck-steam-shortcuts refuses to rewrite it. --------- Co-authored-by: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> --- .../launcher/session/SessionFiles.kt | 1 + tools/linuxfs/desktop/droiddeck-desktop | 1 + .../usr/local/bin/droiddeck-desktop-programs | 317 +++++++++++++++ .../overlay/usr/local/bin/droiddeck-open | 6 + tools/tests/test_desktop_programs.py | 370 ++++++++++++++++++ 5 files changed, 695 insertions(+) create mode 100755 tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-programs create mode 100644 tools/tests/test_desktop_programs.py diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index b65f3ac725..3b0172136c 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -72,6 +72,7 @@ object SessionFiles { "usr/local/bin/droiddeck-login1" to "usr/local/bin/droiddeck-login1", "usr/local/bin/droiddeck-steam-launch" to "usr/local/bin/droiddeck-steam-launch", "usr/local/bin/droiddeck-desktop-games" to "usr/local/bin/droiddeck-desktop-games", + "usr/local/bin/droiddeck-desktop-programs" to "usr/local/bin/droiddeck-desktop-programs", "usr/local/bin/droiddeck-desktop-bookmarks" to "usr/local/bin/droiddeck-desktop-bookmarks", "usr/local/bin/droiddeck-downloads" to "usr/local/bin/droiddeck-downloads", "usr/local/bin/droiddeck-root" to "usr/local/bin/droiddeck-root", diff --git a/tools/linuxfs/desktop/droiddeck-desktop b/tools/linuxfs/desktop/droiddeck-desktop index 799a3dee80..c36083d83c 100644 --- a/tools/linuxfs/desktop/droiddeck-desktop +++ b/tools/linuxfs/desktop/droiddeck-desktop @@ -31,6 +31,7 @@ export BL_DESKTOP=1 ln -sf /usr/local/bin/droiddeck-steam-launch /usr/local/bin/steamdeck-steam 2>/dev/null ln -sf /usr/local/bin/droiddeck-steam-shim /usr/local/bin/steam 2>/dev/null python3 /usr/local/bin/droiddeck-desktop-games 2>&1 | sed 's/^/[games] /' +python3 /usr/local/bin/droiddeck-desktop-programs 2>&1 | sed 's/^/[programs] /' # startplasma applies this file over the session environment, and keeps what an earlier session wrote. kwriteconfig6 --file plasma-localerc --group Formats --key LANG "${LANG:-C.UTF-8}" if [ -n "${LANGUAGE:-}" ]; then diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-programs b/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-programs new file mode 100755 index 0000000000..8c72b0ceff --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-programs @@ -0,0 +1,317 @@ +#!/usr/bin/python3 +import fcntl +import glob +import os +import re +import runpy +import stat +import struct +import subprocess +import sys +import zlib + +HOME = os.environ.get("HOME", "/root") +STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HOME, ".local/share/Steam") +BIN_DIR = os.path.dirname(os.path.abspath(__file__)) +OPEN = os.path.join(BIN_DIR, "droiddeck-open") +APPS_DIR = os.path.join(HOME, ".local/share/applications") +PLACED = os.path.join(HOME, ".local/share/droiddeck/desktop-programs-placed") +PREFIX = "droiddeck-program-" +SHORTCUT_BIT = 0x80000000 +WINDOWS_DESKTOPS = ("users/Public/Desktop", "users/steamuser/Desktop") +NOT_PROGRAMS = re.compile(r"(?i)^unins") +ABSENT = (FileNotFoundError, NotADirectoryError, IsADirectoryError) + +_run = None + + +def present(path, regular=False): + try: + mode = os.stat(path).st_mode + except ABSENT: + return False + return stat.S_ISREG(mode) if regular else True + + +def read(path): + try: + with open(path, encoding="utf-8", errors="replace") as f: + return f.read() + except ABSENT: + return None + + +def proton_run(): + global _run + if _run is None: + _run = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-proton-run")) + return _run + + +def shortcut_ids(root): + tool = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-steam-shortcuts")) + # account_dir takes either of these as missing when it cannot be read. + read(os.path.join(root, "config", "loginusers.vdf")) + listing(os.path.join(root, "userdata")) + account = tool["account_dir"](root) + if account: + try: + with open(os.path.join(account, "config", "shortcuts.vdf"), "rb") as f: + tool["parse"](f.read()) + except ABSENT: + pass + except (ValueError, IndexError, KeyError, struct.error) as error: + raise OSError("Steam's shortcuts.vdf cannot be read: %s" % error) from error + return {appid for appid, _, _ in proton_run()["shortcut_entries"](root)} + + +def runs_here(pfx, exe): + target = proton_run()["prefix_of"](exe) + return target is not None and os.path.realpath(target.compatdata) == os.path.realpath(os.path.dirname(pfx)) + + +def listing(folder, suffix=""): + try: + names = os.listdir(folder) + except ABSENT: + return None + return sorted(os.path.join(folder, name) for name in names if name.lower().endswith(suffix)) + + +def prefixes(root): + compatdata = os.path.join(root, "steamapps", "compatdata") + names = listing(compatdata) + if names is None: + return [] + owned = shortcut_ids(root) + found = [] + for name in (os.path.basename(path) for path in names): + if not re.fullmatch(r"-?[0-9]+", name): + continue + appid = int(name) % 2 ** 32 + pfx = os.path.join(compatdata, name, "pfx") + if appid & SHORTCUT_BIT and appid not in owned and listing(os.path.join(pfx, "drive_c", "proton_shortcuts")) is not None: + found.append((appid, pfx)) + return found + + +def zero_terminated(data, start, wide): + if wide: + end = start + while data[end:end + 2] not in (b"\0\0", b""): + end += 2 + return data[start:end].decode("utf-16-le", "replace") + end = data.find(b"\0", start) + return data[start:end if end >= 0 else len(data)].decode("cp1252", "replace") + + +def link_target(path): + try: + with open(path, "rb") as f: + data = f.read(1 << 16) + size, = struct.unpack_from("<I", data, 0) + flags, = struct.unpack_from("<I", data, 0x14) + pos, target = size, None + if flags & 0x1: + pos += 2 + struct.unpack_from("<H", data, pos)[0] + if flags & 0x2: + info_size, header, info_flags, _, local, _, suffix = struct.unpack_from("<7I", data, pos) + if info_flags & 0x1: + if header >= 0x24: + local_wide, suffix_wide = struct.unpack_from("<2I", data, pos + 0x1C) + target = zero_terminated(data, pos + local_wide, True) + zero_terminated(data, pos + suffix_wide, True) + else: + target = zero_terminated(data, pos + local, False) + zero_terminated(data, pos + suffix, False) + pos += info_size + args = "" + wide = bool(flags & 0x80) + for bit in (0x4, 0x8, 0x10, 0x20, 0x40): + if flags & bit: + count, = struct.unpack_from("<H", data, pos) + end = pos + 2 + count * (2 if wide else 1) + if bit == 0x20: + args = data[pos + 2:end].decode("utf-16-le" if wide else "cp1252", "replace").rstrip("\0") + pos = end + return target, args + except ABSENT + (struct.error, ValueError): + return None, "" + + +def host_path(pfx, windows): + found = re.fullmatch(r"([A-Za-z]):\\?(.*)", windows or "") + if not found: + return None + path = os.path.realpath(os.path.join(pfx, "dosdevices", found.group(1).lower() + ":")) + for part in (p for p in found.group(2).split("\\") if p): + exact = os.path.join(path, part) + if not os.path.lexists(exact): + try: + exact = next((os.path.join(path, name) for name in os.listdir(path) if name.lower() == part.lower()), exact) + except ABSENT: + return None + path = exact + return path if present(path) else None + + +def value(text, key): + found = re.search(r"^%s=(.*)$" % re.escape(key), text, re.M) + return found.group(1).strip() if found else "" + + +def windows_link(exec_value): + if len(exec_value) >= 2 and exec_value[0] == exec_value[-1] == '"': + exec_value = exec_value[1:-1] + # A desktop file escapes a backslash once for the key and again inside a quoted Exec argument. + return exec_value.replace("\\\\", "\\").replace("\\\\", "\\") + + +def icon(shortcuts, name): + best, size = "system-run", 0 + for apps in glob.glob(os.path.join(glob.escape(shortcuts), "icons", "*", "apps")): + found = re.fullmatch(r"(\d+)x\d+", os.path.basename(os.path.dirname(apps))) + path = os.path.join(apps, name + ".png") + if name and found and int(found.group(1)) > size and os.path.isfile(path): + best, size = path, int(found.group(1)) + return best + + +def program(pfx, link): + target, args = link_target(link) + exe = host_path(pfx, target) + if (exe and exe.lower().endswith(".exe") and not NOT_PROGRAMS.match(os.path.basename(exe)) and present(exe, regular=True) + and runs_here(pfx, exe)): + return exe, args + return None, "" + + +def programs(pfx): + shortcuts = os.path.join(pfx, "drive_c", "proton_shortcuts") + found = {} + for entry in listing(shortcuts, ".desktop") or []: + text = read(entry) or "" + link = host_path(pfx, windows_link(value(text, "Exec"))) + if not link or not link.lower().endswith(".lnk"): + continue + exe, args = program(pfx, link) + if exe: + found[exe] = dict(name=value(text, "Name") or os.path.splitext(os.path.basename(entry))[0], args=args, + icon=icon(shortcuts, value(text, "Icon")), wm_class=value(text, "StartupWMClass")) + return found + + +def on_windows_desktop(pfx): + found = set() + for folder in WINDOWS_DESKTOPS: + for link in listing(os.path.join(pfx, "drive_c", folder), ".lnk") or []: + exe, _ = program(pfx, link) + if exe: + found.add(exe) + return found + + +def windows_args(text): + args, current, started, quoted, slashes = [], "", False, False, 0 + for ch in text: + if ch == "\\": + slashes += 1 + started = True + elif ch == '"': + current += "\\" * (slashes // 2) + ('"' if slashes % 2 else "") + if slashes % 2 == 0: + quoted = not quoted + slashes, started = 0, True + else: + current += "\\" * slashes + slashes = 0 + if ch in " \t" and not quoted: + if started: + args.append(current) + current, started = "", False + else: + current += ch + started = True + if started: + args.append(current + "\\" * slashes) + return args + + +def quoted(arg): + escaped = re.sub(r'([\\"`$])', r"\\\1", arg).replace("%", "%%") + return '"%s"' % escaped.replace("\\", "\\\\") + + +def entry(exe, found): + args = windows_args(found["args"]) + lines = ["[Desktop Entry]", "Type=Application", "Name=%s" % found["name"].replace("\n", " "), + "Comment=Windows program installed from the desktop", + "Exec=%s" % " ".join(quoted(arg) for arg in [OPEN, exe] + args), + "Icon=%s" % found["icon"], "Terminal=false", "Categories=Game;"] + if found["wm_class"]: + lines.append("StartupWMClass=%s" % found["wm_class"]) + return "\n".join(lines) + "\n" + + +def desktop_dir(): + try: + path = subprocess.run(["xdg-user-dir", "DESKTOP"], capture_output=True, text=True, timeout=5).stdout.strip() + except (OSError, subprocess.SubprocessError): + path = "" + return path if path and path != HOME else os.path.join(HOME, "Desktop") + + +def sync(directory, wanted, mode=0o644): + os.makedirs(directory, exist_ok=True) + for name in os.listdir(directory): + if name.startswith(PREFIX) and name.endswith(".desktop") and name not in wanted: + os.unlink(os.path.join(directory, name)) + for name, body in wanted.items(): + path = os.path.join(directory, name) + if read(path) != body: + try: + with open(path + ".tmp", "w", encoding="utf-8") as f: + f.write(body) + os.chmod(path + ".tmp", mode) + os.replace(path + ".tmp", path) + except OSError: + if os.path.lexists(path + ".tmp"): + os.unlink(path + ".tmp") + raise + + +def main(): + os.makedirs(os.path.dirname(PLACED), exist_ok=True) + with open(PLACED + ".lock", "w") as lock: + fcntl.flock(lock, fcntl.LOCK_EX) + try: + refresh() + except OSError as error: + print("droiddeck-desktop-programs: the menu is left as it was (%s)" % error) + + +def refresh(): + menu, desktop_wanted = {}, set() + for appid, pfx in prefixes(STEAM_ROOT): + on_desktop = on_windows_desktop(pfx) + for exe, found in programs(pfx).items(): + name = "%s%d-%08x.desktop" % (PREFIX, appid, zlib.crc32(exe.encode("utf-8"))) + menu[name] = entry(exe, found) + if exe in on_desktop: + desktop_wanted.add(name) + placed = set((read(PLACED) or "").split()) + sync(APPS_DIR, menu) + desktop = desktop_dir() + shown = {name: menu[name] for name in sorted(desktop_wanted) + if name not in placed or present(os.path.join(desktop, name), regular=True)} + try: + sync(desktop, shown, 0o755) + finally: + written = {name for name in shown if present(os.path.join(desktop, name), regular=True)} + with open(PLACED + ".tmp", "w", encoding="utf-8") as f: + f.write("".join(name + "\n" for name in sorted((placed | written) & set(menu)))) + os.replace(PLACED + ".tmp", PLACED) + print("droiddeck-desktop-programs: %d program%s in the menu, %d on the desktop" % ( + len(menu), "" if len(menu) == 1 else "s", len(shown))) + + +if __name__ == "__main__": + main() diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-open b/tools/linuxfs/overlay/usr/local/bin/droiddeck-open index 0edd302123..45f806297c 100644 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-open +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-open @@ -17,6 +17,7 @@ PROTON_RUN = os.path.join(BIN, "droiddeck-proton-run") APPIMAGE_RUN = os.path.join(BIN, "droiddeck-appimage-run") SCRIPT_RUN = os.path.join(BIN, "droiddeck-script-run") STEAM_LAUNCH = os.path.join(BIN, "droiddeck-steam-launch") +PROGRAMS = os.path.join(BIN, "droiddeck-desktop-programs") CACHE = os.path.join(HOME, ".cache", "droiddeck") IMPORTS = {"appimage": ("/opt/appimages/user", "app"), "folder": ("/opt/droiddeck-apps", "entry")} SHARED_FOLDERS = ("alarms", "android", "audiobooks", "dcim", "documents", "download", "movies", "music", @@ -395,6 +396,11 @@ def main(argv): if status != 0 and time.monotonic() - started < QUICK_FAILURE: notify("%s did not start" % os.path.basename(path), "It exited with status %d; the session's desktop.log says why." % status) + if what == "windows": + try: + subprocess.call([sys.executable, PROGRAMS]) + except OSError as error: + say("%s: %s" % (PROGRAMS, error)) return status diff --git a/tools/tests/test_desktop_programs.py b/tools/tests/test_desktop_programs.py new file mode 100644 index 0000000000..8abd128420 --- /dev/null +++ b/tools/tests/test_desktop_programs.py @@ -0,0 +1,370 @@ +import contextlib +import os +from pathlib import Path +import runpy +import shutil +import stat +import struct +import sys +import tempfile +import unittest +from unittest import mock + +BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin" +PROGRAMS = runpy.run_path(str(BIN / "droiddeck-desktop-programs"))["main"].__globals__ +SHORTCUT_IDS = PROGRAMS["shortcut_ids"] +OPEN = runpy.run_path(str(BIN / "droiddeck-open"))["main"].__globals__ + +NEXON = 3908901178 + + +def lnk(target, args="", wide_info=False): + flags = 0x2 | 0x80 | (0x20 if args else 0) + header = bytearray(76) + struct.pack_into("<I", header, 0, 76) + struct.pack_into("<I", header, 0x14, flags) + local = target.encode("cp1252") + b"\0" + if wide_info: + wide = target.encode("utf-16-le") + b"\0\0" + size = 36 + len(local) + len(wide) + 2 + info = struct.pack("<9I", size, 36, 1, 0, 36, 0, 36 + len(local) - 1, 36 + len(local), size - 2) + local + wide + b"\0\0" + else: + info = struct.pack("<7I", 28 + len(local), 28, 1, 0, 28, 0, 28 + len(local) - 1) + local + strings = b"" + if args: + strings = struct.pack("<H", len(args) + 1) + (args + "\0").encode("utf-16-le") + return bytes(header) + info + strings + + +class ProgramsTest(unittest.TestCase): + def setUp(self): + self.tmp = Path(tempfile.mkdtemp()) + self.addCleanup(shutil.rmtree, self.tmp, True) + self.home = self.tmp / "home" + self.steam = self.home / ".local/share/Steam" + self.apps = self.home / ".local/share/applications" + self.desktop = self.home / "Desktop" + self.shortcuts = set() + patch = mock.patch.dict(PROGRAMS, { + "STEAM_ROOT": str(self.steam), "APPS_DIR": str(self.apps), + "PLACED": str(self.home / ".local/share/droiddeck/desktop-programs-placed"), + "desktop_dir": lambda: str(self.desktop), "shortcut_ids": lambda root: self.shortcuts, + "print": lambda *a: None, + }) + patch.start() + self.addCleanup(patch.stop) + + def prefix(self, appid): + pfx = self.steam / "steamapps/compatdata" / str(appid) / "pfx" + (pfx / "drive_c").mkdir(parents=True) + (pfx / "dosdevices").mkdir() + os.symlink("../drive_c", pfx / "dosdevices/c:") + os.symlink("/", pfx / "dosdevices/z:") + return pfx + + def install(self, pfx, name="Nexon Launcher", folder="Program Files (x86)/Nexon/Nexon Launcher", + exe="nexon_launcher.exe", on_desktop=True, target=None, args=""): + program = pfx / "drive_c" / folder / exe + program.parent.mkdir(parents=True, exist_ok=True) + program.write_bytes(b"MZ") + windows = target or "C:\\" + folder.replace("/", "\\") + "\\" + exe + menu = "ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\" + name + ".lnk" + link = pfx / "drive_c" / menu.replace("\\", "/") + link.parent.mkdir(parents=True, exist_ok=True) + link.write_bytes(lnk(windows, args)) + shortcuts = pfx / "drive_c/proton_shortcuts" + for size in ("16x16", "256x256"): + icon = shortcuts / "icons" / size / "apps/6D6F_logo.0.png" + icon.parent.mkdir(parents=True, exist_ok=True) + icon.write_bytes(b"png") + (shortcuts / (name + ".desktop")).write_text( + "[Desktop Entry]\nName=%s\nExec=\"%s\"\nType=Application\nStartupNotify=true\nIcon=6D6F_logo.0\n" + "StartupWMClass=%s\n" % (name, ("C:\\" + menu).replace("\\", "\\\\\\\\"), exe)) + if on_desktop: + desktop = pfx / "drive_c/users/Public/Desktop" / (name + ".lnk") + desktop.parent.mkdir(parents=True, exist_ok=True) + desktop.write_bytes(lnk(windows, args)) + return program + + def entries(self, folder): + return sorted(p.name for p in folder.glob(PROGRAMS["PREFIX"] + "*.desktop")) if folder.is_dir() else [] + + def test_an_installed_program_gets_a_menu_entry_that_opens_it_in_its_prefix(self): + pfx = self.prefix(NEXON) + exe = self.install(pfx) + PROGRAMS["main"]() + [name] = self.entries(self.apps) + self.assertTrue(name.startswith("droiddeck-program-%d-" % NEXON)) + text = (self.apps / name).read_text() + self.assertIn("Name=Nexon Launcher\n", text) + self.assertIn('Exec="%s" "%s"\n' % (PROGRAMS["OPEN"], exe), text) + self.assertIn("Icon=%s\n" % (pfx / "drive_c/proton_shortcuts/icons/256x256/apps/6D6F_logo.0.png"), text) + self.assertIn("StartupWMClass=nexon_launcher.exe\n", text) + + def test_it_lands_on_the_desktop_once_when_its_installer_put_it_there(self): + pfx = self.prefix(NEXON) + self.install(pfx) + self.install(pfx, name="Tool", folder="Tool", exe="tool.exe", on_desktop=False) + PROGRAMS["main"]() + self.assertEqual(2, len(self.entries(self.apps))) + [name] = self.entries(self.desktop) + self.assertEqual((self.apps / name).read_text(), (self.desktop / name).read_text()) + self.assertTrue((self.desktop / name).stat().st_mode & stat.S_IXUSR) + (self.desktop / name).unlink() + PROGRAMS["main"]() + self.assertEqual([], self.entries(self.desktop)) + self.assertEqual(2, len(self.entries(self.apps))) + + def test_an_uninstalled_program_leaves_the_menu_and_the_desktop(self): + exe = self.install(self.prefix(NEXON)) + PROGRAMS["main"]() + exe.unlink() + PROGRAMS["main"]() + self.assertEqual([], self.entries(self.apps)) + self.assertEqual([], self.entries(self.desktop)) + self.assertEqual("", Path(PROGRAMS["PLACED"]).read_text()) + + def test_steam_games_and_shortcuts_keep_their_own_entries(self): + self.install(self.prefix(1238080)) + self.install(self.prefix(2243774769)) + self.shortcuts = {2243774769} + PROGRAMS["main"]() + self.assertEqual([], self.entries(self.apps)) + + def steam_shortcut(self, account, appid): + vdf = self.steam / "userdata" / str(account) / "config/shortcuts.vdf" + vdf.parent.mkdir(parents=True) + vdf.write_bytes(b"\0shortcuts\0\0" + b"0\0\x02appid\0" + struct.pack("<i", appid - 2 ** 32) + + b"\x01Exe\0\"C:\\\\launcher.exe\"\0\x08\x08\x08") + return vdf + + def test_steam_shortcuts_it_cannot_read_leave_the_menu_as_it_was(self): + if os.geteuid() == 0: + self.skipTest("file permissions do not apply to root") + self.install(self.prefix(NEXON)) + vdf = self.steam_shortcut(123, NEXON) + with mock.patch.dict(PROGRAMS, {"shortcut_ids": SHORTCUT_IDS}): + PROGRAMS["main"]() + self.assertEqual([], self.entries(self.apps)) + vdf.chmod(0) + try: + PROGRAMS["main"]() + finally: + vdf.chmod(0o644) + self.assertEqual([], self.entries(self.apps)) + for damaged in (vdf.read_bytes()[:20], b""): + vdf.write_bytes(damaged) + PROGRAMS["main"]() + self.assertEqual([], self.entries(self.apps)) + vdf.unlink() + PROGRAMS["main"]() + self.assertEqual(1, len(self.entries(self.apps))) + + def test_a_steam_account_it_cannot_look_up_leaves_the_menu_as_it_was(self): + if os.geteuid() == 0: + self.skipTest("file permissions do not apply to root") + self.install(self.prefix(NEXON)) + self.steam_shortcut(123, NEXON) + (self.steam / "userdata/456").mkdir() + users = self.steam / "config/loginusers.vdf" + users.parent.mkdir(parents=True) + users.write_text('"users"\n{\n\t"%d"\n\t{\n\t\t"MostRecent"\t\t"1"\n\t}\n}\n' % (76561197960265728 + 123)) + with mock.patch.dict(PROGRAMS, {"shortcut_ids": SHORTCUT_IDS}): + PROGRAMS["main"]() + self.assertEqual([], self.entries(self.apps)) + for unreadable in (users, self.steam / "userdata"): + unreadable.chmod(0) + try: + PROGRAMS["main"]() + finally: + unreadable.chmod(0o755) + self.assertEqual([], self.entries(self.apps)) + + def test_uninstallers_and_links_to_other_files_get_no_entry(self): + pfx = self.prefix(NEXON) + self.install(pfx, name="Uninstall", exe="unins000.exe") + self.install(pfx, name="Read me", exe="readme.txt") + PROGRAMS["main"]() + self.assertEqual([], self.entries(self.apps)) + + def test_a_link_in_other_letter_case_with_arguments_still_starts_the_program(self): + pfx = self.prefix(NEXON) + exe = self.install(pfx, target="C:\\PROGRAM FILES (X86)\\NEXON\\nexon launcher\\NEXON_LAUNCHER.EXE", + args='-mode "full screen" C:\\save') + PROGRAMS["main"]() + [name] = self.entries(self.apps) + self.assertIn('Exec="%s" "%s" "-mode" "full screen" "C:\\\\\\\\save"\n' % (PROGRAMS["OPEN"], exe), + (self.apps / name).read_text()) + + def test_a_link_to_a_program_outside_the_prefix_gets_no_entry(self): + outside = self.tmp / "Downloads/tool.exe" + outside.parent.mkdir(parents=True) + outside.write_bytes(b"MZ") + self.install(self.prefix(NEXON), name="Tool", target="Z:" + str(outside).replace("/", "\\")) + PROGRAMS["main"]() + self.assertEqual([], self.entries(self.apps)) + + def test_windows_arguments_follow_windows_quoting(self): + cases = { + "--profile=O'Brien": ["--profile=O'Brien"], + '-mode "full screen" C:\\save': ["-mode", "full screen", "C:\\save"], + '"a\\"b" \\\\server\\share': ['a"b', "\\\\server\\share"], + '"x\\\\" y': ["x\\", "y"], + " ": [], + } + for text, expected in cases.items(): + with self.subTest(text): + self.assertEqual(expected, PROGRAMS["windows_args"](text)) + + def test_an_apostrophe_in_a_links_arguments_does_not_stop_the_refresh(self): + exe = self.install(self.prefix(NEXON), args="--profile=O'Brien") + PROGRAMS["main"]() + [name] = self.entries(self.apps) + self.assertIn('Exec="%s" "%s" "--profile=O\'Brien"\n' % (PROGRAMS["OPEN"], exe), (self.apps / name).read_text()) + + def test_a_file_or_folder_it_cannot_read_leaves_the_menu_and_desktop_alone(self): + if os.geteuid() == 0: + self.skipTest("file permissions do not apply to root") + pfx = self.prefix(NEXON) + self.install(pfx, target="C:\\PROGRAM FILES (X86)\\Nexon\\Nexon Launcher\\nexon_launcher.exe") + PROGRAMS["main"]() + menu, desktop = self.entries(self.apps), self.entries(self.desktop) + placed = Path(PROGRAMS["PLACED"]).read_text() + drive = pfx / "drive_c" + unreadable = { + "compatdata": (self.steam / "steamapps/compatdata", 0), + "proton_shortcuts": (drive / "proton_shortcuts", 0), + "windows desktop": (drive / "users/Public/Desktop", 0), + "shortcut file": (drive / "proton_shortcuts/Nexon Launcher.desktop", 0), + "link file": (drive / "ProgramData/Microsoft/Windows/Start Menu/Programs/Nexon Launcher.lnk", 0), + "folder above a differently cased part": (drive, 0o311), + } + for name, (path, mode) in unreadable.items(): + with self.subTest(name): + before = path.stat().st_mode + path.chmod(mode) + try: + PROGRAMS["main"]() + finally: + path.chmod(before) + self.assertEqual(menu, self.entries(self.apps)) + self.assertEqual(desktop, self.entries(self.desktop)) + self.assertEqual(placed, Path(PROGRAMS["PLACED"]).read_text()) + + def test_an_unreadable_placement_record_does_not_bring_back_a_deleted_icon(self): + if os.geteuid() == 0: + self.skipTest("file permissions do not apply to root") + self.install(self.prefix(NEXON)) + PROGRAMS["main"]() + [icon] = self.entries(self.desktop) + (self.desktop / icon).unlink() + record = Path(PROGRAMS["PLACED"]) + placed = record.read_text() + record.chmod(0) + try: + PROGRAMS["main"]() + finally: + record.chmod(0o644) + self.assertEqual([], self.entries(self.desktop)) + self.assertEqual(placed, record.read_text()) + + def test_icons_written_before_a_failed_write_are_recorded(self): + pfx = self.prefix(NEXON) + self.install(pfx) + self.install(pfx, name="Tool", folder="Tool", exe="tool.exe") + PROGRAMS["main"]() + first, second = self.entries(self.apps) + for name in (first, second): + (self.desktop / name).unlink() + Path(PROGRAMS["PLACED"]).write_text("") + (self.desktop / second / "blocked").mkdir(parents=True) + PROGRAMS["main"]() + self.assertTrue((self.desktop / first).is_file()) + self.assertEqual(first + "\n", Path(PROGRAMS["PLACED"]).read_text()) + self.assertEqual([], list(self.desktop.glob("*.tmp"))) + (self.desktop / first).unlink() + shutil.rmtree(self.desktop / second) + PROGRAMS["main"]() + self.assertEqual([second], self.entries(self.desktop)) + + def test_an_unreadable_placement_record_leaves_the_menu_as_it_was(self): + if os.geteuid() == 0: + self.skipTest("file permissions do not apply to root") + pfx = self.prefix(NEXON) + self.install(pfx) + PROGRAMS["main"]() + menu = self.entries(self.apps) + self.install(pfx, name="Tool", folder="Tool", exe="tool.exe") + record = Path(PROGRAMS["PLACED"]) + record.chmod(0) + try: + PROGRAMS["main"]() + finally: + record.chmod(0o644) + self.assertEqual(menu, self.entries(self.apps)) + + def test_a_program_behind_a_folder_it_cannot_reach_keeps_its_entry(self): + if os.geteuid() == 0: + self.skipTest("file permissions do not apply to root") + exe = self.install(self.prefix(NEXON)) + PROGRAMS["main"]() + menu, desktop = self.entries(self.apps), self.entries(self.desktop) + hidden = self.tmp / "locked/nexon_launcher.exe" + hidden.parent.mkdir() + hidden.write_bytes(b"MZ") + exe.unlink() + exe.symlink_to(hidden) + hidden.parent.chmod(0) + try: + PROGRAMS["main"]() + finally: + hidden.parent.chmod(0o755) + self.assertEqual(menu, self.entries(self.apps)) + self.assertEqual(desktop, self.entries(self.desktop)) + + def test_without_any_prefixes_the_entries_go(self): + self.install(self.prefix(NEXON)) + PROGRAMS["main"]() + shutil.rmtree(self.steam / "steamapps/compatdata") + PROGRAMS["main"]() + self.assertEqual([], self.entries(self.apps)) + + def test_refreshes_take_turns(self): + calls = [] + with mock.patch.object(PROGRAMS["fcntl"], "flock", lambda lock, op: calls.append(op)), \ + mock.patch.dict(PROGRAMS, {"refresh": lambda: calls.append("refresh")}): + PROGRAMS["main"]() + self.assertEqual([PROGRAMS["fcntl"].LOCK_EX, "refresh"], calls) + + def test_a_link_with_a_unicode_path_block_is_read_too(self): + path = self.tmp / "game.lnk" + path.write_bytes(lnk("C:\\Games\\Ünïcode\\game.exe", wide_info=True)) + self.assertEqual(("C:\\Games\\Ünïcode\\game.exe", ""), PROGRAMS["link_target"](str(path))) + + +class OpenTest(unittest.TestCase): + def run_program(self, name, data): + folder = Path(tempfile.mkdtemp()) + self.addCleanup(shutil.rmtree, folder, True) + program = folder / name + program.write_bytes(data) + ran = [] + with mock.patch.dict(OPEN, {"steam_title": lambda path: None, "placed": lambda cmd, *a: cmd, + "say": lambda *a: None, "notify": lambda *a: None, "game_folder": lambda path: None, + "for_x86": lambda path: False}), \ + mock.patch.object(OPEN["subprocess"], "call", lambda cmd: ran.append(cmd) or 0), contextlib.chdir(folder): + self.assertEqual(0, OPEN["main"]([str(program)])) + return ran + + def test_a_windows_run_brings_the_menu_of_installed_programs_up_to_date(self): + ran = self.run_program("NexonLauncherSetup.exe", b"MZ" + bytes(62)) + self.assertEqual([sys.executable, OPEN["PROGRAMS"]], ran[-1]) + self.assertEqual(2, len(ran)) + + def test_other_programs_leave_the_menu_alone(self): + ran = self.run_program("start.sh", b"echo hi\n") + self.assertEqual(1, len(ran)) + + +if __name__ == "__main__": + unittest.main() From 5971b91ed4711cafdb3943872e96e2ac3b79de1e Mon Sep 17 00:00:00 2001 From: MaxsTechReview <maxjividen@gmail.com> Date: Thu, 5 Nov 2026 18:33:38 -0500 Subject: [PATCH 78/85] fix: an unplugged game drive falls back to internal storage (#1913) * fix: an unplugged game drive falls back to internal storage When the drive chosen for game storage is not connected, installs, sessions and the install picker use internal storage instead of failing with "Game storage is unavailable". The saved drive is kept and used again once it is plugged back in. * fix: store installs set to external use internal storage while the drive is unplugged With default storage set to external, a missing drive or folder no longer stops installs at the location dialog or leaves the Epic launcher pointing at it. Installs go to internal storage and switch back to the drive once it is connected again. * fix: external installs do not move to another card while the saved drive is unplugged * fix(storage): verify saved volume is mounted * fix(storage): reject unknown external volumes --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> --- .../droiddeck/launcher/session/GameStorage.kt | 28 +++++++++++- .../launcher/stores/StoreInstallRoot.kt | 15 ++++--- .../launcher/session/GameStorageTest.kt | 43 +++++++++++++++++++ .../launcher/stores/StoreInstallRootTest.kt | 27 ++++++++++-- .../launcher/stores/epic/EpicClientTest.kt | 6 +-- 5 files changed, 106 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/GameStorage.kt b/app/src/main/java/com/droiddeck/launcher/session/GameStorage.kt index eb5bb4e0d9..729533d5a2 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GameStorage.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GameStorage.kt @@ -48,7 +48,33 @@ object GameStorage { return when { pref == SessionPrefs.GAME_STORAGE_OFF -> null pref.isEmpty() -> options(context).firstOrNull()?.let { Option(it.name, it.path) } - else -> Option(SessionPrefs.gameStorageLabel(context), pref) + else -> Option(SessionPrefs.gameStorageLabel(context), pref).takeIf { attached(File(pref)) } + } + } + + fun disconnected(context: Context): Boolean { + val pref = SessionPrefs.gameStorage(context) + return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(pref)) + } + + internal fun attached(path: File): Boolean = + attached(path, runCatching { Environment.getExternalStorageState(path) }.getOrNull()) + + internal fun attached( + path: File, + state: String?, + externalStoragePath: Boolean = isExternalStoragePath(path), + ): Boolean = when { + state == Environment.MEDIA_MOUNTED || state == Environment.MEDIA_MOUNTED_READ_ONLY -> true + externalStoragePath -> false + state == Environment.MEDIA_UNKNOWN || state == null -> path.isDirectory || path.parentFile?.isDirectory == true + else -> false + } + + private fun isExternalStoragePath(path: File): Boolean { + val absolute = path.absoluteFile.toPath().normalize() + return listOf(File("/storage"), File("/mnt/media_rw")).any { + absolute.startsWith(it.absoluteFile.toPath().normalize()) } } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt index 2ba84041f8..b3c3fc0795 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt @@ -97,20 +97,25 @@ object StoreInstallRoot { fun installRoot(context: Context): File = internalRoot(context) - fun externalTarget(context: Context): Target? = - if (SessionPrefs.defaultStorageFolder(context).isNotBlank()) customTarget(context) - else detectedExternalTarget(context) + fun externalTarget(context: Context): Target? = when { + SessionPrefs.defaultStorageFolder(context).isNotBlank() -> customTarget(context) + GameStorage.disconnected(context) -> null + else -> detectedExternalTarget(context) + } internal fun externalTarget(targets: List<Target>, internalRoot: File): Target? = targets.firstOrNull { it.folder && it.root.absolutePath != internalRoot.absolutePath } ?: targets.firstOrNull { it.removable && it.root.absolutePath != internalRoot.absolutePath } fun defaultTarget(context: Context): Target? = when (SessionPrefs.defaultStorage(context)) { - SessionPrefs.DEFAULT_STORAGE_INTERNAL -> Target(internalRoot(context), context.getString(com.droiddeck.launcher.R.string.games_internal), removable = false) - SessionPrefs.DEFAULT_STORAGE_EXTERNAL -> externalTarget(context) + SessionPrefs.DEFAULT_STORAGE_INTERNAL -> internalTarget(context) + SessionPrefs.DEFAULT_STORAGE_EXTERNAL -> externalTarget(context) ?: internalTarget(context) else -> null } + private fun internalTarget(context: Context) = + Target(internalRoot(context), context.getString(com.droiddeck.launcher.R.string.games_internal), removable = false) + fun libraryRoot(context: Context): File? = GameStorage.effective(context)?.let { File(it.path, ON_VOLUME) } fun roots(context: Context): List<File> { diff --git a/app/src/test/java/com/droiddeck/launcher/session/GameStorageTest.kt b/app/src/test/java/com/droiddeck/launcher/session/GameStorageTest.kt index f731c4f1c3..88eb0e0ae2 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/GameStorageTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/GameStorageTest.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.session +import android.os.Environment import com.droiddeck.launcher.frontend.AddedGames import java.io.File import org.junit.Assert.* @@ -48,4 +49,46 @@ class GameStorageTest { SessionPrefs.setAddedGamesDirs(app, odd.map { it.path }) assertTrue(GameStorage.gamesFolderLibraries(app).isEmpty()) } + + @Test fun anUnpluggedDriveFallsBackToInternalWithoutForgettingIt() { + val gone = "/storage/0000-0000/Android/data/com.droiddeck.launcher/files/steam" + SessionPrefs.setGameStorage(app, gone, "USB drive") + assertNull(GameStorage.effective(app)) + assertNull(GameStorage.x64CardLibrary(app)) + assertEquals(gone, SessionPrefs.gameStorage(app)) + } + + @Test fun aPluggedInDriveStaysTheLibrary() { + val files = tmp.newFolder("files") + val steam = File(files, "steam") + SessionPrefs.setGameStorage(app, steam.path, "USB drive") + assertEquals(steam.path, GameStorage.effective(app)?.path) + steam.mkdirs() + assertEquals(steam.path, GameStorage.effective(app)?.path) + assertEquals("USB drive", GameStorage.effective(app)?.label) + } + + @Test fun missingSubfolderIsAttachedWhenItsVolumeIsMounted() { + val path = File(tmp.newFolder("mounted-volume"), "missing/steam") + assertTrue(GameStorage.attached(path, Environment.MEDIA_MOUNTED, externalStoragePath = true)) + } + + @Test fun removedVolumeIsNotAttachedEvenWhenItsParentExists() { + val parent = tmp.newFolder("storage") + val volume = File(parent, "0000-0000") + assertTrue(parent.isDirectory) + assertFalse(GameStorage.attached(volume, Environment.MEDIA_REMOVED, externalStoragePath = true)) + assertFalse(GameStorage.attached(volume, Environment.MEDIA_UNKNOWN, externalStoragePath = true)) + } + + @Test fun onlyASavedDriveThatIsMissingCountsAsDisconnected() { + SessionPrefs.setGameStorage(app, "", "") + assertFalse(GameStorage.disconnected(app)) + SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") + assertFalse(GameStorage.disconnected(app)) + SessionPrefs.setGameStorage(app, "/storage/0000-0000/Android/data/com.droiddeck.launcher/files/steam", "USB drive") + assertTrue(GameStorage.disconnected(app)) + SessionPrefs.setGameStorage(app, tmp.newFolder("plugged").path, "USB drive") + assertFalse(GameStorage.disconnected(app)) + } } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt index c368ca082b..f5ce0d2a97 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt @@ -53,10 +53,10 @@ class StoreInstallRootTest { assertEquals(SessionPrefs.DEFAULT_STORAGE_ASK, SessionPrefs.defaultStorage(app)) } - @Test fun defaultExternalStorageFallsBackToTheInstallDialogWhenNoCardIsPresent() { + @Test fun defaultExternalStorageFallsBackToInternalWhenNoCardIsPresent() { SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") SessionPrefs.setDefaultStorage(app, SessionPrefs.DEFAULT_STORAGE_EXTERNAL) - assertNull(StoreInstallRoot.defaultTarget(app)) + assertEquals(StoreInstallRoot.internalRoot(app).absolutePath, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath) } @Test fun aChosenFolderIsUsedForDefaultExternalStorage() { @@ -74,7 +74,7 @@ class StoreInstallRootTest { assertFalse(File(root, ".droiddeck-write-probe").exists()) } - @Test fun aDisconnectedChosenFolderDoesNotFallBackToAnotherTarget() { + @Test fun aDisconnectedChosenFolderFallsBackToInternalUntilItIsBack() { val card = File(app.filesDir, "card/steam").apply { mkdirs() } SessionPrefs.setGameStorage(app, card.path, "Card") val folder = File(app.filesDir, "usb/SSD").apply { mkdirs() } @@ -83,8 +83,11 @@ class StoreInstallRootTest { assertNotNull(StoreInstallRoot.defaultTarget(app)) assertTrue(folder.delete()) - assertNull(StoreInstallRoot.defaultTarget(app)) + assertEquals(StoreInstallRoot.internalRoot(app).absolutePath, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath) assertEquals(File(card, "Games").absolutePath, StoreInstallRoot.detectedExternalTarget(app)?.root?.absolutePath) + + assertTrue(folder.mkdirs()) + assertEquals(File(folder, "Games").absolutePath, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath) } @Test fun filesOnAChosenFolderAreMappedIntoTheGuest() { @@ -303,4 +306,20 @@ class StoreInstallRootTest { assertEquals("itch", StoreInstallRoot.storeDir(File("/games"), Store.ITCH).name) assertEquals("Game Jolt", StoreInstallRoot.storeDir(File("/games"), Store.GAMEJOLT).name) } + + @Test fun anUnpluggedLibraryDriveSendsInstallsToInternalUntilItIsBack() { + val files = File(app.filesDir, "usb-drive/files") + val library = File(files, "steam") + SessionPrefs.setGameStorage(app, library.path, "USB drive") + SessionPrefs.setDefaultStorage(app, SessionPrefs.DEFAULT_STORAGE_EXTERNAL) + val internal = StoreInstallRoot.internalRoot(app).absolutePath + + assertEquals(internal, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath) + assertEquals(listOf(internal), StoreInstallRoot.targets(app).map { it.root.absolutePath }) + assertNull(StoreInstallRoot.libraryRoot(app)) + + library.mkdirs() + assertEquals(File(library, "Games").absolutePath, StoreInstallRoot.defaultTarget(app)?.root?.absolutePath) + assertEquals(File(library, "Games").absolutePath, StoreInstallRoot.libraryRoot(app)?.absolutePath) + } } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicClientTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicClientTest.kt index 60df152e05..1b92f1f1a0 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicClientTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicClientTest.kt @@ -457,7 +457,7 @@ class EpicClientTest { assertEquals("/root/Games/Stores/Epic", EpicClient.prepareInstallDir(context)) } - @Test fun aDisconnectedDefaultFolderKeepsTheLauncherInstallDir() { + @Test fun aDisconnectedDefaultFolderMovesTheLauncherInstallDirToInternal() { val context = org.robolectric.RuntimeEnvironment.getApplication() val previousStorage = com.droiddeck.launcher.session.SessionPrefs.defaultStorage(context) val previousFolder = com.droiddeck.launcher.session.SessionPrefs.defaultStorageFolder(context) @@ -470,8 +470,8 @@ class EpicClientTest { com.droiddeck.launcher.session.SessionPrefs.setDefaultStorageFolder( context, File(context.filesDir, "missing-${System.nanoTime()}").path, "SSD") try { - assertEquals(current, EpicClient.prepareInstallDir(context)) - assertEquals(current, org.json.JSONObject(settings.readText()).getString("defaultInstallDir")) + assertEquals("/root/Games/Stores/Epic", EpicClient.prepareInstallDir(context)) + assertEquals("/root/Games/Stores/Epic", org.json.JSONObject(settings.readText()).getString("defaultInstallDir")) } finally { com.droiddeck.launcher.session.SessionPrefs.setDefaultStorage(context, previousStorage) if (previousFolder.isBlank()) com.droiddeck.launcher.session.SessionPrefs.clearDefaultStorageFolder(context) From cd452e2b608c4dbb9c42c0b7b84c8e7864aa93cd Mon Sep 17 00:00:00 2001 From: Moroni Granja <moronigranja@gmail.com> Date: Thu, 5 Nov 2026 20:56:21 -0300 Subject: [PATCH 79/85] fix: upload GOG cloud saves in Galaxy's gzip + metadata format (#1952) fix: upload GOG cloud saves in Galaxy's gzip format --- .../droiddeck/launcher/stores/CloudPlan.kt | 13 ++ .../droiddeck/launcher/stores/CloudSaves.kt | 27 +++- .../launcher/stores/CloudTransport.kt | 123 ++++++++++++++++-- .../launcher/stores/CloudPlanTest.kt | 16 +++ .../launcher/stores/CloudSavesTest.kt | 2 +- .../launcher/stores/GogCloudKeysTest.kt | 75 +++++++++++ docs/development/stores.md | 10 ++ 7 files changed, 244 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/CloudPlan.kt b/app/src/main/java/com/droiddeck/launcher/stores/CloudPlan.kt index 6368f558ad..d3c63b203a 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/CloudPlan.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/CloudPlan.kt @@ -52,6 +52,19 @@ object CloudPlan { return Plan(transfer, conflicts, same) } + /** + * Files to send. GOG objects uploaded by older builds are raw while their cloud hash is still the + * local raw MD5, so they appear in [Plan.same]; resending them stores the gzip form Galaxy reads. + * A forced GOG upload is the manual repair path and sends every local file, including unchanged + * ones the service gives no hash for; once rewritten the cloud hash is the compressed MD5. + */ + fun upSend(plan: Plan, force: Boolean, repairRawGog: Boolean, allLocal: Collection<String> = emptyList()): List<String> { + if (force) { + return (plan.transfer + plan.conflicts + if (repairRawGog) allLocal else emptyList()).distinct() + } + return (plan.transfer + if (repairRawGog) plan.same else emptyList()).distinct() + } + fun toJson(baseline: Map<String, Entry>): String = JSONObject().apply { for ((k, e) in baseline) put(k, JSONObject().put("l", e.localMd5).put("c", e.cloudMd5 ?: "").put("t", e.cloudModified)) }.toString() diff --git a/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt b/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt index 2af7a9bff4..48244c4895 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt @@ -374,18 +374,31 @@ object CloudSaves { val remote = remote(cloud) { it in files } val local = files.mapValues { CloudPlan.Local(md5(it.value)) } val plan = CloudPlan.up(local, remote.mapValues { CloudPlan.Remote(it.value.md5, it.value.modifiedMs) }, base) - val send = if (force) plan.transfer + plan.conflicts else plan.transfer + val send = CloudPlan.upSend(plan, force, cloud is GogCloud, files.keys) val next = HashMap(base) for (name in plan.same) remote[name]?.let { r -> next[name] = CloudPlan.Entry(local.getValue(name).md5, r.md5, r.modifiedMs) } if (send.isNotEmpty()) { backupCloud(context, store, id, cloud, send.mapNotNull { remote[it] }) - val data = send.associateWith { files.getValue(it).readBytes() } - val stamped = cloud.put(data) - for ((name, t) in stamped) if (t > 0) files[name]?.setLastModified(t) - val after = remote(cloud) { it in data } - for (name in data.keys) { + val stamped = HashMap<String, Long>() + val sentMd5 = HashMap<String, String>() + if (cloud is GogCloud) { + // Stream one save at a time: gzip needs a full-size buffer and uploads can be large. + val filesToSend = send.associateWith { files.getValue(it) } + val results = cloud.putFiles(filesToSend, send.associateWith { files.getValue(it).lastModified() }) + for ((name, result) in results) { + if (result.modifiedMs > 0) stamped[name] = result.modifiedMs + result.md5?.let { sentMd5[name] = it } + } + } else { + val data = send.associateWith { files.getValue(it).readBytes() } + for ((name, bytes) in data) sentMd5[name] = md5(bytes) + stamped += cloud.put(data, send.associateWith { files.getValue(it).lastModified() }) + for ((name, t) in stamped) if (t > 0) files[name]?.setLastModified(t) + } + val after = remote(cloud) { it in send } + for (name in send) { val r = after[name] - next[name] = CloudPlan.Entry(md5(data.getValue(name)), r?.md5, r?.modifiedMs ?: stamped[name] ?: -1L) + next[name] = CloudPlan.Entry(sentMd5.getValue(name), r?.md5, r?.modifiedMs ?: stamped[name] ?: -1L) } } saveBaseline(context, store, id, next) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt b/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt index 3d46a28da7..ecf318068e 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt @@ -1,24 +1,43 @@ package com.droiddeck.launcher.stores import java.io.ByteArrayOutputStream +import java.io.File +import java.io.FileOutputStream +import java.io.InputStream +import java.io.OutputStream import java.net.HttpURLConnection import java.net.URL import java.net.URLEncoder +import java.security.DigestOutputStream import java.text.SimpleDateFormat +import java.time.Instant +import java.time.ZoneOffset +import java.time.format.DateTimeFormatter +import java.time.temporal.ChronoUnit import java.util.Locale import java.util.TimeZone import java.util.zip.CRC32 import java.util.zip.Deflater +import java.util.zip.DeflaterOutputStream import org.json.JSONArray import org.json.JSONObject class CloudFile(val name: String, var modifiedMs: Long, var md5: String? = null, val readLink: String? = null) +class CloudPut(val modifiedMs: Long, val md5: String?) + interface CloudTransport { fun list(): List<CloudFile> fun details(file: CloudFile) {} fun get(file: CloudFile): Pair<ByteArray, Long> - fun put(files: Map<String, ByteArray>): Map<String, Long> + fun put(files: Map<String, ByteArray>, modifiedMs: Map<String, Long> = emptyMap()): Map<String, Long> + + /** Uploads from files so a transport can stream instead of holding every save in memory. */ + fun putFiles(files: Map<String, File>, modifiedMs: Map<String, Long> = emptyMap()): Map<String, CloudPut> { + val data = files.mapValues { it.value.readBytes() } + val digests = data.mapValues { md5Hex(it.value) } + return put(data, modifiedMs).mapValues { (name, modified) -> CloudPut(modified, digests.getValue(name)) } + } } private const val TIMEOUT = 30_000 @@ -47,6 +66,9 @@ internal fun gunzip(data: ByteArray): ByteArray? = try { java.util.zip.GZIPInputStream(data.inputStream()).use { it.readBytes() } } catch (e: Exception) { null } +/** Same gzip GOG uses on PUT: deflate level 6, mtime 0, OS Unix. */ +private val GOG_GZIP_HEADER = byteArrayOf(0x1f, 0x8b.toByte(), 8, 0, 0, 0, 0, 0, 0, 3) + internal fun gzipGogPut(data: ByteArray): ByteArray { val deflater = Deflater(6, true) val raw = ByteArrayOutputStream() @@ -63,14 +85,14 @@ internal fun gzipGogPut(data: ByteArray): ByteArray { } val crc = CRC32().also { it.update(data) } return ByteArrayOutputStream(18 + raw.size()).apply { - write(byteArrayOf(0x1f, 0x8b.toByte(), 8, 0, 0, 0, 0, 0, 0, 3)) + write(GOG_GZIP_HEADER) write(raw.toByteArray()) writeIntLe(crc.value.toInt()) writeIntLe(data.size) }.toByteArray() } -private fun ByteArrayOutputStream.writeIntLe(v: Int) { +private fun OutputStream.writeIntLe(v: Int) { write(v and 0xff) write(v ushr 8 and 0xff) write(v ushr 16 and 0xff) @@ -117,13 +139,64 @@ internal fun gogRelativeNames(files: List<CloudFile>, location: String?): Pair<S } } +private fun md5Hex(data: ByteArray): String = + java.security.MessageDigest.getInstance("MD5").digest(data).joinToString("") { "%02x".format(it) } + +private fun ByteArray.toHex(): String = joinToString("") { "%02x".format(it) } + +private class GzipFile(val length: Long, val rawMd5: String, val etag: String) + +/** Streams the same gzip framing as [gzipGogPut] into [dst] without reading the save into memory. */ +private fun gzipFile(src: File, dst: File): GzipFile { + val raw = java.security.MessageDigest.getInstance("MD5") + val compressed = java.security.MessageDigest.getInstance("MD5") + val crc = CRC32() + var size = 0L + val file = FileOutputStream(dst) + val out = DigestOutputStream(file, compressed) + try { + out.write(GOG_GZIP_HEADER) + val deflater = Deflater(6, true) + try { + val deflate = DeflaterOutputStream(out, deflater, 64 * 1024) + src.inputStream().use { input -> + val buf = ByteArray(64 * 1024) + while (true) { + val n = input.read(buf) + if (n < 0) break + raw.update(buf, 0, n) + crc.update(buf, 0, n) + size += n + deflate.write(buf, 0, n) + } + } + deflate.finish() + } finally { + deflater.end() + } + out.writeIntLe(crc.value.toInt()) + out.writeIntLe(size.toInt()) + out.flush() + return GzipFile(dst.length(), raw.digest().toHex(), compressed.digest().toHex()) + } finally { + out.close() + } +} + +/** GOG Galaxy parses `X-Object-Meta-LocalLastModified`; objects without it fail as "invalid data". */ +private val GOG_STAMP = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx", Locale.US) + +private fun gogStamp(ms: Long): String = + Instant.ofEpochMilli(ms).atOffset(ZoneOffset.UTC).truncatedTo(ChronoUnit.SECONDS).format(GOG_STAMP) + class GogCloud( private val userId: String, private val clientId: String, private val token: String, private val location: String? = null, + baseUrl: String? = null, ) : CloudTransport { - private val base = "https://cloudstorage.gog.com/v1/$userId/$clientId" + private val base = baseUrl ?: "https://cloudstorage.gog.com/v1/$userId/$clientId" private val ua = "GOG Galaxy" private var prefix: String? = location?.let { "$it/" } @@ -190,16 +263,38 @@ class GogCloud( return gogDecodeCloudBody(data, encoding) to modified } - override fun put(files: Map<String, ByteArray>): Map<String, Long> = files.mapValues { (name, data) -> + override fun put(files: Map<String, ByteArray>, modifiedMs: Map<String, Long>): Map<String, Long> = files.mapValues { (name, data) -> + val body = gzipGogPut(data) + putBody(name, body.inputStream(), body.size.toLong(), md5Hex(body), modifiedMs[name] ?: System.currentTimeMillis()) + } + + override fun putFiles(files: Map<String, File>, modifiedMs: Map<String, Long>): Map<String, CloudPut> = files.mapValues { (name, file) -> + val compressed = File.createTempFile("gog-cloud-", ".gz") + try { + val gz = gzipFile(file, compressed) + val modified = putBody(name, compressed.inputStream(), gz.length, gz.etag, modifiedMs[name] ?: file.lastModified()) + CloudPut(modified, gz.rawMd5) + } finally { + compressed.delete() + } + } + + private fun putBody(name: String, source: InputStream, length: Long, etag: String, modified: Long): Long { val c = open("$base/${cloudKey(name)}", "PUT", token, ua) - c.doOutput = true - c.setRequestProperty("Content-Type", "application/octet-stream") - c.setFixedLengthStreamingMode(data.size) - c.outputStream.use { it.write(data) } - val code = c.responseCode - c.disconnect() - if (code !in 200..299) throw java.io.IOException("GOG cloud put HTTP $code") - CloudFile(name, -1L).also { details(it) }.modifiedMs + try { + c.doOutput = true + c.setRequestProperty("Content-Type", "application/octet-stream") + c.setRequestProperty("Content-Encoding", "gzip") + c.setRequestProperty("Etag", etag) + c.setRequestProperty("X-Object-Meta-LocalLastModified", gogStamp(modified)) + c.setFixedLengthStreamingMode(length) + c.outputStream.use { out -> source.use { it.copyTo(out, 64 * 1024) } } + val code = c.responseCode + if (code !in 200..299) throw java.io.IOException("GOG cloud put HTTP $code") + return CloudFile(name, -1L).also { details(it) }.modifiedMs + } finally { + c.disconnect() + } } } @@ -208,6 +303,6 @@ class EpicCloud(private val accountId: String, private val appName: String, priv override fun get(file: CloudFile): Pair<ByteArray, Long> = com.droiddeck.launcher.stores.epic.EpicSaveSync.read(file) - override fun put(files: Map<String, ByteArray>): Map<String, Long> = + override fun put(files: Map<String, ByteArray>, modifiedMs: Map<String, Long>): Map<String, Long> = com.droiddeck.launcher.stores.epic.EpicSaveSync.write(token, accountId, appName, files) } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/CloudPlanTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/CloudPlanTest.kt index 5338fd3438..1979bece2b 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/CloudPlanTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/CloudPlanTest.kt @@ -54,6 +54,22 @@ class CloudPlanTest { assertTrue(CloudPlan.down(mapOf("s" to Local("a")), mapOf("s" to Remote(null, 2500)), base).transfer.isEmpty()) } + @Test fun gogRawObjectsThatStillMatchTheLocalBytesAreResentOnce() { + val base = mapOf("s" to Entry("a", "a", 1000)) + val plan = CloudPlan.up(mapOf("s" to Local("a")), mapOf("s" to Remote("a", 1000)), base) + assertEquals(listOf("s"), plan.same) + assertEquals(listOf("s"), CloudPlan.upSend(plan, force = false, repairRawGog = true)) + assertTrue(CloudPlan.upSend(plan, force = false, repairRawGog = false).isEmpty()) + } + + @Test fun aForcedGogUploadSendsUnchangedFilesEvenWithoutACloudHash() { + val base = mapOf("s" to Entry("a", "a", 1000)) + val plan = CloudPlan.up(mapOf("s" to Local("a")), mapOf("s" to Remote(null, 1000)), base) + assertTrue(plan.transfer.isEmpty() && plan.conflicts.isEmpty() && plan.same.isEmpty()) + assertEquals(listOf("s"), CloudPlan.upSend(plan, force = true, repairRawGog = true, allLocal = listOf("s"))) + assertTrue(CloudPlan.upSend(plan, force = true, repairRawGog = false, allLocal = listOf("s")).isEmpty()) + } + @Test fun theBaselineSurvivesItsJson() { val b = mapOf("a/b.sav" to Entry("l", "c", 5), "x" to Entry("l2", null, -1)) assertEquals(b, CloudPlan.fromJson(CloudPlan.toJson(b))) diff --git a/app/src/test/java/com/droiddeck/launcher/stores/CloudSavesTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/CloudSavesTest.kt index 0b80032627..9f1dcd2b0d 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/CloudSavesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/CloudSavesTest.kt @@ -22,7 +22,7 @@ class CloudSavesTest { val puts = ArrayList<String>() override fun list() = files.map { (k, v) -> CloudFile(k, v.second, CloudSaves.md5(v.first)) } override fun get(file: CloudFile) = files.getValue(file.name) - override fun put(files: Map<String, ByteArray>): Map<String, Long> = + override fun put(files: Map<String, ByteArray>, modifiedMs: Map<String, Long>): Map<String, Long> = files.mapValues { (k, v) -> puts += k; this.files[k] = v to 99_000L; 99_000L } } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt index df7ba8f2ba..025dbce9b8 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt @@ -56,6 +56,81 @@ class GogCloudKeysTest { assertFalse(gzipGogPut(raw).contentEquals(gameGz)) assertArrayEquals(gameGz, gogDecodeCloudBody(gameGz, null)) } + + @Test fun putUploadsTheGogGzipBodyWithEncodingAndCompressedHash() { + val raw = "savegame0".toByteArray() + val server = java.net.ServerSocket(0, 4, java.net.InetAddress.getByName("127.0.0.1")) + val requests = java.util.concurrent.CopyOnWriteArrayList<Request>() + val worker = Thread { + repeat(2) { + server.accept().use { client -> + client.soTimeout = 5_000 + val input = client.getInputStream() + val line = readLine(input) + val parts = line.split(' ') + val headers = LinkedHashMap<String, String>() + while (true) { + val h = readLine(input) + if (h.isEmpty()) break + val colon = h.indexOf(':') + headers[h.substring(0, colon).trim().lowercase()] = h.substring(colon + 1).trim() + } + val length = headers["content-length"]?.toIntOrNull() ?: 0 + val body = ByteArray(length) + var offset = 0 + while (offset < length) { + val n = input.read(body, offset, length - offset) + if (n < 0) break + offset += n + } + requests += Request(parts[0], parts[1], headers, body) + val response = if (parts[0] == "PUT") { + "HTTP/1.1 200 OK\r\nContent-Length: 0\r\nConnection: close\r\n\r\n" + } else { + "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n" + + "Etag: \"${CloudSaves.md5(body)}\"\r\n" + + "Last-Modified: Tue, 20 Oct 2026 10:00:00 GMT\r\nConnection: close\r\n\r\n" + } + client.getOutputStream().apply { write(response.toByteArray()); flush() } + } + } + }.apply { isDaemon = true; start() } + try { + val cloud = GogCloud("user", "client", "token", "saves", "http://127.0.0.1:${server.localPort}/v1/user/client") + val source = java.io.File.createTempFile("save", ".sav").apply { writeBytes(raw) } + val result = try { + cloud.putFiles(mapOf("save.sav" to source), mapOf("save.sav" to 1_793_490_825_000L)).getValue("save.sav") + } finally { + source.delete() + } + assertTrue(result.modifiedMs > 0) + assertEquals(CloudSaves.md5(raw), result.md5) + val put = requests[0] + assertEquals("PUT", put.method) + assertEquals("/v1/user/client/saves%2Fsave.sav", put.path) + assertEquals("gzip", put.headers["content-encoding"]) + assertEquals("2026-10-31T23:53:45+00:00", put.headers["x-object-meta-locallastmodified"]) + assertArrayEquals(gzipGogPut(raw), put.body) + assertEquals(CloudSaves.md5(put.body), put.headers["etag"]) + assertArrayEquals(raw, gogDecodeCloudBody(put.body, put.headers["content-encoding"])) + assertEquals("HEAD", requests[1].method) + } finally { + server.close() + worker.join(2_000) + } + } +} + +private class Request(val method: String, val path: String, val headers: Map<String, String>, val body: ByteArray) + +private fun readLine(input: java.io.InputStream): String { + val out = ByteArrayOutputStream() + while (true) { + val b = input.read() + if (b < 0 || b == '\n'.code) break + if (b != '\r'.code) out.write(b) + } + return out.toString("UTF-8") } private fun String.hex() = chunked(2).map { it.toInt(16).toByte() }.toByteArray() diff --git a/docs/development/stores.md b/docs/development/stores.md index 5d11e48b65..78855ea749 100644 --- a/docs/development/stores.md +++ b/docs/development/stores.md @@ -300,6 +300,16 @@ the prefix's user folder appears, within a minute. Every path logs `%LocalAppData%/GOG.com/Galaxy/Applications/<clientId>/Storage/Shared/Files`. It goes through the same location-qualified handling below. GET peels gzip when `Content-Encoding` is gzip, or when the object round-trips as GOG's PUT gzip (deflate 6, mtime 0); a gzip-format save is left intact. + PUT mirrors Galaxy's `CloudStorageCompressingClient`: each object is gzipped (deflate 6, mtime 0) + and sent with `Content-Encoding: gzip`, an `Etag` of the compressed bytes and + `X-Object-Meta-LocalLastModified` (`yyyy-MM-dd'T'HH:mm:ss+00:00`, from the local file mtime). + Galaxy's `CloudStorageRemoteClient` rejects an object without that metadata as `invalid data` + before it ever decompresses it; a live probe showed gzip + metadata downloads, while gzip alone, + or `User-Agent` metadata alone, fails. Objects older builds uploaded raw lack it, so + `CloudPlan.upSend` resends those unchanged files once. Automatic repair does not resend + conflicts; ordinary local changes still upload through `plan.transfer`. + An explicit forced upload sends every local GOG file, including unchanged files the service gives + no hash for, so a manual repair rewrites the whole folder. - **GOG names are location-qualified:** the cloud API lists `saves/user1.dat`, where `saves` is the `name` of the selected `cloudStorage.locations` entry and the folder is that entry's `location` (`.../Hollow Knight Silksong/default`). `GogCloud` strips the location segment for the local path From 6a681bcbc288e9245447daf86f98afeb0acd6e7e Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:04:11 -0500 Subject: [PATCH 80/85] docs: clarify DX12 budget consumers and physical limits (#2148) * docs: clarify DX12 budget consumers and physical limits * docs: record controlled Thor gameplay limits --- docs/development/vram-budget.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/development/vram-budget.md b/docs/development/vram-budget.md index fe790f9aca..c9e6820efe 100644 --- a/docs/development/vram-budget.md +++ b/docs/development/vram-budget.md @@ -1,6 +1,8 @@ # Reported video memory budget -The Performance VRAM setting enables `VK_LAYER_DROIDDECK_vram_cap` for games and reports smaller device-local `VK_EXT_memory_budget` budgets. DXVK and vkd3d-proton can use these reports when choosing memory pools. The driver still supplies real heap sizes, usage figures, memory types, and actual allocation results. DXVK also receives its existing `dxgi.maxDeviceMemory` setting. A lower driver budget remains lower; the layer never increases it. +The Performance VRAM setting enables `VK_LAYER_DROIDDECK_vram_cap` for games and reports smaller device-local `VK_EXT_memory_budget` budgets. DXVK exposes these through DXGI's `QueryVideoMemoryInfo`, including to D3D12 games using DXVK's DXGI alongside vkd3d-proton. Games that consult this budget can choose smaller working sets. The driver still supplies real heap sizes, usage figures, memory types, and actual allocation results. DXVK also receives its existing `dxgi.maxDeviceMemory` setting, which separately reduces the adapter's advertised dedicated video memory. A lower driver budget remains lower; the layer never increases it. + +This does not make vkd3d-proton automatically enforce the selected budget. In the [upstream allocator inspected during this investigation](https://github.com/HansKristian-Work/vkd3d-proton/blob/865b12ba0cc20796b3709397ce5d6d3b8a205b04/libs/vkd3d/memory.c), `heapBudget` is used for diagnostic reporting, while the [DXVK adapter](https://github.com/doitsujin/dxvk/blob/cf0a0d90f8965147741ad17dcd0b263817572ab3/src/dxgi/dxgi_adapter.cpp) returns the Vulkan budget to applications. Seeing a smaller budget in a VKD3D log verifies reporting, not reduced allocation or eviction. This is a budget hint, not a physical reservation or a GPU paging implementation. Games may exceed it. On UMA hardware, host-visible Vulkan allocations can share the same device-local heap as textures. Rejecting every allocation above a fixed total can therefore break required upload buffers and other allocations, rather than make a game reduce its texture pool. The layer does not intercept `vkAllocateMemory` or `vkFreeMemory`, and preserves the real heap size so individual allocations larger than the budget remain Vulkan-valid. @@ -14,6 +16,12 @@ On an 8 GB Pocket FIT Elite with DD Turnip 0.4.0, Proton 11-12.1, and Caravan Sa - The initial hard allocation cap caused the existing save to fail a required 603,979,776-byte D3D12 allocation. Android survived, but the game crashed. Discord testers also reported crashes after reaching the cap in Fallout 76. - In the initial test with allocation rejection disabled, vkd3d-proton logged the smaller 2048 MiB heap and budget. Caravan still exhausted system memory while loading the save. A reported budget alone does not solve this workload. - DX11 loaded the same save and supported movement around the station at approximately 60 FPS for more than five minutes, both with and without the reported budget layer. Graphics settings were unchanged. This establishes a renderer workaround, not proof that the layer solved Caravan's OOM. +- The final release-signed APK, preserving real heap size and clamping only the budget to 2048 MiB, also passed more than five minutes of loaded-save DX11 movement. D3D12 with the same budget still exhausted system memory. +- Launching D3D12 through `droiddeck-proton-run --app` without the Linux Steam client reached the loaded save and allowed movement, then Android killed the session for low memory. Removing the client footprint alone was insufficient. + +A separate Windows DXGI query probe on a **12 GB AYN Thor** with the same APK and Proton queried the adapter without allocating game resources. With the layer disabled, dedicated video memory was 8,858,370,048 bytes and the local budget was 5,656,018,944 bytes. Enabling only the layer at 2048 MiB preserved that dedicated-memory value and changed the local and UMA non-local budgets to 2,147,483,648 bytes. Adding the existing `DXVK_CONFIG="dxgi.maxDeviceMemory = 2048"` setting also lowered advertised dedicated memory to 2,147,483,648 bytes while retaining the 2048 MiB budgets. These probes verify the application-facing budget path; they are not 8 GB gameplay results. + +On that Thor, subsequent D3D12 runs both with and without the 2048 MiB budget reached the existing save and supported more than five minutes of movement. Both used the Stability preset and `VKD3D_CONFIG=log_memory_budget`. The budgeted run ended with an Android low-memory kill during the shutdown window; the unbudgeted retry stopped cleanly. Earlier runs also encountered low-memory kills or a separate exception-stack startup failure. These observations do not establish a reduction in Caravan's memory use from the budget hint or a stable D3D12 fix. Native regression coverage exercises core and KHR memory-property queries, chained budget structures, unchanged real usage above the budget, separate heap types, disabled behavior, device lifecycle dispatch, and successful driver allocations whose individual and combined sizes exceed the reported budget. From c8a76e7ccec3b4ef1f3ac83b7952d04211e4ccd1 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 20:04:16 -0500 Subject: [PATCH 81/85] perf(agent): run diagnostic cleanup off startup thread (#2147) * perf(agent): run stage cleanup off startup thread * fix(agent): preserve active diagnostic stages * test(agent): verify active stage locks cross-process --- .../main/java/com/droiddeck/launcher/App.kt | 2 +- .../session/EnhancedSessionLogShare.kt | 20 +++++++++----- .../session/DiagnosticStageLockProbe.java | 19 +++++++++++++ .../session/SessionLogShareZipTest.kt | 27 +++++++++++++++++++ 4 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/session/DiagnosticStageLockProbe.java diff --git a/app/src/main/java/com/droiddeck/launcher/App.kt b/app/src/main/java/com/droiddeck/launcher/App.kt index 311dc00824..5ef39f6b6e 100644 --- a/app/src/main/java/com/droiddeck/launcher/App.kt +++ b/app/src/main/java/com/droiddeck/launcher/App.kt @@ -17,7 +17,7 @@ class App : Application() { override fun onCreate() { super.onCreate() - runCatching { EnhancedSessionLogShare.cleanupAbandonedStages(this) } + Thread({ runCatching { EnhancedSessionLogShare.cleanupAbandonedStages(this) } }, "diagnostic-stage-cleanup").start() com.droiddeck.launcher.ui.Themes.loadGradient(this) com.droiddeck.launcher.ui.BuildWatermark.install(this) HomeApp.trackRecents(this) diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index f838e71ac6..6f9f364539 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -51,17 +51,21 @@ internal object EnhancedSessionLogShare { internal class DiagnosticStageLease internal constructor( val directory: File, + private val canonicalPath: String, private val channel: FileChannel, private val lock: FileLock, ) : Closeable { override fun close() { - try { - lock.release() - } finally { + synchronized(stageLifecycleMonitor) { + activeStagePaths.remove(canonicalPath) try { - channel.close() + lock.release() } finally { - directory.deleteRecursively() + try { + channel.close() + } finally { + directory.deleteRecursively() + } } } } @@ -117,6 +121,7 @@ internal object EnhancedSessionLogShare { override fun initialValue(): SecureSourceOpener? = null } private val stageLifecycleMonitor = Any() + private val activeStagePaths = mutableSetOf<String>() internal fun acquireDiagnosticStage(context: Context, outputName: String): DiagnosticStageLease { val cache = context.cacheDir @@ -133,7 +138,9 @@ internal object EnhancedSessionLogShare { try { val lock = channel.tryLock() ?: throw IOException("Could not lock the diagnostic staging directory") - DiagnosticStageLease(stage, channel, lock) + val canonicalPath = stage.canonicalPath + activeStagePaths += canonicalPath + DiagnosticStageLease(stage, canonicalPath, channel, lock) } catch (error: Exception) { channel.close() stage.deleteRecursively() @@ -149,6 +156,7 @@ internal object EnhancedSessionLogShare { cache.listFiles()?.forEach { stage -> if (!stage.isDirectory || Files.isSymbolicLink(stage.toPath()) || stage.canonicalFile.parentFile != canonicalCache || !isDiagnosticStage(stage.name)) return@forEach + if (stage.canonicalPath in activeStagePaths) return@forEach val active = File(stage, ".active") if (Files.isSymbolicLink(active.toPath())) return@forEach val channel = runCatching { diff --git a/app/src/test/java/com/droiddeck/launcher/session/DiagnosticStageLockProbe.java b/app/src/test/java/com/droiddeck/launcher/session/DiagnosticStageLockProbe.java new file mode 100644 index 0000000000..138185a292 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/DiagnosticStageLockProbe.java @@ -0,0 +1,19 @@ +package com.droiddeck.launcher.session; + +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +public final class DiagnosticStageLockProbe { + public static void main(String[] args) throws Exception { + try (FileChannel channel = FileChannel.open(Path.of(args[0]), StandardOpenOption.WRITE)) { + FileLock lock = channel.tryLock(); + if (lock == null) { + System.exit(0); + } + lock.release(); + System.exit(1); + } + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index 6af039ade9..087c1a9980 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -6,6 +6,7 @@ import java.text.SimpleDateFormat import java.util.UUID import java.util.Date import java.util.Locale +import java.util.concurrent.TimeUnit import java.util.zip.ZipFile import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse @@ -34,6 +35,32 @@ class SessionLogShareZipTest { EnhancedSessionLogShare.cleanupAbandonedStages(app) assertFalse(abandoned.exists()) assertTrue(active.directory.isDirectory) + EnhancedSessionLogShare.cleanupAbandonedStages(app) + assertTrue(active.directory.isDirectory) + val probeClassResource = checkNotNull( + DiagnosticStageLockProbe::class.java.getResource("DiagnosticStageLockProbe.class"), + ) + val probeClass = File(probeClassResource.toURI()) + var classPathRoot = checkNotNull(probeClass.parentFile) + repeat(4) { classPathRoot = checkNotNull(classPathRoot.parentFile) } + val classPath = classPathRoot.absolutePath + val javaName = if (checkNotNull(System.getProperty("os.name")).startsWith("Windows")) { + "java.exe" + } else { + "java" + } + val java = File(File(System.getProperty("java.home"), "bin"), javaName) + val probe = ProcessBuilder( + java.absolutePath, + "-cp", + classPath, + DiagnosticStageLockProbe::class.java.name, + File(active.directory, ".active").absolutePath, + ).redirectErrorStream(true).start() + val completed = probe.waitFor(5, TimeUnit.SECONDS) + if (!completed) probe.destroyForcibly() + assertTrue("lock probe timed out", completed) + assertEquals("cleanup released the active stage lock", 0, probe.exitValue()) } finally { active.close() } From f4e5032b7de4219b2d0a0ac79a3e9970f1a78f99 Mon Sep 17 00:00:00 2001 From: MaxsTechReview <maxjividen@gmail.com> Date: Thu, 5 Nov 2026 21:33:57 -0500 Subject: [PATCH 82/85] fix(fex): skip local patches already in the FEX release (#2152) --- tools/fex/build-in-arch.sh | 9 ++++++++- tools/fex/patches/0002-thunkgen-newer-clang.patch | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/fex/build-in-arch.sh b/tools/fex/build-in-arch.sh index 66d2c2a4ea..75bf7c22a3 100755 --- a/tools/fex/build-in-arch.sh +++ b/tools/fex/build-in-arch.sh @@ -36,7 +36,14 @@ CONF fi rm -rf fex-src out && git clone -q --depth 1 --branch "$VERSION" --recurse-submodules --shallow-submodules https://github.com/FEX-Emu/FEX.git fex-src -for p in tools/fex/patches/*.patch; do patch -d fex-src -p1 --no-backup-if-mismatch < "$p"; done +for p in tools/fex/patches/*.patch; do + upstream=$(sed -n 's/^Fixed-upstream: FEX-\([0-9]\{4\}\)$/\1/p' "$p") + if [ -n "$upstream" ] && [ "${VERSION#FEX-}" -ge "$upstream" ]; then + echo "$(basename "$p"): already in FEX-$upstream, skipped for $VERSION" + continue + fi + patch -d fex-src -p1 --no-backup-if-mismatch < "$p" +done if [ "$THUNKS" = 1 ]; then for t in fex-src/Data/CMake/toolchain_x86_64.cmake fex-src/Data/CMake/toolchain_x86_32.cmake; do printf '\nif (X86_DEV_ROOTFS AND NOT X86_DEV_ROOTFS STREQUAL "/")\n set(CMAKE_SYSROOT "${X86_DEV_ROOTFS}")\nendif()\n' >> "$t" diff --git a/tools/fex/patches/0002-thunkgen-newer-clang.patch b/tools/fex/patches/0002-thunkgen-newer-clang.patch index a6a87c27e7..3e528397f0 100644 --- a/tools/fex/patches/0002-thunkgen-newer-clang.patch +++ b/tools/fex/patches/0002-thunkgen-newer-clang.patch @@ -1,3 +1,4 @@ +Fixed-upstream: FEX-2611 --- a/ThunkLibs/Generator/gen.cpp +++ b/ThunkLibs/Generator/gen.cpp @@ -840,6 +840,5 @@ From 3733c5090248e0e64f10fbe6decf9cfdf5b88d05 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 22:06:16 -0500 Subject: [PATCH 83/85] feat: non-Adreno graphics stack (Venus, open driver pairs, gamescope patches) (#2029) * Retain compositor resources when GPU completion is unconfirmed * Stop quarantined GPU callers before retries and mapped writes * Support Android hardware-buffer presentation over Wayland * Support PowerVR swapchains and linear image imports in Gamescope * Bundle verified PowerVR graphics components through existing build preparation * Detect and select the system Vulkan backend on PowerVR * Apply PowerVR Steam and game compatibility during normal launches * Show PowerVR support through existing driver and component controls * Update existing hardware guidance for system Vulkan support * Import the shared system Vulkan readiness check * Discover and propagate the actual PowerVR render node * Prune obsolete PowerVR runtimes after guest processes exit * Retain external DMA-BUF ownership after GPU quarantine * Name the PowerVR HAL selection explicitly * Isolate component UI tests from application startup * Cover the inherited FEX preset in PowerVR profile tests * Log test worker failures for CI diagnosis * Remove temporary test logging after diagnostic CI * Prefer system dependencies for the Android Vulkan loader * Capture raw stderr before test worker termination * Remove the temporary test worker crash probe * Import pinned DXVK recipe prerequisite from PowerVR PR570 Copy only the standalone build recipe, source pin, BC-format prerequisite and presentation-sync patch/check from wallentx/DroidDeck at d0f7264ea8e402d30c868779198dc2fd74e7431c. Source: https://github.com/Droid-Deck/DroidDeck/pull/570 Preserve that proposal attribution; no Android app, compositor, managed pack, private data or fork development history is imported. * Add opt-in low32 GPU mapping adapter and integrity probes * Add opt-in D3D9 single-sample workaround and fix HUD texel format * Document verified production game workaround and publication scope * Restrict reset diagnostics and create private output atomically * Target official runtime review and document PR570 prerequisite provenance * Fix runtime tool output isolation, mmap64 chaining and DST ambiguity * Normalize swapchain backbuffers for the opt-in D3D9 single-sample path * Experimental Samsung Xclipse support on the system Vulkan path Detect Samsung's Vulkan HAL (vulkan.samsung.so) and its sgpu render node alongside PowerVR, and run Xclipse through the same libhybris bridge: - VK_LAYER_DROIDDECK_xclipse (tools/linuxfs/xclipse-layer), built with the glibc preloads and enabled only on Xclipse: sets bionic's environ for the driver's shader compiler, avoids immutable YCbCr samplers in compute layouts, forwards the KHR calibrated-timestamp entry points to the EXT ones, and reports textureCompressionBC and BC4/BC5 filtering over the compat layer's BC emulation. - Upstream DXVK 2.6.2, pinned as a tar.gz component and selected on Xclipse: the driver has 128 bytes of push constants, DXVK 3 needs 256. - android_wlegl accepts a zero stride and passes it through unchanged: Samsung's gralloc records none for GPU-only buffers. Tested on a Galaxy A56 (Xclipse 540, driver 24.0.560): Steam Big Picture and PICO PARK (D3D9). * Xclipse layer: copy the device chain and track samplers per device - Clear textureCompressionBC in a copy of the device-create chain (every structure up to the VkPhysicalDeviceFeatures2 that enables it) instead of writing the caller's structure; a chain led by a structure of unknown size is passed on unchanged. - Track YCbCr samplers per device in a growable list, drop them on vkDestroySampler and device teardown, and fail sampler creation rather than leave one untracked when the list cannot grow. - Fail descriptor set layout creation with VK_ERROR_OUT_OF_HOST_MEMORY when a replacement sampler array cannot be allocated, instead of passing the original YCbCr samplers to the driver. * Xclipse layer: copy any device-chain structure the headers define The chain copy that clears the emulated textureCompressionBC only knew a handful of structure sizes, so a valid chain such as VkPhysicalDeviceTimelineSemaphoreFeatures -> VkPhysicalDeviceFeatures2 was passed on unchanged and the compat layer refused the bit. Size every structure that may extend VkDeviceCreateInfo from a table generated from the Vulkan registry (gen_device_chain.py, Vulkan-Headers 1.3.275, the headers the build compiles with), and copy onto the heap instead of a fixed buffer. Only a structure newer than those headers still passes the chain unchanged. Add a regression test that runs the layer between a simulated loader and a mock driver: the timeline-semaphore chain, pEnabledFeatures, an unknown structure, the caller's structures left untouched, per-device YCbCr sampler tracking with handle reuse, and the KHR calibrated-timestamp forwarding. CI installs libvulkan-dev for it. * 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. * Test branch: keep #570's DXVK build recipe so its pinned PowerVR components verify #602 adds output checks to tools/dxvk/build.sh; tools/powervr/fetch.py pins the exact recipe the published PowerVR DXVK was built from, so the branch carries #570's copy. * Test branch: make #570, #602 and #560/#561 pass each other's tests - tools/dxvk/build.sh: #602's copy (its output checks) and the PowerVR pin in tools/powervr/release.json moved to that file's hash; the recipe's outputs are unchanged. - droiddeck-session: the presentation block sets _bl_cef for #570's PowerVR path, and the UI block keeps main's order, defaulting to -cef-use-angle=vulkan when the block has not run. - Compositor test harnesses: AHardwareBuffer stubs for #570's AHB import, and a stub for vkp_effects_forget_image (main #597) that #561's caller harness predates. * Auto drivers for Mali and Xclipse on the non-Adreno test branch Auto now picks an open driver pair for the GPU, the way it does for Adreno: - Mali (no KGSL, /dev/mali0): the GPU's name ("Mali-G720-Immortalis MC12", from the vendor Vulkan driver or kbase's gpuinfo) picks the PanVK build: G52-G78 (Job Manager), G610/G710, G615 or G720. A Mali none of them covers (G925...), or one whose pair is not published yet, draws through the Mali bridge, switched on by Auto. - Xclipse keeps the system-driver path as Auto; the RADV pair is offered as a manual choice. - The pairs come from The412Banner/droiddeck-nonadreno-drivers (one pre-release per driver, each a DriverBundle zip). Only a device without an Adreno reads that repo. - The importers accept PanVK and RADV libraries (libvulkan_panfrost / libvulkan_radeon). - An open driver pair and the Mali bridge are alternatives: a selected pair turns the bridge off. - TU_DEBUG is only set for Turnip, on an Adreno. Every new branch is reached only when the device has no Adreno; an Adreno's detection, release sources, Auto choice and session environment are unchanged. * Auto: the one-binary PanVK kbase build for Mali v9-v13 on Android 15+ The412Banner/droiddeck-nonadreno-drivers adds panvk-mali-kbase: one PanVK build for G57/G68/G77/G78, G610/G710, G615/G715, G720/G725 and G925, whose display half needs Android 15. On Android 15+ Auto prefers it for every Mali it covers; below 15, and whenever its release is not listed, Auto falls back to the GPU generation's own pair. G52/G76 keep the Job Manager build; a G715/G725/G925 below Android 15, or any Mali no pair covers, draws through the bridge. Every pair stays selectable by hand. * Test: the G925 is in the kbase build's family now * Offer faux123's device PanVK builds (RP4 Pro, Ace, RG556) as manual pairs for their Mali * Detailed graphics logs for non-Adreno test reports - graphics-report.txt in every session folder: the graphics path the session draws with and why (Turnip, system Vulkan #570, Mali bridge #517, or an open driver pair with its release), the driver mode and choices, what Auto would pick, the GPU (family, Vulkan device name, kbase gpuinfo, Android, SoC, kernel), the GPU nodes the app can see (access, device numbers, SELinux label; nothing is opened) and the guest's graphics environment. At the end it adds the compositor's driver lines from app.log and the game launches that were logged. - vulkan-summary.txt: the session's own vulkaninfo --summary with the driver as exported, in the background with a 10 s timeout. - Per-game logs under games/<time>-<appid>/: Proton's log, DXVK's and vkd3d-proton's, Mesa's and PanVK's startup messages and the launch environment, from droiddeck-game-env. Each file is cut to 20 MB and the folder to 120 MB at the session's end. - The per-game logs and the Vulkan summary are on for a GPU that is not an Adreno, and on an Adreno only with Setup's new "Detailed graphics logs" switch. Share logs already takes the whole session folder, so all of it is in the zip, scrubbed as before. * 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. * Auto takes the RADV pair on a Samsung Xclipse, with the system route as its fallback A tester's Galaxy S24 FE (Xclipse 940) boots to Steam with the RADV-Xclipse pair, where the system-driver route fails at Steam's OpenGL (glamor and GLX cannot load a driver). Auto now downloads and selects RADV on an Xclipse like the Mali pairs, and falls back to the system route only when RADV is not published. #570's reset of both drivers at each start no longer undoes an open driver pair. PowerVR (vulkan.powervr.so) keeps the system driver as before. * An Exynos with a Mali is a Mali, not an Xclipse The system route took vulkan.samsung.so as Samsung's Xclipse, but an Exynos 1280/1380 (Galaxy Tab S9 FE: Mali-G68) may name its HAL the same; with /dev/mali0 present that HAL is not the system route's, and the device is detected as the Mali it is. The chip table adds the Exynos 1380 and 1280 (s5e8835, s5e8825: Mali-G68). * Auto fetches the open drivers itself; Xclipse named as such; sound and frame-gen in the logs - Auto looks online again when its saved release list predates this device's open drivers, so a Samsung or Mali phone gets its pair without pressing refresh first. - A Samsung Xclipse is labelled "Samsung Xclipse" (not PowerVR), with its own support line. - Per-game logs add audio-streams.txt: PulseAudio's sink inputs 20 s and 60 s into the launch, so a silent game shows whether its stream reached Pulse. - graphics-report.txt states the frame-generation setting and keeps the LSFG gate, FrameGen and audio lines from app.log. * Client sound retries a briefly disconnected AAudio; kbase ioctl refusals explained in the report A Galaxy S24 FE's session had no sound at all: the DirectAudio sink's AAudio stream opened with AAUDIO_ERROR_DISCONNECTED while the output route was still changing at session start, and the plain AAudio fallback failed the same moment. The sink guard now retries DirectAudio, then the plain sink, five times over ten seconds and says which one it got. graphics-report.txt keeps the client-sink and kbase lines, and explains a KBASE_IOCTL_MEM_EXEC_INIT EPERM as the kbase driver's own answer rather than the session's sandbox. * Mali pairs draw the display on the phone's own Mali driver; Xwayland falls back without glamor - Testers' Mali pairs got the guest drawing (gamescope on the stand-in node, Zink on PanVK) but the compositor's PanVK Android half failed on Mali gralloc: it probes AHB formats 0x38/0x3b that mali_gralloc does not have, and "vkCreateImage w/ native buffer failed". Under Auto a Mali pair now leaves the display on the phone's own Vulkan driver (dma-buf, modifiers and AHB all pass the testers' checks) and runs the pair's PanVK in the guest; the Android half stays installed for a manual pick. "Pair in use" now follows the runtime half. - A session after one whose Xwayland crashed (segfault, then gamescope's X11 I/O error) starts Xwayland with XWAYLAND_NO_GLAMOR=1 on a non-Adreno device, and says so in app.log. - graphics-report.txt names the display driver the compositor used, and keeps gralloc, dma-buf, modifier and import lines from app.log and Xwayland's own lines from the session log. * Non-Adreno sound: the daemon falls back on its own; the build's commit in device.txt and the report The S24 FE's session still had no sound: its AAudio refuses DirectAudio's low-latency stream with AAUDIO_ERROR_DISCONNECTED, and the sink guard never got to retry because pactl did not reach the daemon in time ("the daemon did not answer in 15 s"). On a GPU that is not an Adreno the daemon's own start-up script now asks DirectAudio again without low latency and loads the plain AAudio sink underneath it, so a default sink exists whatever pactl does. device.txt and graphics-report.txt name the build label and source commit, so a log says which build it came from. * Non-Adreno sound: no second DirectAudio load (it hung the daemon); the plain AAudio sink underneath On the S24 FE the daemon stopped after DirectAudio's failed low-latency load: the second DirectAudio load in the same daemon never returned, so nothing after it ran and pactl never connected. The daemon now loads only the plain AAudio sink (no low latency) after DirectAudio, inside .nofail, and sets whichever exists as the default. * gamescope: explicit sync off where the kernel or the stand-in node cannot signal its timelines Adds tools/gamescope/patches/0126 (GAMESCOPE_DISABLE_EXPLICIT_SYNC=1 for the nested backends) and sets it on a GPU that is not an Adreno when the kernel is older than 6.6 (no DRM_IOCTL_SYNCOBJ_EVENTFD) or the guest's render node is Mali's stand-in. The graphics report lists it with the rest of the guest's graphics environment. * Test branch: gamescope with the explicit-sync switch (0126), pinned by sha Built by build-gamescope.yml run 38335744351 from 0136fb61 and published as a component release of The412Banner/droiddeck-nonadreno-drivers; the apk build fetches it by tag and checks the sha. * Sound: nothing that can block in the daemon's start-up; Steam's web compositing in software on open pairs - The S24 FE (US) daemon hung loading the plain AAudio sink from default.pa (its AAudio open blocks rather than fails), so it never finished starting. default.pa is back to DirectAudio alone inside .nofail; the fallbacks are loaded from the app once the daemon answers, each pactl bounded by its timeout (DirectAudio, then the plain sink with and without low latency). The guard waits 30 s and logs, with timestamps, how long the daemon took, whether its socket and pactl exist, and what it finally got. - With an open driver pair on a GPU that is not an Adreno, Steam's CEF composites in software (-cef-disable-gpu-compositing) with GPU raster kept: RADV on Xclipse showed stale, half-written tiles, as #570 saw on PowerVR. The session log says so. * Mali under Auto: the display always on Android's own Vulkan loader; a reboot hint for refused audio Axel's Tab S9 FE still drew its display with the PanVK Android half, set by an earlier build, and stalled at "Waiting for Steam's first frame" on Mali gralloc's format probes. Under Auto a Mali's display now goes to Android's own loader whatever was set before (DriverMenus resets it, and the compositor's driver choice ignores a pair's Android half), with no HAL path to find first. A pair counts as in use when its runtime half is. A manual pick of the PanVK display is kept. When audio.log shows AAUDIO_ERROR_DISCONNECTED, the report and the client-sink line say Android refused the output and that rebooting the phone usually fixes it. * Fix: call SessionPrefs.gpuDriverMode through its instance from Java * Compositor: log each new dma-buf format/modifier/size it imports (for colour and swizzle reports) Steam's software web compositing already covers every open driver pair, Mali included. * Open driver pairs: vkd3d-proton reports the driver's caps; buffer attach/release tracing; Mesa log - With a PanVK or RADV pair (BL_OPEN_DRIVER=1), droiddeck-game-env drops the app-wide VKD3D_FEATURE_LEVEL=12_2 and VKD3D_SHADER_MODEL=6_9 so vkd3d-proton reports what the driver has (an Unreal DX12 game crashed at start on PanVK with the overrides); a game's own setting still wins, and launch.txt records DROIDDECK_VKD3D_CAPS=driver. - The compositor traces, on a GPU that is not an Adreno, the first 400 dma-buf attaches and buffer releases by wl_buffer id and sending line, and logs any release of a buffer already released and not attached again (gamescope's "Compositor released us but we were not acquired" on G925). - Per-game logs no longer set MESA_DEBUG=silent, which kept mesa.log empty. * Tests: the dma-buf quarantine harness follows send_buffer_release's tracing macro * Mali (Venus): David Cimo's Venus route sources and recipes From DavidCimo/droiddeck-mali, branch mali-venus @ 4f838891 (prototype 13; his 12 commits on top of DroidDeck 0.3.1, GPL-3.0), by David Cimo: - tools/venus: Mesa Venus vtest patch (incl. the per-queue submit_mutex fix and the cached-memory frame readback), virglrenderer Android patch, the Mali compatibility layer (the six features DXVK needs: fill modes, multi-viewport, robustness2, clip/cull distance, BC1-BC7) and his tools. - tools/linuxfs/preload/venus.c: keeps Zink's kopper under Venus. - tools/gamescope/patches/0127 (his 0114): shm buffers uploaded on every commit. - docs/development/mali-venus.md: his design notes. - tools/venus/ci-build.sh and build-venus.yml: his build recipes as one CI job that packs the component (vtest server, ICD, layer) as venus.tzst for the apk. Co-authored-by: Dersim Abbas <derabb0620@gmail.com> * Mali (Venus) as a selectable route, by David Cimo Ports David Cimo's Venus route (DavidCimo/droiddeck-mali, mali-venus @ 4f838891) onto this branch as "Mali (Venus)", one tap in Setup next to the Mali bridge: - VenusComponent (his): stages the Venus ICD and runs virglrenderer's vtest server over the phone's own Vulkan driver; the guest gets VK_ICD_FILENAMES, VN_DEBUG=vtest, VTEST_SOCKET_NAME and MESA_VK_WSI_DEBUG=sw. - Selection rule: Venus when Setup's "Mali (Venus)" is on, on a GPU that is neither an Adreno nor a system-driver one (PowerVR, Xclipse), and the apk carries it. It then replaces the Mali bridge and any open driver pair for the session, and the display stays on the phone's own driver. Auto is unchanged (the PanVK pair). Adreno never takes any of it. - The compositor enables only the dma-buf extensions the driver has, logs a vendor driver's extension list, and gives a zero row pitch a packed row (his vk_present.c changes). - The Mali compatibility layer is staged into the runtime on non-Adreno devices only. - The component (vtest server, ICD, layer) comes from build-venus.yml as venus.tzst, published on The412Banner/droiddeck-nonadreno-drivers and pinned by sha in tools/venus/release.env. - gamescope 3.16.29-p15 adds his shm upload patch (0127) next to 0126; pinned by sha. - device.txt and graphics-report.txt name the route. Co-authored-by: Dersim Abbas <derabb0620@gmail.com> * Mali: Venus gamescope without robustness2, the bridge switch honoured and kept, clean driver switches - gamescope 0128: VK_EXT_robustness2 is optional. A Mali driver through Venus has none, and gamescope stopped at "Missing required extension: VK_EXT_robustness2" (the wayland_surface error after it was only the knock-on). Without it, unused descriptor slots point at a 1x1 texture instead of VK_NULL_HANDLE. (David Cimo's Pixel 9 driver has robustness2, so his build never needed this.) gamescope component rebuilt and pinned by sha. - Open-files limit: on a GPU that is not an Adreno the session script raises the soft limit to the hard limit for the whole session tree (a PanVK-kbase session froze on "Too many open files" after ten minutes) and graphics-report.txt shows before and after. A stopgap; the driver leak is fixed separately. - The Mali bridge switch is honoured: when on and usable it wins over a PanVK pair for the session (Venus still wins over it). Selecting a pair no longer switches the bridge off, which is why the switch did not survive an app restart (Auto re-selected the pair at start). Setup says when this phone cannot use the bridge at all. - Driver switching: picking a Mali pair by hand keeps the display on the phone's own driver, as Auto does (a PanVK Android display stalls on Mali gralloc at "Waiting for Steam's first frame", and stayed set after switching back); installing a bundle again replaces it instead of adding a "-2" copy beside the old one. - graphics-report.txt names the runtime driver's folder and libraries, and the previous session's drivers, flagged when they changed. * gamescope p16 (0128 robustness2 optional), pinned by sha; graphics-report says who chose the display driver * Bundle replace only for open non-Adreno pairs; Adreno bundles keep their numbered copies * Rebuilt open drivers reach phones: re-downloaded when their digest changes, release list hourly on non-Adreno The non-Adreno driver releases replace their assets in place (the PanVK kbase sync-file fd leak fix). A download is now remembered with its GitHub sha256, and an asset whose digest changed counts as not installed, so Auto fetches it again and the bundle replaces the old one; the release list is re-read after an hour instead of a day on a GPU that is not an Adreno. * Mali compatibility layer: multiDrawIndirect, depthClipEnable and robustness2 for DXVK on Venus A Galaxy A15 (Mali-G57) on Venus got gamescope and Steam up, but DXVK refused the GPU: "Device does not support required feature 'multiDrawIndirect'". DXVK 3.1 stops at the first missing feature, so the rest of its required list (dxvk_device_info.cpp) was checked against what the testers' Mali drivers cannot have, and covered in the same pass, on top of David Cimo's six: - multiDrawIndirect: reported, taken off the device, and an indirect draw with drawCount > 1 is recorded as single draws at offset + i * stride; maxDrawIndirectCount reported as 2^30. (drawIndirectCount is optional for DXVK and stays as the driver says.) - VK_EXT_depth_clip_enable (required): offered when the driver lacks it; depthClipEnable off in a pipeline becomes depthClampEnable, and the extension's structures never reach the driver. - VK_EXT_robustness2 missing entirely (gamescope saw the same on these phones): offered with robustBufferAccess2 (as robustBufferAccess, as before) and nullDescriptor, emulated by small stand-ins (a zeroed buffer, a 1x1 image) for VK_NULL_HANDLE buffers, image views and vertex buffers in plain, template and push descriptor writes and vertex-buffer binds. A null texel-buffer view stays null (its format is not known). The layer logs every feature it emulates per device. * Venus component 22694a38 (layer: multiDrawIndirect, depthClipEnable, robustness2), pinned by sha * Non-Adreno round 3: bridge images, Venus GL, shared buffers, Steam GPU drawing - vkbridge: the memory model skips lazily allocated types. Mali-G615 lists DEVICE_LOCAL|LAZILY_ALLOCATED first; taken as the device-local type it left images with no memory type (self-test "image clear/draw: setup" FAIL, gamescope "No compatible image memory type"). - Session: a bridge self-test that fails images or draws falls back to the runtime's driver pair for that session (BL_VKBRIDGE_FALLBACK_ICD); Setup and the graphics report say so. - Venus: the Mali compatibility layer runs in every process but gamescope (DROIDDECK_MALI_COMPAT=1), so Zink in Steam and Xwayland gets nullDescriptor; null texel-buffer views get stand-ins too. Without nullDescriptor the session's GL goes to llvmpipe. - gamescope 0129: a refused compute pipeline is named with its SPIR-V capabilities. - Compositor: a buffer on two surfaces at once (gamescope's planes while a notification is up) is released only when the last one lets go. - Open driver pairs: processes.txt timeline for the first three minutes; Setup "Steam interface: GPU drawing" turns off software web compositing. * Pin gamescope p17 (0129) and Venus 55b30fbf * Non-Adreno round 4: Mali GPU-drawing block, gamescope YCbCr retry, GL probe, bridge draw sync - Setup's "Steam interface: GPU drawing" is hidden on Mali and a saved "on" is cleared: with PanVK it rebooted an Edge 60 (G615) as steamwebhelper started. Kept for Xclipse. - gamescope 0130: a composite pipeline refused at start-up is retried with a layout without immutable YCbCr samplers (G615 through Venus refused every composite shader; their SPIR-V has no Float16, so fp16 was not the cause). - Venus: droiddeck-glprobe opens GL through GLX the way the Steam client does, with the loader's reasons logged; when it fails the client's GL goes to llvmpipe. - vkbridge self-test: the draw check waits for the render pass's stores before copying out (a tiler read zeros without the dependency). * Pin gamescope p18 (0130) * Non-Adreno round 5: gamescope memory fallback, Venus destroy guard, OpenAL depot - gamescope 0131: DEVICE_LOCAL|HOST_VISIBLE requests fall back to host-visible memory (the bridge's unified-memory model lists none with both), with the request, type bits and memory types logged on failure; 0130's probe pipeline is kept and skipped when forced. - Venus: GAMESCOPE_NO_YCBCR_SAMPLERS=1 from the start; virglrenderer ignores the destroy of a pipeline it never created instead of marking the context fatal (vtest server exit 137 on a Mali-G615). - Steam's OpenAL depot (229020) maps to oalinst_dll, so games that list it (Hotline Miami) get OpenAL in their prefix. * Pin gamescope p19 (0131) and Venus 6199a93f * Non-Adreno round 6: PowerVR PRIME on old kernels, thermal, hang-up names, bridge flippable images, Venus Zink variants - drm.c: PR #570's current PRIME ownership check (F_DUPFD_QUERY, then kcmp, then the F_SETOWN_EX owner marker): on a kernel before 6.10 with kcmp blocked, drmPrimeFDToHandle answered EOPNOTSUPP for every PowerVR import (Pixel 10, Android 17: Zink "failed drmPrimeFDToHandle", Xwayland error 7, gamescope X11 I/O error). The Mali stand-in node is kept. - A /sys/class/thermal the kernel will not list gets an empty directory, so mangoapp no longer aborts on it. - gamescope 0132: a hung-up waitable is named before the abort; 0133: the bridge's flippable images use supported-but-unexportable modifiers instead of asserting. - Venus: when Zink does not start, the loader's view is logged and Zink is retried without ZINK_DEBUG=compact, with ZINK_DESCRIPTORS=auto and without kopper before falling back to llvmpipe. * Pin gamescope p20 (0132, 0133) * Non-Adreno round 7: bridge command-buffer guard, Venus Zink trace, PowerVR mangoapp, Xclipse label - vkbridge server: every command buffer a device hands out is tracked; Begin, End (stream replay) and QueueSubmit refuse one it never allocated or has freed (VK_ERROR_DEVICE_LOST, logged) instead of passing it to the driver, where Mali's vkBeginCommandBuffer crashed the app (SIGSEGV 0x10, Steam's Zink on an Edge 60 and a Tab S11). - vkbridge server: a fault inside the driver while serving a request cuts that client off (SIGSEGV/SIGBUS guard per request) and leaves its objects alone; the app and the other clients carry on. Other faults go to the previous handler. - vkbridge server: the pipeline cache directory is copied; the JNI string it pointed at was freed (garbage in the cache path). - Venus: DROIDDECK_MALI_COMPAT_TRACE=1 makes the Mali compatibility layer log what an application queries before vkCreateDevice; a failed glprobe adds a traced run and vulkaninfo --summary under the same environment. - PowerVR: mangoapp draws with llvmpipe (Zink could not make it a swapchain and it crashed at every start). - Setup: an Xclipse GPU reads "Experimental: RADV or the system Xclipse driver", not the PowerVR line. * Pin Venus e40cd361 (layer trace) * Non-Adreno round 8: bridge sharing fallback and crash detail, Venus diagnostics and 1.2 gate, compositor disconnect reasons, RADV upstream - Mali bridge: the self-test fails "memory sharing" when the server offers no host-visible memory type (no sharing method passed, RP4 Pro G77); the session then falls back to the PanVK pair like a failed draw, and Setup says the bridge cannot share memory with that driver. Without a pair to fall back on, the log says so. - Mali bridge: a guarded driver crash now logs the sub-command it was in, the fault address and pc (library + offset via dladdr), the command buffer's level, begin flags, pool flags and state, and the last 32 replayed commands. Begin on an executable buffer from a pool without RESET_COMMAND_BUFFER_BIT is logged once (implicit reset). - Venus: vulkan-summary.txt gets the device extension list and key features (full vulkaninfo in vulkan-full.txt); a failed GL probe runs once with VN_DEBUG=init,result, ZINK_DEBUG=mem, MESA_LOG_LEVEL=debug and the layer trace into glprobe-trace.txt. The Mali compatibility layer's trace covers every pre-device query (devices, memory, queue families, formats, image formats, external handles) and names the extensions. - Venus: off when the phone's driver reports Vulkan below 1.2 (gamescope skips such a device); Setup and the graphics report say why and the session uses the PanVK pair. - Compositor: libwayland's own disconnect reasons go to wayland.log, and a client's buffer may grow to 1 MB before a slow reader is dropped. A session that ended without teardown records Android's exit reasons. - Drivers: RADV-Xclipse upstream (radv-xclipse-upstream) is a manual choice for Xclipse; Auto keeps radv-xclipse. * Tests: the terminal-callers harness stubs the Quest layer and Cardboard modules and Android's system properties * Pin gamescope p21 (main's patches + 0120-0133) and Venus a4d47cf3 (layer trace) * Display driver Auto: Quest's patched Turnip first; the system driver only for a Mali, other GPUs keep the generic fallback * Open driver pairs: the installed build's version, its upload date, and an Update when the release is rebuilt in place - The release check records each asset's GitHub id and updated_at; a download records them (with the digest) for an open non-Adreno pair. - Components > GPU drivers: an installed open pair shows its manifest version ("android <tag> + linux <commit>"), one not yet installed shows "built YYYY-MM-DD". A different digest, asset id or upload time on the same tag marks the installed pair "Update available" with an Update action: the pair is downloaded again and replaced in place, and stays selected only if it was. Adreno and DD-Turnip pairs are unchanged. - graphics-report.txt: the pair release line gives the installed and the listed upload dates and flags a newer build; an exact bundle id match is preferred (RADV-Xclipse-upstream is not RADV-Xclipse). * Session preload: drop oom_score_adj raises so lmkd does not treat games as cached apps steam-launch-wrapper starts every game with --oom-score-adjust 900; on Android 900 is CACHED_APP_MIN_ADJ, so lmkd kills the running game first when memory runs short (and on Linux 6.1 the raise becomes the process's permanent minimum). A process in the app cannot go below the score it inherits, so the writes that succeed from inside are raises: every write-open of /proc/<pid|self|thread-self>[/task/<tid>]/oom_score_adj (or oom_adj), through open/openat or fopen, goes to /dev/null, logged once. Based on the oom_score_adj redirect in the preload's opens.c by jdmg28 (https://github.com/jdmg28/DroidDeck-Mali/commit/6be00e00) * Display: why presenting failed on the session-ended screen, and the display driver that really loaded - The compositor records why it cannot present (no Vulkan driver loaded, vkCreateInstance/vkCreateDevice failed, no GPU or graphics queue, no swapchain on the screen with the driver's reason, device lost, GPU work unconfirmed). Each is a DD_PRESENT_FAULT line in wayland.log, read back over JNI or from wayland.log; the session-ended screen shows it instead of a black screen, and graphics-report.txt gets "!! DISPLAY FAILED". A first frame or a working swapchain clears it. - After the display device is created, the driver that answered is logged from VkPhysicalDeviceDriverProperties (device, driverName, driverInfo, driver id, Vulkan version) and reported in graphics-report.txt. When a driver pair's display half was requested but a vendor driver answered (adrenotools falls back to the system driver when the requested one does not load), it says so. Based on DD_PRESENT_FAULT in vk_present.c / waylandcomp_jni.c / SessionActivity by jdmg28 (https://github.com/jdmg28/DroidDeck-Mali/blob/arena/cd8ab18a-droiddeck-mali/app/src/main/cpp/waylandcomp/src/vk_present.c) Based on the adrenotools silent-fallback finding by ryanistr (https://github.com/ryanistr/DroidDeck-Mali/blob/main/docs/development/panvk-mali-g77-bringup.md) * tests: steam presentation test sets 0.5.0's steam_client * Non-Adreno: find every driver pair, Venus before the bridge, fix the bridge's begin info From the logs testers sent since c9ebb247: - The app read the drivers repo's newest 15 releases only; the component releases (gamescope, Venus) pushed every PanVK pair and RADV-Xclipse past them, so Auto found no pair on any Mali and switched the Mali bridge on. The non-Adreno repo is now read in one page of 100. - Auto's stand-in for a missing pair: Mali (Venus) where the apk carries it (Steam runs on it from the G57 to the G1-Ultra), the bridge otherwise, nothing on a driver below Vulkan 1.2. It no longer clears the Linux driver, does nothing when the list could not be read, records that it chose the route, and turns it off again once a pair is installed. A bridge that earlier builds left on under Auto is taken as Auto's. - Mali bridge: vkBeginCommandBuffer sent its begin info without the count the server decodes, so Mali got a zeroed begin info with stale flags and crashed at 0x10 (Pixel 8 Pro G715, Lenovo G615, Xiaomi G925, Tab S11). - Mali-G1 series (MT6993, arch v14) known by its chip; its label says Venus, not the bridge. - A session Android killed for memory is said so on the next start (the S24 FE "crashes" were low-memory kills, not driver faults). - The in-app updater never installs an official (Adreno-only) build over this test build. * Venus: destroy the device's object mutex after the objects that lock it Bionic aborts on locking a destroyed mutex ("pthread_mutex_lock called on a destroyed mutex", Tab S9 FE G68, Pixel 9a), so a client that exited holding objects took the render worker down. From BattleTempest's DroidDeck-Pixel (kevinbryant551-ux/DroidDeck-Pixel, GPL-3.0). * release check: a session helper may be extracted to another runtime path droiddeck-steam-taskset (#570) goes to usr/local/libexec/droiddeck-steam/taskset, where PATH puts it in front of Steam's own taskset for the client only; 0.5.0's check wanted every droiddeck-* helper at its own path. * Venus component 93038b7d (destroyed-mutex fix) * Update MaliBridge to v0.5.1 (#1135) * Mali Auto: never leave a session on the runtime's Turnip Logs from a Retroid Pocket 4 Pro (G77), Galaxy S21 Ultra (G78), Tab S11 Ultra (G925) and Xiaomi G610 showed Auto ending on the runtime's Turnip, where gamescope finds no GPU ("failed to find physical device"): after a pair's trial rolled back, when the pair is on the bad list, and when the driver list could not be read. In each case Auto now switches on its stand-in (Venus, or the bridge) when no open driver, Venus or bridge is set. Under Auto the Mali display also leaves any imported driver, not only a pair's PanVK half (a lone PanVK_G720 import gave a black screen). * Mali bridge: MaliBridge 224b6e36 (v0.5.3 source, by ASEbrahim) From c65062b6 (v0.5.1). v0.5.2/v0.5.3: Steam mode on older Mali drivers (G77/G710/G610/G57) gets past "starting display and audio", OpenGL 4.6 on most Malis through dynamic-rendering and vertex-format emulation, Dimensity 9500 texture fixes, async pipeline compile, RE2 flicker on G925, DirectX on the Pixel 8 family. JNI entry and session env names are unchanged. * gamescope 0134: linear when the backend offers no modifier; Venus on Mesa 26.2.5 0134: CVulkanTexture::BInit asserted !modifiers.empty() when the nested Wayland backend offered no modifier for a flippable image's format (NieR Replicant on a Pixel 9a under Venus, session exit 134). It now tries linear and logs it. Venus ICD: mesa-26.2.5 (venus TLS teardown from an unloaded driver, virtio-gpu devices without 3D skipped); virglrenderer stays on 1.3.0. * gamescope p22-nonadreno (0134 + main's 0116 cursor fix; build run 40159674290) * CI: build the non-Adreno additions before the preload check * build.gradle: drop verifyHandModel (main moved the hand models into the tracking pack) * Venus component venus-proto13-e24ed8ab (Mesa 26.2.5; build run 40161447324) * CI: fetch the Mali (Venus) component again (lost when build.yml took main's jobs) Build a7a1ebf1 (run 40161734101) had no assets/venus or libvirgl_test_server.so, so VenusComponent.available() was false and Auto's stand-in would have been the bridge. * Auto: the Mali bridge stands in on a Vulkan 1.1 Mali driver Auto refused both Venus and the bridge when the phone's driver reports Vulkan below 1.2, so on the G77, G78 and G610 (r32p1/r38, Vulkan 1.1) a rolled-back or missing pair left the runtime's Turnip: "failed to find physical device" (Retroid Pocket 4 Pro after the JM pair's trial, Xiaomi 13T). Only Venus needs 1.2; the bridge raises the driver for gamescope and runs on these phones. A Venus switch that cannot start on such a driver no longer counts as a route. * Tests: stub main's g_release_unpaced in the DMA-BUF quarantine probe The probe copies release_buffer out of compositor.c; since the merge it reads g_release_unpaced, which the harness did not declare (setUpClass failed to compile). * Update MaliBridge to v0.5.4 (ASEbrahim) 48477fe6 (tag v0.5.4): Dimensity 9500 green squares and red-tinted textures, Balatro and other OpenGL text, fewer crashes when memory runs low, one screen update per game frame, picture kept after a long background pause (SIGHUP no longer stops the server), wrong colours after changing graphics settings on the G720, more in the session report. The app-side changes of his DroidDeck Mali app (Steam menus setting, per-game setup, Send logs, updates) are not part of the MaliBridge repository and are not in this build. * gamescope 0135: linear when the driver rejects every offered modifier An r32p1 Mali-G610 (Vulkan 1.1) behind the Mali bridge answered both of the backend's modifiers for AR24 with VK_ERROR_FORMAT_NOT_SUPPORTED, so the first flippable image failed and gamescope asserted in vulkan_create_flat_texture (Xiaomi 13T). Linear, when offered, is tried anyway; the bridge makes such images without the handle type and exports them through a dma-heap. If the image cannot be made, BInit fails as before. * gamescope: pin the non-Adreno p23 build (0135) * Tests: the terminal-callers harness stubs take_shm's game-frame detection Main's take_shm now reads surface damage, parent/role/mapped and the HUD state to spot game frames; the harness declares them so the copied function compiles (setUpClass failed in Build APK run 40505286127). No damage, so it stays off. * gamescope: number the test branch's patches 0920-0935 Main now has its own 0121-0125 (window override walk, host-event wake, commit fences, done at import, HUD frame times), which sorted in between this branch's 0120-0135. The branch's sixteen patches move to 0920-0935 with the same last two digits, so they apply after main's set and stay clear of its next numbers. Applying all 38 to gamescope 3.16.29 in the old order and the new one gives the same tree (checked with patch -p1, as build-in-arch.sh does). PATCHES.md and the one code comment that named 0130 follow the new numbers. * check_session_assets: helpers count in usr/local/bin or the Steam taskset folder only The merge kept this branch's pattern (any usr/ target), which main's new test rejects: a helper extracted into a subfolder of usr/local/bin must not count. The pattern now takes usr/local/bin under any name, as on main, plus usr/local/libexec/droiddeck-steam for droiddeck-steam-taskset. Every helper in the overlay is still found extracted in SessionFiles.kt. * gamescope: pin 3.16.29 p24 (non-Adreno) Built from this branch @d13b9d88 (run 41119284267): main a5b035b2's patches plus this branch's, now 0920-0935. All 38 applied, gamescope's tests 2/2. sha256 1d1088d4. * Update MaliBridge to v0.5.4.2 (ASEbrahim) 95a1e600 (tag v0.5.4.2), was v0.5.4 (48477fe6). For the bridge: memory sharing without the handle type where that is all the self-test passed (unflagged buffers, client/memory.c, server_memory.c), the older-Mali (G52-G77) game-mode start fixes, the r38p1 beta geometry-shader erratum (gs_hide), present timeouts and an API cap per process. Client, server and the in-app library all build from the submodule with MaliBridge's own scripts, which did not change; the protocol only gained fields an older server sends as 0. * Session end: the compositor fault query no longer fails the hint when the native library is absent presentationFault() (6778a224) called WaylandCompositor.compositorFault() directly. Main's new SessionEndHintTest runs sessionEndHint() in Robolectric, where libdroiddeckwayland cannot load, so all six cases ended in UnsatisfiedLinkError (Build APK run 41125749537). The call is now wrapped like runtimeDamageHint()'s, and without an answer the hint reads wayland.log as before. * test: stub the GPU busy reader in the caller harness * fix: release build is not debuggable, Mali uses the system display driver, staging failure ends its own session * fix: address non-Adreno review findings * fix: preserve current gamescope and GPU warning behavior * fix: retain graphics failure hints and launch diagnostics * fix: identify non-Adreno GPUs in driver failure hints * test: harnesses follow the external client barrier and effects upscaling changes * fix: client sources return to foreign ownership after the overlay draws --------- Co-authored-by: Leask Wong <i@leaskh.com> Co-authored-by: wallentx <william.allentx@gmail.com> Co-authored-by: Stefan Zijlstra <6730062+stefanz92@users.noreply.github.com> Co-authored-by: William Allen <wallentx@users.noreply.github.com> Co-authored-by: The412Banner <the412banner@users.noreply.github.com> Co-authored-by: Dersim Abbas <derabb0620@gmail.com> Co-authored-by: root <root@localhost.localdomain> Co-authored-by: ASEbrahim <ahmadsmain@gmail.com> Co-authored-by: The412Banner <the412banner@gmail.com> Co-authored-by: The412Banner <205237651+The412Banner@users.noreply.github.com> --- .github/workflows/build-venus.yml | 31 + .github/workflows/build.yml | 26 + .gitignore | 1 + app/src/main/cpp/waylandcomp/CMakeLists.txt | 2 + .../generated/wayland-android-protocol.c | 104 +++ .../wayland-android-server-protocol.h | 341 +++++++ .../waylandcomp/protocols/wayland-android.xml | 139 +++ .../main/cpp/waylandcomp/src/ahb_swapchain.c | 4 + app/src/main/cpp/waylandcomp/src/compositor.c | 118 ++- .../cpp/waylandcomp/src/compositor_internal.h | 3 + .../waylandcomp/src/vk_external_image_sync.h | 47 + app/src/main/cpp/waylandcomp/src/vk_loader.h | 2 +- app/src/main/cpp/waylandcomp/src/vk_present.c | 389 ++++++-- app/src/main/cpp/waylandcomp/src/vk_present.h | 9 + .../cpp/waylandcomp/src/waylandcomp_jni.c | 18 + .../cpp/waylandcomp/src/wl_android_buffer.c | 216 +++++ .../com/droiddeck/launcher/DriverMenus.kt | 194 +++- .../droiddeck/launcher/FrontEndActivity.kt | 38 +- .../com/droiddeck/launcher/SessionActivity.kt | 54 +- .../launcher/audio/PulseAudioComponent.java | 46 +- .../droiddeck/launcher/core/DeviceReport.kt | 25 +- .../droiddeck/launcher/core/DeviceSupport.kt | 30 +- .../launcher/frontend/SteamRedists.kt | 2 + .../com/droiddeck/launcher/gpu/DeviceInfo.kt | 16 +- .../droiddeck/launcher/gpu/DriverBundle.kt | 8 +- .../com/droiddeck/launcher/gpu/DriverPairs.kt | 78 +- .../com/droiddeck/launcher/gpu/GpuInfo.kt | 108 ++- .../launcher/gpu/LinuxVulkanDriver.java | 41 +- .../gpu/LinuxVulkanDriverManager.java | 34 +- .../launcher/gpu/SystemVulkanDriver.java | 261 ++++++ .../droiddeck/launcher/gpu/TurnipDriver.java | 20 +- .../droiddeck/launcher/gpu/TurnipReleases.kt | 80 +- .../launcher/runtime/LinuxRuntime.java | 39 +- .../launcher/session/ComponentsManager.kt | 24 +- .../launcher/session/GraphicsReport.kt | 250 +++++ .../launcher/session/OrphanReaper.kt | 16 + .../launcher/session/SessionArtifacts.kt | 66 +- .../launcher/session/SessionFiles.kt | 13 +- .../launcher/session/SessionPrefs.kt | 77 +- .../launcher/session/SessionService.kt | 119 ++- .../launcher/session/VenusComponent.kt | 131 +++ .../droiddeck/launcher/ui/ComponentsPage.kt | 87 +- .../droiddeck/launcher/ui/FrontEndScreen.kt | 9 + .../droiddeck/launcher/ui/FrontEndSetup.kt | 33 +- .../droiddeck/launcher/ui/GpuDriversPanel.kt | 30 +- .../droiddeck/launcher/ui/SessionOverlay.kt | 35 +- .../droiddeck/launcher/update/AppUpdates.kt | 8 + .../launcher/wayland/WaylandCompositor.java | 22 + app/src/main/res/values-ar/strings.xml | 8 +- app/src/main/res/values-b+es+419/strings.xml | 8 +- app/src/main/res/values-bg/strings.xml | 8 +- app/src/main/res/values-cs/strings.xml | 8 +- app/src/main/res/values-da/strings.xml | 8 +- app/src/main/res/values-de/strings.xml | 8 +- app/src/main/res/values-el/strings.xml | 8 +- app/src/main/res/values-es/strings.xml | 8 +- app/src/main/res/values-fi/strings.xml | 8 +- app/src/main/res/values-fr/strings.xml | 8 +- app/src/main/res/values-hi/strings.xml | 8 +- app/src/main/res/values-hu/strings.xml | 8 +- app/src/main/res/values-in/strings.xml | 8 +- app/src/main/res/values-it/strings.xml | 8 +- app/src/main/res/values-ja/strings.xml | 8 +- app/src/main/res/values-ko/strings.xml | 8 +- app/src/main/res/values-ms/strings.xml | 8 +- app/src/main/res/values-nb/strings.xml | 8 +- app/src/main/res/values-nl/strings.xml | 8 +- app/src/main/res/values-pl/strings.xml | 8 +- app/src/main/res/values-pt-rPT/strings.xml | 8 +- app/src/main/res/values-pt/strings.xml | 8 +- app/src/main/res/values-ro/strings.xml | 8 +- app/src/main/res/values-ru/strings.xml | 8 +- app/src/main/res/values-sv/strings.xml | 8 +- app/src/main/res/values-th/strings.xml | 8 +- app/src/main/res/values-tr/strings.xml | 8 +- app/src/main/res/values-uk/strings.xml | 8 +- app/src/main/res/values-vi/strings.xml | 8 +- app/src/main/res/values-zh-rCN/strings.xml | 8 +- app/src/main/res/values-zh-rHK/strings.xml | 8 +- app/src/main/res/values-zh-rTW/strings.xml | 8 +- app/src/main/res/values/strings.xml | 53 +- .../launcher/core/DeviceSupportTest.kt | 14 + .../launcher/frontend/WinCompSourcesTest.kt | 2 + .../droiddeck/launcher/gpu/DeviceInfoTest.kt | 13 + .../launcher/gpu/DriverBundleTest.kt | 15 + .../launcher/gpu/DriverPairUpdateTest.kt | 37 + .../droiddeck/launcher/gpu/DriverPairsTest.kt | 147 +++ .../launcher/gpu/GpuDetectionTest.kt | 2 +- .../launcher/gpu/SystemVulkanPruningTest.kt | 109 +++ .../launcher/gpu/SystemVulkanSelectionTest.kt | 129 +++ .../launcher/session/ForcedPackageTest.kt | 28 + .../launcher/session/GraphicsReportTest.kt | 39 + .../session/OrphanReaperProcessTest.kt | 23 + .../session/PowerVrAutoDriversTest.kt | 44 + .../launcher/session/PowerVrComponentsTest.kt | 14 + .../session/PowerVrQueuedComponentsTest.kt | 41 + .../launcher/session/SessionEndHintTest.kt | 48 +- .../launcher/ui/ComponentsPageProfileTest.kt | 156 +++- .../launcher/update/AppUpdatesTest.kt | 6 + .../american-nightmare-pixel-debug.md | 197 ++++ docs/development/gpu-pending-completion.md | 88 ++ docs/development/mali-venus.md | 269 ++++++ tools/build_local.sh | 8 + tools/docker_platform.sh | 2 +- tools/dxvk/build.sh | 42 + tools/dxvk/check_d3d9_single_sample.py | 112 +++ tools/dxvk/check_hud_storage_format.py | 73 ++ tools/dxvk/check_present_sync.py | 116 +++ .../0001-check-direct3d-bc-formats.patch | 53 ++ ...resent-semaphore-per-swapchain-image.patch | 26 + .../0003-hud-explicit-r8-texel-format.patch | 12 + .../0004-d3d9-force-single-sample.patch | 86 ++ tools/dxvk/source.env | 1 + tools/dxvk/tests/d3d9_single_sample.cpp | 214 +++++ tools/gamescope/PATCHES.md | 75 +- tools/gamescope/build-in-arch.sh | 5 +- ...nested-swapchain-capability-fallback.patch | 358 ++++++++ .../0921-powervr-single-pixel-rcas.patch | 15 + .../0922-powervr-linear-dmabuf-import.patch | 156 ++++ .../0923-powervr-rgba-copy-surface.patch | 61 ++ .../0924-sdl-preserve-explicit-refresh.patch | 78 ++ .../0925-sdl-wait-before-present.patch | 23 + .../patches/0926-explicit-sync-switch.patch | 29 + ...0927-shm-buffers-upload-every-commit.patch | 44 + .../patches/0928-robustness2-optional.patch | 96 ++ .../0929-log-failing-compute-pipeline.patch | 55 ++ ...ite-without-immutable-ycbcr-samplers.patch | 78 ++ ...0931-memory-type-fallback-keep-probe.patch | 55 ++ .../patches/0932-name-hung-up-waitable.patch | 57 ++ ...ippable-image-unexportable-modifiers.patch | 44 + ...flippable-image-no-backend-modifiers.patch | 26 + ...image-linear-when-driver-rejects-all.patch | 38 + tools/gamescope/release.env | 6 +- tools/gamescope/tests/nested-swapchain.cpp | 156 ++++ tools/hybris/build_runtime.sh | 51 + tools/hybris/low32/README.md | 99 ++ tools/hybris/low32/build.sh | 27 + tools/hybris/low32/gpu-copy.c | 166 ++++ tools/hybris/low32/low32.c | 256 ++++++ tools/hybris/low32/test-chain-hook.c | 37 + tools/hybris/low32/test-low32.c | 119 +++ tools/hybris/low32/test-preload-chain.c | 62 ++ .../hybris/patches/0001-dxvk-bc-profile.patch | 505 ++++++++++ tools/hybris/powervr-hal-version.patch | 12 + tools/hybris/run-proton.py | 89 ++ tools/hybris/source.env | 2 + tools/linuxfs/check-preloads.sh | 5 + tools/linuxfs/desktop/droiddeck-gpu | 12 +- .../overlay/usr/local/bin/droiddeck-game-env | 121 ++- .../overlay/usr/local/bin/droiddeck-session | 164 +++- .../usr/local/bin/droiddeck-steam-taskset | 17 + .../overlay/usr/local/bin/steam-compatibility | 3 + tools/linuxfs/preload/drm.c | 183 +++- tools/linuxfs/preload/netif.c | 3 + tools/linuxfs/preload/oomadj.c | 47 + tools/linuxfs/preload/opens.c | 3 + tools/linuxfs/preload/venus.c | 18 + .../VkLayer_droiddeck_xclipse.json | 11 + tools/linuxfs/xclipse-layer/device_chain.inc | 180 ++++ .../linuxfs/xclipse-layer/gen_device_chain.py | 43 + tools/linuxfs/xclipse-layer/xclipse_layer.c | 493 ++++++++++ tools/local-cross.Dockerfile | 2 +- tools/mangoapp/mangoapp | 7 + tools/pixel_reset_diagnostics.py | 152 +++ tools/powervr/fetch.py | 366 ++++++++ tools/powervr/release.json | 335 +++++++ tools/release/check_session_assets.py | 16 +- tools/release/runtime_inputs.py | 15 +- tools/tests/drm_handles_test.c | 343 +++++++ tools/tests/test_drm_handles.py | 26 + tools/tests/test_dxvk_build.py | 121 +++ tools/tests/test_effects_source_resolution.py | 21 +- tools/tests/test_game_environment.py | 241 +++++ tools/tests/test_gamescope_backend.py | 102 ++ tools/tests/test_oom_adj_preload.py | 47 + tools/tests/test_pixel_reset_diagnostics.py | 215 +++++ tools/tests/test_powervr_runtime.py | 291 ++++++ tools/tests/test_proton_wrapper.py | 228 +++++ tools/tests/test_runtime_inputs.py | 19 + tools/tests/test_steam_helper_affinity.py | 91 ++ tools/tests/test_steam_presentation.py | 75 ++ tools/tests/test_vk_dmabuf_quarantine.py | 120 +++ tools/tests/test_vk_external_image_sync.py | 63 ++ tools/tests/test_vk_pending_completion.py | 187 ++++ tools/tests/test_vk_terminal_callers.py | 140 +++ tools/tests/test_xclipse_layer.py | 47 + tools/tests/vk_dmabuf_quarantine_test.c | 199 ++++ tools/tests/vk_external_image_sync_test.c | 63 ++ tools/tests/vk_terminal_callers_test.c | 290 ++++++ tools/tests/xclipse_layer_test.c | 217 +++++ tools/venus/addr2line.sh | 14 + tools/venus/ci-build.sh | 146 +++ tools/venus/glprobe.c | 69 ++ tools/venus/guest-vulkaninfo.sh | 15 + .../layer/VkLayer_droiddeck_mali_compat.json | 17 + tools/venus/layer/bc.c | 869 ++++++++++++++++++ tools/venus/layer/draw.c | 452 +++++++++ tools/venus/layer/layer.c | 812 ++++++++++++++++ tools/venus/layer/mali_compat.h | 301 ++++++ tools/venus/layer/pipeline.c | 308 +++++++ tools/venus/layer/spirv.c | 833 +++++++++++++++++ tools/venus/layer/trace.c | 233 +++++ tools/venus/measure-present.patch | 153 +++ tools/venus/memtypes.c | 40 + tools/venus/mesa-venus-vtest.patch | 541 +++++++++++ tools/venus/release.env | 3 + tools/venus/virglrenderer-android.patch | 322 +++++++ ...renderer-destroy-mutex-after-objects.patch | 30 + ...rglrenderer-destroy-unknown-pipeline.patch | 54 ++ tools/venus/watch-maps.sh | 19 + tools/vulkan-wsi/build.sh | 34 + .../licenses/Vulkan-Headers/LICENSE.md | 19 + .../licenses/Vulkan-Headers/MIT.txt | 9 + .../0001-link-x11-external-memory.patch | 16 + tools/vulkan-wsi/source.env | 2 + 215 files changed, 19024 insertions(+), 428 deletions(-) create mode 100644 .github/workflows/build-venus.yml create mode 100644 app/src/main/cpp/waylandcomp/generated/wayland-android-protocol.c create mode 100644 app/src/main/cpp/waylandcomp/generated/wayland-android-server-protocol.h create mode 100644 app/src/main/cpp/waylandcomp/protocols/wayland-android.xml create mode 100644 app/src/main/cpp/waylandcomp/src/vk_external_image_sync.h create mode 100644 app/src/main/cpp/waylandcomp/src/wl_android_buffer.c create mode 100644 app/src/main/java/com/droiddeck/launcher/gpu/SystemVulkanDriver.java create mode 100644 app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt create mode 100644 app/src/main/java/com/droiddeck/launcher/session/VenusComponent.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/core/DeviceSupportTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/gpu/DeviceInfoTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/gpu/DriverPairUpdateTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/gpu/SystemVulkanPruningTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/gpu/SystemVulkanSelectionTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/session/GraphicsReportTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/session/OrphanReaperProcessTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/session/PowerVrAutoDriversTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/session/PowerVrComponentsTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/session/PowerVrQueuedComponentsTest.kt create mode 100644 docs/development/american-nightmare-pixel-debug.md create mode 100644 docs/development/gpu-pending-completion.md create mode 100644 docs/development/mali-venus.md create mode 100755 tools/dxvk/build.sh create mode 100644 tools/dxvk/check_d3d9_single_sample.py create mode 100644 tools/dxvk/check_hud_storage_format.py create mode 100644 tools/dxvk/check_present_sync.py create mode 100644 tools/dxvk/patches/0001-check-direct3d-bc-formats.patch create mode 100644 tools/dxvk/patches/0002-present-semaphore-per-swapchain-image.patch create mode 100644 tools/dxvk/patches/0003-hud-explicit-r8-texel-format.patch create mode 100644 tools/dxvk/patches/0004-d3d9-force-single-sample.patch create mode 100644 tools/dxvk/source.env create mode 100644 tools/dxvk/tests/d3d9_single_sample.cpp create mode 100644 tools/gamescope/patches/0920-nested-swapchain-capability-fallback.patch create mode 100644 tools/gamescope/patches/0921-powervr-single-pixel-rcas.patch create mode 100644 tools/gamescope/patches/0922-powervr-linear-dmabuf-import.patch create mode 100644 tools/gamescope/patches/0923-powervr-rgba-copy-surface.patch create mode 100644 tools/gamescope/patches/0924-sdl-preserve-explicit-refresh.patch create mode 100644 tools/gamescope/patches/0925-sdl-wait-before-present.patch create mode 100644 tools/gamescope/patches/0926-explicit-sync-switch.patch create mode 100644 tools/gamescope/patches/0927-shm-buffers-upload-every-commit.patch create mode 100644 tools/gamescope/patches/0928-robustness2-optional.patch create mode 100644 tools/gamescope/patches/0929-log-failing-compute-pipeline.patch create mode 100644 tools/gamescope/patches/0930-composite-without-immutable-ycbcr-samplers.patch create mode 100644 tools/gamescope/patches/0931-memory-type-fallback-keep-probe.patch create mode 100644 tools/gamescope/patches/0932-name-hung-up-waitable.patch create mode 100644 tools/gamescope/patches/0933-flippable-image-unexportable-modifiers.patch create mode 100644 tools/gamescope/patches/0934-flippable-image-no-backend-modifiers.patch create mode 100644 tools/gamescope/patches/0935-flippable-image-linear-when-driver-rejects-all.patch create mode 100644 tools/gamescope/tests/nested-swapchain.cpp create mode 100755 tools/hybris/build_runtime.sh create mode 100644 tools/hybris/low32/README.md create mode 100755 tools/hybris/low32/build.sh create mode 100644 tools/hybris/low32/gpu-copy.c create mode 100644 tools/hybris/low32/low32.c create mode 100644 tools/hybris/low32/test-chain-hook.c create mode 100644 tools/hybris/low32/test-low32.c create mode 100644 tools/hybris/low32/test-preload-chain.c create mode 100644 tools/hybris/patches/0001-dxvk-bc-profile.patch create mode 100644 tools/hybris/powervr-hal-version.patch create mode 100644 tools/hybris/run-proton.py create mode 100644 tools/hybris/source.env create mode 100644 tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-taskset create mode 100644 tools/linuxfs/preload/oomadj.c create mode 100644 tools/linuxfs/preload/venus.c create mode 100644 tools/linuxfs/xclipse-layer/VkLayer_droiddeck_xclipse.json create mode 100644 tools/linuxfs/xclipse-layer/device_chain.inc create mode 100755 tools/linuxfs/xclipse-layer/gen_device_chain.py create mode 100644 tools/linuxfs/xclipse-layer/xclipse_layer.c create mode 100644 tools/pixel_reset_diagnostics.py create mode 100644 tools/powervr/fetch.py create mode 100644 tools/powervr/release.json create mode 100644 tools/tests/drm_handles_test.c create mode 100644 tools/tests/test_drm_handles.py create mode 100644 tools/tests/test_dxvk_build.py create mode 100644 tools/tests/test_gamescope_backend.py create mode 100644 tools/tests/test_oom_adj_preload.py create mode 100644 tools/tests/test_pixel_reset_diagnostics.py create mode 100644 tools/tests/test_powervr_runtime.py create mode 100644 tools/tests/test_proton_wrapper.py create mode 100644 tools/tests/test_steam_helper_affinity.py create mode 100644 tools/tests/test_steam_presentation.py create mode 100644 tools/tests/test_vk_dmabuf_quarantine.py create mode 100644 tools/tests/test_vk_external_image_sync.py create mode 100644 tools/tests/test_vk_pending_completion.py create mode 100644 tools/tests/test_vk_terminal_callers.py create mode 100644 tools/tests/test_xclipse_layer.py create mode 100644 tools/tests/vk_dmabuf_quarantine_test.c create mode 100644 tools/tests/vk_external_image_sync_test.c create mode 100644 tools/tests/vk_terminal_callers_test.c create mode 100644 tools/tests/xclipse_layer_test.c create mode 100644 tools/venus/addr2line.sh create mode 100755 tools/venus/ci-build.sh create mode 100644 tools/venus/glprobe.c create mode 100644 tools/venus/guest-vulkaninfo.sh create mode 100644 tools/venus/layer/VkLayer_droiddeck_mali_compat.json create mode 100644 tools/venus/layer/bc.c create mode 100644 tools/venus/layer/draw.c create mode 100644 tools/venus/layer/layer.c create mode 100644 tools/venus/layer/mali_compat.h create mode 100644 tools/venus/layer/pipeline.c create mode 100644 tools/venus/layer/spirv.c create mode 100644 tools/venus/layer/trace.c create mode 100644 tools/venus/measure-present.patch create mode 100644 tools/venus/memtypes.c create mode 100644 tools/venus/mesa-venus-vtest.patch create mode 100644 tools/venus/release.env create mode 100644 tools/venus/virglrenderer-android.patch create mode 100644 tools/venus/virglrenderer-destroy-mutex-after-objects.patch create mode 100644 tools/venus/virglrenderer-destroy-unknown-pipeline.patch create mode 100644 tools/venus/watch-maps.sh create mode 100755 tools/vulkan-wsi/build.sh create mode 100644 tools/vulkan-wsi/licenses/Vulkan-Headers/LICENSE.md create mode 100644 tools/vulkan-wsi/licenses/Vulkan-Headers/MIT.txt create mode 100644 tools/vulkan-wsi/patches/0001-link-x11-external-memory.patch create mode 100644 tools/vulkan-wsi/source.env diff --git a/.github/workflows/build-venus.yml b/.github/workflows/build-venus.yml new file mode 100644 index 0000000000..d355bdcd78 --- /dev/null +++ b/.github/workflows/build-venus.yml @@ -0,0 +1,31 @@ +name: Build Venus (Mali) +# The Mali (Venus) route's binaries from tools/venus (David Cimo's recipes): Mesa's Venus ICD and the +# Mali compatibility layer (glibc, for the session) and virglrenderer's vtest server (bionic, run by +# the app over the phone's own Vulkan driver), packed as venus.tzst rooted at app/src/main. The apk +# build fetches it by tools/venus/release.env (tag + sha256); nothing compiled is kept in this repo. +on: + workflow_dispatch: + push: + branches: [test/non-adreno-all] + paths: ['tools/venus/**', '.github/workflows/build-venus.yml'] +permissions: + contents: read +jobs: + build: + runs-on: ubuntu-24.04 + timeout-minutes: 120 + steps: + - uses: actions/checkout@v4 + - name: Tools + run: | + sudo apt-get update -qq + sudo apt-get install -y -qq ninja-build pkg-config zstd python3-pip + pip3 install --break-system-packages 'meson>=1.5' + - name: Build + run: ANDROID_NDK_HOME="$ANDROID_NDK_LATEST_HOME" WORK=$PWD/venus-work tools/venus/ci-build.sh + - uses: actions/upload-artifact@v4 + with: + name: venus + path: | + venus-work/venus.tzst + venus-work/venus.tzst.sha256 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7418c5bfb5..083c052500 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -275,6 +275,19 @@ jobs: if: steps.proot.outputs.cache-hit != 'true' run: python3 tools/components/prepare.py proot + - name: Build the non-Adreno test additions (Mali bridge client, Venus GL probe, Xclipse layer) + run: | + set -euo pipefail + bash tools/ci/install-ubuntu-packages.sh gcc-aarch64-linux-gnu libvulkan-dev + D=app/src/main/assets/linuxfs + mkdir -p "$D/usr/local/bin" "$D/usr/local/lib/droiddeck-xclipse" + aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -Wextra -Wno-unused-parameter -fvisibility=hidden -pthread \ + -o "$D/usr/local/lib/droiddeck-xclipse/libVkLayer_droiddeck_xclipse.so" tools/linuxfs/xclipse-layer/xclipse_layer.c -ldl + aarch64-linux-gnu-strip --strip-unneeded "$D/usr/local/lib/droiddeck-xclipse/libVkLayer_droiddeck_xclipse.so" + install -m644 tools/linuxfs/xclipse-layer/VkLayer_droiddeck_xclipse.json "$D/usr/local/lib/droiddeck-xclipse/" + aarch64-linux-gnu-gcc -O2 -Wall -o "$D/usr/local/bin/droiddeck-glprobe" tools/venus/glprobe.c -ldl + aarch64-linux-gnu-strip --strip-unneeded "$D/usr/local/bin/droiddeck-glprobe" + - name: Check the preloads run: | set -euo pipefail @@ -573,6 +586,18 @@ jobs: - name: Check out MaliBridge run: git submodule update --init external/MaliBridge + - name: Fetch the Mali (Venus) component (tools/venus/release.env) + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + . tools/venus/release.env + gh release download "${VENUS_TAG}" -R "${VENUS_REPO}" -p venus.tzst -O venus.tzst + echo "${VENUS_SHA256} venus.tzst" | sha256sum -c - + tar --use-compress-program=unzstd -xf venus.tzst -C app/src/main + test -f app/src/main/jniLibs/arm64-v8a/libvirgl_test_server.so + test -f app/src/main/assets/venus/libvulkan_virtio.so + rm venus.tzst - name: Build id: build @@ -581,6 +606,7 @@ jobs: SGDB_API_KEY: ${{ secrets.SGDB_API_KEY }} run: | set -o pipefail + python3 tools/powervr/fetch.py python3 tools/release/runtime_inputs.py record ./gradlew assembleRelease --console=plain -PndkVersion="$NDK_VERSION" 2>&1 | tee /tmp/build.log python3 tools/release/check_session_assets.py app/build/outputs/apk/release/app-release.apk diff --git a/.gitignore b/.gitignore index bfeee76414..0a404ef667 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,5 @@ __pycache__/ .signing.env app/src/main/assets/directaudio/ +app/src/main/assets/hybris/ /tools/vr/out/ diff --git a/app/src/main/cpp/waylandcomp/CMakeLists.txt b/app/src/main/cpp/waylandcomp/CMakeLists.txt index fd0b2f20a9..61baf0d379 100644 --- a/app/src/main/cpp/waylandcomp/CMakeLists.txt +++ b/app/src/main/cpp/waylandcomp/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(droiddeckwayland SHARED src/gpu_clock_pin.c src/droiddeck_ext.c src/wl_dmabuf.c + src/wl_android_buffer.c src/wl_clipboard.c src/wl_text_input.c src/wl_toplevel_icon.c @@ -22,6 +23,7 @@ add_library(droiddeckwayland SHARED generated/color-management-v1-protocol.c generated/xdg-shell-protocol.c generated/linux-dmabuf-v1-protocol.c + generated/wayland-android-protocol.c generated/viewporter-protocol.c generated/banner-desktop-v1-protocol.c generated/presentation-time-protocol.c diff --git a/app/src/main/cpp/waylandcomp/generated/wayland-android-protocol.c b/app/src/main/cpp/waylandcomp/generated/wayland-android-protocol.c new file mode 100644 index 0000000000..79e171faa2 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/wayland-android-protocol.c @@ -0,0 +1,104 @@ +/* Generated by wayland-scanner 1.26.0 */ + +/* + * Copyright © 2012 Collabora, Ltd. + * + * Permission to use, copy, modify, distribute, and sell this + * software and its documentation for any purpose is hereby granted + * without fee, provided that the above copyright notice appear in + * all copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of + * the copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface android_wlegl_handle_interface; +extern const struct wl_interface android_wlegl_server_buffer_handle_interface; +extern const struct wl_interface wl_buffer_interface; + +static const struct wl_interface *android_types[] = { + NULL, + NULL, + &android_wlegl_handle_interface, + NULL, + NULL, + &wl_buffer_interface, + NULL, + NULL, + NULL, + NULL, + NULL, + &android_wlegl_handle_interface, + &android_wlegl_server_buffer_handle_interface, + NULL, + NULL, + NULL, + NULL, + &wl_buffer_interface, + NULL, + NULL, +}; + +static const struct wl_message android_wlegl_requests[] = { + { "create_handle", "nia", android_types + 2 }, + { "create_buffer", "niiiiio", android_types + 5 }, + { "get_server_buffer_handle", "2niiii", android_types + 12 }, +}; + +WL_PRIVATE const struct wl_interface android_wlegl_interface = { + "android_wlegl", 3, + 3, android_wlegl_requests, + 0, NULL, +}; + +static const struct wl_message android_wlegl_handle_requests[] = { + { "add_fd", "h", android_types + 0 }, + { "destroy", "", android_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface android_wlegl_handle_interface = { + "android_wlegl_handle", 1, + 2, android_wlegl_handle_requests, + 0, NULL, +}; + +static const struct wl_message android_wlegl_server_buffer_handle_events[] = { + { "buffer_fd", "h", android_types + 0 }, + { "buffer_ints", "a", android_types + 0 }, + { "buffer", "nii", android_types + 17 }, + { "linear_layout", "3uu", android_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface android_wlegl_server_buffer_handle_interface = { + "android_wlegl_server_buffer_handle", 3, + 0, NULL, + 4, android_wlegl_server_buffer_handle_events, +}; diff --git a/app/src/main/cpp/waylandcomp/generated/wayland-android-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/wayland-android-server-protocol.h new file mode 100644 index 0000000000..0fd3b6d68f --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/wayland-android-server-protocol.h @@ -0,0 +1,341 @@ +/* Generated by wayland-scanner 1.26.0 */ + +#ifndef ANDROID_SERVER_PROTOCOL_H +#define ANDROID_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_android The android protocol + * @section page_ifaces_android Interfaces + * - @subpage page_iface_android_wlegl - Android EGL graphics buffer support + * - @subpage page_iface_android_wlegl_handle - An Android native_handle_t object + * - @subpage page_iface_android_wlegl_server_buffer_handle - a server allocated buffer + * @section page_copyright_android Copyright + * <pre> + * + * Copyright © 2012 Collabora, Ltd. + * + * Permission to use, copy, modify, distribute, and sell this + * software and its documentation for any purpose is hereby granted + * without fee, provided that the above copyright notice appear in + * all copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of + * the copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + * </pre> + */ +struct android_wlegl; +struct android_wlegl_handle; +struct android_wlegl_server_buffer_handle; +struct wl_buffer; + +#ifndef ANDROID_WLEGL_INTERFACE +#define ANDROID_WLEGL_INTERFACE +/** + * @page page_iface_android_wlegl android_wlegl + * @section page_iface_android_wlegl_desc Description + * + * Interface used in the Android wrapper libEGL to share + * graphics buffers between the server and the client. + * @section page_iface_android_wlegl_api API + * See @ref iface_android_wlegl. + */ +/** + * @defgroup iface_android_wlegl The android_wlegl interface + * + * Interface used in the Android wrapper libEGL to share + * graphics buffers between the server and the client. + */ +extern const struct wl_interface android_wlegl_interface; +#endif +#ifndef ANDROID_WLEGL_HANDLE_INTERFACE +#define ANDROID_WLEGL_HANDLE_INTERFACE +/** + * @page page_iface_android_wlegl_handle android_wlegl_handle + * @section page_iface_android_wlegl_handle_desc Description + * + * The Android native_handle_t is a semi-opaque object, that + * contains an EGL implementation specific number of int32 + * values and file descriptors. + * + * We cannot send a variable size array of file descriptors + * over the Wayland protocol, so we send them one by one. + * @section page_iface_android_wlegl_handle_api API + * See @ref iface_android_wlegl_handle. + */ +/** + * @defgroup iface_android_wlegl_handle The android_wlegl_handle interface + * + * The Android native_handle_t is a semi-opaque object, that + * contains an EGL implementation specific number of int32 + * values and file descriptors. + * + * We cannot send a variable size array of file descriptors + * over the Wayland protocol, so we send them one by one. + */ +extern const struct wl_interface android_wlegl_handle_interface; +#endif +#ifndef ANDROID_WLEGL_SERVER_BUFFER_HANDLE_INTERFACE +#define ANDROID_WLEGL_SERVER_BUFFER_HANDLE_INTERFACE +/** + * @page page_iface_android_wlegl_server_buffer_handle android_wlegl_server_buffer_handle + * @section page_iface_android_wlegl_server_buffer_handle_desc Description + * + * On creation a server_side_buffer object will immediately send + * the "buffer_fd" and "buffer_ints" events needed by the client to + * reference the gralloc buffer, followed by the "buffer" event carrying + * the wl_buffer object. + * @section page_iface_android_wlegl_server_buffer_handle_api API + * See @ref iface_android_wlegl_server_buffer_handle. + */ +/** + * @defgroup iface_android_wlegl_server_buffer_handle The android_wlegl_server_buffer_handle interface + * + * On creation a server_side_buffer object will immediately send + * the "buffer_fd" and "buffer_ints" events needed by the client to + * reference the gralloc buffer, followed by the "buffer" event carrying + * the wl_buffer object. + */ +extern const struct wl_interface android_wlegl_server_buffer_handle_interface; +#endif + +#ifndef ANDROID_WLEGL_ERROR_ENUM +#define ANDROID_WLEGL_ERROR_ENUM +enum android_wlegl_error { + ANDROID_WLEGL_ERROR_BAD_HANDLE = 0, + ANDROID_WLEGL_ERROR_BAD_VALUE = 1, +}; +#endif /* ANDROID_WLEGL_ERROR_ENUM */ + +#ifndef ANDROID_WLEGL_ERROR_ENUM_IS_VALID +#define ANDROID_WLEGL_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_android_wlegl + * Validate a android_wlegl error value. + * + * @return true on success, false on error. + * @ref android_wlegl_error + */ +static inline bool +android_wlegl_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ANDROID_WLEGL_ERROR_BAD_HANDLE: + return version >= 1; + case ANDROID_WLEGL_ERROR_BAD_VALUE: + return version >= 1; + default: + return false; + } +} +#endif /* ANDROID_WLEGL_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_android_wlegl + * @struct android_wlegl_interface + */ +struct android_wlegl_interface { + /** + * Create an Android native_handle_t object + * + * This creator method initialises the native_handle_t object + * with everything except the file descriptors, which have to be + * submitted separately. + * @param ints an array of int32_t + */ + void (*create_handle)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + int32_t num_fds, + struct wl_array *ints); + /** + * Create a wl_buffer from the native handle + * + * Pass the Android native_handle_t to the server and attach it + * to the new wl_buffer object. + * + * The android_wlegl_handle object must be destroyed immediately + * after this request. + */ + void (*create_buffer)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + int32_t width, + int32_t height, + int32_t stride, + int32_t format, + int32_t usage, + struct wl_resource *native_handle); + /** + * @since 2 + */ + void (*get_server_buffer_handle)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + int32_t width, + int32_t height, + int32_t format, + int32_t usage); +}; + + +/** + * @ingroup iface_android_wlegl + */ +#define ANDROID_WLEGL_CREATE_HANDLE_SINCE_VERSION 1 +/** + * @ingroup iface_android_wlegl + */ +#define ANDROID_WLEGL_CREATE_BUFFER_SINCE_VERSION 1 +/** + * @ingroup iface_android_wlegl + */ +#define ANDROID_WLEGL_GET_SERVER_BUFFER_HANDLE_SINCE_VERSION 2 + +#ifndef ANDROID_WLEGL_HANDLE_ERROR_ENUM +#define ANDROID_WLEGL_HANDLE_ERROR_ENUM +enum android_wlegl_handle_error { + ANDROID_WLEGL_HANDLE_ERROR_TOO_MANY_FDS = 0, +}; +#endif /* ANDROID_WLEGL_HANDLE_ERROR_ENUM */ + +#ifndef ANDROID_WLEGL_HANDLE_ERROR_ENUM_IS_VALID +#define ANDROID_WLEGL_HANDLE_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_android_wlegl_handle + * Validate a android_wlegl_handle error value. + * + * @return true on success, false on error. + * @ref android_wlegl_handle_error + */ +static inline bool +android_wlegl_handle_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ANDROID_WLEGL_HANDLE_ERROR_TOO_MANY_FDS: + return version >= 1; + default: + return false; + } +} +#endif /* ANDROID_WLEGL_HANDLE_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_android_wlegl_handle + * @struct android_wlegl_handle_interface + */ +struct android_wlegl_handle_interface { + /** + */ + void (*add_fd)(struct wl_client *client, + struct wl_resource *resource, + int32_t fd); + /** + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); +}; + + +/** + * @ingroup iface_android_wlegl_handle + */ +#define ANDROID_WLEGL_HANDLE_ADD_FD_SINCE_VERSION 1 +/** + * @ingroup iface_android_wlegl_handle + */ +#define ANDROID_WLEGL_HANDLE_DESTROY_SINCE_VERSION 1 + +#define ANDROID_WLEGL_SERVER_BUFFER_HANDLE_BUFFER_FD 0 +#define ANDROID_WLEGL_SERVER_BUFFER_HANDLE_BUFFER_INTS 1 +#define ANDROID_WLEGL_SERVER_BUFFER_HANDLE_BUFFER 2 +#define ANDROID_WLEGL_SERVER_BUFFER_HANDLE_LINEAR_LAYOUT 3 + +/** + * @ingroup iface_android_wlegl_server_buffer_handle + */ +#define ANDROID_WLEGL_SERVER_BUFFER_HANDLE_BUFFER_FD_SINCE_VERSION 1 +/** + * @ingroup iface_android_wlegl_server_buffer_handle + */ +#define ANDROID_WLEGL_SERVER_BUFFER_HANDLE_BUFFER_INTS_SINCE_VERSION 1 +/** + * @ingroup iface_android_wlegl_server_buffer_handle + */ +#define ANDROID_WLEGL_SERVER_BUFFER_HANDLE_BUFFER_SINCE_VERSION 1 +/** + * @ingroup iface_android_wlegl_server_buffer_handle + */ +#define ANDROID_WLEGL_SERVER_BUFFER_HANDLE_LINEAR_LAYOUT_SINCE_VERSION 3 + + +/** + * @ingroup iface_android_wlegl_server_buffer_handle + * Sends an buffer_fd event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +android_wlegl_server_buffer_handle_send_buffer_fd(struct wl_resource *resource_, int32_t fd) +{ + wl_resource_post_event(resource_, ANDROID_WLEGL_SERVER_BUFFER_HANDLE_BUFFER_FD, fd); +} + +/** + * @ingroup iface_android_wlegl_server_buffer_handle + * Sends an buffer_ints event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +android_wlegl_server_buffer_handle_send_buffer_ints(struct wl_resource *resource_, struct wl_array *ints) +{ + wl_resource_post_event(resource_, ANDROID_WLEGL_SERVER_BUFFER_HANDLE_BUFFER_INTS, ints); +} + +/** + * @ingroup iface_android_wlegl_server_buffer_handle + * Sends an buffer event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +android_wlegl_server_buffer_handle_send_buffer(struct wl_resource *resource_, struct wl_resource *buffer, int32_t format, int32_t stride) +{ + wl_resource_post_event(resource_, ANDROID_WLEGL_SERVER_BUFFER_HANDLE_BUFFER, buffer, format, stride); +} + +/** + * @ingroup iface_android_wlegl_server_buffer_handle + * Sends an linear_layout event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +android_wlegl_server_buffer_handle_send_linear_layout(struct wl_resource *resource_, uint32_t drm_format, uint32_t stride) +{ + wl_resource_post_event(resource_, ANDROID_WLEGL_SERVER_BUFFER_HANDLE_LINEAR_LAYOUT, drm_format, stride); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/protocols/wayland-android.xml b/app/src/main/cpp/waylandcomp/protocols/wayland-android.xml new file mode 100644 index 0000000000..de8a78b66e --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/wayland-android.xml @@ -0,0 +1,139 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="android"> + + <copyright> + Copyright © 2012 Collabora, Ltd. + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that copyright notice and this permission + notice appear in supporting documentation, and that the name of + the copyright holders not be used in advertising or publicity + pertaining to distribution of the software without specific, + written prior permission. The copyright holders make no + representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied + warranty. + + THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + THIS SOFTWARE. + </copyright> + + <interface name="android_wlegl" version="3"> + <description summary="Android EGL graphics buffer support"> + Interface used in the Android wrapper libEGL to share + graphics buffers between the server and the client. + </description> + + <enum name="error"> + <entry name="bad_handle" value="0" /> + <entry name="bad_value" value="1" /> + </enum> + + <request name="create_handle"> + <description summary="Create an Android native_handle_t object"> + This creator method initialises the native_handle_t object + with everything except the file descriptors, which have to be + submitted separately. + </description> + + <arg name="id" type="new_id" interface="android_wlegl_handle" /> + <arg name="num_fds" type="int" /> + <arg name="ints" type="array" summary="an array of int32_t" /> + </request> + + <request name="create_buffer"> + <description summary="Create a wl_buffer from the native handle"> + Pass the Android native_handle_t to the server and attach it + to the new wl_buffer object. + + The android_wlegl_handle object must be destroyed immediately + after this request. + </description> + + <arg name="id" type="new_id" interface="wl_buffer" /> + <arg name="width" type="int" /> + <arg name="height" type="int" /> + <arg name="stride" type="int" /> + <arg name="format" type="int" /> + <arg name="usage" type="int" /> + <arg name="native_handle" type="object" interface="android_wlegl_handle" /> + </request> + + + <request name="get_server_buffer_handle" since="2"> + <arg name="id" type="new_id" interface="android_wlegl_server_buffer_handle"/> + <arg name="width" type="int"/> + <arg name="height" type="int"/> + <arg name="format" type="int"/> + <arg name="usage" type="int"/> + </request> + + </interface> + + <interface name="android_wlegl_handle" version="1"> + <description summary="An Android native_handle_t object"> + The Android native_handle_t is a semi-opaque object, that + contains an EGL implementation specific number of int32 + values and file descriptors. + + We cannot send a variable size array of file descriptors + over the Wayland protocol, so we send them one by one. + </description> + + <enum name="error"> + <entry name="too_many_fds" value="0" /> + </enum> + + <request name="add_fd"> + <arg name="fd" type="fd" /> + </request> + + <request name="destroy" type="destructor" /> + + </interface> + + + <interface name="android_wlegl_server_buffer_handle" version="3"> + <description summary="a server allocated buffer"> + On creation a server_side_buffer object will immediately send + the "buffer_fd" and "buffer_ints" events needed by the client to + reference the gralloc buffer, followed by the "buffer" event carrying + the wl_buffer object. + </description> + <event name="buffer_fd"> + <arg name="fd" type="fd"/> + </event> + <event name="buffer_ints"> + <arg name="ints" type="array"/> + </event> + <event name="buffer"> + <description summary="the wl_buffer"> + This event will be sent after the ints and all the fds have been sent + </description> + <arg name="buffer" type="new_id" interface="wl_buffer"/> + <arg name="format" type="int"/> + <arg name="stride" type="int"/> + </event> + <event name="linear_layout" since="3"> + <description summary="verified single-plane linear allocation"> + Optional metadata sent before the buffer event. The first buffer_fd + contains one uncompressed 32-bit RGB plane at byte offset zero. + drm_format is its DRM FourCC and stride is its row pitch in bytes. + The server has verified the layout and allocation bounds using + Android mapper metadata, not inferred them from opaque handle ints. + Absence of this event means the layout is unspecified. + </description> + <arg name="drm_format" type="uint"/> + <arg name="stride" type="uint"/> + </event> + </interface> + +</protocol> diff --git a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c index cb44478354..e33b0c77b4 100644 --- a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c +++ b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c @@ -79,6 +79,9 @@ static struct ahb_buf *find_buf(uint64_t id) { } static void buf_free(struct ahb_buf *ab) { + /* A display release does not prove the compositor's Vulkan reads finished. + * Keep the AHB reference and its DMA-BUF record even if the client is gone. */ + if (vkp_completion_unknown()) return; if (ab->resource) { wl_list_remove(&ab->resource_destroy.link); ab->resource = NULL; } if (ab->fence_src) { wl_event_source_remove(ab->fence_src); ab->fence_src = NULL; } if (ab->fence_fd >= 0) { close(ab->fence_fd); ab->fence_fd = -1; } @@ -103,6 +106,7 @@ static void on_buffer_resource_destroyed(struct wl_listener *l, void *data) { static void send_deferred_release(struct ahb_buf *ab) { + if (vkp_completion_unknown()) return; if (ab->release_pending && ab->resource) droiddeck_release_buffer(ab->surface, ab->resource, ab->surface != NULL, ab->deferred_ns); ab->release_pending = 0; diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c index 471748a6d0..21ef1d23f9 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor.c +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -154,6 +154,16 @@ static void on_client_destroyed(struct wl_listener *l, void *data) { free(ci); } +/* libwayland's own reasons for dropping a client (a failed read or flush, an invalid object, a + * malformed request) go through wl_log, which on Android writes to a closed stderr. */ +static void wl_log_to_session(const char *fmt, va_list ap) { + char line[512]; + vsnprintf(line, sizeof(line), fmt, ap); + size_t n = strlen(line); + while (n && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = 0; + droiddeck_log("program", "libwayland: %s", line); +} + static void on_client_created(struct wl_listener *l, void *data) { struct wl_client *client = data; struct client_info *ci = calloc(1, sizeof(*ci)); @@ -349,6 +359,62 @@ static void perf_note_release(int64_t since_ns) { } +/* Completion-unknown is terminal for externally owned DMA-BUF contents too. + * Keeping a VkImage alone cannot stop the client from overwriting its backing + * memory after wl_buffer.release. All paths (including cursors and idle roles) + * use this gate; copied SHM buffers retain their normal release behaviour. */ +static struct dmabuf_buffer *get_dmabuf(struct wl_resource *buffer); +static int buffer_release_blocked(struct wl_resource *buffer) { + return vkp_completion_unknown() && get_dmabuf(buffer) != NULL; +} +/* Buffer tracing on a GPU that is not an Adreno (no KGSL node): every attach and release of the + * first 400 buffer events, by wl_buffer id and the line that sent it, and any release of a buffer + * already released and not attached again since (gamescope: "Compositor released us but we were + * not acquired"). Off on an Adreno. */ +static int g_buf_trace = -1; +static int g_buf_trace_left = 400; +static uint32_t g_released_ids[128]; +static int buf_trace_on(void) { + if (g_buf_trace < 0) g_buf_trace = access("/dev/kgsl-3d0", F_OK) != 0; + return g_buf_trace; +} +static void buf_trace_attach(struct wl_resource *buffer) { + if (!buffer || !buf_trace_on()) return; + uint32_t id = wl_resource_get_id(buffer); + for (int i = 0; i < 128; i++) if (g_released_ids[i] == id) g_released_ids[i] = 0; + if (g_buf_trace_left > 0) { g_buf_trace_left--; droiddeck_log("buffer", "attach id %u", id); } +} +static void buf_trace_release(struct wl_resource *buffer, int line) { + if (!buffer || !buf_trace_on()) return; + uint32_t id = wl_resource_get_id(buffer); + int twice = 0, slot = -1; + for (int i = 0; i < 128; i++) { + if (g_released_ids[i] == id) twice = 1; + if (slot < 0 && g_released_ids[i] == 0) slot = i; + } + if (twice) droiddeck_log("buffer", "DOUBLE release id %u (line %d): released again without an attach", id, line); + else if (slot >= 0) g_released_ids[slot] = id; + if (g_buf_trace_left > 0) { g_buf_trace_left--; droiddeck_log("buffer", "release id %u (line %d)", id, line); } +} + +#define send_buffer_release(b) send_buffer_release_at((b), __LINE__) +static void send_buffer_release_at(struct wl_resource *buffer, int line) { + if (!buffer_release_blocked(buffer)) { buf_trace_release(buffer, line); wl_buffer_send_release(buffer); } +} + +/* Whether a surface other than `except` is showing this buffer right now. gamescope's Wayland + * backend moves one buffer between its planes (the game's frame goes from the window to a + * subsurface above a black backing while a Steam notification is up): releasing it when the first + * surface lets go handed gamescope a buffer still on screen ("Compositor released us but we were + * not acquired"). Only the last surface to let go releases it. */ +static int buffer_shown_elsewhere(struct wl_resource *buffer, const struct surface *except) { + struct surface *o; + if (!buffer) return 0; + wl_list_for_each(o, &g_surfaces, link) + if (o != except && o->dmabuf == buffer) return 1; + return 0; +} + static void pending_release_free(struct pending_release *pr) { if (pr->surface && pr->surface->releases_pending > 0) pr->surface->releases_pending--; wl_list_remove(&pr->destroy.link); @@ -372,7 +438,8 @@ static void arm_release_timer(void) { int64_t earliest = 0; if (g_release_timer_fd < 0) return; wl_list_for_each(pr, &g_pending_releases, link) - if (!earliest || pr->at_ns < earliest) earliest = pr->at_ns; + if (!buffer_release_blocked(pr->buffer) && (!earliest || pr->at_ns < earliest)) + earliest = pr->at_ns; struct itimerspec its = {0}; if (earliest) { its.it_value.tv_sec = earliest / 1000000000LL; its.it_value.tv_nsec = earliest % 1000000000LL; } timerfd_settime(g_release_timer_fd, TFD_TIMER_ABSTIME, &its, NULL); @@ -384,8 +451,13 @@ static int on_release_timer(int fd, uint32_t mask, void *data) { int64_t now = now_ns() + 300000; if (read(fd, &expirations, sizeof(expirations)) < 0 && errno != EAGAIN) return 0; wl_list_for_each_safe(pr, tmp, &g_pending_releases, link) { - if (pr->at_ns <= now) { - wl_buffer_send_release(pr->buffer); + if (pr->at_ns <= now && !buffer_release_blocked(pr->buffer)) { + /* Attached again since (to its surface or another): that surface releases it later. */ + if (buffer_shown_elsewhere(pr->buffer, NULL)) { + pending_release_free(pr); + continue; + } + send_buffer_release(pr->buffer); perf_note_release(pr->since_ns); pending_release_free(pr); } @@ -396,9 +468,12 @@ static int on_release_timer(int fd, uint32_t mask, void *data) { } static void release_buffer(struct surface *s, struct wl_resource *buffer, int64_t since_ns) { + /* No allocation or immediate-release fallback is allowed for a quarantined + * DMA-BUF. Existing queued releases stay held; their timer is disarmed. */ + if (buffer_release_blocked(buffer)) return; const int limit = g_fps_limit; const int64_t interval = limit > 0 ? 1000000000LL / limit : g_refresh_ns; - if (g_release_unpaced || interval <= 0 || g_release_timer_fd < 0) { wl_buffer_send_release(buffer); perf_note_release(since_ns); return; } + if (g_release_unpaced || interval <= 0 || g_release_timer_fd < 0) { send_buffer_release(buffer); perf_note_release(since_ns); return; } int64_t now = now_ns(); int64_t at = s->next_release_ns + interval; int64_t latest = now + interval * (int64_t)(s->releases_pending + 1); @@ -406,7 +481,7 @@ static void release_buffer(struct surface *s, struct wl_resource *buffer, int64_ if (at > latest) at = latest; s->next_release_ns = at; struct pending_release *pr = calloc(1, sizeof(*pr)); - if (!pr) { wl_buffer_send_release(buffer); perf_note_release(since_ns); return; } + if (!pr) { send_buffer_release(buffer); perf_note_release(since_ns); return; } pr->buffer = buffer; pr->surface = s; pr->at_ns = at; @@ -523,7 +598,10 @@ static void constraints_focus_entered(struct wl_resource *target, struct wl_clie void dmabuf_buffer_unref(struct dmabuf_buffer *b) { - if (!b || --b->refs > 0) return; + /* Surface/client destruction must not close the backing FDs or free the + * imported-buffer record while a GPU read may still be pending. Retain the + * reference without allocating a quarantine node; process exit reclaims it. */ + if (!b || vkp_completion_unknown() || --b->refs > 0) return; vkp_image_destroy(b->img); for (int i = 0; i < b->n_planes; i++) if (b->fd[i] >= 0) close(b->fd[i]); @@ -622,9 +700,10 @@ static void unmap_toplevel(struct surface *s) { static void drop_dmabuf(struct surface *s, int paced) { if (s->dmabuf) { wl_list_remove(&s->dmabuf_destroy.link); - if (!ahb_swapchain_defer_release(s->dmabuf_buf, s->dmabuf, s, paced)) { + if (buffer_shown_elsewhere(s->dmabuf, s)) { + } else if (!ahb_swapchain_defer_release(s->dmabuf_buf, s->dmabuf, s, paced)) { if (paced) release_buffer(s, s->dmabuf, now_ns()); - else wl_buffer_send_release(s->dmabuf); + else send_buffer_release(s->dmabuf); } s->dmabuf = NULL; } @@ -733,7 +812,7 @@ static void take_shm(struct surface *s, struct wl_shm_buffer *shm, struct wl_res vkp_image_upload_shm(s->shm_img, wl_shm_buffer_get_data(shm), stride); wl_shm_buffer_end_access(shm); } - wl_buffer_send_release(buffer); + send_buffer_release(buffer); s->buf_w = w; s->buf_h = h; s->buf_alpha = wl_shm_buffer_get_format(shm) == WL_SHM_FORMAT_ARGB8888; @@ -777,7 +856,7 @@ static void take_pixel(struct surface *s, const uint8_t bgra[4], struct wl_resou } if (!s->shm_img) s->shm_img = vkp_image_create_shm(1, 1); if (s->shm_img) vkp_image_upload_shm(s->shm_img, bgra, 4); - wl_buffer_send_release(buffer); + send_buffer_release(buffer); s->buf_w = 1; s->buf_h = 1; s->buf_alpha = bgra[3] != 0xff; @@ -880,8 +959,9 @@ void **droiddeck_dmabuf_ahb_slot(struct dmabuf_buffer *b) { return &b->ahb_state void droiddeck_dmabuf_ref(struct dmabuf_buffer *b) { b->refs++; } void droiddeck_dmabuf_unref(struct dmabuf_buffer *b) { dmabuf_buffer_unref(b); } void droiddeck_release_buffer(struct surface *s, struct wl_resource *buffer, int paced, int64_t since_ns) { + if (buffer_release_blocked(buffer)) return; if (paced && s) release_buffer(s, buffer, since_ns); - else { wl_buffer_send_release(buffer); perf_note_release(since_ns); } + else { send_buffer_release(buffer); perf_note_release(since_ns); } } void droiddeck_surface_describe(const struct surface *s, char *out, size_t size) { describe(s, out, size); } const struct droiddeck_color *droiddeck_surface_color(const struct surface *s) { @@ -1101,7 +1181,7 @@ static void surface_hold_idle(struct surface *s, struct wl_resource *buffer) { struct wl_shm_buffer *shm = db ? NULL : wl_shm_buffer_get(buffer); int64_t px = db ? (int64_t)db->width * db->height : shm ? (int64_t)wl_shm_buffer_get_width(shm) * wl_shm_buffer_get_height(shm) : 0; - if (px <= 0 || px > CURSOR_MAX_PX) { wl_buffer_send_release(buffer); return; } + if (px <= 0 || px > CURSOR_MAX_PX) { send_buffer_release(buffer); return; } s->idle_buffer = buffer; s->idle_buffer_destroy.notify = on_idle_buffer_destroyed; wl_resource_add_destroy_listener(buffer, &s->idle_buffer_destroy); @@ -1119,7 +1199,7 @@ static struct wl_resource *surface_take_idle(struct surface *s) { static void surface_drop_idle(struct surface *s) { surface_forget_idle_px(s); struct wl_resource *buffer = surface_take_idle(s); - if (buffer) wl_buffer_send_release(buffer); + if (buffer) send_buffer_release(buffer); } static void surface_commit(struct wl_client *c, struct wl_resource *r) { @@ -1172,11 +1252,12 @@ static void surface_commit(struct wl_client *c, struct wl_resource *r) { cursor_publish_hidden(); } else { cursor_publish_buffer(s, buffer); - wl_buffer_send_release(buffer); + send_buffer_release(buffer); } } else if (s->role == ROLE_NONE) { if (buffer) surface_hold_idle(s, buffer); } else if (db) { + buf_trace_attach(buffer); take_dmabuf(s, db, buffer); } else if (shm) { drop_dmabuf(s, 1); @@ -1187,7 +1268,7 @@ static void surface_commit(struct wl_client *c, struct wl_resource *r) { } else { drop_dmabuf(s, 1); s->has_content = 0; - if (buffer) wl_buffer_send_release(buffer); + if (buffer) send_buffer_release(buffer); } } @@ -2437,7 +2518,7 @@ static void pointer_set_cursor(struct wl_client *c, struct wl_resource *r, uint3 struct wl_resource *buffer = surface_take_idle(s); if (buffer) { cursor_publish_buffer(s, buffer); - wl_buffer_send_release(buffer); + send_buffer_release(buffer); } else if (g_cursor_shown == s) { cursor_publish_shown(); } else if (s->idle_px) { @@ -3836,6 +3917,10 @@ int droiddeck_wayland_run(void) { return 1; } droiddeck_log("display", "Wayland compositor listening on %s/wayland-0", rt ? rt : "?"); + wl_log_set_handler_server(wl_log_to_session); + /* A client that falls behind reading (gamescope at a few fps) must not be dropped for a full + * event buffer: libwayland's default is 4 KB per direction. */ + wl_display_set_default_max_buffer_size(display, 1u << 20); wl_display_add_client_created_listener(display, &g_client_created); wl_global_create(display, &wl_compositor_interface, 6, NULL, bind_compositor); @@ -3846,6 +3931,7 @@ int droiddeck_wayland_run(void) { wl_global_create(display, &wl_output_interface, 4, NULL, bind_output); wl_global_create(display, &xdg_wm_base_interface, 1, NULL, bind_xdg_wm_base); wl_global_create(display, &zwp_linux_dmabuf_v1_interface, 4, NULL, bind_dmabuf); + droiddeck_android_wlegl_init(display); wl_global_create(display, &wl_seat_interface, 9, NULL, bind_seat); wl_global_create(display, &banner_desktop_v1_interface, 1, NULL, bind_desktop); wl_global_create(display, &wp_presentation_interface, 2, NULL, bind_presentation); diff --git a/app/src/main/cpp/waylandcomp/src/compositor_internal.h b/app/src/main/cpp/waylandcomp/src/compositor_internal.h index 0e4229d0a4..c70f9dd193 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor_internal.h +++ b/app/src/main/cpp/waylandcomp/src/compositor_internal.h @@ -61,3 +61,6 @@ extern volatile int g_no_render_node; COMPOSITOR_INTERNAL extern dev_t g_main_device; COMPOSITOR_INTERNAL void bind_dmabuf(struct wl_client *c, void *data, uint32_t ver, uint32_t id); + +/* ---- wl_android_buffer.c */ +COMPOSITOR_INTERNAL void droiddeck_android_wlegl_init(struct wl_display *display); diff --git a/app/src/main/cpp/waylandcomp/src/vk_external_image_sync.h b/app/src/main/cpp/waylandcomp/src/vk_external_image_sync.h new file mode 100644 index 0000000000..676c36a145 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/vk_external_image_sync.h @@ -0,0 +1,47 @@ +#ifndef VK_EXTERNAL_IMAGE_SYNC_H +#define VK_EXTERNAL_IMAGE_SYNC_H + +#include <vulkan/vulkan.h> + +struct vkp_external_client_barrier_pair { + VkImageMemoryBarrier acquire; + VkImageMemoryBarrier release; +}; + +static inline int vkp_is_external_client_image(int dmabuf, int blit_dst) { + return dmabuf && !blit_dst; +} + +/* Client-owned dma-bufs, including AHardwareBuffers, live in GENERAL while + * FOREIGN owns them. Layer pool dma-bufs are destinations with a separate + * acquire/release lifecycle and must never take this source-image path. */ +static inline int vkp_external_client_barrier_pair( + VkImage image, uint32_t queue_family, int dmabuf, int blit_dst, + struct vkp_external_client_barrier_pair *pair) { + if (!vkp_is_external_client_image(dmabuf, blit_dst) || !pair) return 0; + + const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + pair->acquire = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .oldLayout = VK_IMAGE_LAYOUT_GENERAL, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, + .dstQueueFamilyIndex = queue_family, + .image = image, + .subresourceRange = range, + .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT, + }; + pair->release = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, + .srcQueueFamilyIndex = queue_family, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, + .image = image, + .subresourceRange = range, + .srcAccessMask = VK_ACCESS_MEMORY_READ_BIT, + }; + return 1; +} + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/vk_loader.h b/app/src/main/cpp/waylandcomp/src/vk_loader.h index 54cb888816..2f5701dd6b 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_loader.h +++ b/app/src/main/cpp/waylandcomp/src/vk_loader.h @@ -12,7 +12,7 @@ X(CreateAndroidSurfaceKHR) X(DestroySurfaceKHR) X(CreateDevice) \ X(GetDeviceProcAddr) X(EnumerateDeviceExtensionProperties) \ X(GetPhysicalDeviceMemoryProperties) X(GetPhysicalDeviceFormatProperties2) \ - X(GetPhysicalDeviceImageFormatProperties2) + X(GetPhysicalDeviceImageFormatProperties2) X(GetPhysicalDeviceProperties2) #define VK_DEVICE_FUNCS(X) \ X(GetDeviceQueue) X(CreateSwapchainKHR) X(DestroySwapchainKHR) X(GetSwapchainImagesKHR) \ diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index 9e1d1f7d61..8d0267cc13 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -1,6 +1,7 @@ #define _POSIX_C_SOURCE 200809L #include "vk_present.h" #include "vk_loader.h" +#include "vk_external_image_sync.h" #include "sc_layer.h" #include "effects_chain.h" #include "cardboard.h" @@ -19,6 +20,7 @@ #include <poll.h> #include <time.h> #include <pthread.h> +#include <stdarg.h> #include <android/log.h> #include <android/hardware_buffer.h> @@ -38,16 +40,59 @@ struct vkp_image { int in_general; VkFormat fmt; int sampled; + AHardwareBuffer *android_buffer; }; static ANativeWindow *g_window; static int g_ahb_import; static char *g_driver_path, *g_library_name, *g_native_lib_dir; static int g_dev_state; +static void device_lost(const char *where); +static const char *vk_result_name(VkResult r); + +/* Why the compositor cannot present ("" while it can). Logged as a DD_PRESENT_FAULT line, read + * back over JNI, and shown on the session-ended screen instead of a silent black one. */ +static char g_fault[256]; +static char g_swap_reason[160]; +static pthread_mutex_t g_fault_lock = PTHREAD_MUTEX_INITIALIZER; +static void set_fault(const char *fmt, ...) __attribute__((format(printf, 1, 2))); +static void set_fault(const char *fmt, ...) { + char msg[sizeof(g_fault)]; + va_list ap; + va_start(ap, fmt); + vsnprintf(msg, sizeof(msg), fmt, ap); + va_end(ap); + pthread_mutex_lock(&g_fault_lock); + int same = !strcmp(msg, g_fault); + if (!same) snprintf(g_fault, sizeof(g_fault), "%s", msg); + pthread_mutex_unlock(&g_fault_lock); + if (!same) droiddeck_log("present", "DD_PRESENT_FAULT: %s", msg); +} +static void clear_fault(void) { + pthread_mutex_lock(&g_fault_lock); + int had = g_fault[0] != 0; + g_fault[0] = 0; + pthread_mutex_unlock(&g_fault_lock); + if (had) droiddeck_log("present", "presentation recovered: fault cleared"); +} +const char *vkp_fault(void) { + static __thread char copy[sizeof(g_fault)]; + pthread_mutex_lock(&g_fault_lock); + snprintf(copy, sizeof(copy), "%s", g_fault); + pthread_mutex_unlock(&g_fault_lock); + if (!copy[0] && g_dev_state == -3) + snprintf(copy, sizeof(copy), "the GPU did not confirm the compositor's work finished; presenting stopped"); + return copy; +} + +/* The driver that answered for the display, as the driver itself reports it. */ +static char g_display_driver[320]; +const char *vkp_display_driver(void) { return g_display_driver; } static VkInstance g_inst; static VkPhysicalDevice g_pd; static VkDevice g_dev; static VkQueue g_queue; +static PFN_vkGetAndroidHardwareBufferPropertiesANDROID g_ahb_properties; static uint32_t g_qfam; static VkCommandPool g_pool; #define MAX_PRESENTS (1 + VKP_FG_MAX_GENERATIONS) @@ -108,10 +153,22 @@ static void perf_add(int64_t *sum, int64_t *max, unsigned *count, int64_t d) { if (d > *max) *max = d; (*count)++; } +static void quarantine_pending_work(VkResult result, const char *where) { + if (g_dev_state != 1) return; + g_dev_state = -3; + g_base_black = 0; + LOGE("GPU completion unconfirmed (%d in %s): presenting stopped; pending resources retained; " + "restart DroidDeck", (int)result, where); +} + static VkResult timed_wait(VkFence fence, uint64_t timeout) { + if (g_dev_state != 1) + return g_dev_state == -2 ? VK_ERROR_DEVICE_LOST : VK_ERROR_UNKNOWN; int64_t t0 = perf_now(); VkResult r = g_vk.WaitForFences(g_dev, 1, &fence, VK_TRUE, timeout); perf_add(&g_perf.wait_ns, &g_perf.wait_max_ns, &g_perf.waits, perf_now() - t0); + if (r != VK_SUCCESS && r != VK_ERROR_DEVICE_LOST) + quarantine_pending_work(r, "fence wait"); return r; } @@ -206,7 +263,12 @@ static void reset_sync(void) { static void destroy_swapchain(void) { g_base_black = 0; if (g_dev_state != 1) return; - g_vk.DeviceWaitIdle(g_dev); + VkResult idle = g_vk.DeviceWaitIdle(g_dev); + if (idle != VK_SUCCESS) { + if (idle == VK_ERROR_DEVICE_LOST) device_lost("swapchain idle"); + else quarantine_pending_work(idle, "swapchain idle"); + return; + } reset_sync(); for (uint32_t i = 0; i < g_nimg; i++) blendp_forget_image(g_images[i]); if (g_swapchain) g_vk.DestroySwapchainKHR(g_dev, g_swapchain, NULL); @@ -296,6 +358,7 @@ int vkp_has_window(void) { } int vkp_device_lost(void) { return g_dev_state == -2; } +int vkp_completion_unknown(void) { return g_dev_state == -3; } void vk_present_set_scale_mode(int mode, int alignment) { if (mode < VKP_MODE_OFF || mode > VKP_MODE_INTEGER) mode = VKP_MODE_FIT; @@ -406,11 +469,43 @@ static int has_ext(VkExtensionProperties *e, uint32_t n, const char *name) { return 0; } +static int is_proprietary(VkDriverId id) { + return id == VK_DRIVER_ID_ARM_PROPRIETARY || id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY || + id == VK_DRIVER_ID_IMAGINATION_PROPRIETARY || id == VK_DRIVER_ID_SAMSUNG_PROPRIETARY || + id == VK_DRIVER_ID_BROADCOM_PROPRIETARY; +} + +/* What really loaded: adrenotools falls back to the vendor driver when the requested one fails + * to load (hook_impl.cpp), so the name asked for is not proof of the driver in use. */ +static void log_display_driver(void) { + PFN_vkGetPhysicalDeviceProperties2 props2 = g_vk.GetPhysicalDeviceProperties2; + VkPhysicalDeviceDriverProperties drv = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES}; + VkPhysicalDeviceProperties2 p2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, .pNext = &drv}; + if (!props2) { + snprintf(g_display_driver, sizeof(g_display_driver), "%.200s (driver properties not available)", g_gpu_name); + droiddeck_log("gpu", "display driver: %s", g_display_driver); + return; + } + props2(g_pd, &p2); + int fell_back = g_library_name && is_proprietary(drv.driverID); + snprintf(g_display_driver, sizeof(g_display_driver), "%.80s: %.64s %.96s (driver id %d, Vulkan %u.%u.%u)%s", p2.properties.deviceName, + drv.driverName, drv.driverInfo, (int)drv.driverID, VK_API_VERSION_MAJOR(p2.properties.apiVersion), + VK_API_VERSION_MINOR(p2.properties.apiVersion), VK_API_VERSION_PATCH(p2.properties.apiVersion), + fell_back ? " - FELL BACK to the phone's own driver" : ""); + droiddeck_log("gpu", "display driver loaded: %s", g_display_driver); + if (fell_back) + droiddeck_log("gpu", "display driver: %s was requested but the phone's own driver answered; the requested " + "driver did not load (a missing library beside it, or a rejected ABI - see the adrenotools lines)", + g_library_name); +} + static int dev_init(void) { if (g_dev_state != 0) return g_dev_state == 1 ? 0 : -1; if (vk_loader_open(g_driver_path, g_library_name, g_native_lib_dir) != 0) { - LOGE("present: vk_loader_open failed"); g_dev_state = -1; return -1; + LOGE("present: vk_loader_open failed"); g_dev_state = -1; + set_fault("no Vulkan driver could be loaded for the display (%s)", g_library_name ? g_library_name : "libvulkan.so"); + return -1; } const char *inst_exts[3] = {VK_KHR_SURFACE_EXTENSION_NAME, @@ -441,13 +536,19 @@ static int dev_init(void) { .enabledExtensionCount = n_inst_exts, .ppEnabledExtensionNames = inst_exts}; if (g_vk.CreateInstance(&ici, NULL, &g_inst) != VK_SUCCESS) { - LOGE("present: vkCreateInstance failed"); g_dev_state = -1; return -1; + LOGE("present: vkCreateInstance failed"); g_dev_state = -1; + set_fault("vkCreateInstance failed on the display driver (%s)", g_library_name ? g_library_name : "the phone's own"); + return -1; } vk_loader_load_instance(g_inst); uint32_t npd = 0; g_vk.EnumeratePhysicalDevices(g_inst, &npd, NULL); - if (!npd) { LOGE("present: no physical devices"); g_dev_state = -1; return -1; } + if (!npd) { + LOGE("present: no physical devices"); g_dev_state = -1; + set_fault("the display driver exposed no GPU to the app"); + return -1; + } VkPhysicalDevice pds[8]; if (npd > 8) npd = 8; g_vk.EnumeratePhysicalDevices(g_inst, &npd, pds); g_pd = VK_NULL_HANDLE; @@ -459,7 +560,11 @@ static int dev_init(void) { for (uint32_t q = 0; q < nq; q++) if (qs[q].queueFlags & VK_QUEUE_GRAPHICS_BIT) { g_pd = pds[i]; g_qfam = q; break; } } - if (g_pd == VK_NULL_HANDLE) { LOGE("present: no graphics queue"); g_dev_state = -1; return -1; } + if (g_pd == VK_NULL_HANDLE) { + LOGE("present: no graphics queue"); g_dev_state = -1; + set_fault("the display GPU offers no graphics queue"); + return -1; + } { VkPhysicalDeviceProperties props; g_vk.GetPhysicalDeviceProperties(g_pd, &props); @@ -479,6 +584,21 @@ static int dev_init(void) { g_vk.EnumerateDeviceExtensionProperties(g_pd, NULL, &ne, NULL); VkExtensionProperties *exts = calloc(ne ? ne : 1, sizeof(*exts)); g_vk.EnumerateDeviceExtensionProperties(g_pd, NULL, &ne, exts); + if (!g_library_name || !strstr(g_library_name, "freedreno")) { + char names[440]; + size_t len = 0; + names[0] = 0; + droiddeck_log("gpu", "device extensions: %u", ne); + for (uint32_t i = 0; i < ne; i++) { + if (len + strlen(exts[i].extensionName) + 2 > sizeof(names)) { + droiddeck_log("gpu", " %s", names); + len = 0; + names[0] = 0; + } + len += (size_t)snprintf(names + len, sizeof(names) - len, "%s%s", len ? " " : "", exts[i].extensionName); + } + if (len) droiddeck_log("gpu", " %s", names); + } for (unsigned i = 0; i < 4; i++) { if (has_ext(exts, ne, import_exts[i])) dev_exts[n_dev_exts++] = import_exts[i]; else LOGE("present: driver MISSING %s (dmabuf import will fail)", import_exts[i]); @@ -492,6 +612,8 @@ static int dev_init(void) { if (want_sem_fd) dev_exts[n_dev_exts++] = VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME; g_ahb_import = has_ext(exts, ne, VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME) && has_ext(exts, ne, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME); + /* The present path's own AHB import (#561) stays on the phone's own driver. */ + const int want_ahb = !g_library_name && g_ahb_import; if (g_ahb_import) { dev_exts[n_dev_exts++] = VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME; dev_exts[n_dev_exts++] = VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME; @@ -514,11 +636,17 @@ static int dev_init(void) { dr = g_vk.CreateDevice(g_pd, &dci, NULL, &g_dev); } if (dr != VK_SUCCESS) { - LOGE("present: vkCreateDevice failed"); g_dev_state = -1; return -1; + LOGE("present: vkCreateDevice failed"); g_dev_state = -1; + set_fault("vkCreateDevice failed on %s (%s)", g_gpu_name[0] ? g_gpu_name : "the display GPU", vk_result_name(dr)); + return -1; } vk_loader_load_device(g_dev); + log_display_driver(); g_vk.GetDeviceQueue(g_dev, g_qfam, 0, &g_queue); vkp_gpu_busy_device(g_pd, g_dev, g_qfam); + if (want_ahb) + g_ahb_properties = (PFN_vkGetAndroidHardwareBufferPropertiesANDROID) + g_vk.GetDeviceProcAddr(g_dev, "vkGetAndroidHardwareBufferPropertiesANDROID"); if (want_sem_fd) { g_import_sem_fd = (PFN_vkImportSemaphoreFdKHR)g_vk.GetDeviceProcAddr(g_dev, "vkImportSemaphoreFdKHR"); VkSemaphoreCreateInfo wsci = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; @@ -555,6 +683,7 @@ static int dev_init(void) { g_dev_state = 1; reset_sync(); init_black_image(); + if (g_dev_state != 1) return -1; vkp_framegen_device_ready(g_dev, g_queue, g_qfam, fg_features != NULL); return 0; } @@ -566,13 +695,15 @@ static int swap_init_locked(void); static int swap_init(void) { struct timespec ts; int64_t now; - if (!g_window) return -1; + if (!g_window || g_dev_state != 1) return -1; clock_gettime(CLOCK_MONOTONIC, &ts); now = (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec; if (now < g_swap_retry_at_ns) return -1; + g_swap_reason[0] = 0; if (swap_init_locked() == 0) { g_swap_retry_at_ns = 0; g_swap_fail_logged = 0; + clear_fault(); return 0; } destroy_swapchain(); @@ -580,11 +711,12 @@ static int swap_init(void) { if (!g_swap_fail_logged) { g_swap_fail_logged = 1; LOGE("present: no swapchain on the screen surface; retrying every 0.5 s"); + set_fault("no swapchain on the session screen (%s)", g_swap_reason[0] ? g_swap_reason : "unknown reason"); } return -1; } -#define SWLOGE(...) do { if (!g_swap_fail_logged) LOGE(__VA_ARGS__); } while (0) +#define SWLOGE(...) do { snprintf(g_swap_reason, sizeof(g_swap_reason), __VA_ARGS__); if (!g_swap_fail_logged) LOGE(__VA_ARGS__); } while (0) static void vk_format_short(VkFormat f, char *out, size_t n) { const char *s = NULL; @@ -824,10 +956,15 @@ static void init_black_image(void) { g_vk.EndCommandBuffer(cmd); VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, .pCommandBuffers = &cmd}; g_vk.ResetFences(g_dev, 1, &g_fence); - if (g_vk.QueueSubmit(g_queue, 1, &si, g_fence) == VK_SUCCESS && - g_vk.WaitForFences(g_dev, 1, &g_fence, VK_TRUE, 1000000000ULL) == VK_SUCCESS) - g_black_state = 1; - else + VkResult qr = g_vk.QueueSubmit(g_queue, 1, &si, g_fence); + if (qr == VK_SUCCESS) { + VkResult fr = timed_wait(g_fence, 1000000000ULL); + if (fr == VK_SUCCESS) g_black_state = 1; + else if (fr == VK_ERROR_DEVICE_LOST) device_lost("black image"); + } else if (qr == VK_ERROR_DEVICE_LOST) { + device_lost("black image submit"); + } + if (g_black_state != 1) droiddeck_log("gpu", "letterbox black image unavailable: the whole output is cleared every copy-path frame"); } @@ -926,7 +1063,98 @@ struct vkp_image *vkp_image_from_dmabuf(int fd, uint32_t drm_format, uint64_t mo return vkp_image_import_dmabuf(fd, drm_format, modifier, w, h, stride, offset, 0); } -int vkp_image_is_dmabuf(const struct vkp_image *img) { return img && img->dmabuf && !img->blit_dst; } +/* Return client sources to FOREIGN after their final read. The consuming paths + * wait for our fence before Wayland can release an ordinary dma-buf or an + * android_wlegl AHardwareBuffer. Producer-fence synchronization is separate from + * these image-layout and ownership transfers. */ +static void release_external_client_image(VkCommandBuffer cmd, struct vkp_image *img) { + struct vkp_external_client_barrier_pair pair; + if (!img || !vkp_external_client_barrier_pair( + img->image, g_qfam, img->dmabuf, img->blit_dst, &pair)) + return; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, NULL, 0, NULL, 1, &pair.release); +} + +static void release_external_client_draws(VkCommandBuffer cmd, const struct vkp_draw *draws, int count) { + for (int i = 0; i < count; i++) { + int seen = 0; + for (int j = 0; j < i; j++) if (draws[j].img == draws[i].img) { seen = 1; break; } + if (!seen) release_external_client_image(cmd, draws[i].img); + } +} + +int vkp_image_is_dmabuf(const struct vkp_image *img) { + return img && vkp_is_external_client_image(img->dmabuf, img->blit_dst); +} + +int vkp_android_buffer_supported(void) { + return dev_init() == 0 && g_ahb_properties != NULL; +} + +struct vkp_image *vkp_image_from_android_buffer(AHardwareBuffer *buffer) { + if (!buffer || !vkp_android_buffer_supported()) return NULL; + AHardwareBuffer_Desc desc; + AHardwareBuffer_describe(buffer, &desc); + if (!desc.width || !desc.height || desc.layers != 1 || + (desc.usage & (AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT | AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE)) || + !(desc.usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE)) return NULL; + VkAndroidHardwareBufferFormatPropertiesANDROID format = { + .sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID}; + VkAndroidHardwareBufferPropertiesANDROID props = { + .sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID, .pNext = &format}; + VkResult result = g_ahb_properties(g_dev, buffer, &props); + if (result != VK_SUCCESS || + (format.format != VK_FORMAT_R8G8B8A8_UNORM && format.format != VK_FORMAT_R8G8B8A8_SRGB && + format.format != VK_FORMAT_B8G8R8A8_UNORM && format.format != VK_FORMAT_B8G8R8A8_SRGB) || + !props.memoryTypeBits || + !(format.formatFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT)) { + LOGE("android_wlegl: unsupported Android buffer import (%s, format %d)", + vk_result_name(result), format.format); + return NULL; + } + struct vkp_image *img = calloc(1, sizeof(*img)); + if (!img) return NULL; + img->w = (int)desc.width; img->h = (int)desc.height; + img->fmt = format.format; img->dmabuf = 1; + const VkFormatFeatureFlags sampled = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | + VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT; + img->sampled = (format.formatFeatures & sampled) == sampled; + VkExternalMemoryImageCreateInfo external = { + .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, + .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID}; + VkImageCreateInfo create = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .pNext = &external, + .imageType = VK_IMAGE_TYPE_2D, .format = img->fmt, + .extent = {desc.width, desc.height, 1}, .mipLevels = 1, .arrayLayers = 1, + .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL, + .usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | (img->sampled ? VK_IMAGE_USAGE_SAMPLED_BIT : 0), + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED}; + result = g_vk.CreateImage(g_dev, &create, NULL, &img->image); + if (result != VK_SUCCESS) goto fail; + /* AHB image requirements are not queryable before binding. The AHB query supplies them. */ + uint32_t memory_type = 0; + while (!(props.memoryTypeBits & (1u << memory_type))) memory_type++; + VkImportAndroidHardwareBufferInfoANDROID import = { + .sType = VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID, .buffer = buffer}; + VkMemoryDedicatedAllocateInfo dedicated = { + .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO, + .pNext = &import, .image = img->image}; + VkMemoryAllocateInfo allocate = { + .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .pNext = &dedicated, + .allocationSize = props.allocationSize, .memoryTypeIndex = memory_type}; + result = g_vk.AllocateMemory(g_dev, &allocate, NULL, &img->mem); + if (result != VK_SUCCESS) goto fail; + result = g_vk.BindImageMemory(g_dev, img->image, img->mem, 0); + if (result != VK_SUCCESS) goto fail; + AHardwareBuffer_acquire(buffer); + img->android_buffer = buffer; + return img; +fail: + LOGE("android_wlegl: Vulkan buffer import failed: %s", vk_result_name(result)); + vkp_image_destroy(img); + return NULL; +} struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, int w, int h, uint32_t stride, uint32_t offset, int as_blit_dst) { @@ -940,7 +1168,27 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t const VkImageUsageFlags sampled_usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; img->sampled = !as_blit_dst && g_vk.GetPhysicalDeviceImageFormatProperties2 && modifier_importable(img->fmt, modifier, sampled_usage); + /* Each new format/modifier/size a client hands over, once, for the graphics report: a colour + * or swizzle mismatch on a non-Adreno driver shows up as the pair it arrived as. */ + { + static struct { uint32_t fmt; uint64_t mod; int w, h; } seen[32]; + static int nseen; + int known = 0; + for (int i = 0; i < nseen; i++) + if (seen[i].fmt == drm_format && seen[i].mod == modifier && seen[i].w == w && seen[i].h == h) known = 1; + if (!known && nseen < 32) { + seen[nseen].fmt = drm_format; seen[nseen].mod = modifier; seen[nseen].w = w; seen[nseen].h = h; nseen++; + droiddeck_log("gpu", "dmabuf import: %c%c%c%c %s %dx%d stride %u offset %u -> vk format %d, %s%s", + drm_format & 0xff, (drm_format >> 8) & 0xff, (drm_format >> 16) & 0xff, (drm_format >> 24) & 0xff, + vkp_modifier_name(modifier), w, h, stride, offset, (int)img->fmt, + img->sampled ? "sampled" : "copied", as_blit_dst ? ", blit target" : ""); + } + } + /* Venus reports a row pitch of 0 for gamescope's 1x1 root buffer, and a zero pitch fails + * vkCreateImage, which left the whole window unshown (David Cimo). One packed, 64-byte aligned + * row is what a linear buffer that small holds. */ + if (stride == 0 && modifier == 0) stride = ((uint32_t)w * 4 + 63) & ~63u; VkSubresourceLayout plane = {.offset = offset, .rowPitch = stride}; VkImageDrmFormatModifierExplicitCreateInfoEXT modInfo = { .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT, @@ -1211,7 +1459,7 @@ struct vkp_image *vkp_image_create_shm(int w, int h) { } void vkp_image_upload_shm(struct vkp_image *img, const void *data, int stride) { - if (!img || !img->map || !data) return; + if (g_dev_state != 1 || !img || !img->map || !data) return; size_t rowbytes = (size_t)img->w * 4; if ((size_t)stride < rowbytes) rowbytes = (size_t)stride; for (int y = 0; y < img->h; y++) @@ -1224,12 +1472,14 @@ int vkp_image_height(const struct vkp_image *img) { return img ? img->h : 0; } void vkp_image_destroy(struct vkp_image *img) { if (!img) return; + if (g_dev_state == -3) return; /* completion unknown: retain GPU ownership */ if (g_dev) { blendp_forget_image(img->image); if (img->map) g_vk.UnmapMemory(g_dev, img->mem); if (img->image) g_vk.DestroyImage(g_dev, img->image, NULL); if (img->mem) g_vk.FreeMemory(g_dev, img->mem, NULL); } + if (img->android_buffer) AHardwareBuffer_release(img->android_buffer); free(img); } @@ -1325,11 +1575,14 @@ static void effects_source_note(int scene_w, int scene_h, const struct vkp_draw static void record_draw(VkCommandBuffer cmd, const struct vkp_draw *d, const VkImageBlit *blit, VkImage target, VkFormat target_fmt, int target_w, int target_h, VkFilter filter) { const struct vkp_image *im = d->img; + const int external_client = vkp_image_is_dmabuf(im); if (d->blend && im->sampled && - blendp_draw(cmd, im->image, im->fmt, im->w, im->h, !im->dmabuf, target, target_fmt, target_w, target_h, + blendp_draw(cmd, im->image, im->fmt, im->w, im->h, !external_client, + target, target_fmt, target_w, target_h, blit) == 0) return; - g_vk.CmdBlitImage(cmd, im->image, im->dmabuf ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, + g_vk.CmdBlitImage(cmd, im->image, + external_client ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, target, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, blit, filter); } @@ -1491,6 +1744,7 @@ static void device_lost(const char *where) { vkp_gpu_busy_device_lost(); droiddeck_log("error", "GPU device lost (VK_ERROR_DEVICE_LOST in %s): the compositor has stopped presenting; " "restart the session", where); + set_fault("the display GPU was lost (VK_ERROR_DEVICE_LOST in %s)", where); for (uint32_t i = 0; i < g_nimg; i++) blendp_forget_image(g_images[i]); if (g_swapchain) g_vk.DestroySwapchainKHR(g_dev, g_swapchain, NULL); g_swapchain = VK_NULL_HANDLE; @@ -1588,6 +1842,7 @@ static void record_screen_blit(VkCommandBuffer cmd, VkImage src, int src_w, int static int acquire_image(int k, int first, uint32_t *img, VkResult *ar_out) { for (int attempt = 0; ; attempt++) { + if (g_dev_state != 1) return -1; if (!g_swapchain && (!first || swap_init() != 0)) return -1; const int64_t t_acq = perf_now(); VkResult ar = g_vk.AcquireNextImageKHR(g_dev, g_swapchain, 1000000000ULL, g_acqs[k], VK_NULL_HANDLE, img); @@ -1597,7 +1852,7 @@ static int acquire_image(int k, int first, uint32_t *img, VkResult *ar_out) { if (ar == VK_ERROR_OUT_OF_DATE_KHR || ar == VK_ERROR_SURFACE_LOST_KHR) { droiddeck_log("gpu", "screen surface %s on acquire: rebuilding the swapchain", vk_result_name(ar)); destroy_swapchain(); - if (first && attempt == 0) continue; + if (first && attempt == 0 && g_dev_state == 1) continue; return -1; } droiddeck_log("error", "present: acquire %d failed (%s %d)", k, vk_result_name(ar), (int)ar); @@ -1714,6 +1969,7 @@ static void send_hdr_metadata(const struct droiddeck_color *c) { static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf, int *how) { if (how) *how = 0; + if (g_dev_state < 0) return -1; vkp_apply_window_request(); sc_layer_hide_base(); check_surface_changed(); @@ -1732,6 +1988,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i : "no HDR frames through the screen swapchain any more: rebuilding it as SDR"); destroy_swapchain(); } + if (g_dev_state != 1) return -1; g_swap_hdr_want = want_hdr; uint32_t img = 0; @@ -1815,13 +2072,11 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i int seen = 0; for (int j = 0; j < i; j++) if (draws[j].img == im) { seen = 1; break; } if (seen || !im) continue; - if (im->dmabuf) { - bars[nb++] = (VkImageMemoryBarrier){ - .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, - .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .dstQueueFamilyIndex = g_qfam, - .image = im->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; - } else if (!im->in_general) { + struct vkp_external_client_barrier_pair pair; + if (vkp_external_client_barrier_pair( + im->image, g_qfam, im->dmabuf, im->blit_dst, &pair)) { + bars[nb++] = pair.acquire; + } else if (!im->blit_dst && !im->in_general) { bars[nb++] = (VkImageMemoryBarrier){ .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED, .newLayout = VK_IMAGE_LAYOUT_GENERAL, @@ -1880,6 +2135,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i drawn++; } + if (!(pass && fx)) release_external_client_draws(cmd, draws, n); int ngen = 0; VkImage gens[VKP_FG_MAX_GENERATIONS] = {VK_NULL_HANDLE}; VkImage result = scene_img; @@ -1901,6 +2157,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h, &rw, &rh); effects_overlay_draws(cmd, result, rw, rh, scene_w, scene_h, draws ? draws + overlay_start : NULL, n - overlay_start); + release_external_client_draws(cmd, draws, n); result_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; } VkImageMemoryBarrier b_general = { @@ -1932,6 +2189,10 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i if (k > 0) { VkResult ark; if (acquire_image(k, 0, &img, &ark) != 0) { + /* Teardown may have retained this frame's pending work, or + * acquire may have reported real device loss. Neither permits + * a completion-marker submit or another fence wait. */ + if (g_dev_state != 1) return -1; droiddeck_log("framegen", "present %d/%d: no swapchain image; the frame ends early", k + 1, presents); pr = VK_ERROR_OUT_OF_DATE_KHR; break; @@ -1963,15 +2224,22 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i pr = g_vk.QueuePresentKHR(g_queue, &pi); perf_add(&g_perf.present_ns, &g_perf.present_max_ns, &g_perf.presents, perf_now() - t_pres); if (k < ngen) presented_gen++; - if (pr == VK_ERROR_OUT_OF_DATE_KHR || pr == VK_ERROR_SURFACE_LOST_KHR || pr == VK_ERROR_DEVICE_LOST) break; + if (pr == VK_ERROR_DEVICE_LOST) { device_lost("present"); return -1; } + if (pr == VK_ERROR_OUT_OF_DATE_KHR || pr == VK_ERROR_SURFACE_LOST_KHR) break; } if (!fence_submitted) { VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO}; - g_vk.QueueSubmit(g_queue, 1, &si, g_fence); + VkResult marker = g_vk.QueueSubmit(g_queue, 1, &si, g_fence); + if (marker != VK_SUCCESS) { + if (marker == VK_ERROR_DEVICE_LOST) device_lost("frame completion submit"); + else quarantine_pending_work(marker, "frame completion submit"); + return -1; /* no fence was submitted; never wait on its unsignalled state */ + } } VkResult fr = timed_wait(g_fence, UINT64_MAX); - if (fg) vkp_framegen_presented(presented_gen); if (fr == VK_ERROR_DEVICE_LOST || pr == VK_ERROR_DEVICE_LOST) { device_lost("present"); return -1; } + if (fr != VK_SUCCESS) return -1; + if (fg) vkp_framegen_presented(presented_gen); if (pr == VK_ERROR_OUT_OF_DATE_KHR || pr == VK_ERROR_SURFACE_LOST_KHR) { droiddeck_log("gpu", "screen surface %s on present: rebuilding the swapchain", vk_result_name(pr)); destroy_swapchain(); @@ -2038,6 +2306,7 @@ void vkp_reset_first_frame(void) { void vkp_signal_first_frame(void) { if (g_first_frame_done) return; g_first_frame_done = 1; + clear_fault(); droiddeck_on_first_frame(); } @@ -2051,6 +2320,7 @@ int vkp_update_map(int scene_w, int scene_h) { return g_map.valid ? 0 : -1; } check_surface_changed(); + if (g_dev_state != 1) return -1; if (!g_swapchain && swap_init() != 0) return -1; update_map(scene_w, scene_h); return g_map.valid ? 0 : -1; @@ -2073,7 +2343,7 @@ int vkp_map_draw(const struct vkp_draw *d, int out[8]) { } int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) { - if (!src || !dst || !dst->blit_dst || g_dev_state == -2 || dev_init() != 0) { + if (!src || src->blit_dst || !dst || !dst->blit_dst || g_dev_state == -2 || dev_init() != 0) { if (wait_fd >= 0) close(wait_fd); return -1; } @@ -2086,17 +2356,21 @@ int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) { VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT}; g_vk.BeginCommandBuffer(g_cmd, &bi); + struct vkp_external_client_barrier_pair src_pair; + const int src_external = vkp_external_client_barrier_pair( + src->image, g_qfam, src->dmabuf, src->blit_dst, &src_pair); VkImageMemoryBarrier acq[2] = { - {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + src_external ? src_pair.acquire : (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - .srcQueueFamilyIndex = src->dmabuf ? VK_QUEUE_FAMILY_FOREIGN_EXT : VK_QUEUE_FAMILY_IGNORED, - .dstQueueFamilyIndex = src->dmabuf ? g_qfam : VK_QUEUE_FAMILY_IGNORED, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = src->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}, {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .dstQueueFamilyIndex = g_qfam, .image = dst->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}}; - if (!src->dmabuf) { + if (!src_external) { acq[0].oldLayout = src->in_general ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_PREINITIALIZED; acq[0].newLayout = VK_IMAGE_LAYOUT_GENERAL; acq[0].srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; @@ -2110,8 +2384,9 @@ int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) { .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .dstOffsets = {{0, 0, 0}, {bw, bh, 1}}}; g_vk.CmdBlitImage(g_cmd, src->image, - src->dmabuf ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, + src_external ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, dst->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_NEAREST); + release_external_client_image(g_cmd, src); VkImageMemoryBarrier rel = { .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, .newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = g_qfam, @@ -2146,7 +2421,7 @@ int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) { static struct vkp_image *g_rb; int vkp_image_readback(struct vkp_image *src, uint32_t *out, int max_px) { - if (!src || !out || src->w <= 0 || src->h <= 0 || src->w * src->h > max_px || + if (!src || src->blit_dst || !out || src->w <= 0 || src->h <= 0 || src->w * src->h > max_px || g_dev_state == -2 || dev_init() != 0) return -1; if (g_rb && (g_rb->w != src->w || g_rb->h != src->h)) { vkp_image_destroy(g_rb); g_rb = NULL; } @@ -2187,11 +2462,15 @@ int vkp_image_readback(struct vkp_image *src, uint32_t *out, int max_px) { VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT}; g_vk.BeginCommandBuffer(cmd, &bi); + struct vkp_external_client_barrier_pair src_pair; + const int src_external = vkp_external_client_barrier_pair( + src->image, g_qfam, src->dmabuf, src->blit_dst, &src_pair); VkImageMemoryBarrier acq[2] = { - {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + src_external ? src_pair.acquire : (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - .srcQueueFamilyIndex = src->dmabuf ? VK_QUEUE_FAMILY_FOREIGN_EXT : VK_QUEUE_FAMILY_IGNORED, - .dstQueueFamilyIndex = src->dmabuf ? g_qfam : VK_QUEUE_FAMILY_IGNORED, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = src->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}, {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, .newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, @@ -2209,15 +2488,20 @@ int vkp_image_readback(struct vkp_image *src, uint32_t *out, int max_px) { {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_GENERAL, .newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = g_rb->image, .subresourceRange = range, - .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, .dstAccessMask = VK_ACCESS_HOST_READ_BIT}, - {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, .dstAccessMask = VK_ACCESS_HOST_READ_BIT}}; + uint32_t done_count = 1; + if (!src_external) { + done[done_count++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, .newLayout = VK_IMAGE_LAYOUT_GENERAL, - .srcQueueFamilyIndex = src->dmabuf ? g_qfam : VK_QUEUE_FAMILY_IGNORED, - .dstQueueFamilyIndex = src->dmabuf ? VK_QUEUE_FAMILY_FOREIGN_EXT : VK_QUEUE_FAMILY_IGNORED, - .image = src->image, .subresourceRange = range, .srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT}}; + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = src->image, .subresourceRange = range, .srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; + } g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, - 0, 0, NULL, 0, NULL, 2, done); + 0, 0, NULL, 0, NULL, done_count, done); + release_external_client_image(cmd, src); g_vk.EndCommandBuffer(cmd); VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, .pCommandBuffers = &cmd}; g_vk.ResetFences(g_dev, 1, &g_fence); @@ -2307,13 +2591,11 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw int seen = 0; for (int j = 0; j < i; j++) if (draws[j].img == im) { seen = 1; break; } if (seen || !im) continue; - if (im->dmabuf) { - bars[nb++] = (VkImageMemoryBarrier){ - .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, - .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .dstQueueFamilyIndex = g_qfam, - .image = im->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; - } else if (!im->in_general) { + struct vkp_external_client_barrier_pair pair; + if (vkp_external_client_barrier_pair( + im->image, g_qfam, im->dmabuf, im->blit_dst, &pair)) { + bars[nb++] = pair.acquire; + } else if (!im->blit_dst && !im->in_general) { bars[nb++] = (VkImageMemoryBarrier){ .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED, .newLayout = VK_IMAGE_LAYOUT_GENERAL, @@ -2358,6 +2640,7 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw &g_pass.rw, &g_pass.rh); effects_overlay_draws(cmd, g_pass.result, g_pass.rw, g_pass.rh, scene_w, scene_h, draws ? draws + overlay_start : NULL, n - overlay_start); + release_external_client_draws(cmd, draws, n); g_pass.active = 1; if (rw) *rw = g_pass.rw; if (rh) *rh = g_pass.rh; @@ -2367,8 +2650,9 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) { if (!g_pass.active) { if (wait_fd >= 0) close(wait_fd); return -1; } g_pass.active = 0; + if (g_dev_state != 1) { if (wait_fd >= 0) close(wait_fd); return -1; } VkCommandBuffer cmd = g_cmds[0]; - if (!dst || !dst->blit_dst || g_dev_state == -2) { + if (!dst || !dst->blit_dst) { if (wait_fd >= 0) close(wait_fd); g_vk.EndCommandBuffer(cmd); return -1; @@ -2420,5 +2704,6 @@ int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) { void vkp_pass_abort(void) { if (!g_pass.active) return; g_pass.active = 0; - g_vk.EndCommandBuffer(g_cmds[0]); + if (g_dev_state == 1) + g_vk.EndCommandBuffer(g_cmds[0]); } diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.h b/app/src/main/cpp/waylandcomp/src/vk_present.h index ac975c93d8..3a76b4c0b6 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.h +++ b/app/src/main/cpp/waylandcomp/src/vk_present.h @@ -3,6 +3,8 @@ #include <stdint.h> #include <stddef.h> #include <android/native_window.h> +#include <android/hardware_buffer.h> + void vk_present_set_driver(const char *driver_path, const char *library_name, const char *native_lib_dir); @@ -22,6 +24,9 @@ void vkp_output_size(int *w, int *h); struct vkp_image; +int vkp_android_buffer_supported(void); +struct vkp_image *vkp_image_from_android_buffer(AHardwareBuffer *buffer); + #define VKP_MOD_LINEAR 0x0000000000000000ULL #define VKP_MOD_QCOM_COMPRESSED 0x0500000000000001ULL #define VKP_MOD_INVALID 0x00ffffffffffffffULL @@ -61,6 +66,10 @@ int vkp_ready(void); int vkp_has_window(void); int vkp_wait_window_request(int timeout_ms); int vkp_device_lost(void); +/* Compositor thread only. Submitted reads may still be pending: retain imported + * buffer references and withhold DMA-BUF releases until the app process exits. + * This terminal state is distinct from genuine device loss. */ +int vkp_completion_unknown(void); int vkp_render(int scene_w, int scene_h, const struct vkp_draw *draws, int n); int vkp_render_plain(int scene_w, int scene_h); diff --git a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c index 5d69098a62..ffbfdfd935 100644 --- a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c +++ b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c @@ -216,6 +216,24 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeCompositorTid(JNIEnv return (jint)g_comp_tid; } +/* Why presenting failed ("" while it works), for the session-ended screen and the report. */ +JNIEXPORT jstring JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeCompositorFault(JNIEnv *env, jclass clazz) { + (void)clazz; + extern const char *vkp_fault(void); + const char *f = vkp_fault(); + return (*env)->NewStringUTF(env, f ? f : ""); +} + +/* The display driver as the driver itself reports it ("" before the compositor's device exists). */ +JNIEXPORT jstring JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeDisplayDriver(JNIEnv *env, jclass clazz) { + (void)clazz; + extern const char *vkp_display_driver(void); + const char *d = vkp_display_driver(); + return (*env)->NewStringUTF(env, d ? d : ""); +} + JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeStart(JNIEnv *env, jclass clazz, jstring xdgRuntimeDir) { diff --git a/app/src/main/cpp/waylandcomp/src/wl_android_buffer.c b/app/src/main/cpp/waylandcomp/src/wl_android_buffer.c new file mode 100644 index 0000000000..c7b436f463 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/wl_android_buffer.c @@ -0,0 +1,216 @@ +/* android_wlegl buffer import for the existing libhybris Wayland WSI. + * Protocol: Collabora/libhybris, vendored with its license in protocols/wayland-android.xml. + * Native handles are cloned through Android; opaque vendor integers are never interpreted. */ +#include "compositor_internal.h" +#include "droiddeck_ext.h" +#include "wayland-android-server-protocol.h" +#include <android/hardware_buffer.h> +#include <dlfcn.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +/* Stable native_handle_t ABI, unavailable in the public NDK. */ +struct android_native_handle { + int version, num_fds, num_ints; + int data[]; +}; +struct wire_handle { + struct android_native_handle *handle; + int received; +}; +enum { MAX_HANDLE_FDS = 64, MAX_HANDLE_INTS = 256, MAX_BUFFER_SIDE = 8192 }; +/* VNDK ABI (not exposed by the NDK): frameworks/native/libs/nativewindow/include/ + * vndk/hardware_buffer.h, AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_CLONE = 3. + * Method 1 is not accepted by AHardwareBuffer_createFromHandle. */ +enum { CREATE_FROM_HANDLE_CLONE = 3 }; +static int (*import_handle)(const AHardwareBuffer_Desc *, const struct android_native_handle *, + int32_t, AHardwareBuffer **); +static const struct android_native_handle *(*native_handle)(const AHardwareBuffer *); + +static int valid_description(int32_t width, int32_t height, int32_t stride, int32_t format) { + return width > 0 && height > 0 && width <= MAX_BUFFER_SIDE && height <= MAX_BUFFER_SIDE && + stride >= width && stride <= MAX_BUFFER_SIDE * 4 && + (format == 1 || format == 2 || format == 5); +} + +static void handle_resource_destroy(struct wl_resource *resource) { + struct wire_handle *wire = wl_resource_get_user_data(resource); + if (!wire) return; + for (int i = 0; i < wire->received; i++) close(wire->handle->data[i]); + free(wire->handle); + free(wire); +} + +static void handle_add_fd(struct wl_client *client, struct wl_resource *resource, int32_t fd) { + struct wire_handle *wire = wl_resource_get_user_data(resource); + if (wire->received >= wire->handle->num_fds) { + close(fd); + wl_resource_post_error(resource, ANDROID_WLEGL_HANDLE_ERROR_TOO_MANY_FDS, + "more native handle descriptors than declared"); + return; + } + wire->handle->data[wire->received++] = fd; +} + +static void handle_destroy(struct wl_client *client, struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static const struct android_wlegl_handle_interface handle_impl = { + .add_fd = handle_add_fd, .destroy = handle_destroy, +}; + +static void create_handle(struct wl_client *client, struct wl_resource *resource, + uint32_t id, int32_t fds, struct wl_array *ints) { + if (fds < 0 || fds > MAX_HANDLE_FDS || ints->size % sizeof(int32_t) || + ints->size > MAX_HANDLE_INTS * sizeof(int32_t)) { + wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_VALUE, "invalid native handle size"); + return; + } + struct wire_handle *wire = calloc(1, sizeof(*wire)); + if (!wire) { wl_client_post_no_memory(client); return; } + wire->handle = calloc(1, sizeof(*wire->handle) + (size_t)fds * sizeof(int32_t) + ints->size); + if (!wire->handle) { free(wire); wl_client_post_no_memory(client); return; } + wire->handle->version = sizeof(*wire->handle); + wire->handle->num_fds = fds; + wire->handle->num_ints = (int)(ints->size / sizeof(int32_t)); + if (ints->size) memcpy(wire->handle->data + fds, ints->data, ints->size); + struct wl_resource *handle = wl_resource_create(client, &android_wlegl_handle_interface, 1, id); + if (!handle) { + free(wire->handle); free(wire); wl_client_post_no_memory(client); return; + } + wl_resource_set_implementation(handle, &handle_impl, wire, handle_resource_destroy); +} + +static void buffer_resource_destroy(struct wl_resource *resource) { + dmabuf_buffer_unref(wl_resource_get_user_data(resource)); +} + +static struct wl_resource *create_android_buffer(struct wl_client *client, uint32_t id, + AHardwareBuffer *hardware) { + AHardwareBuffer_Desc desc; + AHardwareBuffer_describe(hardware, &desc); + struct vkp_image *image = vkp_image_from_android_buffer(hardware); + if (!image) return NULL; + struct dmabuf_buffer *buffer = calloc(1, sizeof(*buffer)); + if (!buffer) { vkp_image_destroy(image); wl_client_post_no_memory(client); return NULL; } + buffer->refs = 1; + buffer->width = (int32_t)desc.width; buffer->height = (int32_t)desc.height; + buffer->format = desc.format == 5 ? DRM_ARGB8888 : desc.format == 2 ? DRM_XBGR8888 : DRM_ABGR8888; + buffer->modifier = MOD_INVALID; /* No DMA-BUF layout was inferred from the native handle. */ + buffer->img = image; + for (int i = 0; i < MAX_PLANES; i++) buffer->fd[i] = -1; + struct wl_resource *result = wl_resource_create(client, &wl_buffer_interface, 1, id); + if (!result) { dmabuf_buffer_unref(buffer); wl_client_post_no_memory(client); return NULL; } + wl_resource_set_implementation(result, &dbuf_buffer_impl, buffer, buffer_resource_destroy); + struct client_info *info = client_info_of(client); + if (info) info->dmabuf_buffers++; + return result; +} + +static void create_buffer(struct wl_client *client, struct wl_resource *resource, uint32_t id, + int32_t width, int32_t height, int32_t stride, int32_t format, + int32_t usage, struct wl_resource *handle_resource) { + /* Some vendor allocators (Samsung Xclipse) record no stride for GPU-only buffers. The import + * must pass that 0 back unchanged: gralloc validates it against the handle's own value. */ + if (!valid_description(width, height, stride ? stride : width, format) || + !wl_resource_instance_of(handle_resource, &android_wlegl_handle_interface, &handle_impl)) { + droiddeck_log("display", "android_wlegl rejected: %dx%d stride=%d format=%d usage=0x%x", + width, height, stride, format, (uint32_t)usage); + wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_VALUE, "invalid Android buffer description"); + return; + } + struct wire_handle *wire = wl_resource_get_user_data(handle_resource); + if (wire->received != wire->handle->num_fds || !wire->received) { + wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_HANDLE, "incomplete native handle"); + return; + } + AHardwareBuffer_Desc desc = { + .width = (uint32_t)width, .height = (uint32_t)height, .layers = 1, + .format = (uint32_t)format, .usage = (uint32_t)usage, .stride = (uint32_t)stride}; + AHardwareBuffer *hardware = NULL; + int status = import_handle(&desc, wire->handle, CREATE_FROM_HANDLE_CLONE, &hardware); + if (status != 0 || !hardware) { + droiddeck_log("display", "android_wlegl import failed: status=%d %dx%d stride=%d format=%d usage=0x%x fds=%d ints=%d", + status, width, height, stride, format, (uint32_t)usage, + wire->handle->num_fds, wire->handle->num_ints); + wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_HANDLE, + "Android rejected the native handle (status %d)", status); + return; + } + struct wl_resource *buffer = create_android_buffer(client, id, hardware); + AHardwareBuffer_release(hardware); + if (!buffer) wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_HANDLE, "Vulkan cannot import this buffer"); +} + +static void get_server_buffer(struct wl_client *client, struct wl_resource *resource, uint32_t id, + int32_t width, int32_t height, int32_t format, int32_t usage) { + if (!format) format = 1; + if (!valid_description(width, height, width, format)) { + wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_VALUE, "invalid buffer allocation request"); + return; + } + AHardwareBuffer_Desc desc = { + .width = (uint32_t)width, .height = (uint32_t)height, .layers = 1, + .format = (uint32_t)format, + .usage = (uint32_t)usage | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT}; + AHardwareBuffer *hardware = NULL; + if (AHardwareBuffer_allocate(&desc, &hardware) != 0 || !hardware) { + wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_VALUE, "Android buffer allocation failed"); + return; + } + AHardwareBuffer_describe(hardware, &desc); + const struct android_native_handle *handle = native_handle(hardware); + if (!handle || handle->num_fds < 1 || handle->num_fds > MAX_HANDLE_FDS || + handle->num_ints < 0 || handle->num_ints > MAX_HANDLE_INTS) { + AHardwareBuffer_release(hardware); + wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_HANDLE, "invalid allocated native handle"); + return; + } + struct wl_resource *buffer = create_android_buffer(client, 0, hardware); + if (!buffer) { + AHardwareBuffer_release(hardware); + wl_resource_post_error(resource, ANDROID_WLEGL_ERROR_BAD_HANDLE, "Vulkan cannot import allocated buffer"); + return; + } + struct wl_resource *reply = wl_resource_create(client, &android_wlegl_server_buffer_handle_interface, + wl_resource_get_version(resource), id); + if (!reply) { + wl_resource_destroy(buffer); AHardwareBuffer_release(hardware); + wl_client_post_no_memory(client); return; + } + struct wl_array ints = {.size = (size_t)handle->num_ints * sizeof(int32_t), + .alloc = 0, .data = (void *)(handle->data + handle->num_fds)}; + android_wlegl_server_buffer_handle_send_buffer_ints(reply, &ints); + for (int i = 0; i < handle->num_fds; i++) + android_wlegl_server_buffer_handle_send_buffer_fd(reply, handle->data[i]); + /* No linear_layout event: Android's opaque allocation need not be linear. */ + android_wlegl_server_buffer_handle_send_buffer(reply, buffer, (int32_t)desc.format, (int32_t)desc.stride); + wl_resource_destroy(reply); + AHardwareBuffer_release(hardware); +} + +static const struct android_wlegl_interface wlegl_impl = { + .create_handle = create_handle, .create_buffer = create_buffer, + .get_server_buffer_handle = get_server_buffer, +}; + +static void bind_android_wlegl(struct wl_client *client, void *data, uint32_t version, uint32_t id) { + struct wl_resource *resource = wl_resource_create(client, &android_wlegl_interface, + version < 3 ? version : 3, id); + if (!resource) { wl_client_post_no_memory(client); return; } + wl_resource_set_implementation(resource, &wlegl_impl, NULL, NULL); +} + +void droiddeck_android_wlegl_init(struct wl_display *display) { + if (!vkp_android_buffer_supported()) return; + void *library = dlopen("libnativewindow.so", RTLD_NOW | RTLD_LOCAL); + if (!library) return; + import_handle = dlsym(library, "AHardwareBuffer_createFromHandle"); + native_handle = dlsym(library, "AHardwareBuffer_getNativeHandle"); + if (!import_handle || !native_handle) { dlclose(library); return; } + /* Keep the platform entry points valid for the compositor's lifetime. */ + if (wl_global_create(display, &android_wlegl_interface, 3, NULL, bind_android_wlegl)) + droiddeck_log("display", "android_wlegl v3: Android buffer import available"); +} diff --git a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt index 200deb55aa..5fa92865fb 100644 --- a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt +++ b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt @@ -14,10 +14,12 @@ import androidx.compose.runtime.mutableIntStateOf import com.droiddeck.launcher.gpu.AutoDriverTrial import com.droiddeck.launcher.gpu.AutoPicks import com.droiddeck.launcher.gpu.DriverBundle +import com.droiddeck.launcher.core.DeviceSupport import com.droiddeck.launcher.gpu.DriverPairs import com.droiddeck.launcher.gpu.GpuInfo import com.droiddeck.launcher.gpu.LinuxVulkanDriver import com.droiddeck.launcher.gpu.LinuxVulkanDriverManager +import com.droiddeck.launcher.gpu.SystemVulkanDriver import com.droiddeck.launcher.gpu.TurnipDriver import com.droiddeck.launcher.gpu.TurnipReleases import com.droiddeck.launcher.session.SessionService @@ -42,7 +44,8 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl var canRestoreBundled by mutableStateOf(false) private val releaseProgress = HashMap<String, Int>() var linuxSelected by mutableStateOf("") - val gpu: GpuInfo = GpuInfo.detect() + var gpu: GpuInfo = GpuInfo.detect() + private set var mode by mutableStateOf(SessionPrefs.GPU_DRIVERS_AUTO) var pairRows by mutableStateOf<List<PairRow>>(emptyList()) var pairBusy by mutableStateOf<String?>(null) @@ -65,13 +68,14 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl } fun state() = GpuDriversState( - gpuName = gpu.displayName(activity), gpuFamily = gpu.family.label(activity), soc = gpu.soc, supportText = gpu.supportText(activity, com.droiddeck.launcher.core.DeviceSupport.vkBridge(activity)), + gpuName = gpu.displayName(activity), gpuFamily = if (gpu.name.contains("Xclipse", ignoreCase = true)) gpu.family.label(gpu.name) else gpu.family.label(activity), soc = gpu.soc, supportText = gpu.supportText(activity, com.droiddeck.launcher.core.DeviceSupport.vkBridge(activity)), supported = gpu.support == GpuInfo.Support.TESTED, unsupported = gpu.support == GpuInfo.Support.UNSUPPORTED, auto = mode == SessionPrefs.GPU_DRIVERS_AUTO, pairs = pairRows, busy = pairBusy, percent = pairPercent, autoStatus = autoStatus, releaseStatus = releaseStatus.ifEmpty { activity.getString(R.string.drivers_not_checked) }, checking = releaseChecking, linuxRows = linuxRows, linuxSelected = linuxSelected, androidRows = androidRows, androidSelected = androidSelected, linuxDownloads = linuxDownloads, androidDownloads = androidDownloads, canRestoreBundled = canRestoreBundled, - activeBundle = activeBundle, + activeBundle = activeBundle, powerVr = gpu.family == GpuInfo.Family.POWERVR, + systemPowerVr = SystemVulkanDriver.usesDefault(linuxSelected), mode = uiMode, display = displaySlot(), runtime = runtimeSlot(), canRestart = !sessionRunning, checkedAt = TurnipReleases.cached(activity)?.checkedAt ?: 0L, @@ -142,7 +146,7 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl DriverRow(id, it.label, activity.getString(if (linux) R.string.drivers_bundle_sets_display else R.string.drivers_bundle_sets_runtime), true, DriverRow.BUNDLE) } 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) + if (id.isEmpty()) DriverRow("", activity.getString(if (gpu.family == GpuInfo.Family.POWERVR) R.string.gpu_system_powervr else R.string.gpu_runtime_default), activity.getString(R.string.drivers_runtime_builtin), false) else bundleRow(id, linux = true) ?: DriverRow( id, lm.getDriverName(id), listOfNotNull( @@ -177,6 +181,7 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl fun summary(): String { val active = pairRows.firstOrNull { it.active }?.name ?: activeBundle + ?: if (SystemVulkanDriver.usesDefault(linuxSelected) && androidSelected == TurnipDriver.AUTO) activity.getString(R.string.gpu_system_powervr) else null val display = displaySlot().name val base = when { uiMode == GPU_MODE_AUTO -> activity.getString(R.string.drivers_summary, activity.getString(R.string.common_auto), active ?: display) @@ -193,17 +198,28 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl val pairs = DriverPairs.from(TurnipReleases.cached(activity)) val recommended = if (QuestExperimental.isSupported()) null else recommendedKey(pairs) pairRows = pairs.map { p -> - val bundle = p.bundle?.let { installedBundle(it) } + val nad = DriverPairs.isNonAdreno(p.key) + val bundle = p.bundle?.let { if (nad) installedBundleAnyBuild(it) else installedBundle(it) } val displayId = if (p.bundle != null) bundle?.androidId else p.display?.let { TurnipReleases.installedId(activity, it, td::isInstalled) } val linuxId = if (p.bundle != null) bundle?.linuxId else p.linux?.let { TurnipReleases.installedId(activity, it, lm::isInstalled) } val mb = p.assets.sumOf { it.size } / 1_048_576.0 + val update = nad && bundle != null && p.bundle?.let { TurnipReleases.updateAvailable(activity, it) } == true + val builtOn = if (nad) p.bundle?.builtOn.orEmpty() else "" + val version = when { + !nad -> p.version + bundle != null -> bundle.version.ifEmpty { p.version } + builtOn.isNotEmpty() -> activity.getString(R.string.drivers_built_on, builtOn) + else -> p.version + } PairRow( - key = p.key, name = p.name, version = p.version, + key = p.key, name = p.name, version = version, update = if (update) builtOn.takeIf { it.isNotEmpty() }?.let { activity.getString(R.string.drivers_built_on, it) } ?: p.version else null, detail = if (!p.complete) activity.getString(R.string.drivers_half_published) else activity.getString(R.string.drivers_pair_size, mb), recommended = p.key == recommended, suits = p.suits(gpu), complete = p.complete, installed = displayId != null && linuxId != null, - active = displayId != null && linuxId != null && - SessionPrefs.androidDriver(activity) == displayId && SessionPrefs.linuxDriver(activity) == linuxId, + active = displayId != null && linuxId != null && SessionPrefs.linuxDriver(activity) == linuxId && + (SessionPrefs.androidDriver(activity) == displayId || + // A Mali pair under Auto: the display is the phone's own driver. + (gpu.family.mali && DriverPairs.isNonAdreno(p.key) && SessionPrefs.androidDriver(activity) == TurnipDriver.AUTO)), ) }.sortedByDescending { it.recommended } } @@ -237,7 +253,9 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl private fun releasesStale(): Boolean { val cached = TurnipReleases.cached(activity) return cached == null || System.currentTimeMillis() - cached.checkedAt > RELEASE_CHECK_INTERVAL_MS || - cached.assets.none { it.pair.isNotEmpty() } + cached.assets.none { it.pair.isNotEmpty() } || + // A list checked before this device's open non-Adreno drivers were offered has none of them. + (!DeviceSupport.adreno() && cached.assets.none { DriverPairs.isNonAdreno(it.pair) }) } fun ensureAuto(force: Boolean) { @@ -247,9 +265,33 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl if (force) autoStatus = activity.getString(R.string.drivers_auto_waits_for_session) return } + if (gpu.family == GpuInfo.Family.POWERVR && !SystemVulkanDriver.isXclipse()) { + // Auto owns both choices. Manual imports remain available when Manual is selected. + SessionPrefs.ensurePowerVrAutoDrivers(activity) + autoStatus = activity.getString(R.string.drivers_powervr_builtin) + refreshDrivers() + return + } + // A Mali pair set by an earlier build put its PanVK Android half on the display, which fails + // on Mali gralloc. Under Auto the display is the phone's own driver (Android's loader). + if (gpu.family.mali) { + // Builds before 0.5.0-nad1 turned the bridge on under Auto without recording it, and + // left it on for good (it wins over the pair). Under Auto that switch is taken as Auto's. + if (!SessionPrefs.maliFallbackKnown(activity)) + SessionPrefs.setMaliFallbackByAuto(activity, if (SessionPrefs.vkBridge(activity)) "bridge" else "") + // A lone imported PanVK Android driver set by hand stalls the display the same way + // ("black screen with the start-up logo"), so under Auto any imported display goes. + val display = SessionPrefs.androidDriver(activity) + if (display != TurnipDriver.AUTO) { + SessionPrefs.setAndroidDriver(activity, TurnipDriver.AUTO) + Log.i(TAG, "auto: Mali display back on the phone's own driver (was $display)") + } + } AutoDriverTrial.rollbackDue(activity)?.let { trial -> AutoDriverTrial.rollBack(activity, trial) autoStatus = activity.getString(R.string.drivers_rolled_back, trial.name) + // The drivers before the trial on a Mali are the runtime's Turnip, which finds no GPU there. + if (gpu.family.mali && maliHasNoRoute()) useMaliFallback(trial.name) refreshDrivers() return } @@ -263,6 +305,29 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl refreshDrivers() return } + if (gpu.family.mali && DriverPairs.recommendedKey(gpu, emptyList()) == null && + com.droiddeck.launcher.gpu.VulkanInfo.cachedOrNull() == null) { + releaseChecking = true + autoStatus = activity.getString(R.string.drivers_checking_latest) + Thread({ + com.droiddeck.launcher.gpu.VulkanInfo.query() + ui.post { + releaseChecking = false + gpu = GpuInfo.detect() + Log.i(TAG, "auto: Mali named by its driver: ${gpu.name} -> ${gpu.family}") + lastAutoCheck = 0L + 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) { + // No PanVK build covers this Mali (e.g. the G1 series, arch v14): the phone's own driver. + autoStatus = useMaliFallback(null) + refreshDrivers() + return + } if (DriverPairs.recommendedKey(gpu, emptyList()) == null) { autoStatus = activity.getString(R.string.drivers_none_to_set, gpu.supportText(activity, com.droiddeck.launcher.core.DeviceSupport.vkBridge(activity)).lowercase()) return @@ -284,10 +349,37 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl when { row?.active == true -> autoStatus = problem?.let { activity.getString(R.string.drivers_up_to_date_check_failed, it) } ?: activity.getString(R.string.upd_current_status) + gpu.family == GpuInfo.Family.POWERVR && (pair == null || !pair.complete) -> { + // RADV is not published right now: the Xclipse falls back to the system route. + SessionPrefs.ensurePowerVrAutoDrivers(activity) + autoStatus = activity.getString(R.string.drivers_powervr_builtin) + refreshDrivers() + } + gpu.family.mali && (pair == null || !pair.complete) && + (problem != null || TurnipReleases.cached(activity)?.failed?.contains(TurnipReleases.NON_ADRENO_LABEL) == true) -> { + // The list could not be read: nothing is known to be missing, so a working route stays. + // With no open driver, Venus or bridge the session would run the runtime's Turnip, + // which finds no GPU on a Mali, so the stand-in goes on anyway. + autoStatus = activity.getString(R.string.upd_couldnt_check, problem ?: TurnipReleases.NON_ADRENO_LABEL) + if (maliHasNoRoute()) { + useMaliFallback(null) + refreshDrivers() + } + } + gpu.family.mali && (pair == null || !pair.complete) -> { + // No open driver for this Mali published yet: the phone's own driver until it is. + autoStatus = useMaliFallback(key?.let { DriverPairs.nonAdrenoName(it) } ?: gpu.name) + refreshDrivers() + } pair == null || !pair.complete -> autoStatus = problem?.let { activity.getString(R.string.upd_couldnt_check, it) } ?: activity.getString(R.string.drivers_recommended_unpublished) - AutoDriverTrial.release(pair) in AutoDriverTrial.bad(activity) -> + AutoDriverTrial.release(pair) in AutoDriverTrial.bad(activity) -> { autoStatus = activity.getString(R.string.drivers_skipping_bad, pair.name, pair.version) + if (gpu.family.mali && maliHasNoRoute()) { + useMaliFallback(pair.name) + refreshDrivers() + } + } SessionState.running -> autoStatus = activity.getString(R.string.drivers_auto_waits_for_session) holdBack && row?.installed != true -> autoStatus = activity.getString(R.string.drivers_auto_waits_for_network, pair.name, pair.version) else -> installPair(pair, auto = true) @@ -296,6 +388,53 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl }, "gpu-driver-auto").start() } + /** + * A Mali with no open driver pair to install ([missing] names the unpublished pair, or null when + * no PanVK build covers this GPU) runs through the phone's own driver: Mali (Venus) where this + * apk carries it (Steam runs on it from the G57 to the G1 series), the Mali bridge otherwise. + * Venus needs Vulkan 1.2 from the phone's driver; the bridge raises a Vulkan 1.1 driver + * (r32p1 on the G77, G78 and G610) for gamescope itself, so there the bridge stands in. + * The Linux driver choice is left alone (it is the bridge's fallback), and Auto + * switches only its own choice off again once a pair is installed ([endMaliFallback]). + */ + private fun useMaliFallback(missing: String?): String { + val oldVulkan = com.droiddeck.launcher.session.VenusComponent.hostVulkanTooOld(activity) + val venus = oldVulkan == null && com.droiddeck.launcher.session.VenusComponent.available(activity) + if (oldVulkan != null) Log.i(TAG, "auto: Mali driver reports Vulkan $oldVulkan; Venus needs 1.2, the bridge stands in") + if (venus && !SessionPrefs.venus(activity)) { + SessionPrefs.setVenus(activity, true) + SessionPrefs.setMaliFallbackByAuto(activity, "venus") + } else if (!venus && !SessionPrefs.vkBridge(activity)) { + SessionPrefs.setVkBridge(activity, true) + SessionPrefs.setMaliFallbackByAuto(activity, "bridge") + } + val route = activity.getString(if (venus) R.string.drivers_route_venus else R.string.drivers_route_bridge) + Log.i(TAG, "auto: Mali stand-in route $route (missing pair: ${missing ?: "none covers ${gpu.name}"})") + if (oldVulkan != null) return activity.getString(R.string.drivers_mali_old_vulkan_bridge, missing ?: gpu.name, oldVulkan) + return if (missing == null) activity.getString(R.string.drivers_mali_no_pair_auto, route) + else activity.getString(R.string.drivers_mali_unpublished_auto, missing, route) + } + + /** Neither an installed open Linux driver nor Venus or the bridge: the runtime's Turnip would run. */ + private fun maliHasNoRoute(): Boolean { + if (SessionPrefs.vkBridge(activity)) return false + // Venus on a Vulkan 1.1 driver does not start (VenusComponent.wanted), so it is no route. + if (SessionPrefs.venus(activity) && com.droiddeck.launcher.session.VenusComponent.hostVulkanTooOld(activity) == null) return false + val linux = SessionPrefs.linuxDriver(activity) + return linux.isEmpty() || !LinuxVulkanDriverManager(activity).isInstalled(linux) + } + + /** A pair is installed for this Mali: the route Auto switched on in its place goes off again. */ + private fun endMaliFallback() { + when (SessionPrefs.maliFallbackByAuto(activity)) { + "venus" -> SessionPrefs.setVenus(activity, false) + "bridge" -> SessionPrefs.setVkBridge(activity, false) + else -> return + } + Log.i(TAG, "auto: pair installed; ${SessionPrefs.maliFallbackByAuto(activity)} (Auto's stand-in) off") + SessionPrefs.setMaliFallbackByAuto(activity, "") + } + fun selectPair(key: String) { if (pairBusy != null) return val pair = DriverPairs.from(TurnipReleases.cached(activity)).firstOrNull { it.key == key && it.complete } ?: return @@ -304,7 +443,15 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl installPair(pair, auto = false) } - private fun installPair(pair: DriverPairs.DriverPair, auto: Boolean) { + /** A newer build of an installed open non-Adreno pair: replaced in place, still selected if it was. */ + fun updatePair(key: String) { + if (pairBusy != null) return + val pair = DriverPairs.from(TurnipReleases.cached(activity)).firstOrNull { it.key == key && it.complete } ?: return + val wasActive = pairRows.firstOrNull { it.key == key }?.active == true + installPair(pair, auto = wasActive && mode == SessionPrefs.GPU_DRIVERS_AUTO, force = true, select = wasActive) + } + + private fun installPair(pair: DriverPairs.DriverPair, auto: Boolean, force: Boolean = false, select: Boolean = true) { if (!pair.complete) return pairBusy = pair.key pairPercent = 0 @@ -314,7 +461,7 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl val result = runCatching { val zips = pair.assets val ids = zips.mapIndexed { i, asset -> - installedIdOf(asset) + (if (force) null else installedIdOf(asset)) ?: installAsset(asset) { pct -> ui.post { pairPercent = (i * 100 + pct) / zips.size } }.also { downloaded = true } } if (pair.bundle != null) DriverBundle.get(activity, ids[0])!!.let { listOf(it.androidId, it.linuxId) } else ids @@ -322,23 +469,39 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl ui.post { pairBusy = null pairPercent = -1 - result.onSuccess { (displayId, linuxId) -> + result.onSuccess { (pairDisplayId, linuxId) -> + if (!select) { + android.widget.Toast.makeText(activity, activity.getString(R.string.drivers_pair_updated, pair.name), android.widget.Toast.LENGTH_LONG).show() + return@onSuccess + } if (auto && SessionState.running) { lastAutoCheck = 0L autoStatus = activity.getString(R.string.drivers_auto_waits_for_session) return@onSuccess } + // A Mali pair under Auto: the compositor draws on the phone's own Mali driver + // (dma-buf, modifiers and AHB all work there) and the guest runs the pair's + // PanVK. Its Android half stays installed for a manual pick. + // The same when the pair is picked by hand: a PanVK Android half on the display + // stalls Mali gralloc ("Waiting for Steam's first frame"); it stays a manual pick + // under "Runtime and display drivers separately". + val displayId = if (gpu.family.mali && DriverPairs.isNonAdreno(pair.key)) TurnipDriver.AUTO else pairDisplayId val previousDisplay = SessionPrefs.androidDriver(activity) val previousLinux = SessionPrefs.linuxDriver(activity) val displayChanged = previousDisplay != displayId SessionPrefs.setAndroidDriver(activity, displayId) SessionPrefs.setLinuxDriver(activity, linuxId) + // A route Auto switched on in place of a missing pair goes off now that one is + // here. A Mali bridge or Venus switch the user set stays: it wins for the session + // (DeviceSupport.vkBridge, VenusComponent.wanted) and the pair waits. + if (gpu.family.mali && DriverPairs.isNonAdreno(pair.key)) endMaliFallback() val restart = displayChanged && CompositorHost.isStarted if (auto) { val trial = AutoDriverTrial.current(activity) val lastGood = trial?.let { setOf(it.previousDisplay, it.previousLinux) } ?: setOf(previousDisplay, previousLinux) val changed = previousDisplay != displayId || previousLinux != linuxId - SessionPrefs.setGpuAutoInstalled(activity, SessionPrefs.gpuAutoInstalled(activity) + setOf(displayId, linuxId)) + // A Mali pair's display is the phone's own driver (AUTO): not a download to own or prune. + SessionPrefs.setGpuAutoInstalled(activity, SessionPrefs.gpuAutoInstalled(activity) + setOf(displayId, linuxId).filter { it.isNotEmpty() && it != TurnipDriver.AUTO }) if (changed) AutoDriverTrial.begin( activity, AutoDriverTrial.release(pair), "${pair.name} ${pair.version}", displayId, linuxId, trial?.previousDisplay ?: previousDisplay, trial?.previousLinux ?: previousLinux, @@ -366,6 +529,9 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl private fun installedBundle(asset: TurnipReleases.Asset): DriverBundle.Bundle? = TurnipReleases.installedId(activity, asset) { DriverBundle.get(activity, it) != null }?.let { DriverBundle.get(activity, it) } + private fun installedBundleAnyBuild(asset: TurnipReleases.Asset): DriverBundle.Bundle? = + TurnipReleases.installedIdAnyBuild(activity, asset) { DriverBundle.get(activity, it) != null }?.let { DriverBundle.get(activity, it) } + private fun installedIdOf(asset: TurnipReleases.Asset): String? = when { asset.bundle -> installedBundle(asset)?.id asset.linux -> TurnipReleases.installedId(activity, asset, LinuxVulkanDriverManager(activity)::isInstalled) diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index eee09c03bc..919d02cabd 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -164,6 +164,8 @@ class FrontEndActivity : ComponentActivity() { private var tuSysmem by mutableStateOf(false) private var zinkLazy by mutableStateOf(false) private var vkBridge by mutableStateOf(false) + private var venus by mutableStateOf(false) + private var venusHostVulkan by mutableStateOf<String?>(null) private var vkBridgeSafe by mutableStateOf(true) private var bridgeProtonDxvk by mutableStateOf(false) private val adrenoGpu by lazy { com.droiddeck.launcher.core.DeviceSupport.adreno() } @@ -582,6 +584,10 @@ class FrontEndActivity : ComponentActivity() { private var gameDebugLogsNeedsRestart by mutableStateOf(false) private var vacDiagnostics by mutableStateOf(false) private var agentCommands by mutableStateOf(false) + private var graphicsLogs by mutableStateOf(false) + private var steamGpuDrawing by mutableStateOf(false) + private var bridgeFellBack by mutableStateOf(false) + private var bridgeFellBackMemory by mutableStateOf(false) private var clearCachedApps by mutableStateOf(false) private var adbPaired by mutableStateOf(false) private var memoryHud by mutableStateOf(SessionPrefs.MEMORY_HUD_OFF) @@ -1129,7 +1135,7 @@ class FrontEndActivity : ComponentActivity() { FrontEndScreen( FrontEndState( installed = installed, ready = ready, available = available?.version, removalPending = removalPending, runtimeActionsBlocked = runtimeChangesBlocked(), - vkBridge = vkBridge, vkBridgeSafe = vkBridgeSafe, bridgeProtonDxvk = bridgeProtonDxvk, adreno = adrenoGpu, + vkBridge = vkBridge, venus = venus, venusHostVulkan = venusHostVulkan, vkBridgeSafe = vkBridgeSafe, bridgeProtonDxvk = bridgeProtonDxvk, adreno = adrenoGpu, shortcutPicker = shortcutPicker, shortcutLibraryScanning = shortcutLibraryScanning, gameSyncFolder = gameSyncFolder, @@ -1140,6 +1146,7 @@ class FrontEndActivity : ComponentActivity() { enhancedDiagnosticsArmed = enhancedDiagnosticsArmed, gameDebugLogsEnabled = gameDebugLogsEnabled, gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart, vacDiagnostics = vacDiagnostics, agentCommands = agentCommands, + graphicsLogs = graphicsLogs, steamGpuDrawing = steamGpuDrawing, bridgeFellBack = bridgeFellBack, bridgeFellBackMemory = bridgeFellBackMemory, clearCachedApps = clearCachedApps, adbPaired = adbPaired, memoryHud = memoryHud, backgroundAppLimit = backgroundAppLimit, steamGames = steamGames, steamGamesX64 = steamGamesX64, emulators = emulatorList, running = runningLabel, frameGen = FrameGen.mode(this), @@ -1285,9 +1292,18 @@ class FrontEndActivity : ComponentActivity() { onRemovePackage = { id -> removePackage(id) }, onRuntime = { onRuntimeButton() }, onVkBridge = { on -> - SessionPrefs.setVkBridge(this, on); vkBridge = on + SessionPrefs.setVkBridge(this, on); SessionPrefs.setMaliFallbackByAuto(this, ""); vkBridge = on if (!on) com.droiddeck.launcher.session.ComponentsManager.settleAutoDxvk(this) }, + onVenus = { on -> + SessionPrefs.setVenus(this, on) + SessionPrefs.setMaliFallbackByAuto(this, "") + venus = on + if (on && !com.droiddeck.launcher.core.DeviceSupport.adreno()) Thread({ + com.droiddeck.launcher.gpu.VulkanInfo.query()["api"]?.let { SessionPrefs.setHostVulkanApi(this, it) } + runOnUiThread { venusHostVulkan = com.droiddeck.launcher.session.VenusComponent.hostVulkanTooOld(this) } + }, "venus-host-vulkan").start() + }, onVkBridgeSafe = { on -> SessionPrefs.setVkBridgeSafe(this, on); vkBridgeSafe = on }, onBridgeProtonDxvk = { on -> SessionPrefs.setBridgeProtonDxvk(this, on); bridgeProtonDxvk = on @@ -1346,6 +1362,14 @@ class FrontEndActivity : ComponentActivity() { gameDebugLogsEnabled = SessionPrefs.gameDebugLogsEnabled(this) gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart() }, + onSteamGpuDrawing = { + SessionPrefs.setSteamGpuCompositing(this, !SessionPrefs.steamGpuCompositing(this)) + steamGpuDrawing = SessionPrefs.steamGpuCompositing(this) + }, + onGraphicsLogs = { + SessionPrefs.setDetailedGraphicsLogs(this, !SessionPrefs.detailedGraphicsLogs(this)) + graphicsLogs = SessionPrefs.detailedGraphicsLogs(this) + }, onVacDiagnostics = { SessionPrefs.setVacDiagnostics(this, !SessionPrefs.vacDiagnostics(this)) vacDiagnostics = SessionPrefs.vacDiagnostics(this) @@ -1684,6 +1708,9 @@ class FrontEndActivity : ComponentActivity() { com.droiddeck.launcher.frontend.GamesFolderMigration.run(this) SessionLogShare.clear(this) SessionArtifacts.finishAbandoned(this) + if (SessionPrefs.takeMemoryKillNotice(this)) runOnUiThread { + android.widget.Toast.makeText(this, R.string.session_killed_for_memory, android.widget.Toast.LENGTH_LONG).show() + } SessionArtifacts.scrubOlder(this) SessionArtifacts.prune(this) }, "finish-abandoned").start() @@ -2137,6 +2164,7 @@ class FrontEndActivity : ComponentActivity() { gpuActions = com.droiddeck.launcher.ui.GpuDriversActions( onAuto = { on -> drivers.setMode(on) }, onPair = { key -> drivers.selectPair(key) }, + onPairUpdate = { key -> drivers.updatePair(key) }, onRefresh = { if (drivers.mode == SessionPrefs.GPU_DRIVERS_AUTO) drivers.ensureAuto(force = true) else drivers.checkLatestTurnip() }, onSelectLinux = { id -> drivers.selectDriver(id, linux = true) }, onSelectAndroid = { id -> drivers.selectDriver(id, linux = false) }, @@ -2687,6 +2715,8 @@ class FrontEndActivity : ComponentActivity() { tuSysmem = SessionPrefs.tuSysmem(this) zinkLazy = SessionPrefs.zinkLazy(this) vkBridge = SessionPrefs.vkBridge(this) + venus = SessionPrefs.venus(this) + venusHostVulkan = com.droiddeck.launcher.session.VenusComponent.hostVulkanTooOld(this) vkBridgeSafe = SessionPrefs.vkBridgeSafe(this) bridgeProtonDxvk = SessionPrefs.bridgeProtonDxvk(this) noXalia = SessionPrefs.noXalia(this) @@ -2764,6 +2794,10 @@ class FrontEndActivity : ComponentActivity() { gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart() vacDiagnostics = SessionPrefs.vacDiagnostics(this) agentCommands = com.droiddeck.launcher.agent.AgentAccess.commandsEnabled(this) + graphicsLogs = SessionPrefs.detailedGraphicsLogs(this) + steamGpuDrawing = SessionPrefs.steamGpuCompositing(this) + bridgeFellBack = SessionPrefs.bridgeFellBack(this) + bridgeFellBackMemory = SessionPrefs.bridgeFellBackForMemory(this) clearCachedApps = SessionPrefs.clearCachedApps(this) adbPaired = WirelessAdbFix.hasSavedPairing(this) memoryHud = SessionPrefs.memoryHud(this) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index f8e11d2891..2363b8beb5 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -1214,6 +1214,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { SessionDrawer(drawerOpen || (docked && drawerPinned), drawerPage, drawerControllerActive, onPageChange = { drawerPage = it }, docked = docked, backRequest = drawerBackRequests, onLayerChange = { drawerLayerOpen = it }, a = DrawerActions( steam = SessionState.mode == SessionService.MODE_STEAM, + systemPowerVr = com.droiddeck.launcher.gpu.SystemVulkanDriver.usesDefault( + SessionPrefs.linuxDriver(this@SessionActivity)), direct = noSteamSession(), title = if (SessionState.mode == SessionService.MODE_RUN) com.droiddeck.launcher.frontend.Library.nameForProgram(SessionState.program) ?: getString(R.string.session_title_game) else null, @@ -2476,10 +2478,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { closeSecondScreen(reset = true) updateGlassesScreen() updateHeadTracker() - if (status == 0) { + Thread({ + val hint = sessionExitHint(status) runOnUiThread { if (isFinishing || isDestroyed) return@runOnUiThread - SessionState.relaunch?.let { next -> + if (status == 0) SessionState.relaunch?.let { next -> SessionState.relaunch = null next.putExtra(EXTRA_RETURN_HOME, intent.getBooleanExtra(EXTRA_RETURN_HOME, false)) next.putExtra(EXTRA_LINK_TASK, intent.getIntExtra(EXTRA_LINK_TASK, -1)) @@ -2487,14 +2490,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { recreate() return@runOnUiThread } - finish() - } - return - } - Thread({ - val hint = runtimeDamageHint() ?: sessionEndHint(SessionState.logFile) ?: prootFailureHint() - runOnUiThread { - if (isFinishing || isDestroyed) return@runOnUiThread showEnded(status, hint) } }, "session-end-hint").start() @@ -2557,13 +2552,44 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { return EndHint(resources.getQuantityString(R.plurals.session_end_runtime_damaged, broken.size, broken.size, broken.first()), repair = true) } + private fun presentationFault(): String? { + runCatching { com.droiddeck.launcher.wayland.WaylandCompositor.compositorFault() }.getOrNull() + ?.takeIf { it.isNotEmpty() }?.let { return it } + val waylandLog = SessionState.logDirectory?.let { File(it, "wayland.log") }?.takeIf { it.isFile } ?: return null + return try { + java.io.RandomAccessFile(waylandLog, "r").use { f -> + val start = maxOf(0L, waylandLog.length() - 256L * 1024) + f.seek(start) + val bytes = ByteArray((waylandLog.length() - start).toInt()) + f.readFully(bytes) + var fault: String? = null + String(bytes, Charsets.ISO_8859_1).lineSequence().forEach { line -> + val i = line.indexOf("DD_PRESENT_FAULT: ") + if (i >= 0) fault = line.substring(i + 18).trim().ifEmpty { null } + else if (line.contains("presentation recovered: fault cleared")) fault = null + } + fault + } + } catch (_: Exception) { + null + } + } + private fun prootFailureHint(): EndHint? { if (SessionState.failureCode != "PROOT_MISSING") return null val message = SessionState.failureMessage ?: return null return EndHint(message) } + private fun presentationFaultHint(): EndHint? = presentationFault()?.let { + EndHint(getString(R.string.session_end_present_fault, it), evenOnSuccess = true) + } + + private fun sessionExitHint(status: Int): EndHint? = if (status == 0) presentationFaultHint() + else runtimeDamageHint() ?: sessionEndHint(SessionState.logFile) ?: prootFailureHint() + private fun sessionEndHint(log: File?): EndHint? { + presentationFaultHint()?.let { return it } if (log == null || !log.isFile) return null return try { var enosys = 0 @@ -2590,8 +2616,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { val fallback = if (SessionState.steamClientArch == "arm64") getString(R.string.session_end_steam_try_x64) else null EndHint(listOfNotNull(message, fallback).joinToString("\n")) } else if (launchFailure == com.droiddeck.launcher.session.SessionLaunchFailure.VULKAN_DEVICE_MISSING) { - val adreno = com.droiddeck.launcher.gpu.GpuInfo.detect().family != com.droiddeck.launcher.gpu.GpuInfo.Family.NOT_ADRENO - EndHint(getString(if (adreno) R.string.session_end_vulkan_device else R.string.session_end_gpu_unsupported)) + val gpu = com.droiddeck.launcher.gpu.GpuInfo.detect() + val family = gpu.family + val adreno = family != com.droiddeck.launcher.gpu.GpuInfo.Family.NOT_ADRENO && + family != com.droiddeck.launcher.gpu.GpuInfo.Family.POWERVR && !family.mali + val message = getString(R.string.session_end_vulkan_device) + EndHint(if (adreno) message else "${gpu.name} (${family.label(gpu.name)})\n$message") } else if (fexMissing) { val what = com.droiddeck.launcher.frontend.Library.nameForProgram(SessionState.program) ?: getString(R.string.session_end_program) EndHint(getString(R.string.session_end_fex_missing, what), evenOnSuccess = true) diff --git a/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java b/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java index 32d5f5189e..08c463dfdc 100644 --- a/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java +++ b/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java @@ -130,22 +130,46 @@ public class PulseAudioComponent extends SessionPart { private void ensureClientSink(java.io.PrintWriter out) { try { - long deadline = System.currentTimeMillis() + 15000L; + // Nothing that may block (a sink whose AAudio open hangs: a Galaxy S24 FE (US) hung the + // daemon's start-up loading one from default.pa) is loaded by the daemon itself; the + // fallbacks are loaded here, after it is up, each pactl call bounded by its timeout. + long started = System.currentTimeMillis(); + long deadline = started + 30000L; String sinks = null; + boolean socketSeen = false; while (System.currentTimeMillis() < deadline && pid > 1) { - if (socket().exists() && (sinks = pactl("list", "short", "sinks")) != null) break; + socketSeen |= socket().exists(); + if (socketSeen && (sinks = pactl("list", "short", "sinks")) != null) break; try { Thread.sleep(250L); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } } + note(out, "client sink: daemon " + (sinks != null ? "answered" : "did not answer") + " after " + + (System.currentTimeMillis() - started) + " ms (socket " + (socketSeen ? "present" : "never appeared") + ", pactl " + + (new File(workingDir, "pactl").isFile() ? "present" : "MISSING") + ", daemon pid " + pid + ")"); String line; if (sinks == null) { - line = "== client sink: the daemon did not answer in 15 s; no fallback attempted"; + line = "== client sink: the daemon did not answer in 30 s; no fallback attempted"; } else if (sinks.contains("\tDirectAudio\t") || sinks.startsWith("DirectAudio\t") || sinks.contains("\tDirectAudio\n") || sinks.matches("(?s).*\\bDirectAudio\\b.*")) { line = "== client sink: DirectAudio (module-directaudio-native-sink)"; } else { - boolean loaded = pactl("load-module", "module-aaudio-sink", "sink_name=AAudioSink", "performance_mode=1", "adaptive=1", "volume=1.0", "control_dir=" + deviceControls) != null - && pactl("set-default-sink", "AAudioSink") != null; - line = loaded ? "== client sink: DirectAudio did not come up; FALLBACK to the plain AAudio sink (AAudioSink)" - : "== client sink: DirectAudio did not come up and the AAudio fallback failed too - no client sound"; + // AAudio can refuse the first open with AAUDIO_ERROR_DISCONNECTED while Android is + // still switching the output route as the session starts (seen on a Galaxy S24 FE): + // try DirectAudio again, then the plain sink, a few times over ten seconds. + String loadedAs = null; + for (int attempt = 1; attempt <= 5 && loadedAs == null && pid > 1; attempt++) { + try { Thread.sleep(2000L); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } + if (pactl("load-module", "module-directaudio-native-sink", "sink_name=DirectAudio", "performance_mode=1", + "adaptive=1", "decay=0", "limiter=1", "watchdog=1", "volume=1.0", "control_dir=" + deviceControls) != null + && pactl("set-default-sink", "DirectAudio") != null) { + loadedAs = "DirectAudio on attempt " + attempt; + } else if (pactl("load-module", "module-aaudio-sink", "sink_name=AAudioSink", + "performance_mode=" + (attempt == 1 ? "1" : "0"), "adaptive=1", "volume=1.0", "control_dir=" + deviceControls) != null + && pactl("set-default-sink", "AAudioSink") != null) { + loadedAs = "the plain AAudio sink (AAudioSink) on attempt " + attempt; + } + } + line = loadedAs != null ? "== client sink: DirectAudio did not come up at start; retried and got " + loadedAs + : "== client sink: DirectAudio did not come up and the AAudio fallback failed too after 5 retries - no client sound." + + " If audio.log shows AAUDIO_ERROR_DISCONNECTED, Android refused the audio output: rebooting the phone usually fixes this"; Log.w(TAG, line); } Log.i(TAG, line); @@ -155,6 +179,14 @@ public class PulseAudioComponent extends SessionPart { } } + /** A timestamped line in the session's audio log. */ + private void note(java.io.PrintWriter out, String what) { + String line = "== " + new java.text.SimpleDateFormat("HH:mm:ss.SSS", java.util.Locale.US).format(new java.util.Date()) + " " + what; + Log.i(TAG, line); + if (out != null) synchronized (out) { out.println(line); out.flush(); } + } + + /** Runs pactl against this daemon; its stdout, or null when it failed or timed out. */ private String pactl(String... args) { File pactl = new File(workingDir, "pactl"); if (!pactl.isFile() || pid <= 1) return null; diff --git a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt index 309716d3fc..cb0b9487b8 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt @@ -10,6 +10,8 @@ import android.os.PowerManager import android.os.StatFs import android.provider.Settings import android.util.Log +import com.droiddeck.launcher.gpu.DeviceInfo +import com.droiddeck.launcher.gpu.SystemVulkanDriver import android.view.Display import com.droiddeck.launcher.gpu.LinuxVulkanDriver import com.droiddeck.launcher.gpu.LinuxVulkanDriverManager @@ -110,6 +112,7 @@ object DeviceReport { runCatching { val info = context.packageManager.getPackageInfo(context.packageName, 0) k("Version", "${info.versionName} (${info.longVersionCode})") + k("App build", "${com.droiddeck.launcher.BuildConfig.BUILD_LABEL} (source ${com.droiddeck.launcher.BuildConfig.SOURCE_COMMIT})") } k("Package", context.packageName) k("targetSdk", context.applicationInfo.targetSdkVersion) @@ -186,7 +189,11 @@ object DeviceReport { h("GPU") k("KGSL gpu_model", readSys("/sys/class/kgsl/kgsl-3d0/gpu_model")) k("KGSL chip id", readSys("/sys/class/kgsl/kgsl-3d0/gpu_chipid")) - k("System Vulkan ICD", if (File("/vendor/lib64/hw/vulkan.adreno.so").exists()) "/vendor/lib64/hw/vulkan.adreno.so" else "not at the usual path") + k("System Vulkan ICD", when { + SystemVulkanDriver.isPowerVr() -> SystemVulkanDriver.hal() + File("/vendor/lib64/hw/vulkan.adreno.so").exists() -> "/vendor/lib64/hw/vulkan.adreno.so" + else -> "not at the usual path" + }) h("Display") k("Session output", SessionState.outputSize?.let { "${it.first}x${it.second}" }) @@ -208,7 +215,7 @@ object DeviceReport { h("Drivers") val gpu = com.droiddeck.launcher.gpu.GpuInfo.detect() - k("GPU", "${gpu.name} · ${gpu.family.label} · ${gpu.supportText(SessionPrefs.vkBridge(context))}" + if (gpu.oneUi8Gen2) " · One UI 8 Gen 2" else "") + k("GPU", "${gpu.name} · ${gpu.family.label(gpu.name)} · ${gpu.supportText(SessionPrefs.vkBridge(context))}" + if (gpu.oneUi8Gen2) " · One UI 8 Gen 2" else "") if (gpu.model == 740) { val hint = com.droiddeck.launcher.gpu.TpUbwcHint k("TP UBWC hint", hint.forThisDevice(context) ?: "driver default") @@ -221,19 +228,25 @@ object DeviceReport { com.droiddeck.launcher.gpu.AutoDriverTrial.bad(context))?.let { " (recommended pair: $it)" } ?: "")) val turnip = TurnipDriver(context) val androidChoice = SessionPrefs.androidDriver(context) - k("Display driver (chosen)", if (androidChoice.isEmpty()) "Auto -> ${turnip.autoId()}" else androidChoice) - k(" name / version", "${turnip.displayName(if (androidChoice.isEmpty()) turnip.autoId() else androidChoice)} ${turnip.driverVersion(if (androidChoice.isEmpty()) turnip.autoId() else androidChoice)}".trim()) + val displayId = androidChoice.ifEmpty { turnip.autoId() } + val displayLabel = if (displayId == "system") DeviceInfo.builtinDriverLabel(SystemVulkanDriver.isPowerVr(), runtime = false) + else "${turnip.displayName(displayId)} ${turnip.driverVersion(displayId)}".trim() + k("Display driver (chosen)", if (androidChoice.isEmpty()) "Auto -> $displayLabel" else androidChoice) + k(" name / version", displayLabel) k(" imported available", turnip.enumerateImported().ifEmpty { listOf("none") }.joinToString(", ")) 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.isEmpty()) DeviceInfo.builtinDriverLabel(SystemVulkanDriver.isPowerVr(), runtime = true) 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]" + 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) } k("Runtime's own ICD", LinuxRuntime.vulkanIcd(context)?.path) + k("Mali (Venus)", if (com.droiddeck.launcher.session.VenusComponent.wanted(context)) "in use" + else if (com.droiddeck.launcher.session.VenusComponent.available(context)) "available, off" else "not in this build") h("Runtime") k("Installed version", LinuxRuntimeInstaller.installedVersion(context)) diff --git a/app/src/main/java/com/droiddeck/launcher/core/DeviceSupport.kt b/app/src/main/java/com/droiddeck/launcher/core/DeviceSupport.kt index ee214fedfe..c847dbcdfc 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/DeviceSupport.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/DeviceSupport.kt @@ -3,6 +3,7 @@ package com.droiddeck.launcher.core import android.content.Context import android.os.Build import com.droiddeck.launcher.R +import com.droiddeck.launcher.gpu.SystemVulkanDriver import java.io.File object DeviceSupport { @@ -10,16 +11,35 @@ object DeviceSupport { File("/sys/class/kgsl/kgsl-3d0").exists() || File("/vendor/lib64/hw/vulkan.adreno.so").exists() } - private val maliGpu by lazy { !adrenoGpu && File("/dev/mali0").exists() } - fun adreno(): Boolean = adrenoGpu - fun mali(): Boolean = maliGpu + fun graphicsAvailable(): Boolean = graphicsAvailable(adreno(), SystemVulkanDriver.isAvailable()) + + internal fun graphicsAvailable(adreno: Boolean, powerVrReady: Boolean): Boolean = adreno || powerVrReady fun vkBridge(context: Context): Boolean = - !adreno() && com.droiddeck.launcher.session.SessionPrefs.vkBridge(context) + bridgeUsable() && !com.droiddeck.launcher.session.VenusComponent.wanted(context) && + com.droiddeck.launcher.session.SessionPrefs.vkBridge(context) - fun canDraw(context: Context): Boolean = adreno() || vkBridge(context) + fun mali(): Boolean = isMali + + private val isMali by lazy { + !adreno() && (File("/dev/mali0").exists() || + com.droiddeck.launcher.gpu.GpuInfo.detect().family.name.startsWith("MALI")) + } + + fun bridgeUsable(): Boolean = !adreno() && !SystemVulkanDriver.isAvailable() && File("/dev/mali0").exists() + + fun openDriverActive(context: Context): Boolean { + if (adreno()) return false + if (com.droiddeck.launcher.session.VenusComponent.wanted(context)) return false + if (bridgeUsable() && com.droiddeck.launcher.session.SessionPrefs.vkBridge(context)) return false + val linux = com.droiddeck.launcher.session.SessionPrefs.linuxDriver(context).ifEmpty { return false } + return com.droiddeck.launcher.gpu.DriverPairs.isNonAdreno(com.droiddeck.launcher.gpu.DriverBundle.containing(context, linux, true)?.id) + } + + fun canDraw(context: Context): Boolean = graphicsAvailable() || openDriverActive(context) || vkBridge(context) || + com.droiddeck.launcher.session.VenusComponent.wanted(context) fun gpuName(context: Context): String { val soc = if (Build.VERSION.SDK_INT >= 31) Build.SOC_MODEL.takeIf { it.isNotBlank() && it != Build.UNKNOWN } else null diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/SteamRedists.kt b/app/src/main/java/com/droiddeck/launcher/frontend/SteamRedists.kt index a287c2299e..17a2e8b6c8 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/SteamRedists.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/SteamRedists.kt @@ -14,6 +14,8 @@ object SteamRedists { "228988" to ("vcredist2019_dll" to "VC++ 2019"), "228989" to ("vcredist2022_dll" to "VC++ 2022"), "228990" to ("d3dx9" to "DirectX (June 2010)"), + // OpenAL 2.0.7.0 (Hotline Miami lists it; without it HotlineGL.exe fails to load, c0000135). + "229020" to ("oalinst_dll" to "OpenAL"), ) val SCRIPTED = mapOf( 72850 to listOf("xact" to "DirectX XACT audio"), diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/DeviceInfo.kt b/app/src/main/java/com/droiddeck/launcher/gpu/DeviceInfo.kt index 2d9aab9020..148555c5c3 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/DeviceInfo.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/DeviceInfo.kt @@ -53,7 +53,7 @@ object DeviceInfo { private fun gpu(context: Context, gpu: GpuInfo) = Section("GPU", buildList<Pair<String, String>> { add("GPU", gpu.name) - add("Family", gpu.family.label) + add("Family", gpu.family.label(gpu.name)) add("Model found from", when (gpu.modelSource) { "kernel" -> "the kernel's GPU name" "vulkan" -> "the Vulkan driver (the kernel's name has no model)" @@ -146,10 +146,20 @@ object DeviceInfo { add("Driver mode", SessionPrefs.gpuDriverMode(context)) val turnip = TurnipDriver(context) val choice = SessionPrefs.androidDriver(context).ifEmpty { turnip.autoId() } - add("Display driver", "${turnip.displayName(choice)} ${turnip.driverVersion(choice)}".trim()) + 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()) "the runtime's own Turnip" else "${linux.getDriverName(id)} ${linux.getDriverVersion(id)}".trim()) + add("Game driver", 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") }) + + /** 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" + runtime -> "the runtime's own Turnip" + else -> "System Vulkan" + } + } 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 db8dc86c4b..594dbebb27 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt @@ -75,8 +75,8 @@ object DriverBundle { val linuxStage = lm.newStagingDir() val linuxId = try { - val library = linuxDir.listFiles()?.firstOrNull { it.isFile && it.name.startsWith("libvulkan_freedreno") && it.name.endsWith(".so") } - library?.copyTo(File(linuxStage, LinuxVulkanDriverManager.LIB_NAME)) + val library = linuxDir.listFiles()?.firstOrNull { it.isFile && LinuxVulkanDriverManager.isDriverLibrary(it.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) @@ -86,6 +86,10 @@ object DriverBundle { } val base = LinuxVulkanDriverManager.sanitizeId(manifest.tag.ifEmpty { "${manifest.name}-${manifest.version}" }) + get(context, base)?.takeIf { DriverPairs.isNonAdreno(it.id) }?.let { old -> + Log.i(TAG, "replacing bundle ${old.id} (display ${old.androidId}, runtime ${old.linuxId})") + remove(context, old) + } val saved = registry(context) var id = base var n = 2 diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/DriverPairs.kt b/app/src/main/java/com/droiddeck/launcher/gpu/DriverPairs.kt index c99bfb5f10..367a747b3c 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/DriverPairs.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/DriverPairs.kt @@ -12,6 +12,47 @@ object DriverPairs { const val DD_TURNIP = "dd-turnip" fun ddTurnip(tag: String) = "$DD_TURNIP:$tag" + /** The open non-Adreno drivers (The412Banner/droiddeck-nonadreno-drivers), one pair per driver. */ + const val NON_ADRENO = "nad" + const val NAD_RADV_XCLIPSE = "nad:radv-xclipse" + /** RADV-Xclipse rebased on JimVulkan's upstream: a manual choice, never Auto. */ + const val NAD_RADV_XCLIPSE_UPSTREAM = "nad:radv-xclipse-upstream" + const val NAD_MALI_JM = "nad:panvk-mali-jm" + const val NAD_MALI_G710 = "nad:panvk-mali-g710" + const val NAD_MALI_G615 = "nad:panvk-mali-g615" + const val NAD_MALI_G720 = "nad:panvk-mali-g720" + /** One PanVK kbase binary for Mali v9-v13; its display half needs Android 15. */ + const val NAD_MALI_KBASE = "nad:panvk-mali-kbase" + const val MALI_KBASE_MIN_SDK = 35 + /** faux123's PanVK builds for three handhelds: manual choices, never Auto. */ + const val NAD_FAUX_RP4PRO = "nad:panvk-faux123-rp4pro" + const val NAD_FAUX_ACE = "nad:panvk-faux123-ace" + const val NAD_FAUX_RG556 = "nad:panvk-faux123-rg556" + /** The one Mali a device-specific build is for, by the number in the GPU's name. */ + private val DEVICE_BUILDS = mapOf(NAD_FAUX_RP4PRO to 77, NAD_FAUX_ACE to 610, NAD_FAUX_RG556 to 57) + /** "PanVK-Mali-G720" (the release asset's id) to its pair key, "nad:panvk-mali-g720". */ + fun nonAdreno(id: String) = "$NON_ADRENO:" + id.lowercase() + /** True for a non-Adreno pair's key, or a bundle installed from one ("PanVK-Mali-G720"). */ + fun isNonAdreno(keyOrBundleId: String?): Boolean = keyOrBundleId != null && + (keyOrBundleId.startsWith("$NON_ADRENO:") || Regex("""^(?i)(RADV-Xclipse|PanVK-[A-Za-z0-9]+)(-[A-Za-z0-9]+)*$""").matches(keyOrBundleId)) + + fun nonAdrenoName(key: String): String = describeNonAdreno(key).first + + private fun describeNonAdreno(key: String): Pair<String, Set<Family>> = when (key) { + NAD_RADV_XCLIPSE -> "RADV · Samsung Xclipse" to setOf(Family.POWERVR) + NAD_RADV_XCLIPSE_UPSTREAM -> "RADV upstream · Samsung Xclipse" to setOf(Family.POWERVR) + NAD_MALI_JM -> "PanVK · Mali G52-G78" to setOf(Family.MALI_JM) + NAD_MALI_G710 -> "PanVK · Mali-G610/G710" to setOf(Family.MALI_G610_G710) + NAD_MALI_G615 -> "PanVK · Mali-G615" to setOf(Family.MALI_G615) + NAD_MALI_G720 -> "PanVK · Mali-G720" to setOf(Family.MALI_G720) + NAD_FAUX_RP4PRO -> "PanVK faux123 · Retroid Pocket 4 Pro (Mali-G77)" to setOf(Family.MALI_JM) + NAD_FAUX_ACE -> "PanVK faux123 · GameForce Ace (Mali-G610)" to setOf(Family.MALI_G610_G710) + NAD_FAUX_RG556 -> "PanVK faux123 · Anbernic RG556 (Mali-G57)" to setOf(Family.MALI_JM) + NAD_MALI_KBASE -> "PanVK kbase · Mali G57-G925" to + setOf(Family.MALI_JM, Family.MALI_G610_G710, Family.MALI_G615, Family.MALI_G720, Family.MALI_LATEST) + else -> key.removePrefix("$NON_ADRENO:") to emptySet<Family>() + } + class DriverPair( val key: String, val name: String, @@ -24,14 +65,23 @@ object DriverPairs { val assets: List<TurnipReleases.Asset> get() = listOfNotNull(bundle ?: display, if (bundle == null) linux else null) val version: String get() = listOfNotNull(bundle?.tag, display?.tag, linux?.tag).distinct().joinToString(" + ") { it.removePrefix("linux-").removePrefix("DD-Turnip-") } - fun suits(gpu: GpuInfo) = gpu.family in families || - (gpu.family == Family.ADRENO_UNKNOWN && (Family.A7XX in families || Family.A8XX in families)) + fun suits(gpu: GpuInfo) = when { + // The system-driver family covers PowerVR and Xclipse; RADV is only for the Xclipse. + key == NAD_RADV_XCLIPSE || key == NAD_RADV_XCLIPSE_UPSTREAM -> + gpu.family == Family.POWERVR && gpu.name.contains("Xclipse", ignoreCase = true) + // One binary for Mali v9-v13, not the older G52/G76 in the Job Manager family. + key == NAD_MALI_KBASE -> gpu.family.mali && GpuInfo.maliKbaseCovered(gpu.name) + key in DEVICE_BUILDS -> gpu.family.mali && GpuInfo.maliNumber(gpu.name) == DEVICE_BUILDS[key] + else -> gpu.family in families || + (gpu.family == Family.ADRENO_UNKNOWN && (Family.A7XX in families || Family.A8XX in families)) + } } private val ALL_ADRENO = setOf(Family.A6XX, Family.A7XX, Family.A7XX_LOW, Family.A8XX, Family.ADRENO_UNKNOWN) private fun describe(key: String): Pair<String, Set<Family>> = when { key.startsWith(DD_TURNIP) -> "DroidDeck · DD-Turnip" to ALL_ADRENO + key.startsWith("$NON_ADRENO:") -> describeNonAdreno(key) else -> describeFixed(key) } @@ -47,7 +97,7 @@ object DriverPairs { fun from(check: TurnipReleases.Check?): List<DriverPair> { val assets = check?.assets.orEmpty().filter { it.pair.isNotEmpty() } - val order = listOf(DD_TURNIP, BANNER, BANNER_A8XX, BANNER_ONEUI, BANNER_710, WN_BALANCED, WN_PERFORMANCE) + val order = listOf(DD_TURNIP, BANNER, BANNER_A8XX, BANNER_ONEUI, BANNER_710, WN_BALANCED, WN_PERFORMANCE, NON_ADRENO) return assets.map { it.pair }.distinct() .sortedBy { key -> order.indexOf(key.substringBefore(':')).let { i -> if (i < 0) order.size else i } } .map { key -> @@ -66,7 +116,13 @@ object DriverPairs { rules: List<AutoPicks.Rule> = AutoPicks.BUILT_IN, bad: Set<String> = emptySet(), sdk: Int = android.os.Build.VERSION.SDK_INT, blob: Int? = null, ): String? { - if (gpu.family == Family.NOT_ADRENO) return null + when (gpu.family) { + Family.POWERVR -> return NAD_RADV_XCLIPSE.takeIf { gpu.name.contains("Xclipse", ignoreCase = true) } + Family.MALI_OTHER, Family.NOT_ADRENO -> return null + Family.MALI_JM, Family.MALI_G610_G710, Family.MALI_G615, Family.MALI_G720, Family.MALI_LATEST -> + return maliKey(gpu, pairs, sdk) + else -> Unit + } val keys = AutoPicks.preferences(gpu, rules, sdk, blob) .ifEmpty { AutoPicks.preferences(gpu, AutoPicks.BUILT_IN, sdk, blob) } .mapNotNull { if (it == AutoPicks.NEWEST_DD_TURNIP) newestDdTurnip(pairs) else it } @@ -74,6 +130,20 @@ object DriverPairs { ?: keys.firstOrNull() } + private fun maliKey(gpu: GpuInfo, pairs: List<DriverPair>, sdk: Int): String? { + val family = when (gpu.family) { + Family.MALI_JM -> NAD_MALI_JM + Family.MALI_G610_G710 -> NAD_MALI_G710 + Family.MALI_G615 -> NAD_MALI_G615 + Family.MALI_G720 -> NAD_MALI_G720 + else -> null + } + val kbase = NAD_MALI_KBASE.takeIf { sdk >= MALI_KBASE_MIN_SDK && GpuInfo.maliKbaseCovered(gpu.name) } + if (pairs.isEmpty()) return kbase ?: family + fun listed(key: String?) = key?.takeIf { k -> pairs.any { it.key == k && it.complete } } + return listed(kbase) ?: listed(family) ?: kbase ?: family + } + fun newestDdTurnip(pairs: List<DriverPair>): String? = pairs .filter { it.key.startsWith("$DD_TURNIP:") && it.complete } .maxByOrNull { p -> 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 9b0a1897e1..7645d3326a 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt @@ -24,8 +24,22 @@ data class GpuInfo( A7XX("Adreno 7xx"), A6XX("Adreno 6xx"), ADRENO_UNKNOWN("Adreno"), + POWERVR("PowerVR"), + /** Mali on Arm's kbase driver, by the open PanVK build each generation needs. */ + MALI_JM("Mali (G52-G78)"), + MALI_G610_G710("Mali-G610/G710"), + MALI_G615("Mali-G615"), + MALI_G720("Mali-G720"), + /** Mali-G715/G725/G925: only the one-binary PanVK kbase build covers them (Android 15+). */ + MALI_LATEST("Mali-G715/G725/G925"), + /** A Mali no open driver build covers: the Vulkan bridge is its only path. */ + MALI_OTHER("Mali"), NOT_ADRENO("Not an Adreno GPU"); + val mali: Boolean get() = name.startsWith("MALI_") + + fun label(gpuName: String): String = if (this == POWERVR && gpuName.contains("Xclipse", ignoreCase = true)) "Samsung Xclipse" else label + fun label(context: Context): String = if (this == NOT_ADRENO) context.getString(R.string.gpuinfo_not_adreno) else label } @@ -47,10 +61,16 @@ data class GpuInfo( val supportText: String get() = when (support) { Support.TESTED -> "Supported" - Support.UNTESTED -> if (isA850) "Experimental Adreno 850 support: requires compatible experimental display and game drivers; not verified on this device" - else if (family == Family.A7XX_LOW) "Experimental: its drivers are test builds" - else "Outside tested hardware (Adreno 650, 725 and newer): it may not run" - Support.UNSUPPORTED -> "Not supported: DroidDeck needs an Adreno (Snapdragon) GPU" + Support.UNTESTED -> when { + family == Family.POWERVR -> if (name.contains("Xclipse", ignoreCase = true)) "Experimental: RADV or the system Xclipse driver" + else "System PowerVR driver: compatibility varies by device" + family == Family.MALI_OTHER -> "Experimental: Mali through the phone's own driver (Venus)" + family.mali -> "Experimental: open Mali driver (test builds)" + isA850 -> "Experimental Adreno 850 support: requires compatible experimental display and game drivers; not verified on this device" + family == Family.A7XX_LOW -> "Experimental: its drivers are test builds" + else -> "Outside tested hardware (Adreno 650, 725 and newer): it may not run" + } + Support.UNSUPPORTED -> "Not supported: no compatible graphics backend is available for this GPU" } fun supportText(bridge: Boolean): String = when { @@ -68,8 +88,9 @@ data class GpuInfo( fun supportText(context: Context): String = context.getString(when (support) { Support.TESTED -> R.string.gpuinfo_supported Support.UNTESTED -> when { + family == Family.POWERVR -> if (name.contains("Xclipse", ignoreCase = true)) R.string.gpuinfo_xclipse else R.string.gpuinfo_powervr isA850 -> R.string.gpuinfo_a850_experimental - family == Family.A7XX_LOW -> R.string.gpuinfo_experimental + family == Family.A7XX_LOW || family.mali -> R.string.gpuinfo_experimental else -> R.string.gpuinfo_below_tested } Support.UNSUPPORTED -> R.string.gpuinfo_unsupported @@ -91,10 +112,20 @@ data class GpuInfo( { VulkanInfo.cachedOrNull()?.get("device") }, { platformGpuModel }, ) else 0 to "" - val family = familyOf(adreno, model) + // Mali, named by the vendor's Vulkan driver ("Mali-G720-Immortalis MC12") or by kbase. + val mali = if (adreno || !File("/dev/mali0").exists()) null else maliName() + val family = familyOf(adreno, model, SystemVulkanDriver.isPowerVr(), mali) val samsung = Build.MANUFACTURER.equals("samsung", ignoreCase = true) return GpuInfo( - name = if (!adreno) Build.HARDWARE.ifBlank { UNNAMED } else if (model > 0) "Adreno $model" else "Adreno", + name = when { + family == Family.POWERVR -> SystemVulkanDriver.gpuName().let { gpu -> + VulkanInfo.cachedOrNull()?.get("device")?.takeIf { it.contains(gpu, ignoreCase = true) } ?: gpu + } + mali != null && mali.isNotEmpty() -> mali + !adreno -> Build.HARDWARE.ifBlank { UNNAMED } + model > 0 -> "Adreno $model" + else -> "Adreno" + }, model = model, family = family, soc = soc, oneUi8Gen2 = samsung && model == 740, kgslName = raw.orEmpty(), modelSource = source, kgslChipId = chipId, @@ -136,7 +167,68 @@ data class GpuInfo( "" } - internal fun familyOf(adreno: Boolean, model: Int): Family = when { + /** + * 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<String> = 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( + "mt6993" to "Mali-G1-Ultra", "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", + "s5e8835" to "Mali-G68", "s5e8825" to "Mali-G68", + ) + + /** The Mali [ids] name a chip of, "Mali-G720 (by chip mt6989)", or null for an unknown chip. */ + internal fun maliOfSoc(ids: List<String>): 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() + + /** + * The Malis the one-binary PanVK kbase build covers (arch v9-v13): G57/G68/G77/G78, + * G610/G710, G615/G715, G720/G725 and G925. Not the older Bifrost G52/G76. + */ + fun maliKbaseCovered(name: String): Boolean = + maliNumber(name) in setOf(57, 68, 77, 78, 610, 710, 615, 715, 720, 725, 925) + + /** The PanVK generation a Mali name belongs to; MALI_OTHER when none of the builds covers it. */ + internal fun maliFamily(name: String): Family { + val number = maliNumber(name) ?: return Family.MALI_OTHER + return when (number) { + 31, 51, 52, 57, 68, 71, 72, 76, 77, 78 -> Family.MALI_JM + 610, 710 -> Family.MALI_G610_G710 + 615 -> Family.MALI_G615 + 720 -> Family.MALI_G720 + 715, 725, 925 -> Family.MALI_LATEST + else -> Family.MALI_OTHER + } + } + + internal fun familyOf(adreno: Boolean, model: Int, powerVr: Boolean = false, mali: String? = null): Family = when { + !adreno && powerVr -> Family.POWERVR + !adreno && mali != null -> maliFamily(mali) !adreno -> Family.NOT_ADRENO model == 0 -> Family.ADRENO_UNKNOWN model >= 800 -> Family.A8XX diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriver.java b/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriver.java index 42dce3d64e..25dd68b4d9 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriver.java +++ b/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriver.java @@ -3,8 +3,12 @@ package com.droiddeck.launcher.gpu; import android.content.Context; import android.util.Log; +import com.droiddeck.launcher.R; + import java.util.ArrayList; import java.util.List; +import java.util.function.Function; +import java.util.function.Supplier; public final class LinuxVulkanDriver { private static final String TAG = "LinuxVulkanDriver"; @@ -25,15 +29,36 @@ public final class LinuxVulkanDriver { return values; } - public static String resolveIcdPath(Context context, String value) { - if (value == null || value.isEmpty()) return null; + public static String optionLabel(Context context, String value) { + if (value == null || value.isEmpty()) return SystemVulkanDriver.isPowerVr() + ? context.getString(R.string.gpu_system_powervr) : "Runtime default (built into the runtime)"; LinuxVulkanDriverManager m = new LinuxVulkanDriverManager(context); - String icd = m.getIcdPath(value); - if (icd == null) { - Log.w(TAG, "imported Linux driver \"" + value + "\" is gone; using the runtime's own driver"); - return null; - } - Log.i(TAG, "Linux session draws with imported driver " + value + " (" + icd + ")"); + if (!m.isInstalled(value)) return value + (SystemVulkanDriver.isPowerVr() + ? " (imported, missing)" : " (imported, missing - uses the runtime default)"); + String ver = m.getDriverVersion(value); + return m.getDriverName(value) + (ver.isEmpty() ? "" : " " + ver) + " (imported)"; + } + + public static String resolveIcdPath(Context context, String value) { + boolean powerVr = SystemVulkanDriver.isPowerVr(); + return resolveIcdPath(value, powerVr, + () -> SystemVulkanDriver.icdPath(context), id -> { + String icd = new LinuxVulkanDriverManager(context).getIcdPath(id); + if (icd == null) Log.w(TAG, "imported Linux driver \"" + id + "\" is gone" + + (powerVr ? "" : "; using the runtime's own driver")); + else Log.i(TAG, "Linux session draws with imported driver " + id + " (" + icd + ")"); + return icd; + }); + } + + /** Resolve the selected backend before looking up an imported driver. */ + static String resolveIcdPath(String value, boolean powerVr, Supplier<String> systemIcd, + Function<String, String> importedIcd) { + if (SystemVulkanDriver.usesDefault(powerVr, value)) return systemIcd.get(); + if (value == null || value.isEmpty()) return null; + String icd = importedIcd.apply(value); + if (powerVr && icd == null) throw new IllegalStateException( + "Selected Linux Vulkan driver \"" + value + "\" is unavailable. Select an installed driver or use Auto."); return icd; } } 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 3973297cd8..4f0b62eddb 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java +++ b/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java @@ -45,7 +45,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; } public String getIcdPath(String id) { @@ -107,10 +109,10 @@ public class LinuxVulkanDriverManager { if (entry.isDirectory()) continue; String base = new File(entry.getName()).getName(); if (base.isEmpty()) continue; - if (base.startsWith("libvulkan_freedreno") && base.endsWith(".so")) { - if (soName != null) Log.w(TAG, "zip has several libvulkan_freedreno*.so; using the first (" + soName + ")"); + 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)) { @@ -142,7 +144,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)); } @@ -167,7 +170,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"); @@ -180,6 +183,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"); @@ -198,6 +202,24 @@ public class LinuxVulkanDriverManager { return id; } + /** 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")); + } + static String sanitizeId(String name) { String s = name.trim().replaceAll("[^A-Za-z0-9._-]+", "_").replaceAll("^[._]+", ""); if (s.length() > 64) s = s.substring(0, 64); diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/SystemVulkanDriver.java b/app/src/main/java/com/droiddeck/launcher/gpu/SystemVulkanDriver.java new file mode 100644 index 0000000000..07ba47cd16 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/gpu/SystemVulkanDriver.java @@ -0,0 +1,261 @@ +package com.droiddeck.launcher.gpu; + +import android.content.Context; +import android.os.Build; +import android.system.ErrnoException; +import android.system.Os; +import android.system.OsConstants; +import com.droiddeck.launcher.core.FileUtils; +import com.droiddeck.launcher.core.TarZst; +import java.io.File; +import java.io.IOException; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.List; +import java.util.TreeSet; +import java.util.UUID; +import java.util.function.Predicate; +import org.json.JSONObject; + +/** Isolated glibc-to-Android Vulkan bridge. It does not replace the rootfs's Mesa libraries. */ +public final class SystemVulkanDriver { + private static final String ASSET = "hybris/runtime.tzst"; + /** Vendor HALs the bridge loads. Samsung Xclipse (Exynos, sgpu) is experimental. */ + private static final String[] HALS = { + "/vendor/lib64/hw/vulkan.powervr.so", + "/vendor/lib64/hw/vulkan.samsung.so" + }; + private static final String[] REQUIRED = { + "lib/libhybris-vulkan-icd.so.0", "lib/libhybris-common.so.1", + "lib/libhybris/linker/q.so", "lib/libVkLayer_hybris_compat.so", + "run-proton.py", "wsi/libVkLayer_window_system_integration.so", + "wsi/VkLayer_window_system_integration.json", + "dxvk/x32/d3d8.dll", "dxvk/x32/d3d9.dll", "dxvk/x32/d3d10core.dll", + "dxvk/x32/d3d11.dll", "dxvk/x32/dxgi.dll", + "dxvk/x64/d3d8.dll", "dxvk/x64/d3d9.dll", "dxvk/x64/d3d10core.dll", + "dxvk/x64/d3d11.dll", "dxvk/x64/dxgi.dll" + }; + + /** Rootfs directory of the Xclipse layer the apk stages (SessionFiles). */ + private static final String XCLIPSE_LAYER_DIR = "/usr/local/lib/droiddeck-xclipse"; + + private SystemVulkanDriver() {} + + /** + * The first vendor HAL present, or null. An Exynos with a Mali (Exynos 1280/1380: /dev/mali0) + * may name its HAL vulkan.samsung.so too; that is a Mali, not an Xclipse, and is not taken. + */ + public static String hal() { + for (String path : HALS) { + if (!new File(path).isFile()) continue; + if (path.endsWith("/vulkan.samsung.so") && new File("/dev/mali0").exists()) continue; + return path; + } + return null; + } + + /** Samsung's Xclipse (Exynos, sgpu) rather than PowerVR. */ + public static boolean isXclipse() { + String hal = hal(); + return hal != null && hal.endsWith("/vulkan.samsung.so"); + } + + /** The system-driver GPU family, for labels. */ + public static String gpuName() { return isXclipse() ? "Xclipse" : "PowerVR"; } + + /** Whether a system-driver GPU (PowerVR or Xclipse) is present; the name predates Xclipse. */ + public static boolean isPowerVr() { return hal() != null; } + + /** HAL detection names the GPU; launching also needs the real DRM render node. */ + public static boolean isAvailable() { return isPowerVr() && renderNodeAvailable(); } + + public static boolean renderNodeAvailable() { + return renderNodePath() != null; + } + + /** Select the actual PowerVR node, including devices where another GPU owns renderD128. */ + public static String renderNodePath() { + String[] nodes = new File("/dev/dri").list(); + if (nodes == null) nodes = new File("/sys/class/drm").list(); + return findRenderNode(nodes, SystemVulkanDriver::renderNodeAvailable); + } + + static String findRenderNode(String[] nodes, Predicate<String> available) { + TreeSet<String> candidates = new TreeSet<>(); + // Android can deny directory listing while allowing direct access. Probe the kernel's + // reserved render range too; directory entries also cover dynamically allocated minors. + for (int minor = 128; minor < 192; minor++) candidates.add("renderD" + minor); + if (nodes != null) for (String node : nodes) + if (node.matches("renderD[0-9]+")) candidates.add(node); + for (String node : candidates) { + String path = "/dev/dri/" + node; + if (available.test(path)) return path; + } + return null; + } + + private static boolean renderNodeAvailable(String node) { + try { + if (!renderNodeAvailable(OsConstants.S_ISCHR(Os.stat(node).st_mode), + Os.access(node, OsConstants.R_OK), Os.access(node, OsConstants.W_OK))) return false; + return powerVrDevice(new File("/sys/class/drm/" + new File(node).getName() + "/device")); + } catch (ErrnoException error) { + return false; + } + } + + static boolean powerVrDriver(String driver) { + return "pvrsrvkm".equals(driver) || "pvr".equals(driver) || "powervr".equals(driver) + || "sgpu".equals(driver); + } + + static boolean powerVrDevice(File device) { + try { + return powerVrDriver(Files.readSymbolicLink(new File(device, "driver").toPath()) + .getFileName().toString()); + } catch (IOException error) { + // Some Android policies expose uevent but deny reading the driver symlink. + try (BufferedReader input = Files.newBufferedReader( + new File(device, "uevent").toPath(), StandardCharsets.US_ASCII)) { + String line; + while ((line = input.readLine()) != null) + if (line.startsWith("DRIVER=")) return powerVrDriver(line.substring(7)); + } catch (IOException ignored) { } + return false; + } + } + + static boolean renderNodeAvailable(boolean characterDevice, boolean readable, boolean writable) { + return characterDevice && readable && writable; + } + + public static boolean usesDefault(String choice) { + return usesDefault(isPowerVr(), choice); + } + + static boolean usesDefault(boolean powerVr, String choice) { + return powerVr && (choice == null || choice.isEmpty()); + } + + /** APK-versioned directories stay intact while an older session still has libraries mapped. */ + public static synchronized File prepare(Context context) throws IOException { + if (!isPowerVr()) throw new IOException("System PowerVR Vulkan driver is unavailable"); + if (!renderNodeAvailable()) throw new IOException( + "System PowerVR requires an identifiable, readable and writable DRM render node"); + File target = runtimeDirectory(context); + File base = target.getParentFile(); + if (complete(target)) return target; + if (!base.isDirectory() && !base.mkdirs()) throw new IOException("Cannot create system Vulkan directory"); + File staged = new File(base, ".stage-" + UUID.randomUUID()); + try { + if (!TarZst.extractAsset(context, ASSET, staged)) throw new IOException("Cannot unpack system Vulkan runtime"); + for (String name : REQUIRED) + if (!present(staged, name)) throw new IOException("Missing system Vulkan component: " + name); + if (!new File(staged, "run-proton.py").canExecute()) + throw new IOException("System Vulkan Proton wrapper is not executable"); + JSONObject library = new JSONObject(); + library.put("library_path", new File(target, REQUIRED[0]).getPath()); + library.put("api_version", "1.3.0"); + JSONObject manifest = new JSONObject(); + manifest.put("file_format_version", "1.0.0"); + manifest.put("ICD", library); + Files.write(new File(staged, "icd.json").toPath(), manifest.toString().getBytes(StandardCharsets.UTF_8)); + if (target.exists()) throw new IOException("Incomplete system Vulkan runtime directory: " + target.getName()); + if (!staged.renameTo(target)) throw new IOException("Cannot publish system Vulkan runtime"); + return target; + } catch (org.json.JSONException error) { + throw new IOException("Cannot write system Vulkan manifest", error); + } finally { + if (staged.exists()) FileUtils.delete(staged); + } + } + + /** The current APK's versioned runtime path, without extracting or modifying it. */ + public static File runtimeDirectory(Context context) throws IOException { + String version; + try (BufferedReader input = new BufferedReader(new InputStreamReader( + context.getAssets().open("hybris/version.txt"), StandardCharsets.US_ASCII))) { + version = input.readLine(); + } + if (version == null || !version.matches("[0-9a-f]{64}")) throw new IOException("Invalid system Vulkan runtime version"); + return new File(new File(context.getFilesDir(), "system_vulkan"), version); + } + + /** Collect abandoned stages, and obsolete versions once older guests can no longer load them. */ + public static synchronized void pruneUnused(Context context, boolean guestsStopped) throws IOException { + pruneUnused(runtimeDirectory(context), guestsStopped); + } + + static synchronized void pruneUnused(File current, boolean guestsStopped) { + File base = current.getParentFile(); + if (base == null || Files.isSymbolicLink(base.toPath()) || Files.isSymbolicLink(current.toPath())) return; + File[] entries = base.listFiles(); + if (entries == null) return; + // Retain the previous good version if publishing the replacement failed. + boolean pruneVersions = guestsStopped && complete(current); + for (File entry : entries) { + if (entry.equals(current)) continue; + String name = entry.getName(); + boolean oldVersion = pruneVersions && name.matches("[0-9a-f]{64}"); + boolean abandonedStage = name.matches("\\.stage-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"); + // The prepare monitor excludes any extraction still writing a .stage directory. + if (oldVersion || abandonedStage) FileUtils.delete(entry); + } + } + + private static boolean complete(File directory) { + if (!new File(directory, "icd.json").isFile()) return false; + for (String name : REQUIRED) if (!present(directory, name)) return false; + return new File(directory, "run-proton.py").canExecute(); + } + + private static boolean present(File directory, String name) { + File file = new File(directory, name); + return file.isFile() && file.length() > 0; + } + + public static String icdPath(Context context) { + try { + return new File(prepare(context), "icd.json").getPath(); + } catch (IOException error) { + throw new IllegalStateException("System Vulkan runtime is unavailable", error); + } + } + + public static void addEnvironment(Context context, List<String> environment) { + File directory; + try { directory = prepare(context); } + catch (IOException error) { throw new IllegalStateException("System Vulkan runtime is unavailable", error); } + String node = renderNodePath(); + if (node == null) throw new IllegalStateException("System PowerVR render node is unavailable"); + environment.add("HYBRIS_ANDROID_SDK_VERSION=" + Build.VERSION.SDK_INT); + environment.add("HYBRIS_VULKAN_HAL=" + hal()); + environment.add("HYBRIS_LINKER_DIR=" + new File(directory, "lib/libhybris/linker").getPath()); + // Prefer framework dependencies for the system Vulkan loader, including libbase.so. + environment.add("HYBRIS_LD_LIBRARY_PATH=/system/lib64:/system_ext/lib64:/vendor/lib64/egl:/vendor/lib64/hw:/vendor/lib64"); + boolean xclipse = isXclipse(); + // Xclipse gets its own layer (tools/linuxfs/xclipse-layer) in front of everything: it sets + // bionic's environ for the driver's shader compiler, among other driver workarounds. The + // session's own clients need nothing else; games keep the compat layer's BC emulation. + String layers = xclipse ? "VK_LAYER_DROIDDECK_xclipse" : "VK_LAYER_HYBRIS_compat"; + environment.add("VK_LAYER_PATH=" + new File(directory, "lib").getPath() + (xclipse ? ":" + XCLIPSE_LAYER_DIR : "")); + environment.add("VK_INSTANCE_LAYERS=" + layers); + // Proton game launches add their WSI layer in front of these (droiddeck-game-env). + environment.add("DROIDDECK_HYBRIS_LAYERS=" + (xclipse ? layers + ":VK_LAYER_HYBRIS_compat" : layers)); + if (xclipse) environment.add("DROIDDECK_HYBRIS_LAYER_PATH=" + XCLIPSE_LAYER_DIR); + // DXVK 3 needs 256 bytes of push constants; this driver has 128. + if (xclipse) environment.add("DROIDDECK_HYBRIS_DXVK=dxvk-2.6.2"); + // The Android driver has a render node, but no KMS primary node. SDL presents + // through the wrapper's Wayland Vulkan swapchain instead of a KMS-style path. + environment.add("BL_GAMESCOPE_BACKEND=sdl"); + // The Android pvr kernel accepts Vulkan DMA-BUF imports but rejects PRIME GEM handles. + environment.add("BL_POWERVR_DRM_HANDLES=1"); + environment.add("BL_POWERVR_RENDER_NODE=" + node); + // Inner Gamescope/Xwayland lacks the bridge's Android-buffer WSI protocols. + environment.add("BL_STEAM_GL_PRESENT=1"); + // Only actual Proton game launches use the bundled DXVK and X11 WSI layer. + environment.add("DROIDDECK_POWERVR_RUNTIME=" + directory.getPath()); + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipDriver.java b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipDriver.java index ba96c3eca8..294f5a95b8 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipDriver.java +++ b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipDriver.java @@ -263,7 +263,24 @@ public final class TurnipDriver { } private String choose() { + SessionPrefs.ensurePowerVrAutoDrivers(context); String chosen = SessionPrefs.androidDriver(context); + // Mali (Venus): the phone's own driver draws the screen, as Venus replays on it. + if (com.droiddeck.launcher.session.VenusComponent.wanted(context)) { + Log.i(TAG, "Mali (Venus): display on the system Vulkan loader"); + return null; + } + // A Mali under Auto draws its display on Android's own Vulkan loader, whatever an earlier + // build set: a PanVK Android half fails on Mali gralloc. A manual pick is respected. + if (chosen != null && !chosen.isEmpty() && new File("/dev/mali0").exists() + && !com.droiddeck.launcher.core.DeviceSupport.INSTANCE.adreno() + && SessionPrefs.GPU_DRIVERS_AUTO.equals(SessionPrefs.INSTANCE.gpuDriverMode(context))) { + DriverBundle.Bundle bundle = DriverBundle.INSTANCE.containing(context, chosen, false); + if (bundle != null && DriverPairs.INSTANCE.isNonAdreno(bundle.getId())) { + Log.i(TAG, "Mali under Auto: display on the system Vulkan loader, not " + chosen); + return null; + } + } if (chosen != null && !chosen.isEmpty()) { if (BUNDLED.contains(chosen)) { Log.i(TAG, "driver pinned by the user: " + chosen); @@ -289,6 +306,7 @@ public final class TurnipDriver { if (forced.startsWith("a7")) return DRIVER_A7XX; if (forced.startsWith("a6")) return DRIVER_A6XX; } + if (SystemVulkanDriver.isPowerVr()) return null; String quest = QuestExperimental.INSTANCE.defaultAndroidDriver(); if (quest != null) return quest; if (com.droiddeck.launcher.core.DeviceSupport.INSTANCE.vkBridge(context)) { @@ -296,7 +314,7 @@ public final class TurnipDriver { return null; } GpuInfo gpu = gpuDetector.get(); - if (gpu.getFamily() == GpuInfo.Family.NOT_ADRENO) { + if (gpu.getFamily() == GpuInfo.Family.NOT_ADRENO || gpu.getFamily().getMali()) { Log.i(TAG, "not an Adreno GPU; leaving the display driver to the system"); return null; } diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt index 43540c0e23..1936779cbd 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt @@ -22,12 +22,17 @@ object TurnipReleases { private const val KEY_PICKS = "autoPicks" class Asset(val source: String, val tag: String, val name: String, val url: String, val size: Long, val linux: Boolean, val label: String, - val sha256: String = "", val pair: String = "", val bundle: Boolean = false) + val sha256: String = "", val pair: String = "", val bundle: Boolean = false, + val assetId: Long = 0, val updatedAt: String = "") { + /** "2026-10-15" from GitHub's updated_at; empty when the check did not record it. */ + val builtOn: String get() = updatedAt.take(10) + } class Check(val assets: List<Asset>, val latest: List<Pair<String, String>>, val failed: List<String>, val checkedAt: Long) private class Kind(val linux: Boolean, val label: String, val pair: String, val bundle: Boolean = false) - private class Source(val label: String, val repo: String, val classify: (name: String, tag: String) -> Kind?) + /** [prerelease]: a source whose bundles are all test builds offers them from pre-releases too. */ + private class Source(val label: String, val repo: String, val prerelease: Boolean = false, val classify: (name: String, tag: String) -> Kind?) private val SOURCES = listOf( Source("Banners-Turnip", "The412Banner/Banners-Turnip") { name, tag -> @@ -56,8 +61,22 @@ object TurnipReleases { if (!Regex("""^DD-Turnip-v\d+\.\d+\.\d+\.zip$""").matches(name)) return@Source null Kind(false, "Android + Linux · all Adreno", DriverPairs.ddTurnip(tag), bundle = true) }, + // <Id>-Pair.zip: open drivers for GPUs that are not Adreno (PanVK for Mali, RADV for + // Xclipse), both halves in one zip. One release per driver, replaced in place on each + // rebuild; every one is a test build, published as a pre-release. + Source(NON_ADRENO_LABEL, NON_ADRENO_REPO, prerelease = true) { name, _ -> + val m = Regex("""^(RADV-Xclipse(?:-[A-Za-z0-9]+)*?|PanVK-[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*?)-Pair\.zip$""").find(name) ?: return@Source null + val key = DriverPairs.nonAdreno(m.groupValues[1]) + Kind(false, "Android + Linux · " + DriverPairs.nonAdrenoName(key), key, bundle = true) + }, ) + private const val NON_ADRENO_REPO = "The412Banner/droiddeck-nonadreno-drivers" + const val NON_ADRENO_LABEL = "Non-Adreno" + + private fun sources(): List<Source> = + if (com.droiddeck.launcher.core.DeviceSupport.adreno()) SOURCES.filter { it.repo != NON_ADRENO_REPO } else SOURCES + fun autoPicks(context: Context): List<AutoPicks.Rule> = AutoPicks.parse(prefs(context).getString(KEY_PICKS, null)) ?: AutoPicks.BUILT_IN @@ -71,9 +90,13 @@ object TurnipReleases { val latest = JSONArray() val failed = ArrayList<String>() var lastError: Exception? = null - for (src in SOURCES) { + val sources = sources() + for (src in sources) { try { - val releases = JSONArray(get(context, "https://api.github.com/repos/${src.repo}/releases?per_page=15")) + // The non-Adreno repo keeps one release per driver plus many component builds (gamescope, + // Venus): its driver pairs fall past the first 15, so it is read in one full page. + val perPage = if (src.repo == NON_ADRENO_REPO) 100 else 15 + val releases = JSONArray(get(context, "https://api.github.com/repos/${src.repo}/releases?per_page=$perPage")) val seen = HashSet<String>() var newest: String? = null for (i in 0 until releases.length()) { @@ -86,7 +109,7 @@ object TurnipReleases { val a = list.getJSONObject(j) val name = a.getString("name") val kind = src.classify(name, tag) ?: continue - if (kind.bundle && r.optBoolean("prerelease")) continue + if (kind.bundle && r.optBoolean("prerelease") && !src.prerelease) continue val linux = kind.linux val label = kind.label val sha = Hashes.githubSha256(a.optString("digest")) ?: continue @@ -94,7 +117,7 @@ object TurnipReleases { assets.put(JSONObject().put("source", src.label).put("tag", tag).put("name", name) .put("url", a.getString("browser_download_url")).put("size", a.optLong("size")) .put("linux", linux).put("label", label).put("sha256", sha).put("pair", kind.pair) - .put("bundle", kind.bundle)) + .put("bundle", kind.bundle).put("id", a.optLong("id")).put("updated_at", a.optString("updated_at"))) } } if (newest != null) latest.put(JSONObject().put("source", src.label).put("tag", newest)) @@ -103,7 +126,7 @@ object TurnipReleases { lastError = e } } - if (failed.size == SOURCES.size) throw lastError ?: IOException("no source answered") + if (failed.size == sources.size) throw lastError ?: IOException("no source answered") runCatching { get(context, AutoPicks.URL, AutoPicks.URL) } .onFailure { Log.i(TAG, "auto picks: ${it.message}") } .getOrNull()?.takeIf { AutoPicks.parse(it) != null } @@ -154,7 +177,7 @@ object TurnipReleases { val a = list.getJSONObject(i) out.add(Asset(a.getString("source"), a.getString("tag"), a.getString("name"), a.getString("url"), a.optLong("size"), a.getBoolean("linux"), a.getString("label"), a.optString("sha256", ""), a.optString("pair", ""), - a.optBoolean("bundle", false))) + a.optBoolean("bundle", false), a.optLong("id"), a.optString("updated_at", ""))) } val latest = ArrayList<Pair<String, String>>() val l = json.optJSONArray("latest") ?: JSONArray() @@ -165,16 +188,53 @@ object TurnipReleases { return Check(out, latest, failed, json.optLong("checkedAt")) } - fun installedId(context: Context, asset: Asset, isInstalled: (String) -> Boolean): String? = + fun installedId(context: Context, asset: Asset, isInstalled: (String) -> Boolean): String? { + val d = downloads(context) + if (DriverPairs.isNonAdreno(asset.pair) && asset.sha256.isNotEmpty() && + !asset.sha256.equals(d.optString(SHA_PREFIX + asset.name, asset.sha256), ignoreCase = true)) return null + return d.optString(asset.name, "").takeIf { it.isNotEmpty() && isInstalled(it) } + } + + private const val SHA_PREFIX = "sha256:" + private const val ASSET_ID_PREFIX = "asset:" + private const val UPDATED_PREFIX = "updated:" + + /** The id an open non-Adreno pair's asset was installed as, whichever build of it that was. */ + fun installedIdAnyBuild(context: Context, asset: Asset, isInstalled: (String) -> Boolean): String? = downloads(context).optString(asset.name, "").takeIf { it.isNotEmpty() && isInstalled(it) } + /** + * An open non-Adreno pair is rebuilt in place under the same tag: a different digest, asset id + * or upload time than the one installed means a newer build. + */ + fun updateAvailable(context: Context, asset: Asset): Boolean { + if (!DriverPairs.isNonAdreno(asset.pair)) return false + val d = downloads(context) + if (d.optString(asset.name, "").isEmpty()) return false + val sha = d.optString(SHA_PREFIX + asset.name, "") + val id = d.optLong(ASSET_ID_PREFIX + asset.name, 0) + val updated = d.optString(UPDATED_PREFIX + asset.name, "") + return (sha.isNotEmpty() && asset.sha256.isNotEmpty() && !sha.equals(asset.sha256, ignoreCase = true)) || + (id != 0L && asset.assetId != 0L && id != asset.assetId) || + (updated.isNotEmpty() && asset.updatedAt.isNotEmpty() && updated != asset.updatedAt) + } + + /** When the installed build of [asset] was uploaded, as recorded at download ("" if unknown). */ + fun installedBuiltOn(context: Context, asset: Asset): String = downloads(context).optString(UPDATED_PREFIX + asset.name, "").take(10) + fun isDownloaded(context: Context, id: String): Boolean { val d = downloads(context) return d.keys().asSequence().any { d.optString(it) == id } } fun recordDownload(context: Context, asset: Asset, id: String) { - prefs(context).edit().putString(KEY_DOWNLOADS, downloads(context).put(asset.name, id).toString()).apply() + val d = downloads(context).put(asset.name, id) + if (DriverPairs.isNonAdreno(asset.pair)) { + if (asset.sha256.isNotEmpty()) d.put(SHA_PREFIX + asset.name, asset.sha256) + if (asset.assetId != 0L) d.put(ASSET_ID_PREFIX + asset.name, asset.assetId) + if (asset.updatedAt.isNotEmpty()) d.put(UPDATED_PREFIX + asset.name, asset.updatedAt) + } + prefs(context).edit().putString(KEY_DOWNLOADS, d.toString()).apply() } fun forget(context: Context, id: String) { 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 e2cc349aae..3e5b0a29cb 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -7,6 +7,7 @@ import android.system.ErrnoException; import android.system.Os; import android.system.StructStat; import android.system.StructUtsname; +import com.droiddeck.launcher.gpu.SystemVulkanDriver; import com.droiddeck.launcher.session.SessionPrefs; @@ -191,6 +192,13 @@ public final class LinuxRuntime { bind(cmd, "/dev"); bind(cmd, "/proc"); bind(cmd, "/sys"); + if (com.droiddeck.launcher.gpu.SystemVulkanDriver.isPowerVr()) { + // The glibc bridge loads the device's existing Android HAL and its dependencies. + // These read-only Android partitions remain subject to the app's normal permissions. + for (String path : new String[]{"/system", "/vendor", "/apex", "/system_ext", "/product", "/odm"}) + if (new File(path).isDirectory()) bind(cmd, path); + if (new File("/linkerconfig/ld.config.txt").isFile()) bind(cmd, "/linkerconfig/ld.config.txt"); + } bind(cmd, DeviceControlsComponent.prepareBacklight(context, root).getPath() + ":/sys/class/backlight"); bind(cmd, "/dev/urandom:/dev/random"); bind(cmd, "/proc/self/fd:/dev/fd"); @@ -198,6 +206,10 @@ public final class LinuxRuntime { bind(cmd, "/proc/self/fd/1:/dev/stdout"); bind(cmd, "/proc/self/fd/2:/dev/stderr"); bind(cmd, new File(root, "etc/droiddeck/empty").getPath() + ":/sys/fs/selinux"); + // A kernel that refuses to list /sys/class/thermal (Pixel 10, Android 17) made mangoapp abort + // at start ("filesystem_error ... Permission denied: '/sys/class/thermal/'") until its + // wrapper gave up: it lists the directory for CPU temperatures. Empty there instead. + if (new File("/sys/class/thermal").list() == null) bind(cmd, new File(root, "etc/droiddeck/empty").getPath() + ":/sys/class/thermal"); bind(cmd, context.getFilesDir().getPath()); bind(cmd, context.getCacheDir().getPath()); bind(cmd, liveDir(context).getPath()); @@ -259,7 +271,11 @@ public final class LinuxRuntime { if (unreadablePciDevice()) { bind(cmd, new File(root, "etc/droiddeck/empty").getPath() + ":/sys/bus/pci/devices"); } - bindGpuNode(context, cmd); + if (com.droiddeck.launcher.gpu.SystemVulkanDriver.isPowerVr()) { + bindPowerVrGpuNode(context, cmd); + } else { + bindGpuNode(context, cmd); + } bindAdrenoStats(cmd, extraBinds); bindCpuTemps(cmd, root); if (extraBinds != null) { @@ -270,6 +286,24 @@ public final class LinuxRuntime { return specs; } + private static void bindPowerVrGpuNode(Context context, List<String> cmd) { + if (new File("/dev/dri").list() != null) return; + String node = SystemVulkanDriver.renderNodePath(); + if (node == null) return; + String name = new File(node).getName(); + File dri = new File(context.getCacheDir(), "powervr-drm/" + name + "/dri"); + try { + if (!dri.isDirectory() && !dri.mkdirs()) return; + new File(dri, name).createNewFile(); + } catch (IOException e) { + android.util.Log.w("LinuxRuntime", "Cannot expose the PowerVR render node", e); + return; + } + bind(cmd, dri.getPath() + ":/dev/dri"); + bind(cmd, node + ":" + node); + android.util.Log.i("LinuxRuntime", "PowerVR: exposing real " + name + " through a listable directory"); + } + private static boolean unreadablePciDevice() { File[] devices = new File("/sys/bus/pci/devices").listFiles(); if (devices == null) return false; @@ -279,7 +313,7 @@ public final class LinuxRuntime { return false; } - static final String MALI_DEVICE = "/dev/mali0"; + public static final String MALI_DEVICE = "/dev/mali0"; static final String[] DRM_RENDER_NODES = { "/dev/dri/renderD128", "/dev/dri/renderD129", "/dev/dri/renderD130", "/dev/dri/renderD131", @@ -287,6 +321,7 @@ 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.openDriverActive(context) && new File(MALI_DEVICE).exists()) return MALI_DEVICE; if (!com.droiddeck.launcher.core.DeviceSupport.INSTANCE.vkBridge(context)) return null; return bridgeStandIn(path -> new File(path).exists()); } diff --git a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt index 8255209d19..df5db5eb64 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt @@ -9,6 +9,7 @@ import com.droiddeck.launcher.core.FileUtils import com.droiddeck.launcher.core.GameEnvironment import com.droiddeck.launcher.gpu.AppVulkan import com.droiddeck.launcher.gpu.GpuInfo +import com.droiddeck.launcher.gpu.SystemVulkanDriver import com.droiddeck.launcher.runtime.LinuxRuntime import com.github.luben.zstd.ZstdInputStream import com.github.luben.zstd.ZstdOutputStream @@ -199,9 +200,13 @@ object ComponentsManager { COMPONENTS.mapNotNull { comp -> profile.optString(comp).takeIf(String::isNotEmpty)?.let { comp to it } }.toMap() } - fun setGameComponent(context: Context, scope: String, comp: String, file: String?) = synchronized(lock) { + fun setGameComponent(context: Context, scope: String, comp: String, file: String?) = + setGameComponent(context, scope, comp, file) { runtimeManaged(context, it) } + + internal fun setGameComponent(context: Context, scope: String, comp: String, file: String?, managed: (String) -> Boolean) = synchronized(lock) { require(scope.matches(Regex("[1-9][0-9]{0,9}")) && scope.toLong() <= 4294967295L) require(comp in COMPONENTS) + if (file != null) requireSelectable(context, comp, managed) val state = loadState(context) val profiles = state.sub("profiles") val profile = profiles.optJSONObject(scope) ?: JSONObject().also { profiles.put(scope, it) } @@ -638,11 +643,21 @@ object ComponentsManager { return PreparedLaunchState(lines.toString(), keep) } + internal fun runtimeManaged(comp: String, systemPowerVr: Boolean): Boolean = comp == "dxvk" && systemPowerVr + + private fun runtimeManaged(context: Context, comp: String): Boolean = + runtimeManaged(comp, SystemVulkanDriver.usesDefault(SessionPrefs.linuxDriver(context))) + + private fun requireSelectable(context: Context, comp: String, managed: (String) -> Boolean = { runtimeManaged(context, it) }) { + check(!managed(comp)) { context.getString(R.string.cmgr_powervr_dxvk_managed) } + } + fun swap(context: Context, protonId: String, file: String, auto: Boolean = false): String = synchronized(lock) { val p = proton(context, protonId) val wcp = File(packagesDir(context), safeName(file)) val info = packageInfo(context, wcp) + requireSelectable(context, info.comp) val state = loadState(context) if (inUse(context, p)) { state.sub("queued").sub(p.id).put(info.comp, JSONObject().put("kind", "package").put("file", wcp.name).put("label", info.version) @@ -668,6 +683,7 @@ object ComponentsManager { } fun restore(context: Context, protonId: String, comp: String, protonVersion: String): String = synchronized(lock) { + requireSelectable(context, comp) val p = proton(context, protonId) val wcp = File(originalsDir(context), "$protonId/${safeName(protonVersion)}/$comp.wcp") check(wcp.isFile) { context.getString(R.string.cmgr_original_missing) } @@ -693,7 +709,10 @@ object ComponentsManager { .put("protonVersion", p.version).put("files", JSONObject(fingerprint(p.dir, comp) as Map<*, *>)).put("at", System.currentTimeMillis() / 1000)) } - fun applyQueued(context: Context): List<String> = synchronized(lock) { + /** Runs the swaps that waited for a game to close. Cheap when nothing is queued. */ + fun applyQueued(context: Context): List<String> = applyQueued(context) { runtimeManaged(context, it) } + + internal fun applyQueued(context: Context, managed: (String) -> Boolean): List<String> = synchronized(lock) { val state = loadState(context) val queued = state.sub("queued") if (queued.length() == 0) return emptyList() @@ -705,6 +724,7 @@ object ComponentsManager { val comps = queued.optJSONObject(pid) ?: continue for (comp in comps.keys().asSequence().toList()) { val q = comps.optJSONObject(comp) ?: continue + if (managed(comp)) continue runCatching { if (q.optString("kind") == "original") { val v = q.optString("protonVersion") diff --git a/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt b/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt new file mode 100644 index 0000000000..4d1ee473e4 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt @@ -0,0 +1,250 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import android.os.Build +import android.system.Os +import com.droiddeck.launcher.core.DeviceSupport +import com.droiddeck.launcher.core.FileUtils +import com.droiddeck.launcher.gpu.DriverBundle +import com.droiddeck.launcher.gpu.DriverPairs +import com.droiddeck.launcher.gpu.GpuInfo +import com.droiddeck.launcher.gpu.SystemVulkanDriver +import com.droiddeck.launcher.gpu.TurnipReleases +import com.droiddeck.launcher.gpu.VulkanInfo +import java.io.File +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +/** + * graphics-report.txt in each session's folder: which graphics path the session drew with and why, + * the GPU and its device nodes, the environment the guest got, and at the end what the compositor + * said about its driver. Written for a non-Adreno test report, where a black screen otherwise comes + * with nothing to read; the Share logs zip takes the whole folder, so it travels with the logs. + * Read-only: nothing here opens a GPU node or changes a setting. + */ +object GraphicsReport { + const val FILE = "graphics-report.txt" + const val GAMES_DIR = "games" + + /** One file in games/ past this is cut to its first part at the session's end. */ + private const val GAME_FILE_MAX = 20L * 1024 * 1024 + /** All of games/ past this loses its oldest launches. */ + private const val GAMES_TOTAL_MAX = 120L * 1024 * 1024 + + /** The guest keys the report repeats: everything that decides which Vulkan driver loads. */ + private val ENV_PREFIXES = listOf( + "VK_", "BL_VK", "BL_DRM", "BL_VKBRIDGE", "VKBRIDGE", "MESA_", "GALLIUM_", "ZINK", "TU_", "PANVK", + "DROIDDECK_POWERVR", "DROIDDECK_HYBRIS", "BL_GAME_LOGS", "LIBGL_", "GAMESCOPE_DISABLE", "XWAYLAND", + ) + + /** Per-game graphics logs and the guest's Vulkan summary: on for a non-Adreno GPU, or by Setup's switch. */ + fun detailed(context: Context): Boolean = !DeviceSupport.adreno() || SessionPrefs.detailedGraphicsLogs(context) + + /** For finish(), which runs from the session's end without a context of its own. */ + @Volatile private var appContext: Context? = null + + /** Writes the start of the report; never throws. */ + fun begin(context: Context, dir: File, guest: List<String>) { + appContext = context.applicationContext + runCatching { File(dir, FILE).writeText(start(context, guest)) } + .onFailure { android.util.Log.w("GraphicsReport", "could not write $FILE", it) } + } + + private fun start(context: Context, guest: List<String>): String = buildString { + val time = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(Date()) + appendLine("== graphics report, session start $time") + appendLine("build: ${com.droiddeck.launcher.BuildConfig.BUILD_LABEL} (source ${com.droiddeck.launcher.BuildConfig.SOURCE_COMMIT})") + appendLine() + val gpu = runCatching { GpuInfo.detect() }.getOrNull() + 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) + 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)" }) + 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") + ")") + } + val prefs = context.getSharedPreferences("graphics_report", Context.MODE_PRIVATE) + val previous = prefs.getString("lastDrivers", null) + val now = "display ${SessionPrefs.androidDriver(context).ifEmpty { "(auto)" }}, runtime ${linux.ifEmpty { "(default)" }}, bridge ${DeviceSupport.vkBridge(context)}, venus ${VenusComponent.wanted(context)}" + appendLine("previous session's drivers: " + (previous ?: "(none recorded)") + if (previous != null && previous != now) " << CHANGED" else "") + prefs.edit().putString("lastDrivers", now).apply() + DriverBundle.active(context)?.let { b -> + appendLine("pair: ${b.name} ${b.version} (bundle ${b.id})") + release(context, b.id)?.let { appendLine("pair release: $it") } + } + if (gpu != null) { + val pairs = DriverPairs.from(TurnipReleases.cached(context)) + appendLine("auto would pick: " + (DriverPairs.recommendedKey(gpu, pairs) ?: "(no pair: system driver or bridge)")) + } + appendLine("frame generation: " + runCatching { com.droiddeck.launcher.gpu.FrameGen.mode(context).toString() }.getOrDefault("?") + + " (engine=off means it is switched off in Play settings; a driver that fails LSFG's gates logs \"device gates\" below)") + 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) { + appendLine("family: ${gpu.family} (${gpu.supportText})") + appendLine("name: ${gpu.name}" + if (gpu.model > 0) ", model ${gpu.model} (${gpu.modelSource})" else "") + } + appendLine("vulkan device (app): " + (VulkanInfo.cachedOrNull()?.get("device") ?: "(not probed)")) + appendLine("system vulkan hal: " + (SystemVulkanDriver.hal() ?: "none")) + read("/sys/class/misc/mali0/device/gpuinfo")?.let { appendLine("mali gpuinfo: $it") } + appendLine("android: ${Build.VERSION.RELEASE} (sdk ${Build.VERSION.SDK_INT}), ${Build.MANUFACTURER} ${Build.MODEL}") + val soc = if (Build.VERSION.SDK_INT >= 31) "${Build.SOC_MANUFACTURER} ${Build.SOC_MODEL}" else Build.HARDWARE + appendLine("soc: $soc, board ${Build.BOARD}, hardware ${Build.HARDWARE}") + appendLine("kernel: " + (System.getProperty("os.version") ?: "?")) + appendLine() + appendLine("-- gpu nodes (from the app; not opened)") + val dri = File("/dev/dri").list()?.sorted()?.map { "/dev/dri/$it" }.orEmpty() + for (path in listOf("/dev/kgsl-3d0", "/dev/mali0") + dri) appendLine(node(path)) + if (dri.isEmpty()) appendLine("/dev/dri: " + if (File("/dev/dri").exists()) "not listable" else "absent") + appendLine() + appendLine("-- guest environment (graphics)") + guest.filter { e -> ENV_PREFIXES.any { e.startsWith(it) } }.sorted().forEach { appendLine(it) } + appendLine() + } + + /** Which backend this session's Vulkan goes through, as the session decides it. */ + private fun path(context: Context): String = when { + DeviceSupport.adreno() -> "Turnip (Adreno, KGSL)" + VenusComponent.wanted(context) -> "Mali (Venus): Mesa Venus over vtest to the phone's own Vulkan driver, with the Mali compatibility layer" + DeviceSupport.vkBridge(context) -> "Mali bridge (#517): the phone's own Vulkan driver through the bridge" + DeviceSupport.openDriverActive(context) -> "open driver pair (PanVK / RADV)" + SystemVulkanDriver.usesDefault(SessionPrefs.linuxDriver(context)) && SystemVulkanDriver.isAvailable() -> + "system Vulkan (#570): ${SystemVulkanDriver.gpuName()} driver through libhybris" + SessionPrefs.linuxDriver(context).isNotEmpty() -> "imported runtime driver ${SessionPrefs.linuxDriver(context)}" + else -> "none for this GPU (no Adreno, no system HAL, no pair, bridge off)" + } + + /** The release tag and download a pair bundle came from, when the last release check knows it. */ + private fun release(context: Context, bundleId: String): String? { + val bundles = TurnipReleases.cached(context)?.assets?.filter { it.bundle }.orEmpty() + val asset = bundles.firstOrNull { it.name.removeSuffix("-Pair.zip") == bundleId } + ?: bundles.firstOrNull { bundleId.startsWith(it.name.removeSuffix("-Pair.zip") + "-") } + ?: return null + val installed = TurnipReleases.installedBuiltOn(context, asset) + return "${asset.tag} ${asset.url}" + + (if (installed.isNotEmpty()) ", installed build uploaded $installed" else "") + + (if (asset.builtOn.isNotEmpty()) ", listed build uploaded ${asset.builtOn}" else "") + + (if (TurnipReleases.updateAvailable(context, asset)) " << NEWER BUILD AVAILABLE" else "") + } + + private fun node(path: String): String { + val f = File(path) + if (!f.exists()) return "$path: absent" + val access = (if (f.canRead()) "r" else "-") + (if (f.canWrite()) "w" else "-") + val rdev = runCatching { Os.stat(path).st_rdev }.getOrNull() + val numbers = rdev?.let { " ${major(it)}:${minor(it)}" }.orEmpty() + val label = runCatching { String(Os.getxattr(path, "security.selinux")).trimEnd('\u0000') }.getOrNull() + return "$path: $access$numbers" + (label?.let { " $it" } ?: "") + } + + /** Linux's dev_t split (glibc's gnu_dev_major / gnu_dev_minor). */ + internal fun major(dev: Long): Long = ((dev ushr 8) and 0xfff) or ((dev ushr 32) and 0xfffff000L) + internal fun minor(dev: Long): Long = (dev and 0xff) or ((dev ushr 12) and 0xffffff00L) + + private fun read(path: String): String? = FileUtils.readString(File(path))?.trim()?.takeIf { it.isNotEmpty() } + + /** The compositor's driver lines from the app's own log. */ + private val COMPOSITOR = Regex( + """vk_present|waylandcomp|vk_loader|compositor|vkCreateDevice|extension|adrenotools|TurnipDriver|""" + + """graphics driver|display driver|DD_PRESENT_FAULT|SystemVulkan|vkbridge|VkBridge|mali_gralloc|panvk|PanVK|radv|MESA|native buffer|first frame|present|""" + + """lsfg|FrameGen|device gates|AAudio|directaudio|pulse|gralloc|dma.?buf|modifier|import""", + 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|kbase|AAUDIO|client sink|Xwayland|\(EE\)|glamor|XWAYLAND_NO_GLAMOR""", 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. + */ + fun finish(dir: File) { + runCatching { + val report = File(dir, FILE) + 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() + val fallbackLines = File(dir, "vkbridge-fallback").takeIf { it.isFile }?.readLines()?.map { it.trim() }?.filter { it.isNotEmpty() } + val fellBack = fallbackLines?.firstOrNull() + val fallbackReason = fallbackLines?.getOrNull(1).orEmpty() + runCatching { SessionPrefs.setBridgeFellBack(appContext ?: return@runCatching, fellBack != null, fallbackReason) } + val limits = File(dir, "limits.txt").takeIf { it.isFile }?.readText()?.trim() + val audio = File(dir, "audio.log").takeIf { it.isFile }?.readText().orEmpty() + report.appendText(buildString { + limits?.let { appendLine("open files limit: $it") } + fellBack?.let { + if (fallbackReason == "memory") appendLine("!! MALI BRIDGE FELL BACK: memory sharing = none (no method passed the server's self-test); the session ran on $it") + else appendLine("!! MALI BRIDGE FELL BACK: the self-test failed images or draws; the session ran on $it") + } + com.droiddeck.launcher.wayland.WaylandCompositor.compositorFault().takeIf { it.isNotEmpty() }?.let { + appendLine("!! DISPLAY FAILED: $it") + } + com.droiddeck.launcher.wayland.WaylandCompositor.displayDriver().takeIf { it.isNotEmpty() }?.let { + appendLine("display driver (as loaded): $it") + } + appContext?.let { ctx -> + if (SessionPrefs.venus(ctx)) VenusComponent.hostVulkanTooOld(ctx)?.let { + appendLine("!! VENUS OFF: the phone's driver reports Vulkan $it; gamescope needs 1.2 or newer, so the session did not use Venus") + } + } + if (audio.contains("AAUDIO_ERROR_DISCONNECTED")) { + appendLine("!! SOUND: Android refused the audio output (AAUDIO_ERROR_DISCONNECTED) - rebooting the phone usually fixes this") + } + 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)") + } + if (guestLines.any { it.contains("MEM_EXEC_INIT") }) { + appendLine("note: kbase refused KBASE_IOCTL_MEM_EXEC_INIT with EPERM. That answer comes from the kbase driver") + appendLine(" itself (proot does not filter ioctls; Android's seccomp would kill or return ENOSYS; SELinux") + appendLine(" would return EACCES), so it is the kernel's policy for this context, not the session's.") + } + 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() + appendLine("-- game launches with detailed logs: ${games.size}") + games.forEach { appendLine(it.name) } + appendLine("== session end " + SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(Date())) + }) + capGames(File(dir, GAMES_DIR)) + }.onFailure { android.util.Log.w("GraphicsReport", "could not finish $FILE", it) } + } + + /** Cuts each file in [games] to [GAME_FILE_MAX] and drops the oldest launches past [GAMES_TOTAL_MAX]. */ + internal fun capGames(games: File, fileMax: Long = GAME_FILE_MAX, totalMax: Long = GAMES_TOTAL_MAX) { + if (!games.isDirectory) return + games.walkTopDown().filter { it.isFile && it.length() > fileMax }.forEach { f -> + runCatching { java.io.RandomAccessFile(f, "rw").use { it.setLength(fileMax) } } + } + val launches = games.listFiles()?.filter { it.isDirectory }?.sortedBy { it.name }.orEmpty().toMutableList() + fun size(d: File) = d.walkTopDown().filter { it.isFile }.sumOf { it.length() } + var total = launches.sumOf { size(it) } + while (total > totalMax && launches.size > 1) { + val oldest = launches.removeAt(0) + total -= size(oldest) + FileUtils.delete(oldest) + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/OrphanReaper.kt b/app/src/main/java/com/droiddeck/launcher/session/OrphanReaper.kt index 300306f8c7..cbcd904bc1 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/OrphanReaper.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/OrphanReaper.kt @@ -11,6 +11,22 @@ object OrphanReaper { fun release(pid: Int) { kept.remove(pid) } + fun hasOtherProcesses(): Boolean = hasOtherProcesses( + File("/proc").list()?.mapNotNull { it.toIntOrNull() }, android.os.Process.myPid(), + ) { pid -> + try { + android.system.Os.kill(pid, 0) + true + } catch (error: android.system.ErrnoException) { + error.errno != android.system.OsConstants.ESRCH && error.errno != android.system.OsConstants.EPERM + } catch (error: SecurityException) { + true + } + } + + internal fun hasOtherProcesses(pids: List<Int>?, ownPid: Int, signalable: (Int) -> Boolean): Boolean = + pids == null || pids.any { it > 1 && it != ownPid && signalable(it) } + fun reap(reason: String, matching: (String) -> Boolean = { true }): Int { val me = android.os.Process.myPid() val uid = android.os.Process.myUid() diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 4fc0043043..cb766a2de3 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -502,14 +502,20 @@ object SessionArtifacts { return true } + /** + * Finishes the folders of sessions whose process died without its teardown. Returns true when + * the newest of them ended because Android killed the app for memory, so the app can say so + * (a game "crashing" on a phone with little free RAM is usually this, not a driver fault). + */ @Synchronized - fun finishAbandoned(context: Context, beforeGuestStart: Boolean = false) { + fun finishAbandoned(context: Context, beforeGuestStart: Boolean = false): Boolean { val stopWhenSessionStarts = !beforeGuestStart val parent = LinuxRuntime.logDir(context) val abandoned = parent.listFiles { f -> SessionPaths.isSessionFolder(f) && !File(f, COMPLETE_MARKER).exists() && !inFlight(f) - }?.sortedWith(SessionPaths.chronological) ?: return - if (abandoned.isEmpty()) return + }?.sortedWith(SessionPaths.chronological) ?: return false + if (abandoned.isEmpty()) return false + var killedForMemory = false val current = SessionPaths.current() val latestPreviousSession = SessionPaths.sessionFolders(context).lastOrNull { it != current } LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) @@ -534,8 +540,10 @@ object SessionArtifacts { "audio.log, device.txt) were on disk already and are as they were left.\n" + (if (newest) "" else "Steam's logs are not included: a later session has overwritten them.\n") + "crash.log holds Android's crash buffer as of the next app start - if this\n" + - "session died of a crash, the entry is in there unless the device rebooted.\n" + "session died of a crash, the entry is in there unless the device rebooted.\n" + + (if (newest) exitReasons(context) else "") ) + if (newest && lastExitForMemory(context)) killedForMemory = true } if (recoveryPreviouslyAttempted && !runtimeCaptured.exists() && (runtimeExpired.exists() || !beforeGuestStart) && @@ -593,7 +601,7 @@ object SessionArtifacts { break } SessionEvents.record("session.artifacts_recovered", mapOf("newest" to newest), dir) - if (beforeGuestStart) return + if (beforeGuestStart) break val scrubbed = scrubTree(record) { stopWhenSessionStarts && SessionState.running } val marked = markScrubbed(scrubbed) if (scrubbed.deferred) break @@ -604,6 +612,54 @@ object SessionArtifacts { Log.w(TAG, "could not finish $dir", e) } } + // Whoever finishes the folder first (the agent provider starts before the activity) leaves + // the notice for the launcher to show. + if (killedForMemory) SessionPrefs.setMemoryKillNotice(context, true) + return killedForMemory + } + + /** Android's newest record for this app's main process says it was killed for memory. */ + private fun lastExitForMemory(context: Context): Boolean { + if (android.os.Build.VERSION.SDK_INT < 30) return false + return runCatching { + val am = context.getSystemService(android.app.ActivityManager::class.java) ?: return false + am.getHistoricalProcessExitReasons(context.packageName, 0, 3) + .firstOrNull { it.processName == context.packageName } + ?.reason == android.app.ApplicationExitInfo.REASON_LOW_MEMORY + }.getOrDefault(false) + } + + private fun exitReasons(context: Context): String { + if (android.os.Build.VERSION.SDK_INT < 30) return "" + return runCatching { + val am = context.getSystemService(android.app.ActivityManager::class.java) ?: return "" + val reasons = am.getHistoricalProcessExitReasons(context.packageName, 0, 3) + if (reasons.isEmpty()) return "" + val fmt = java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss", java.util.Locale.US) + buildString { + append("\nAndroid's record of how this app's recent processes ended (newest first):\n") + reasons.forEach { r -> + append(" ${fmt.format(java.util.Date(r.timestamp))} ${r.processName} pid ${r.pid}: reason ${reasonName(r.reason)}, " + + "status ${r.status}, importance ${r.importance}, pss ${r.pss / 1024} MB, rss ${r.rss / 1024} MB" + + (r.description?.let { " - $it" } ?: "") + "\n") + } + } + }.getOrDefault("") + } + + private fun reasonName(reason: Int): String = when (reason) { + android.app.ApplicationExitInfo.REASON_LOW_MEMORY -> "LOW_MEMORY (killed for memory)" + android.app.ApplicationExitInfo.REASON_SIGNALED -> "SIGNALED" + android.app.ApplicationExitInfo.REASON_CRASH -> "CRASH" + android.app.ApplicationExitInfo.REASON_CRASH_NATIVE -> "CRASH_NATIVE" + android.app.ApplicationExitInfo.REASON_ANR -> "ANR" + android.app.ApplicationExitInfo.REASON_EXCESSIVE_RESOURCE_USAGE -> "EXCESSIVE_RESOURCE_USAGE" + android.app.ApplicationExitInfo.REASON_USER_REQUESTED -> "USER_REQUESTED" + android.app.ApplicationExitInfo.REASON_USER_STOPPED -> "USER_STOPPED" + android.app.ApplicationExitInfo.REASON_EXIT_SELF -> "EXIT_SELF" + android.app.ApplicationExitInfo.REASON_DEPENDENCY_DIED -> "DEPENDENCY_DIED" + android.app.ApplicationExitInfo.REASON_OTHER -> "OTHER" + else -> reason.toString() } @Synchronized diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 3b0172136c..cb9b5391fc 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -45,6 +45,7 @@ object SessionFiles { "usr/local/bin/droiddeck-msi-install" to "usr/local/bin/droiddeck-msi-install", "usr/local/bin/droiddeck-esync" to "usr/local/bin/droiddeck-esync", "usr/local/bin/droiddeck-steam-compat" to "usr/local/bin/droiddeck-steam-compat", + "usr/local/bin/droiddeck-steam-taskset" to "usr/local/libexec/droiddeck-steam/taskset", "usr/local/bin/droiddeck-fex" to "usr/local/bin/droiddeck-fex", "libblsession.so" to "usr/local/lib/libblsession.so", "libfakeinput.so" to "usr/local/lib/libfakeinput.so", @@ -143,6 +144,8 @@ object SessionFiles { "usr/local/lib/mangoapp/libtraceevent.so.1", "usr/local/lib/mangoapp/libtracefs.so.1", ).map { it to it } + val xclipse = listOf("libVkLayer_droiddeck_xclipse.so", "VkLayer_droiddeck_xclipse.json") + .map { "usr/local/lib/droiddeck-xclipse/$it" } val msitools = listOf("msiinfo", "cabextract", "7z", "7z.so", "libmsi-1.0.so.0", "libgsf-1.so.114", "libgcab-1.0.so.0") .map { "usr/local/lib/droiddeck-msitools/$it" } + listOf("NOTICE", "GPL-2", "GPL-3", "LGPL-2.1", "7zip-License", "7zip-unRarLicense").map { "usr/local/share/licenses/droiddeck-msitools/$it" } @@ -172,8 +175,16 @@ object SessionFiles { val fexPreloads = listOf("x86_64", "i386").flatMap { arch -> listOf("libblsession.so", "libfakeinput.so", "libfaultreport.so").map { "$arch/$it" to "usr/local/lib/droiddeck-fex/$arch/$it" } } + listOf("libvulkan-thunk.so", "libwebkitinput.so").map { "x86_64/$it" to "usr/local/lib/droiddeck-fex/x86_64/$it" } + // The Mali compatibility layer (tools/venus/layer, David Cimo): an implicit Vulkan layer that + // fills in the features DXVK requires and Mali lacks. Idle outside Wine and on GPUs that have them. + // Never staged on an Adreno: an implicit layer is loaded into every Vulkan program there. + val maliCompat = if (com.droiddeck.launcher.core.DeviceSupport.adreno()) emptyList() else listOf( + "usr/local/lib/droiddeck-mali/libVkLayer_droiddeck_mali_compat.so", + "usr/local/share/vulkan/implicit_layer.d/VkLayer_droiddeck_mali_compat.json", + ).map { it to it } val optional = (arrayOf( "usr/local/bin/gamescope" to "usr/local/bin/gamescope", + "usr/local/bin/droiddeck-glprobe" to "usr/local/bin/droiddeck-glprobe", "usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so" to "usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so", "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", @@ -182,7 +193,7 @@ object SessionFiles { "usr/local/lib/droiddeck-pipewire.tzst" to "usr/local/lib/droiddeck-pipewire.tzst", "usr/local/share/licenses/uruntime/LICENSE" to "usr/local/share/licenses/uruntime/LICENSE", "usr/local/lib/droiddeck-dirt/ws2_32.dll" to "usr/local/lib/droiddeck-dirt/ws2_32.dll", - ) + mangoapp + msitools.map { it to it } + vr + gpuLoad + fexPreloads).filter { (asset, _) -> + ) + mangoapp + xclipse.map { it to it } + maliCompat + msitools.map { it to it } + vr + gpuLoad + fexPreloads).filter { (asset, _) -> val dir = asset.substringBeforeLast('/') runCatching { context.assets.list("linuxfs/$dir")?.contains(asset.substringAfterLast('/')) == true }.getOrDefault(false) } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 2e7f3b6c54..a7541e2619 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -8,6 +8,8 @@ import com.droiddeck.launcher.core.GameEnvironment import com.droiddeck.launcher.core.TextureFiltering import com.droiddeck.launcher.gpu.Cardboard import com.droiddeck.launcher.gpu.ScreenEffects +import com.droiddeck.launcher.gpu.SystemVulkanDriver +import com.droiddeck.launcher.gpu.TurnipDriver import org.json.JSONObject import java.io.File @@ -504,6 +506,17 @@ object SessionPrefs { p.edit().putString("gpuDriverMode", if (chosen) GPU_DRIVERS_MANUAL else GPU_DRIVERS_AUTO).apply() } + @JvmStatic + fun ensurePowerVrAutoDrivers(context: Context) { + if (com.droiddeck.launcher.core.DeviceSupport.openDriverActive(context)) return + ensurePowerVrAutoDrivers(context, SystemVulkanDriver.isPowerVr()) + } + + internal fun ensurePowerVrAutoDrivers(context: Context, powerVr: Boolean) { + if (!powerVr || gpuDriverMode(context) != GPU_DRIVERS_AUTO) return + prefs(context).edit().putString("linuxDriver", "").putString("androidDriver", TurnipDriver.AUTO).apply() + } + fun gpuAutoInstalled(context: Context): Set<String> = prefs(context).getStringSet("gpuAutoInstalled", emptySet()).orEmpty() @@ -775,8 +788,62 @@ object SessionPrefs { @JvmStatic fun vkBridge(context: Context): Boolean = prefs(context).getBoolean("vkBridge", com.droiddeck.launcher.core.DeviceSupport.mali()) + fun venus(context: Context): Boolean = prefs(context).getBoolean("venus", false) + + fun hostVulkanApi(context: Context): String = prefs(context).getString("hostVulkanApi", "").orEmpty() + + fun setHostVulkanApi(context: Context, api: String) { + if (api != hostVulkanApi(context)) prefs(context).edit().putString("hostVulkanApi", api).apply() + } + + fun bridgeFellBack(context: Context): Boolean = prefs(context).getBoolean("bridgeFellBack", false) + + fun bridgeFellBackForMemory(context: Context): Boolean = prefs(context).getString("bridgeFallbackReason", "") == "memory" + + fun setBridgeFellBack(context: Context, on: Boolean, reason: String = "") { + prefs(context).edit().putBoolean("bridgeFellBack", on).putString("bridgeFallbackReason", if (on) reason else "").apply() + } + + fun steamGpuCompositing(context: Context): Boolean { + if (!steamGpuCompositingAllowed()) { + if (prefs(context).getBoolean("steamGpuCompositing", false)) + prefs(context).edit().putBoolean("steamGpuCompositing", false).apply() + return false + } + return prefs(context).getBoolean("steamGpuCompositing", false) + } + + fun steamGpuCompositingAllowed(): Boolean = + !com.droiddeck.launcher.core.DeviceSupport.adreno() && !com.droiddeck.launcher.core.DeviceSupport.mali() + + fun setSteamGpuCompositing(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("steamGpuCompositing", on && steamGpuCompositingAllowed()).apply() + } + + fun takeMemoryKillNotice(context: Context): Boolean { + val on = prefs(context).getBoolean("memoryKillNotice", false) + if (on) prefs(context).edit().putBoolean("memoryKillNotice", false).apply() + return on + } + + fun setMemoryKillNotice(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("memoryKillNotice", on).apply() + } + + fun maliFallbackByAuto(context: Context): String = prefs(context).getString("maliFallbackByAuto", "").orEmpty() + + fun maliFallbackKnown(context: Context): Boolean = prefs(context).contains("maliFallbackByAuto") + + fun setMaliFallbackByAuto(context: Context, route: String) { + prefs(context).edit().putString("maliFallbackByAuto", route).apply() + } + + fun setVenus(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("venus", on).apply() + } + fun setVkBridge(context: Context, on: Boolean) { - prefs(context).edit().putBoolean("vkBridge", on).apply() + prefs(context).edit().putBoolean("vkBridge", on).putBoolean("bridgeFellBack", false).apply() } @JvmStatic @@ -786,6 +853,7 @@ object SessionPrefs { prefs(context).edit().putBoolean("bridgeProtonDxvk", on).apply() } + @JvmStatic fun vkBridgeSafe(context: Context): Boolean = prefs(context).getBoolean("vkBridgeSafe", true) fun setVkBridgeSafe(context: Context, on: Boolean) { @@ -886,6 +954,13 @@ object SessionPrefs { } } + fun detailedGraphicsLogs(context: Context): Boolean = + prefs(context).getBoolean("detailedGraphicsLogs", false) + + fun setDetailedGraphicsLogs(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("detailedGraphicsLogs", on).apply() + } + internal fun gameDebugLogsEffective( context: Context, logs: Boolean = logsEnabled(context), 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 1a6e00bcf0..72e5543d3e 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -3,6 +3,7 @@ package com.droiddeck.launcher.session import com.droiddeck.launcher.core.AddonPack import com.droiddeck.launcher.gpu.LinuxVulkanDriver import com.droiddeck.launcher.gpu.LinuxVulkanDriverManager +import com.droiddeck.launcher.gpu.SystemVulkanDriver import android.app.Notification import android.app.NotificationChannel @@ -405,6 +406,7 @@ class SessionService : Service() { private fun collectSessionArtifacts(dir: File, steamArch: String?) { SessionLogCapture.stopFor(dir) try { + GraphicsReport.finish(dir) SessionArtifacts.collect(this, dir, "session stopped", steamArch) } finally { SessionPaths.release(this, dir) @@ -424,6 +426,21 @@ class SessionService : Service() { return lines } + /** Whether a kernel release ("6.1.157-android14-11") is older than [major].[minor]; false if unreadable. */ + internal fun kernelBefore(release: String, major: Int, minor: Int): Boolean { + val m = Regex("""^(\d+)\.(\d+)""").find(release) ?: return false + val (a, b) = m.destructured + return a.toInt() < major || (a.toInt() == major && b.toInt() < minor) + } + + /** Whether the newest finished session's log shows Xwayland itself crashing. */ + private fun lastXwaylandCrashed(): Boolean = runCatching { + val last = SessionPaths.sessionFolders(this).filter { it != SessionPaths.current() }.lastOrNull() ?: return false + val log = File(last, "session.log").takeIf { it.isFile } ?: return false + log.useLines { lines -> lines.any { it.contains("(EE) Segmentation fault") } } && + log.useLines { lines -> lines.any { it.contains("X11 I/O error") || it.contains("Xwayland", ignoreCase = true) } } + }.getOrDefault(false) + private fun tuDebugOverride(): String? = File(Environment.getExternalStorageDirectory(), TU_DEBUG_SWITCH) .takeIf { it.isFile }?.let { FileUtils.readString(it)?.trim() }?.takeIf { it.isNotEmpty() } @@ -435,6 +452,13 @@ class SessionService : Service() { private fun runSession(gen: Int) { + SessionPrefs.ensurePowerVrAutoDrivers(this) + if (!com.droiddeck.launcher.core.DeviceSupport.adreno()) { + com.droiddeck.launcher.gpu.VulkanInfo.query()["api"]?.let { SessionPrefs.setHostVulkanApi(this, it) } + if (SessionPrefs.venus(this)) VenusComponent.hostVulkanTooOld(this)?.let { + Log.w(TAG, "venus: off for this session - the phone's driver reports Vulkan $it and gamescope needs 1.2 or newer; the session uses the PanVK pair or the bridge") + } + } SessionTerminal.clear() com.droiddeck.launcher.gpu.TpUbwcHint.forThisDevice(this) try { @@ -476,7 +500,17 @@ class SessionService : Service() { val agentEnvironment = runCatching { com.droiddeck.launcher.agent.AgentEnv.beginSession(this) } .onFailure { Log.w(TAG, "agent environment skipped", it) } .getOrDefault(emptyList()) - SessionFiles.stage(this, root, startsSession = true) + try { + if (SystemVulkanDriver.usesDefault(SessionPrefs.linuxDriver(this))) { + SystemVulkanDriver.prepare(this) + pruneSystemVulkanRuntime() + } + SessionFiles.stage(this, root, startsSession = true) + } catch (error: Exception) { + Log.e(TAG, "Could not prepare the session graphics runtime", error) + stopSession(-1, gen) + return + } SessionArtifacts.awaitCollections() SessionArtifacts.finishAbandoned(this, beforeGuestStart = true) VacDiagnostics.arm(this) @@ -512,18 +546,28 @@ class SessionService : Service() { .onSuccess { if (it != null) Log.i(TAG, it) } .onFailure { Log.w(TAG, "forced components", it) } } - addClientEnvironment(guest, steamHere, agentEnvironment) + try { + addClientEnvironment(guest, steamHere, agentEnvironment) + } catch (e: IllegalStateException) { + Log.e(TAG, "Could not resolve the selected Linux Vulkan driver", e) + failSession(gen, "VULKAN_DRIVER_UNAVAILABLE", e.message ?: "Selected Linux Vulkan driver is unavailable", -1) + stopSession(-1, gen) + return + } if (steamHere) guest.add("BL_EPIC_APP_ID=" + com.droiddeck.launcher.stores.epic.EpicClient.shortcutAppId) val fastPathAt = guest.size val pulse = startAudio(guest, sessionDir, directAudioPack) + startVkBridge(guest, sessionDir) + if (VenusComponent.wanted(this)) { + components.add(VenusComponent(File(sessionDir, "venus.log")).also { it.attach(this) }) + } if (steamHere) { val encoder = VideoEncodeBridge(File(filesDir, "venc/venc.sock")) encoder.attach(this) components.add(encoder) guest.add("BL_VENC_SOCKET=" + encoder.socket.absolutePath) } - startVkBridge(guest, sessionDir) com.droiddeck.launcher.gpu.ClockLogComponent(File(sessionDir, "clocks.log")).let { it.attach(this) components.add(it) @@ -574,6 +618,10 @@ class SessionService : Service() { guest.add("BL_LAUNCH_DIR=" + sessionRoot.path) GameStorage.effective(this)?.let { guest.add("BL_LIBRARY_LABEL=" + it.label.replace('"', ' ')) } if (SessionState.mode == MODE_STEAM && SessionState.steamUi == "desktop") guest.add("BL_STEAM_UI=desktop") + // Detailed graphics logs: per-game logs and the guest's Vulkan summary (a GPU that is not + // an Adreno, or Setup's switch), and graphics-report.txt for every session. + if (GraphicsReport.detailed(this)) guest.add("BL_GAME_LOGS=1") + GraphicsReport.begin(this, sessionDir, guest) val shellGuest = ArrayList(guest).apply { add("SHELL=/bin/bash") add("TERM=xterm-256color") @@ -673,7 +721,14 @@ class SessionService : Service() { if (gen == sessionGen) components.clear() return } - components.forEach { it.start() } + try { + components.forEach { it.start() } + } catch (e: Exception) { + Log.e(TAG, "Could not start the session components", e) + failSession(gen, "COMPONENT_START_FAILED", e.message ?: "Session component could not be started", -1) + stopSession(-1, gen) + return + } val line = command.joinToString(" ") { it.replace("\\", "\\\\").replace(" ", "\\ ") @@ -816,7 +871,12 @@ 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 venus = VenusComponent.wanted(this) + if (venus) { + VenusComponent.guestEnv(this).forEach { guest.add(it) } + } else { + LinuxRuntime.vulkanIcd(this)?.let { guest.add("VK_ICD_FILENAMES=" + it.path) } + } val linuxDriverId = SessionPrefs.linuxDriver(this) SessionState.runtimeDriver = linuxDriverId com.droiddeck.launcher.gpu.AutoDriverTrial.sessionStarting( @@ -825,11 +885,39 @@ class SessionService : Service() { ?: SessionPrefs.androidDriver(this), linuxDriverId, ) - if (!com.droiddeck.launcher.core.DeviceSupport.vkBridge(this)) LinuxVulkanDriver.resolveIcdPath(this, linuxDriverId) + val bridge = com.droiddeck.launcher.core.DeviceSupport.vkBridge(this) + if (!bridge && !venus && SystemVulkanDriver.usesDefault(linuxDriverId)) { + SystemVulkanDriver.addEnvironment(this, guest) + } + (if (bridge || venus) null else LinuxVulkanDriver.resolveIcdPath(this, linuxDriverId)) ?.let { guest.add(LinuxVulkanDriver.ENV + "=" + it) } + if (!com.droiddeck.launcher.core.DeviceSupport.adreno() && lastXwaylandCrashed()) { + guest.add("XWAYLAND_NO_GLAMOR=1") + Log.w(TAG, "xwayland: the last session's Xwayland crashed; glamor off for this one (XWAYLAND_NO_GLAMOR=1)") + } + if (!com.droiddeck.launcher.core.DeviceSupport.adreno()) guest.add("BL_RAISE_NOFILE=1") + if (!com.droiddeck.launcher.core.DeviceSupport.adreno()) { + val kernel = System.getProperty("os.version").orEmpty() + val old = kernelBefore(kernel, 6, 6) + val maliNode = LinuxRuntime.gpuStandIn(this) == LinuxRuntime.MALI_DEVICE + if (old || maliNode) { + guest.add("GAMESCOPE_DISABLE_EXPLICIT_SYNC=1") + Log.i(TAG, "gamescope: explicit sync off (" + (if (old) "kernel $kernel has no SYNCOBJ_EVENTFD" else "Mali stand-in node has no syncobjs") + ")") + } + } + if (!bridge && com.droiddeck.launcher.core.DeviceSupport.openDriverActive(this)) { + if (SessionPrefs.steamGpuCompositing(this)) { + Log.i(TAG, "steam: GPU web compositing (Setup's \"Steam interface: GPU drawing\")") + } else { + guest.add("BL_STEAM_SOFT_COMPOSITING=1") + Log.i(TAG, "steam: software web compositing for the open driver pair (GPU raster kept)") + } + guest.add("BL_OPEN_DRIVER=1") + LinuxRuntime.gpuStandIn(this)?.takeIf { it == LinuxRuntime.MALI_DEVICE }?.let { guest.add("BL_DRM_STANDIN=$it") } + } val tuOverride = tuDebugOverride() val tuDriver = sysmemDriver(linuxDriverId) - (tuOverride ?: "sysmem".takeIf { tuDriver || SessionPrefs.tuSysmem(this) })?.let { guest.add("TU_DEBUG=$it") } + if (!venus && com.droiddeck.launcher.core.DeviceSupport.adreno()) (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") @@ -878,9 +966,6 @@ class SessionService : Service() { .takeIf { it.isNotEmpty() }?.let { guest.add("BL_GAME_CPUS=$it") } } - private fun noSteamGame(): Boolean = - SessionState.mode == MODE_RUN && SessionState.program in setOf(NoSteamLaunch.PROTON_RUN, NoSteamLaunch.EPIC, NoSteamLaunch.BATTLENET) - private fun startVkBridge(guest: MutableList<String>, sessionDir: File) { if (!com.droiddeck.launcher.core.DeviceSupport.vkBridge(this)) return val socket = File(filesDir, "vkbridge/server.sock") @@ -888,6 +973,10 @@ class SessionService : Service() { bridge.attach(this) components.add(bridge) guest.add("BL_VKBRIDGE=1") + if (SessionPrefs.steamGpuCompositing(this)) guest.add("BL_STEAM_GPU_COMPOSITING=1") + SessionPrefs.linuxDriver(this).takeIf { it.isNotEmpty() } + ?.let { runCatching { LinuxVulkanDriver.resolveIcdPath(this, it) }.getOrNull() } + ?.let { guest.add("BL_VKBRIDGE_FALLBACK_ICD=$it") } guest.add("VKBRIDGE_SOCKET=" + socket.path) guest.add("VKBRIDGE_CLIENT_LOG=" + File(sessionDir, "vkbridge-client.log").path) guest.add("VKBRIDGE_MODE=" + SessionPrefs.vkBridgeMode(this)) @@ -897,6 +986,8 @@ class SessionService : Service() { } Log.i(TAG, "vkbridge: on (${com.droiddeck.launcher.core.DeviceSupport.gpuName(this)}, ${SessionPrefs.vkBridgeMode(this)} mode), socket $socket") } + private fun noSteamGame(): Boolean = + SessionState.mode == MODE_RUN && SessionState.program in setOf(NoSteamLaunch.PROTON_RUN, NoSteamLaunch.EPIC, NoSteamLaunch.BATTLENET) private fun startAudio(guest: MutableList<String>, sessionDir: File, directAudioPack: Boolean): PulseAudioComponent { val wantsDirectAudio = directAudioPack && @@ -1834,6 +1925,12 @@ class SessionService : Service() { }.onFailure { Log.w(TAG, "could not request Steam wake", it) } } + /** Background-only: preserve old runtimes until all earlier guest processes are gone. */ + private fun pruneSystemVulkanRuntime() { + runCatching { SystemVulkanDriver.pruneUnused(this, !OrphanReaper.hasOtherProcesses()) } + .onFailure { Log.w(TAG, "could not prune unused system Vulkan runtimes", it) } + } + private fun finishSessionStop(status: Int, stoppedGen: Int, afterStopped: () -> Unit = {}) { mainHandler.post { try { @@ -1973,10 +2070,12 @@ class SessionService : Service() { auxiliary.forEach { (pid, started) -> teardown(pid, started) } if (prootPid > 1) teardown(prootPid) killGuestLeftovers() + pruneSystemVulkanRuntime() finishSessionStop(status, stoppedGen, collectEnded) if (launcherEnded) importLauncherGames() }, "session-teardown").start() } else { + Thread({ pruneSystemVulkanRuntime() }, "system-vulkan-prune").start() Thread({ com.droiddeck.launcher.stores.gog.GogComet.end(stoppedSession) finishSessionStop(status, stoppedGen, collectEnded) diff --git a/app/src/main/java/com/droiddeck/launcher/session/VenusComponent.kt b/app/src/main/java/com/droiddeck/launcher/session/VenusComponent.kt new file mode 100644 index 0000000000..a1856a6a9c --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/VenusComponent.kt @@ -0,0 +1,131 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import android.os.Process +import android.util.Log +import com.droiddeck.launcher.core.DeviceSupport +import com.droiddeck.launcher.core.FileUtils +import com.droiddeck.launcher.core.HostProcess +import com.droiddeck.launcher.core.SessionPart +import java.io.File +import java.io.PrintWriter + +/** + * Vulkan for the session on a Mali, through Venus (the "Mali (Venus)" route; by David Cimo, + * DavidCimo/droiddeck-mali, ported to this branch). + * + * The guest's processes are glibc and cannot load the vendor's bionic driver. Instead they load + * Mesa's Venus ICD (libvulkan_virtio.so), which serializes every Vulkan call over a unix socket to + * virglrenderer's vtest server. The server runs here, on the Android side, and replays the calls + * on the device's own Vulkan driver. Both ends of the socket are under the app's files directory, + * which the session binds at its own path, so the same path works inside and out. + */ +class VenusComponent(private val logFile: File?) : SessionPart() { + @Volatile private var pid = -1 + + override fun start() { + val context = app() + stageIcd(context) + val libDir = context.applicationInfo.nativeLibraryDir + val socket = socket(context) + socket.delete() + val env = arrayOf( + "LD_LIBRARY_PATH=$libDir", + // vtest forks a render server per client; this is where its executable is. + "RENDER_SERVER_EXEC_PATH=$libDir/libvirgl_render_server.so", + "TMPDIR=" + context.cacheDir.path, + ) + val command = "$libDir/libvirgl_test_server.so --venus --no-virgl --socket-path " + socket.path + val out = logFile?.let { runCatching { PrintWriter(java.io.FileWriter(it, true)) }.getOrNull() } + pid = HostProcess.start(command, env, context.filesDir, { status -> + Log.w(TAG, "vtest server exited: $status") + out?.let { synchronized(it) { it.println("vtest server exited: $status"); it.flush() } } + }, { line -> + Log.i(TAG, line) + out?.let { synchronized(it) { it.println(line); it.flush() } } + }) + Log.i(TAG, "vtest server pid $pid on $socket") + } + + override fun stop() { + if (pid > 1) Process.killProcess(pid) + pid = -1 + } + + companion object { + private const val TAG = "Venus" + private const val ASSET = "venus/libvulkan_virtio.so" + private const val DIR = "venus" + private const val LIB = "libvulkan_virtio.so" + private const val ICD = "virtio_icd.json" + + /** + * The selection rule: Venus when Setup's "Mali (Venus)" is on, on a GPU that is neither an + * Adreno nor one the system-driver route covers (PowerVR, Xclipse), and the apk carries it. + * It then replaces the Mali bridge and any open driver pair for the session. + */ + @JvmStatic + fun wanted(context: Context): Boolean = + !DeviceSupport.adreno() && !com.droiddeck.launcher.gpu.SystemVulkanDriver.isAvailable() && + SessionPrefs.venus(context) && available(context) && hostVulkanTooOld(context) == null + + /** The phone driver's Vulkan version when it is below 1.2: gamescope skips such a device, so Venus cannot run. */ + @JvmStatic + fun hostVulkanTooOld(context: Context): String? { + val api = com.droiddeck.launcher.gpu.VulkanInfo.cachedOrNull()?.get("api") ?: SessionPrefs.hostVulkanApi(context) + val parts = api.split('.').mapNotNull { it.trim().toIntOrNull() } + if (parts.size < 2) return null + return api.takeIf { parts[0] < 1 || (parts[0] == 1 && parts[1] < 2) } + } + + /** Whether this apk carries the Venus component (tools/venus, venus.tzst). */ + @JvmStatic + fun available(context: Context): Boolean = runCatching { + context.assets.list(DIR)?.contains(LIB) == true && + File(context.applicationInfo.nativeLibraryDir, "libvirgl_test_server.so").isFile + }.getOrDefault(false) + + @JvmStatic + fun socket(context: Context): File = File(File(context.filesDir, DIR), "vtest.sock") + + /** What the guest needs to find the ICD and the server. */ + @JvmStatic + fun guestEnv(context: Context): List<String> { + val dir = File(context.filesDir, DIR) + return listOf( + "VK_ICD_FILENAMES=" + File(dir, ICD).path, + "VN_DEBUG=vtest", + "VTEST_SOCKET_NAME=" + socket(context).path, + // Xwayland has no DRI3 without a DRM node, so swapchains present through shared memory. + "MESA_VK_WSI_DEBUG=sw", + // The Mali compatibility layer in every process but gamescope, not only Wine: Zink + // (Steam's GL, Xwayland's glamor) requires robustness2's nullDescriptor, which the + // layer stands in for. The session script checks it and falls back to llvmpipe. + "DROIDDECK_MALI_COMPAT=1", + "BL_VENUS=1", + // gamescope's composite layout without immutable YCbCr samplers from the start + // (patch 0930): a Mali-G615 refused every composite pipeline with them, and testing + // that through Venus took the render server down. + "GAMESCOPE_NO_YCBCR_SAMPLERS=1", + ) + } + + /** Copies the ICD out of the APK when it changed, and writes its manifest with an absolute path. */ + private fun stageIcd(context: Context) { + val dir = File(context.filesDir, DIR).apply { mkdirs() } + val lib = File(dir, LIB) + // Copied again after every app update: the asset is compressed, so its size is unknown up front. + val installed = context.packageManager.getPackageInfo(context.packageName, 0).lastUpdateTime + if (!lib.isFile || lib.lastModified() < installed) { + val tmp = File(dir, "$LIB.tmp") + context.assets.open(ASSET).use { input -> tmp.outputStream().use { input.copyTo(it) } } + if (!tmp.renameTo(lib)) throw java.io.IOException("could not move the Venus ICD into place") + Log.i(TAG, "staged $lib (${lib.length()} bytes)") + } + if (!FileUtils.writeString( + File(dir, ICD), + """{"file_format_version":"1.0.1","ICD":{"library_path":"${lib.path}","api_version":"1.4.354"}}""", + )) throw java.io.IOException("could not write the Venus ICD manifest") + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt index 6c15923b69..43f613486d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt @@ -483,17 +483,27 @@ fun ComponentsPage( ) else -> { val st = compState(l) + val managedDxvk = ComponentsManager.runtimeManaged(l, gpu.systemPowerVr) val label = ComponentsManager.LABEL[l] ?: l if (st == null) InUseBar(false, stringResource(R.string.comp_no_proton), "") else { val reappliedAt = view?.reappliedAt?.takeIf { it > 0 }?.let { DateFormat.getTimeInstance(DateFormat.SHORT).format(Date(it * 1000)) } - InUseBar( - queued = st.queued != null, - sentence = (if (st.queued != null) stringResource(R.string.comp_next_queued, st.queued) else stringResource(R.string.comp_in_use, label, st.inUse)) - .let { if (reappliedAt != null) stringResource(R.string.comp_reapplied, it, reappliedAt) else it }, - note = if (view?.inUseByGame == true) stringResource(R.string.comp_waits) else stringResource(R.string.comp_applies_next_game), - onCancel = if (st.queued != null) onCancelQueued else null, - ) + Column { + InUseBar( + queued = st.queued != null, + sentence = (if (managedDxvk) stringResource(R.string.comp_in_use, label, stringResource(R.string.gpu_system_powervr)) + + (st.queued?.let { "\n" + stringResource(R.string.cmgr_powervr_dxvk_queued, it) } ?: "") + else if (st.queued != null) stringResource(R.string.comp_next_queued, st.queued) else stringResource(R.string.comp_in_use, label, st.inUse)) + .let { if (reappliedAt != null && !managedDxvk) stringResource(R.string.comp_reapplied, it, reappliedAt) else it }, + note = if (managedDxvk) "" else if (view?.inUseByGame == true) stringResource(R.string.comp_waits) else stringResource(R.string.comp_applies_next_game), + onCancel = if (st.queued != null) onCancelQueued else null, + maxLines = if (managedDxvk && st.queued != null) 3 else 2, + ) + if (managedDxvk) Text( + stringResource(R.string.cmgr_powervr_dxvk_managed), + fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 8.dp), + ) + } } } } @@ -537,16 +547,17 @@ fun ComponentsPage( } else -> { val label = ComponentsManager.LABEL[l] ?: l - val rows = installedFor(l, view, snapshot) + val managedDxvk = ComponentsManager.runtimeManaged(l, gpu.systemPowerVr) + val rows = installedFor(l, view, snapshot, managedDxvk) if (rows.isEmpty()) EmptyLine(stringResource(R.string.comp_nothing_stored, label)) val p = view?.proton rows.forEachIndexed { i, item -> val key = "row:$l:${item.file ?: item.protonVersion}" ChoiceLine( - item.name, item.detail, item.selected, item.removable, tag = item.tag, - modifier = (if (i == 0) Modifier.focusRequester(firstRow) else Modifier).trackRow(key, rowsAt), + item.name, item.detail, item.selected, item.removable, tag = item.tag, enabled = !managedDxvk, + modifier = (if (i == 0 && !managedDxvk) Modifier.focusRequester(firstRow) else Modifier).trackRow(key, rowsAt), onSelect = { - if (item.selected || p == null) return@ChoiceLine + if (managedDxvk || item.selected || p == null) return@ChoiceLine val waits = if (view.inUseByGame) ctx.getString(R.string.comp_waits_long) else ctx.getString(R.string.comp_applies_long) if (item.file != null) ask(key, right, ctx.getString(R.string.comp_swap_title, label), ctx.getString(R.string.comp_swap_body, item.name, p.name, waits), ctx.getString(R.string.comp_swap), false, item.name) { onSwap(item.file); flyHome(key, l) @@ -617,14 +628,19 @@ fun ComponentsPage( } } else -> { - SmallButton(stringResource(R.string.comp_import_wcp), onClick = onImport) + val managedDxvk = ComponentsManager.runtimeManaged(l, gpu.systemPowerVr) + SmallButton( + stringResource(R.string.comp_import_wcp), onClick = onImport, + modifier = if (managedDxvk) Modifier.focusRequester(firstRow) else Modifier, + ) val st = compState(l) val p = view?.proton val build = p?.let { ComponentsManager.safeName(it.version) } if (st != null && p != null && st.activeFile != null && view.originals.any { it.comp == l && it.protonVersion == build }) { val label = ComponentsManager.LABEL[l] ?: l Box(Modifier.trackRow("restore:$l", rowsAt)) { - FocusText(stringResource(R.string.comp_restore_original), pal.signal) { + if (managedDxvk) SmallButton(stringResource(R.string.comp_restore_original), enabled = false) {} + else FocusText(stringResource(R.string.comp_restore_original), pal.signal) { ask("restore:$l", false, ctx.getString(R.string.comp_restore_title, label), ctx.getString(R.string.comp_restore_original_body, p.name, label), ctx.getString(R.string.common_restore), false, ctx.getString(R.string.comp_restore_original)) { onRestore(build!!); flyHome("restore:$l", l) } @@ -770,6 +786,7 @@ fun ComponentsPage( protonChoice = gameProtonChoice, packages = snapshot?.packages.orEmpty(), componentChoices = gameComponents, + systemPowerVr = gpu.systemPowerVr, componentMenu = gameComponentMenu, protonMenu = gameProtonMenu, fexMenu = fexMenu, @@ -909,11 +926,11 @@ fun ComponentsPage( } @Composable -private fun installedFor(l: String, view: ComponentsManager.ProtonView?, snapshot: Snapshot?): List<InstalledItem> { +private fun installedFor(l: String, view: ComponentsManager.ProtonView?, snapshot: Snapshot?, runtimeManaged: Boolean = false): List<InstalledItem> { view ?: return emptyList() val st = view.components[l] ?: return emptyList() val build = ComponentsManager.safeName(view.proton.version) - val activeIsOriginal = st.activeFile == null + val activeIsOriginal = !runtimeManaged && st.activeFile == null return view.originals.filter { it.comp == l }.map { o -> val isCurrent = o.protonVersion == build InstalledItem( @@ -922,7 +939,7 @@ private fun installedFor(l: String, view: ComponentsManager.ProtonView?, snapsho "ORIGINAL", activeIsOriginal && isCurrent, !isCurrent, null, o.protonVersion, ) } + (snapshot?.packages ?: emptyList()).filter { it.comp == l }.map { s -> - InstalledItem(s.version, stringResource(R.string.common_size_mb, s.size / 1048576.0), "STORED", s.file == st.activeFile, true, s.file, null) + InstalledItem(s.version, stringResource(R.string.common_size_mb, s.size / 1048576.0), "STORED", !runtimeManaged && s.file == st.activeFile, true, s.file, null) } } @@ -961,11 +978,12 @@ private fun Stack( LayerCard( title = LayerTitle(l), value = when (l) { - GPU_TAB -> gpuCardValue(gpu, auto) + GPU_TAB -> if (gpu.systemPowerVr) stringResource(R.string.gpu_system_powervr) else gpuCardValue(gpu, auto) PROTON_TAB -> (view?.proton?.name ?: "") + " ▾" - else -> st?.let { if (it.activeFile == null) original else it.inUse } ?: "" + else -> if (ComponentsManager.runtimeManaged(l, gpu.systemPowerVr)) stringResource(R.string.gpu_system_powervr) + else st?.let { if (it.activeFile == null) original else it.inUse } ?: "" }, - swapped = l in ComponentsManager.COMPONENTS && st?.activeFile != null, + swapped = l in ComponentsManager.COMPONENTS && st?.activeFile != null && !ComponentsManager.runtimeManaged(l, gpu.systemPowerVr), selected = l == layer, landed = landed[l] ?: 0, ring = rings[l] ?: 0, modifier = Modifier.focusRequester(focus.getValue(l)).onGloballyPositioned { onPlaced(l, it.boundsInRoot()) }, @@ -1032,7 +1050,7 @@ private fun LayerCard( } @Composable -private fun InUseBar(queued: Boolean, sentence: String, note: String, onCancel: (() -> Unit)? = null) { +private fun InUseBar(queued: Boolean, sentence: String, note: String, onCancel: (() -> Unit)? = null, maxLines: Int = 2) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current Row( @@ -1041,7 +1059,7 @@ private fun InUseBar(queued: Boolean, sentence: String, note: String, onCancel: .border(1.dp, pal.line, RoundedCornerShape(12.dp)).padding(horizontal = 14.dp, vertical = 8.dp), ) { Box(Modifier.size(8.dp).background(if (queued) QUEUED else pal.good, CircleShape)) - Text(sentence, fontSize = 14.sp, color = colors.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) + Text(sentence, fontSize = 14.sp, color = colors.onBackground, maxLines = maxLines, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) if (onCancel != null) FocusText(stringResource(R.string.common_cancel), pal.signal, onClick = onCancel) else if (note.isNotEmpty() && !LocalNarrowPane.current) Text(note, fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) } @@ -1076,6 +1094,7 @@ private fun GameComponentOverrides( protonChoice: ProtonDefault.GameChoice?, packages: List<ComponentsManager.Package>, componentChoices: Map<String, String>, + systemPowerVr: Boolean, componentMenu: String?, protonMenu: Boolean, fexMenu: Boolean, @@ -1167,6 +1186,7 @@ private fun GameComponentOverrides( } GamePackageRow( comp = "dxvk", + runtimeManaged = ComponentsManager.runtimeManaged("dxvk", systemPowerVr), packages = packages, selectedFile = componentChoices["dxvk"], open = componentMenu == "dxvk", @@ -1231,13 +1251,16 @@ private fun GamePackageRow( onMenu: (String?) -> Unit, onPick: (String, String?) -> Unit, onRuntimeOptions: (() -> Unit)? = null, + runtimeManaged: Boolean = false, ) { val choices = packages.filter { it.comp == comp } val selected = choices.firstOrNull { it.file == selectedFile } val title = ComponentsManager.LABEL[comp] ?: comp + val enabled = !busy && (!runtimeManaged || selectedFile != null) SettingsRow( title, - if (selected == null) { + if (runtimeManaged) stringResource(R.string.cmgr_powervr_dxvk_managed) + else if (selected == null) { if (proton == null) stringResource(R.string.comp_game_component_general) else stringResource(R.string.comp_game_component_runtime, proton.name) } else stringResource(R.string.comp_game_component_override, selected.version), @@ -1245,18 +1268,18 @@ private fun GamePackageRow( Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) { Box { ValueChip( - selected?.version ?: stringResource(R.string.comp_game_use_general), - open, - enabled = !busy, + if (runtimeManaged) stringResource(R.string.gpu_system_powervr) else selected?.version ?: stringResource(R.string.comp_game_use_general), + open && enabled, + enabled = enabled, modifier = Modifier.widthIn(max = 240.dp), ) { onMenu(if (open) null else comp) } - AnchoredMenu(open, onDismiss = { onMenu(null) }, title = title) { first -> + AnchoredMenu(open && enabled, onDismiss = { onMenu(null) }, title = title) { first -> MenuItem( stringResource(R.string.comp_game_use_general), checked = selected == null, focusRequester = first, ) { onPick(comp, null); onMenu(null) } - choices.forEach { option -> + if (!runtimeManaged) choices.forEach { option -> MenuItem(option.version, checked = option.file == selectedFile, detail = option.description) { onPick(comp, option.file) onMenu(null) @@ -1378,13 +1401,13 @@ private fun Tag(text: String) { @Composable private fun ChoiceLine( name: String, detail: String, selected: Boolean, removable: Boolean, - modifier: Modifier = Modifier, tag: String? = null, badge: String? = null, progress: Int? = null, + modifier: Modifier = Modifier, tag: String? = null, badge: String? = null, progress: Int? = null, enabled: Boolean = true, onSelect: () -> Unit, onDelete: () -> Unit = {}, ) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val src = remember { MutableInteractionSource() } - val hot = rememberHot(src) + val hot = rememberHot(src) && enabled Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth() @@ -1394,8 +1417,8 @@ private fun ChoiceLine( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.weight(1f).heightIn(min = 56.dp).then(modifier) .glideBorder(hot, ROW_SHAPE, pal.signal) - .hoverable(src).clickable(interactionSource = src, indication = null, role = Role.RadioButton, onClick = onSelect) - .controllerConfirm(onClick = onSelect) + .hoverable(src).clickable(interactionSource = src, indication = null, enabled = enabled, role = Role.RadioButton, onClick = onSelect) + .controllerConfirm(enabled = enabled, onClick = onSelect) .padding(start = 14.dp, end = 8.dp, top = 8.dp, bottom = 8.dp), ) { Box(contentAlignment = Alignment.Center, modifier = Modifier.size(20.dp).border(2.dp, if (selected) pal.signal else colors.onSurfaceVariant, CircleShape)) { @@ -1405,7 +1428,7 @@ private fun ChoiceLine( Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { Text( name, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 2, overflow = TextOverflow.Ellipsis, - color = if (selected) pal.signal else colors.onBackground, modifier = Modifier.weight(1f, fill = false), + color = if (!enabled) colors.onSurfaceVariant else if (selected) pal.signal else colors.onBackground, modifier = Modifier.weight(1f, fill = false), ) if (tag != null) Tag(tag) } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 5881ad715d..fda8c6fedb 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -107,6 +107,10 @@ class FrontEndState( val gameDebugLogsNeedsRestart: Boolean = false, val vacDiagnostics: Boolean = false, val agentCommands: Boolean = false, + val graphicsLogs: Boolean = false, + val steamGpuDrawing: Boolean = false, + val bridgeFellBack: Boolean = false, + val bridgeFellBackMemory: Boolean = false, val clearCachedApps: Boolean = false, val adbPaired: Boolean = false, val backgroundAppLimit: Int = -1, @@ -152,6 +156,8 @@ class FrontEndState( val phantomProcessStatus: PhantomProcessStatus = PhantomProcessStatus.NOT_APPLICABLE, val adreno: Boolean = true, val vkBridge: Boolean = false, + val venus: Boolean = false, + val venusHostVulkan: String? = null, val vkBridgeSafe: Boolean = true, val bridgeProtonDxvk: Boolean = false, val showPhantomGate: Boolean = false, @@ -211,6 +217,7 @@ class FrontEndActions( val onRemovePackage: (String) -> Unit, val onRuntime: () -> Unit, val onVkBridge: (Boolean) -> Unit = {}, + val onVenus: (Boolean) -> Unit = {}, val onVkBridgeSafe: (Boolean) -> Unit = {}, val onBridgeProtonDxvk: (Boolean) -> Unit = {}, val onFrameGenPick: (FrameGen.Mode) -> Unit, @@ -232,6 +239,8 @@ class FrontEndActions( val onGameDebugLogs: () -> Unit = {}, val onVacDiagnostics: () -> Unit = {}, val onAgentCommands: () -> Unit = {}, + val onGraphicsLogs: () -> Unit = {}, + val onSteamGpuDrawing: () -> Unit = {}, val onClearCachedApps: (Boolean) -> Unit = {}, val onMemoryHud: (String) -> Unit = {}, val onBackgroundAppLimit: (Int) -> Unit = {}, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 830b68ef35..66dd4e0e1d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -248,6 +248,8 @@ internal fun SetupPanel( Column(modifier = Modifier.weight(1f).fillMaxWidth().verticalScroll(rememberScrollState()).padding(bottom = 24.dp)) { when (tab) { 0 -> { + // Setup's "Safe mode" row, under the GPU row while the bridge is on and can be used here. + val bridgeModeRow = !s.adreno && s.vkBridge && com.droiddeck.launcher.core.DeviceSupport.bridgeUsable() val gpuCheck: @Composable (Boolean) -> Unit = { divider -> CheckRow( if (gpuOk) CheckState.OK else CheckState.WARN, @@ -259,19 +261,32 @@ 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 -> if (s.vkBridge) stringResource(R.string.setup_gpu_bridge_detail, gpuName) + com.droiddeck.launcher.gpu.GpuInfo.Support.UNTESTED -> + if (!s.adreno && s.venus && s.venusHostVulkan != null) stringResource(R.string.setup_gpu_venus_host_too_old, gpu.displayName(ctx), s.venusHostVulkan) + else if (!s.adreno && s.vkBridge && !com.droiddeck.launcher.core.DeviceSupport.bridgeUsable()) stringResource(R.string.setup_gpu_bridge_unusable, gpu.displayName(ctx)) + else if (!s.adreno && s.vkBridge && s.bridgeFellBack) stringResource(if (s.bridgeFellBackMemory) R.string.setup_gpu_bridge_no_memory_sharing else R.string.setup_gpu_bridge_fell_back, gpu.displayName(ctx)) + else stringResource(R.string.setup_gpu_untested_detail, gpu.displayName(ctx), gpu.supportText(ctx).replaceFirstChar { it.lowercase() }) + else -> if (s.venus && s.venusHostVulkan != null) stringResource(R.string.setup_gpu_venus_host_too_old, gpuName, s.venusHostVulkan) + else if (s.vkBridge && !com.droiddeck.launcher.core.DeviceSupport.bridgeUsable()) stringResource(R.string.setup_gpu_bridge_unusable, gpuName) + else if (s.vkBridge && s.bridgeFellBack) stringResource(if (s.bridgeFellBackMemory) R.string.setup_gpu_bridge_no_memory_sharing else R.string.setup_gpu_bridge_fell_back, gpuName) + else if (s.vkBridge) stringResource(R.string.setup_gpu_bridge_detail, gpuName) else stringResource(R.string.setup_gpu_unsupported_detail, gpuName) }, - divider = divider || (!s.adreno && s.vkBridge), + divider = divider || bridgeModeRow, 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) }, - ) + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + SecondaryButton( + stringResource(if (s.venus) R.string.setup_gpu_venus_on else R.string.setup_gpu_venus_off), + enabled = !s.sessionRunning, compact = true, onClick = { a.onVenus(!s.venus) }, + ) + 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) }, + ) + } } }, ) - if (!s.adreno && s.vkBridge) CheckRow( + if (bridgeModeRow) 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), @@ -558,6 +573,8 @@ internal fun SetupPanel( ) { a.onGameDebugLogs() } ToggleRow(host, "vacdiag", stringResource(R.string.setup_vac_diag), stringResource(R.string.setup_vac_diag_hint), s.vacDiagnostics) { a.onVacDiagnostics() } ToggleRow(host, "agent-commands", stringResource(R.string.setup_agent_commands), null, s.agentCommands) { a.onAgentCommands() } + ToggleRow(host, "graphics-logs", stringResource(R.string.setup_graphics_logs), stringResource(R.string.setup_graphics_logs_hint), s.graphicsLogs) { a.onGraphicsLogs() } + if (!s.adreno && com.droiddeck.launcher.session.SessionPrefs.steamGpuCompositingAllowed()) ToggleRow(host, "steam-gpu-drawing", stringResource(R.string.setup_steam_gpu_drawing), stringResource(R.string.setup_steam_gpu_drawing_hint), s.steamGpuDrawing) { a.onSteamGpuDrawing() } ActionRow(stringResource(R.string.setup_latest_logs), stringResource(R.string.drawer_logs_hint), stringResource(R.string.drawer_share_logs), a.onShareLogs, progress = com.droiddeck.launcher.session.SessionLogShare.progress) androidx.compose.material3.HorizontalDivider() diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt index 69936548ce..f0df5a2209 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt @@ -89,6 +89,8 @@ class PairRow( val complete: Boolean, val installed: Boolean, val active: Boolean, + /** A newer build of this installed pair (its build date), or null. */ + val update: String? = null, ) const val GPU_MODE_AUTO = "auto" @@ -110,6 +112,9 @@ class GpuDriversState( val supported: Boolean = true, val unsupported: Boolean = false, val auto: Boolean = true, + val powerVr: Boolean = false, + /** The selected runtime supplies DXVK for PowerVR game launches. */ + val systemPowerVr: Boolean = false, val pairs: List<PairRow> = emptyList(), val busy: String? = null, val percent: Int = -1, @@ -138,6 +143,7 @@ class GpuDriversState( class GpuDriversActions( val onAuto: (Boolean) -> Unit = {}, val onPair: (String) -> Unit = {}, + val onPairUpdate: (String) -> Unit = {}, val onRefresh: () -> Unit = {}, val onSelectLinux: (String) -> Unit = {}, val onSelectAndroid: (String) -> Unit = {}, @@ -258,7 +264,7 @@ internal fun GpuDriversBody( modes.indices.forEach { choice(it, Modifier.weight(1f).fillMaxHeight()) } } when (gpu.mode) { - GPU_MODE_AUTO -> AutoBody(gpu) + GPU_MODE_AUTO -> AutoBody(gpu, actions) GPU_MODE_PAIR -> PairBody(gpu, actions) else -> MixBody(single, actions, slotFocus, onOpenSlot) } @@ -351,14 +357,26 @@ private fun RestartBanner(target: String, canRestart: Boolean, afterLater: Focus } @Composable -private fun AutoBody(gpu: GpuDriversState) { +private fun AutoBody(gpu: GpuDriversState, actions: GpuDriversActions) { val colors = MaterialTheme.colorScheme Column(verticalArrangement = Arrangement.spacedBy(10.dp)) { PanelTitle( stringResource(if (gpu.activePair != null) R.string.gpu_auto_title else R.string.gpu_auto_builtin_title, gpu.gpuName), stringResource(R.string.gpu_auto_reason, gpu.gpuFamily), ) - gpu.activePair?.let { p -> PanelRow(p.name, "${p.version} · ${p.detail}", selected = true, onClick = null) } + gpu.activePair?.let { p -> + // An open non-Adreno pair is rebuilt in place while it is tested: offer the newer build. + PanelRow( + p.name, "${p.version} · " + (p.update?.let { stringResource(R.string.proton_update_available, it) } ?: p.detail), selected = true, + trailing = when { + gpu.busy == p.key -> "${gpu.percent.coerceAtLeast(0)}%" + p.update != null -> stringResource(R.string.common_update) + else -> null + }, + enabled = gpu.busy == null, + onClick = p.update?.let { { actions.onPairUpdate(p.key) } }, + ) + } if (gpu.autoStatus.isNotEmpty()) Text(gpu.autoStatus, fontSize = 13.sp, color = colors.onSurfaceVariant) } } @@ -376,15 +394,17 @@ private fun PairBody(gpu: GpuDriversState, actions: GpuDriversActions) { fontSize = 13.sp, color = colors.onSurfaceVariant, ) for (p in rows) PanelRow( - p.name, "${p.version} · ${p.detail}", selected = p.active, + p.name, "${p.version} · " + (p.update?.let { stringResource(R.string.proton_update_available, it) } ?: p.detail), selected = p.active, badge = if (p.recommended) stringResource(R.string.gpu_autos_pick) else null, trailing = when { gpu.busy == p.key -> "${gpu.percent.coerceAtLeast(0)}%" + p.update != null -> stringResource(R.string.common_update) p.installed -> stringResource(R.string.gpu_installed) else -> stringResource(R.string.common_download) }, enabled = gpu.busy == null, - onClick = { if (!p.active) actions.onPair(p.key) }, + // A rebuilt open non-Adreno pair (same release, newer build) is updated in place. + onClick = { if (p.update != null) actions.onPairUpdate(p.key) else if (!p.active) actions.onPair(p.key) }, ) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { if (gpu.pairs.any { !it.suits }) FocusText(stringResource(if (showAll) R.string.gpu_hide_other else R.string.gpu_show_other), pal.signal) { showAll = !showAll } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index b11b0640b6..92074c314e 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -324,6 +324,7 @@ class DrawerActions( val onClose: () -> Unit, val onDismissScreen: (() -> Unit)? = null, val components: ComponentsManager.Snapshot? = null, + val systemPowerVr: Boolean = false, val onComponentsRefresh: () -> Unit = {}, val componentCatalog: List<ComponentsManager.CatalogItem> = emptyList(), val componentCatalogAt: Long = 0, @@ -1341,7 +1342,11 @@ private fun SelectedGameProfileGroup(host: MenuHost, a: DrawerActions, track: (S for (component in ComponentsManager.COMPONENTS) { val value = profile.components.getValue(component) if (!value.inherited) { - ProfileSummaryRow(ComponentsManager.LABEL.getValue(component), profileValueLabel(value)) + ProfileSummaryRow( + ComponentsManager.LABEL.getValue(component), + if (ComponentsManager.runtimeManaged(component, a.systemPowerVr)) stringResource(R.string.gpu_system_powervr) + else profileValueLabel(value), + ) } } if (profile.startWithoutSteam) { @@ -1450,20 +1455,23 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin ) for (comp in ComponentsManager.COMPONENTS) { val value = gameProfile.components.getValue(comp) + val managedDxvk = ComponentsManager.runtimeManaged(comp, a.systemPowerVr) val options: List<Pair<String?, String>> = listOf(null to stringResource(R.string.comp_game_use_general)) + - snap.packages.filter { it.comp == comp }.map { it.file to it.version } + if (managedDxvk) emptyList() else snap.packages.filter { it.comp == comp }.map { it.file to it.version } DrawerStackedChoice( host = host, key = "game-cmp-$comp", label = ComponentsManager.LABEL.getValue(comp), - hint = if (value.inherited) { + hint = if (managedDxvk) stringResource(R.string.cmgr_powervr_dxvk_managed) else if (value.inherited) { stringResource(R.string.drawer_component_inherited, value.value) } else { null }, options = options, selected = gameProfile.componentFiles[comp], + enabled = !managedDxvk || gameProfile.componentFiles[comp] != null, + valueLabel = if (managedDxvk) stringResource(R.string.gpu_system_powervr) else null, chipModifier = track("cmp-$comp"), onPick = { file -> a.onGameComponent(gameProfile.appId, comp, file) }, ) @@ -1498,7 +1506,11 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin for (comp in ComponentsManager.COMPONENTS) { Row(modifier = Modifier.fillMaxWidth().padding(top = 3.dp)) { Text(ComponentsManager.LABEL.getValue(comp), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.width(96.dp)) - Text(r.components.getValue(comp).inUse, fontSize = 12.sp, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) + Text( + if (ComponentsManager.runtimeManaged(comp, a.systemPowerVr)) stringResource(R.string.gpu_system_powervr) + else r.components.getValue(comp).inUse, + fontSize = 12.sp, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, + ) } } } @@ -1526,16 +1538,21 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin val build = ComponentsManager.safeName(p.version) for (comp in ComponentsManager.COMPONENTS) { val st = view.components.getValue(comp) + val managedDxvk = ComponentsManager.runtimeManaged(comp, a.systemPowerVr) val originals = view.originals.filter { it.comp == comp } val options = originals.map { "orig:${it.protonVersion}" to (if (it.protonVersion == build) originalLabel else stringResource(R.string.comp_original, it.protonVersion)) } + snap.packages.filter { it.comp == comp }.map { it.file to it.version } - if (options.isEmpty()) continue + if (options.isEmpty() && !managedDxvk) continue val current = st.activeFile ?: "orig:$build" val shown = options.firstOrNull { it.first == current }?.second DrawerStackedChoice( host, "cmp-$comp", ComponentsManager.LABEL.getValue(comp), - st.queued?.let { stringResource(R.string.comp_next_queued, it) } ?: st.inUse.takeIf { it != shown }, + if (managedDxvk) stringResource(R.string.cmgr_powervr_dxvk_managed) + + (st.queued?.let { "\n" + stringResource(R.string.cmgr_powervr_dxvk_queued, it) } ?: "") + else st.queued?.let { stringResource(R.string.comp_next_queued, it) } ?: st.inUse.takeIf { it != shown }, options, current, + enabled = !managedDxvk, + valueLabel = if (managedDxvk) stringResource(R.string.gpu_system_powervr) else null, note = if (view.inUseByGame) stringResource(R.string.comp_waits_long) else stringResource(R.string.comp_applies_long), chipModifier = track("cmp-$comp"), onPick = { v -> if (v != current || st.queued != null) a.onComponentSwap(p.id, comp, v) }, @@ -1648,11 +1665,11 @@ internal fun ComponentDownloadsDrawerGroup( private fun <T> DrawerStackedChoice( host: MenuHost, key: String, label: String, hint: String?, options: List<Pair<T, String>>, selected: T, note: String? = null, - chipModifier: Modifier = Modifier, onPick: (T) -> Unit, + chipModifier: Modifier = Modifier, enabled: Boolean = true, valueLabel: String? = null, onPick: (T) -> Unit, ) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current - val open = host.open == key + val open = host.open == key && enabled Column( modifier = Modifier.fillMaxWidth() .background(if (open) pal.signal.copy(alpha = 0.10f) else Color.Transparent) @@ -1660,7 +1677,7 @@ private fun <T> DrawerStackedChoice( ) { Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) Box(modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) { - ValueChip(options.firstOrNull { it.first == selected }?.second ?: "-", open, modifier = chipModifier.fillMaxWidth()) { + ValueChip(valueLabel ?: options.firstOrNull { it.first == selected }?.second ?: "-", open, enabled = enabled, modifier = chipModifier.fillMaxWidth()) { host.open = if (open) null else key } AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null }, title = label, note = note) { firstItemFocus -> diff --git a/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt b/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt index 1bbeb18e2f..51b5fc3d32 100644 --- a/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt +++ b/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt @@ -74,6 +74,12 @@ object AppUpdates { val updatable: Boolean, val committedAt: Long = 0L, val ciBuild: Boolean = BuildConfig.CI_BUILD, + /** + * A build of the non-Adreno test branch (Mali / Xclipse / PowerVR routes). The official + * channels carry the Adreno-only app: installing one over it drops those routes, so none is + * offered. Its updates are published on The412Banner/droiddeck-nonadreno-drivers. + */ + val nonAdrenoTest: Boolean = false, ) enum class PreviewHistoryKind { CURRENT, BEHIND, RECENT } @@ -125,6 +131,7 @@ object AppUpdates { BuildConfig.VERSION_CODE, releaseSigned, BuildConfig.COMMIT_TIME, + nonAdrenoTest = BuildConfig.BUILD_LABEL.contains("non-adreno"), ) fun release(catalog: Catalog, follow: Follow): Release? = when (follow.channel) { @@ -191,6 +198,7 @@ object AppUpdates { } fun installBlock(r: Release, me: Installed = installed()): InstallBlock? = when { + me.nonAdrenoTest -> InstallBlock(R.string.upd_block_non_adreno_test) r.apk == null -> InstallBlock(R.string.upd_block_no_apk) r.apk.versionCode < me.versionCode -> InstallBlock(R.string.upd_block_version_code, r.apk.versionCode, me.versionCode) else -> null diff --git a/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java b/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java index 8fd329ce2f..a2ac2171df 100644 --- a/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java +++ b/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java @@ -180,6 +180,28 @@ public final class WaylandCompositor { public static native int nativeCompositorTid(); + private static native String nativeCompositorFault(); + + private static native String nativeDisplayDriver(); + + /** Why the compositor cannot present, or "" while it can (or before the library is loaded). */ + public static String compositorFault() { + try { + return nativeCompositorFault(); + } catch (Throwable t) { + return ""; + } + } + + /** The driver that answered for the display, as it reports itself; "" when not known yet. */ + public static String displayDriver() { + try { + return nativeDisplayDriver(); + } catch (Throwable t) { + return ""; + } + } + public static native void nativeSetHideShell(boolean hide); public static native void nativeSetOutputRefreshRate(float hz); diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index d0222536cd..c891154b5d 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -825,7 +825,7 @@ <string name="setup_gpu_unsupported">GPU غير مدعوم</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">يحتاج Steam إلى برنامج تشغيل Adreno؛ قد يعرض %1$s شاشة سوداء</string> + <string name="setup_gpu_unsupported_detail">لا تتوفر واجهة رسومات متوافقة مع %1$s. قد يعرض Steam شاشة سوداء.</string> <string name="setup_runtime">بيئة تشغيل Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">غير مثبّت · نحو 3 GB، يُثبَّت عند أول تشغيل</string> @@ -1450,8 +1450,8 @@ <string name="main_wadb_unavailable">تصحيح الأخطاء اللاسلكي غير متاح</string> <string name="main_adb_copied">تم نسخ أمر ADB</string> <string name="main_pick_roms">اختر مجلد ROMs</string> - <string name="main_non_adreno_title">وحدة GPU ليست من نوع Adreno</string> - <string name="main_non_adreno_text">يدعم Turnip وحدات GPU من نوع Adreno. على %1$s، قد يعرض Steam شاشة سوداء. حجم التنزيل: %2$.0f MB.</string> + <string name="main_non_adreno_title">وحدة معالجة رسومات غير مدعومة</string> + <string name="main_non_adreno_text">لا تتوفر واجهة رسومات متوافقة مع %1$s. قد يعرض Steam شاشة سوداء. التنزيل: %2$.0f ميغابايت.</string> <string name="main_install_anyway">التثبيت على أي حال</string> <string name="main_remove_runtime_title">إزالة بيئة تشغيل Linux</string> <string name="main_remove_runtime_text">سيؤدي هذا إلى حذف بيئة التشغيل وعميل Steam بداخلها وكل لعبة مثبَّتة فيها.</string> @@ -2217,7 +2217,7 @@ <string name="gpuinfo_experimental">تجريبي: برامج تشغيله إصدارات اختبارية</string> <string name="gpuinfo_a850_experimental">دعم تجريبي لـ Adreno 850: يتطلب برامج تشغيل تجريبية متوافقة للعرض والألعاب، ولم يُتحقَّق منه على هذا الجهاز</string> <string name="gpuinfo_below_tested">أقل من العتاد المُختبَر (Adreno 725 وأحدث): قد لا يعمل</string> - <string name="gpuinfo_unsupported">غير مدعوم: يحتاج DroidDeck إلى وحدة GPU من نوع Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">غير مدعوم: لا تتوفر واجهة رسومات متوافقة مع وحدة معالجة الرسومات هذه</string> <string name="turnip_rate_limited">تم الوصول إلى حدّ الطلبات في GitHub - حاوِل مرة أخرى لاحقًا</string> <string name="turnip_github_http">استجاب GitHub بـ HTTP %1$d</string> diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index e89919b32b..df69655077 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -843,7 +843,7 @@ <string name="setup_gpu_unsupported">GPU no compatible</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam necesita un controlador Adreno; %1$s puede mostrar una pantalla negra</string> + <string name="setup_gpu_unsupported_detail">No hay un motor gráfico compatible disponible para %1$s. Steam puede mostrar una pantalla negra.</string> <string name="setup_runtime">Runtime de Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">No instalado · unos 3 GB, se instala al jugar por primera vez</string> @@ -1483,8 +1483,8 @@ <string name="main_wadb_unavailable">La Depuración inalámbrica no está disponible</string> <string name="main_adb_copied">Comando ADB copiado</string> <string name="main_pick_roms">Elige la carpeta de ROMs</string> - <string name="main_non_adreno_title">La GPU no es Adreno</string> - <string name="main_non_adreno_text">Turnip es compatible con GPU Adreno. En %1$s, Steam puede mostrar una pantalla negra. Descarga: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU no compatible</string> + <string name="main_non_adreno_text">No hay un motor gráfico compatible disponible para %1$s. Steam puede mostrar una pantalla negra. Descarga: %2$.0f MB.</string> <string name="main_install_anyway">Instalar de todos modos</string> <string name="main_remove_runtime_title">Eliminar el runtime de Linux</string> <string name="main_remove_runtime_text">Esto elimina el runtime, el cliente de Steam que contiene y todos los juegos instalados en él.</string> @@ -2192,7 +2192,7 @@ <string name="gpuinfo_experimental">Experimental: sus controladores son versiones de prueba</string> <string name="gpuinfo_a850_experimental">Compatibilidad experimental con Adreno 850: requiere controladores experimentales de pantalla y de juegos compatibles; no verificada en este dispositivo</string> <string name="gpuinfo_below_tested">Por debajo del hardware probado (Adreno 725 y posteriores): puede que no funcione</string> - <string name="gpuinfo_unsupported">No compatible: DroidDeck necesita una GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">No compatible: no hay un motor gráfico compatible disponible para esta GPU</string> <string name="turnip_rate_limited">Se alcanzó el límite de solicitudes de GitHub - inténtalo más tarde</string> <string name="turnip_github_http">GitHub respondió HTTP %1$d</string> <string name="turnip_download_failed">Error en la descarga</string> diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 3087a2ccaf..a12a74bc8e 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">GPU не се поддържа</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam изисква драйвер за Adreno; %1$s може да покаже черен екран</string> + <string name="setup_gpu_unsupported_detail">Няма съвместим графичен бекенд за %1$s. Steam може да показва черен екран.</string> <string name="setup_runtime">Linux среда за изпълнение</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Не е инсталирано · около 3 GB, инсталира се при първото Play</string> @@ -1402,8 +1402,8 @@ <string name="main_wadb_unavailable">Безжичното отстраняване на грешки не е достъпно</string> <string name="main_adb_copied">Командата за ADB е копирана</string> <string name="main_pick_roms">Избор на папката ROMs</string> - <string name="main_non_adreno_title">Не е Adreno GPU</string> - <string name="main_non_adreno_text">Turnip поддържа Adreno GPU-та. На %1$s Steam може да покаже черен екран. Изтегляне: %2$.0f MB.</string> + <string name="main_non_adreno_title">Неподдържан GPU</string> + <string name="main_non_adreno_text">Няма съвместим графичен бекенд за %1$s. Steam може да показва черен екран. Изтегляне: %2$.0f MB.</string> <string name="main_install_anyway">Инсталиране въпреки това</string> <string name="main_remove_runtime_title">Премахване на средата на Linux</string> <string name="main_remove_runtime_text">Това изтрива средата, клиента на Steam в нея и всяка инсталирана в нея игра.</string> @@ -2117,7 +2117,7 @@ <string name="gpuinfo_experimental">Експериментален: драйверите му са тестови версии</string> <string name="gpuinfo_a850_experimental">Експериментална поддръжка на Adreno 850: изисква съвместими експериментални драйвери за дисплея и игрите; не е проверена на това устройство</string> <string name="gpuinfo_below_tested">Под тестваните устройства (Adreno 725 и по-нови): може да не работи</string> - <string name="gpuinfo_unsupported">Не се поддържа: DroidDeck изисква GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Не се поддържа: няма съвместим графичен бекенд за този GPU</string> <string name="turnip_rate_limited">Достигнато е ограничението на GitHub за заявки - опитай отново по-късно</string> <string name="turnip_github_http">GitHub отговори с HTTP %1$d</string> diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 6d60588137..f66fb31fb7 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -819,7 +819,7 @@ <string name="setup_gpu_unsupported">GPU nepodporováno</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam vyžaduje ovladač Adreno; %1$s může zobrazit černou obrazovku</string> + <string name="setup_gpu_unsupported_detail">Pro %1$s není k dispozici kompatibilní grafický backend. Steam může zobrazit černou obrazovku.</string> <string name="setup_runtime">Běhové prostředí Linuxu</string> <string name="setup_runtime_progress">%1$s · %2$d %%</string> <string name="setup_runtime_missing">Nenainstalováno · přibližně 3 GB, instaluje se při prvním Play</string> @@ -1426,8 +1426,8 @@ <string name="main_wadb_unavailable">Bezdrátové ladění není k dispozici</string> <string name="main_adb_copied">Příkaz ADB zkopírován</string> <string name="main_pick_roms">Vybrat složku ROMs</string> - <string name="main_non_adreno_title">Není GPU Adreno</string> - <string name="main_non_adreno_text">Turnip podporuje GPU Adreno. Na %1$s může Steam zobrazit černou obrazovku. Stažení: %2$.0f MB.</string> + <string name="main_non_adreno_title">Nepodporovaný GPU</string> + <string name="main_non_adreno_text">Pro %1$s není k dispozici kompatibilní grafický backend. Steam může zobrazit černou obrazovku. Ke stažení: %2$.0f MB.</string> <string name="main_install_anyway">Přesto instalovat</string> <string name="main_remove_runtime_title">Odstranit runtime Linuxu</string> <string name="main_remove_runtime_text">Tím se odstraní runtime, klient Steam v něm a všechny hry v něm nainstalované.</string> @@ -2167,7 +2167,7 @@ <string name="gpuinfo_experimental">Experimentální: jeho ovladače jsou testovací sestavení</string> <string name="gpuinfo_a850_experimental">Experimentální podpora Adreno 850: vyžaduje kompatibilní experimentální ovladače displeje a her; na tomto zařízení neověřeno</string> <string name="gpuinfo_below_tested">Pod testovaným hardwarem (Adreno 725 a novější): nemusí fungovat</string> - <string name="gpuinfo_unsupported">Není podporováno: DroidDeck potřebuje GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Nepodporováno: pro tento GPU není k dispozici kompatibilní grafický backend</string> <string name="turnip_rate_limited">Byl dosažen limit požadavků GitHubu - zkuste to později</string> <string name="turnip_github_http">GitHub odpověděl HTTP %1$d</string> diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 191c15c7b9..ab5f0859c0 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">GPU ikke understøttet</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam kræver en Adreno-driver; %1$s kan vise en sort skærm</string> + <string name="setup_gpu_unsupported_detail">Ingen kompatibel grafikbackend er tilgængelig for %1$s. Steam kan vise en sort skærm.</string> <string name="setup_runtime">Linux-runtime</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Ikke installeret · omkring 3 GB, installeres ved første Spil</string> @@ -1402,8 +1402,8 @@ <string name="main_wadb_unavailable">Trådløs fejlretning er ikke tilgængelig</string> <string name="main_adb_copied">ADB-kommando kopieret</string> <string name="main_pick_roms">Vælg ROMs-mappen</string> - <string name="main_non_adreno_title">Ikke en Adreno-GPU</string> - <string name="main_non_adreno_text">Turnip understøtter Adreno-GPU\'er. På %1$s kan Steam vise en sort skærm. Download: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU understøttes ikke</string> + <string name="main_non_adreno_text">Ingen kompatibel grafikbackend er tilgængelig for %1$s. Steam kan vise en sort skærm. Download: %2$.0f MB.</string> <string name="main_install_anyway">Installer alligevel</string> <string name="main_remove_runtime_title">Fjern Linux-runtime</string> <string name="main_remove_runtime_text">Dette sletter runtime\'en, Steam-klienten i den og alle spil installeret der.</string> @@ -2117,7 +2117,7 @@ <string name="gpuinfo_experimental">Eksperimentel: dens drivere er testversioner</string> <string name="gpuinfo_a850_experimental">Eksperimentel Adreno 850-understøttelse: kræver kompatible eksperimentelle skærm- og spildrivere; ikke bekræftet på denne enhed</string> <string name="gpuinfo_below_tested">Under testet hardware (Adreno 725 og nyere): kører muligvis ikke</string> - <string name="gpuinfo_unsupported">Ikke understøttet: DroidDeck kræver en Adreno (Snapdragon) GPU</string> + <string name="gpuinfo_unsupported">Understøttes ikke: ingen kompatibel grafikbackend er tilgængelig for denne GPU</string> <string name="turnip_rate_limited">GitHubs hastighedsgrænse blev nået - forsøg igen senere</string> <string name="turnip_github_http">GitHub svarede HTTP %1$d</string> diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 200e8e242a..e4bfaa32b7 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">GPU nicht unterstützt</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam benötigt einen Adreno-Treiber; %1$s zeigt möglicherweise einen schwarzen Bildschirm</string> + <string name="setup_gpu_unsupported_detail">Für %1$s ist kein kompatibles Grafik-Backend verfügbar. Steam zeigt möglicherweise einen schwarzen Bildschirm.</string> <string name="setup_runtime">Linux-Laufzeit</string> <string name="setup_runtime_progress">%1$s · %2$d %%</string> <string name="setup_runtime_missing">Nicht installiert · ca. 3 GB, wird beim ersten „Spielen“ installiert</string> @@ -1394,8 +1394,8 @@ <string name="main_wadb_unavailable">Debugging über WLAN ist nicht verfügbar</string> <string name="main_adb_copied">ADB-Befehl kopiert</string> <string name="main_pick_roms">ROMs-Ordner auswählen</string> - <string name="main_non_adreno_title">Keine Adreno-GPU</string> - <string name="main_non_adreno_text">Turnip unterstützt Adreno-GPUs. Auf %1$s zeigt Steam eventuell einen schwarzen Bildschirm. Download: %2$.0f MB.</string> + <string name="main_non_adreno_title">Nicht unterstützte GPU</string> + <string name="main_non_adreno_text">Für %1$s ist kein kompatibles Grafik-Backend verfügbar. Steam zeigt möglicherweise einen schwarzen Bildschirm. Download: %2$.0f MB.</string> <string name="main_install_anyway">Trotzdem installieren</string> <string name="main_remove_runtime_title">Linux-Laufzeit entfernen</string> <string name="main_remove_runtime_text">Dadurch werden die Laufzeit, der Steam-Client darin und alle dort installierten Spiele gelöscht.</string> @@ -2109,7 +2109,7 @@ <string name="gpuinfo_experimental">Experimentell: Die Treiber sind Test-Builds</string> <string name="gpuinfo_a850_experimental">Experimentelle Adreno-850-Unterstützung: erfordert kompatible experimentelle Anzeige- und Spieltreiber; auf diesem Gerät nicht geprüft</string> <string name="gpuinfo_below_tested">Unter der getesteten Hardware (Adreno 725 und neuer): läuft eventuell nicht</string> - <string name="gpuinfo_unsupported">Nicht unterstützt: DroidDeck braucht eine Adreno-GPU (Snapdragon)</string> + <string name="gpuinfo_unsupported">Nicht unterstützt: Für diese GPU ist kein kompatibles Grafik-Backend verfügbar</string> <string name="turnip_rate_limited">Das Rate-Limit von GitHub wurde erreicht - versuche es später erneut</string> <string name="turnip_github_http">GitHub antwortete mit HTTP %1$d</string> diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index d8a9e8d13a..806ba09726 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">Η GPU δεν υποστηρίζεται</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Το Steam απαιτεί πρόγραμμα οδήγησης Adreno· το %1$s μπορεί να εμφανίσει μαύρη οθόνη</string> + <string name="setup_gpu_unsupported_detail">Δεν υπάρχει συμβατό υποσύστημα γραφικών για %1$s. Το Steam μπορεί να εμφανίσει μαύρη οθόνη.</string> <string name="setup_runtime">Runtime Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Δεν έχει εγκατασταθεί · περίπου 3 GB, εγκαθίσταται στο πρώτο Play</string> @@ -1402,8 +1402,8 @@ <string name="main_wadb_unavailable">Ο ασύρματος εντοπισμός σφαλμάτων δεν είναι διαθέσιμος</string> <string name="main_adb_copied">Η εντολή ADB αντιγράφηκε</string> <string name="main_pick_roms">Επιλέξτε τον φάκελο ROMs</string> - <string name="main_non_adreno_title">Δεν είναι GPU Adreno</string> - <string name="main_non_adreno_text">Το Turnip υποστηρίζει GPU Adreno. Σε %1$s, το Steam ίσως εμφανίσει μαύρη οθόνη. Λήψη: %2$.0f MB.</string> + <string name="main_non_adreno_title">Μη υποστηριζόμενη GPU</string> + <string name="main_non_adreno_text">Δεν υπάρχει συμβατό υποσύστημα γραφικών για %1$s. Το Steam μπορεί να εμφανίσει μαύρη οθόνη. Λήψη: %2$.0f MB.</string> <string name="main_install_anyway">Εγκατάσταση παρόλα αυτά</string> <string name="main_remove_runtime_title">Κατάργηση του Linux runtime</string> <string name="main_remove_runtime_text">Αυτό διαγράφει το runtime, τον πελάτη Steam μέσα σε αυτό και κάθε παιχνίδι που είναι εγκατεστημένο εκεί.</string> @@ -2117,7 +2117,7 @@ <string name="gpuinfo_experimental">Πειραματικό: τα προγράμματα οδήγησής του είναι δοκιμαστικές εκδόσεις</string> <string name="gpuinfo_a850_experimental">Πειραματική υποστήριξη Adreno 850: απαιτεί συμβατά πειραματικά προγράμματα οδήγησης οθόνης και παιχνιδιών· δεν έχει επαληθευτεί σε αυτή τη συσκευή</string> <string name="gpuinfo_below_tested">Κάτω από το δοκιμασμένο υλικό (Adreno 725 και νεότερα): ίσως να μην εκτελεστεί</string> - <string name="gpuinfo_unsupported">Δεν υποστηρίζεται: το DroidDeck χρειάζεται GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Δεν υποστηρίζεται: δεν υπάρχει συμβατό υποσύστημα γραφικών για αυτήν την GPU</string> <string name="turnip_rate_limited">Το όριο ρυθμού του GitHub ξεπεράστηκε - δοκιμάστε ξανά αργότερα</string> <string name="turnip_github_http">Το GitHub απάντησε με HTTP %1$d</string> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index ae6cda5572..25fe78e325 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -816,7 +816,7 @@ <string name="setup_gpu_unsupported">GPU no compatible</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam necesita un controlador Adreno; %1$s puede mostrar una pantalla negra</string> + <string name="setup_gpu_unsupported_detail">No hay un motor gráfico compatible disponible; %1$s puede mostrar una pantalla negra</string> <string name="setup_runtime">Runtime de Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">No instalado · unos 3 GB, se instala al jugar por primera vez</string> @@ -1414,8 +1414,8 @@ <string name="main_wadb_unavailable">La Depuración inalámbrica no está disponible</string> <string name="main_adb_copied">Comando ADB copiado</string> <string name="main_pick_roms">Elige la carpeta de ROMs</string> - <string name="main_non_adreno_title">La GPU no es Adreno</string> - <string name="main_non_adreno_text">Turnip es compatible con GPU Adreno. En %1$s, Steam puede mostrar una pantalla negra. Descarga: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU no compatible</string> + <string name="main_non_adreno_text">No hay un motor gráfico compatible disponible para %1$s. Steam puede mostrar una pantalla negra. Descarga: %2$.0f MB.</string> <string name="main_install_anyway">Instalar de todos modos</string> <string name="main_remove_runtime_title">Eliminar el runtime de Linux</string> <string name="main_remove_runtime_text">Esto elimina el runtime, el cliente de Steam que contiene y todos los juegos instalados en él.</string> @@ -2142,7 +2142,7 @@ <string name="gpuinfo_experimental">Experimental: sus controladores son versiones de prueba</string> <string name="gpuinfo_a850_experimental">Compatibilidad experimental con Adreno 850: requiere controladores experimentales de pantalla y de juegos compatibles; no verificada en este dispositivo</string> <string name="gpuinfo_below_tested">Por debajo del hardware probado (Adreno 725 y posteriores): puede que no funcione</string> - <string name="gpuinfo_unsupported">No compatible: DroidDeck necesita una GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">No compatible: no hay un motor gráfico compatible disponible para esta GPU</string> <string name="turnip_rate_limited">Se alcanzó el límite de solicitudes de GitHub - inténtalo más tarde</string> <string name="turnip_github_http">GitHub respondió HTTP %1$d</string> diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index b96591b1cf..22732a6733 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">GPU ei ole tuettu</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam tarvitsee Adreno-ajurin; %1$s saattaa näyttää mustan ruudun</string> + <string name="setup_gpu_unsupported_detail">GPU:lle %1$s ei ole saatavilla yhteensopivaa grafiikkataustajärjestelmää. Steam saattaa näyttää mustan ruudun.</string> <string name="setup_runtime">Linux-ajoympäristö</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Ei asennettu · noin 3 GB, asennetaan ensimmäisellä Pelaa-painalluksella</string> @@ -1402,8 +1402,8 @@ <string name="main_wadb_unavailable">Langaton virheenkorjaus ei ole käytettävissä</string> <string name="main_adb_copied">ADB-komento kopioitu</string> <string name="main_pick_roms">Valitse ROMs-kansio</string> - <string name="main_non_adreno_title">Ei Adreno-grafiikkapiiri</string> - <string name="main_non_adreno_text">Turnip tukee Adreno-grafiikkapiirejä. Laitteella %1$s Steam voi näyttää mustan ruudun. Latauksen koko: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU:ta ei tueta</string> + <string name="main_non_adreno_text">GPU:lle %1$s ei ole saatavilla yhteensopivaa grafiikkataustajärjestelmää. Steam saattaa näyttää mustan ruudun. Lataus: %2$.0f Mt.</string> <string name="main_install_anyway">Asenna silti</string> <string name="main_remove_runtime_title">Poista Linux-ajoympäristö</string> <string name="main_remove_runtime_text">Tämä poistaa ajoympäristön, siihen asennetun Steam-asiakasohjelman ja kaikki sinne asennetut pelit.</string> @@ -2117,7 +2117,7 @@ <string name="gpuinfo_experimental">Kokeellinen: sen ajurit ovat testiversioita</string> <string name="gpuinfo_a850_experimental">Kokeellinen Adreno 850 -tuki: vaatii yhteensopivat kokeelliset näyttö- ja peliajurit; ei vahvistettu tällä laitteella</string> <string name="gpuinfo_below_tested">Testatun laitteiston alapuolella (Adreno 725 ja uudemmat): ei välttämättä toimi</string> - <string name="gpuinfo_unsupported">Ei tuettu: DroidDeck vaatii Adreno (Snapdragon) -grafiikkapiirin</string> + <string name="gpuinfo_unsupported">Ei tuettu: tälle GPU:lle ei ole saatavilla yhteensopivaa grafiikkataustajärjestelmää</string> <string name="turnip_rate_limited">GitHubin käyttörajoitus tuli vastaan - yritä myöhemmin uudelleen</string> <string name="turnip_github_http">GitHub vastasi HTTP %1$d</string> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2b71aeadd4..f7cf229421 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -816,7 +816,7 @@ <string name="setup_gpu_unsupported">GPU non pris en charge</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s : %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam nécessite un pilote Adreno ; %1$s peut afficher un écran noir.</string> + <string name="setup_gpu_unsupported_detail">Aucun moteur graphique compatible n’est disponible ; %1$s peut afficher un écran noir.</string> <string name="setup_runtime">Environnement d\'exécution Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Non installé · Environ 3 Go, installé lors du premier lancement d\'un jeu</string> @@ -1414,8 +1414,8 @@ <string name="main_wadb_unavailable">Le débogage sans fil n\'est pas disponible</string> <string name="main_adb_copied">Commande ADB copiée</string> <string name="main_pick_roms">Choisir le dossier ROM</string> - <string name="main_non_adreno_title">GPU non Adreno</string> - <string name="main_non_adreno_text">Turnip prend en charge les GPU Adreno. Sur %1$s, Steam peut afficher un écran noir. Téléchargement : %2$.0f Mo.</string> + <string name="main_non_adreno_title">GPU non pris en charge</string> + <string name="main_non_adreno_text">Aucun moteur graphique compatible n’est disponible pour %1$s. Steam peut afficher un écran noir. Téléchargement : %2$.0f Mo.</string> <string name="main_install_anyway">Installer quand même</string> <string name="main_remove_runtime_title">Supprimer l\'environnement d\'exécution Linux</string> <string name="main_remove_runtime_text">Cela supprime l\'environnement d\'exécution, le client Steam qu\'il contient et tous les jeux qui y sont installés.</string> @@ -2142,7 +2142,7 @@ <string name="gpuinfo_experimental">Expérimental : ses pilotes sont des versions de test</string> <string name="gpuinfo_a850_experimental">Prise en charge expérimentale de l\'Adreno 850 : nécessite des pilotes d\'affichage et de jeu expérimentaux compatibles ; non vérifiée sur cet appareil</string> <string name="gpuinfo_below_tested">En dessous du matériel testé (Adreno 725 et plus récent) : risque de ne pas fonctionner</string> - <string name="gpuinfo_unsupported">Non pris en charge : DroidDeck nécessite un GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Non pris en charge : aucun moteur graphique compatible n’est disponible pour ce GPU</string> <string name="turnip_rate_limited">Limite de requêtes GitHub atteinte - réessayez plus tard</string> <string name="turnip_github_http">GitHub a répondu HTTP %1$d</string> diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index f039dd0221..97a501f42f 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">GPU समर्थित नहीं</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam को Adreno ड्राइवर चाहिए; %1$s में काली स्क्रीन दिख सकती है</string> + <string name="setup_gpu_unsupported_detail">%1$s के लिए कोई संगत ग्राफ़िक्स बैकएंड उपलब्ध नहीं है। Steam काली स्क्रीन दिखा सकता है।</string> <string name="setup_runtime">Linux रनटाइम</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">इंस्टॉल नहीं है · लगभग 3 GB, पहली बार Play पर इंस्टॉल होगा</string> @@ -1402,8 +1402,8 @@ <string name="main_wadb_unavailable">वायरलेस डीबगिंग उपलब्ध नहीं है</string> <string name="main_adb_copied">ADB कमांड कॉपी हो गया</string> <string name="main_pick_roms">ROM फ़ोल्डर चुनें</string> - <string name="main_non_adreno_title">Adreno GPU नहीं है</string> - <string name="main_non_adreno_text">Turnip Adreno GPU को सपोर्ट करता है। %1$s पर, Steam में काली स्क्रीन दिख सकती है। डाउनलोड: %2$.0f MB।</string> + <string name="main_non_adreno_title">असमर्थित GPU</string> + <string name="main_non_adreno_text">%1$s के लिए कोई संगत ग्राफ़िक्स बैकएंड उपलब्ध नहीं है। Steam काली स्क्रीन दिखा सकता है। डाउनलोड: %2$.0f MB।</string> <string name="main_install_anyway">फिर भी इंस्टॉल करें</string> <string name="main_remove_runtime_title">Linux रनटाइम हटाएं</string> <string name="main_remove_runtime_text">यह रनटाइम, इसके भीतर का Steam क्लाइंट, और वहां इंस्टॉल हर गेम हटा देता है।</string> @@ -2117,7 +2117,7 @@ <string name="gpuinfo_experimental">एक्सपेरिमेंटल: इसके ड्राइवर टेस्ट बिल्ड हैं</string> <string name="gpuinfo_a850_experimental">प्रयोगात्मक Adreno 850 समर्थन: कम्पैटिबल प्रयोगात्मक डिस्प्ले और गेम ड्राइवर चाहिए; इस डिवाइस पर जांचा नहीं गया</string> <string name="gpuinfo_below_tested">जांचे गए हार्डवेयर से नीचे (Adreno 725 और नए): यह शायद न चले</string> - <string name="gpuinfo_unsupported">समर्थित नहीं: DroidDeck को Adreno (Snapdragon) GPU चाहिए</string> + <string name="gpuinfo_unsupported">समर्थित नहीं: इस GPU के लिए कोई संगत ग्राफ़िक्स बैकएंड उपलब्ध नहीं है</string> <string name="turnip_rate_limited">GitHub की रेट लिमिट पार हो गई - बाद में फिर कोशिश करें</string> <string name="turnip_github_http">GitHub ने HTTP %1$d जवाब दिया</string> diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index bfa3f5f5a6..9106d8a271 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">A GPU nem támogatott</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">A Steamnek Adreno-illesztőprogram szükséges; a %1$s fekete képernyőt jeleníthet meg</string> + <string name="setup_gpu_unsupported_detail">Nincs kompatibilis grafikus háttérrendszer ehhez: %1$s. A Steam fekete képernyőt jeleníthet meg.</string> <string name="setup_runtime">Linux futtatókörnyezet</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Nincs telepítve · kb. 3 GB, az első Játék gombnyomáskor települ</string> @@ -1402,8 +1402,8 @@ <string name="main_wadb_unavailable">A vezeték nélküli hibakeresés nem áll rendelkezésre</string> <string name="main_adb_copied">ADB-parancs másolva</string> <string name="main_pick_roms">ROMs mappa kiválasztása</string> - <string name="main_non_adreno_title">Nem Adreno GPU</string> - <string name="main_non_adreno_text">A Turnip Adreno GPU-kat támogat. %1$s esetén a Steam fekete képernyőt jeleníthet meg. Letöltés: %2$.0f MB.</string> + <string name="main_non_adreno_title">Nem támogatott GPU</string> + <string name="main_non_adreno_text">Nincs kompatibilis grafikus háttérrendszer ehhez: %1$s. A Steam fekete képernyőt jeleníthet meg. Letöltés: %2$.0f MB.</string> <string name="main_install_anyway">Telepítés mindenképpen</string> <string name="main_remove_runtime_title">Linux futtatókörnyezet eltávolítása</string> <string name="main_remove_runtime_text">Ez törli a futtatókörnyezetet, a benne lévő Steam-klienst és az összes ott telepített játékot.</string> @@ -2117,7 +2117,7 @@ <string name="gpuinfo_experimental">Kísérleti: az illesztőprogramjai teszt buildek</string> <string name="gpuinfo_a850_experimental">Kísérleti Adreno 850-támogatás: kompatibilis kísérleti kijelző- és játék-illesztőprogramokat igényel; ezen az eszközön nincs ellenőrizve</string> <string name="gpuinfo_below_tested">A tesztelt hardver alatt (Adreno 725 és újabb): lehet, hogy nem fut</string> - <string name="gpuinfo_unsupported">Nem támogatott: a DroidDecknek Adreno (Snapdragon) GPU szükséges</string> + <string name="gpuinfo_unsupported">Nem támogatott: nincs kompatibilis grafikus háttérrendszer ehhez a GPU-hoz</string> <string name="turnip_rate_limited">A GitHub korlátja elérve – próbálja újra később</string> <string name="turnip_github_http">A GitHub HTTP %1$d választ adott</string> diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 9027200239..5746a1ed6d 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -810,7 +810,7 @@ <string name="setup_gpu_unsupported">GPU tidak didukung</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam memerlukan driver Adreno; %1$s mungkin menampilkan layar hitam</string> + <string name="setup_gpu_unsupported_detail">Tidak ada backend grafis yang kompatibel untuk %1$s. Steam mungkin menampilkan layar hitam.</string> <string name="setup_runtime">Runtime Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Belum terinstal · sekitar 3 GB, terinstal saat Play pertama kali</string> @@ -1390,8 +1390,8 @@ <string name="main_wadb_unavailable">Debugging nirkabel tidak tersedia</string> <string name="main_adb_copied">Perintah ADB disalin</string> <string name="main_pick_roms">Pilih folder ROMs</string> - <string name="main_non_adreno_title">Bukan GPU Adreno</string> - <string name="main_non_adreno_text">Turnip mendukung GPU Adreno. Di %1$s, Steam mungkin menampilkan layar hitam. Unduhan: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU tidak didukung</string> + <string name="main_non_adreno_text">Tidak ada backend grafis yang kompatibel untuk %1$s. Steam mungkin menampilkan layar hitam. Unduhan: %2$.0f MB.</string> <string name="main_install_anyway">Tetap instal</string> <string name="main_remove_runtime_title">Hapus runtime Linux</string> <string name="main_remove_runtime_text">Ini menghapus runtime, klien Steam di dalamnya, dan setiap game yang terinstal di sana.</string> @@ -2092,7 +2092,7 @@ <string name="gpuinfo_experimental">Eksperimental: drivernya adalah build uji</string> <string name="gpuinfo_a850_experimental">Dukungan eksperimental Adreno 850: memerlukan driver tampilan dan driver gim eksperimental yang kompatibel; belum diverifikasi di perangkat ini</string> <string name="gpuinfo_below_tested">Di bawah perangkat keras yang diuji (Adreno 725 dan lebih baru): mungkin tidak dapat berjalan</string> - <string name="gpuinfo_unsupported">Tidak didukung: DroidDeck memerlukan GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Tidak didukung: tidak ada backend grafis yang kompatibel untuk GPU ini</string> <string name="turnip_rate_limited">Batas kecepatan GitHub tercapai - coba lagi nanti</string> <string name="turnip_github_http">GitHub merespons HTTP %1$d</string> diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 0b9fcdd674..64ef998189 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -816,7 +816,7 @@ <string name="setup_gpu_unsupported">GPU non supportata</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam richiede un driver Adreno; %1$s potrebbe mostrare una schermata nera</string> + <string name="setup_gpu_unsupported_detail">Nessun backend grafico compatibile disponibile per %1$s. Steam potrebbe mostrare una schermata nera.</string> <string name="setup_runtime">Runtime Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Non installato · circa 3 GB, si installa la prima volta che premi Gioca</string> @@ -1406,8 +1406,8 @@ <string name="main_wadb_unavailable">Il debug wireless non è disponibile</string> <string name="main_adb_copied">Comando ADB copiato</string> <string name="main_pick_roms">Scegli la cartella delle ROM</string> - <string name="main_non_adreno_title">Non è una GPU Adreno</string> - <string name="main_non_adreno_text">Turnip supporta le GPU Adreno. Su %1$s, Steam potrebbe mostrare una schermata nera. Download: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU non supportata</string> + <string name="main_non_adreno_text">Nessun backend grafico compatibile disponibile per %1$s. Steam potrebbe mostrare una schermata nera. Download: %2$.0f MB.</string> <string name="main_install_anyway">Installa comunque</string> <string name="main_remove_runtime_title">Rimuovi runtime Linux</string> <string name="main_remove_runtime_text">Verranno eliminati il runtime, il client Steam al suo interno e tutti i giochi installati lì.</string> @@ -2134,7 +2134,7 @@ <string name="gpuinfo_experimental">Sperimentale: i suoi driver sono build di test</string> <string name="gpuinfo_a850_experimental">Supporto sperimentale per Adreno 850: richiede driver di visualizzazione e di gioco sperimentali compatibili; non verificato su questo dispositivo</string> <string name="gpuinfo_below_tested">Inferiore all\'hardware testato (Adreno 725 e successive): potrebbe non funzionare</string> - <string name="gpuinfo_unsupported">Non supportata: DroidDeck richiede una GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Non supportata: nessun backend grafico compatibile disponibile per questa GPU</string> <string name="turnip_rate_limited">Raggiunto il limite di richieste di GitHub - riprova più tardi</string> <string name="turnip_github_http">GitHub ha risposto HTTP %1$d</string> diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 1015207fe9..a2bb315e02 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -810,7 +810,7 @@ <string name="setup_gpu_unsupported">GPUはサポートされていません</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s:%2$s</string> - <string name="setup_gpu_unsupported_detail">SteamにはAdrenoドライバーが必要です。%1$sでは画面が真っ暗になる可能性があります。</string> + <string name="setup_gpu_unsupported_detail">利用できる互換グラフィックスバックエンドがありません。%1$sでは画面が真っ暗になる可能性があります。</string> <string name="setup_runtime">Linux実行環境</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">未インストール · 約3GB、初回ゲーム起動時にインストール</string> @@ -1390,8 +1390,8 @@ <string name="main_wadb_unavailable">ワイヤレスデバッグは利用できません</string> <string name="main_adb_copied">ADBコマンドをコピーしました</string> <string name="main_pick_roms">ROMフォルダを選択</string> - <string name="main_non_adreno_title">Adreno GPUではありません</string> - <string name="main_non_adreno_text">TurnipはAdreno GPUをサポートしています。%1$sでは、Steamの画面が真っ暗になる可能性があります。ダウンロード:%2$.0f MB。</string> + <string name="main_non_adreno_title">サポート対象外のGPU</string> + <string name="main_non_adreno_text">%1$sで利用できる互換グラフィックスバックエンドがありません。Steamの画面が真っ暗になる可能性があります。ダウンロード:%2$.0f MB。</string> <string name="main_install_anyway">インストールする</string> <string name="main_remove_runtime_title">Linux実行環境を削除</string> <string name="main_remove_runtime_text">実行環境、その中のSteamクライアント、そこにインストールされたすべてのゲームが削除されます。</string> @@ -2092,7 +2092,7 @@ <string name="gpuinfo_experimental">実験的:ドライバーはテストビルドです</string> <string name="gpuinfo_a850_experimental">Adreno 850の実験的サポート:互換性のある実験版のディスプレイドライバーとゲームドライバーが必要です。このデバイスでは未検証です</string> <string name="gpuinfo_below_tested">テスト済みハードウェア(Adreno 725以降)未満:動作しない可能性があります</string> - <string name="gpuinfo_unsupported">サポート対象外:DroidDeckにはAdreno(Snapdragon)GPUが必要です</string> + <string name="gpuinfo_unsupported">サポート対象外:このGPUで利用できる互換グラフィックスバックエンドがありません</string> <string name="turnip_rate_limited">GitHubのレート制限に達しました。後でもう一度お試しください</string> <string name="turnip_github_http">GitHubがHTTP %1$dを返しました</string> diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 09b4273562..2772a9ce1a 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -810,7 +810,7 @@ <string name="setup_gpu_unsupported">GPU 지원되지 않음</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam에는 Adreno 드라이버가 필요합니다. %1$s에서 화면이 검게 변할 수 있습니다.</string> + <string name="setup_gpu_unsupported_detail">사용할 수 있는 호환 그래픽 백엔드가 없습니다. %1$s에서 화면이 검게 표시될 수 있습니다.</string> <string name="setup_runtime">Linux 런타임</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">설치되지 않음 · 약 3GB, 처음 \"Steam 실행\" 시 설치</string> @@ -1390,8 +1390,8 @@ <string name="main_wadb_unavailable">무선 디버깅을 사용할 수 없습니다</string> <string name="main_adb_copied">ADB 명령이 복사되었습니다</string> <string name="main_pick_roms">ROM 폴더 선택</string> - <string name="main_non_adreno_title">Adreno GPU가 아님</string> - <string name="main_non_adreno_text">Turnip은 Adreno GPU를 지원합니다. %1$s에서는 Steam 화면이 검게 표시될 수 있습니다. 다운로드: %2$.0f MB.</string> + <string name="main_non_adreno_title">지원되지 않는 GPU</string> + <string name="main_non_adreno_text">%1$s에서 사용할 수 있는 호환 그래픽 백엔드가 없습니다. Steam 화면이 검게 표시될 수 있습니다. 다운로드: %2$.0f MB.</string> <string name="main_install_anyway">그래도 설치</string> <string name="main_remove_runtime_title">Linux 런타임 제거</string> <string name="main_remove_runtime_text">런타임과 그 안의 Steam 클라이언트, 그리고 런타임에 설치된 모든 게임이 삭제됩니다.</string> @@ -2092,7 +2092,7 @@ <string name="gpuinfo_experimental">실험적: 드라이버가 테스트 빌드입니다</string> <string name="gpuinfo_a850_experimental">실험적 Adreno 850 지원: 호환되는 실험용 디스플레이 및 게임 드라이버가 필요하며, 이 기기에서 검증되지 않았습니다</string> <string name="gpuinfo_below_tested">테스트된 하드웨어(Adreno 725 이상)보다 낮음: 실행되지 않을 수 있습니다</string> - <string name="gpuinfo_unsupported">지원되지 않음: DroidDeck에는 Adreno(Snapdragon) GPU가 필요합니다</string> + <string name="gpuinfo_unsupported">지원되지 않음: 이 GPU에서 사용할 수 있는 호환 그래픽 백엔드가 없습니다</string> <string name="turnip_rate_limited">GitHub 요청 한도에 도달했습니다. 나중에 다시 시도하세요</string> <string name="turnip_github_http">GitHub 응답: HTTP %1$d</string> diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index f39b732126..604346d7f2 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -810,7 +810,7 @@ <string name="setup_gpu_unsupported">GPU tidak disokong</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam memerlukan pemacu Adreno; %1$s mungkin memaparkan skrin hitam</string> + <string name="setup_gpu_unsupported_detail">Tiada backend grafik yang serasi tersedia untuk %1$s. Steam mungkin memaparkan skrin hitam.</string> <string name="setup_runtime">Masa jalan Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Belum dipasang · kira-kira 3 GB, dipasang pada Main pertama</string> @@ -1390,8 +1390,8 @@ <string name="main_wadb_unavailable">Debugging Wayarles tidak tersedia</string> <string name="main_adb_copied">Arahan ADB disalin</string> <string name="main_pick_roms">Pilih folder ROM</string> - <string name="main_non_adreno_title">Bukan GPU Adreno</string> - <string name="main_non_adreno_text">Turnip menyokong GPU Adreno. Pada %1$s, Steam mungkin memaparkan skrin hitam. Muat turun: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU tidak disokong</string> + <string name="main_non_adreno_text">Tiada backend grafik yang serasi tersedia untuk %1$s. Steam mungkin memaparkan skrin hitam. Muat turun: %2$.0f MB.</string> <string name="main_install_anyway">Pasang juga</string> <string name="main_remove_runtime_title">Alih keluar masa jalan Linux</string> <string name="main_remove_runtime_text">Ini memadam masa jalan, klien Steam di dalamnya, dan setiap permainan yang dipasang di sana.</string> @@ -2092,7 +2092,7 @@ <string name="gpuinfo_experimental">Eksperimen: pemacunya ialah binaan ujian</string> <string name="gpuinfo_a850_experimental">Sokongan eksperimen Adreno 850: memerlukan pemacu paparan dan permainan eksperimen yang serasi; belum disahkan pada peranti ini</string> <string name="gpuinfo_below_tested">Di bawah perkakasan yang diuji (Adreno 725 dan lebih baharu): mungkin tidak dapat berjalan</string> - <string name="gpuinfo_unsupported">Tidak disokong: DroidDeck memerlukan GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Tidak disokong: tiada backend grafik yang serasi tersedia untuk GPU ini</string> <string name="turnip_rate_limited">Had kadar GitHub dicapai - cuba lagi kemudian</string> <string name="turnip_github_http">GitHub menjawab HTTP %1$d</string> diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 6efdff9927..91921ebcaa 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">GPU ikke støttet</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam krever en Adreno-driver; %1$s kan vise en svart skjerm</string> + <string name="setup_gpu_unsupported_detail">Ingen kompatibel grafikkbackend er tilgjengelig for %1$s. Steam kan vise en svart skjerm.</string> <string name="setup_runtime">Linux-kjøretid</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Ikke installert · omtrent 3 GB, installeres ved første Spill</string> @@ -1402,8 +1402,8 @@ <string name="main_wadb_unavailable">Trådløs feilsøking er ikke tilgjengelig</string> <string name="main_adb_copied">ADB-kommando kopiert</string> <string name="main_pick_roms">Velg ROM-mappen</string> - <string name="main_non_adreno_title">Ikke en Adreno-GPU</string> - <string name="main_non_adreno_text">Turnip støtter Adreno-GPU-er. På %1$s kan Steam vise en svart skjerm. Nedlasting: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU støttes ikke</string> + <string name="main_non_adreno_text">Ingen kompatibel grafikkbackend er tilgjengelig for %1$s. Steam kan vise en svart skjerm. Nedlasting: %2$.0f MB.</string> <string name="main_install_anyway">Installer likevel</string> <string name="main_remove_runtime_title">Fjern Linux-kjøretid</string> <string name="main_remove_runtime_text">Dette sletter kjøretiden, Steam-klienten inni den, og hvert spill installert der.</string> @@ -2117,7 +2117,7 @@ <string name="gpuinfo_experimental">Eksperimentell: driverne er testbuilder</string> <string name="gpuinfo_a850_experimental">Eksperimentell støtte for Adreno 850: krever kompatible eksperimentelle skjerm- og spilldrivere; ikke bekreftet på denne enheten</string> <string name="gpuinfo_below_tested">Under testet maskinvare (Adreno 725 og nyere): den kan ikke kjøre</string> - <string name="gpuinfo_unsupported">Ikke støttet: DroidDeck krever en Adreno (Snapdragon) GPU</string> + <string name="gpuinfo_unsupported">Støttes ikke: ingen kompatibel grafikkbackend er tilgjengelig for denne GPU-en</string> <string name="turnip_rate_limited">GitHubs hastighetsgrense ble nådd – prøv igjen senere</string> <string name="turnip_github_http">GitHub svarte HTTP %1$d</string> diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 40e6503caf..cc6cafe928 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">GPU niet ondersteund</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam heeft een Adreno-driver nodig; %1$s kan een zwart scherm tonen</string> + <string name="setup_gpu_unsupported_detail">Er is geen compatibele grafische backend beschikbaar voor %1$s. Steam kan een zwart scherm tonen.</string> <string name="setup_runtime">Linux-runtime</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Niet geïnstalleerd · ongeveer 3 GB, geïnstalleerd bij de eerste keer Spelen</string> @@ -1402,8 +1402,8 @@ <string name="main_wadb_unavailable">Draadloze foutopsporing is niet beschikbaar</string> <string name="main_adb_copied">ADB-opdracht gekopieerd</string> <string name="main_pick_roms">Kies de ROM-map</string> - <string name="main_non_adreno_title">Geen Adreno-GPU</string> - <string name="main_non_adreno_text">Turnip ondersteunt Adreno-GPU\'s. Op %1$s kan Steam een zwart scherm tonen. Download: %2$.0f MB.</string> + <string name="main_non_adreno_title">Niet-ondersteunde GPU</string> + <string name="main_non_adreno_text">Er is geen compatibele grafische backend beschikbaar voor %1$s. Steam kan een zwart scherm tonen. Download: %2$.0f MB.</string> <string name="main_install_anyway">Toch installeren</string> <string name="main_remove_runtime_title">Linux-runtime verwijderen</string> <string name="main_remove_runtime_text">Hiermee verwijder je de runtime, de Steam-client erin en alle games die daar zijn geïnstalleerd.</string> @@ -2117,7 +2117,7 @@ <string name="gpuinfo_experimental">Experimenteel: de drivers zijn testbuilds</string> <string name="gpuinfo_a850_experimental">Experimentele ondersteuning voor Adreno 850: vereist compatibele experimentele scherm- en gamedrivers; niet geverifieerd op dit apparaat</string> <string name="gpuinfo_below_tested">Onder de geteste hardware (Adreno 725 en nieuwer): werkt mogelijk niet</string> - <string name="gpuinfo_unsupported">Niet ondersteund: DroidDeck heeft een Adreno-GPU (Snapdragon) nodig</string> + <string name="gpuinfo_unsupported">Niet ondersteund: er is geen compatibele grafische backend beschikbaar voor deze GPU</string> <string name="turnip_rate_limited">De ratelimiet van GitHub is bereikt - probeer het later opnieuw</string> <string name="turnip_github_http">GitHub antwoordde met HTTP %1$d</string> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 0265a3ab81..a7f13dc4e6 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -819,7 +819,7 @@ <string name="setup_gpu_unsupported">GPU nieobsługiwany</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam wymaga sterownika Adreno; %1$s może wyświetlać czarny ekran</string> + <string name="setup_gpu_unsupported_detail">Brak zgodnego zaplecza graficznego dla %1$s. Steam może wyświetlać czarny ekran.</string> <string name="setup_runtime">Środowisko Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Nie zainstalowano · ok. 3 GB, instalowane przy pierwszym „Graj”</string> @@ -1426,8 +1426,8 @@ <string name="main_wadb_unavailable">Debugowanie bezprzewodowe jest niedostępne</string> <string name="main_adb_copied">Skopiowano polecenie ADB</string> <string name="main_pick_roms">Wybierz folder ROM-ów</string> - <string name="main_non_adreno_title">To nie jest GPU Adreno</string> - <string name="main_non_adreno_text">Turnip obsługuje GPU Adreno. Na tym urządzeniu (%1$s) Steam może wyświetlać czarny ekran. Pobieranie: %2$.0f MB.</string> + <string name="main_non_adreno_title">Nieobsługiwany GPU</string> + <string name="main_non_adreno_text">Brak zgodnego zaplecza graficznego dla %1$s. Steam może wyświetlać czarny ekran. Do pobrania: %2$.0f MB.</string> <string name="main_install_anyway">Zainstaluj mimo to</string> <string name="main_remove_runtime_title">Usuń środowisko Linux</string> <string name="main_remove_runtime_text">Spowoduje to usunięcie środowiska, klienta Steam w nim i wszystkich zainstalowanych tam gier.</string> @@ -2167,7 +2167,7 @@ <string name="gpuinfo_experimental">Eksperymentalny: jego sterowniki to wersje testowe</string> <string name="gpuinfo_a850_experimental">Eksperymentalna obsługa Adreno 850: wymaga zgodnych eksperymentalnych sterowników ekranu i gier; nie zweryfikowano na tym urządzeniu</string> <string name="gpuinfo_below_tested">Poniżej testowanego sprzętu (Adreno 725 i nowsze): może nie działać</string> - <string name="gpuinfo_unsupported">Nieobsługiwany: DroidDeck wymaga GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Nieobsługiwany: brak zgodnego zaplecza graficznego dla tego GPU</string> <string name="turnip_rate_limited">Osiągnięto limit zapytań GitHub – spróbuj ponownie później</string> <string name="turnip_github_http">GitHub odpowiedział HTTP %1$d</string> diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index aaff56fc08..d546126ad8 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -816,7 +816,7 @@ <string name="setup_gpu_unsupported">GPU não suportada</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">O Steam requer um controlador Adreno; %1$s pode mostrar um ecrã preto</string> + <string name="setup_gpu_unsupported_detail">Não está disponível um backend gráfico compatível para %1$s. O Steam pode apresentar um ecrã preto.</string> <string name="setup_runtime">Ambiente de execução Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Não instalado · cerca de 3 GB, instalado ao tocar em Jogar pela primeira vez</string> @@ -1406,8 +1406,8 @@ <string name="main_wadb_unavailable">A depuração sem fios não está disponível</string> <string name="main_adb_copied">Comando ADB copiado</string> <string name="main_pick_roms">Escolha a pasta de ROMs</string> - <string name="main_non_adreno_title">Não é uma GPU Adreno</string> - <string name="main_non_adreno_text">O Turnip suporta GPUs Adreno. Com %1$s, o Steam pode mostrar um ecrã preto. Transferência: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU não suportada</string> + <string name="main_non_adreno_text">Não está disponível um backend gráfico compatível para %1$s. O Steam pode apresentar um ecrã preto. Transferência: %2$.0f MB.</string> <string name="main_install_anyway">Instalar mesmo assim</string> <string name="main_remove_runtime_title">Remover runtime Linux</string> <string name="main_remove_runtime_text">Isto elimina o runtime, o cliente Steam que nele existe e todos os jogos lá instalados.</string> @@ -2134,7 +2134,7 @@ <string name="gpuinfo_experimental">Experimental: os controladores são versões de teste</string> <string name="gpuinfo_a850_experimental">Suporte experimental para Adreno 850: requer controladores de ecrã e de jogos experimentais compatíveis; não verificado neste dispositivo</string> <string name="gpuinfo_below_tested">Abaixo do hardware testado (Adreno 725 e mais recentes): pode não funcionar</string> - <string name="gpuinfo_unsupported">Não suportada: o DroidDeck precisa de uma GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Não suportada: não está disponível um backend gráfico compatível para esta GPU</string> <string name="turnip_rate_limited">Foi atingido o limite de pedidos do GitHub - tente novamente mais tarde</string> <string name="turnip_github_http">O GitHub respondeu HTTP %1$d</string> diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 31ea84d9d8..2d16517905 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -816,7 +816,7 @@ <string name="setup_gpu_unsupported">GPU sem suporte</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">A Steam requer um driver Adreno; %1$s pode mostrar uma tela preta</string> + <string name="setup_gpu_unsupported_detail">Nenhum backend gráfico compatível está disponível para %1$s. O Steam pode exibir uma tela preta.</string> <string name="setup_runtime">Runtime do Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Não instalado · cerca de 3 GB, instalado no primeiro Jogar</string> @@ -1406,8 +1406,8 @@ <string name="main_wadb_unavailable">A depuração por Wi-Fi não está disponível</string> <string name="main_adb_copied">Comando ADB copiado</string> <string name="main_pick_roms">Escolha a pasta de ROMs</string> - <string name="main_non_adreno_title">Não é uma GPU Adreno</string> - <string name="main_non_adreno_text">O Turnip é compatível com GPUs Adreno. Com %1$s, o Steam pode mostrar uma tela preta. Download: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU não suportada</string> + <string name="main_non_adreno_text">Nenhum backend gráfico compatível está disponível para %1$s. O Steam pode exibir uma tela preta. Download: %2$.0f MB.</string> <string name="main_install_anyway">Instalar mesmo assim</string> <string name="main_remove_runtime_title">Remover runtime Linux</string> <string name="main_remove_runtime_text">Isso exclui o runtime, o cliente Steam dentro dele e todos os jogos instalados nele.</string> @@ -2134,7 +2134,7 @@ <string name="gpuinfo_experimental">Experimental: os drivers são versões de teste</string> <string name="gpuinfo_a850_experimental">Suporte experimental à Adreno 850: requer drivers de tela e de jogos experimentais compatíveis; não verificado neste dispositivo</string> <string name="gpuinfo_below_tested">Abaixo do hardware testado (Adreno 725 ou mais recente): pode não funcionar</string> - <string name="gpuinfo_unsupported">Incompatível: o DroidDeck precisa de uma GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Não suportada: nenhum backend gráfico compatível está disponível para esta GPU</string> <string name="turnip_rate_limited">O limite de requisições do GitHub foi atingido - tente mais tarde</string> <string name="turnip_github_http">O GitHub respondeu HTTP %1$d</string> diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index 859638f0fa..acb7d2aaef 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -816,7 +816,7 @@ <string name="setup_gpu_unsupported">GPU neacceptat</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam are nevoie de un driver Adreno; %1$s poate arăta un ecran negru</string> + <string name="setup_gpu_unsupported_detail">Nu este disponibil un backend grafic compatibil pentru %1$s. Steam poate afișa un ecran negru.</string> <string name="setup_runtime">Mediul de execuție Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Neinstalat · circa 3 GB, instalat la prima apăsare pe Play</string> @@ -1414,8 +1414,8 @@ <string name="main_wadb_unavailable">Depanarea wireless nu este disponibilă</string> <string name="main_adb_copied">Comanda ADB copiată</string> <string name="main_pick_roms">Alege folderul ROMs</string> - <string name="main_non_adreno_title">Nu este un GPU Adreno</string> - <string name="main_non_adreno_text">Turnip acceptă GPU-uri Adreno. Pe %1$s, Steam poate arăta un ecran negru. Descărcare: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU neacceptat</string> + <string name="main_non_adreno_text">Nu este disponibil un backend grafic compatibil pentru %1$s. Steam poate afișa un ecran negru. Descărcare: %2$.0f MB.</string> <string name="main_install_anyway">Instalează oricum</string> <string name="main_remove_runtime_title">Elimină mediul de execuție Linux</string> <string name="main_remove_runtime_text">Aceasta șterge mediul de execuție, clientul Steam din interiorul lui și fiecare joc instalat acolo.</string> @@ -2142,7 +2142,7 @@ <string name="gpuinfo_experimental">Experimental: driverele sale sunt versiuni de test</string> <string name="gpuinfo_a850_experimental">Suport experimental pentru Adreno 850: necesită drivere experimentale compatibile de afișaj și de jocuri; neverificat pe acest dispozitiv</string> <string name="gpuinfo_below_tested">Sub hardware-ul testat (Adreno 725 și mai nou): poate să nu ruleze</string> - <string name="gpuinfo_unsupported">Neacceptat: DroidDeck are nevoie de un GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Neacceptat: nu este disponibil un backend grafic compatibil pentru acest GPU</string> <string name="turnip_rate_limited">S-a atins limita de solicitări a GitHub - încearcă din nou mai târziu</string> <string name="turnip_github_http">GitHub a răspuns cu HTTP %1$d</string> diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index a710de9258..dd904460a5 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -839,7 +839,7 @@ <string name="setup_gpu_bridged">GPU через мост Mali</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam требует драйвер Adreno; на %1$s возможен черный экран.</string> + <string name="setup_gpu_unsupported_detail">Совместимый графический бэкенд недоступен; на %1$s возможен черный экран.</string> <string name="setup_runtime">Среда выполнения Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Не установлено · около 3 ГБ, устанавливается при первом запуске игры</string> @@ -1472,8 +1472,8 @@ <string name="main_wadb_unavailable">Отладка по Wi-Fi недоступна</string> <string name="main_adb_copied">Команда ADB скопирована</string> <string name="main_pick_roms">Выберите папку ROM</string> - <string name="main_non_adreno_title">GPU не Adreno</string> - <string name="main_non_adreno_text">Turnip поддерживает GPU Adreno. На %1$s в Steam может быть черный экран. Загрузка: %2$.0f МБ.</string> + <string name="main_non_adreno_title">Неподдерживаемый GPU</string> + <string name="main_non_adreno_text">Для %1$s нет совместимого графического бэкенда. В Steam может отображаться чёрный экран. Загрузка: %2$.0f МБ.</string> <string name="main_install_anyway">Все равно установить</string> <string name="main_remove_runtime_title">Удалить среду выполнения Linux</string> <string name="main_remove_runtime_text">Будут удалены среда выполнения, клиент Steam в ней и все установленные туда игры.</string> @@ -2248,7 +2248,7 @@ <string name="gpuinfo_experimental">Экспериментально: его драйверы — тестовые сборки</string> <string name="gpuinfo_a850_experimental">Экспериментальная поддержка Adreno 850: требуются совместимые экспериментальные драйверы дисплея и игр; не проверено на этом устройстве</string> <string name="gpuinfo_below_tested">Ниже проверенного оборудования (Adreno 725 и новее): может не работать</string> - <string name="gpuinfo_unsupported">Не поддерживается: DroidDeck требует GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Не поддерживается: для этого GPU нет совместимого графического бэкенда</string> <string name="gpuinfo_bridge">Работает через мост Mali на собственном драйвере Vulkan телефона</string> <string name="gpuinfo_bridge_off">Не поддерживается без моста Mali: Turnip нужен GPU Adreno (Snapdragon)</string> diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index b1546f900d..c9d57f28e1 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">GPU stöds inte</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam behöver en Adreno-drivrutin; %1$s kan visa en svart skärm</string> + <string name="setup_gpu_unsupported_detail">Ingen kompatibel grafikbackend är tillgänglig för %1$s. Steam kan visa en svart skärm.</string> <string name="setup_runtime">Linux-körmiljö</string> <string name="setup_runtime_progress">%1$s · %2$d %%</string> <string name="setup_runtime_missing">Inte installerad · cirka 3 GB, installeras första gången du trycker på Play</string> @@ -1402,8 +1402,8 @@ <string name="main_wadb_unavailable">Trådlös felsökning är inte tillgänglig</string> <string name="main_adb_copied">ADB-kommandot har kopierats</string> <string name="main_pick_roms">Välj ROM-mappen</string> - <string name="main_non_adreno_title">Inte en Adreno-GPU</string> - <string name="main_non_adreno_text">Turnip stöder Adreno-GPU:er. På %1$s kan Steam visa en svart skärm. Nedladdning: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU stöds inte</string> + <string name="main_non_adreno_text">Ingen kompatibel grafikbackend är tillgänglig för %1$s. Steam kan visa en svart skärm. Hämtning: %2$.0f MB.</string> <string name="main_install_anyway">Installera trots det</string> <string name="main_remove_runtime_title">Ta bort Linux-körmiljön</string> <string name="main_remove_runtime_text">Det här tar bort körmiljön, Steam-klienten i den och alla spel som är installerade där.</string> @@ -2117,7 +2117,7 @@ <string name="gpuinfo_experimental">Experimentell: dess drivrutiner är testversioner</string> <string name="gpuinfo_a850_experimental">Experimentellt stöd för Adreno 850: kräver kompatibla experimentella skärm- och speldrivrutiner; inte verifierat på den här enheten</string> <string name="gpuinfo_below_tested">Under testad maskinvara (Adreno 725 och nyare): det kan hända att det inte fungerar</string> - <string name="gpuinfo_unsupported">Stöds inte: DroidDeck behöver en Adreno-GPU (Snapdragon)</string> + <string name="gpuinfo_unsupported">Stöds inte: ingen kompatibel grafikbackend är tillgänglig för denna GPU</string> <string name="turnip_rate_limited">GitHubs hastighetsgräns nåddes - försök igen senare</string> <string name="turnip_github_http">GitHub svarade HTTP %1$d</string> diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index a28cdeeaf4..fa9ab354bf 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -810,7 +810,7 @@ <string name="setup_gpu_unsupported">ไม่รองรับ GPU นี้</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam ต้องใช้ไดรเวอร์ Adreno; %1$s อาจแสดงจอดำ</string> + <string name="setup_gpu_unsupported_detail">ไม่มีแบ็กเอนด์กราฟิกที่เข้ากันได้สำหรับ %1$s Steam อาจแสดงหน้าจอสีดำ</string> <string name="setup_runtime">รันไทม์ Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">ยังไม่ติดตั้ง · ประมาณ 3 GB จะติดตั้งเมื่อกด Play ครั้งแรก</string> @@ -1390,8 +1390,8 @@ <string name="main_wadb_unavailable">Wireless debugging ไม่พร้อมใช้งาน</string> <string name="main_adb_copied">คัดลอกคำสั่ง ADB แล้ว</string> <string name="main_pick_roms">เลือกโฟลเดอร์ ROM</string> - <string name="main_non_adreno_title">ไม่ใช่ GPU Adreno</string> - <string name="main_non_adreno_text">Turnip รองรับ GPU Adreno บน %1$s Steam อาจแสดงจอดำ ดาวน์โหลด: %2$.0f MB</string> + <string name="main_non_adreno_title">ไม่รองรับ GPU</string> + <string name="main_non_adreno_text">ไม่มีแบ็กเอนด์กราฟิกที่เข้ากันได้สำหรับ %1$s Steam อาจแสดงหน้าจอสีดำ ดาวน์โหลด: %2$.0f MB</string> <string name="main_install_anyway">ติดตั้งอยู่ดี</string> <string name="main_remove_runtime_title">ลบรันไทม์ Linux</string> <string name="main_remove_runtime_text">การลบนี้จะลบรันไทม์ ไคลเอนต์ Steam ภายใน และเกมทุกเกมที่ติดตั้งอยู่ในนั้น</string> @@ -2092,7 +2092,7 @@ <string name="gpuinfo_experimental">ทดลอง: ไดรเวอร์เป็นบิลด์ทดสอบ</string> <string name="gpuinfo_a850_experimental">รองรับ Adreno 850 แบบทดลอง: ต้องใช้ไดรเวอร์จอแสดงผลและไดรเวอร์เกมแบบทดลองที่เข้ากันได้ ยังไม่ได้ตรวจสอบบนอุปกรณ์นี้</string> <string name="gpuinfo_below_tested">ต่ำกว่าฮาร์ดแวร์ที่ทดสอบแล้ว (Adreno 725 และรุ่นใหม่กว่า): อาจรันไม่ได้</string> - <string name="gpuinfo_unsupported">ไม่รองรับ: DroidDeck ต้องใช้ GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">ไม่รองรับ: ไม่มีแบ็กเอนด์กราฟิกที่เข้ากันได้สำหรับ GPU นี้</string> <string name="turnip_rate_limited">ติดขีดจำกัดอัตราของ GitHub - ลองใหม่ในหลัง</string> <string name="turnip_github_http">GitHub ตอบกลับด้วย HTTP %1$d</string> diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 794f7225e8..9015b0d890 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -813,7 +813,7 @@ <string name="setup_gpu_unsupported">GPU desteklenmiyor</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam için Adreno sürücüsü gerekir; %1$s siyah ekran gösterebilir</string> + <string name="setup_gpu_unsupported_detail">%1$s için uyumlu bir grafik arka ucu yok. Steam siyah ekran gösterebilir.</string> <string name="setup_runtime">Linux çalışma zamanı</string> <string name="setup_runtime_progress">%1$s · %%%2$d</string> <string name="setup_runtime_missing">Yüklü değil · yaklaşık 3 GB, ilk kez Oyna\'ya basınca yüklenir</string> @@ -1394,8 +1394,8 @@ <string name="main_wadb_unavailable">Kablosuz hata ayıklama kullanılamıyor</string> <string name="main_adb_copied">ADB komutu kopyalandı</string> <string name="main_pick_roms">ROM klasörünü seçin</string> - <string name="main_non_adreno_title">Adreno GPU değil</string> - <string name="main_non_adreno_text">Turnip, Adreno GPU\'larını destekler. %1$s üzerinde Steam siyah ekran gösterebilir. İndirme: %2$.0f MB.</string> + <string name="main_non_adreno_title">Desteklenmeyen GPU</string> + <string name="main_non_adreno_text">%1$s için uyumlu bir grafik arka ucu yok. Steam siyah ekran gösterebilir. İndirme: %2$.0f MB.</string> <string name="main_install_anyway">Yine de yükle</string> <string name="main_remove_runtime_title">Linux çalışma ortamını kaldır</string> <string name="main_remove_runtime_text">Bu işlem çalışma ortamını, içindeki Steam istemcisini ve oraya yüklenen tüm oyunları siler.</string> @@ -2109,7 +2109,7 @@ <string name="gpuinfo_experimental">Deneysel: sürücüleri test derlemeleri</string> <string name="gpuinfo_a850_experimental">Deneysel Adreno 850 desteği: uyumlu deneysel ekran ve oyun sürücüleri gerekir; bu cihazda doğrulanmadı</string> <string name="gpuinfo_below_tested">Test edilen donanımın altında (Adreno 725 ve daha yenisi): çalışmayabilir</string> - <string name="gpuinfo_unsupported">Desteklenmiyor: DroidDeck bir Adreno (Snapdragon) GPU\'su gerektirir</string> + <string name="gpuinfo_unsupported">Desteklenmiyor: bu GPU için uyumlu bir grafik arka ucu yok</string> <string name="turnip_rate_limited">GitHub\'ın hız sınırına ulaşıldı - daha sonra yeniden deneyin</string> <string name="turnip_github_http">GitHub HTTP %1$d yanıtı verdi</string> diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 90cb9d7e76..7b9d82f355 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -819,7 +819,7 @@ <string name="setup_gpu_unsupported">GPU не підтримується</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam потребує драйвера Adreno; %1$s може показувати чорний екран</string> + <string name="setup_gpu_unsupported_detail">Для %1$s немає сумісного графічного бекенда. Steam може показувати чорний екран.</string> <string name="setup_runtime">Середовище Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Не встановлено · приблизно 3 GB, встановлюється під час першого натискання «Грати»</string> @@ -1426,8 +1426,8 @@ <string name="main_wadb_unavailable">Бездротове налагодження недоступне</string> <string name="main_adb_copied">Команду ADB скопійовано</string> <string name="main_pick_roms">Виберіть папку ROMs</string> - <string name="main_non_adreno_title">GPU не Adreno</string> - <string name="main_non_adreno_text">Turnip підтримує GPU Adreno. На %1$s Steam може показувати чорний екран. Завантаження: %2$.0f MB.</string> + <string name="main_non_adreno_title">Непідтримуваний GPU</string> + <string name="main_non_adreno_text">Для %1$s немає сумісного графічного бекенда. Steam може показувати чорний екран. Завантаження: %2$.0f МБ.</string> <string name="main_install_anyway">Усе одно встановити</string> <string name="main_remove_runtime_title">Видалити середовище Linux</string> <string name="main_remove_runtime_text">Буде видалено середовище, клієнт Steam у ньому та всі встановлені там ігри.</string> @@ -2167,7 +2167,7 @@ <string name="gpuinfo_experimental">Експериментально: його драйвери - тестові збірки</string> <string name="gpuinfo_a850_experimental">Експериментальна підтримка Adreno 850: потрібні сумісні експериментальні драйвери дисплея та ігор; не перевірено на цьому пристрої</string> <string name="gpuinfo_below_tested">Нижче за протестоване обладнання (Adreno 725 і новіші): може не запрацювати</string> - <string name="gpuinfo_unsupported">Не підтримується: DroidDeck потребує GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Не підтримується: для цього GPU немає сумісного графічного бекенда</string> <string name="turnip_rate_limited">Перевищено ліміт запитів GitHub - спробуйте пізніше</string> <string name="turnip_github_http">GitHub відповів HTTP %1$d</string> diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index b4c2c9ec6c..8541e9c792 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -810,7 +810,7 @@ <string name="setup_gpu_unsupported">GPU không được hỗ trợ</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam cần driver Adreno; %1$s có thể hiện màn hình đen</string> + <string name="setup_gpu_unsupported_detail">Không có backend đồ họa tương thích cho %1$s. Steam có thể hiển thị màn hình đen.</string> <string name="setup_runtime">Runtime Linux</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Chưa cài · khoảng 3 GB, được cài vào lần Play đầu tiên</string> @@ -1390,8 +1390,8 @@ <string name="main_wadb_unavailable">Gỡ lỗi qua mạng không dây không khả dụng</string> <string name="main_adb_copied">Đã sao chép lệnh ADB</string> <string name="main_pick_roms">Chọn thư mục ROM</string> - <string name="main_non_adreno_title">Không phải GPU Adreno</string> - <string name="main_non_adreno_text">Turnip hỗ trợ GPU Adreno. Trên %1$s, Steam có thể hiện màn hình đen. Tải xuống: %2$.0f MB.</string> + <string name="main_non_adreno_title">GPU không được hỗ trợ</string> + <string name="main_non_adreno_text">Không có backend đồ họa tương thích cho %1$s. Steam có thể hiển thị màn hình đen. Tải xuống: %2$.0f MB.</string> <string name="main_install_anyway">Vẫn cài</string> <string name="main_remove_runtime_title">Gỡ runtime Linux</string> <string name="main_remove_runtime_text">Việc này xóa runtime, client Steam bên trong nó, và mọi game đã cài ở đó.</string> @@ -2092,7 +2092,7 @@ <string name="gpuinfo_experimental">Thử nghiệm: driver của nó là bản build thử nghiệm</string> <string name="gpuinfo_a850_experimental">Hỗ trợ thử nghiệm Adreno 850: cần driver hiển thị và driver game thử nghiệm tương thích; chưa được xác minh trên thiết bị này</string> <string name="gpuinfo_below_tested">Dưới mức phần cứng đã kiểm thử (Adreno 725 và mới hơn): có thể không chạy được</string> - <string name="gpuinfo_unsupported">Không được hỗ trợ: DroidDeck cần GPU Adreno (Snapdragon)</string> + <string name="gpuinfo_unsupported">Không được hỗ trợ: không có backend đồ họa tương thích cho GPU này</string> <string name="turnip_rate_limited">Đã đạt giới hạn tốc độ của GitHub - hãy thử lại sau</string> <string name="turnip_github_http">GitHub trả về HTTP %1$d</string> diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index ab4ea52424..3c64d969fa 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -811,7 +811,7 @@ <string name="setup_gpu_bridged">GPU 通过 Mali 桥接</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s:%2$s</string> - <string name="setup_gpu_unsupported_detail">Steam 需要 Adreno 驱动;%1$s 可能显示黑屏</string> + <string name="setup_gpu_unsupported_detail">没有可用的兼容图形后端;%1$s 可能显示黑屏</string> <string name="setup_runtime">Linux 运行时</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">未安装 · 约 3 GB,首次点“游玩”时安装</string> @@ -1474,8 +1474,8 @@ <string name="main_wadb_unavailable">无线调试不可用</string> <string name="main_adb_copied">已复制 ADB 命令</string> <string name="main_pick_roms">选择 ROM 文件夹</string> - <string name="main_non_adreno_title">不是 Adreno GPU</string> - <string name="main_non_adreno_text">Turnip 支持 Adreno GPU。在 %1$s 上,Steam 可能显示黑屏。需下载:%2$.0f MB。</string> + <string name="main_non_adreno_title">不受支持的 GPU</string> + <string name="main_non_adreno_text">没有适用于 %1$s 的兼容图形后端。Steam 可能显示黑屏。需下载:%2$.0f MB。</string> <string name="main_install_anyway">仍要安装</string> <string name="main_remove_runtime_title">移除 Linux 运行时</string> <string name="main_remove_runtime_text">这会删除运行时、其中的 Steam 客户端,以及安装在其中的所有游戏。</string> @@ -2171,7 +2171,7 @@ <string name="gpuinfo_experimental">实验性:其驱动为测试构建</string> <string name="gpuinfo_a850_experimental">Adreno 850 实验支持:需要配套的实验版显示驱动和游戏驱动;尚未在此设备上验证</string> <string name="gpuinfo_below_tested">低于已测试的硬件(Adreno 725 及更新):可能无法运行</string> - <string name="gpuinfo_unsupported">不受支持:DroidDeck 需要 Adreno(骁龙)GPU</string> + <string name="gpuinfo_unsupported">不受支持:没有适用于此 GPU 的兼容图形后端</string> <string name="gpuinfo_bridge">通过 Mali 桥接运行,使用手机自带的 Vulkan 驱动</string> <string name="gpuinfo_bridge_off">关闭 Mali 桥接时不受支持:Turnip 需要 Adreno(骁龙)GPU</string> diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index f555a538c3..b864d4bf14 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -810,7 +810,7 @@ <string name="setup_gpu_unsupported">GPU 不受支援</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s:%2$s</string> - <string name="setup_gpu_unsupported_detail">Steam 需要 Adreno 驅動程式;%1$s 可能會出現黑畫面</string> + <string name="setup_gpu_unsupported_detail">沒有可用的兼容圖形後端;%1$s 可能會出現黑畫面</string> <string name="setup_runtime">Linux 運行環境</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">未安裝 · 約 3 GB,首次開啟 Steam 時安裝</string> @@ -1390,8 +1390,8 @@ <string name="main_wadb_unavailable">無法使用無線偵錯</string> <string name="main_adb_copied">已複製 ADB 指令</string> <string name="main_pick_roms">選擇 ROM 資料夾</string> - <string name="main_non_adreno_title">不是 Adreno GPU</string> - <string name="main_non_adreno_text">Turnip 支援 Adreno GPU。在 %1$s 上,Steam 可能會出現黑畫面。下載大小:%2$.0f MB。</string> + <string name="main_non_adreno_title">不受支援的 GPU</string> + <string name="main_non_adreno_text">沒有適用於 %1$s 的兼容圖形後端。Steam 可能會出現黑畫面。下載大小:%2$.0f MB。</string> <string name="main_install_anyway">仍要安裝</string> <string name="main_remove_runtime_title">移除 Linux 運行環境</string> <string name="main_remove_runtime_text">此操作會刪除運行環境、其中的 Steam 用戶端,以及安裝在其中的所有遊戲。</string> @@ -2092,7 +2092,7 @@ <string name="gpuinfo_experimental">實驗性:其驅動程式為測試版本</string> <string name="gpuinfo_a850_experimental">Adreno 850 實驗性支援:需要相容的實驗版顯示驅動程式及遊戲驅動程式;尚未在此裝置上驗證</string> <string name="gpuinfo_below_tested">低於已測試的硬件(Adreno 725 或更新):可能無法執行</string> - <string name="gpuinfo_unsupported">不受支援:DroidDeck 需要 Adreno (Snapdragon) GPU</string> + <string name="gpuinfo_unsupported">不受支援:沒有適用於此 GPU 的兼容圖形後端</string> <string name="turnip_rate_limited">已達 GitHub 的速率限制 - 請稍後再試</string> <string name="turnip_github_http">GitHub 回應 HTTP %1$d</string> diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 6fe964d7f0..e2988446ec 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -810,7 +810,7 @@ <string name="setup_gpu_unsupported">GPU 不受支援</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s:%2$s</string> - <string name="setup_gpu_unsupported_detail">Steam 需要 Adreno 驅動程式;%1$s 可能出現黑畫面。</string> + <string name="setup_gpu_unsupported_detail">沒有可用的相容圖形後端;%1$s 可能出現黑畫面。</string> <string name="setup_runtime">Linux 執行環境</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">未安裝 · 約 3 GB,首次點擊「執行」時安裝</string> @@ -1390,8 +1390,8 @@ <string name="main_wadb_unavailable">無法使用無線偵錯</string> <string name="main_adb_copied">已複製 ADB 指令</string> <string name="main_pick_roms">選擇 ROM 資料夾</string> - <string name="main_non_adreno_title">不是 Adreno GPU</string> - <string name="main_non_adreno_text">Turnip 支援 Adreno GPU。在 %1$s 上,Steam 可能會出現黑畫面。下載大小:%2$.0f MB。</string> + <string name="main_non_adreno_title">不受支援的 GPU</string> + <string name="main_non_adreno_text">沒有適用於 %1$s 的相容圖形後端。Steam 可能會出現黑畫面。下載大小:%2$.0f MB。</string> <string name="main_install_anyway">仍要安裝</string> <string name="main_remove_runtime_title">移除 Linux 執行環境</string> <string name="main_remove_runtime_text">這會刪除執行環境、其中的 Steam 用戶端,以及安裝在其中的所有遊戲。</string> @@ -2092,7 +2092,7 @@ <string name="gpuinfo_experimental">實驗性:其驅動程式為測試版本</string> <string name="gpuinfo_a850_experimental">Adreno 850 實驗性支援:需要相容的實驗版顯示驅動程式及遊戲驅動程式;尚未在此裝置上驗證</string> <string name="gpuinfo_below_tested">低於已測試的硬體(Adreno 725 及更新機型):可能無法執行</string> - <string name="gpuinfo_unsupported">不受支援:DroidDeck 需要 Adreno(Snapdragon)GPU</string> + <string name="gpuinfo_unsupported">不受支援:沒有適用於此 GPU 的相容圖形後端</string> <string name="turnip_rate_limited">已達 GitHub 速率限制 - 請稍後再試</string> <string name="turnip_github_http">GitHub 回應 HTTP %1$d</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f82841a888..0bb1673a0f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -210,6 +210,7 @@ <string name="session_proot_missing">DroidDeck\'s proot could not be downloaded. Check the connection and try again. The session was not started, because the fallback proot is too slow to play on.</string> <string name="session_directaudio_missing">DirectAudio could not be downloaded, so game audio uses the slower path this session.</string> <string name="session_end_program">This program</string> + <string name="session_end_present_fault">The session could not draw to the screen: %1$s. This screen shows why instead of a black one; the session logs have the details.</string> <string name="session_end_steam_download">Couldn\'t download the Steam client. Your network or VPN may be blocking Steam\'s servers; check the connection and try again.</string> <string name="session_end_steam_setup">Couldn\'t set up the Steam client. Check your connection and free storage, then try again.</string> <string name="session_end_fex_missing">%1$s is built for x86 PCs and runs through FEX, which is not installed yet. Start Steam once while signed in and let it download FEX and the Steam Linux Runtime, then start this again.</string> @@ -888,7 +889,7 @@ <string name="setup_gpu_bridged">GPU via Mali bridge</string> <string name="setup_gpu_detail">%1$s · %2$s</string> <string name="setup_gpu_untested_detail">%1$s: %2$s</string> - <string name="setup_gpu_unsupported_detail">Steam needs an Adreno driver; %1$s may show a black screen</string> + <string name="setup_gpu_unsupported_detail">No compatible graphics backend is available; %1$s may show a black screen</string> <string name="setup_runtime">Linux runtime</string> <string name="setup_runtime_progress">%1$s · %2$d%%</string> <string name="setup_runtime_missing">Not installed · about 3 GB, installed on first Play</string> @@ -927,6 +928,14 @@ <string name="setup_game_debug_logs_restart">Restart this session to save game debug logs</string> <string name="setup_logging_update_failed">Couldn\'t update logging. Check the switch and try again.</string> <string name="setup_agent_commands">Debugging tools</string> + <string name="setup_graphics_logs">Detailed graphics logs</string> + <string name="setup_steam_gpu_drawing">Steam interface: GPU drawing</string> + <string name="setup_steam_gpu_drawing_hint">With the Xclipse driver pair, Steam draws its pages in software (GPU drawing showed broken tiles). Turn on for a faster Steam interface if it looks right on this phone.</string> + <string name="drivers_built_on">built %1$s</string> + <string name="drivers_pair_updated">%1$s updated to the newest build</string> + <string name="setup_gpu_bridge_fell_back">The Mali bridge failed its self-test on %1$s last session (images or draws), so the session used the PanVK driver pair instead.</string> + <string name="setup_gpu_bridge_no_memory_sharing">The Mali bridge found no way to share memory with the driver on %1$s last session, so the session used the PanVK driver pair instead. The bridge cannot work on this phone; turning it off keeps the PanVK pair.</string> + <string name="setup_graphics_logs_hint">Each game\'s Proton, DXVK and driver logs in the session\'s logs. Always on when the GPU is not an Adreno.</string> <string name="setup_latest_logs">Latest session logs</string> <string name="setup_saved_logs">Saved session logs</string> <string name="setup_saved_logs_hint">Keeps the newest %1$d</string> @@ -1552,8 +1561,8 @@ <string name="main_wadb_unavailable">Wireless debugging is unavailable</string> <string name="main_adb_copied">ADB command copied</string> <string name="main_pick_roms">Choose the ROMs folder</string> - <string name="main_non_adreno_title">Not an Adreno GPU</string> - <string name="main_non_adreno_text">Turnip supports Adreno GPUs. On %1$s, Steam may show a black screen. Download: %2$.0f MB.</string> + <string name="main_non_adreno_title">Unsupported GPU</string> + <string name="main_non_adreno_text">No compatible graphics backend is available for %1$s. Steam may show a black screen. Download: %2$.0f MB.</string> <string name="main_install_anyway">Install anyway</string> <string name="main_remove_runtime_title">Remove Linux runtime</string> <string name="main_remove_runtime_text">This deletes the runtime, the Steam client inside it, and every game installed there.</string> @@ -2310,11 +2319,27 @@ <string name="look_anime_edge_desc">Toon outlines plus sharpening.</string> <string name="gpuinfo_not_adreno">Not an Adreno GPU</string> + <string name="gpuinfo_powervr">System PowerVR driver: compatibility varies by device</string> + <string name="gpuinfo_xclipse">Experimental: RADV or the system Xclipse driver</string> + <string name="gpu_system_powervr">System PowerVR</string> + <string name="gpu_auto_system_hint">Uses the built-in drivers for this GPU</string> + <string name="drivers_powervr_builtin">The system PowerVR driver is selected for the runtime and display.</string> + <string name="drivers_mali_bridge_auto">No open driver covers this Mali yet: the Mali bridge is on.</string> + <string name="upd_block_non_adreno_test">This is the non-Snapdragon test build: the official builds here only run on Adreno, so they are not installed over it. New test builds are on github.com/The412Banner/droiddeck-nonadreno-drivers.</string> + <string name="session_killed_for_memory">The last session ended because Android closed DroidDeck to free memory, not a crash. Close other apps or lower the game\'s texture settings, then try again.</string> + <string name="drivers_route_venus">Mali (Venus)</string> + <string name="drivers_route_bridge">the Mali bridge</string> + <string name="drivers_mali_no_pair_auto">No open driver covers this Mali yet: %1$s is used, on the phone\'s own driver.</string> + <string name="drivers_mali_unpublished_auto">%1$s isn\'t published yet: %2$s is used until it is.</string> + <string name="drivers_mali_old_vulkan_bridge">%1$s isn\'t available, and this phone\'s driver reports Vulkan %2$s (Venus needs 1.2): the Mali bridge is used.</string> + <string name="drivers_mali_bridge_fallback">%1$s isn\'t published yet: the Mali bridge is on until it is.</string> + <string name="cmgr_powervr_dxvk_queued">Queued: %1$s (waiting for a different runtime driver)</string> + <string name="cmgr_powervr_dxvk_managed">DXVK is provided by the system PowerVR runtime. Other DXVK packages can be stored but are not applied with this driver.</string> <string name="gpuinfo_supported">Supported</string> <string name="gpuinfo_experimental">Experimental: its drivers are test builds</string> <string name="gpuinfo_a850_experimental">Experimental Adreno 850 support: requires compatible experimental display and game drivers; not verified on this device</string> <string name="gpuinfo_below_tested">Below tested hardware (Adreno 725 and newer): it may not run</string> - <string name="gpuinfo_unsupported">Not supported: DroidDeck needs an Adreno (Snapdragon) GPU</string> + <string name="gpuinfo_unsupported">Not supported: no compatible graphics backend is available for this GPU</string> <string name="gpuinfo_bridge">Runs through the Mali bridge, on the phone\'s own Vulkan driver</string> <string name="gpuinfo_bridge_off">Not supported with the Mali bridge off: Turnip needs an Adreno (Snapdragon) GPU</string> @@ -2869,6 +2894,13 @@ <string name="gog_achievements_enable_store">Enable GOG achievements in Stores settings</string> <string name="gog_achievements_unavailable">Achievements unavailable; check session logs</string> <string name="achievement_unlocked">Achievement unlocked</string> + <string name="setup_gpu_venus_off">Mali (Venus): off</string> + <string name="setup_gpu_venus_on">Mali (Venus): on</string> + <string name="setup_gpu_venus_host_too_old">The driver on %1$s reports Vulkan %2$s. Mali (Venus) needs Vulkan 1.2 or newer (gamescope does not start on older), so sessions skip Venus and use the PanVK driver pair instead.</string> + <string name="setup_gpu_bridge_off">Mali bridge: off</string> + <string name="setup_gpu_bridge_unusable">%1$s cannot use the Mali bridge (it needs a Mali GPU without a system-driver route), so this switch has no effect here.</string> + <string name="setup_gpu_bridge_on">Mali bridge: on</string> + <string name="setup_gpu_bridge_detail">%1$s is not an Adreno. The experimental Vulkan bridge is on: the session draws through the phone\'s own driver. Expect bugs; send the session logs.</string> <string name="touch_paste">Paste</string> <string name="touch_dpad">D-pad</string> <string name="touch_left_stick">Left stick</string> @@ -3644,6 +3676,11 @@ <string name="sync_web_title">Syncthing</string> <string name="sync_web_reload">Reload</string> <string name="sync_not_running">Syncthing isn\'t running.</string> + <string name="setup_bridge_safe">Safe mode</string> + <string name="setup_bridge_safe_on">Safe mode: on</string> + <string name="setup_bridge_safe_off">Safe mode: off</string> + <string name="setup_bridge_safe_on_detail">Most compatible. Recommended for a new device.</string> + <string name="setup_bridge_safe_off_detail">Faster where this GPU passed its checks.</string> <string name="session_end_steam_sigill">Steam stopped with an illegal instruction (SIGILL). This can be a CPU instruction compatibility problem or a client crash. Share the logs with your device details.</string> <string name="session_end_steam_try_x64">You can try Steam settings → Steam client → x86-64 (experimental). It needs an additional download and may run more slowly.</string> <string name="session_end_vulkan_device">The Linux graphics driver could not find a usable Vulkan device. Check that the selected Linux GPU driver supports this GPU.</string> @@ -3723,19 +3760,11 @@ <string name="stores_xbox_cloud_settings">Cloud settings</string> <string name="xbox_cloud_gaming" translatable="false">Xbox Cloud Gaming</string> <string name="xbox_filter_game_pass" translatable="false">Game Pass</string> - <string name="setup_gpu_bridge_off">Mali bridge: off</string> - <string name="setup_gpu_bridge_on">Mali bridge: on</string> - <string name="setup_bridge_safe">Safe mode</string> - <string name="setup_bridge_safe_on">Safe mode: on</string> - <string name="setup_bridge_safe_off">Safe mode: off</string> - <string name="setup_bridge_safe_on_detail">Most compatible. Recommended for a new device.</string> - <string name="setup_bridge_safe_off_detail">Faster where this GPU passed its checks.</string> <string name="setup_bridge_dxvk">DXVK</string> <string name="setup_bridge_dxvk_auto">DXVK: automatic</string> <string name="setup_bridge_dxvk_proton">DXVK: Proton\'s own</string> <string name="setup_bridge_dxvk_auto_detail">Uses an older DXVK where this GPU\'s Vulkan is too old for Proton\'s.</string> <string name="setup_bridge_dxvk_proton_detail">Every Proton keeps its own DXVK, even where this GPU\'s Vulkan may be too old for it.</string> - <string name="setup_gpu_bridge_detail">%1$s is not an Adreno. The experimental Vulkan bridge is on: the session draws through the phone\'s own driver. Expect bugs; send the session logs.</string> <string name="integration_title">Steam integration</string> <string name="integration_count">%1$d of %2$d on</string> <string name="integration_set_up">Set up</string> diff --git a/app/src/test/java/com/droiddeck/launcher/core/DeviceSupportTest.kt b/app/src/test/java/com/droiddeck/launcher/core/DeviceSupportTest.kt new file mode 100644 index 0000000000..6338889980 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/core/DeviceSupportTest.kt @@ -0,0 +1,14 @@ +package com.droiddeck.launcher.core + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class DeviceSupportTest { + @Test fun runtimeDownloadAcceptsOnlyRecognizedGraphicsBackends() { + assertTrue(DeviceSupport.graphicsAvailable(adreno = true, powerVrReady = false)) + assertTrue(DeviceSupport.graphicsAvailable(adreno = false, powerVrReady = true)) + // A PowerVR HAL without usable DRM access also reaches this unavailable case. + assertFalse(DeviceSupport.graphicsAvailable(adreno = false, powerVrReady = false)) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt index 409637e0cc..638533b12a 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/WinCompSourcesTest.kt @@ -77,6 +77,8 @@ class WinCompSourcesTest { @Test fun steamworksSharedDepotsMapToComponents() { assertEquals(listOf("vcredist2015_dll" to "VC++ 2015", "d3dx9" to "DirectX (June 2010)"), WinCompSources.steamDepots(listOf("228986", "228990", "999"))) + // Hotline Miami's OpenAL depot: the DLL-copy entry, which installs without running anything. + assertEquals(listOf("oalinst_dll" to "OpenAL"), WinCompSources.steamDepots(listOf("229020"))) } diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/DeviceInfoTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/DeviceInfoTest.kt new file mode 100644 index 0000000000..808425f67d --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/gpu/DeviceInfoTest.kt @@ -0,0 +1,13 @@ +package com.droiddeck.launcher.gpu + +import org.junit.Assert.assertEquals +import org.junit.Test + +class DeviceInfoTest { + @Test fun builtinLabelsDistinguishPowerVrFromTurnipAndGenericSystemVulkan() { + assertEquals("System PowerVR", DeviceInfo.builtinDriverLabel(powerVr = true, runtime = true)) + assertEquals("System PowerVR", DeviceInfo.builtinDriverLabel(powerVr = true, runtime = false)) + assertEquals("the runtime's own Turnip", DeviceInfo.builtinDriverLabel(powerVr = false, runtime = true)) + assertEquals("System Vulkan", DeviceInfo.builtinDriverLabel(powerVr = false, runtime = false)) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/DriverBundleTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/DriverBundleTest.kt index 6082d3ddf6..b9c0ce819b 100644 --- a/app/src/test/java/com/droiddeck/launcher/gpu/DriverBundleTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/gpu/DriverBundleTest.kt @@ -129,4 +129,19 @@ class DriverBundleTest { assertEquals(2, DriverBundle.all(context).size) assertFalse(first.androidId == second.androidId) } + + @Test fun failedNonAdrenoReplacementKeepsTheInstalledPairAndSelection() { + manifest.put("tag", "PanVK-G610-v1") + val first = DriverBundle.install(context, bundle()) + DriverBundle.select(context, first) + try { + DriverBundle.install(context, bundle(linuxLibc = "libc.so")) + fail("Accepted a bionic Linux driver") + } catch (_: IllegalArgumentException) { + } + assertEquals(first.id, DriverBundle.active(context)?.id) + assertTrue(TurnipDriver(context).isInstalled(first.androidId)) + assertTrue(LinuxVulkanDriverManager(context).isInstalled(first.linuxId)) + assertEquals(1, DriverBundle.all(context).size) + } } diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairUpdateTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairUpdateTest.kt new file mode 100644 index 0000000000..eb3a556de4 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairUpdateTest.kt @@ -0,0 +1,37 @@ +package com.droiddeck.launcher.gpu + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], manifest = Config.NONE) +class DriverPairUpdateTest { + private fun pair(sha: String, id: Long, updated: String, key: String = DriverPairs.nonAdreno("PanVK-Mali-G615")) = + TurnipReleases.Asset("Non-Adreno", "panvk-mali-g615", "PanVK-Mali-G615-Pair.zip", "https://example/p", 9_000_000, false, + "label", sha, key, bundle = true, assetId = id, updatedAt = updated) + + @Test fun aRebuildUnderTheSameTagIsAnUpdate() { + val context = RuntimeEnvironment.getApplication() + val installed = pair("a".repeat(64), 1, "2026-10-13T10:00:00Z") + assertFalse("nothing installed yet", TurnipReleases.updateAvailable(context, installed)) + TurnipReleases.recordDownload(context, installed, "PanVK-Mali-G615") + assertFalse(TurnipReleases.updateAvailable(context, installed)) + assertEquals("2026-10-13", TurnipReleases.installedBuiltOn(context, installed)) + assertTrue(TurnipReleases.updateAvailable(context, pair("b".repeat(64), 2, "2026-10-15T10:00:00Z"))) + assertTrue("a new asset id alone", TurnipReleases.updateAvailable(context, pair("a".repeat(64), 2, "2026-10-13T10:00:00Z"))) + assertEquals("2026-10-15", pair("b".repeat(64), 2, "2026-10-15T10:00:00Z").builtOn) + } + + @Test fun adrenoPairsAreNeverFlagged() { + val context = RuntimeEnvironment.getApplication() + val turnip = pair("a".repeat(64), 1, "2026-10-13T10:00:00Z", key = DriverPairs.BANNER) + TurnipReleases.recordDownload(context, turnip, "Turnip-x") + assertFalse(TurnipReleases.updateAvailable(context, pair("b".repeat(64), 2, "2026-10-15T10:00:00Z", key = DriverPairs.BANNER))) + } +} 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 6ff43cb125..514afac36d 100644 --- a/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt @@ -42,6 +42,23 @@ class DriverPairsTest { assertEquals(GpuInfo.Support.UNSUPPORTED, gpu(0, adreno = false).support) } + @Test + fun powerVrUsesItsOwnFamilyWithoutClaimingAllModelsAreTested() { + assertEquals(Family.POWERVR, GpuInfo.familyOf(false, 0, powerVr = true)) + assertEquals(Family.NOT_ADRENO, GpuInfo.familyOf(false, 0, powerVr = false)) + assertEquals(Family.A7XX, GpuInfo.familyOf(true, 740, powerVr = true)) + val powerVr = GpuInfo("PowerVR", 0, Family.POWERVR, "", false) + assertEquals(GpuInfo.Support.UNTESTED, powerVr.support) + assertNull("PowerVR never downloads an Adreno driver pair", DriverPairs.recommendedKey(powerVr, emptyList())) + val pairs = DriverPairs.from(TurnipReleases.Check( + listOf(asset("Turnip-r4.zip", "r4", false, DriverPairs.BANNER), + asset("Turnip-r4-Linux.zip", "r4", true, DriverPairs.BANNER)), + emptyList(), emptyList(), 0L, + )) + assertFalse(pairs.single().suits(powerVr)) + assertNull(DriverPairs.recommendedKey(powerVr, pairs)) + } + @Test fun autoPicksWinNativeBalancedOn8xxAndBannersElsewhere() { assertEquals(DriverPairs.WN_BALANCED, DriverPairs.recommendedKey(gpu(830), emptyList())) @@ -116,4 +133,134 @@ class DriverPairsTest { assertEquals(DriverPairs.BANNER_ONEUI, DriverPairs.recommendedKey(gpu(740, oneUi = true), pairs)) assertEquals(DriverPairs.BANNER, DriverPairs.recommendedKey(gpu(650), pairs)) } + + @Test + fun maliFamiliesFollowTheOpenDriverBuilds() { + assertEquals(Family.MALI_JM, GpuInfo.familyOf(false, 0, mali = "Mali-G57 MC2")) + assertEquals(Family.MALI_JM, GpuInfo.familyOf(false, 0, mali = "Mali-G77")) + assertEquals(Family.MALI_G610_G710, GpuInfo.familyOf(false, 0, mali = "Mali-G710")) + assertEquals(Family.MALI_G615, GpuInfo.familyOf(false, 0, mali = "Mali-G615 MC6")) + assertEquals(Family.MALI_G720, GpuInfo.familyOf(false, 0, mali = "Mali-G720-Immortalis MC12")) + assertEquals(Family.MALI_LATEST, GpuInfo.familyOf(false, 0, mali = "Mali-G925-Immortalis MC12")) + assertEquals(Family.MALI_OTHER, GpuInfo.familyOf(false, 0, mali = "Mali-T880")) + assertEquals(Family.MALI_OTHER, GpuInfo.familyOf(false, 0, mali = "")) + // An Adreno is an Adreno whatever else the device reports, and the system HAL keeps priority. + assertEquals(Family.A7XX, GpuInfo.familyOf(true, 740, mali = "Mali-G720")) + assertEquals(Family.POWERVR, GpuInfo.familyOf(false, 0, powerVr = true, mali = "Mali-G720")) + } + + @Test + fun autoPicksTheOpenDriverForEachMaliAndNothingForTheRest() { + fun mali(name: String) = GpuInfo(name, 0, GpuInfo.familyOf(false, 0, mali = name), "", false) + // Android 14: the per-generation builds; the newest Malis have none and use the bridge. + assertEquals(DriverPairs.NAD_MALI_JM, DriverPairs.recommendedKey(mali("Mali-G57"), emptyList(), sdk = 34)) + assertEquals(DriverPairs.NAD_MALI_G710, DriverPairs.recommendedKey(mali("Mali-G710"), emptyList(), sdk = 34)) + assertEquals(DriverPairs.NAD_MALI_G615, DriverPairs.recommendedKey(mali("Mali-G615"), emptyList(), sdk = 34)) + assertEquals(DriverPairs.NAD_MALI_G720, DriverPairs.recommendedKey(mali("Mali-G720"), emptyList(), sdk = 34)) + assertNull(DriverPairs.recommendedKey(mali("Mali-G925-Immortalis MC12"), emptyList(), sdk = 34)) + // Android 15+: the one-binary kbase build for every Mali it covers, not the Bifrost G52/G76. + assertEquals(DriverPairs.NAD_MALI_KBASE, DriverPairs.recommendedKey(mali("Mali-G57"), emptyList(), sdk = 35)) + assertEquals(DriverPairs.NAD_MALI_KBASE, DriverPairs.recommendedKey(mali("Mali-G720"), emptyList(), sdk = 36)) + assertEquals(DriverPairs.NAD_MALI_KBASE, DriverPairs.recommendedKey(mali("Mali-G925-Immortalis MC12"), emptyList(), sdk = 36)) + assertEquals(DriverPairs.NAD_MALI_JM, DriverPairs.recommendedKey(mali("Mali-G52 MC2"), emptyList(), sdk = 36)) + assertNull("a Mali no build covers uses the bridge", DriverPairs.recommendedKey(mali("Mali-T880"), emptyList(), sdk = 36)) + assertEquals(DriverPairs.BANNER, DriverPairs.recommendedKey(gpu(740), emptyList())) + } + + @Test + fun aMissingKbaseReleaseFallsBackToTheGenerationsPair() { + val g720 = GpuInfo("Mali-G720", 0, Family.MALI_G720, "", false) + fun bundle(id: String) = TurnipReleases.Asset("Non-Adreno", id.lowercase(), "$id-Pair.zip", "https://example/$id", 9_000_000, + false, "label", "0".repeat(64), DriverPairs.nonAdreno(id), bundle = true) + val onlyG720 = DriverPairs.from(TurnipReleases.Check(listOf(bundle("PanVK-Mali-G720")), emptyList(), emptyList(), 0L)) + assertEquals(DriverPairs.NAD_MALI_G720, DriverPairs.recommendedKey(g720, onlyG720, sdk = 36)) + val both = DriverPairs.from(TurnipReleases.Check(listOf(bundle("PanVK-Mali-G720"), bundle("PanVK-Mali-kbase")), emptyList(), emptyList(), 0L)) + assertEquals(DriverPairs.NAD_MALI_KBASE, DriverPairs.recommendedKey(g720, both, sdk = 36)) + assertTrue(both.single { it.key == DriverPairs.NAD_MALI_KBASE }.suits(g720)) + assertFalse(both.single { it.key == DriverPairs.NAD_MALI_KBASE }.suits(GpuInfo("Mali-G52", 0, Family.MALI_JM, "", false))) + } + + @Test + fun nonAdrenoPairsComeFromTheirBundlesAndSuitOnlyTheirGpu() { + val pairs = DriverPairs.from(TurnipReleases.Check( + listOf( + TurnipReleases.Asset("Non-Adreno", "panvk-mali-g720", "PanVK-Mali-G720-Pair.zip", "https://example/a", 9_000_000, + false, "label", "0".repeat(64), DriverPairs.nonAdreno("PanVK-Mali-G720"), bundle = true), + TurnipReleases.Asset("Non-Adreno", "radv-xclipse", "RADV-Xclipse-Pair.zip", "https://example/b", 9_000_000, + false, "label", "0".repeat(64), DriverPairs.nonAdreno("RADV-Xclipse"), bundle = true), + ), + emptyList(), emptyList(), 0L, + )) + val g720 = pairs.single { it.key == DriverPairs.NAD_MALI_G720 } + val radv = pairs.single { it.key == DriverPairs.NAD_RADV_XCLIPSE } + assertTrue(g720.complete) + assertTrue(g720.suits(GpuInfo("Mali-G720", 0, Family.MALI_G720, "", false))) + assertFalse(g720.suits(gpu(740))) + assertTrue(radv.suits(GpuInfo("Xclipse", 0, Family.POWERVR, "", false))) + assertFalse("RADV is not for a PowerVR Pixel", radv.suits(GpuInfo("PowerVR", 0, Family.POWERVR, "", false))) + assertTrue(DriverPairs.isNonAdreno("PanVK-Mali-G720")) + assertTrue(DriverPairs.isNonAdreno("RADV-Xclipse-2")) + assertFalse(DriverPairs.isNonAdreno("DD-Turnip-v0.1.0")) + assertFalse(DriverPairs.isNonAdreno(null)) + } + + @Test + fun upstreamRadvIsAManualXclipseChoiceAndAutoKeepsOurs() { + val asset = { id: String -> TurnipReleases.Asset("Non-Adreno", id.lowercase(), "$id-Pair.zip", "https://example/$id", 9_000_000, + false, "label", "0".repeat(64), DriverPairs.nonAdreno(id), bundle = true) } + val pairs = DriverPairs.from(TurnipReleases.Check(listOf(asset("RADV-Xclipse"), asset("RADV-Xclipse-upstream")), emptyList(), emptyList(), 0L)) + val xclipse = GpuInfo("Samsung Xclipse 940", 0, Family.POWERVR, "", false) + val upstream = pairs.single { it.key == DriverPairs.NAD_RADV_XCLIPSE_UPSTREAM } + assertEquals("nad:radv-xclipse-upstream", DriverPairs.nonAdreno("RADV-Xclipse-upstream")) + assertTrue(upstream.complete) + assertTrue(upstream.suits(xclipse)) + assertFalse(upstream.suits(GpuInfo("PowerVR", 0, Family.POWERVR, "", false))) + assertEquals("RADV upstream · Samsung Xclipse", upstream.name) + assertEquals(DriverPairs.NAD_RADV_XCLIPSE, DriverPairs.recommendedKey(xclipse, pairs)) + assertTrue(DriverPairs.isNonAdreno("RADV-Xclipse-upstream")) + } + + @Test + fun deviceBuildsAreOfferedOnlyForTheirMaliAndNeverByAuto() { + fun bundle(id: String) = TurnipReleases.Asset("Non-Adreno", id.lowercase(), "$id-Pair.zip", "https://example/$id", 9_000_000, + false, "label", "0".repeat(64), DriverPairs.nonAdreno(id), bundle = true) + val pairs = DriverPairs.from(TurnipReleases.Check( + listOf(bundle("PanVK-faux123-RP4Pro"), bundle("PanVK-faux123-Ace"), bundle("PanVK-faux123-RG556")), + emptyList(), emptyList(), 0L)) + val g77 = GpuInfo("Mali-G77 MC9", 0, Family.MALI_JM, "", false) + val g57 = GpuInfo("Mali-G57 MC2", 0, Family.MALI_JM, "", false) + val g610 = GpuInfo("Mali-G610 MC6", 0, Family.MALI_G610_G710, "", false) + assertTrue(pairs.single { it.key == DriverPairs.NAD_FAUX_RP4PRO }.suits(g77)) + assertFalse(pairs.single { it.key == DriverPairs.NAD_FAUX_RP4PRO }.suits(g57)) + assertTrue(pairs.single { it.key == DriverPairs.NAD_FAUX_RG556 }.suits(g57)) + assertTrue(pairs.single { it.key == DriverPairs.NAD_FAUX_ACE }.suits(g610)) + 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"))) + // An Exynos with a Mali, and a Helio G99, by board name. + assertEquals(Family.MALI_JM, GpuInfo.familyOf(false, 0, mali = GpuInfo.maliOfSoc(listOf("s5e8835")))) + assertEquals(Family.MALI_JM, GpuInfo.familyOf(false, 0, mali = GpuInfo.maliOfSoc(listOf("MT6789")))) + 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)")) + } + + @Test + fun theMaliG1SeriesHasNoPanVkPairAndIsKnownByItsChip() { + // Arch v14 (Dimensity 9500): no PanVK build is proven there, so Auto uses the phone's own driver. + assertEquals("Mali-G1-Ultra (by chip mt6993)", GpuInfo.maliOfSoc(listOf("MT6993"))) + assertEquals(Family.MALI_OTHER, GpuInfo.familyOf(false, 0, mali = "Mali-G1-Ultra MC12")) + } + + @Test + fun autoTakesRadvOnAnXclipseAndLeavesPowerVrOnTheSystemDriver() { + assertEquals(DriverPairs.NAD_RADV_XCLIPSE, DriverPairs.recommendedKey(GpuInfo("Samsung Xclipse 940", 0, Family.POWERVR, "", false), emptyList())) + assertNull(DriverPairs.recommendedKey(GpuInfo("PowerVR", 0, Family.POWERVR, "", false), emptyList())) + } } diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/GpuDetectionTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/GpuDetectionTest.kt index 7348210c9b..cf4bfe76c5 100644 --- a/app/src/test/java/com/droiddeck/launcher/gpu/GpuDetectionTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/gpu/GpuDetectionTest.kt @@ -80,7 +80,7 @@ class GpuDetectionTest { assertEquals("Experimental Adreno 850 support: requires compatible experimental display and game drivers; not verified on this device", info(true, 850).supportText) assertEquals("Experimental: its drivers are test builds", info(true, 720).supportText) assertEquals("Outside tested hardware (Adreno 650, 725 and newer): it may not run", info(true, 618).supportText) - assertEquals("Not supported: DroidDeck needs an Adreno (Snapdragon) GPU", info(false, 0).supportText) + assertEquals("Not supported: no compatible graphics backend is available for this GPU", info(false, 0).supportText) assertEquals("Not an Adreno GPU", Family.NOT_ADRENO.label) assertEquals("Adreno 8xx", Family.A8XX.label) } diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/SystemVulkanPruningTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/SystemVulkanPruningTest.kt new file mode 100644 index 0000000000..9f593658f7 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/gpu/SystemVulkanPruningTest.kt @@ -0,0 +1,109 @@ +package com.droiddeck.launcher.gpu + +import java.io.File +import java.nio.file.Files +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder + +class SystemVulkanPruningTest { + @get:Rule val temporary = TemporaryFolder() + + @Test fun completedReplacementCollectsOnlyManagedOldDirectories() { + val base = temporary.newFolder("system_vulkan") + val current = completeRuntime(base, "a".repeat(64)) + val old = completeRuntime(base, "b".repeat(64)) + val stage = abandonedStage(base) + val unrelated = File(base, "notes").apply { mkdir(); File(this, "keep").writeText("keep") } + + SystemVulkanDriver.pruneUnused(current, true) + + assertEquals("current ICD", File(current, "icd.json").readText()) + assertTrue(File(current, "run-proton.py").canExecute()) + assertFalse(old.exists()) + assertFalse(stage.exists()) + assertEquals("keep", File(unrelated, "keep").readText()) + } + + @Test fun aSurvivingGuestKeepsOldVersionsButNotAbandonedStages() { + val base = temporary.newFolder("system_vulkan") + val current = completeRuntime(base, "a".repeat(64)) + val old = completeRuntime(base, "b".repeat(64)) + val stage = abandonedStage(base) + + SystemVulkanDriver.pruneUnused(current, false) + + assertTrue(current.isDirectory) + assertTrue(old.isDirectory) + assertFalse(stage.exists()) + SystemVulkanDriver.pruneUnused(current, true) + assertFalse("collect the old version once guests stop", old.exists()) + } + + @Test fun failedReplacementPreservesThePreviousGoodRuntime() { + val base = temporary.newFolder("system_vulkan") + val current = File(base, "a".repeat(64)) + val old = completeRuntime(base, "b".repeat(64)) + val stage = abandonedStage(base) + + SystemVulkanDriver.pruneUnused(current, true) + assertTrue("missing replacement", old.isDirectory) + assertFalse(stage.exists()) + + current.mkdir() + File(current, "icd.json").writeText("incomplete") + SystemVulkanDriver.pruneUnused(current, true) + assertEquals("current ICD", File(old, "icd.json").readText()) + } + + @Test fun deletingOldRuntimeDoesNotFollowItsSymlinks() { + val base = temporary.newFolder("system_vulkan") + val current = completeRuntime(base, "a".repeat(64)) + val old = File(base, "b".repeat(64)).apply { mkdir() } + val outside = temporary.newFolder("outside") + val sentinel = File(outside, "keep").apply { writeText("keep") } + Files.createSymbolicLink(File(old, "outside").toPath(), outside.toPath()) + + SystemVulkanDriver.pruneUnused(current, true) + + assertFalse(old.exists()) + assertEquals("keep", sentinel.readText()) + } + + @Test fun linkedBaseOrCurrentRuntimePreventsCleanup() { + val base = temporary.newFolder("system_vulkan") + val old = completeRuntime(base, "b".repeat(64)) + val current = File(base, "a".repeat(64)) + Files.createSymbolicLink(current.toPath(), old.toPath()) + SystemVulkanDriver.pruneUnused(current, true) + assertTrue(old.isDirectory) + + Files.delete(current.toPath()) + completeRuntime(base, current.name) + val alias = File(temporary.root, "alias") + Files.createSymbolicLink(alias.toPath(), base.toPath()) + SystemVulkanDriver.pruneUnused(File(alias, current.name), true) + assertTrue(old.isDirectory) + } + + private fun abandonedStage(base: File) = + File(base, ".stage-12345678-1234-1234-1234-123456789abc").apply { mkdir(); File(this, "partial").writeText("partial") } + + private fun completeRuntime(base: File, version: String): File { + val directory = File(base, version).apply { mkdir() } + val components = listOf( + "lib/libhybris-vulkan-icd.so.0", "lib/libhybris-common.so.1", "lib/libhybris/linker/q.so", + "lib/libVkLayer_hybris_compat.so", "run-proton.py", + "wsi/libVkLayer_window_system_integration.so", "wsi/VkLayer_window_system_integration.json", + ) + listOf("x32", "x64").flatMap { arch -> + listOf("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi").map { "dxvk/$arch/$it.dll" } + } + components.forEach { path -> File(directory, path).apply { parentFile!!.mkdirs(); writeText("component") } } + File(directory, "run-proton.py").setExecutable(true) + File(directory, "icd.json").writeText("current ICD") + return directory + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/SystemVulkanSelectionTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/SystemVulkanSelectionTest.kt new file mode 100644 index 0000000000..29a25037ff --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/gpu/SystemVulkanSelectionTest.kt @@ -0,0 +1,129 @@ +package com.droiddeck.launcher.gpu + +import java.io.File +import java.nio.file.Files +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Assert.assertThrows +import org.junit.Test + +class SystemVulkanSelectionTest { + @Test fun defaultPowerVrUsesTheSystemBridge() { + assertTrue(SystemVulkanDriver.usesDefault(true, "")) + assertTrue(SystemVulkanDriver.usesDefault(true, null)) + } + + @Test fun otherGpusAndExplicitImportsKeepTheirDriver() { + assertFalse(SystemVulkanDriver.usesDefault(false, "")) + assertFalse(SystemVulkanDriver.usesDefault(false, null)) + assertFalse(SystemVulkanDriver.usesDefault(true, "custom-driver")) + } + @Test fun renderNodeRequiresARealCharacterDeviceAndBothAccessModes() { + assertTrue(SystemVulkanDriver.renderNodeAvailable(true, true, true)) + assertFalse("a regular placeholder is not a DRM device", SystemVulkanDriver.renderNodeAvailable(false, true, true)) + assertFalse("read access is required", SystemVulkanDriver.renderNodeAvailable(true, false, true)) + assertFalse("write access is required", SystemVulkanDriver.renderNodeAvailable(true, true, false)) + assertFalse("a missing node is unavailable", SystemVulkanDriver.renderNodeAvailable(false, false, false)) + } + + @Test fun renderNodeDriverMustIdentifyPowerVrExactly() { + for (name in listOf("pvrsrvkm", "pvr", "powervr")) + assertTrue(name, SystemVulkanDriver.powerVrDriver(name)) + for (name in listOf(null, "", "msm", "panfrost", "not-pvr")) + assertFalse(name, SystemVulkanDriver.powerVrDriver(name)) + } + + @Test fun samsungXclipseGpuNodeIsSelectedOverItsDisplayNode() { + assertTrue(SystemVulkanDriver.powerVrDriver("sgpu")) + assertFalse("the display controller is not the GPU", SystemVulkanDriver.powerVrDriver("exynos-drm")) + // Galaxy A56 (Exynos 1580): the GPU owns renderD128, the display controller renderD129. + val drivers = mapOf("/dev/dri/renderD128" to "sgpu", "/dev/dri/renderD129" to "exynos-drm") + assertEquals("/dev/dri/renderD128", SystemVulkanDriver.findRenderNode(null) { path -> + SystemVulkanDriver.powerVrDriver(drivers[path]) + }) + } + + @Test fun renderNodeIdentityUsesTheDriverLinkOrUevent() { + val device = Files.createTempDirectory("powervr-device").toFile() + try { + assertFalse("missing identity is unavailable", SystemVulkanDriver.powerVrDevice(device)) + val uevent = File(device, "uevent") + uevent.writeText("DRIVER=pvrsrvkm\nOF_NAME=gpu0\n") + assertTrue(SystemVulkanDriver.powerVrDevice(device)) + uevent.writeText("DRIVER=msm\nOF_COMPATIBLE_0=not-pvr\n") + assertFalse(SystemVulkanDriver.powerVrDevice(device)) + val driver = File(device, "driver").toPath() + Files.createSymbolicLink(driver, File("../../drivers/pvrsrvkm").toPath()) + assertTrue(SystemVulkanDriver.powerVrDevice(device)) + Files.delete(driver) + Files.createSymbolicLink(driver, File("../../drivers/msm").toPath()) + uevent.writeText("DRIVER=pvrsrvkm\n") + assertFalse("an unrelated driver link must not fall back", SystemVulkanDriver.powerVrDevice(device)) + } finally { + device.deleteRecursively() + } + } + + @Test fun renderNodeDiscoverySkipsOtherDriversAndDeniedNodes() { + val drivers = mapOf( + "/dev/dri/renderD128" to "msm", + "/dev/dri/renderD129" to "pvr", + "/dev/dri/renderD130" to "pvrsrvkm", + ) + assertEquals("/dev/dri/renderD129", SystemVulkanDriver.findRenderNode(null) { path -> + SystemVulkanDriver.powerVrDriver(drivers[path]) + }) + assertEquals("/dev/dri/renderD130", SystemVulkanDriver.findRenderNode(null) { path -> + SystemVulkanDriver.powerVrDriver(drivers[path]) && + SystemVulkanDriver.renderNodeAvailable(true, path != "/dev/dri/renderD129", true) + }) + } + + @Test fun renderNodesAreDiscoveredWithoutDirectoryListing() { + for (minor in listOf(128, 129, 191)) { + val expected = "/dev/dri/renderD$minor" + assertEquals(expected, SystemVulkanDriver.findRenderNode(null) { it == expected }) + } + assertNull(SystemVulkanDriver.findRenderNode(null) { false }) + } + + @Test fun listedRenderNodesCoverExtendedMinorNumbers() { + assertEquals("/dev/dri/renderD256", SystemVulkanDriver.findRenderNode( + arrayOf("card0", "renderD256", "renderD128/device", "../renderD129"), + ) { path -> + assertTrue(path, path.matches(Regex("/dev/dri/renderD[0-9]+"))) + path == "/dev/dri/renderD256" + }) + } + + @Test fun defaultPowerVrResolvesToTheSystemIcd() { + assertEquals("system/icd.json", LinuxVulkanDriver.resolveIcdPath("", true, + { "system/icd.json" }, { error("default must not resolve an import") })) + } + + @Test fun defaultAdrenoLeavesTheRuntimeIcdUnchanged() { + assertNull(LinuxVulkanDriver.resolveIcdPath("", false, + { error("Adreno must not prepare the system bridge") }, { error("default must not resolve an import") })) + } + + @Test fun missingManualPowerVrImportFailsWithoutSwitchingBackends() { + val failure = assertThrows(IllegalStateException::class.java) { + LinuxVulkanDriver.resolveIcdPath("missing-driver", true, + { error("manual preference must not silently switch to the system backend") }, { null }) + } + assertTrue(failure.message!!.contains("missing-driver")) + assertTrue(failure.message!!.contains("use Auto")) + } + + @Test fun missingAdrenoImportKeepsTheExistingRuntimeFallback() { + assertNull(LinuxVulkanDriver.resolveIcdPath("missing-driver", false, + { error("Adreno must not prepare the system bridge") }, { null })) + } + + @Test fun manualPowerVrResolvesTheChosenImport() { + assertEquals("imports/chosen/icd.json", LinuxVulkanDriver.resolveIcdPath("chosen", true, + { error("manual must not prepare the system bridge") }, { "imports/$it/icd.json" })) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/ForcedPackageTest.kt b/app/src/test/java/com/droiddeck/launcher/session/ForcedPackageTest.kt index 241d815459..966934ef04 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/ForcedPackageTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/ForcedPackageTest.kt @@ -141,6 +141,34 @@ class ForcedPackageTest { assertDefaultDxvkRestoreRow(protonName) } + @Test fun systemPowerVrRejectsNewGameDxvkSelectionsWithoutChangingSavedProfiles() { + writeGameProfile("42", "dxvk", "custom-dxvk.wcp") + val state = File(context.filesDir, "components/state.json") + val saved = state.readText() + + assertThrows(IllegalStateException::class.java) { + ComponentsManager.setGameComponent(context, "42", "dxvk", "replacement.wcp") { + ComponentsManager.runtimeManaged(it, true) + } + } + + assertEquals(saved, state.readText()) + assertEquals("custom-dxvk.wcp", ComponentsManager.gameComponents(context, "42")["dxvk"]) + assertFalse(launchState().exists()) + } + + @Test fun systemPowerVrAllowsClearingASavedGameDxvkSelection() { + proton("proton-exp") + writeGameProfile("42", "dxvk", "custom-dxvk.wcp") + + ComponentsManager.setGameComponent(context, "42", "dxvk", null) { + ComponentsManager.runtimeManaged(it, true) + } + + assertTrue(ComponentsManager.gameComponents(context, "42").isEmpty()) + assertDefaultDxvkRestoreRow("proton-exp") + } + @Test fun aNewProtonIsCapturedWhenTheLastOverrideIsReset() { proton("existing") writeGameProfile("42", "dxvk", "custom-dxvk.wcp") diff --git a/app/src/test/java/com/droiddeck/launcher/session/GraphicsReportTest.kt b/app/src/test/java/com/droiddeck/launcher/session/GraphicsReportTest.kt new file mode 100644 index 0000000000..0900617ae5 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/GraphicsReportTest.kt @@ -0,0 +1,39 @@ +package com.droiddeck.launcher.session + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import java.io.File + +class GraphicsReportTest { + @get:Rule val tmp = TemporaryFolder() + + @Test fun deviceNumbersSplitAsLinuxDoes() { + // /dev/mali0 on the testers' phones: 10:103 (misc); a DRM render node: 226:128. + assertEquals(10L, GraphicsReport.major(10L shl 8 or 103L)) + assertEquals(103L, GraphicsReport.minor(10L shl 8 or 103L)) + assertEquals(226L, GraphicsReport.major(226L shl 8 or 128L)) + assertEquals(128L, GraphicsReport.minor(226L shl 8 or 128L)) + } + + @Test fun gameLogsAreCutPerFileAndOldestLaunchesGoFirst() { + val games = tmp.newFolder("games") + fun launch(name: String, bytes: Int) = File(games, name).apply { mkdirs() }.also { File(it, "steam-1.log").writeBytes(ByteArray(bytes)) } + 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 = 170) + assertEquals(100L, File(new, "steam-1.log").length()) + assertFalse(old.exists()) + assertTrue(mid.exists()) + assertTrue(new.exists()) + } + + @Test fun aMissingGamesFolderIsFine() { + GraphicsReport.capGames(File(tmp.root, "none")) + GraphicsReport.finish(tmp.newFolder("session")) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/OrphanReaperProcessTest.kt b/app/src/test/java/com/droiddeck/launcher/session/OrphanReaperProcessTest.kt new file mode 100644 index 0000000000..bb766e75ca --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/OrphanReaperProcessTest.kt @@ -0,0 +1,23 @@ +package com.droiddeck.launcher.session + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class OrphanReaperProcessTest { + @Test fun unavailableProcessListDefersCleanup() { + assertTrue(OrphanReaper.hasOtherProcesses(null, 100) { false }) + } + + @Test fun theAppAndForeignProcessesDoNotKeepOldRuntimes() { + assertFalse(OrphanReaper.hasOtherProcesses(listOf(0, 1, 100, 200), 100) { pid -> + check(pid == 200) { "do not probe self or process groups" } + false + }) + } + + @Test fun anyRemainingAppProcessDefersCleanup() { + assertTrue(OrphanReaper.hasOtherProcesses(listOf(100, 200, 300), 100) { it == 300 }) + assertFalse(OrphanReaper.hasOtherProcesses(emptyList(), 100) { true }) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/PowerVrAutoDriversTest.kt b/app/src/test/java/com/droiddeck/launcher/session/PowerVrAutoDriversTest.kt new file mode 100644 index 0000000000..fe2f6a8125 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/PowerVrAutoDriversTest.kt @@ -0,0 +1,44 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import org.robolectric.RuntimeEnvironment +import com.droiddeck.launcher.gpu.TurnipDriver +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], manifest = Config.NONE) +class PowerVrAutoDriversTest { + private val context: Context = RuntimeEnvironment.getApplication() + + @Before fun reset() { + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit() + SessionPrefs.setLinuxDriver(context, "imported-linux") + SessionPrefs.setAndroidDriver(context, "imported-display") + } + + @Test fun autoRepairsStaleAdrenoSelectionsOnPowerVr() { + SessionPrefs.setGpuDriverMode(context, SessionPrefs.GPU_DRIVERS_AUTO) + SessionPrefs.ensurePowerVrAutoDrivers(context, powerVr = true) + assertEquals("", SessionPrefs.linuxDriver(context)) + assertEquals(TurnipDriver.AUTO, SessionPrefs.androidDriver(context)) + } + + @Test fun explicitManualChoicesRemainOnPowerVr() { + SessionPrefs.setGpuDriverMode(context, SessionPrefs.GPU_DRIVERS_MANUAL) + SessionPrefs.ensurePowerVrAutoDrivers(context, powerVr = true) + assertEquals("imported-linux", SessionPrefs.linuxDriver(context)) + assertEquals("imported-display", SessionPrefs.androidDriver(context)) + } + + @Test fun adrenoAutoChoicesRemain() { + SessionPrefs.setGpuDriverMode(context, SessionPrefs.GPU_DRIVERS_AUTO) + SessionPrefs.ensurePowerVrAutoDrivers(context, powerVr = false) + assertEquals("imported-linux", SessionPrefs.linuxDriver(context)) + assertEquals("imported-display", SessionPrefs.androidDriver(context)) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/PowerVrComponentsTest.kt b/app/src/test/java/com/droiddeck/launcher/session/PowerVrComponentsTest.kt new file mode 100644 index 0000000000..3a768aee77 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/PowerVrComponentsTest.kt @@ -0,0 +1,14 @@ +package com.droiddeck.launcher.session + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class PowerVrComponentsTest { + @Test fun onlyDxvkIsManagedWithTheSystemPowerVrRuntime() { + assertTrue(ComponentsManager.runtimeManaged("dxvk", systemPowerVr = true)) + assertFalse(ComponentsManager.runtimeManaged("dxvk", systemPowerVr = false)) + assertFalse(ComponentsManager.runtimeManaged("fex", systemPowerVr = true)) + assertFalse(ComponentsManager.runtimeManaged("vkd3d", systemPowerVr = true)) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/PowerVrQueuedComponentsTest.kt b/app/src/test/java/com/droiddeck/launcher/session/PowerVrQueuedComponentsTest.kt new file mode 100644 index 0000000000..66aaeb650c --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/PowerVrQueuedComponentsTest.kt @@ -0,0 +1,41 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import com.droiddeck.launcher.runtime.LinuxRuntime +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], manifest = Config.NONE) +class PowerVrQueuedComponentsTest { + @Test fun managedDxvkQueueRemainsVisibleAndCanBeCancelled() { + val context: Context = RuntimeEnvironment.getApplication() + val root = LinuxRuntime.rootDir(context) + root.deleteRecursively() + val data = File(context.filesDir, "components") + data.deleteRecursively() + data.mkdirs() + val proton = File(root, "root/.local/share/Steam/compatibilitytools.d/test-proton") + File(proton, "files/lib/wine").mkdirs() + File(proton, "proton").writeText("# test Proton\n") + File(proton, "version").writeText("1 test-build\n") + File(data, "state.json").writeText(JSONObject().put("queued", JSONObject().put("test-proton", + JSONObject().put("dxvk", JSONObject().put("kind", "package").put("file", "chosen.wcp").put("label", "chosen DXVK")) + )).toString()) + + assertTrue(ComponentsManager.applyQueued(context) { ComponentsManager.runtimeManaged(it, true) }.isEmpty()) + val deferred = ComponentsManager.snapshot(context).protons.single().components.getValue("dxvk") + assertEquals("chosen DXVK", deferred.queued) + + ComponentsManager.cancelQueued(context, "test-proton", "dxvk") + assertNull(ComponentsManager.snapshot(context).protons.single().components.getValue("dxvk").queued) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionEndHintTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionEndHintTest.kt index c5f75297ea..4bc4aef334 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionEndHintTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionEndHintTest.kt @@ -8,6 +8,7 @@ import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test @@ -31,11 +32,18 @@ class SessionEndHintTest { @get:Rule val temporary = TemporaryFolder() private lateinit var activity: SessionActivity private var previousArchitecture: String? = null + private var previousLog: File? = null + private var previousDirectory: File? = null @Before fun setUp() { previousArchitecture = SessionState.steamClientArch + previousLog = SessionState.logFile + previousDirectory = SessionState.logDirectory + SessionState.logFile = null + SessionState.logDirectory = null DetectedGpu.family = GpuInfo.Family.NOT_ADRENO + DetectedGpu.name = "test GPU" activity = Robolectric.buildActivity(SessionActivity::class.java).get() SessionState.steamClientArch = "arm64" } @@ -43,7 +51,10 @@ class SessionEndHintTest { @After fun tearDown() { SessionState.steamClientArch = previousArchitecture + SessionState.logFile = previousLog + SessionState.logDirectory = previousDirectory DetectedGpu.family = GpuInfo.Family.NOT_ADRENO + DetectedGpu.name = "test GPU" } @Test @@ -80,10 +91,35 @@ class SessionEndHintTest { } @Test - fun vulkanFailureOnNonAdrenoExplainsTheMissingLinuxDriver() { - DetectedGpu.family = GpuInfo.Family.NOT_ADRENO + fun vulkanFailureOnNonAdrenoIdentifiesTheGpuAndOffersDriverGuidance() { + for (family in GpuInfo.Family.entries.filter { it.mali || it == GpuInfo.Family.POWERVR || it == GpuInfo.Family.NOT_ADRENO }) { + DetectedGpu.family = family + val expected = "test GPU (${family.label("test GPU")})\n" + activity.getString(R.string.session_end_vulkan_device) + assertEquals(family.name, expected, hintText(vulkanLog())) + } + DetectedGpu.family = GpuInfo.Family.POWERVR + DetectedGpu.name = "Samsung Xclipse 940" + assertEquals("Samsung Xclipse 940 (Samsung Xclipse)\n" + activity.getString(R.string.session_end_vulkan_device), + hintText(vulkanLog())) + } - assertEquals(activity.getString(R.string.session_end_gpu_unsupported), hintText(vulkanLog())) + @Test + fun cleanExitRetainsAnUnrecoveredPresentationFault() { + SessionState.logDirectory = temporary.root + File(temporary.root, "wayland.log").writeText("DD_PRESENT_FAULT: GPU completion is unknown\n") + val hint = exitHint(0) + assertNotNull(hint) + assertEquals(activity.getString(R.string.session_end_present_fault, "GPU completion is unknown"), + ReflectionHelpers.getField<String>(hint, "text")) + assertTrue(ReflectionHelpers.getField(hint, "evenOnSuccess")) + } + + @Test + fun cleanExitIgnoresRecoveredFaultsAndUnrelatedSessionWarnings() { + SessionState.logDirectory = temporary.root + File(temporary.root, "wayland.log").writeText("DD_PRESENT_FAULT: old fault\npresentation recovered: fault cleared\n") + SessionState.logFile = sigillLog() + assertNull(exitHint(0)) } @Test @@ -103,6 +139,9 @@ class SessionEndHintTest { private fun hint(log: File?): Any? = SessionActivity::class.java .getDeclaredMethod("sessionEndHint", File::class.java).apply { isAccessible = true }.invoke(activity, log) + private fun exitHint(status: Int): Any? = SessionActivity::class.java + .getDeclaredMethod("sessionExitHint", Int::class.javaPrimitiveType).apply { isAccessible = true }.invoke(activity, status) + private fun hintText(log: File): String { val result = hint(log) assertNotNull(result) @@ -112,10 +151,11 @@ class SessionEndHintTest { @Implements(value = GpuInfo.Companion::class, isInAndroidSdk = false) class DetectedGpu { @Implementation - fun detect(): GpuInfo = GpuInfo("test GPU", if (family == GpuInfo.Family.A6XX) 610 else 0, family, "", false) + fun detect(): GpuInfo = GpuInfo(name, if (family == GpuInfo.Family.A6XX) 610 else 0, family, "", false) companion object { var family = GpuInfo.Family.NOT_ADRENO + var name = "test GPU" } } } diff --git a/app/src/test/java/com/droiddeck/launcher/ui/ComponentsPageProfileTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/ComponentsPageProfileTest.kt index 501438788e..8d9d59f8d7 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/ComponentsPageProfileTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/ComponentsPageProfileTest.kt @@ -1,10 +1,24 @@ package com.droiddeck.launcher.ui +import android.app.Application +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.semantics.SemanticsProperties +import androidx.compose.ui.test.SemanticsMatcher +import androidx.compose.ui.test.assertCountEquals +import androidx.compose.ui.test.assertIsEnabled +import androidx.compose.ui.test.assertIsNotEnabled +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.onAllNodesWithText +import androidx.compose.ui.test.onLast import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performScrollTo import com.droiddeck.launcher.R import com.droiddeck.launcher.frontend.Library +import com.droiddeck.launcher.session.ComponentsManager +import java.io.File +import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -12,8 +26,9 @@ import org.robolectric.RobolectricTestRunner import org.robolectric.RuntimeEnvironment import org.robolectric.annotation.Config +// Exercise the component UI without starting App's process-wide servers or crash handler. @RunWith(RobolectricTestRunner::class) -@Config(sdk = [28]) +@Config(sdk = [28], application = Application::class) class ComponentsPageProfileTest { @get:Rule val compose = createRobolectricComposeRule() private val gameA = Library.SteamGame(42, "Game A", null, "internal") @@ -98,4 +113,143 @@ class ComponentsPageProfileTest { } } } + + @Test @Config(qualifiers = "w1280dp-h1000dp") + fun systemPowerVrKeepsStoredDxvkDisabledAndQueuedDxvkCancellable() { + val context = RuntimeEnvironment.getApplication() + var cancelled = 0 + var imported = 0 + var swapped = 0 + var restored = 0 + showDxvk( + systemPowerVr = true, + onCancel = { cancelled++ }, + onImport = { imported++ }, + onSwap = { swapped++ }, + onRestore = { restored++ }, + ) + + compose.onNodeWithText(context.getString(R.string.cmgr_powervr_dxvk_managed)).assertExists() + compose.onNodeWithText(context.getString(R.string.cmgr_powervr_dxvk_queued, "Next DXVK"), substring = true).assertExists() + compose.onNodeWithText("Stored DXVK").assertIsNotEnabled() + compose.onNodeWithText(context.getString(R.string.comp_original, "1.0")).assertIsNotEnabled() + compose.onNodeWithText(context.getString(R.string.comp_restore_original)).assertIsNotEnabled() + compose.onNodeWithText(context.getString(R.string.common_cancel)).performClick() + compose.onNodeWithText(context.getString(R.string.comp_import_wcp)).performScrollTo().assertIsEnabled().performClick() + compose.runOnIdle { + assertEquals(1, cancelled) + assertEquals(1, imported) + assertEquals(0, swapped) + assertEquals(0, restored) + } + } + + @Test @Config(qualifiers = "w1280dp-h1000dp") + fun manualRuntimeKeepsDxvkSelectionAvailable() { + val context = RuntimeEnvironment.getApplication() + showDxvk(systemPowerVr = false) + + compose.onNode(hasText("Stored DXVK") and SemanticsMatcher.expectValue(SemanticsProperties.Role, Role.RadioButton)).assertIsEnabled() + compose.onNodeWithText(context.getString(R.string.comp_original, "1.0")).assertIsEnabled() + compose.onNodeWithText(context.getString(R.string.comp_restore_original)).assertIsEnabled() + compose.onNodeWithText(context.getString(R.string.cmgr_powervr_dxvk_managed)).assertDoesNotExist() + } + + @Test @Config(qualifiers = "w1280dp-h1000dp") + fun systemPowerVrGameProfileKeepsOtherComponentChoicesAndRuntimeOptionsAvailable() { + val context = RuntimeEnvironment.getApplication() + showDxvk(systemPowerVr = true) + compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick() + compose.onNodeWithText("Game A").performClick() + compose.waitUntil(5_000) { + compose.onAllNodesWithText(context.getString(R.string.comp_game_reset)).fetchSemanticsNodes().isNotEmpty() + } + + compose.onNodeWithText(context.getString(R.string.gpu_system_powervr)).assertIsNotEnabled() + compose.onNodeWithText(context.getString(R.string.cmgr_powervr_dxvk_managed)).assertExists() + val inheritedChoices = compose.onAllNodesWithText(context.getString(R.string.comp_game_use_general)) + inheritedChoices.assertCountEquals(4) // FEX preset, FEX package, Proton and VKD3D remain selectable. + repeat(4) { inheritedChoices[it].assertIsEnabled() } + val runtimeOptions = compose.onAllNodesWithText(context.getString(R.string.comp_game_runtime_options)) + runtimeOptions.assertCountEquals(2) + repeat(2) { runtimeOptions[it].assertIsEnabled() } + compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertDoesNotExist() + + compose.onNodeWithText("Game A").performClick() + compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick() + compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertExists() + } + + @Test @Config(qualifiers = "w1280dp-h1000dp") + fun systemPowerVrGameProfileCanClearAnExistingDxvkOverrideWithoutSelectingAnother() { + val context = RuntimeEnvironment.getApplication() + showDxvk(systemPowerVr = true, gameDxvkOverride = true) + compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick() + compose.onNodeWithText("Game A").performClick() + compose.waitUntil(5_000) { + compose.onAllNodesWithText(context.getString(R.string.comp_game_reset)).fetchSemanticsNodes().isNotEmpty() + } + + compose.onNodeWithText(context.getString(R.string.gpu_system_powervr)).performScrollTo().assertIsEnabled().performClick() + compose.onNodeWithText("Stored DXVK").assertDoesNotExist() + compose.onAllNodesWithText(context.getString(R.string.comp_game_use_general)).onLast().performClick() + compose.waitUntil(5_000) { "dxvk" !in ComponentsManager.gameComponents(context, "42") } + compose.onNodeWithText(context.getString(R.string.gpu_system_powervr)).assertIsNotEnabled() + } + + private fun showDxvk( + systemPowerVr: Boolean, + gameDxvkOverride: Boolean = false, + onCancel: () -> Unit = {}, + onImport: () -> Unit = {}, + onSwap: (String) -> Unit = {}, + onRestore: (String) -> Unit = {}, + ) { + val context = RuntimeEnvironment.getApplication() + File(context.filesDir, "components/state.json").apply { + parentFile!!.mkdirs() + writeText(if (gameDxvkOverride) """{"profiles":{"42":{"dxvk":"stored.wcp"}}}""" else "{}") + } + val proton = ComponentsManager.Proton( + "test-proton", "Test Proton", File(context.filesDir, "test-proton"), "/test-proton", "1.0", false, + ) + val snapshot = ComponentsManager.Snapshot( + protons = listOf(ComponentsManager.ProtonView( + proton = proton, + components = mapOf("dxvk" to ComponentsManager.Component("1.0", "", "Stored DXVK", "", "stored.wcp", "Next DXVK")), + originals = listOf(ComponentsManager.Original("dxvk", "1.0", "Original DXVK", 1)), + inUseByGame = false, + )), + packages = listOf(ComponentsManager.Package("stored.wcp", "dxvk", "Stored DXVK", "", 1)), + ) + compose.setContent { + DroidDeckTheme { + ComponentsPage( + snapshot = snapshot, + catalog = emptyList(), + catalogAt = 0, + protonId = proton.id, + comp = "dxvk", + checking = false, + busy = null, + downloads = emptyMap(), + onProton = {}, + onComp = {}, + onSwap = onSwap, + onRestore = onRestore, + onCancelQueued = onCancel, + onDeletePackage = {}, + onDeleteOriginal = {}, + onDownload = {}, + onRefresh = {}, + onImport = onImport, + onBack = {}, + gpu = GpuDriversState(powerVr = true, systemPowerVr = systemPowerVr), + games = listOf(Library.SteamGame(42, "Game A", null, "internal")), + requestInitialFocus = false, + ) + } + } + } + } diff --git a/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt b/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt index 5bb78ff9cc..1dad18e921 100644 --- a/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt @@ -130,6 +130,12 @@ class AppUpdatesTest { assertNull(AppUpdates.installBlock(stable, me("eeeeeee", versionCode = 9))) } + @Test + fun theNonAdrenoTestBuildIsNeverReplacedByAnOfficialBuild() { + val testBuild = AppUpdates.Installed("eeeeeee", 0, "0.2.0", 9, updatable = true, nonAdrenoTest = true) + assertNotNull(AppUpdates.installBlock(stable, testBuild)) + } + @Test fun aMissingVariantIsBlockedBeforeDownload() { val missing = release("ddddddd", withApk = false) diff --git a/docs/development/american-nightmare-pixel-debug.md b/docs/development/american-nightmare-pixel-debug.md new file mode 100644 index 0000000000..ef5992dd03 --- /dev/null +++ b/docs/development/american-nightmare-pixel-debug.md @@ -0,0 +1,197 @@ +# American Nightmare on Pixel: rendering workaround and remaining limits + +Local engineering results from 2026-10-11/12. Steam game 202750 was tested on a +Pixel 11 Pro Fold using the Pixel Lab runtime. These observations do not establish +compatibility across the Pixel family or a fix for the system resets. + +## Rendering result + +The bright dotted triangle edges over textured rocks, boards and the player are +not an application wireframe setting: traced input and driver pipelines all used +`VK_POLYGON_MODE_FILL`, with no dynamic polygon mode. The original affected path +used 2x MSAA, RGBA16F color and D24S8 depth. The game's minimum UI AA setting and +`d3d11.disableMsaa` did not disable its D3D9 multisampling. + +A real single-sample D3D9 comparison removed the visible bright triangle edges. +Trial 16 verified 114 input and 114 driver pipelines, all single-sample. Trial 17 +retained correct meshes/textures through movement and turning, with 119 pipelines +in each phase, all single-sample. This isolates a useful workaround to the MSAA +path; it does not identify the precise faulty operation or prove a vendor bug. +The override also changes effective surface descriptors, so the application may +select different AA-aware shader/rendering paths. + +`tools/dxvk/patches/0004-d3d9-force-single-sample.patch` adds an explicit per-game +`d3d9.forceSingleSample` option, default **False**. After validating the original +sample request, D3D9 surface normalization selects `D3DMULTISAMPLE_NONE` and quality +0. GetDesc, image creation, resolves and sample-dependent state use this effective +description. This intentionally disables MSAA, per-sample masks and +alpha-to-coverage. It is a compatibility override, not transparent MSAA emulation +or a universal PowerVR default. Existing low32, BC-format, present synchronization +and tiler workarounds must remain intact. + +Swapchain backbuffers have a separate creation path. With the override enabled, +that path now validates a copy of the original requested descriptor and transfers +the effective sample type/quality before allocation, so automatic depth surfaces +and backbuffers agree. Validation uses the application's lockable-backbuffer flag; +the internal lockability required for GDI fallback is retained on the allocated +backbuffer. With the override disabled the original backbuffer path is unchanged. +This correction addresses official PR602 review 5486295088. Its CPU harness +compiles the actual DXVK sample decoder, surface normalizer and backbuffer method, +plus the automatic-depth descriptor and framebuffer depth-binding excerpts. +Fifteen cases cover on/off, NONMASKABLE quality, matching depth, no-depth operation, +unsupported/invalid/lockable requests, allocation cleanup and recreation. Backend +images and adapter capabilities are mocked; these are not GPU or gameplay tests. + +## Independent HUD correction + +The diagnostic frametimes HUD bound an R8_UINT storage texel buffer to a shader +whose SPIR-V image format was Unknown. This required formatless buffer writes +which the device did not report for that format, producing VUID 07029. +`0003-hud-explicit-r8-texel-format.patch` declares `r8ui` to match the actual host +view. No capabilities are fabricated. The build now compiles and validates the +actual shader, and checks binding 3 for DimBuffer/storage/R8ui. The original shader +fails that contract; the patched shader passes. Real-game trial 15 used the new +DLLs, removed 07029, and retained the original triangle edges. This HUD bug is +separate from the rendering workaround, and is not a proven reset cause. + +VUID 06479 for color-format comparison descriptors remains under investigation. +The D3D9 shader uses a conditional comparison path; static validation output alone +does not prove that the offending branch executes. No warning suppression or +false format-feature claims are proposed. Trial 14's LOG+FAIL with a duplicate +limit blocked only the first message of each kind, not every invalid API call; +subsequent trials used logging only. Do not describe these runs as fully blocked +validation or GPU-assisted validation. + +## Responsiveness, performance and stability + +Paired screenshots prove movement and camera changes, rather than relying on an +input receipt. Trial 17 completed eight samples without a black viewport. Its +cold sample was 3.2 FPS; later recognized samples were 19.1-29.9 FPS, with roughly +2.54 CPU-core equivalents. Camera/workload, capture overhead and thermals were +not controlled; this is not a reliable A/B benchmark. + +The planned eight-minute trial 17 stopped at a focus/session guard after the last +confirmed sample at 315.6 seconds. Steam owned focus; the target game was still +available for a single client quit. Its temporary settings were successfully +restored, and the phone boot counter remained 12. The focus change's cause is +unknown. The run is **incomplete**, not an eight-minute pass or a demonstrated +game crash. Controls, focus ownership and sustained stability still need broader +coverage beyond these short tests. + +### Final production configuration and user confirmation + +The clean production configuration was persisted only for game 202750 through +the application's per-game environment UI. It selects the tested DXVK component +and sets `d3d9.forceSingleSample = True`, retaining the existing low32, BC, +presentation-sync and `dxvk.tilerMode = False` workarounds. Shared configuration +and other games were unchanged. Shader audit layers, validation and the +frametimes HUD are not enabled in this production configuration. + +A final automated production trial loaded the existing saved game, verified +turning/movement with five paired non-black screenshots, and observed 115 seconds +without the bright triangle edges or another phone reset. It then quit normally; +the saved per-game environment remained unchanged. This is bounded observation, +not a long-duration stability or controlled performance benchmark. + +On 2026-10-11 (America/Toronto), the device owner separately confirmed that this +stage worked and authorized publication. No duration, frame rate or full-game +completion was supplied with that confirmation. It is additional user validation +of the stage, not a claim that all Pixel devices or the GNOC resets are fixed. + +## Native guards, resets and diagnostic controls + +The Pixel base is e589e3ae21959c9c74c490d917cebf256acc8ac8. PR561's 9e6fe314 and +3c363910 guards were integrated in an isolated worktree; 26 selected production-C +regressions and a full APK/runtime verification passed. Pixel AHB support remains +present. The existing Lab app was updated without uninstalling or resetting its +Steam account. This APK preceded a second system reset, so the native guards are +not a verified reset fix. + +Two resets changed the boot counter 10 -> 11 -> 12. After personal unlock, narrow +kernel/firmware projections confirmed GNOC/access-control details for the first, +and `reset,warm,gnoc_error` with a fresh GNOC numeric record for the second. The +specific faulty component/operation and any relation to rendering are unknown. +`tools/pixel_reset_diagnostics.py` exports only fixed fault categories/numeric +fields, lock state, boot counter and entry times; never arbitrary log text or +account data. Boot-property and kernel last-boot reasons use the same exact +allowlist of canonical categories and the observed `reset,warm,gnoc_error` value; +unknown reasons and custom suffixes produce `unknown`, never their original text. +Primary-user states are likewise limited to recognized lifecycle categories. +Output files are created exclusively with mode `0600` before any bytes are +written (POSIX), and existing files/symlinks are refused. Host regressions cover +these boundaries as well as freshness, unlock gating and narrow output. +Dropbox's offset-free local timestamp is not assigned a guessed instant during +a DST transition: repeated hours report `ambiguous_device_local_time`, skipped +hours report `nonexistent_device_local_time`. Neither is attributed to the trial +or used to project kernel-body categories until its time can be established. + +Private opt-in diagnostics captured maintenance5 inline modules, which the older +shim path missed. Materialization passed nine actual-C ASan/UBSan cases; benign +pipeline-chain planning passed twelve. Real-game NoContraction, scaled vertex +conversion and force-clip rewrites were actually applied and did not remove the +edges. None is a production default. Sixty-two valid bounded, owned offscreen GPU +cases passed exact pixel readback, fences and validation, covering interpolation, +seams, perspective meshes, interface widening, scaled fetch, HDR/depth prepasses, +real clipping and nonconstant depth. Invalid initial fixtures are excluded. These +passing controls do not exonerate every driver/rendering path. + +## Reproducibility and recovery + +The runtime artifact supplies both architectures, exact DLL hashes, public patched +DXVK sources, all four patches, wrapper and build recipe. It contains no game +assets, bytecode, saves, account files, screenshots or raw device logs. Source +patches apply cleanly to pinned DXVK revision 25ca63f17f34bdc05a39873ee63907d3cbbfa030. +All five runtime DLL targets were built for both architectures. + +Stop further load tests after a full reset. Wait for personal unlock and inspect a +fresh narrow projection before another launch. Temporary profile restoration checks +baseline/current hashes and unchanged shared/other-game settings; it never rolls +back saved game progress. Persistent selection must affect only 202750 and leave +private shader audit layers, validation settings and frametimes HUD disabled. +Routine Heartbeat must not launch games or automatically resume this engineering. + +## Submission scope + +These opt-in runtime tools are submitted directly against official DroidDeck +`main`. The standalone DXVK build recipe, source pin, BC-format prerequisite and +presentation-semaphore patch/check are imported verbatim from the PowerVR proposal +<https://github.com/Droid-Deck/DroidDeck/pull/570> at +`d0f7264ea8e402d30c868779198dc2fd74e7431c`. That proposal's attribution and existing +source/license provenance are retained. The semaphore correction originated in +<https://github.com/wallentx/DroidDeck/pull/3>. No Android app changes, managed pack +or the experimental fork's development history are imported with those recipes. + +The source tools can be reviewed and built independently. Automatic PowerVR +integration and delivery in DroidDeck require the separately reviewed #570 +foundation and a new managed-runtime release. This submission does not change +managed-pack manifests/checksums or globally enable any override. The earlier +fork-only stage <https://github.com/wallentx/DroidDeck/pull/4> is superseded by the +official submission; its review history is preserved. + +For standalone verification, run +`python3 -m unittest discover -s tools/tests -p test_pixel_reset_diagnostics.py` +on the host. On native 64-bit Linux/glibc, +`tools/hybris/low32/build.sh /absolute/output-dir` builds and runs the CPU integrity +and independent mmap/mmap64 preload-chain regressions (both library orders in +off, trace and low32 modes). Optional Vulkan headers produce `gpu-copy-native` +for the selected native host architecture, not a hardcoded ARM64 filename. +`python3 -m unittest discover -s tools/tests -p test_dxvk_build.py` verifies output +isolation with a synthetic toolchain, without fetching or compiling DXVK. +The DXVK component recipe is `tools/dxvk/build.sh /absolute/output-dir`; +it requires the pinned DXVK build prerequisites, including Meson/Ninja, MinGW +cross compilers, glslangValidator and SPIR-V Tools. It retains both architectures, +source/license provenance and downstream patches, without editing an installed +runtime or APK. Its output directory must be new or empty (including hidden +entries). Prior or partially built outputs are refused before fetching sources, +left untouched and never included in a new DLL manifest. Use a fresh directory +after a failed build. +The recipe also requires a native C++17 compiler for +`python3 tools/dxvk/check_d3d9_single_sample.py /path/to/patched-dxvk` before DLL +compilation. Add `--sanitize` on supported hosts to run its ASan/UBSan controls. + +The compositor ownership safeguards are independently proposed in +<https://github.com/Droid-Deck/DroidDeck/pull/561>. Those native changes were present +in the integrated Pixel Lab APK used for the game experiments, but are not part +of this runtime PR's diff. The original BC emulation is a prerequisite supplied by +the separately proposed PowerVR runtime. This submission supplies source and reproducibility tools, +not an APK, proprietary driver, game data or private diagnostic archive. diff --git a/docs/development/gpu-pending-completion.md b/docs/development/gpu-pending-completion.md new file mode 100644 index 0000000000..db036ba21e --- /dev/null +++ b/docs/development/gpu-pending-completion.md @@ -0,0 +1,88 @@ +# Compositor work whose completion is unknown + +A timed-out fence wait does not cancel submitted GPU work. Continuing after +that result can reset a command buffer or fence still in use, or destroy an +image and its memory while the GPU may still read them. Previously the finite +wait paths returned without putting the compositor into a terminal state, and +swapchain teardown ignored the result of `vkDeviceWaitIdle`. + +An unsuccessful completion check other than real `VK_ERROR_DEVICE_LOST` now +puts the compositor in a distinct completion-unknown state. It stops subsequent +presentation and retains potentially pending image/memory and swapchain +resources until the DroidDeck app process exits. Device loss continues through +the existing device-loss path. This is deliberate retention rather than an +automatic recovery; restarting a guest session cannot reset the in-process GPU +state, so the diagnostic asks for an app restart. + +Initialization checks the black-image submit and fence result. An unsuccessful +empty completion-marker submit no longer causes a wait on an unsignalled fence. +Surface-rebuild and effect-map paths stop when teardown cannot establish idle. +Acquire retries also stop: retaining the old swapchain is not permission to +acquire from it again. A later frame-generation acquire that ends in a terminal +state returns before the completion marker, fence wait or any further recording. +Real device loss on present is handled before attempting that marker, too. +Mapped SHM bytes are retained unchanged, including same-size `wl_shm` and +single-pixel commits; keeping only the allocation would still race a GPU read. +Off-screen pass copy/abort and the internal fence wait reject terminal states +without further Vulkan calls. Release fds are still consumed on rejected copies. +The normal frame fence still has its existing infinite timeout; this change is +not a general GPU hang watchdog. + +Externally owned DMA-BUF contents need the same protection. `vkp_completion_unknown()` +exposes the terminal state to compositor-thread lifecycle paths. Replacement, +surface/client destruction, cursor/idle-role releases, previously queued paced +releases and SurfaceFlinger callbacks no longer return a DMA-BUF to its client +after quarantine. The compositor retains DMA-BUF references/backing FDs and AHB +references until app process exit. A display fence alone does not establish that +the compositor's Vulkan reads completed. Queued releases detach destroyed surfaces +and remain held without repeatedly arming an expired timer. New terminal releases +require no allocation, so allocation failure cannot fall back to an unsafe release. +Copied SHM releases and healthy/genuine-device-loss cleanup keep their existing +behaviour. This intentionally prevents further client buffer reuse; restarting +the Android app process, not just the guest session, is required. + +## Regression coverage + +`python3 -m unittest discover -s tools/tests -p test_vk_pending_completion.py -v` +compiles the production wait/destructor and swapchain teardown functions with a +fake Vulkan dispatch table. The two cases cover success, timeout, host-memory +errors, genuine device loss, resource retention and suppressed repeated teardown. +No real GPU fault is injected. The harness matches main's Vulkan-image resources; +it does not assume the experimental PowerVR branch's additional AHB fields. + +`python3 -m unittest discover -s tools/tests -p test_vk_terminal_callers.py -v` +additionally compiles the **entire production `vk_present.c`**, with fake Vulkan +dispatch callbacks and stub external modules. The compositor's `take_shm` and +`take_pixel` callers are inserted verbatim, not rewritten. It needs the Android +NDK's Vulkan-Headers (`ANDROID_HOME`/`ANDROID_SDK_ROOT`/`NDK`), a host Vulkan +development package, or `DROIDDECK_VULKAN_INCLUDE`; absent headers are explicitly +reported as a skip. No Android runtime or GPU is required. + +The 12 scenarios include first/later OUT_OF_DATE and SURFACE_LOST followed by an +idle failure, a finite blit timeout followed by same-size SHM/single-pixel +uploads, normal presentation/frame generation, a healthy later acquire timeout +whose earlier work still needs draining, real acquire/present device loss, and +terminal off-screen pass entry. Every work-issuing fake callback asserts the +device is live. After quarantine, the tests verify retained handles and unchanged +mapped bytes, and probe the public render/blit/readback/import/pass entry points +for suppressed acquire/submit/wait/reset and destruction. Consumed fds are checked. +Against PR #560's `68dc1c45` the same harness compiles, but nine scenarios fail +(the three healthy controls pass); the corrected production unit passes all 12. + +The baseline production fence/destructor compiles but fails the timeout-state +oracle; the corrected functions pass both cases with `-Wall -Wextra -Werror`. +The change was also exercised in an independently integrated Pixel PowerVR Lab, +but its short game observations do not establish the cause of the earlier GNOC +reboot or sustained device stability. Main's native CI and APK build remain +separate validation. + +`python3 -m unittest discover -s tools/tests -p test_vk_dmabuf_quarantine.py -v` +compiles the production compositor/AHB release, reference and listener functions +verbatim, using the real Wayland list layouts/macros with fake IPC/timer/AHB +endpoints. It covers paced replacement, immediate surface cleanup, already queued +releases, a mixed DMA-BUF/SHM queue, client destruction, a display-fence callback, +healthy cleanup and genuine device loss. It checks withheld releases, retained +FDs/references/AHB ownership, removal of surface listeners and disarmed timers. +The same harness can test an old source directory via +`DROIDDECK_DMABUF_TEST_SOURCE`; it does not inject a real driver fault or prove +long-term device stability. diff --git a/docs/development/mali-venus.md b/docs/development/mali-venus.md new file mode 100644 index 0000000000..8a722ff7e0 --- /dev/null +++ b/docs/development/mali-venus.md @@ -0,0 +1,269 @@ +# DroidDeck on Mali (Pixel 9 Pro) through Venus + +Venus implementation notes and historical prototype measurements from a Pixel 9 Pro +(Tensor G4, Mali-G715, Android 17). These October prototype results do not validate +the current DroidDeck integration. + +## Status (2026-10-08, night) + +Prototype 13 is the APK on the phone, a release build (not debuggable). +Prototypes 12 and 13 are published as GitHub prereleases. +Steam Big Picture shows a clean, live picture, and Slay the Spire 2 runs at about 40 fps. + +Direct3D 9-11 games run through DXVK. +Test game: Hollow Knight Silksong (Unity, D3D11), app id 1030300. +- Prototype 12: 35-40 fps in game, stable, with good audio. The phone was not throttling. +- Prototype 13 (cached frame readback, see Performance): 45-52 fps, averaging 47-52. + +Done and verified on the phone: +- The Mali compatibility layer (`tools/venus/layer`) loads and reports the six features DXVK requires. +- DXVK accepts the GPU and creates its device. D3D11 runs at feature level 11_0. +- Silksong loads and plays. +- The APK carries the layer and the Venus ICD; nothing on the phone is installed by hand any more. + +Fixed: a crash in the Venus guest driver, about 20 s after launch, with a black screen until then. +- Where: `vtest_vcmd_submit_cmd2` (`src/virtio/vulkan/vn_renderer_vtest.c`), on the `dxvk-submit` thread inside `vkQueueSubmit2`. +- What: it reads `batch->syncs[1]->sync_id` and `syncs[1]` is the pointer `0x1`. +- Cause: two threads submit to the same queue at once. + - Venus's async present thread (`vn_wsi`) makes the WSI submits. On vtest, `vn_wsi_fence_wait` drops the queue lock while it waits on a fence. + - It assumes one submit per swapchain. But `wsi_queue_submit2_unordered` makes a second, empty submit for DXVK's present fence. + - DXVK's thread passes `vn_wsi_flush` in that window and submits at the same time. + - Both use the per-queue scratch buffer `queue->storage`. The empty submit's `sync_vals[0] = 1` lands on DXVK's `syncs[1]`. + - gamescope and Zink use no present fences, so Steam and Slay the Spire 2 never hit it. +- Fix: `vn_queue_submit` holds a new per-queue `submit_mutex`. Verified with Silksong. + +Other open problems: +- Steam's UI blocks 30 s at a time on `IClientFriends::GetVoiceMicrophoneVolume`. A launch looks stuck on "Launching" even after the game died. +- The render server aborts ("pthread_mutex_lock called on a destroyed mutex") when a context dies after an error. Not fixed. +- The phone runs short of memory: about 1-2 GB free during a session. BC decoding makes textures 4-8x bigger. +- Prototype 13 is not debuggable, so private-storage access through `adb run-as` is unavailable. + - To debug again: add `debuggable true` to the `release` build type in `app/build.gradle`, rebuild, reinstall. Keep it out of commits. + - A debuggable build shows a harmless "not 16 KB-compatible" dialog. + +## Performance + +How a game frame reaches the screen (Silksong, 1280x720): +1. The game draws through Venus. gamescope's WSI layer turns its X11 window into a Wayland surface on gamescope. +2. Venus's present thread (`vn_wsi[0,0]`) runs WSI's software path (`MESA_VK_WSI_DEBUG=sw`). + - It blits the image into a host-visible buffer, waits for the GPU, and `memcpy`s the buffer into a `wl_shm` buffer (3.6 MB). +3. gamescope uploads that `wl_shm` buffer into a texture (patch 0927), composites, and hands a dma-buf to the app. +4. The app's compositor draws it at 60 Hz. Its own work is about 2-3 ms a frame (`wayland.log`, `perf` lines). + +Measured with `tools/venus/measure-present.patch`: + +| Per frame | Prototype 12 | Prototype 13 | +|---|---|---| +| Frame interval | 26-29 ms | ~20 ms | +| `memcpy` out of the readback buffer | 7-10 ms (~400 MB/s) | ~1.3 ms, cache sync included | +| Present thread total | 17-20 ms | ~12 ms | +| GPU fence waits (two per present) | ~4 ms | ~4.5 ms | +| Game blocked in `vn_wsi_flush` | ~0.4 ms | ~0.01 ms | + +Why the copy was slow: Venus hid Mali's cached memory type. +- Mali's native types (`memtypes` probe): 0 = device-local, host-visible, coherent (uncached); 1 = device-local, host-visible, cached (not coherent). +- `vn_physical_device_init_memory_properties` strips host-visible from cached types that are not coherent, and labels type 0 "cached" for app compatibility. +- So WSI's readback buffer landed on uncached memory, and the CPU read it at ~400 MB/s. + +The fix (prototype 13): +- Venus allocates WSI's readback buffer in the hidden cached type (`vn_wsi_memory_type_index`). Apps still never see that type. +- The vtest renderer keeps that buffer's dma-buf fd and implements flush and invalidate as `DMA_BUF_IOCTL_SYNC`. +- WSI calls `vkInvalidateMappedMemoryRanges` before every CPU read of a frame (Wayland and X11 software paths). +- The render server allocates cached memory types from the cached dma-buf heap (`/dev/dma_heap/system`). + +What is left on the present thread (~12 ms): +- ~4.5 ms in two GPU fence waits. WSI makes a second, empty submit for DXVK's present fence, and Venus waits on each. +- ~6 ms in those two submits and their Venus round trips. +- Thread sample (`top -H`, prototype 12): no thread at 100%. Game main thread 48%, `vn_wsi` 30%, `dxvk-frame` 30%, Unity render thread 25%. + - `dxvk-frame` mostly waits for presents; 30% CPU looks like Venus polling in its semaphore waits. + +## Repository entrypoints + +- `tools/venus/ci-build.sh`: guest ICD, compatibility layer and Android server build. +- `tools/venus/release.env`: Venus component pin consumed by APK builds. +- `.github/workflows/build-venus.yml`: Venus component artifact workflow. +- `tools/gamescope/build-in-arch.sh`: patched gamescope build. +- `tools/gamescope/release.env`: gamescope component pin consumed by APK builds. +- `.github/workflows/build.yml`: APK build and regression tests. + +## How it works + +The session's Linux processes (glibc) cannot load Mali's Android (bionic) Vulkan driver. +Venus bridges them: + +1. The guest loads Mesa's Venus ICD (`libvulkan_virtio.so`) with `VN_DEBUG=vtest`. +2. The ICD serializes Vulkan calls over a unix socket: `files/venus/vtest.sock`. +3. virglrenderer's `virgl_test_server --venus --no-virgl` runs on the Android side as an app child process. +4. Per client, it forks `virgl_render_server`, which replays the calls on Mali's system Vulkan driver. + +For Wine games, the Mali compatibility layer sits between DXVK (via winevulkan) and the Venus ICD. + +The app's own compositor uses Mali's system driver directly. + +## Mali compatibility layer (`tools/venus/layer`) + +Why: DXVK 3.1.1 refuses any GPU without six features, and Mali-G715 has none of them. +The list comes from `dxvk/dxvk_device_info.cpp`, `getFeatureList`, compared with `vulkaninfo` through Venus. +Everything else DXVK requires is present: Vulkan 1.4, geometry and tessellation shaders, maxPushConstantsSize 256. + +What it does, per feature: +- `fillModeNonSolid`: LINE and POINT polygon modes draw as FILL. +- `multiViewport`: reports maxViewports 16. Pipelines and `vkCmdSet{Viewport,Scissor}[WithCount]` keep only the first. +- `robustBufferAccess2`: the device gets `robustBufferAccess` (version 1) instead. +- `shaderClipDistance`: emulated per pipeline. + - The last pre-rasterization stage writes the distances to a free varying location. + - The fragment shader reads them and runs `OpKill` when one is negative. + - Only when that stage is the only one using distances and the fragment shader's code is known. + - Otherwise the distances are dropped. Depth-only passes lose clipping too. + - DXVK passes shader code inline (`VkShaderModuleCreateInfo` in the stage), so its pipelines qualify. + - Mali has no `graphicsPipelineLibraryIndependentInterpolationDecoration`, so DXVK compiles whole pipelines and the layer sees both stages. +- `shaderCullDistance`: dropped. +- `textureCompressionBC`: BC1-BC7 images are created as RGBA8, R8, RG8 or RGBA16F. + - Every upload into one is decoded on the CPU with `bcdec` while the copy is recorded. + - The source must be memory the application has mapped; DXVK's staging memory is. + - Decoded texels go through the layer's own staging buffers, recycled when the command buffer is reset. + - Copies from a BC image into a buffer, and between BC and uncompressed images, are skipped with a warning. + +Files: +- `layer.c`: loader plumbing, feature and limit reporting, device creation, the hook table. +- `pipeline.c`: pipelines, shader modules, viewports. +- `spirv.c`: the SPIR-V rewriter for clip and cull distances. +- `bc.c`: BC formats, images and uploads. +- `VkLayer_droiddeck_mali_compat.json`: implicit layer manifest. + +When it is active: +- Only in Wine processes (`WINEPREFIX` set), and only for features the GPU lacks. +- `DROIDDECK_MALI_COMPAT=1` forces it on, `0` off. `DROIDDECK_MALI_COMPAT_DISABLE=1` keeps the loader from loading it. +- Wine's own `explorer.exe` uses Zink, so it gets the layer too. +- It logs one line per device: `droiddeck-mali-compat: emulating …`. + +How it ships: +- `build-apk.sh` copies `layer/` into the APK's `assets/linuxfs/usr/local/…`. +- `SessionFiles.kt` stages both files into the guest at every session start (its `optional` list). + - Guest paths: `usr/local/lib/droiddeck-mali/` and `usr/local/share/vulkan/implicit_layer.d/`. + +Not done yet: +- Unit tests for the SPIR-V rewriter. It is untested beyond DXVK's shaders, and unknown whether Silksong's shaders used clip distances at all. +- Performance: BC decoding on the CPU makes loads slow. A compute-shader decoder would be the next step. + +## Changes on the branch + +App (Kotlin/C): +- `session/VenusComponent.kt` (new): on a non-Adreno GPU, starts the vtest server and stages the ICD to `files/venus/`. + - It sets the guest env: `VK_ICD_FILENAMES`, `VN_DEBUG=vtest`, `VTEST_SOCKET_NAME`, `MESA_VK_WSI_DEBUG=sw`. +- `session/SessionService.kt`: uses the Venus env instead of the Turnip ICD, and adds the component. +- `gpu/TurnipDriver.java`: the compositor uses the system Vulkan driver on non-Adreno. +- `cpp/waylandcomp/src/vk_present.c`: + - Enables only the dma-buf extensions the driver has. + - Logs the driver's full extension list. + - Gives a zero row pitch a packed 64-byte row (gamescope's 1x1 root buffer). +- `gpu/GpuInfo.kt`, `FrontEndActivity.kt`, `core/DeviceReport.kt`: wording, plus a "Venus" line in `device.txt`. +- `session/SessionFiles.kt`: stages the Mali compatibility layer when the APK carries it. +- `tools/linuxfs/preload/venus.c` (new, part of `libblsession`): unsets `LIBGL_KOPPER_DISABLE` when `VN_DEBUG` has `vtest`. + - Steam's `steamwebhelper.sh` sets it unconditionally. + - Without kopper and without DRI3, Zink gets no GL context, and the Steam UI crash-loops. + - Steam restores that script when it verifies its install, so it cannot be edited. + +`tools/venus/mesa-venus-vtest.patch` (Mesa 26.2.4, guest side): +- No `VK_EXT_physical_device_drm` under vtest. gamescope otherwise demanded a primary node. +- Sync-fd export for fences and semaphores under vtest: a CPU wait that returns -1 (already signaled). gamescope requires `VK_KHR_external_semaphore_fd`. +- WSI skips attaching a -1 sync file to a dma-buf. +- `vn_queue_submission_init_syncs` submits only the sync slots it filled. +- Timeline semaphores free all `queue_count + 1` renderer syncs. Upstream freed one too few and leaked a vtest sync each. +- `vn_queue_submit` runs under a per-queue `submit_mutex`. The async present thread raced the app's submits; see Status. +- WSI's CPU readback buffer goes to Mali's hidden cached memory type; see Performance. + - `vn_physical_device`: keeps the renderer's real memory flags, and picks the hidden type under vtest. + - `vn_renderer_vtest.c`: flush and invalidate of incoherent memory are `DMA_BUF_IOCTL_SYNC` on the bo's dma-buf. + - WSI common code: `vkInvalidateMappedMemoryRanges` before every CPU read of a frame. + +`tools/venus/measure-present.patch`: per-frame present timings on stderr, applied on top for `MEASURE=1` builds only. + +`tools/venus/virglrenderer-android.patch` (virglrenderer 1.3.0, host side): +- Mali on Android can import dma-bufs but cannot export any memory. + - Buffers report dma_buf features 0x4 (importable only); opaque fd reports nothing. + - virglrenderer's minigbm fallback does not exist on Android. +- On Android the server allocates the dma-buf itself and imports it. + - Source for coherent types: `/dev/dma_heap/system-uncached`, then `/dev/dma_heap/system`, then an `AHardwareBuffer` fd. + - Uncached because Mali here is not cache-coherent with the CPU, and nobody calls `DMA_BUF_IOCTL_SYNC` on coherent memory. + - The guest maps coherent memory without syncs, and on the cached heap frames tore at cache-line granularity: the streaks. + - Cached types (not coherent) come from `/dev/dma_heap/system`. Whoever maps them syncs through the dma-buf. + - The fd rides the existing udmabuf plumbing. +- Image and buffer queries report "importable dma-buf" as exportable too. gamescope keeps only exportable modifiers. +- Exports of any memory type go through that allocator. +- Logs what the driver reports, and failed allocations. + +`tools/gamescope/patches/0927-shm-buffers-upload-every-commit.patch`: +- Xwayland has no glamor here, so it reuses about three wl_shm buffers with new pixels. +- gamescope cached one texture per buffer, copied at first import. +- The screen cycled through three stale frames: the flicker. Input and audio still worked. +- The patch caches dma-buf textures only, and uploads shm buffers on every commit. +- See `tools/gamescope/PATCHES.md`. +- The session stages gamescope from the APK assets every start, so it needs an APK rebuild. + +## Build + +Run workflows on the branch being tested: + +1. Build the Venus component with `.github/workflows/build-venus.yml`. Its `venus` + artifact contains `venus.tzst` and its SHA256. For a local Linux build with Docker, + the Android NDK, Meson and Ninja, run: + `ANDROID_NDK_HOME=/path/to/ndk WORK="$PWD/venus-work" bash tools/venus/ci-build.sh`. +2. After gamescope patches change, run `.github/workflows/build-gamescope.yml`. + Leave its tag input empty for an artifact-only build. This runs + `tools/gamescope/build-in-arch.sh` in an Arch Linux ARM container and produces + `gamescope.tzst` and its SHA256. +3. Publish component bundles and update their repository, tag and SHA256 pins in + the corresponding `release.env` before building an APK that fetches them. + Building Venus alone does not rebuild gamescope or the APK. +4. Push the branch for `.github/workflows/build.yml` to prepare pinned components, + compile the APK and run Android, Python and native tests. For a configured + local environment, `tools/build_local.sh` fetches the same pinned inputs and + builds the APK. + +Release APKs remain non-debuggable. Private-storage debugging requires a separate +local development build; exported session logs work with standard builds. + +## Device validation + +Install a compatibly signed APK with `adb install -r /path/to/build.apk`. Start a +Steam session with Mali (Venus) selected in Setup. Check the exported session +folder under `/sdcard/Download/DroidDeck/`: + +- `session.log`: gamescope, Steam and game output. +- `venus.log`: vtest and render server output. +- `wayland.log`: compositor frames and windows. +- `events.jsonl`: `frame.first` records the first displayed frame. +- `crash.log`: crash diagnostics when available. + +Use `tools/droiddeckctl` for diagnostics on standard builds. The +`tools/venus/guest-vulkaninfo.sh` helper requires a configured development build. +Stop the session through DroidDeck to collect the final Steam logs. + +Validate Steam UI rendering and a game on real Mali hardware, then check Adreno +regressions. Historical prototype results do not replace testing a new APK. + +## Failure history (prototype → cause → fix) + +1. Official APK installed → Turnip ICD, no GPU → install the prototype. +2. gamescope: "physical device has no primary node" → Mesa: drop `EXT_physical_device_drm` under vtest. +3. gamescope: missing `VK_KHR_external_semaphore_fd` → Mesa: CPU-wait sync-fd export. +4. Hang on loading: server "minigbm_allocation is not enabled" → virgl: relax the export check. Not enough: Mali exports nothing. +5. Same hang → virgl: allocate a dma-buf (dma-heap or AHB) and import it. +6. gamescope assert `modifiers.size() > 0` → virgl: report importable dma-buf as exportable; route exports through the allocator. +7. Updater "zink: could not create swapchain"; Xwayland has no glamor, so no DRI3 → `MESA_VK_WSI_DEBUG=sw`. +8. steamwebhelper restart loop, "failed to acquire a gl context" → `venus.c` preload unsets `LIBGL_KOPPER_DISABLE`. +9. Frames reach the compositor but "0 windows open" and the overlay stays → compositor: fix stride 0 on gamescope's 1x1 root buffer. +10. Sign-in screen shows, with dash streaks across it → virgl: allocate from the uncached dma-heap. +11. Picture looks frozen or flickers between old frames, though clicks play sounds → gamescope patch 0927. +12. Steam sign-in and Slay the Spire 2 at about 40 fps. Silksong: "d3d11: failed to create factory"; DXVK skips the GPU for `fillModeNonSolid` → the Mali compatibility layer. +13. Silksong: D3D11 starts, black screen, then a crash in Venus's `vtest_vcmd_submit_cmd2` → Mesa: serialize queue submits against the async present thread. Silksong plays at 35-40 fps. +14. Silksong held at 35-40 fps; Venus's present thread spent half its time copying frames from uncached memory → cached readback buffer (prototype 13), 47-52 fps. + +## Next steps + +1. Performance, measured first with `MEASURE=1` (see Performance): + - The two GPU fence waits and two submits per present (~10 ms on the present thread). + - The `dxvk-frame` thread at 30% CPU, probably Venus polling in semaphore waits. +2. Silksong: check BC textures look right and loading time is bearable. +3. Test more games on different engines: GameMaker, FNA (Celeste, Stardew Valley), Unity D3D9, Godot. Fix shared gaps in the layer, never per game. +4. Direct3D 12 games use VKD3D-Proton, which has its own requirement list. Check it the same way. +5. Clean up: delete `droiddeck-env` when debugging is done. diff --git a/tools/build_local.sh b/tools/build_local.sh index 93ffd51fd6..041d6b3131 100755 --- a/tools/build_local.sh +++ b/tools/build_local.sh @@ -139,8 +139,15 @@ docker run --rm --platform "${docker_platform}" \ aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -pthread \ -o "$d/libssbs.so" tools/linuxfs/ssbs/ssbs_adapter.c -ldl aarch64-linux-gnu-strip --strip-unneeded "$d/libssbs.so" + mkdir -p "$d/usr/local/lib/droiddeck-xclipse" + aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -Wextra -Wno-unused-parameter -fvisibility=hidden -pthread \ + -o "$d/usr/local/lib/droiddeck-xclipse/libVkLayer_droiddeck_xclipse.so" tools/linuxfs/xclipse-layer/xclipse_layer.c -ldl + aarch64-linux-gnu-strip --strip-unneeded "$d/usr/local/lib/droiddeck-xclipse/libVkLayer_droiddeck_xclipse.so" + install -m644 tools/linuxfs/xclipse-layer/VkLayer_droiddeck_xclipse.json "$d/usr/local/lib/droiddeck-xclipse/" mkdir -p "$d/usr/local/bin" external/MaliBridge/scripts/build-client-linux.sh "$d" aarch64-linux-gnu-gcc + aarch64-linux-gnu-gcc -O2 -Wall -o "$d/usr/local/bin/droiddeck-glprobe" tools/venus/glprobe.c -ldl + aarch64-linux-gnu-strip --strip-unneeded "$d/usr/local/bin/droiddeck-glprobe" aarch64-linux-gnu-gcc -O2 -Wall -Wextra -o "$d/usr/local/bin/droiddeck-clipboard" tools/linuxfs/clipboard/clipboard.c -ldl aarch64-linux-gnu-strip --strip-unneeded "$d/usr/local/bin/droiddeck-clipboard" for script in tools/linuxfs/overlay/usr/local/bin/droiddeck-* tools/linuxfs/overlay/usr/local/bin/steam-compatibility; do @@ -417,6 +424,7 @@ if ! restore_step comet "${comet_key}" "${comet_out}"; then DROIDDECK_BUILD_IMAGE="${image_name}" bash tools/comet/build-local.sh save_step comet "${comet_key}" "${comet_out}" fi +python3 tools/powervr/fetch.py bash tools/packs/build.sh app/build/packs python3 tools/release/runtime_inputs.py record ./gradlew "${gradle_task}" --console=plain -PndkVersion="${ndk_version}" ${gradle_rust_arg} diff --git a/tools/docker_platform.sh b/tools/docker_platform.sh index 4d4744875d..3360c81ec0 100644 --- a/tools/docker_platform.sh +++ b/tools/docker_platform.sh @@ -4,7 +4,7 @@ if [[ -z "${docker_platform}" ]]; then fi case "${docker_platform}" in linux/arm64|linux/arm64/*) docker_platform=linux/arm64 ;; esac if [[ -z "${DROIDDECK_BUILD_IMAGE:-}" ]]; then - DROIDDECK_BUILD_IMAGE=droiddeck-local-cross:24.04-v3 + DROIDDECK_BUILD_IMAGE=droiddeck-local-cross:24.04-v4 [[ "${docker_platform}" == linux/arm64 ]] && DROIDDECK_BUILD_IMAGE+=-arm64 fi export DROIDDECK_DOCKER_PLATFORM=${docker_platform} DROIDDECK_BUILD_IMAGE diff --git a/tools/dxvk/build.sh b/tools/dxvk/build.sh new file mode 100755 index 0000000000..d403aa0506 --- /dev/null +++ b/tools/dxvk/build.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# CI component build; this does not change the APK or an installed Proton depot. +set -euo pipefail +root=$(cd "$(dirname "$0")/../.." && pwd) +. "$root/tools/dxvk/source.env" +mkdir -p "${1:?output directory required}" +out=$(cd "$1" && pwd) +# Refuse to mix a pinned build with prior DLLs or an incomplete previous build. +# Include dotfiles in the check and leave all existing contents untouched. +shopt -s nullglob dotglob +existing=("$out"/*) +if ((${#existing[@]})); then + printf '%s\n' 'output directory must be empty; use a fresh build directory' >&2 + exit 1 +fi +shopt -u nullglob dotglob +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +git init -q "$work/source" +git -C "$work/source" fetch --depth=1 https://github.com/doitsujin/dxvk.git "$DXVK_REVISION" +git -C "$work/source" checkout -q --detach FETCH_HEAD +test "$(git -C "$work/source" rev-parse HEAD)" = "$DXVK_REVISION" +git -C "$work/source" submodule update --init --recursive --depth=1 +for patch in "$root"/tools/dxvk/patches/*.patch; do + git -C "$work/source" apply --check "$patch" + git -C "$work/source" apply "$patch" +done +python3 "$root/tools/dxvk/check_present_sync.py" "$work/source/src/dxvk/dxvk_presenter.cpp" +python3 "$root/tools/dxvk/check_hud_storage_format.py" "$work/source/src/dxvk/hud/shaders/hud_frame_time_eval.comp" +python3 "$root/tools/dxvk/check_d3d9_single_sample.py" "$work/source" +for arch in 32 64; do + meson setup "$work/build$arch" "$work/source" --cross-file "$work/source/build-win$arch.txt" \ + --buildtype release --prefix "$out" --bindir "x$arch" --libdir "x$arch" -Db_ndebug=if-release --strip + meson compile -C "$work/build$arch" -j 4 + meson install -C "$work/build$arch" +done +cp "$work/source/LICENSE" "$out/LICENSE" +printf '%s\n' "$DXVK_REVISION" > "$out/source-commit" +git -C "$work/source" submodule status --recursive > "$out/submodules.txt" +git -C "$work/source" diff > "$out/downstream.patch" +tar --exclude-vcs --zstd -cf "$out/source.tar.zst" -C "$work/source" . +(cd "$out" && find x32 x64 -name '*.dll' -type f -print0 | sort -z | xargs -0 sha256sum > SHA256SUMS) diff --git a/tools/dxvk/check_d3d9_single_sample.py b/tools/dxvk/check_d3d9_single_sample.py new file mode 100644 index 0000000000..8f73a3f3a7 --- /dev/null +++ b/tools/dxvk/check_d3d9_single_sample.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +"""Compile pinned DXVK's actual descriptor paths against a controlled backend. + +This checks CPU control flow, not GPU rendering. No Wine/game/device is started. +""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import re +import subprocess +import sys +import tempfile + +CASES = ('forced_msaa_depth', 'default_msaa_depth', 'forced_nonmaskable', + 'default_nonmaskable', 'forced_already_single', 'forced_no_depth', + 'forced_unsupported', 'forced_invalid_type', 'forced_lockable_msaa', + 'forced_lockable_single', 'forced_allocation_failure', + 'default_allocation_failure', 'forced_recreate', 'ordinary_surface', + 'ordinary_invalid_lockable') + + +def function(text, signature): + start = text.index(signature) + opening = text.index('{', start) + # Ignore braces in comments and strings while preserving source positions. + stripped = re.sub(r'//[^\n]*|/\*.*?\*/|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'', + lambda m: ' ' * len(m.group()), text, flags=re.S) + depth = 0 + for index in range(opening, len(stripped)): + depth += (stripped[index] == '{') - (stripped[index] == '}') + if depth == 0: + return text[start:index + 1] + raise ValueError('Unterminated source function: ' + signature) + + +def production(source): + base = source / 'src/d3d9' + common = (base / 'd3d9_common_texture.cpp').read_text() + header = (base / 'd3d9_common_texture.h').read_text() + swap = (base / 'd3d9_swapchain.cpp').read_text() + device = (base / 'd3d9_device.cpp').read_text() + util = (base / 'd3d9_util.cpp').read_text() + pieces = { + 'decode': function(util, 'HRESULT DecodeMultiSampleType('), + 'normalize': function(common, 'HRESULT D3D9CommonTexture::NormalizeTextureProperties('), + 'backbuffers': function(swap, 'HRESULT D3D9SwapChainEx::CreateBackBuffers('), + 'uses_image': function(header, 'static bool TextureUsesImage('), + } + reset = function(device, 'HRESULT D3D9DeviceEx::ResetSwapChain(') + begin = reset.index('D3D9_COMMON_TEXTURE_DESC desc;', reset.index('if (pPresentationParameters->EnableAutoDepthStencil)')) + end = reset.index('m_autoDepthStencil =', begin) + pieces['auto_depth'] = reset[begin:end].rstrip() + framebuffer = function(device, 'void D3D9DeviceEx::BindFramebuffer(') + begin = framebuffer.index('const bool mismatch =') + end = framebuffer.index(';', framebuffer.index('const bool bindDS =', begin)) + 1 + pieces['depth_binding'] = framebuffer[begin:end] + return pieces + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('source', type=Path, help='Pinned DXVK tree with downstream patches applied') + parser.add_argument('--cxx', default=os.environ.get('CXX', 'c++')) + parser.add_argument('--sanitize', action='store_true', help='Enable ASan/UBSan on the CPU harness') + args = parser.parse_args() + pieces = production(args.source) + harness = (Path(__file__).parent / 'tests/d3d9_single_sample.cpp').read_text() + harness = harness.replace('/* PRODUCTION_USES_IMAGE */', pieces['uses_image']) + with tempfile.TemporaryDirectory(prefix='dxvk-d3d9-') as directory: + out = Path(directory) + (out / 'harness.cpp').write_text(harness) + include = '\n\n'.join(pieces[key] for key in ('decode', 'normalize', 'backbuffers')) + include += '\nHRESULT auto_depth(D3D9DeviceEx* device, D3DPRESENT_PARAMETERS* pPresentationParameters, D3D9_COMMON_TEXTURE_DESC* output) {\n' + include += 'auto* self = device;\n' + pieces['auto_depth'].replace('(this,', '(self,') + include += '\n*output = desc; return D3D_OK;\n}\n' + include += '\nbool depth_binds(const ImageInfo& color, const ImageInfo& dsInfo) {\n' + include += 'auto sampleCount = color.sampleCount; auto renderArea = color.extent;\n' + include += 'const bool noRT0Bound = false, ignoreRT0 = false;\n' + include += pieces['depth_binding'] + '\nreturn bindDS;\n}\n' + (out / 'd3d9_production.inc').write_text(include) + command = [args.cxx, '-std=c++17', '-Wall', '-Wextra', '-Werror', + '-Wno-unused-parameter', str(out / 'harness.cpp'), '-o', str(out / 'check')] + # The original CreateBackBuffers does not use Flags; that known baseline + # warning must not turn a negative control into a compiler-fixture error. + if args.sanitize: + command[1:1] = ['-fsanitize=address,undefined', '-fno-omit-frame-pointer'] + compilation = subprocess.run(command, capture_output=True, text=True) + if compilation.returncode: + raise SystemExit(compilation.stderr) + results = [] + for case in CASES: + process = subprocess.run([str(out / 'check'), case], capture_output=True, + text=True, timeout=10, cwd=out, + env={'ASAN_OPTIONS': 'detect_leaks=' + + ('0' if sys.platform == 'darwin' else '1')}) + results.append({'case': case, 'passed': process.returncode == 0, + 'exit': process.returncode, 'detail': process.stderr.strip()[-800:]}) + result = {'cases': results, 'passed': sum(row['passed'] for row in results), + 'failed': sum(not row['passed'] for row in results), + 'production_sha256': {key: hashlib.sha256(value.encode()).hexdigest() + for key, value in pieces.items()}, + 'backend_and_adapter_mocked': True, 'GPU_test': False, + 'sanitizers': args.sanitize, + 'leak_detection': args.sanitize and sys.platform != 'darwin'} + print(json.dumps(result, indent=2)) + return bool(result['failed']) + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/tools/dxvk/check_hud_storage_format.py b/tools/dxvk/check_hud_storage_format.py new file mode 100644 index 0000000000..f376cad6b0 --- /dev/null +++ b/tools/dxvk/check_hud_storage_format.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +"""Compile the actual HUD shader and verify its binding-3 R8_UINT contract. + +The frame-time HUD binds an R8_UINT texel-buffer view. An Unknown SPIR-V image +format requires STORAGE_WRITE_WITHOUT_FORMAT, which PowerVR does not report +for that buffer format. Static spirv-val alone accepts both declarations; +this check validates the shader against the known host-side binding contract. +""" +import argparse +from pathlib import Path +import shutil +import struct +import subprocess +import tempfile + + +def check(shader): + compiler = shutil.which('glslangValidator') + validator = shutil.which('spirv-val') + if not compiler or not validator: + raise RuntimeError('glslangValidator and spirv-val required') + with tempfile.TemporaryDirectory(prefix='dxvk-hud-contract-') as directory: + output = Path(directory) / 'hud.spv' + for command in ([compiler, '-V', '--target-env', 'vulkan1.3', str(shader), '-o', str(output)], + [validator, '--target-env', 'vulkan1.3', str(output)]): + process = subprocess.run(command, capture_output=True, text=True, timeout=30) + if process.returncode: + raise RuntimeError('HUD shader compilation/SPIR-V validation failed') + raw = output.read_bytes() + if len(raw) < 20 or len(raw) % 4: + raise RuntimeError('Malformed SPIR-V') + words = struct.unpack('<' + str(len(raw) // 4) + 'I', raw) + if words[0] != 0x07230203: + raise RuntimeError('Unexpected SPIR-V magic') + bindings, sets, variables, pointers, images = {}, {}, {}, {}, {} + offset = 5 + while offset < len(words): + size, opcode = words[offset] >> 16, words[offset] & 0xffff + if not size or size > len(words) - offset: + raise RuntimeError('Malformed SPIR-V instruction') + instruction = words[offset:offset + size] + if opcode == 71 and size == 4: # OpDecorate + if instruction[2] == 33: + bindings[instruction[1]] = instruction[3] + elif instruction[2] == 34: + sets[instruction[1]] = instruction[3] + elif opcode == 59 and size >= 4: # OpVariable + variables[instruction[2]] = instruction[1] + elif opcode == 32 and size == 4: # OpTypePointer + pointers[instruction[1]] = instruction[3] + elif opcode == 25 and size >= 9: # OpTypeImage + images[instruction[1]] = (instruction[3], instruction[7], instruction[8]) + offset += size + targets = [images.get(pointers.get(variables.get(identifier))) + for identifier, binding in bindings.items() + if binding == 3 and sets.get(identifier) == 0] + if targets != [(5, 2, 39)]: # DimBuffer, storage image, ImageFormatR8ui + raise RuntimeError('HUD binding 3 must compile to a storage texel buffer with ImageFormatR8ui') + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('shader', type=Path) + args = parser.parse_args() + try: + check(args.shader) + except RuntimeError as error: + parser.exit(1, str(error) + '\n') + print('HUD binding 3: SPIR-V valid, explicit R8ui storage texel-buffer format') + + +if __name__ == '__main__': + main() diff --git a/tools/dxvk/check_present_sync.py b/tools/dxvk/check_present_sync.py new file mode 100644 index 0000000000..ad47a8aded --- /dev/null +++ b/tools/dxvk/check_present_sync.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Replay asynchronous WSI ownership using the pinned presenter's actual selections. + +This checks semaphore selection, not the full Vulkan presenter. Real Vulkan +validation and device testing remain separate gates. Requires a native C++ compiler. +""" +import argparse +import os +from pathlib import Path +import re +import subprocess +import tempfile + + +def selection_code(source): + match = re.search( + r"// Return relevant Vulkan objects for the acquired image\s*" + r"(?P<acquire>.*?)\s*m_presentPending = true;", source, re.S) + wait = re.search(r"info\.pWaitSemaphores\s*=.*?;", source, re.S) + if not match or not wait: + raise ValueError("unsupported pinned presenter layout") + return match["acquire"], wait[0] + + +HARNESS = r''' +#include <array> +#include <cstdint> +#include <cstdio> +#include <vector> +using VkSemaphore = uint64_t; +struct Sync { VkSemaphore acquire, present; }; +struct Info { const VkSemaphore* pWaitSemaphores; }; + +struct Presenter { + std::vector<Sync> m_semaphores; + std::vector<unsigned> m_images = {0, 1, 2, 3}; + unsigned m_frameIndex = 0, m_imageIndex = 0; + bool m_hasSwapchainMaintenance1; + explicit Presenter(bool maintenance): m_hasSwapchainMaintenance1(maintenance) { + for (unsigned i = 0; i < (maintenance ? 4u : 8u); ++i) + m_semaphores.push_back({100 + i, 1 + i}); + } + Sync acquire() { + Sync sync{}; unsigned image; + ACQUIRE_SELECTION + (void)image; + return sync; + } + VkSemaphore present() { + auto& currSync = m_semaphores.at(m_frameIndex); + Info info{}; + PRESENT_SELECTION + return *info.pWaitSemaphores; + } +}; + +int replay(bool maintenance) { + Presenter p(maintenance); + std::array<VkSemaphore, 4> outstandingByImage{}; + std::array<VkSemaphore, 4> outstandingByFence{}; + // Deliberately delay reacquisition of image 2 beyond a full frame-ring cycle. + const std::array<unsigned, 21> imageOrder = { + 2,0,3,0,1,3,0,1,1,2,3,1,0,3,2,2,0,1,3,0,2 + }; + for (unsigned iteration = 0; iteration < 200; ++iteration) { + p.m_imageIndex = imageOrder[iteration % imageOrder.size()]; + if (maintenance) { + // The existing fence path waits this frame's previous present fence. + const auto completed = outstandingByFence.at(p.m_frameIndex); + for (auto& pending : outstandingByImage) + if (pending == completed) pending = 0; + } + // Acquisition and its GPU wait complete the last present of THIS image. + outstandingByImage.at(p.m_imageIndex) = 0; + const auto signal = p.acquire().present; + const auto wait = p.present(); + if (signal != wait) { + std::fprintf(stderr, "FAIL: render signal differs from present wait\n"); + return 2; + } + for (auto pending : outstandingByImage) { + if (pending == signal) { + std::fprintf(stderr, "FAIL: semaphore reused before presentation completion at frame %u\n", iteration); + return 2; + } + } + outstandingByImage.at(p.m_imageIndex) = signal; + if (maintenance) outstandingByFence.at(p.m_frameIndex) = signal; + p.m_frameIndex = (p.m_frameIndex + 1) % p.m_semaphores.size(); + } + std::printf("PASS: %s, 200 out-of-order acquisitions\n", maintenance ? "present-fence path" : "no-present-fence path"); + return 0; +} +int main() { + if (int status = replay(false)) return status; + return replay(true); +} +''' + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("source", type=Path, help="pinned dxvk_presenter.cpp, after patching") + args = parser.parse_args() + acquire, present = selection_code(args.source.read_text()) + code = HARNESS.replace("ACQUIRE_SELECTION", acquire).replace("PRESENT_SELECTION", present) + with tempfile.TemporaryDirectory(prefix="dxvk-present-sync-") as directory: + cpp = Path(directory) / "replay.cpp" + exe = Path(directory) / "replay" + cpp.write_text(code) + subprocess.run([os.environ.get("HOST_CXX", "c++"), "-std=c++17", "-Wall", "-Wextra", str(cpp), "-o", str(exe)], check=True) + return subprocess.run([str(exe)]).returncode + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/dxvk/patches/0001-check-direct3d-bc-formats.patch b/tools/dxvk/patches/0001-check-direct3d-bc-formats.patch new file mode 100644 index 0000000000..db327f0388 --- /dev/null +++ b/tools/dxvk/patches/0001-check-direct3d-bc-formats.patch @@ -0,0 +1,53 @@ +diff --git a/src/dxvk/dxvk_device_info.cpp b/src/dxvk/dxvk_device_info.cpp +index db09fba..8e9a76e 100644 +--- a/src/dxvk/dxvk_device_info.cpp ++++ b/src/dxvk/dxvk_device_info.cpp +@@ -118,6 +118,17 @@ namespace dxvk { + initQueueProperties(instance, adapter, deviceInfo); + initMemoryProperties(instance, adapter); + ++ m_hasBcFormats = true; ++ for (uint32_t value = VK_FORMAT_BC1_RGBA_UNORM_BLOCK; value <= VK_FORMAT_BC7_SRGB_BLOCK; value++) { ++ VkFormatProperties properties = { }; ++ vk->vkGetPhysicalDeviceFormatProperties(adapter, VkFormat(value), &properties); ++ constexpr VkFormatFeatureFlags required = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT ++ | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT ++ | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT; ++ if ((properties.optimalTilingFeatures & required) != required) ++ m_hasBcFormats = false; ++ } ++ + disableUnusedFeatures(instance, safeMode); + + enableFeaturesAndExtensions(); +@@ -785,6 +796,9 @@ namespace dxvk { + } + } + ++ if (!m_hasBcFormats) ++ return std::string("Device does not support the BC formats required by Direct3D"); ++ + if (!m_featuresEnabled.extDescriptorHeap.descriptorHeap && m_properties.core.properties.limits.maxPushConstantsSize < MaxTotalPushDataSize) + return str::format("Device does not support ", MaxTotalPushDataSize, " of push data"); + +@@ -886,7 +900,7 @@ namespace dxvk { + ENABLE_FEATURE(core.features, shaderResourceResidency, false), + ENABLE_FEATURE(core.features, shaderResourceMinLod, false), + ENABLE_FEATURE(core.features, tessellationShader, false), +- ENABLE_FEATURE(core.features, textureCompressionBC, true), ++ ENABLE_FEATURE(core.features, textureCompressionBC, false), + ENABLE_FEATURE(core.features, variableMultisampleRate, false), + ENABLE_FEATURE(core.features, vertexPipelineStoresAndAtomics, false), + ENABLE_FEATURE(core.features, wideLines, false), +diff --git a/src/dxvk/dxvk_device_info.h b/src/dxvk/dxvk_device_info.h +index 0a55f90..8bbc770 100644 +--- a/src/dxvk/dxvk_device_info.h ++++ b/src/dxvk/dxvk_device_info.h +@@ -394,6 +394,7 @@ namespace dxvk { + + DxvkDeviceQueueMapping m_queueMapping = { }; + ++ bool m_hasBcFormats = false; + bool m_hasMeshShader = false; + bool m_hasFmask = false; + diff --git a/tools/dxvk/patches/0002-present-semaphore-per-swapchain-image.patch b/tools/dxvk/patches/0002-present-semaphore-per-swapchain-image.patch new file mode 100644 index 0000000000..bd22bdc52a --- /dev/null +++ b/tools/dxvk/patches/0002-present-semaphore-per-swapchain-image.patch @@ -0,0 +1,26 @@ +diff --git a/src/dxvk/dxvk_presenter.cpp b/src/dxvk/dxvk_presenter.cpp +index 643f7c5..4dc8c4d 100644 +--- a/src/dxvk/dxvk_presenter.cpp ++++ b/src/dxvk/dxvk_presenter.cpp +@@ -161,6 +161,10 @@ namespace dxvk { + + // Return relevant Vulkan objects for the acquired image + sync = m_semaphores.at(m_frameIndex); ++ // Without a present fence, reacquiring this image is the only guarantee ++ // that its previous presentation has consumed the wait semaphore. ++ if (!m_hasSwapchainMaintenance1) ++ sync.present = m_semaphores.at(m_imageIndex).present; + image = m_images.at(m_imageIndex); + + m_presentPending = true; +@@ -239,7 +243,9 @@ namespace dxvk { + + VkPresentInfoKHR info = { VK_STRUCTURE_TYPE_PRESENT_INFO_KHR }; + info.waitSemaphoreCount = 1; +- info.pWaitSemaphores = &currSync.present; ++ info.pWaitSemaphores = m_hasSwapchainMaintenance1 ++ ? &currSync.present ++ : &m_semaphores.at(m_imageIndex).present; + info.swapchainCount = 1; + info.pSwapchains = &m_swapchain; + info.pImageIndices = &m_imageIndex; diff --git a/tools/dxvk/patches/0003-hud-explicit-r8-texel-format.patch b/tools/dxvk/patches/0003-hud-explicit-r8-texel-format.patch new file mode 100644 index 0000000000..85ed529e8d --- /dev/null +++ b/tools/dxvk/patches/0003-hud-explicit-r8-texel-format.patch @@ -0,0 +1,12 @@ +--- a/src/dxvk/hud/shaders/hud_frame_time_eval.comp ++++ b/src/dxvk/hud/shaders/hud_frame_time_eval.comp +@@ -41,7 +41,8 @@ + draw_info_t draw_infos[]; + }; + +-layout(binding = 3) ++// The bound text view is VK_FORMAT_R8_UINT; do not require formatless writes. ++layout(binding = 3, r8ui) + uniform writeonly uimageBuffer text_buffer; + + layout(push_constant) diff --git a/tools/dxvk/patches/0004-d3d9-force-single-sample.patch b/tools/dxvk/patches/0004-d3d9-force-single-sample.patch new file mode 100644 index 0000000000..6ae7343c16 --- /dev/null +++ b/tools/dxvk/patches/0004-d3d9-force-single-sample.patch @@ -0,0 +1,86 @@ +diff --git a/dxvk.conf b/dxvk.conf +index ba4bc20..26d3127 100644 +--- a/dxvk.conf ++++ b/dxvk.conf +@@ -336,6 +336,15 @@ + + # d3d11.disableMsaa = False + ++# Forces D3D9 surfaces to single-sample after validating the original request. ++# The effective surface description reports D3DMULTISAMPLE_NONE; MSAA quality, ++# alpha-to-coverage and per-sample masks are consequently disabled. This is an ++# opt-in compatibility override for games with broken MSAA rendering. ++# ++# Supported values: True, False ++ ++# d3d9.forceSingleSample = False ++ + + # Forces insertion of memory and control barriers after writes to group-shared + # memory in compute shaders. This is only intended to be used as a workaround +diff --git a/src/d3d9/d3d9_common_texture.cpp b/src/d3d9/d3d9_common_texture.cpp +index 9d5fe38..629fea3 100644 +--- a/src/d3d9/d3d9_common_texture.cpp ++++ b/src/d3d9/d3d9_common_texture.cpp +@@ -212,6 +212,15 @@ namespace dxvk { + return D3DERR_INVALIDCALL; + } + ++ // Keep original request validation above. This opt-in override changes ++ // the effective surface description as well as the backing image. ++ // All surface descriptors and resolves then see the actual sample count. ++ if (ResourceType == D3DRTYPE_SURFACE && options->forceSingleSample ++ && sampleCount != VK_SAMPLE_COUNT_1_BIT) { ++ pDesc->MultiSample = D3DMULTISAMPLE_NONE; ++ pDesc->MultisampleQuality = 0; ++ } ++ + // Using MANAGED pool with DYNAMIC usage is illegal + if (IsPoolManaged(pDesc->Pool) && (pDesc->Usage & D3DUSAGE_DYNAMIC)) + return D3DERR_INVALIDCALL; +diff --git a/src/d3d9/d3d9_options.cpp b/src/d3d9/d3d9_options.cpp +index e46864e..0cab7dc 100644 +--- a/src/d3d9/d3d9_options.cpp ++++ b/src/d3d9/d3d9_options.cpp +@@ -59,6 +59,7 @@ namespace dxvk { + this->memoryTrackTest = config.getOption<bool> ("d3d9.memoryTrackTest", false); + this->forceSamplerTypeSpecConstants = config.getOption<bool> ("d3d9.forceSamplerTypeSpecConstants", false); + this->forceSampleRateShading = config.getOption<bool> ("d3d9.forceSampleRateShading", false); ++ this->forceSingleSample = config.getOption<bool> ("d3d9.forceSingleSample", false); + this->forceAspectRatio = config.getOption<std::string> ("d3d9.forceAspectRatio", ""); + this->forceRefreshRate = config.getOption<int32_t> ("d3d9.forceRefreshRate", 0u); + this->modeCountCompatibility = config.getOption<bool> ("d3d9.modeCountCompatibility", false); +diff --git a/src/d3d9/d3d9_options.h b/src/d3d9/d3d9_options.h +index e69a39a..4478420 100644 +--- a/src/d3d9/d3d9_options.h ++++ b/src/d3d9/d3d9_options.h +@@ -113,6 +113,9 @@ namespace dxvk { + /// Forces sample rate shading + bool forceSampleRateShading; + ++ /// Optional compatibility override: report and render surfaces as single-sample. ++ bool forceSingleSample; ++ + /// Allow D3DLOCK_DISCARD + bool allowDiscard; + +diff --git a/src/d3d9/d3d9_swapchain.cpp b/src/d3d9/d3d9_swapchain.cpp +--- a/src/d3d9/d3d9_swapchain.cpp ++++ b/src/d3d9/d3d9_swapchain.cpp +@@ -1055,1 +1055,16 @@ namespace dxvk { ++ if (m_parent->GetOptions()->forceSingleSample) { ++ // Backbuffers bypass the normal surface-creation entry points. Validate ++ // the application's request, then apply the same effective sample count. ++ // IsLockable above is an internal GDI fallback requirement, not the ++ // application's lockability request used by MSAA validation. ++ auto requestedDesc = desc; ++ requestedDesc.IsLockable = (Flags & D3DPRESENTFLAG_LOCKABLE_BACKBUFFER) != 0; ++ HRESULT hr = D3D9CommonTexture::NormalizeTextureProperties( ++ m_parent, D3DRTYPE_SURFACE, &requestedDesc); ++ if (FAILED(hr)) ++ return hr; ++ desc.MultiSample = requestedDesc.MultiSample; ++ desc.MultisampleQuality = requestedDesc.MultisampleQuality; ++ } ++ + const bool isExtended = m_parent->IsD3DCompatibile(D3DCompatibility::D3D9Ex); diff --git a/tools/dxvk/source.env b/tools/dxvk/source.env new file mode 100644 index 0000000000..7aac170c6e --- /dev/null +++ b/tools/dxvk/source.env @@ -0,0 +1 @@ +DXVK_REVISION=25ca63f17f34bdc05a39873ee63907d3cbbfa030 diff --git a/tools/dxvk/tests/d3d9_single_sample.cpp b/tools/dxvk/tests/d3d9_single_sample.cpp new file mode 100644 index 0000000000..2c9782f92e --- /dev/null +++ b/tools/dxvk/tests/d3d9_single_sample.cpp @@ -0,0 +1,214 @@ +// Backend/adapter fixture for the verbatim DXVK functions in d3d9_production.inc. +#include <algorithm> +#include <cassert> +#include <cstdint> +#include <memory> +#include <stdexcept> +#include <string> +#include <vector> + +using HRESULT = int32_t; +using DWORD = uint32_t; +using UINT = uint32_t; +using VkSampleCountFlagBits = uint32_t; +constexpr HRESULT D3D_OK = 0, D3DERR_INVALIDCALL = -1, + D3DERR_NOTAVAILABLE = -2, D3DERR_OUTOFVIDEOMEMORY = -3; +constexpr uint32_t VK_SAMPLE_COUNT_1_BIT = 1, VK_IMAGE_ASPECT_COLOR_BIT = 1; +constexpr bool FALSE = false, TRUE = true; +#define FAILED(x) ((x) < 0) +#define unlikely(x) (x) +enum D3DMULTISAMPLE_TYPE { D3DMULTISAMPLE_NONE, D3DMULTISAMPLE_NONMASKABLE, + D3DMULTISAMPLE_16_SAMPLES = 16 }; +enum D3DRESOURCETYPE { D3DRTYPE_SURFACE, D3DRTYPE_CUBETEXTURE, D3DRTYPE_VOLUMETEXTURE }; +enum D3DPOOL { D3DPOOL_DEFAULT, D3DPOOL_MANAGED, D3DPOOL_SYSTEMMEM, D3DPOOL_SCRATCH }; +enum class D3DCompatibility { D3D9Ex }; +enum class D3D9Format { X8R8G8B8, D24S8, A8, NULL_FORMAT, ATI2, + D32_LOCKABLE, D32F_LOCKABLE, D16_LOCKABLE, S8_LOCKABLE }; +constexpr DWORD D3DUSAGE_RENDERTARGET = 1, D3DUSAGE_DEPTHSTENCIL = 2, + D3DUSAGE_DYNAMIC = 4, D3DUSAGE_WRITEONLY = 8, D3DUSAGE_AUTOGENMIPMAP = 16; +constexpr DWORD D3DPRESENTFLAG_LOCKABLE_BACKBUFFER = 1, D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL = 2; +constexpr int D3DDEVTYPE_HAL = 1, VK_IMAGE_LAYOUT_UNDEFINED = 0; +struct Extent { uint32_t width, height, depth = 1; }; +namespace util { +uint32_t computeMipLevelCount(Extent e) { + uint32_t n = std::max({e.width, e.height, e.depth}), levels = 0; + do { ++levels; n >>= 1; } while (n); + return levels; +} +} +bool IsPoolManaged(D3DPOOL pool) { return pool == D3DPOOL_MANAGED; } +bool IsDXTFormat(D3D9Format) { return false; } +bool IsDepthStencilFormat(D3D9Format format) { return format == D3D9Format::D24S8; } +bool IsLockableDepthStencilFormat(D3D9Format) { return false; } +struct D3D9_FORMAT_BLOCK_SIZE { uint32_t Width, Height; }; +D3D9_FORMAT_BLOCK_SIZE GetFormatAlignedBlockSize(D3D9Format) { return {1, 1}; } +D3D9Format EnumerateFormat(D3D9Format format) { return format; } +struct D3D9_COMMON_TEXTURE_DESC { + uint32_t Width = 1280, Height = 720, Depth = 1, MipLevels = 1, ArraySize = 1; + D3D9Format Format = D3D9Format::X8R8G8B8; + D3DMULTISAMPLE_TYPE MultiSample = D3DMULTISAMPLE_NONE; + DWORD MultisampleQuality = 0; + D3DPOOL Pool = D3DPOOL_DEFAULT; + DWORD Usage = D3DUSAGE_RENDERTARGET; + bool Discard = false, IsBackBuffer = false, IsAttachmentOnly = false, IsLockable = false; +}; +struct D3DPRESENT_PARAMETERS { + uint32_t BackBufferWidth = 1280, BackBufferHeight = 720; + D3D9Format BackBufferFormat = D3D9Format::X8R8G8B8; + D3DMULTISAMPLE_TYPE MultiSampleType = D3DMULTISAMPLE_TYPE(4); + DWORD MultiSampleQuality = 0, Flags = 0; + D3D9Format AutoDepthStencilFormat = D3D9Format::D24S8; +}; +struct Options { + bool forceSingleSample = false, extraFrontbuffer = false, + disableA8RT = false, supportCubeDepthFormats = false; +}; +struct FormatMapping { + uint32_t Aspect; + bool IsValid() const { return true; } +}; +struct Adapter { + bool supported = true; + std::vector<D3DMULTISAMPLE_TYPE> checked; + HRESULT CheckDeviceMultiSampleType(int, D3D9Format, bool, D3DMULTISAMPLE_TYPE samples, void*) { + checked.push_back(samples); + return supported ? D3D_OK : D3DERR_NOTAVAILABLE; + } +}; +struct ImageInfo { Extent extent; VkSampleCountFlagBits sampleCount; }; +struct DxvkImage { ImageInfo info; }; +template<typename T> using Rc = std::shared_ptr<T>; +template<typename T, unsigned N> using small_vector = std::vector<T>; +struct DxvkContext { + unsigned initialized = 0; + void initImage(const Rc<DxvkImage>&, int) { ++initialized; } +}; +struct D3D9DeviceEx { + Options options; + Adapter adapter; + DxvkContext context; + unsigned attempts = 0, failAt = 0, losable = 0, live = 0, injected = 0; + std::vector<D3D9_COMMON_TEXTURE_DESC> created; + Options* GetOptions() { return &options; } + Adapter* GetAdapter() { return &adapter; } + FormatMapping LookupFormat(D3D9Format format) { return {IsDepthStencilFormat(format) ? 2u : 1u}; } + struct Unsupported { unsigned elementSize = 0; }; + Unsupported unsupported; + const Unsupported* UnsupportedFormatInfo(D3D9Format) { return &unsupported; } + bool IsD3DCompatibile(D3DCompatibility) { return false; } + void IncrementLosableCounter() { ++losable; } + template<typename F> void InjectCs(F function) { ++injected; function(&context); } +}; +HRESULT DecodeMultiSampleType(D3DMULTISAMPLE_TYPE, DWORD, VkSampleCountFlagBits*); +struct D3D9CommonTexture { + Rc<DxvkImage> image; + const Rc<DxvkImage>& GetImage() const { return image; } + static HRESULT NormalizeTextureProperties(D3D9DeviceEx*, D3DRESOURCETYPE, D3D9_COMMON_TEXTURE_DESC*); + /* PRODUCTION_USES_IMAGE */ +}; +class DxvkError : public std::runtime_error { +public: + using std::runtime_error::runtime_error; + std::string message() const { return what(); } +}; +struct Logger { static void err(const std::string&) {} }; +struct D3D9SwapChainEx; +struct D3D9Surface { + D3D9CommonTexture texture; + D3D9DeviceEx* device; + D3D9Surface(D3D9DeviceEx* d, D3D9_COMMON_TEXTURE_DESC* desc, bool, D3D9SwapChainEx*, void*) : device(d) { + if (++d->attempts == d->failAt) throw DxvkError("controlled allocation failure"); + VkSampleCountFlagBits samples; + if (FAILED(DecodeMultiSampleType(desc->MultiSample, desc->MultisampleQuality, &samples))) + throw DxvkError("invalid backend sample count"); + texture.image = std::make_shared<DxvkImage>(DxvkImage{{{desc->Width, desc->Height}, samples}}); + d->created.push_back(*desc); ++d->live; + } + ~D3D9Surface() { --device->live; } + D3D9CommonTexture* GetCommonTexture() { return &texture; } +}; +struct D3D9SwapChainEx { + D3D9DeviceEx* m_parent; + D3DPRESENT_PARAMETERS m_presentParams; + std::vector<std::unique_ptr<D3D9Surface>> m_backBuffers; + bool flip = false; + unsigned destroys = 0; + bool SwapWithFrontBuffer() { return flip; } + void DestroyBackBuffers() { ++destroys; m_backBuffers.clear(); } + HRESULT CreateBackBuffers(uint32_t, DWORD); +}; +#include "d3d9_production.inc" + +void paired(bool enabled, D3DMULTISAMPLE_TYPE type, DWORD quality) { + D3D9DeviceEx device; device.options.forceSingleSample = enabled; + device.options.extraFrontbuffer = true; + D3D9SwapChainEx chain{&device, {}, {}}; + chain.m_presentParams.MultiSampleType = type; chain.m_presentParams.MultiSampleQuality = quality; + assert(chain.CreateBackBuffers(2, 0) == D3D_OK); + D3D9_COMMON_TEXTURE_DESC depth; + assert(auto_depth(&device, &chain.m_presentParams, &depth) == D3D_OK); + VkSampleCountFlagBits requested, dsSamples; + assert(DecodeMultiSampleType(type, quality, &requested) == D3D_OK); + assert(DecodeMultiSampleType(depth.MultiSample, depth.MultisampleQuality, &dsSamples) == D3D_OK); + assert(chain.m_backBuffers.size() == 3 && device.context.initialized == 3); + for (const auto& surface : chain.m_backBuffers) { + const auto& image = surface->GetCommonTexture()->GetImage()->info; + assert(image.sampleCount == (enabled ? 1u : requested)); + assert(depth_binds(image, {{depth.Width, depth.Height}, dsSamples})); + } + for (const auto& desc : device.created) { + assert(desc.IsLockable && desc.IsBackBuffer && !desc.IsAttachmentOnly); + assert(desc.MultiSample == (enabled ? D3DMULTISAMPLE_NONE : type)); + assert(desc.MultisampleQuality == (enabled ? 0u : quality)); + } + // Original presentation parameters remain available for reset/auto-depth validation. + assert(chain.m_presentParams.MultiSampleType == type && chain.m_presentParams.MultiSampleQuality == quality); + if (enabled && requested > 1) assert(device.adapter.checked.front() == D3DMULTISAMPLE_TYPE(requested)); +} + +int main(int argc, char** argv) { + assert(argc == 2); std::string name = argv[1]; + if (name == "forced_msaa_depth") paired(true, D3DMULTISAMPLE_TYPE(4), 0); + else if (name == "default_msaa_depth") paired(false, D3DMULTISAMPLE_TYPE(4), 0); + else if (name == "forced_nonmaskable") paired(true, D3DMULTISAMPLE_NONMASKABLE, 2); + else if (name == "default_nonmaskable") paired(false, D3DMULTISAMPLE_NONMASKABLE, 2); + else if (name == "forced_already_single") paired(true, D3DMULTISAMPLE_NONE, 0); + else if (name == "forced_no_depth" || name == "forced_lockable_single") { + D3D9DeviceEx d; d.options.forceSingleSample = true; + D3D9SwapChainEx c{&d, {}, {}}; + if (name == "forced_lockable_single") c.m_presentParams.MultiSampleType = D3DMULTISAMPLE_NONE; + assert(c.CreateBackBuffers(1, name == "forced_lockable_single" ? D3DPRESENTFLAG_LOCKABLE_BACKBUFFER : 0) == D3D_OK); + assert(c.m_backBuffers.size() == 1 && d.created[0].MultiSample == D3DMULTISAMPLE_NONE); + assert(d.created[0].IsLockable && d.context.initialized == 1); + } else if (name == "forced_unsupported" || name == "forced_invalid_type" || name == "forced_lockable_msaa") { + D3D9DeviceEx d; d.options.forceSingleSample = true; + D3D9SwapChainEx c{&d, {}, {}}; + if (name == "forced_unsupported") d.adapter.supported = false; + if (name == "forced_invalid_type") c.m_presentParams.MultiSampleType = D3DMULTISAMPLE_TYPE(17); + HRESULT expected = name == "forced_unsupported" ? D3DERR_NOTAVAILABLE : D3DERR_INVALIDCALL; + assert(c.CreateBackBuffers(2, name == "forced_lockable_msaa" ? D3DPRESENTFLAG_LOCKABLE_BACKBUFFER : 0) == expected); + assert(d.attempts == 0 && d.losable == 0 && d.injected == 0 && c.m_backBuffers.empty()); + } else if (name == "forced_allocation_failure" || name == "default_allocation_failure") { + D3D9DeviceEx d; d.options.forceSingleSample = name == "forced_allocation_failure"; d.failAt = 2; + D3D9SwapChainEx c{&d, {}, {}}; + assert(c.CreateBackBuffers(3, 0) == D3DERR_OUTOFVIDEOMEMORY); + assert(d.attempts == 2 && d.losable == 1 && d.live == 0 && d.injected == 0 && c.m_backBuffers.empty()); + } else if (name == "forced_recreate") { + D3D9DeviceEx d; d.options.forceSingleSample = true; + D3D9SwapChainEx c{&d, {}, {}}; + assert(c.CreateBackBuffers(3, 0) == D3D_OK); + c.m_presentParams.MultiSampleType = D3DMULTISAMPLE_TYPE(8); + assert(c.CreateBackBuffers(1, 0) == D3D_OK); + assert(d.live == 1 && c.m_backBuffers.size() == 1 && c.destroys == 2); + assert(d.adapter.checked.size() == 2 && d.adapter.checked.back() == D3DMULTISAMPLE_TYPE(8)); + assert(c.m_backBuffers[0]->GetCommonTexture()->GetImage()->info.sampleCount == 1); + } else if (name == "ordinary_surface" || name == "ordinary_invalid_lockable") { + D3D9DeviceEx d; d.options.forceSingleSample = true; + D3D9_COMMON_TEXTURE_DESC desc; desc.MultiSample = D3DMULTISAMPLE_TYPE(4); + desc.IsLockable = name == "ordinary_invalid_lockable"; + assert(D3D9CommonTexture::NormalizeTextureProperties(&d, D3DRTYPE_SURFACE, &desc) + == (desc.IsLockable ? D3DERR_INVALIDCALL : D3D_OK)); + if (!desc.IsLockable) assert(desc.MultiSample == D3DMULTISAMPLE_NONE && desc.MultisampleQuality == 0); + } else assert(false); + return 0; +} diff --git a/tools/gamescope/PATCHES.md b/tools/gamescope/PATCHES.md index fc3b1b481e..4736d32320 100644 --- a/tools/gamescope/PATCHES.md +++ b/tools/gamescope/PATCHES.md @@ -64,14 +64,79 @@ library list, before anything is published. refresh output they now wait for it too, for at most `external_overlay_hold_cycles` refreshes (4, so 30 fps at 120 Hz still merges), and are painted on their own after that. +The non-Adreno test branch's own patches are numbered 0920-0935 (0120-0135 until main took +0121-0125), so they apply after DroidDeck's. Applied in either order the tree is the same. + +The system PowerVR driver uses the existing SDL/Wayland swapchain backend. Its additional patches are: + +- `0920-nested-swapchain-capability-fallback.patch`: negotiate the surface's usages, mutable-format + support, image count, alpha and extent; use offscreen composition and GPU copies when required. +- `0921-powervr-single-pixel-rcas.patch`: use the existing single-pixel RCAS shader on PowerVR, + where the quad variant fails compilation. +- `0922-powervr-linear-dmabuf-import.patch`: retain the explicit linear layout when PowerVR + rejects the mutable-format query, and intersect imported-image and FD memory-type masks. +- `0923-powervr-rgba-copy-surface.patch`: require an advertised RGBA SDR copy surface matching + the shader's `rgba8` storage view. The tested workaround leaves other vendors, HDR and direct + composition unchanged; it does not restrict game-facing BGRA formats. +- `0924-sdl-preserve-explicit-refresh.patch` and `0925-sdl-wait-before-present.patch`: preserve + configured refresh across SDL events and finish composition before presenting without a + render-finished semaphore. The build runs the focused capability, format and refresh tests. + Sixteen more of Armada's patches are DRM/lease/HDR-on-KMS work for a native display, which this app's Wayland-hosted gamescope never reaches, or need a newer gamescope than the runtime has. +- `0926-explicit-sync-switch.patch`: `GAMESCOPE_DISABLE_EXPLICIT_SYNC=1` makes the nested + (Wayland and SDL) backends report no explicit sync, so gamescope does not offer + wp_linux_drm_syncobj_manager_v1 and clients use implicit sync. The app sets it on a GPU that is + not an Adreno when the kernel is older than 6.6 (no DRM_IOCTL_SYNCOBJ_EVENTFD: an Exynos 2400e + on 6.1 logged hundreds of "timeline: DRM_IOCTL_SYNCOBJ_EVENTFD failed" and a game hung at a + black screen) or when the render node is Mali's stand-in (/dev/mali0 has no DRM syncobjs). +- `0927-shm-buffers-upload-every-commit.patch` (David Cimo, for Mali through Venus; his `0114`): with + no DRM node, Xwayland has no glamor and commits a few wl_shm buffers over and over with new pixels. + gamescope memoizes one texture per `wlr_buffer`, and a shm buffer's texture is a copy taken at + import, so the screen cycled through the first few frames forever while Steam ran on behind them. + Only dma-buf textures are memoized now; a shm buffer is uploaded on every commit. Adreno never + takes this path, since its Xwayland hands over dma-bufs. Also what XWAYLAND_NO_GLAMOR sessions need. +- `0929-log-failing-compute-pipeline.patch`: when `vkCreateComputePipelines` fails, one extra line + per shader type names the pipeline (shader type, layer count, ycbcr/colorspace masks, fp16) and the + SPIR-V capabilities its shader declares. A Mali-G615 through Venus refused all 119 composite + pipelines with VK_ERROR_INITIALIZATION_FAILED and nothing said which feature it objected to. +- `0930-composite-without-immutable-ycbcr-samplers.patch`: one composite pipeline is compiled at + start-up; when the driver refuses it, the descriptor layout is rebuilt without binding 4's immutable + YCbCr samplers (that binding then takes the slot's ordinary sampler) and the probe tried again, with + both outcomes in the log. `GAMESCOPE_NO_YCBCR_SAMPLERS=1` forces it. A Mali-G615 through Venus + refused every composite shader (blit, blur, RCAS: SPIR-V capabilities Shader, Sampled1D, + ImageQuery, no Float16) while EASU, NIS and the NV12 converter, which share the layout but never + touch binding 4, compiled. +- `0931-memory-type-fallback-keep-probe.patch`: `findMemoryType` asked for DEVICE_LOCAL|HOST_VISIBLE + memory falls back to host-visible memory without DEVICE_LOCAL, and a failure logs the requested + properties, the type bits and every memory type. The Mali bridge models a unified-memory GPU like a + discrete one (host-visible types without DEVICE_LOCAL), so the upload buffer found nothing and the + backend failed. Also: 0930's probe pipeline is kept instead of destroyed, and skipped when + `GAMESCOPE_NO_YCBCR_SAMPLERS=1` (destroying a pipeline the Venus host had refused killed the + render server). +- `0932-name-hung-up-waitable.patch`: "IWaitable hung up. Aborting." now names the waitable's class, + its fd and what the fd is (`/proc/self/fd`), and the Wayland backend's input thread says why the + compositor connection ended (protocol error or errno) first. An S24 FE aborted there after 60/120 Hz + flips and after a resume with nothing else in the log. +- `0933-flippable-image-unexportable-modifiers.patch`: a flippable (dma-buf exported) image whose + modifiers the driver supports but does not report EXPORTABLE uses them anyway, and an image with no + usable modifier fails with a log line instead of asserting in `CVulkanTexture::BInit`. The Mali + bridge forwards the phone driver's answer, which leaves EXPORTABLE out, though it exports dma-bufs. +- `0934-flippable-image-no-backend-modifiers.patch`: when the nested backend offers no modifier at all + for a flippable image's format, `CVulkanTexture::BInit` tries linear and logs it instead of asserting + `!modifiers.empty()`. NieR Replicant ended the session there on a Pixel 9a under Venus. +- `0935-flippable-image-linear-when-driver-rejects-all.patch`: when the driver answers every offered + modifier with `VK_ERROR_FORMAT_NOT_SUPPORTED` and linear was among them, the flippable image tries + linear anyway; if it cannot be made, `BInit` fails as before. An r32p1 Mali-G610 (Vulkan 1.1) behind + the Mali bridge rejected both of the backend's modifiers for AR24, so the session ended at start + (0933's "no usable modifier"); the bridge makes such images without the handle type and exports + them through a dma-heap. -- `0116-release-cursor-shm-buffers.patch` - this app: pointer cursor surfaces have no - X11/xdg window association, so routing their commits through `g_PendingCommits` - retained every old SHM buffer until the surface was destroyed. Ignore cursor-role - commits before taking the buffer lock; X11 cursor images still follow the existing - MouseCursor path. Window commits awaiting association are unchanged. +The shared DroidDeck patch also includes `0116-release-cursor-shm-buffers.patch`: pointer cursor +surfaces have no X11/xdg window association, so routing their commits through `g_PendingCommits` +retained every old SHM buffer until the surface was destroyed. It ignores cursor-role commits before +taking the buffer lock; X11 cursor images still follow the existing MouseCursor path. Window commits +awaiting association are unchanged. The live regression probe is `tools/tests/test_gamescope_cursor_shm.py`. Run it inside an active Gamescope session with access to that process's `/proc` fd diff --git a/tools/gamescope/build-in-arch.sh b/tools/gamescope/build-in-arch.sh index dbf323136f..cf56408bff 100755 --- a/tools/gamescope/build-in-arch.sh +++ b/tools/gamescope/build-in-arch.sh @@ -43,9 +43,12 @@ meson test -C src/build --no-rebuild --print-errorlogs cursor_routing wayland_sc ls -l *.pkg.tar.* " cd "$WORK" +g++ -std=c++17 -Wall -Wextra -Werror -UNDEBUG -I pkg/arch/src/gamescope/src \ + tools/gamescope/tests/nested-swapchain.cpp -o pkg/test-nested-swapchain +pkg/test-nested-swapchain rm -rf out && mkdir -p out/usr/local/bin PKG=$(ls pkg/arch/gamescope-*.pkg.tar.* | grep -v -- '-debug-' | head -1) -tar --use-compress-program=unzstd -xf "$PKG" -C out --strip-components=2 usr/bin/gamescope +tar -xf "$PKG" -C out --strip-components=2 usr/bin/gamescope mv out/gamescope out/usr/local/bin/gamescope chmod 755 out/usr/local/bin/gamescope strip --strip-unneeded out/usr/local/bin/gamescope || true diff --git a/tools/gamescope/patches/0920-nested-swapchain-capability-fallback.patch b/tools/gamescope/patches/0920-nested-swapchain-capability-fallback.patch new file mode 100644 index 0000000000..c26c8f82bb --- /dev/null +++ b/tools/gamescope/patches/0920-nested-swapchain-capability-fallback.patch @@ -0,0 +1,358 @@ +diff --git a/src/nested_swapchain.hpp b/src/nested_swapchain.hpp +new file mode 100644 +index 0000000..06fc987 +--- /dev/null ++++ b/src/nested_swapchain.hpp +@@ -0,0 +1,53 @@ ++#pragma once ++ ++#include <algorithm> ++#include <vulkan/vulkan_core.h> ++ ++namespace gamescope ++{ ++struct NestedSwapchainConfig ++{ ++ bool copy = false; ++ uint32_t imageCount = 0; ++ VkImageUsageFlags usage = 0; ++ VkCompositeAlphaFlagBitsKHR alpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; ++ VkExtent2D extent = {}; ++}; ++ ++inline bool ChooseNestedSwapchainConfig( const VkSurfaceCapabilitiesKHR &caps, ++ bool mutableFormat, uint32_t width, uint32_t height, NestedSwapchainConfig &config ) ++{ ++ constexpr VkImageUsageFlags direct = VK_IMAGE_USAGE_SAMPLED_BIT | ++ VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; ++ config.copy = !mutableFormat || ( caps.supportedUsageFlags & direct ) != direct; ++ config.usage = config.copy ? VkImageUsageFlags{VK_IMAGE_USAGE_TRANSFER_DST_BIT} : direct; ++ if ( ( caps.supportedUsageFlags & config.usage ) != config.usage ) ++ return false; ++ ++ bool foundAlpha = false; ++ for ( auto alpha : { VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR, ++ VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR, VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR } ) ++ { ++ if ( caps.supportedCompositeAlpha & alpha ) ++ { ++ config.alpha = alpha; ++ foundAlpha = true; ++ break; ++ } ++ } ++ if ( !foundAlpha || caps.maxImageExtent.width < caps.minImageExtent.width || ++ caps.maxImageExtent.height < caps.minImageExtent.height ) ++ return false; ++ ++ config.imageCount = caps.minImageCount + ( caps.minImageCount != UINT32_MAX ); ++ if ( caps.maxImageCount ) ++ config.imageCount = std::min( config.imageCount, caps.maxImageCount ); ++ if ( config.imageCount < caps.minImageCount ) ++ return false; ++ config.extent = caps.currentExtent.width == UINT32_MAX ++ ? VkExtent2D{ std::clamp( width, caps.minImageExtent.width, caps.maxImageExtent.width ), ++ std::clamp( height, caps.minImageExtent.height, caps.maxImageExtent.height ) } ++ : caps.currentExtent; ++ return config.extent.width && config.extent.height; ++} ++} +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index ffad695..ffc8e28 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -12,6 +12,7 @@ + #include <deque> + #include <dlfcn.h> + #include "vulkan_include.h" ++#include "nested_swapchain.hpp" + #include "Utils/Algorithm.h" + + #if defined(__linux__) +@@ -450,6 +451,8 @@ bool CVulkanDevice::createDevice() + bool hasDrmProps = vulkan_has_drm_props(); + bool supportsForeignQueue = false; + bool supportsHDRMetadata = false; ++ bool presentIdExtension = false; ++ bool presentWaitExtension = false; + for (const auto& ext : m_supportedExts) { + if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 ) + m_bSupportsModifiers = true; +@@ -457,6 +460,13 @@ bool CVulkanDevice::createDevice() + if ( strcmp(ext.extensionName, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME) == 0 ) + supportsForeignQueue = true; + ++ if ( strcmp(ext.extensionName, VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME) == 0 ) ++ m_bSupportsMutableSwapchain = true; ++ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_ID_EXTENSION_NAME) == 0 ) ++ presentIdExtension = true; ++ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_WAIT_EXTENSION_NAME) == 0 ) ++ presentWaitExtension = true; ++ + if ( strcmp(ext.extensionName, VK_EXT_HDR_METADATA_EXTENSION_NAME) == 0 ) + supportsHDRMetadata = true; + } +@@ -576,10 +586,24 @@ bool CVulkanDevice::createDevice() + if ( GetBackend()->UsesVulkanSwapchain() ) + { + enabledExtensions.push_back( VK_KHR_SWAPCHAIN_EXTENSION_NAME ); +- enabledExtensions.push_back( VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME ); ++ if ( m_bSupportsMutableSwapchain ) ++ enabledExtensions.push_back( VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME ); + +- enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME ); +- enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME ); ++ if ( presentIdExtension && presentWaitExtension ) ++ { ++ VkPhysicalDevicePresentWaitFeaturesKHR wait = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_FEATURES_KHR }; ++ VkPhysicalDevicePresentIdFeaturesKHR id = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, .pNext = &wait }; ++ VkPhysicalDeviceFeatures2 features = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = &id }; ++ vk.GetPhysicalDeviceFeatures2( physDev(), &features ); ++ m_bSupportsPresentWait = id.presentId && wait.presentWait; ++ } ++ if ( m_bSupportsPresentWait ) ++ { ++ enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME ); ++ enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME ); ++ } ++ else ++ vk_log.infof( "Using FIFO acquire pacing; presentation timestamps unavailable" ); + + if ( supportsHDRMetadata ) + enabledExtensions.push_back( VK_EXT_HDR_METADATA_EXTENSION_NAME ); +@@ -654,7 +678,7 @@ bool CVulkanDevice::createDevice() + + VkPhysicalDeviceFeatures2 features2 = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, +- .pNext = &presentIdFeatures, ++ .pNext = m_bSupportsPresentWait ? static_cast<void *>( &presentIdFeatures ) : static_cast<void *>( &features13 ), + .features = { + .shaderInt16 = m_bSupportsFp16, + }, +@@ -2660,7 +2684,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin + return true; + } + +-bool CVulkanTexture::BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format ) ++bool CVulkanTexture::BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format, bool transferOnly ) + { + m_drmFormat = VulkanFormatToDRM( format ); + m_vkImage = image; +@@ -2672,6 +2696,12 @@ bool CVulkanTexture::BInitFromSwapchain( VkImage image, uint32_t width, uint32_t + m_contentWidth = width; + m_contentHeight = height; + m_bOutputImage = true; ++ if ( transferOnly ) ++ { ++ // A copy destination needs no views (and the swapchain need not be mutable). ++ m_bInitialized = true; ++ return true; ++ } + + VkImageViewCreateInfo createInfo = { + .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, +@@ -3094,7 +3124,7 @@ void vulkan_present_to_window( void ) + + VkPresentInfoKHR presentInfo = { + .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, +- .pNext = &presentIdInfo, ++ .pNext = g_device.supportsPresentWait() ? &presentIdInfo : nullptr, + .swapchainCount = 1, + .pSwapchains = &g_output.swapChain, + .pImageIndices = &g_output.nOutImage, +@@ -3102,14 +3132,22 @@ void vulkan_present_to_window( void ) + + if ( g_device.vk.QueuePresentKHR( g_device.queue(), &presentInfo ) == VK_SUCCESS ) + { +- g_currentPresentWaitId = presentId; +- g_currentPresentWaitId.notify_all(); ++ if ( g_device.supportsPresentWait() ) ++ { ++ g_currentPresentWaitId = presentId; ++ g_currentPresentWaitId.notify_all(); ++ } + } + else + vulkan_remake_swapchain(); + + while ( !acquire_next_image() ) + vulkan_remake_swapchain(); ++ if ( !g_device.supportsPresentWait() ) ++ { ++ // Estimated scheduling anchor after FIFO buffer acquisition, not presentation feedback. ++ GetVBlankTimer().MarkVBlank( get_time_in_nanos(), true ); ++ } + } + + gamescope::Rc<CVulkanTexture> vulkan_create_1d_lut(uint32_t size) +@@ -3219,7 +3257,19 @@ extern bool g_bOutputHDREnabled; + + bool vulkan_make_swapchain( VulkanOutput_t *pOutput ) + { +- uint32_t imageCount = pOutput->surfaceCaps.minImageCount + 1; ++ // Re-query on resize as well as initial creation. ++ if ( g_device.vk.GetPhysicalDeviceSurfaceCapabilitiesKHR( g_device.physDev(), pOutput->surface, &pOutput->surfaceCaps ) != VK_SUCCESS ) ++ return false; ++ gamescope::NestedSwapchainConfig config; ++ if ( !gamescope::ChooseNestedSwapchainConfig( pOutput->surfaceCaps, g_device.supportsMutableSwapchain(), g_nOutputWidth, g_nOutputHeight, config ) ) ++ { ++ vk_log.errorf( "Surface supports neither direct composition nor transfer presentation" ); ++ return false; ++ } ++ pOutput->copyToSwapchain = config.copy; ++ g_nOutputWidth = config.extent.width; ++ g_nOutputHeight = config.extent.height; ++ uint32_t imageCount = config.imageCount; + uint32_t formatCount = pOutput->surfaceFormats.size(); + uint32_t surfaceFormat = formatCount; + VkColorSpaceKHR preferredColorSpace = g_bOutputHDREnabled ? VK_COLOR_SPACE_HDR10_ST2084_EXT : VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; +@@ -3254,6 +3304,13 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput ) + } + } + ++ if ( surfaceFormat == formatCount ) ++ { ++ for ( surfaceFormat = 0; surfaceFormat < formatCount; ++surfaceFormat ) ++ if ( pOutput->surfaceFormats[surfaceFormat].format == VK_FORMAT_R8G8B8A8_UNORM && ++ pOutput->surfaceFormats[surfaceFormat].colorSpace == preferredColorSpace ) ++ break; ++ } + if ( surfaceFormat == formatCount ) + return false; + +@@ -3276,8 +3333,8 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput ) + + VkSwapchainCreateInfoKHR createInfo = { + .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, +- .pNext = formats[0] != formats[1] ? &usageListInfo : nullptr, +- .flags = formats[0] != formats[1] ? VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR : (VkSwapchainCreateFlagBitsKHR )0, ++ .pNext = !config.copy && formats[0] != formats[1] ? &usageListInfo : nullptr, ++ .flags = !config.copy && formats[0] != formats[1] ? VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR : (VkSwapchainCreateFlagBitsKHR )0, + .surface = pOutput->surface, + .minImageCount = imageCount, + .imageFormat = eVkFormat, +@@ -3287,10 +3344,10 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput ) + .height = g_nOutputHeight, + }, + .imageArrayLayers = 1, +- .imageUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, ++ .imageUsage = config.usage, + .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE, + .preTransform = pOutput->surfaceCaps.currentTransform, +- .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, ++ .compositeAlpha = config.alpha, + .presentMode = VK_PRESENT_MODE_FIFO_KHR, + .clipped = VK_TRUE, + }; +@@ -3304,12 +3361,30 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput ) + g_device.vk.GetSwapchainImagesKHR( g_device.device(), pOutput->swapChain, &imageCount, swapchainImages.data() ); + + pOutput->outputImages.resize(imageCount); ++ pOutput->presentationImages.clear(); ++ if ( config.copy ) ++ { ++ vk_log.infof( "Nested swapchain: composing offscreen and copying to FIFO presentation images" ); ++ pOutput->presentationImages.resize(imageCount); ++ } + + for ( uint32_t i = 0; i < pOutput->outputImages.size(); i++ ) + { + pOutput->outputImages[i] = new CVulkanTexture(); + +- if ( !pOutput->outputImages[i]->BInitFromSwapchain(swapchainImages[i], g_nOutputWidth, g_nOutputHeight, eVkFormat)) ++ if ( config.copy ) ++ { ++ CVulkanTexture::createFlags flags; ++ flags.bStorage = true; ++ flags.bSampled = true; ++ flags.bTransferSrc = true; ++ if ( !pOutput->outputImages[i]->BInit( g_nOutputWidth, g_nOutputHeight, 1, pOutput->uOutputFormat, flags ) ) ++ return false; ++ pOutput->presentationImages[i] = new CVulkanTexture(); ++ if ( !pOutput->presentationImages[i]->BInitFromSwapchain( swapchainImages[i], g_nOutputWidth, g_nOutputHeight, eVkFormat, true ) ) ++ return false; ++ } ++ else if ( !pOutput->outputImages[i]->BInitFromSwapchain(swapchainImages[i], g_nOutputWidth, g_nOutputHeight, eVkFormat)) + return false; + } + +@@ -3335,6 +3410,10 @@ bool vulkan_remake_swapchain( void ) + g_device.vk.QueueWaitIdle( g_device.queue() ); + + pOutput->outputImages.clear(); ++ pOutput->presentationImages.clear(); ++ if ( pOutput->acquireFence ) ++ g_device.vk.DestroyFence( g_device.device(), pOutput->acquireFence, nullptr ); ++ pOutput->acquireFence = VK_NULL_HANDLE; + + g_device.vk.DestroySwapchainKHR( g_device.device(), pOutput->swapChain, nullptr ); + +@@ -3670,7 +3749,7 @@ bool vulkan_init( VkInstance instance, VkSurfaceKHR surface ) + if (!init_nis_data()) + return false; + +- if ( GetBackend()->UsesVulkanSwapchain() ) ++ if ( GetBackend()->UsesVulkanSwapchain() && g_device.supportsPresentWait() ) + { + std::thread present_wait_thread( present_wait_thread_func ); + present_wait_thread.detach(); +@@ -4579,6 +4658,9 @@ std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamesco + CompositeTimingEnd( cmdBuffer.get(), *oTimingSlot, pszKey, pszKeyPre, pszKeyPost ); + } + ++ if ( !pOutputOverride && g_output.copyToSwapchain ) ++ cmdBuffer->copyImage( compositeImage, g_output.presentationImages[g_output.nOutImage] ); ++ + uint64_t sequence = g_device.submit(std::move(cmdBuffer)); + if ( oTimingSlot ) + g_CompositeTiming.pending.back().ulSeqNo = sequence; +diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp +index fa519db..674a3b4 100644 +--- a/src/rendervulkan.hpp ++++ b/src/rendervulkan.hpp +@@ -162,7 +162,7 @@ public: + }; + + bool BInit( uint32_t width, uint32_t height, uint32_t depth, uint32_t drmFormat, createFlags flags, wlr_dmabuf_attributes *pDMA = nullptr, uint32_t contentWidth = 0, uint32_t contentHeight = 0, CVulkanTexture *pExistingImageToReuseMemory = nullptr, gamescope::OwningRc<gamescope::IBackendFb> pBackendFb = nullptr ); +- bool BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format ); ++ bool BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format, bool transferOnly = false ); + + uint32_t IncRef(); + uint32_t DecRef(); +@@ -586,7 +586,9 @@ struct VulkanOutput_t + + std::shared_ptr<gamescope::BackendBlob> swapchainHDRMetadata; + VkSwapchainKHR swapChain; +- VkFence acquireFence; ++ VkFence acquireFence = VK_NULL_HANDLE; ++ bool copyToSwapchain = false; ++ std::vector<gamescope::OwningRc<CVulkanTexture>> presentationImages; + + uint32_t nOutImage; // swapchain index in nested mode, or ping/pong between two RTs + std::vector<gamescope::OwningRc<CVulkanTexture>> outputImages; +@@ -756,6 +758,7 @@ static inline uint32_t div_roundup(uint32_t x, uint32_t y) + VK_FUNC(CreateDescriptorPool) \ + VK_FUNC(CreateDescriptorSetLayout) \ + VK_FUNC(CreateFence) \ ++ VK_FUNC(DestroyFence) \ + VK_FUNC(CreateGraphicsPipelines) \ + VK_FUNC(CreateImage) \ + VK_FUNC(CreateImageView) \ +@@ -862,6 +865,8 @@ public: + inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;} + inline int drmRenderFd() {return m_drmRendererFd;} + inline bool supportsModifiers() {return m_bSupportsModifiers;} ++ inline bool supportsMutableSwapchain() {return m_bSupportsMutableSwapchain;} ++ inline bool supportsPresentWait() {return m_bSupportsPresentWait;} + inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;} + inline dev_t primaryDevId() {return m_drmPrimaryDevId;} + inline bool supportsFp16() {return m_bSupportsFp16;} +@@ -930,6 +935,8 @@ protected: + uint32_t m_uVendorID = 0; + bool m_bHasDrmPrimaryDevId = false; + bool m_bSupportsModifiers = false; ++ bool m_bSupportsMutableSwapchain = false; ++ bool m_bSupportsPresentWait = false; + bool m_bInitialized = false; + + diff --git a/tools/gamescope/patches/0921-powervr-single-pixel-rcas.patch b/tools/gamescope/patches/0921-powervr-single-pixel-rcas.patch new file mode 100644 index 0000000000..d2b3aafeab --- /dev/null +++ b/tools/gamescope/patches/0921-powervr-single-pixel-rcas.patch @@ -0,0 +1,15 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -996,8 +996,9 @@ + SHADER(BLUR, cs_composite_blur); + SHADER(BLUR_COND, cs_composite_blur_cond); + SHADER(BLUR_FIRST_PASS, cs_gaussian_blur_horizontal); +- // The one pixel layout is only measured on Adreno, every other vendor keeps the quad swizzle. +- if (m_uVendorID == 0x5143) /* Qualcomm */ ++ // PowerVR rejects the quad-swizzled RCAS for 3+ layers with YCbCr mask 2. ++ // The existing one-pixel shader compiles those variants and covers the same 16x16 tile. ++ if (m_uVendorID == 0x5143 || m_uVendorID == 0x1010) /* Qualcomm or Imagination */ + { + SHADER(RCAS, cs_composite_rcas_1px); + } diff --git a/tools/gamescope/patches/0922-powervr-linear-dmabuf-import.patch b/tools/gamescope/patches/0922-powervr-linear-dmabuf-import.patch new file mode 100644 index 0000000000..40a913560c --- /dev/null +++ b/tools/gamescope/patches/0922-powervr-linear-dmabuf-import.patch @@ -0,0 +1,156 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -13,6 +13,7 @@ + #include <dlfcn.h> + #include "vulkan_include.h" + #include "nested_swapchain.hpp" ++#include "dmabuf_import.hpp" + #include "Utils/Algorithm.h" + + #if defined(__linux__) +@@ -2229,8 +2230,27 @@ + return false; + } + +- if ( res == VK_SUCCESS && +- ( externalImageProperties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT ) ) ++ bool importable = res == VK_SUCCESS && ++ ( externalImageProperties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT ); ++ if ( gamescope::RetryPowerVRLinearQuery( g_device.vendorID(), imageInfo.format, ++ pDMA->modifier, pDMA->n_planes, imageInfo.flags, res ) ) ++ { ++ // PowerVR's mutable-format query rejects this linear import even though ++ // explicit-layout imports and UNORM/sRGB GPU sampling work. Query the base ++ // format without changing the image we actually create or its supplied stride. ++ VkImageCreateInfo baseFormat = imageInfo; ++ baseFormat.flags &= ~VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; ++ baseFormat.pNext = nullptr; ++ res = getModifierProps( &baseFormat, pDMA->modifier, &externalImageProperties ); ++ importable = res == VK_SUCCESS && ++ ( externalImageProperties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT ); ++ } ++ if ( !importable && g_device.vendorID() == 0x1010 ) ++ { ++ vk_log.errorf( "PowerVR DMA-BUF modifier is not importable; refusing a different tiling" ); ++ return false; ++ } ++ if ( importable ) + { + modifierInfo = { + .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT, +@@ -2348,6 +2368,22 @@ + + m_format = imageInfo.format; + ++ VkMemoryFdPropertiesKHR fdProperties = { ++ .sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR, ++ }; ++ if ( pDMA ) ++ { ++ if ( !g_device.vk.GetMemoryFdPropertiesKHR ) ++ return false; ++ res = g_device.vk.GetMemoryFdPropertiesKHR( g_device.device(), ++ VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, pDMA->fd[0], &fdProperties ); ++ if ( res != VK_SUCCESS ) ++ { ++ vk_errorf( res, "vkGetMemoryFdPropertiesKHR failed" ); ++ return false; ++ } ++ } ++ + res = g_device.vk.CreateImage(g_device.device(), &imageInfo, nullptr, &m_vkImage); + if (res != VK_SUCCESS) { + vk_errorf( res, "vkCreateImage failed" ); +@@ -2357,10 +2393,22 @@ + VkMemoryRequirements memRequirements; + g_device.vk.GetImageMemoryRequirements(g_device.device(), m_vkImage, &memRequirements); + ++ uint32_t memoryType = pDMA ++ ? gamescope::DmabufMemoryType( g_device.memoryProperties(), memRequirements.memoryTypeBits, ++ fdProperties.memoryTypeBits, properties ) ++ : uint32_t( g_device.findMemoryType( properties, memRequirements.memoryTypeBits ) ); ++ if ( memoryType == UINT32_MAX ) ++ { ++ vk_log.errorf( "No compatible image memory type (image=0x%x, fd=0x%x)", ++ memRequirements.memoryTypeBits, fdProperties.memoryTypeBits ); ++ g_device.vk.DestroyImage( g_device.device(), m_vkImage, nullptr ); ++ m_vkImage = VK_NULL_HANDLE; ++ return false; ++ } + VkMemoryAllocateInfo allocInfo = { + .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .allocationSize = memRequirements.size, +- .memoryTypeIndex = uint32_t(g_device.findMemoryType(properties, memRequirements.memoryTypeBits)), ++ .memoryTypeIndex = memoryType, + }; + + m_size = allocInfo.allocationSize; +@@ -2453,6 +2501,13 @@ + if ( res != VK_SUCCESS ) + { + vk_errorf( res, "vkBindImageMemory failed" ); ++ if ( pDMA ) ++ vk_log.errorf( "DMA-BUF: %ux%u format=%u modifier=0x%" PRIx64 ++ " planes=%d stride=%u offset=%u tiling=%u allocation=%" PRIu64 ++ " memoryType=%u imageBits=0x%x fdBits=0x%x", width, height, imageInfo.format, ++ pDMA->modifier, pDMA->n_planes, pDMA->stride[0], pDMA->offset[0], imageInfo.tiling, ++ uint64_t( allocInfo.allocationSize ), allocInfo.memoryTypeIndex, ++ memRequirements.memoryTypeBits, fdProperties.memoryTypeBits ); + return false; + } + +diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp +--- a/src/rendervulkan.hpp ++++ b/src/rendervulkan.hpp +@@ -791,6 +791,7 @@ + VK_FUNC(GetImageMemoryRequirements) \ + VK_FUNC(GetImageSubresourceLayout) \ + VK_FUNC(GetMemoryFdKHR) \ ++ VK_FUNC(GetMemoryFdPropertiesKHR) \ + VK_FUNC(GetQueryPoolResults) \ + VK_FUNC(GetSemaphoreCounterValue) \ + VK_FUNC(GetSwapchainImagesKHR) \ +@@ -865,6 +866,8 @@ + inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;} + inline int drmRenderFd() {return m_drmRendererFd;} + inline bool supportsModifiers() {return m_bSupportsModifiers;} ++ inline uint32_t vendorID() const {return m_uVendorID;} ++ inline const VkPhysicalDeviceMemoryProperties &memoryProperties() const {return m_memoryProperties;} + inline bool supportsMutableSwapchain() {return m_bSupportsMutableSwapchain;} + inline bool supportsPresentWait() {return m_bSupportsPresentWait;} + inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;} +diff --git a/src/dmabuf_import.hpp b/src/dmabuf_import.hpp +new file mode 100644 +--- /dev/null ++++ b/src/dmabuf_import.hpp +@@ -0,0 +1,29 @@ ++#pragma once ++#include <vulkan/vulkan_core.h> ++ ++namespace gamescope ++{ ++inline bool RetryPowerVRLinearQuery( uint32_t vendor, VkFormat format, uint64_t modifier, ++ uint32_t planes, VkImageCreateFlags flags, VkResult result ) ++{ ++ return vendor == 0x1010 && modifier == 0 && planes == 1 && ++ flags == VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT && result == VK_ERROR_FORMAT_NOT_SUPPORTED && ++ ( format == VK_FORMAT_R8G8B8A8_UNORM || format == VK_FORMAT_B8G8R8A8_UNORM ); ++} ++ ++inline uint32_t DmabufMemoryType( const VkPhysicalDeviceMemoryProperties &memory, ++ uint32_t imageBits, uint32_t fdBits, VkMemoryPropertyFlags preferred ) ++{ ++ uint32_t fallback = UINT32_MAX; ++ const uint32_t compatible = imageBits & fdBits; ++ for ( uint32_t i = 0; i < memory.memoryTypeCount; ++i ) ++ { ++ if ( !( compatible & ( 1u << i ) ) ) continue; ++ if ( fallback == UINT32_MAX ) fallback = i; ++ if ( ( memory.memoryTypes[i].propertyFlags & preferred ) == preferred ) return i; ++ } ++ // Device-local is a preference for an existing imported buffer. CPU mapping ++ // properties are requirements and must never be silently relaxed. ++ return preferred == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ? fallback : UINT32_MAX; ++} ++} diff --git a/tools/gamescope/patches/0923-powervr-rgba-copy-surface.patch b/tools/gamescope/patches/0923-powervr-rgba-copy-surface.patch new file mode 100644 index 0000000000..72344e6bc6 --- /dev/null +++ b/tools/gamescope/patches/0923-powervr-rgba-copy-surface.patch @@ -0,0 +1,61 @@ +diff --git a/src/nested_surface_format.hpp b/src/nested_surface_format.hpp +new file mode 100644 +--- /dev/null ++++ b/src/nested_surface_format.hpp +@@ -0,0 +1,31 @@ ++#pragma once ++ ++#include <vulkan/vulkan_core.h> ++ ++namespace gamescope ++{ ++// The SDR composition shader declares rgba8, which requires an R8G8B8A8_UNORM ++// storage view. Binding a BGRA view is a format mismatch; a same-format copy ++// cannot correct it. Keep the workaround scoped to the PowerVR SDR copy path ++// where the channel reversal was reproduced, not game-facing texture formats. ++// On success, formatCount means the existing selector should choose the format. ++// On failure, no matching RGBA SDR surface was advertised for this scoped path. ++inline bool ChooseNestedSDRCopySurfaceFormat( uint32_t vendorId, bool copy, bool hdr, ++ const VkSurfaceFormatKHR *formats, uint32_t formatCount, uint32_t &surfaceFormat ) ++{ ++ surfaceFormat = formatCount; ++ if ( vendorId != 0x1010 || !copy || hdr ) ++ return true; ++ ++ for ( uint32_t i = 0; i < formatCount; ++i ) ++ { ++ if ( formats[i].format == VK_FORMAT_R8G8B8A8_UNORM && ++ formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR ) ++ { ++ surfaceFormat = i; ++ return true; ++ } ++ } ++ return false; ++} ++} +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -14,6 +14,7 @@ + #include "vulkan_include.h" + #include "nested_swapchain.hpp" + #include "dmabuf_import.hpp" ++#include "nested_surface_format.hpp" + #include "Utils/Algorithm.h" + + #if defined(__linux__) +@@ -3330,6 +3331,13 @@ + uint32_t surfaceFormat = formatCount; + VkColorSpaceKHR preferredColorSpace = g_bOutputHDREnabled ? VK_COLOR_SPACE_HDR10_ST2084_EXT : VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + ++ if ( !gamescope::ChooseNestedSDRCopySurfaceFormat( g_device.vendorID(), config.copy, ++ g_bOutputHDREnabled, pOutput->surfaceFormats.data(), formatCount, surfaceFormat ) ) ++ { ++ vk_log.errorf( "PowerVR copy composition requires an RGBA SDR surface" ); ++ return false; ++ } ++ + if ( surfaceFormat == formatCount ) + { + for ( surfaceFormat = 0; surfaceFormat < formatCount; surfaceFormat++ ) diff --git a/tools/gamescope/patches/0924-sdl-preserve-explicit-refresh.patch b/tools/gamescope/patches/0924-sdl-preserve-explicit-refresh.patch new file mode 100644 index 0000000000..2ec1a18d29 --- /dev/null +++ b/tools/gamescope/patches/0924-sdl-preserve-explicit-refresh.patch @@ -0,0 +1,78 @@ +diff --git a/src/sdl_refresh.hpp b/src/sdl_refresh.hpp +new file mode 100644 +--- /dev/null ++++ b/src/sdl_refresh.hpp +@@ -0,0 +1,22 @@ ++#pragma once ++ ++#include <cstdint> ++ ++namespace gamescope ++{ ++struct SDLRefreshChoice ++{ ++ int32_t refresh = 0; ++ bool configured = false; ++}; ++ ++// SDL reports the desktop mode again when its window is shown, moved or resized. Keep an ++// explicit -r as the rate exposed by nested Gamescope; discover the desktop rate only when the ++// caller did not configure one. ++inline constexpr SDLRefreshChoice ChooseSDLRefresh( int32_t configuredRefresh, int32_t desktopRefresh ) ++{ ++ return configuredRefresh > 0 ++ ? SDLRefreshChoice{ configuredRefresh, true } ++ : SDLRefreshChoice{ desktopRefresh, false }; ++} ++} +diff --git a/src/Backends/SDLBackend.cpp b/src/Backends/SDLBackend.cpp +--- a/src/Backends/SDLBackend.cpp ++++ b/src/Backends/SDLBackend.cpp +@@ -18,14 +18,20 @@ + #include "steamcompmgr.hpp" + #include "Utils/Defer.h" + #include "refresh_rate.h" ++#include "log.hpp" ++#include "sdl_refresh.hpp" + + #include "sdlscancodetable.hpp" + + static int g_nOldNestedRefresh = 0; + static bool g_bWindowFocused = true; ++static int g_nLastLoggedConfiguredRefresh = -1; ++static int g_nLastLoggedDesktopRefresh = -1; ++static int g_nLastLoggedEffectiveRefresh = -1; + + static int g_nOutputWidthPts = 0; + static int g_nOutputHeightPts = 0; ++static LogScope sdl_log( "sdl_backend" ); + + extern bool g_bForceHDR10OutputDebug; + extern bool steamMode; +@@ -846,9 +851,25 @@ namespace gamescope + SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; + + display_index = SDL_GetWindowDisplayIndex( m_Connector.GetSDLWindow() ); + if ( SDL_GetDesktopDisplayMode( display_index, &mode ) == 0 ) + { +- g_nOutputRefresh = ConvertHztomHz( mode.refresh_rate ); ++ const int nDesktopRefresh = ConvertHztomHz( mode.refresh_rate ); ++ const SDLRefreshChoice refresh = ChooseSDLRefresh( g_nOldNestedRefresh, nDesktopRefresh ); ++ g_nOutputRefresh = refresh.refresh; ++ ++ if ( g_nLastLoggedConfiguredRefresh != g_nOldNestedRefresh || ++ g_nLastLoggedDesktopRefresh != nDesktopRefresh || ++ g_nLastLoggedEffectiveRefresh != refresh.refresh ) ++ { ++ sdl_log.infof( "Refresh mode: configured=%.3fHz desktop=%.3fHz effective=%.3fHz source=%s", ++ ConvertmHzToHz( float( g_nOldNestedRefresh ) ), ++ ConvertmHzToHz( float( nDesktopRefresh ) ), ++ ConvertmHzToHz( float( refresh.refresh ) ), ++ refresh.configured ? "configured -r" : "SDL desktop" ); ++ g_nLastLoggedConfiguredRefresh = g_nOldNestedRefresh; ++ g_nLastLoggedDesktopRefresh = nDesktopRefresh; ++ g_nLastLoggedEffectiveRefresh = refresh.refresh; ++ } + } + } + break; diff --git a/tools/gamescope/patches/0925-sdl-wait-before-present.patch b/tools/gamescope/patches/0925-sdl-wait-before-present.patch new file mode 100644 index 0000000000..d8037df9c4 --- /dev/null +++ b/tools/gamescope/patches/0925-sdl-wait-before-present.patch @@ -0,0 +1,23 @@ +diff --git a/src/Backends/SDLBackend.cpp b/src/Backends/SDLBackend.cpp +--- a/src/Backends/SDLBackend.cpp ++++ b/src/Backends/SDLBackend.cpp +@@ -351,14 +351,15 @@ namespace gamescope + std::optional oCompositeResult = vulkan_composite( (FrameInfo_t *)pFrameInfo, nullptr, false ); + if ( !oCompositeResult ) + return -EINVAL; + ++ // Present has no render-finished semaphore, so wait before the native consumer can read ++ // the old contents. This serializes composition and present; a future pipelined path must ++ // signal a binary render-finished semaphore and make vkQueuePresentKHR wait on it. ++ vulkan_wait( *oCompositeResult, true ); ++ + vulkan_present_to_window(); + + // TODO: Hook up PresentationFeedback. +- +- // Wait for the composite result on our side *after* we +- // commit the buffer to the compositor to avoid a bubble. +- vulkan_wait( *oCompositeResult, true ); + + GetVBlankTimer().UpdateWasCompositing( true ); + GetVBlankTimer().UpdateLastDrawTime( get_time_in_nanos() - g_SteamCompMgrVBlankTime.ulWakeupTime ); diff --git a/tools/gamescope/patches/0926-explicit-sync-switch.patch b/tools/gamescope/patches/0926-explicit-sync-switch.patch new file mode 100644 index 0000000000..92d97dead3 --- /dev/null +++ b/tools/gamescope/patches/0926-explicit-sync-switch.patch @@ -0,0 +1,29 @@ +--- a/src/Backends/WaylandBackend.cpp ++++ b/src/Backends/WaylandBackend.cpp +@@ -2309,7 +2309,10 @@ + + bool CWaylandBackend::SupportsExplicitSync() const + { +- return true; ++ // GAMESCOPE_DISABLE_EXPLICIT_SYNC=1: a kernel without DRM_IOCTL_SYNCOBJ_EVENTFD (before ++ // Linux 6.6) cannot signal the timelines, so clients use implicit sync instead. ++ const char *pszDisable = getenv( "GAMESCOPE_DISABLE_EXPLICIT_SYNC" ); ++ return !( pszDisable && *pszDisable == '1' ); + } + + bool CWaylandBackend::IsPaused() const +--- a/src/Backends/SDLBackend.cpp ++++ b/src/Backends/SDLBackend.cpp +@@ -506,8 +506,10 @@ + + bool CSDLBackend::SupportsExplicitSync() const + { +- // We use a Vulkan swapchain, so yes. +- return true; ++ // We use a Vulkan swapchain, so yes - unless the kernel cannot signal the timelines ++ // (no DRM_IOCTL_SYNCOBJ_EVENTFD before Linux 6.6): GAMESCOPE_DISABLE_EXPLICIT_SYNC=1. ++ const char *pszDisable = getenv( "GAMESCOPE_DISABLE_EXPLICIT_SYNC" ); ++ return !( pszDisable && *pszDisable == '1' ); + } + + bool CSDLBackend::IsPaused() const diff --git a/tools/gamescope/patches/0927-shm-buffers-upload-every-commit.patch b/tools/gamescope/patches/0927-shm-buffers-upload-every-commit.patch new file mode 100644 index 0000000000..5f382c15b9 --- /dev/null +++ b/tools/gamescope/patches/0927-shm-buffers-upload-every-commit.patch @@ -0,0 +1,44 @@ +diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp +index 18b799e..b803ee0 100644 +--- a/src/steamcompmgr.cpp ++++ b/src/steamcompmgr.cpp +@@ -1850,16 +1850,23 @@ import_commit ( + commit->fifo = false; + } + +- if ( gamescope::OwningRc<CVulkanTexture> pTexture = s_BufferMemos.LookupVulkanTexture( buf ) ) ++ struct wlr_dmabuf_attributes dmabuf = {0}; ++ const bool bDmabuf = wlr_buffer_get_dmabuf( buf, &dmabuf ); ++ ++ // Only a dma-buf's texture shows the buffer itself. A shm buffer's texture is a copy taken at ++ // import, and Xwayland without glamor commits the same shm buffers again with new pixels. ++ if ( bDmabuf ) + { +- // Going from OwningRc -> Rc now. +- commit->vulkanTex = pTexture; +- return commit; ++ if ( gamescope::OwningRc<CVulkanTexture> pTexture = s_BufferMemos.LookupVulkanTexture( buf ) ) ++ { ++ // Going from OwningRc -> Rc now. ++ commit->vulkanTex = pTexture; ++ return commit; ++ } + } + +- struct wlr_dmabuf_attributes dmabuf = {0}; + gamescope::OwningRc<gamescope::IBackendFb> pBackendFb; +- if ( wlr_buffer_get_dmabuf( buf, &dmabuf ) ) ++ if ( bDmabuf ) + { + pBackendFb = GetBackend()->ImportDmabufToBackend( &dmabuf ); + } +@@ -1873,7 +1880,8 @@ import_commit ( + + commit->vulkanTex = pOwnedTexture; + +- s_BufferMemos.MemoizeBuffer( buf, std::move( pOwnedTexture ) ); ++ if ( bDmabuf ) ++ s_BufferMemos.MemoizeBuffer( buf, std::move( pOwnedTexture ) ); + + return commit; + } diff --git a/tools/gamescope/patches/0928-robustness2-optional.patch b/tools/gamescope/patches/0928-robustness2-optional.patch new file mode 100644 index 0000000000..35e8a7cd55 --- /dev/null +++ b/tools/gamescope/patches/0928-robustness2-optional.patch @@ -0,0 +1,96 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index 41294f7..42b2ec6 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -435,6 +435,9 @@ bool CVulkanDevice::selectPhysDev(VkSurfaceKHR surface) + return true; + } + ++// Stands in for VK_NULL_HANDLE in descriptor slots when the device has no nullDescriptor. ++static gamescope::OwningRc<CVulkanTexture> s_nullDescriptorFallback; ++ + bool CVulkanDevice::createDevice() + { + uint32_t supportedExtensionCount; +@@ -459,6 +462,9 @@ bool CVulkanDevice::createDevice() + if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 ) + m_bSupportsModifiers = true; + ++ if ( strcmp(ext.extensionName, VK_EXT_ROBUSTNESS_2_EXTENSION_NAME) == 0 ) ++ m_bSupportsNullDescriptor = true; ++ + if ( strcmp(ext.extensionName, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME) == 0 ) + supportsForeignQueue = true; + +@@ -622,7 +628,10 @@ bool CVulkanDevice::createDevice() + + enabledExtensions.push_back( VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME ); + +- enabledExtensions.push_back( VK_EXT_ROBUSTNESS_2_EXTENSION_NAME ); ++ if ( m_bSupportsNullDescriptor ) ++ enabledExtensions.push_back( VK_EXT_ROBUSTNESS_2_EXTENSION_NAME ); ++ else ++ vk_log.infof( "no VK_EXT_robustness2: unused descriptor slots use a 1x1 texture" ); + #if 0 + enabledExtensions.push_back( VK_KHR_MAINTENANCE_5_EXTENSION_NAME ); + #endif +@@ -711,9 +720,10 @@ bool CVulkanDevice::createDevice() + + VkPhysicalDeviceRobustness2FeaturesEXT robustness2Features = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT, +- .pNext = std::exchange(features2.pNext, &robustness2Features), + .nullDescriptor = VK_TRUE, + }; ++ if ( m_bSupportsNullDescriptor ) ++ robustness2Features.pNext = std::exchange(features2.pNext, &robustness2Features); + + VkResult res = vk.CreateDevice(physDev(), &deviceCreateInfo, nullptr, &m_device); + if ( res == VK_ERROR_NOT_PERMITTED_KHR && useRealtimeVulkanQueue ) +@@ -1861,6 +1871,15 @@ void CVulkanCmdBuffer::dispatch(uint32_t x, uint32_t y, uint32_t z) + lut3DDescriptor[i].imageView = m_lut3D[i] ? m_lut3D[i]->srgbView() : VK_NULL_HANDLE; + } + ++ if ( !m_device->supportsNullDescriptor() && s_nullDescriptorFallback != nullptr ) ++ { ++ VkImageView fallback = s_nullDescriptorFallback->srgbView(); ++ for (auto &d : imageDescriptors) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback; ++ for (auto &d : ycbcrImageDescriptors) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback; ++ for (auto &d : shaperLutDescriptor) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback; ++ for (auto &d : lut3DDescriptor) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback; ++ } ++ + if (!m_target->isYcbcr()) + { + targetDescriptors[0].imageView = m_target->srgbView(); +@@ -3546,6 +3565,9 @@ static bool vulkan_make_output_images( VulkanOutput_t *pOutput ) + // Oh no. + pOutput->temporaryHackyBlankImage = vulkan_create_debug_blank_texture(); + ++ if ( !g_device.supportsNullDescriptor() && s_nullDescriptorFallback == nullptr ) ++ s_nullDescriptorFallback = vulkan_create_flat_texture( 1, 1, 0, 0, 0, 0 ); ++ + if ( pOutput->uOutputFormatOverlay != VK_FORMAT_UNDEFINED && !kDisablePartialComposition ) + { + uint32_t uPartialDRMFormat = pOutput->uOutputFormatOverlay; +diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp +index 5ffec4a..901e6a6 100644 +--- a/src/rendervulkan.hpp ++++ b/src/rendervulkan.hpp +@@ -866,6 +866,9 @@ public: + inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;} + inline int drmRenderFd() {return m_drmRendererFd;} + inline bool supportsModifiers() {return m_bSupportsModifiers;} ++ // VK_EXT_robustness2's nullDescriptor. A Mali driver through Venus has no robustness2: unused ++ // descriptor slots then point at a 1x1 texture instead of VK_NULL_HANDLE. ++ inline bool supportsNullDescriptor() {return m_bSupportsNullDescriptor;} + inline uint32_t vendorID() const {return m_uVendorID;} + inline const VkPhysicalDeviceMemoryProperties &memoryProperties() const {return m_memoryProperties;} + inline bool supportsMutableSwapchain() {return m_bSupportsMutableSwapchain;} +@@ -938,6 +941,7 @@ protected: + uint32_t m_uVendorID = 0; + bool m_bHasDrmPrimaryDevId = false; + bool m_bSupportsModifiers = false; ++ bool m_bSupportsNullDescriptor = false; + bool m_bSupportsMutableSwapchain = false; + bool m_bSupportsPresentWait = false; + bool m_bInitialized = false; diff --git a/tools/gamescope/patches/0929-log-failing-compute-pipeline.patch b/tools/gamescope/patches/0929-log-failing-compute-pipeline.patch new file mode 100644 index 0000000000..3d5ebc00f3 --- /dev/null +++ b/tools/gamescope/patches/0929-log-failing-compute-pipeline.patch @@ -0,0 +1,55 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index 42b2ec6..103baee 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -994,6 +994,8 @@ bool CVulkanDevice::createPools() + return true; + } + ++static std::string s_shaderCaps[SHADER_TYPE_COUNT]; ++ + bool CVulkanDevice::createShaders() + { + struct ShaderInfo_t +@@ -1040,6 +1042,25 @@ bool CVulkanDevice::createShaders() + .pCode = shaderInfos[i].spirv, + }; + ++ // The SPIR-V capabilities each shader declares, for the log when its pipeline is refused. ++ { ++ const uint32_t *pWords = shaderInfos[i].spirv; ++ size_t nWords = shaderInfos[i].size / sizeof(uint32_t); ++ std::string &sCaps = s_shaderCaps[i]; ++ sCaps.clear(); ++ for ( size_t w = 5; w < nWords; ) ++ { ++ uint32_t uLen = pWords[w] >> 16; ++ if ( !uLen ) ++ break; ++ if ( ( pWords[w] & 0xffffu ) == 17 /* OpCapability */ && w + 1 < nWords ) ++ sCaps += " " + std::to_string( pWords[w + 1] ); ++ else if ( ( pWords[w] & 0xffffu ) == 54 /* OpFunction: past the header */ ) ++ break; ++ w += uLen; ++ } ++ } ++ + VkResult res = vk.CreateShaderModule(device(), &shaderCreateInfo, nullptr, &m_shaderModules[i]); + if ( res != VK_SUCCESS ) + { +@@ -1240,6 +1261,15 @@ VkPipeline CVulkanDevice::compilePipeline(uint32_t layerCount, uint32_t ycbcrMas + VkResult res = vk.CreateComputePipelines(device(), VK_NULL_HANDLE, 1, &computePipelineCreateInfo, nullptr, &result); + if (res != VK_SUCCESS) { + vk_errorf( res, "vkCreateComputePipelines failed" ); ++ // Which pipeline, once per shader type: a vendor driver through Venus may refuse one variant only. ++ static uint32_t s_uLoggedTypes = 0; ++ if ( !( s_uLoggedTypes & ( 1u << ( (uint32_t)type & 31u ) ) ) ) ++ { ++ s_uLoggedTypes |= 1u << ( (uint32_t)type & 31u ); ++ vk_log.errorf( " failing compute pipeline: shader type %u, layers %u, ycbcr mask 0x%x, blur layers %u, colorspace mask 0x%x, output eotf %u, itm %u, fp16 %d, SPIR-V capabilities:%s", ++ (uint32_t)type, layerCount, ycbcrMask, blur_layer_count, colorspace_mask, (uint32_t)output_eotf, (uint32_t)itm_enable, m_bSupportsFp16 ? 1 : 0, ++ (uint32_t)type < SHADER_TYPE_COUNT ? s_shaderCaps[type].c_str() : "" ); ++ } + return VK_NULL_HANDLE; + } + diff --git a/tools/gamescope/patches/0930-composite-without-immutable-ycbcr-samplers.patch b/tools/gamescope/patches/0930-composite-without-immutable-ycbcr-samplers.patch new file mode 100644 index 0000000000..edbf2ad765 --- /dev/null +++ b/tools/gamescope/patches/0930-composite-without-immutable-ycbcr-samplers.patch @@ -0,0 +1,78 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index 103baee..d344a99 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -319,6 +319,33 @@ bool CVulkanDevice::BInit(VkInstance instance, VkSurfaceKHR surface) + return false; + if (!createShaders()) + return false; ++ { ++ // One composite pipeline up front: a driver that refuses it with the immutable YCbCr ++ // samplers gets the layout without them (NV12 textures then sample without conversion). ++ if ( getenv( "GAMESCOPE_NO_YCBCR_SAMPLERS" ) && *getenv( "GAMESCOPE_NO_YCBCR_SAMPLERS" ) == '1' ) ++ { ++ vk_log.infof( "GAMESCOPE_NO_YCBCR_SAMPLERS=1: composite layout without immutable YCbCr samplers" ); ++ vk.DestroyPipelineLayout( device(), m_pipelineLayout, nullptr ); ++ vk.DestroyDescriptorSetLayout( device(), m_descriptorSetLayout, nullptr ); ++ m_bYcbcrImmutableSamplers = false; ++ if ( !createLayouts() ) ++ return false; ++ } ++ VkPipeline probe = compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false ); ++ if ( probe == VK_NULL_HANDLE && m_bYcbcrImmutableSamplers ) ++ { ++ vk_log.errorf( "composite pipeline refused; retrying without immutable YCbCr samplers" ); ++ vk.DestroyPipelineLayout( device(), m_pipelineLayout, nullptr ); ++ vk.DestroyDescriptorSetLayout( device(), m_descriptorSetLayout, nullptr ); ++ m_bYcbcrImmutableSamplers = false; ++ if ( !createLayouts() ) ++ return false; ++ probe = compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false ); ++ vk_log.infof( "composite pipeline without immutable YCbCr samplers: %s", probe ? "accepted" : "STILL refused" ); ++ } ++ if ( probe != VK_NULL_HANDLE ) ++ vk.DestroyPipeline( device(), probe, nullptr ); ++ } + if (!createScratchResources()) + return false; + +@@ -869,7 +896,7 @@ bool CVulkanDevice::createLayouts() + .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .descriptorCount = VKR_SAMPLER_SLOTS, + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, +- .pImmutableSamplers = ycbcrSamplers.data(), ++ .pImmutableSamplers = m_bYcbcrImmutableSamplers ? ycbcrSamplers.data() : nullptr, + }, + VkDescriptorSetLayoutBinding { + .binding = 5, +@@ -1870,6 +1897,8 @@ void CVulkanCmdBuffer::dispatch(uint32_t x, uint32_t y, uint32_t z) + imageDescriptors[i].sampler = m_device->sampler(m_samplerState[i]); + imageDescriptors[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; + ycbcrImageDescriptors[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; ++ if ( !m_device->ycbcrImmutableSamplers() ) ++ ycbcrImageDescriptors[i].sampler = imageDescriptors[i].sampler; + if (m_boundTextures[i] == nullptr) + continue; + +diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp +index 901e6a6..e0ede11 100644 +--- a/src/rendervulkan.hpp ++++ b/src/rendervulkan.hpp +@@ -876,6 +876,7 @@ public: + inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;} + inline dev_t primaryDevId() {return m_drmPrimaryDevId;} + inline bool supportsFp16() {return m_bSupportsFp16;} ++ inline bool ycbcrImmutableSamplers() {return m_bYcbcrImmutableSamplers;} + inline std::vector<VkExtensionProperties>& supportedExtensions() {return m_supportedExts;} + + inline std::pair<void *, uint32_t> uploadBufferData(uint32_t size) +@@ -925,6 +926,9 @@ protected: + VkQueue m_generalQueue = nullptr; + VkSamplerYcbcrConversion m_ycbcrConversion = VK_NULL_HANDLE; + VkSampler m_ycbcrSampler = VK_NULL_HANDLE; ++ // Binding 4 carries immutable YCbCr samplers; off when the driver refuses every composite ++ // pipeline with them (Mali-G615 through Venus: VK_ERROR_INITIALIZATION_FAILED). ++ bool m_bYcbcrImmutableSamplers = true; + VkDescriptorSetLayout m_descriptorSetLayout = VK_NULL_HANDLE; + VkPipelineLayout m_pipelineLayout = VK_NULL_HANDLE; + VkDescriptorPool m_descriptorPool = VK_NULL_HANDLE; diff --git a/tools/gamescope/patches/0931-memory-type-fallback-keep-probe.patch b/tools/gamescope/patches/0931-memory-type-fallback-keep-probe.patch new file mode 100644 index 0000000000..1f99540418 --- /dev/null +++ b/tools/gamescope/patches/0931-memory-type-fallback-keep-probe.patch @@ -0,0 +1,55 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index d344a99..e699c85 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -331,7 +331,10 @@ bool CVulkanDevice::BInit(VkInstance instance, VkSurfaceKHR surface) + if ( !createLayouts() ) + return false; + } +- VkPipeline probe = compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false ); ++ // Forced off: no probe. Through Venus a pipeline the host refused can still come back as a ++ // handle, and destroying it later is a command the render server rejects - it killed the ++ // whole vtest context (Mali-G615: "vkDestroyPipeline resulted in CS error", exit 137). ++ VkPipeline probe = m_bYcbcrImmutableSamplers ? compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false ) : VK_NULL_HANDLE; + if ( probe == VK_NULL_HANDLE && m_bYcbcrImmutableSamplers ) + { + vk_log.errorf( "composite pipeline refused; retrying without immutable YCbCr samplers" ); +@@ -343,8 +346,8 @@ bool CVulkanDevice::BInit(VkInstance instance, VkSurfaceKHR surface) + probe = compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false ); + vk_log.infof( "composite pipeline without immutable YCbCr samplers: %s", probe ? "accepted" : "STILL refused" ); + } +- if ( probe != VK_NULL_HANDLE ) +- vk.DestroyPipeline( device(), probe, nullptr ); ++ // The probe is kept, never destroyed (see above): one pipeline. ++ (void)probe; + } + if (!createScratchResources()) + return false; +@@ -1380,7 +1383,26 @@ int32_t CVulkanDevice::findMemoryType( VkMemoryPropertyFlags properties, uint32_ + + return i; + } +- ++ ++ // A device that lists its host-visible memory without DEVICE_LOCAL (the Mali bridge models a ++ // unified-memory GPU that way, as a discrete one would) still has it all on the GPU: settle for ++ // host-visible memory rather than fail ("findMemoryType failed", then no backend). ++ if ( properties & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT && properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ) ++ { ++ int32_t nFallback = findMemoryType( properties & ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, requiredTypeBits ); ++ static bool s_bLogged = false; ++ if ( !s_bLogged ) ++ { ++ s_bLogged = true; ++ vk_log.infof( "no memory type with properties 0x%x in type bits 0x%x; without DEVICE_LOCAL: %d", properties, requiredTypeBits, nFallback ); ++ } ++ if ( nFallback >= 0 ) ++ return nFallback; ++ } ++ ++ vk_log.errorf( "findMemoryType: no memory type with properties 0x%x in type bits 0x%x (%u types)", properties, requiredTypeBits, m_memoryProperties.memoryTypeCount ); ++ for ( uint32_t i = 0; i < m_memoryProperties.memoryTypeCount; i++ ) ++ vk_log.errorf( " memory type %u: flags 0x%x heap %u", i, m_memoryProperties.memoryTypes[ i ].propertyFlags, m_memoryProperties.memoryTypes[ i ].heapIndex ); + return -1; + } + diff --git a/tools/gamescope/patches/0932-name-hung-up-waitable.patch b/tools/gamescope/patches/0932-name-hung-up-waitable.patch new file mode 100644 index 0000000000..51abe76eb4 --- /dev/null +++ b/tools/gamescope/patches/0932-name-hung-up-waitable.patch @@ -0,0 +1,57 @@ +diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp +index a927f69..2c9bd73 100644 +--- a/src/Backends/WaylandBackend.cpp ++++ b/src/Backends/WaylandBackend.cpp +@@ -2882,7 +2882,22 @@ namespace gamescope + abort(); + } + +- CFunctionWaitable waitable( nFD ); ++ // The compositor's connection: a hang-up says why (the protocol error, if one was posted). ++ class CDisplayWaitable final : public IWaitable ++ { ++ public: ++ CDisplayWaitable( int nFD, wl_display *pDisplay ) : m_nFD{ nFD }, m_pDisplay{ pDisplay } {} ++ int GetFD() final { return m_nFD; } ++ void OnPollHangUp() final ++ { ++ LogDisplayError( "The Wayland compositor closed gamescope's connection (input thread)", m_pDisplay ); ++ IWaitable::OnPollHangUp(); ++ } ++ private: ++ int m_nFD; ++ wl_display *m_pDisplay; ++ }; ++ CDisplayWaitable waitable( nFD, m_pBackend->GetDisplay() ); + m_Waiter.AddWaitable( &waitable ); + + int nRet = 0; +diff --git a/src/waitable.h b/src/waitable.h +index be54d46..b9116fe 100644 +--- a/src/waitable.h ++++ b/src/waitable.h +@@ -9,6 +9,8 @@ + + #include <functional> + #include <mutex> ++#include <typeinfo> ++#include <stdio.h> + + #include "log.hpp" + +@@ -30,7 +32,14 @@ namespace gamescope + virtual void OnPollPri() {} + virtual void OnPollHangUp() + { +- g_WaitableLog.errorf( "IWaitable hung up. Aborting." ); ++ // Which one: its class and what its descriptor is (a socket, a pipe, an eventfd...). ++ int nFD = GetFD(); ++ char szPath[64], szTarget[256] = "?"; ++ snprintf( szPath, sizeof( szPath ), "/proc/self/fd/%d", nFD ); ++ ssize_t nLen = nFD >= 0 ? readlink( szPath, szTarget, sizeof( szTarget ) - 1 ) : -1; ++ if ( nLen >= 0 ) ++ szTarget[nLen] = '\0'; ++ g_WaitableLog.errorf( "IWaitable hung up: %s, fd %d -> %s. Aborting.", typeid( *this ).name(), nFD, szTarget ); + abort(); + } + diff --git a/tools/gamescope/patches/0933-flippable-image-unexportable-modifiers.patch b/tools/gamescope/patches/0933-flippable-image-unexportable-modifiers.patch new file mode 100644 index 0000000000..ab704f0318 --- /dev/null +++ b/tools/gamescope/patches/0933-flippable-image-unexportable-modifiers.patch @@ -0,0 +1,44 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index e699c85..0ddd249 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -2372,6 +2372,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin + } + + std::vector<uint64_t> modifiers = {}; ++ std::vector<uint64_t> unexportable = {}; + // TODO(JoshA): Move this code to backend for making flippable image. + if ( GetBackend()->UsesModifiers() && flags.bFlippable && g_device.supportsModifiers() && !pDMA ) + { +@@ -2410,12 +2411,30 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin + } + + if ( !( externalFormatProps.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT ) ) ++ { ++ vk_log.infof( "flippable image: modifier 0x%" PRIx64 " for DRM format 0x%x supported but not reported exportable (features 0x%x)", ++ modifier, drmFormat, externalFormatProps.externalMemoryProperties.externalMemoryFeatures ); ++ unexportable.push_back( modifier ); + continue; ++ } + + modifiers.push_back( modifier ); + } + +- assert( modifiers.size() > 0 ); ++ // A driver that supports the modifier but leaves EXPORTABLE out (the Mali bridge forwards the ++ // phone's own driver's answer) can still export the memory as a dma-buf: the bridge's ++ // swapchains do exactly that. Try those rather than assert (rendervulkan.cpp, CVulkanTexture::BInit). ++ if ( modifiers.empty() && !unexportable.empty() ) ++ { ++ vk_log.errorf( "flippable image: no modifier reported exportable for DRM format 0x%x; trying %zu supported one(s) anyway", ++ drmFormat, unexportable.size() ); ++ modifiers = unexportable; ++ } ++ if ( modifiers.empty() ) ++ { ++ vk_log.errorf( "flippable image: no usable modifier for DRM format 0x%x (%zu offered by the backend)", drmFormat, numPossibleModifiers ); ++ return false; ++ } + + modifierListInfo = { + .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT, diff --git a/tools/gamescope/patches/0934-flippable-image-no-backend-modifiers.patch b/tools/gamescope/patches/0934-flippable-image-no-backend-modifiers.patch new file mode 100644 index 0000000000..cd22f44847 --- /dev/null +++ b/tools/gamescope/patches/0934-flippable-image-no-backend-modifiers.patch @@ -0,0 +1,26 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -2235,9 +2235,19 @@ + else + { + std::span<const uint64_t> modifiers = GetBackend()->GetSupportedModifiers( drmFormat ); +- assert( !modifiers.empty() ); +- possibleModifiers = modifiers.data(); +- numPossibleModifiers = modifiers.size(); ++ if ( modifiers.empty() ) ++ { ++ // The nested backend offered no modifier for this format (a game's buffer on Venus, ++ // NieR Replicant on a Pixel 9a): linear instead of the assert that ended the session. ++ vk_log.errorf( "flippable image: the backend offers no modifier for DRM format 0x%x; trying linear", drmFormat ); ++ possibleModifiers = &linear; ++ numPossibleModifiers = 1; ++ } ++ else ++ { ++ possibleModifiers = modifiers.data(); ++ numPossibleModifiers = modifiers.size(); ++ } + } + + for ( size_t i = 0; i < numPossibleModifiers; i++ ) diff --git a/tools/gamescope/patches/0935-flippable-image-linear-when-driver-rejects-all.patch b/tools/gamescope/patches/0935-flippable-image-linear-when-driver-rejects-all.patch new file mode 100644 index 0000000000..dd26e94d32 --- /dev/null +++ b/tools/gamescope/patches/0935-flippable-image-linear-when-driver-rejects-all.patch @@ -0,0 +1,38 @@ +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -2373,6 +2373,7 @@ + + std::vector<uint64_t> modifiers = {}; + std::vector<uint64_t> unexportable = {}; ++ bool linearRejected = false; + // TODO(JoshA): Move this code to backend for making flippable image. + if ( GetBackend()->UsesModifiers() && flags.bFlippable && g_device.supportsModifiers() && !pDMA ) + { +@@ -2414,7 +2415,10 @@ + }; + res = getModifierProps( &imageInfo, modifier, &externalFormatProps ); + if ( res == VK_ERROR_FORMAT_NOT_SUPPORTED ) ++ { ++ linearRejected |= modifier == DRM_FORMAT_MOD_LINEAR; + continue; ++ } + else if ( res != VK_SUCCESS ) { + vk_errorf( res, "getModifierProps failed" ); + return false; +@@ -2440,6 +2444,16 @@ + drmFormat, unexportable.size() ); + modifiers = unexportable; + } ++ // An r32p1 Mali driver (G610, Vulkan 1.1) behind the Mali bridge answers every modifier query ++ // with VK_ERROR_FORMAT_NOT_SUPPORTED, yet the bridge makes such an image without the handle type ++ // and exports it through a dma-heap. Linear, when the backend offered it, is tried rather than ++ // giving up; if the image cannot be made, BInit fails as before (Xiaomi 13T, AR24). ++ if ( modifiers.empty() && linearRejected ) ++ { ++ vk_log.errorf( "flippable image: the driver supports none of the %zu modifier(s) offered for DRM format 0x%x; trying linear anyway", ++ numPossibleModifiers, drmFormat ); ++ modifiers.push_back( DRM_FORMAT_MOD_LINEAR ); ++ } + if ( modifiers.empty() ) + { + vk_log.errorf( "flippable image: no usable modifier for DRM format 0x%x (%zu offered by the backend)", drmFormat, numPossibleModifiers ); diff --git a/tools/gamescope/release.env b/tools/gamescope/release.env index a5633d960d..a8b4653dc0 100644 --- a/tools/gamescope/release.env +++ b/tools/gamescope/release.env @@ -1,3 +1,3 @@ -GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components -GAMESCOPE_TAG=gamescope-3.16.29-p21 -GAMESCOPE_SHA256=c34d2728eb31a5ded35e5cb874e68dd4932a7fba4bcce5f99edf654108f97018 +GAMESCOPE_REPO=Droid-Deck/DroidDeck +GAMESCOPE_TAG=gamescope-3.16.29-pr2029-22b50d182 +GAMESCOPE_SHA256=d6bf0fe2ebb98e1fc7c9a09fccce7d7916c9cc6a10016018040cda01a940b781 diff --git a/tools/gamescope/tests/nested-swapchain.cpp b/tools/gamescope/tests/nested-swapchain.cpp new file mode 100644 index 0000000000..a2054aa746 --- /dev/null +++ b/tools/gamescope/tests/nested-swapchain.cpp @@ -0,0 +1,156 @@ +#include "nested_swapchain.hpp" +#include "nested_surface_format.hpp" +#include "dmabuf_import.hpp" +#include "sdl_refresh.hpp" +#include <cassert> +#include <cstdio> + +int main() +{ + using gamescope::ChooseSDLRefresh; + constexpr int configured60 = 60'000; + constexpr int desktop120 = 120'000; + auto capped = ChooseSDLRefresh(configured60, desktop120); + assert(capped.configured && capped.refresh == configured60); + + auto discovered = ChooseSDLRefresh(0, desktop120); + assert(!discovered.configured && discovered.refresh == desktop120); + + auto configured120 = ChooseSDLRefresh(120'000, 60'000); + assert(configured120.configured && configured120.refresh == 120'000); + + VkSurfaceCapabilitiesKHR caps = {}; + caps.minImageCount = 2; + caps.maxImageCount = 3; + caps.currentExtent = {UINT32_MAX, UINT32_MAX}; + caps.minImageExtent = {16, 16}; + caps.maxImageExtent = {4096, 4096}; + caps.supportedCompositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + caps.supportedUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + gamescope::NestedSwapchainConfig config; + + // Existing desktop drivers retain direct composition into mutable swapchains. + assert(gamescope::ChooseNestedSwapchainConfig(caps, true, 1280, 720, config)); + assert(!config.copy && config.imageCount == 3 && config.extent.width == 1280); + + // No mutable formats: compose offscreen and request only a copy destination. + assert(gamescope::ChooseNestedSwapchainConfig(caps, false, 1280, 720, config)); + assert(config.copy && config.usage == VK_IMAGE_USAGE_TRANSFER_DST_BIT); + + // The Android bridge exposes transfer usage and inherited alpha, but no storage. + caps.supportedUsageFlags &= ~VK_IMAGE_USAGE_STORAGE_BIT; + caps.supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR; + caps.maxImageCount = 2; + caps.currentExtent = {1602, 720}; + assert(gamescope::ChooseNestedSwapchainConfig(caps, true, 1920, 1080, config)); + assert(config.copy && config.alpha == VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR); + assert(config.imageCount == 2 && config.extent.width == 1602); + + // Fail rather than submitting unsupported image usage or alpha. + caps.supportedUsageFlags &= ~VK_IMAGE_USAGE_TRANSFER_DST_BIT; + assert(!gamescope::ChooseNestedSwapchainConfig(caps, true, 1280, 720, config)); + caps.supportedUsageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; + caps.supportedCompositeAlpha = 0; + assert(!gamescope::ChooseNestedSwapchainConfig(caps, false, 1280, 720, config)); + caps.supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR; + + caps.currentExtent = {0, 0}; + assert(!gamescope::ChooseNestedSwapchainConfig(caps, false, 1280, 720, config)); + caps.currentExtent = {UINT32_MAX, UINT32_MAX}; + assert(gamescope::ChooseNestedSwapchainConfig(caps, false, 1, 9000, config)); + assert(config.extent.width == 16 && config.extent.height == 4096); + caps.maxImageCount = 1; + assert(!gamescope::ChooseNestedSwapchainConfig(caps, false, 1280, 720, config)); + + using gamescope::ChooseNestedSDRCopySurfaceFormat; + const VkSurfaceFormatKHR rgba = { + VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}; + const VkSurfaceFormatKHR bgra = { + VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}; + uint32_t surfaceFormat = UINT32_MAX; + + // PowerVR SDR copy output needs the RGBA view matching the rgba8 shader. + const VkSurfaceFormatKHR bgraFirst[] = {bgra, rgba, rgba}; + assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, false, + bgraFirst, 3, surfaceFormat)); + assert(surfaceFormat == 1); + const VkSurfaceFormatKHR rgbaFirst[] = {rgba, bgra}; + assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, false, + rgbaFirst, 2, surfaceFormat)); + assert(surfaceFormat == 0); + assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, false, + &rgba, 1, surfaceFormat)); + assert(surfaceFormat == 0); + + // Reusing a successful index must not hide a missing compatible format. + assert(!ChooseNestedSDRCopySurfaceFormat(0x1010, true, false, + &bgra, 1, surfaceFormat)); + assert(surfaceFormat == 1); + const VkSurfaceFormatKHR wrongColorSpace = { + VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT}; + assert(!ChooseNestedSDRCopySurfaceFormat(0x1010, true, false, + &wrongColorSpace, 1, surfaceFormat)); + assert(surfaceFormat == 1); + const VkSurfaceFormatKHR srgbFormat = { + VK_FORMAT_R8G8B8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}; + assert(!ChooseNestedSDRCopySurfaceFormat(0x1010, true, false, + &srgbFormat, 1, surfaceFormat)); + assert(surfaceFormat == 1); + const VkSurfaceFormatKHR compatibleLast[] = {wrongColorSpace, srgbFormat, rgba}; + assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, false, + compatibleLast, 3, surfaceFormat)); + assert(surfaceFormat == 2); + assert(!ChooseNestedSDRCopySurfaceFormat(0x1010, true, false, + nullptr, 0, surfaceFormat)); + assert(surfaceFormat == 0); + + // The existing selector still owns HDR, direct output, and other vendors. + // Each call clears a stale index even when BGRA is the only advertised format. + surfaceFormat = 0; + assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, true, + &bgra, 1, surfaceFormat)); + assert(surfaceFormat == 1); + surfaceFormat = 0; + assert(ChooseNestedSDRCopySurfaceFormat(0x1010, false, false, + &bgra, 1, surfaceFormat)); + assert(surfaceFormat == 1); + surfaceFormat = 0; + assert(ChooseNestedSDRCopySurfaceFormat(0x5143, true, false, + &bgra, 1, surfaceFormat)); + assert(surfaceFormat == 1); + + // Retry only the device/format/layout/flag combination reproduced on PowerVR. + using gamescope::RetryPowerVRLinearQuery; + assert(RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 0, 1, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED)); + assert(RetryPowerVRLinearQuery(0x1010, VK_FORMAT_R8G8B8A8_UNORM, 0, 1, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED)); + assert(!RetryPowerVRLinearQuery(0x5143, VK_FORMAT_B8G8R8A8_UNORM, 0, 1, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED)); + assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 1, 1, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED)); + assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 0, 2, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED)); + assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_R16G16B16A16_SFLOAT, 0, 1, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED)); + assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 0, 1, + 0, VK_ERROR_FORMAT_NOT_SUPPORTED)); + assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 0, 1, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_DEVICE_LOST)); + + VkPhysicalDeviceMemoryProperties memory = {}; + memory.memoryTypeCount = 3; + memory.memoryTypes[0].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + memory.memoryTypes[1].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + memory.memoryTypes[2].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; + using gamescope::DmabufMemoryType; + assert(DmabufMemoryType(memory, 7, 6, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == 1); + assert(DmabufMemoryType(memory, 7, 4, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == 2); + assert(DmabufMemoryType(memory, 1, 6, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == UINT32_MAX); + assert(DmabufMemoryType(memory, 7, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == UINT32_MAX); + assert(DmabufMemoryType(memory, 7, 4, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == UINT32_MAX); + std::puts("Gamescope presentation and DMA-BUF import tests passed"); +} diff --git a/tools/hybris/build_runtime.sh b/tools/hybris/build_runtime.sh new file mode 100755 index 0000000000..53c7d9481e --- /dev/null +++ b/tools/hybris/build_runtime.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# CI-only full libhybris build, using the upstream pinned cross-toolchain recipe. +set -euo pipefail +root=$(cd "$(dirname "$0")/../.." && pwd) +out=${1:?output directory required} +mkdir -p "$out" +out=$(cd "$out" && pwd) +. "$root/tools/hybris/source.env" +work=$(mktemp -d "${TMPDIR:-/tmp}/droiddeck-hybris.XXXXXX") +trap 'rm -rf "$work"' EXIT +fetch() { + git init -q "$3" + git -C "$3" fetch --depth=1 "$1" "$2" + git -C "$3" checkout -q --detach FETCH_HEAD + test "$(git -C "$3" rev-parse HEAD)" = "$2" +} +fetch https://github.com/taowen/libhybris.git "$HYBRIS_REVISION" "$work/libhybris" +fetch https://github.com/taowen/arlinux-rootfs.git "$PROTOCOL_REVISION" "$work/rootfs" +git -C "$work/libhybris" apply --check "$root/tools/hybris/powervr-hal-version.patch" +git -C "$work/libhybris" apply "$root/tools/hybris/powervr-hal-version.patch" +for patch in "$root"/tools/hybris/patches/*.patch; do + git -C "$work/libhybris" apply --check "$patch" + git -C "$work/libhybris" apply "$patch" +done +export ARLINUX_WSI_PROTOCOL_DIR="$work/rootfs/graphics-protocols" +export CONTAINER_ENGINE=podman +"$work/libhybris/tools/build-aarch64.sh" --out "$work/build" + +mkdir -p "$work/package/lib" "$work/package/licenses" +cp -a "$work/build/install/usr/lib/hybris/." "$work/package/lib/" +find "$work/package/lib" -name '*.la' -delete +rm -rf "$work/package/lib/include" "$work/package/lib/pkgconfig" "$work/package/lib/bin" +# Resolve the wrapper's private dependencies without putting its EGL/Vulkan frontends +# on the session's LD_LIBRARY_PATH. The Linux runtime keeps owning its Mesa loader. +while IFS= read -r -d '' library; do + patchelf --set-rpath '$ORIGIN:$ORIGIN/../..' "$library" +done < <(find "$work/package/lib" -type f -name '*.so*' -print0) +for library in libhybris-vulkan-icd.so.0 libhybris-common.so.1 libVkLayer_hybris_compat.so libhybris/linker/q.so; do + test -s "$work/package/lib/$library" +done +cp "$work/libhybris"/LICENSE.* "$work/package/licenses/" +cp "$work/build/manifest.json" "$work/package/build-manifest.json" +printf '%s\n' "$HYBRIS_REVISION" > "$work/package/source-commit" +# Ship the exact patched source and protocol license with the runtime. +git -C "$work/libhybris" diff > "$work/package/licenses/powervr.patch" +git -C "$work/libhybris" archive HEAD | zstd -T0 -q -o "$work/package/licenses/libhybris-source.tar.zst" +cp "$ARLINUX_WSI_PROTOCOL_DIR/wayland-android.xml" "$work/package/licenses/" +(cd "$work/package" && find lib -type f -print0 | sort -z | xargs -0 sha256sum > SHA256SUMS) +tar --zstd -cf "$out/runtime.tzst" -C "$work/package" . +sha256sum "$out/runtime.tzst" | cut -d' ' -f1 > "$out/version.txt" +printf 'Built libhybris %s for Android HAL access from AArch64 Linux\n' "$HYBRIS_REVISION" diff --git a/tools/hybris/low32/README.md b/tools/hybris/low32/README.md new file mode 100644 index 0000000000..43f1586735 --- /dev/null +++ b/tools/hybris/low32/README.md @@ -0,0 +1,99 @@ +# Opt-in device-backed low mappings for Wine WoW64 + +On the tested Pixel PowerVR stack, Vulkan maps host-visible GPU allocations +above 4 GiB. Wine's 32-bit WoW64 Vulkan bridge rejects those pointers. This +caused American Nightmare (202750) to stop at D3D9 vertex-buffer creation even +after the separate PowerVR BC texture profile passed device initialization. + +`low32.c` is an experimental native Linux/glibc preload adapter. It is off by +default. It applies only to anonymous-address, non-executable `MAP_SHARED` +mappings of one explicitly selected character device. It retains the original +device FD, offset, protection, flags, and actual GPU backing, and searches low +address space with `MAP_FIXED_NOREPLACE`. It never truncates a pointer, copies +into shadow storage, replaces existing mappings, or disables Wine's guard. +Caller-specified/fixed mappings, regular files, private/anonymous memory and +other devices retain their original behavior. Failure to find a suitable low +hole fails with ENOMEM. The mmap and mmap64 preload chains are independently +resolved and called through their respective RTLD_NEXT symbols; +only resolver bootstrap uses the raw syscall. A compact atomic cursor avoids +wasting large address slots on thousands of small driver control allocations. +If the compact probe collides, a bounded address-range walk of +/proc/self/maps finds page-sized holes and uses NOREPLACE again to handle races. +The walk runs before coarse fallback, so small allocations do not fragment +large available ranges. A game load had 2.3 GB free below 4 GiB but no hole as large as 4 MiB; the +coarse-only version falsely failed even 4 KiB mappings. Mapping failures are +reported even after the ordinary 256-event trace limit. + +## Build and verify + +Use a native 64-bit Linux/glibc compiler, not the Android NDK or macOS compiler: + +```sh +tools/hybris/low32/build.sh /absolute/build-dir /path/to/Vulkan-Headers/include +``` + +The native library and unit test are always built. GPU probes are optional when +headers are provided; `gpu-copy-native` uses the selected native host compiler +and has the host's architecture, while the Windows x86 probe also needs +i686-w64-mingw32-gcc. Copy a native probe to a device only when their architectures match. +The unit test uses /dev/zero and proves CPU data integrity, collision handling, +concurrency, 2000 simultaneous small mappings, invalid offsets, forwarding and +opt-out. A fragmented-address-space regression reserves the low region, opens +64 off-grid page holes, and verifies all 64 mappings and their data. The old +coarse adapter fails that regression; the address-range fallback passes. An +additional density regression fills 64 existing page holes while preserving a +separate contiguous 16 MiB interval for a later complete data-readback map; the +prior gap-after-coarse implementation fails and the gap-first strategy passes. These +CPU tests do not by themselves prove GPU correctness. +The build also tests both preload orders with a second library that hooks mmap +and mmap64 independently. Opt-out, tracing and adaptation must each preserve +the selected symbol's chain, invalid-offset errno and file offsets above 4 GiB. + +`gpu-copy.c` tests actual Vulkan transfer operations on vendor 0x1010. It maps +two 32 MiB device allocations, runs four copies of full deterministic patterns, +including offset/unmap/remap, uses flush/invalidate and barriers/fences, and +compares every word. It can require each full CPU range to fit below 4 GiB: + +```sh +./gpu-copy-native 32 --require-low32 +# Through a separate Proton ARM64/WoW64 test prefix: +proton run gpu-copy-x86.exe 32 --require-low32 'Z:\path\probe-output.txt' +``` + +The Windows output file avoids Wine's detached console hiding probe results. +Run with Khronos synchronization validation. Keep raw Steam/account logs local; +export only controlled PROBE results, validation IDs and counts. The tested +memory type was device-local, host-visible and coherent; noncoherent physical +memory is not covered by that run. + +## Activation scope + +Set only the target game's overrides, after identifying the render device's +`st_rdev` and validating the installed library's hash: + +```text +LD_PRELOAD=/absolute/guest/path/libdroiddeck-low32.so +DROIDDECK_LOW32_MODE=low32 +DROIDDECK_LOW32_RDEV=<verified decimal st_rdev> +``` + +Preserve any existing target-game preload rather than replacing it. The tested +Pixel's /dev/dri/renderD128 was character device major 226/minor 128, st_rdev 57984. +Do not hardcode that value for other machines. BC emulation and the repaired +DXVK presentation component remain separate prerequisites; this adapter does +not implement them. No global Steam profile, managed graphics pack, Android +security setting or unrelated game's overrides should change. + +Before activating, back up the exact game-environment bytes and only the target +prefix's graphics DLLs, preserving symlinks. Rollback must check for concurrent +edits. Keep original backups in the app; do not copy account files or an entire +Steam prefix to a report. Removing these three overrides disables the adapter. + +## Compatibility limits + +This initial binary was built on Ubuntu 24.04 ARM64 and needs glibc 2.38. The +tested guest supports it. This is not yet a universal runtime component; other +glibc versions, page sizes, drivers, GPU families, native 32-bit processes and +general game stability require their own tests. Bounded native and Windows GPU +copies prove data integrity for those workloads, not unrestricted gameplay. +Never enable globally based on successful testing of one game. diff --git a/tools/hybris/low32/build.sh b/tools/hybris/low32/build.sh new file mode 100755 index 0000000000..f923070669 --- /dev/null +++ b/tools/hybris/low32/build.sh @@ -0,0 +1,27 @@ +#!/bin/sh +set -eu +# Run on native 64-bit Linux/glibc. This is not an Android/Bionic library. +base=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +output=${1:?usage: build.sh /absolute/build-directory [Vulkan-header-directory]} +mkdir -p "$output" +cc=${CC:-cc} +"$cc" -std=gnu11 -Wall -Wextra -Werror -O2 -fPIC -shared -s \ + "$base/low32.c" -ldl -o "$output/libdroiddeck-low32.so" +"$cc" -std=gnu11 -Wall -Wextra -Werror -O2 "$base/test-low32.c" -pthread -o "$output/test-low32" +LD_PRELOAD="$output/libdroiddeck-low32.so" "$output/test-low32" +"$cc" -std=gnu11 -Wall -Wextra -Werror -O2 -fPIC -shared \ + "$base/test-chain-hook.c" -ldl -o "$output/test-chain-hook.so" +"$cc" -std=gnu11 -Wall -Wextra -Werror -O2 "$base/test-preload-chain.c" -ldl -o "$output/test-preload-chain" +for preloads in "$output/libdroiddeck-low32.so:$output/test-chain-hook.so" \ + "$output/test-chain-hook.so:$output/libdroiddeck-low32.so"; do + for mode in off trace low32; do + LD_PRELOAD="$preloads" "$output/test-preload-chain" "$mode" + done +done +if [ "$#" -ge 2 ]; then + "$cc" -std=gnu11 -Wall -Wextra -Werror -O2 -s -I"$2" "$base/gpu-copy.c" -ldl -o "$output/gpu-copy-native" + if command -v i686-w64-mingw32-gcc >/dev/null 2>&1; then + i686-w64-mingw32-gcc -std=gnu11 -Wall -Wextra -Werror -O2 -s -I"$2" \ + "$base/gpu-copy.c" -o "$output/gpu-copy-x86.exe" + fi +fi diff --git a/tools/hybris/low32/gpu-copy.c b/tools/hybris/low32/gpu-copy.c new file mode 100644 index 0000000000..d59dbf6770 --- /dev/null +++ b/tools/hybris/low32/gpu-copy.c @@ -0,0 +1,166 @@ +/* Same standalone GPU-copy probe built as Linux AArch64 and Windows x86. + * Tests actual Vulkan buffers, complete data comparison, noncoherent cache + * operations, remapping with an offset and queue completion. No Steam API. + */ +#define VK_NO_PROTOTYPES +#ifdef _WIN32 +#include <windows.h> +#else +#include <dlfcn.h> +#endif +#include <inttypes.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <vulkan/vulkan.h> + +#define IFNS(X) X(DestroyInstance) X(EnumeratePhysicalDevices) X(GetPhysicalDeviceProperties) \ + X(GetPhysicalDeviceMemoryProperties) X(GetPhysicalDeviceQueueFamilyProperties) X(CreateDevice) X(GetDeviceProcAddr) +#define DFNS(X) X(DestroyDevice) X(GetDeviceQueue) X(CreateBuffer) X(DestroyBuffer) \ + X(GetBufferMemoryRequirements) X(AllocateMemory) X(FreeMemory) X(BindBufferMemory) \ + X(MapMemory) X(UnmapMemory) X(FlushMappedMemoryRanges) X(InvalidateMappedMemoryRanges) \ + X(CreateCommandPool) X(DestroyCommandPool) X(AllocateCommandBuffers) X(ResetCommandBuffer) \ + X(BeginCommandBuffer) X(EndCommandBuffer) X(CmdCopyBuffer) X(CmdPipelineBarrier) \ + X(CreateFence) X(DestroyFence) X(ResetFences) X(QueueSubmit) X(WaitForFences) +#define DECL(n) static PFN_vk##n p##n; +IFNS(DECL) +DFNS(DECL) +#undef DECL +#define CHECK(x) do { VkResult rc=(x); if(rc!=VK_SUCCESS){printf("PROBE_FAIL stage=%s vk_result=%d\n",#x,rc);goto cleanup;} }while(0) +#define REQUIRE(x,msg) do {if(!(x)){puts("PROBE_FAIL " msg);goto cleanup;}}while(0) + +int main(int argc,char **argv) +{ +#ifdef _WIN32 + /* Wine/Proton can detach the Windows console from the Linux pipe. */ + if(argc>3 && !freopen(argv[3],"w",stdout)) return 4; +#endif + setvbuf(stdout,NULL,_IONBF,0); + puts("PROBE_STAGE main"); + unsigned mib=argc>1?(unsigned)strtoul(argv[1],NULL,10):32; + int require_low=argc>2&&!strcmp(argv[2],"--require-low32"); + if(mib<1||mib>256)return 2; + const VkDeviceSize bytes=(VkDeviceSize)mib*1024*1024; + VkInstance instance=VK_NULL_HANDLE;VkDevice device=VK_NULL_HANDLE; + VkBuffer buffers[2]={0};VkDeviceMemory memories[2]={0}; + VkDeviceSize allocated[2]={0};void *mapped[2]={0}; + VkCommandPool pool=VK_NULL_HANDLE;VkFence fence=VK_NULL_HANDLE; + int success=0,pending=0;uint64_t mismatches=0;unsigned iterations=0; + int low_all=1;uint32_t memory_flags[2]={0}; + PFN_vkGetInstanceProcAddr gipa; +#ifdef _WIN32 + HMODULE loader=LoadLibraryA("vulkan-1.dll"); + REQUIRE(loader,"load_vulkan_failed"); + gipa=(PFN_vkGetInstanceProcAddr)(void *)GetProcAddress(loader,"vkGetInstanceProcAddr"); +#else + void *loader=dlopen("libvulkan.so.1",RTLD_NOW|RTLD_LOCAL); + REQUIRE(loader,"load_vulkan_failed"); + gipa=(PFN_vkGetInstanceProcAddr)dlsym(loader,"vkGetInstanceProcAddr"); +#endif + REQUIRE(gipa,"missing_gipa"); + puts("PROBE_STAGE vulkan_loader"); + PFN_vkCreateInstance create=(PFN_vkCreateInstance)gipa(NULL,"vkCreateInstance"); + REQUIRE(create,"missing_create_instance"); + VkApplicationInfo app={.sType=VK_STRUCTURE_TYPE_APPLICATION_INFO, + .pApplicationName="DroidDeck low32 buffer integrity probe",.apiVersion=VK_API_VERSION_1_1}; + VkInstanceCreateInfo ici={.sType=VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,.pApplicationInfo=&app}; + CHECK(create(&ici,NULL,&instance)); + puts("PROBE_STAGE instance_created"); +#define LOADI(n) p##n=(PFN_vk##n)gipa(instance,"vk" #n);REQUIRE(p##n,"missing_" #n); + IFNS(LOADI) +#undef LOADI + uint32_t count=0;CHECK(pEnumeratePhysicalDevices(instance,&count,NULL)); + puts("PROBE_STAGE physical_device_enumeration"); + REQUIRE(count&&count<=16,"physical_device_count"); + VkPhysicalDevice physicals[16],physical=VK_NULL_HANDLE; + CHECK(pEnumeratePhysicalDevices(instance,&count,physicals)); + VkPhysicalDeviceProperties properties; + for(uint32_t i=0;i<count;i++){ + pGetPhysicalDeviceProperties(physicals[i],&properties); + if(properties.vendorID==0x1010&&properties.deviceType!=VK_PHYSICAL_DEVICE_TYPE_CPU){physical=physicals[i];break;} + } + REQUIRE(physical,"no_real_powervr"); + printf("PROBE_DEVICE vendor=%x device=%x api=%x pointer_bits=%zu\n", + properties.vendorID,properties.deviceID,properties.apiVersion,sizeof(void *)*8); + uint32_t qcount=0;pGetPhysicalDeviceQueueFamilyProperties(physical,&qcount,NULL); + REQUIRE(qcount&&qcount<=64,"queue_count"); + VkQueueFamilyProperties qp[64];pGetPhysicalDeviceQueueFamilyProperties(physical,&qcount,qp); + uint32_t family=UINT32_MAX; + for(uint32_t i=0;i<qcount;i++)if(qp[i].queueCount&&(qp[i].queueFlags&VK_QUEUE_GRAPHICS_BIT)){family=i;break;} + REQUIRE(family!=UINT32_MAX,"no_graphics_queue");float priority=1.0f; + VkDeviceQueueCreateInfo qci={.sType=VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,.queueFamilyIndex=family,.queueCount=1,.pQueuePriorities=&priority}; + VkDeviceCreateInfo dci={.sType=VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,.queueCreateInfoCount=1,.pQueueCreateInfos=&qci}; + CHECK(pCreateDevice(physical,&dci,NULL,&device)); +#define LOADD(n) p##n=(PFN_vk##n)pGetDeviceProcAddr(device,"vk" #n);REQUIRE(p##n,"missing_" #n); + DFNS(LOADD) +#undef LOADD + VkPhysicalDeviceMemoryProperties mp;pGetPhysicalDeviceMemoryProperties(physical,&mp); + for(unsigned j=0;j<2;j++){ + VkBufferCreateInfo bci={.sType=VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,.size=bytes, + .usage=VK_BUFFER_USAGE_TRANSFER_SRC_BIT|VK_BUFFER_USAGE_TRANSFER_DST_BIT,.sharingMode=VK_SHARING_MODE_EXCLUSIVE}; + CHECK(pCreateBuffer(device,&bci,NULL,&buffers[j]));VkMemoryRequirements mr; + pGetBufferMemoryRequirements(device,buffers[j],&mr); + uint32_t type=UINT32_MAX; + for(uint32_t i=0;i<mp.memoryTypeCount;i++)if((mr.memoryTypeBits&(1u<<i))&&(mp.memoryTypes[i].propertyFlags&VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)){type=i;break;} + REQUIRE(type!=UINT32_MAX,"no_host_visible_memory");memory_flags[j]=mp.memoryTypes[type].propertyFlags; + VkMemoryAllocateInfo mai={.sType=VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,.allocationSize=mr.size,.memoryTypeIndex=type}; + allocated[j]=mr.size;CHECK(pAllocateMemory(device,&mai,NULL,&memories[j])); + CHECK(pBindBufferMemory(device,buffers[j],memories[j],0)); + } + VkCommandPoolCreateInfo pci={.sType=VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, + .flags=VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,.queueFamilyIndex=family}; + CHECK(pCreateCommandPool(device,&pci,NULL,&pool));VkCommandBuffer command; + VkCommandBufferAllocateInfo cai={.sType=VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, + .commandPool=pool,.level=VK_COMMAND_BUFFER_LEVEL_PRIMARY,.commandBufferCount=1}; + CHECK(pAllocateCommandBuffers(device,&cai,&command)); + VkFenceCreateInfo fci={.sType=VK_STRUCTURE_TYPE_FENCE_CREATE_INFO}; + CHECK(pCreateFence(device,&fci,NULL,&fence));VkQueue queue;pGetDeviceQueue(device,family,0,&queue); + for(unsigned k=0;k<4;k++){ + /* Alternate full mapping and a 64KiB aligned offset, preserving every word. */ + VkDeviceSize offset=(k&1)?65536:0,span=bytes-offset; + for(unsigned j=0;j<2;j++){ + CHECK(pMapMemory(device,memories[j],offset,VK_WHOLE_SIZE,0,&mapped[j])); + int low=(uint64_t)(uintptr_t)mapped[j]+(allocated[j]-offset)<=UINT64_C(0x100000000); + low_all&=low; + printf("PROBE_MAP iteration=%u buffer=%u offset=%" PRIu64 " bytes=%" PRIu64 " ptr=%p low32=%d flags=%x\n", + k,j,(uint64_t)offset,(uint64_t)(allocated[j]-offset),mapped[j],low,memory_flags[j]); + REQUIRE(!require_low||low,"mapping_not_low32"); + } + uint32_t *src=mapped[0],*dst=mapped[1];size_t words=(size_t)(span/4); + for(size_t i=0;i<words;i++){src[i]=((uint32_t)i*2654435761u)^(0xa5a50000u+k);dst[i]=0;} + VkMappedMemoryRange ranges[2];memset(ranges,0,sizeof(ranges)); + for(unsigned j=0;j<2;j++)ranges[j]=(VkMappedMemoryRange){.sType=VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,.memory=memories[j],.offset=offset,.size=VK_WHOLE_SIZE}; + CHECK(pFlushMappedMemoryRanges(device,2,ranges)); + if(k){CHECK(pResetFences(device,1,&fence));CHECK(pResetCommandBuffer(command,0));} + VkCommandBufferBeginInfo cbi={.sType=VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,.flags=VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT}; + CHECK(pBeginCommandBuffer(command,&cbi)); + VkMemoryBarrier before={.sType=VK_STRUCTURE_TYPE_MEMORY_BARRIER,.srcAccessMask=VK_ACCESS_HOST_WRITE_BIT,.dstAccessMask=VK_ACCESS_TRANSFER_READ_BIT|VK_ACCESS_TRANSFER_WRITE_BIT}; + pCmdPipelineBarrier(command,VK_PIPELINE_STAGE_HOST_BIT,VK_PIPELINE_STAGE_TRANSFER_BIT,0,1,&before,0,NULL,0,NULL); + VkBufferCopy copy={.srcOffset=offset,.dstOffset=offset,.size=span};pCmdCopyBuffer(command,buffers[0],buffers[1],1,©); + VkMemoryBarrier after={.sType=VK_STRUCTURE_TYPE_MEMORY_BARRIER,.srcAccessMask=VK_ACCESS_TRANSFER_WRITE_BIT,.dstAccessMask=VK_ACCESS_HOST_READ_BIT}; + pCmdPipelineBarrier(command,VK_PIPELINE_STAGE_TRANSFER_BIT,VK_PIPELINE_STAGE_HOST_BIT,0,1,&after,0,NULL,0,NULL); + CHECK(pEndCommandBuffer(command));VkSubmitInfo si={.sType=VK_STRUCTURE_TYPE_SUBMIT_INFO,.commandBufferCount=1,.pCommandBuffers=&command}; + CHECK(pQueueSubmit(queue,1,&si,fence));pending=1; + VkResult waited=pWaitForFences(device,1,&fence,VK_TRUE,UINT64_C(10000000000)); + if(waited!=VK_SUCCESS){printf("PROBE_FAIL GPU_COMPLETION_UNCONFIRMED result=%d\n",waited);goto cleanup;} + pending=0;CHECK(pInvalidateMappedMemoryRanges(device,1,&ranges[1])); + for(size_t i=0;i<words;i++)if(dst[i]!=(((uint32_t)i*2654435761u)^(0xa5a50000u+k)))mismatches++; + for(unsigned j=0;j<2;j++){pUnmapMemory(device,memories[j]);mapped[j]=NULL;} + iterations++;REQUIRE(!mismatches,"data_mismatch"); + } + success=1; +cleanup: + printf("PROBE_RESULT success=%d mib=%u iterations=%u mismatches=%" PRIu64 " all_mappings_low32=%d\n",success,mib,iterations,mismatches,low_all); + if(pending)return 3; /* Do not explicitly destroy objects with unknown GPU completion. */ + if(device){ + if(pUnmapMemory)for(unsigned j=0;j<2;j++)if(mapped[j])pUnmapMemory(device,memories[j]); + if(fence&&pDestroyFence)pDestroyFence(device,fence,NULL); + if(pool&&pDestroyCommandPool)pDestroyCommandPool(device,pool,NULL); + for(unsigned j=0;j<2;j++)if(buffers[j]&&pDestroyBuffer)pDestroyBuffer(device,buffers[j],NULL); + for(unsigned j=0;j<2;j++)if(memories[j]&&pFreeMemory)pFreeMemory(device,memories[j],NULL); + if(pDestroyDevice)pDestroyDevice(device,NULL); + } + if(instance&&pDestroyInstance)pDestroyInstance(instance,NULL); + return success?0:1; +} diff --git a/tools/hybris/low32/low32.c b/tools/hybris/low32/low32.c new file mode 100644 index 0000000000..220212cbfe --- /dev/null +++ b/tools/hybris/low32/low32.c @@ -0,0 +1,256 @@ +/* Experimental per-process PowerVR device-backed low-address mmap adapter. + * No copied/shadow memory, changed device offset or MAP_FIXED replacement. + * Default is off. Enable only for the identified render-device rdev and the + * target x86/WoW64 game. Native 64-bit Linux/glibc preload, not an Android ABI DLL. + */ +#define _GNU_SOURCE +#define _LARGEFILE64_SOURCE +#include <dlfcn.h> +#include <errno.h> +#include <inttypes.h> +#include <stdatomic.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/syscall.h> +#include <unistd.h> + +#ifndef MAP_FIXED_NOREPLACE +#define MAP_FIXED_NOREPLACE 0x100000 +#endif + +static _Atomic uint64_t cursor; +static _Atomic unsigned logged; +typedef void *(*map_function)(void *,size_t,int,int,int,off_t); +typedef void *(*map64_function)(void *,size_t,int,int,int,off64_t); +static _Atomic(map_function) next_map; +static _Atomic(map64_function) next_map64; +_Static_assert(sizeof(off_t) == sizeof(off64_t) && sizeof(off_t) == 8, + "64-bit host required"); +static __thread int resolving __attribute__((tls_model("initial-exec"))); +static __thread int active __attribute__((tls_model("initial-exec"))); +static void *native_map(void *addr, size_t length, int prot, int flags, int fd, off_t offset) +{ + map_function next=atomic_load(&next_map); + if (!next && !resolving) { + resolving=1; + next=(map_function)dlsym(RTLD_NEXT,"mmap"); + atomic_store(&next_map,next); + resolving=0; + } + /* Bootstrap only while resolving; otherwise preserve existing preload hooks. */ + if (next) return next(addr,length,prot,flags,fd,offset); + return (void *)syscall(SYS_mmap, addr, length, prot, flags, fd, offset); +} + +static void *native_map64(void *addr, size_t length, int prot, int flags, int fd, off_t offset) +{ + map64_function next=atomic_load(&next_map64); + if (!next && !resolving) { + resolving=1; + next=(map64_function)dlsym(RTLD_NEXT,"mmap64"); + atomic_store(&next_map64,next); + resolving=0; + } + if (next) return next(addr,length,prot,flags,fd,(off64_t)offset); + return (void *)syscall(SYS_mmap, addr, length, prot, flags, fd, offset); +} + +static void trace_map(const char *kind, size_t n, int prot, int flags, int fd, + off_t off, const struct stat *st, void *p, int error) +{ + int saved = errno; + unsigned count = atomic_fetch_add(&logged, 1); + if (count < 256 || error != 0) { + char text[320]; + int nbytes = snprintf(text, sizeof(text), + "DD_LOW32 %s pid=%ld len=%zu prot=%x flags=%x fd=%d off=%jd mode=%o rdev=%ju ptr=%p errno=%d\n", + kind, (long)getpid(), n, prot, flags, fd, (intmax_t)off, st ? st->st_mode : 0, + st ? (uintmax_t)st->st_rdev : 0, p, error); + if (nbytes > 0) { + ssize_t written = write(STDERR_FILENO, text, + (size_t)nbytes < sizeof(text) ? (size_t)nbytes : sizeof(text)-1); + (void)written; + } + } + errno = saved; +} + +static int target_device(int fd, struct stat *st) +{ + const char *value = getenv("DROIDDECK_LOW32_RDEV"); + char *end = NULL; + if (!value || !*value || fd < 0) return 0; + int saved = errno; + errno = 0; + uintmax_t expected = strtoumax(value, &end, 10); + int valid = !errno && end && !*end && expected > 0 && + fstat(fd, st) == 0 && S_ISCHR(st->st_mode) && + (uintmax_t)st->st_rdev == expected; + errno = saved; + return valid; +} + +static void *adapted_map(map_function forward, void *addr, size_t length, int prot, + int flags, int fd, off_t offset) +{ + const char *mode = getenv("DROIDDECK_LOW32_MODE"); + struct stat st = {0}; + if (mode && !strcmp(mode, "trace")) { + void *p = forward(addr, length, prot, flags, fd, offset); + if (fd >= 0 && (prot & PROT_WRITE) && !(prot & PROT_EXEC) && + (flags & MAP_TYPE) == MAP_SHARED) { + int saved=errno; + (void)fstat(fd,&st); + errno=saved; + trace_map("trace", length, prot, flags, fd, offset, &st, p, + p == MAP_FAILED ? errno : 0); + } + return p; + } + if (!mode || strcmp(mode, "low32") || addr || !length || + (flags & (MAP_ANONYMOUS | MAP_FIXED | MAP_FIXED_NOREPLACE)) || + (prot & PROT_EXEC) || (flags & MAP_TYPE) != MAP_SHARED || + !target_device(fd, &st)) + return forward(addr, length, prot, flags, fd, offset); + + const uintptr_t lower = 0x10000000u, upper = 0xffff0000u; + const uintptr_t step = 0x00400000u; + if (length > upper-lower) { + errno = ENOMEM; + trace_map("too_large", length, prot, flags, fd, offset, &st, MAP_FAILED, errno); + return MAP_FAILED; + } + long page_value=sysconf(_SC_PAGESIZE); + uintptr_t page=page_value>0?(uintptr_t)page_value:4096; + uintptr_t rounded=(length+page-1)&~(page-1); + uintptr_t span=upper-lower; + uintptr_t compact=(uintptr_t)(atomic_fetch_add(&cursor,rounded)%span); + if (rounded>span-compact) compact=0; + unsigned slots = (unsigned)((span-length)/step)+1; + unsigned start = (unsigned)(compact/step)%slots; + int original_errno = errno; + for (unsigned i = 0; i < 1; i++) { + /* Compact first: hundreds of small driver mappings must not waste a + * 4MiB address slot each. Coarse search is only for existing Wine holes. */ + uintptr_t hint = lower + (i==0?compact:(uintptr_t)((start+i-1)%slots)*step); + void *p = forward((void *)hint, length, prot, + flags|MAP_FIXED_NOREPLACE, fd, offset); + if (p != MAP_FAILED) { + uintptr_t first = (uintptr_t)p; + if (first >= lower && first < upper && length <= upper-first) { + errno = original_errno; + trace_map("mapped", length, prot, flags, fd, offset, &st, p, 0); + return p; + } + /* Older kernels can ignore NOREPLACE; never return a high mapping. */ + int saved = errno; + (void)syscall(SYS_munmap, p, length); + errno = saved; + } else if (errno != EEXIST && errno != ENOMEM && errno != EAGAIN) { + trace_map("rejected", length, prot, flags, fd, offset, &st, p, errno); + return p; + } + } + /* Pack small allocations into address holes before coarse probing can + * fragment large holes. Walk + * this process's current mappings, then use NOREPLACE to tolerate races. + * No pointer paths or contents are read; only address ranges are used. */ + for (unsigned pass = 0; pass < 2; ++pass) { + FILE *maps = fopen("/proc/self/maps", "r"); + if (!maps) break; + char line[512]; + uintptr_t gap_start = lower; + unsigned lines = 0; + while (fgets(line, sizeof(line), maps) && ++lines < 65536) { + uintptr_t first, last; + if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &first, &last) != 2) continue; + if (last <= gap_start) continue; + uintptr_t gap_end = first < upper ? first : upper; + if (gap_end > gap_start && rounded <= gap_end - gap_start) { + void *p = forward((void *)gap_start, length, prot, + flags | MAP_FIXED_NOREPLACE, fd, offset); + if (p != MAP_FAILED) { + uintptr_t address = (uintptr_t)p; + if (address >= lower && address < upper && length <= upper - address) { + fclose(maps); + errno = original_errno; + trace_map("mapped_gap", length, prot, flags, fd, offset, &st, p, 0); + return p; + } + (void)syscall(SYS_munmap, p, length); + } else if (errno != EEXIST && errno != ENOMEM && errno != EAGAIN) { + int saved = errno; + fclose(maps); + errno = saved; + trace_map("rejected", length, prot, flags, fd, offset, &st, MAP_FAILED, errno); + return MAP_FAILED; + } + } + if (last > gap_start) gap_start = last; + if (gap_start >= upper) break; + } + if (gap_start < upper && rounded <= upper - gap_start) { + void *p = forward((void *)gap_start, length, prot, + flags | MAP_FIXED_NOREPLACE, fd, offset); + if (p != MAP_FAILED) { + uintptr_t address = (uintptr_t)p; + if (address >= lower && address < upper && length <= upper - address) { + fclose(maps); + errno = original_errno; + trace_map("mapped_gap", length, prot, flags, fd, offset, &st, p, 0); + return p; + } + (void)syscall(SYS_munmap, p, length); + } + } + fclose(maps); + } + for (unsigned i = 1; i <= slots; i++) { + /* Last resort if address walking was unavailable or raced. */ + uintptr_t hint = lower + (i==0?compact:(uintptr_t)((start+i-1)%slots)*step); + void *p = forward((void *)hint, length, prot, + flags|MAP_FIXED_NOREPLACE, fd, offset); + if (p != MAP_FAILED) { + uintptr_t first = (uintptr_t)p; + if (first >= lower && first < upper && length <= upper-first) { + errno = original_errno; + trace_map("mapped", length, prot, flags, fd, offset, &st, p, 0); + return p; + } + /* Older kernels can ignore NOREPLACE; never return a high mapping. */ + int saved = errno; + (void)syscall(SYS_munmap, p, length); + errno = saved; + } else if (errno != EEXIST && errno != ENOMEM && errno != EAGAIN) { + trace_map("rejected", length, prot, flags, fd, offset, &st, p, errno); + return p; + } + } + errno = ENOMEM; + trace_map("no_low_hole", length, prot, flags, fd, offset, &st, MAP_FAILED, errno); + return MAP_FAILED; +} + +static void *intercept_map(map_function forward, void *addr, size_t length, + int prot, int flags, int fd, off_t offset) +{ + if (active) return forward(addr,length,prot,flags,fd,offset); + active=1; + void *p=adapted_map(forward,addr,length,prot,flags,fd,offset); + active=0; + return p; +} + +void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) +{ + return intercept_map(native_map,addr,length,prot,flags,fd,offset); +} + +void *mmap64(void *addr, size_t length, int prot, int flags, int fd, off64_t offset) +{ + return intercept_map(native_map64,addr,length,prot,flags,fd,(off_t)offset); +} diff --git a/tools/hybris/low32/test-chain-hook.c b/tools/hybris/low32/test-chain-hook.c new file mode 100644 index 0000000000..b5e68a1e64 --- /dev/null +++ b/tools/hybris/low32/test-chain-hook.c @@ -0,0 +1,37 @@ +/* Controlled second preload: distinct mmap/mmap64 counters and 64-bit offsets. */ +#define _GNU_SOURCE +#define _LARGEFILE64_SOURCE +#include <dlfcn.h> +#include <stdint.h> +#include <sys/mman.h> +#include <sys/types.h> + +static int selected_fd = -2; +static unsigned calls[2]; +static int64_t offsets[2]; + +void chain_clear(int fd) +{ + selected_fd = fd; + calls[0] = calls[1] = 0; + offsets[0] = offsets[1] = -1; +} + +unsigned chain_calls(unsigned channel) { return calls[channel]; } +int64_t chain_offset(unsigned channel) { return offsets[channel]; } + +void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off) +{ + static void *(*next)(void *, size_t, int, int, int, off_t); + if (!next) next = dlsym(RTLD_NEXT, "mmap"); + if (fd == selected_fd) { ++calls[0]; offsets[0] = off; } + return next(addr, len, prot, flags, fd, off); +} + +void *mmap64(void *addr, size_t len, int prot, int flags, int fd, off64_t off) +{ + static void *(*next)(void *, size_t, int, int, int, off64_t); + if (!next) next = dlsym(RTLD_NEXT, "mmap64"); + if (fd == selected_fd) { ++calls[1]; offsets[1] = off; } + return next(addr, len, prot, flags, fd, off); +} diff --git a/tools/hybris/low32/test-low32.c b/tools/hybris/low32/test-low32.c new file mode 100644 index 0000000000..88c2b7130b --- /dev/null +++ b/tools/hybris/low32/test-low32.c @@ -0,0 +1,119 @@ +#define _GNU_SOURCE +#include <assert.h> +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <unistd.h> + +#define N (32u*1024u*1024u) +static int zero_fd; +static void *thread_test(void *arg) +{ + unsigned seed = (unsigned)(uintptr_t)arg; + uint32_t *p = mmap(NULL,N,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0); + assert(p != MAP_FAILED && (uintptr_t)p+N <= 0x100000000ull); + for (size_t i=0;i<N/4;i++) p[i]=(uint32_t)i^seed; + for (size_t i=0;i<N/4;i++) assert(p[i]==((uint32_t)i^seed)); + assert(!munmap(p,N)); + return NULL; +} +int main(void) +{ + zero_fd=open("/dev/zero",O_RDWR|O_CLOEXEC); assert(zero_fd>=0); + struct stat st; assert(!fstat(zero_fd,&st)); char value[48]; + snprintf(value,sizeof(value),"%ju",(uintmax_t)st.st_rdev); + assert(!setenv("DROIDDECK_LOW32_RDEV",value,1)); + assert(!setenv("DROIDDECK_LOW32_MODE","low32",1)); + /* Existing low-address memory must survive device mappings. */ + uint32_t *guard=mmap((void *)0x10000000,128u*1024u*1024u,PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED_NOREPLACE,-1,0); + assert(guard==(void *)0x10000000);guard[0]=0xdeadbeef;guard[32767]=0xcafef00d; + pthread_t threads[8]; + for (uintptr_t i=0;i<8;i++) assert(!pthread_create(&threads[i],NULL,thread_test,(void *)i)); + for (unsigned i=0;i<8;i++) assert(!pthread_join(threads[i],NULL)); + assert(guard[0]==0xdeadbeef && guard[32767]==0xcafef00d); + puts("PASS concurrent 32MiB mappings, full pattern readback and occupied-memory preservation"); + assert(!munmap(guard,128u*1024u*1024u)); + /* Caller-specified address and MAP_FIXED semantics are preserved. */ + void *explicit=mmap((void *)0x30000000,4096,PROT_READ|PROT_WRITE, + MAP_SHARED|MAP_FIXED_NOREPLACE,zero_fd,0); + assert(explicit==(void *)0x30000000); assert(!munmap(explicit,4096)); + int mem=memfd_create("low32-nontarget",0);assert(mem>=0);assert(!ftruncate(mem,N)); + uint32_t *q=mmap((void *)0x500000000ull,N,PROT_READ|PROT_WRITE,MAP_SHARED,mem,0); + assert(q==(void *)0x500000000ull);q[0]=123;assert(q[0]==123);assert(!munmap(q,N));close(mem); + puts("PASS unrelated regular-file mapping and explicit-address forwarding"); + errno=0; + void *bad=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,1); + assert(bad==MAP_FAILED && errno==EINVAL); + puts("PASS invalid device offset retains EINVAL"); + /* Real game initialization creates many small control/buffer mappings. */ + void *small[2000]; + for(unsigned i=0;i<2000;i++) { + small[i]=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0); + assert(small[i]!=MAP_FAILED && (uintptr_t)small[i]+4096<=0x100000000ull); + *(uint32_t *)small[i]=i; + } + for(unsigned i=0;i<2000;i++){ + assert(*(uint32_t *)small[i]==i);assert(!munmap(small[i],4096)); + } + puts("PASS 2000 simultaneous small mappings without address-slot exhaustion"); + /* A fragmented Wine address space has usable holes away from every + * 4MiB probe location. The mapping walk must find them without clobbering. */ + const uintptr_t lo=0x10000000u, hi=0xffff0000u; + void *reservation=mmap((void *)lo,hi-lo,PROT_NONE, + MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_FIXED_NOREPLACE,-1,0); + assert(reservation==(void *)lo); + void *holes[64], *fragmented[64]; + for (unsigned i=0;i<64;i++) { + holes[i]=(void *)(lo+0x12345000u+(uintptr_t)i*0x10000u); + assert(!munmap(holes[i],4096)); + } + for (unsigned i=0;i<64;i++) { + fragmented[i]=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0); + assert(fragmented[i]!=MAP_FAILED); + int found=0;for(unsigned j=0;j<64;j++)found|=fragmented[i]==holes[j];assert(found); + *(uint32_t *)fragmented[i]=i+77; + } + for (unsigned i=0;i<64;i++) assert(*(uint32_t *)fragmented[i]==i+77); + for (unsigned i=0;i<64;i++) assert(!munmap(fragmented[i],4096)); + assert(!munmap(reservation,hi-lo)); + puts("PASS fragmented low32 mappings find 64 page holes beyond coarse probes"); + /* Small allocations must consume existing page holes rather than punch + * coarse-grid holes into the only large interval needed by a later map. */ + reservation=mmap((void *)lo,hi-lo,PROT_NONE, + MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_FIXED_NOREPLACE,-1,0); + assert(reservation==(void *)lo); + for (unsigned i=0;i<64;i++) assert(!munmap(holes[i],4096)); + const uintptr_t large_address=0x70000000u; + const size_t large_size=16u*1024u*1024u; + assert(!munmap((void *)large_address,large_size)); + for (unsigned i=0;i<64;i++) { + fragmented[i]=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0); + assert(fragmented[i]!=MAP_FAILED); + int found=0;for(unsigned j=0;j<64;j++)found|=fragmented[i]==holes[j];assert(found); + *(uint32_t *)fragmented[i]=i+99; + } + uint32_t *large=mmap(NULL,large_size,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0); + assert(large==(void *)large_address); + for(size_t i=0;i<large_size/4;i++)large[i]=(uint32_t)i^0xa5a5a5a5u; + for(size_t i=0;i<large_size/4;i++)assert(large[i]==((uint32_t)i^0xa5a5a5a5u)); + for(unsigned i=0;i<64;i++){ + assert(*(uint32_t *)fragmented[i]==i+99);assert(!munmap(fragmented[i],4096)); + } + assert(!munmap(large,large_size));assert(!munmap(reservation,hi-lo)); + puts("PASS page-sized mapping density preserves subsequent contiguous 16MiB allocation"); + assert(!setenv("DROIDDECK_LOW32_RDEV","999999999",1)); + q=mmap((void *)0x510000000ull,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0); + assert(q==(void *)0x510000000ull);assert(!munmap(q,4096)); + puts("PASS mismatched device remains untouched"); + assert(!unsetenv("DROIDDECK_LOW32_MODE")); + q=mmap((void *)0x520000000ull,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0); + assert(q==(void *)0x520000000ull);assert(!munmap(q,4096)); + puts("PASS opt-in disabled by default"); + close(zero_fd);return 0; +} diff --git a/tools/hybris/low32/test-preload-chain.c b/tools/hybris/low32/test-preload-chain.c new file mode 100644 index 0000000000..f631763549 --- /dev/null +++ b/tools/hybris/low32/test-preload-chain.c @@ -0,0 +1,62 @@ +#define _GNU_SOURCE +#define _LARGEFILE64_SOURCE +#include <assert.h> +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <unistd.h> + +int main(int argc, char **argv) +{ + assert(argc == 2); + void (*clear)(int) = dlsym(RTLD_DEFAULT, "chain_clear"); + unsigned (*calls)(unsigned) = dlsym(RTLD_DEFAULT, "chain_calls"); + int64_t (*offset)(unsigned) = dlsym(RTLD_DEFAULT, "chain_offset"); + assert(clear && calls && offset); + if (strcmp(argv[1], "off")) assert(!setenv("DROIDDECK_LOW32_MODE", argv[1], 1)); + else assert(!unsetenv("DROIDDECK_LOW32_MODE")); + int fd = open("/dev/zero", O_RDWR | O_CLOEXEC); + assert(fd >= 0); + struct stat st; + assert(!fstat(fd, &st)); + char rdev[48]; + snprintf(rdev, sizeof(rdev), "%ju", (uintmax_t)st.st_rdev); + assert(!setenv("DROIDDECK_LOW32_RDEV", rdev, 1)); + for (unsigned channel = 0; channel < 2; ++channel) { + clear(fd); + void *p = channel ? mmap64(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) + : mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + assert(p != MAP_FAILED); + assert(calls(channel) == 1 && calls(1 - channel) == 0 && offset(channel) == 0); + if (!strcmp(argv[1], "low32")) assert((uintptr_t)p + 4096 <= UINT64_C(0x100000000)); + *(unsigned *)p = 0xcafef00d; + assert(*(unsigned *)p == 0xcafef00d && !munmap(p, 4096)); + clear(fd); + errno = 0; + p = channel ? mmap64(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 1) + : mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 1); + assert(p == MAP_FAILED && errno == EINVAL); + assert(calls(channel) == 1 && calls(1 - channel) == 0 && offset(channel) == 1); + } + close(fd); + /* Regular-file forwarding must preserve an mmap64 offset above 4 GiB. */ + fd = memfd_create("preload-chain-test", 0); + const off64_t large_offset = INT64_C(0x200001000); + assert(fd >= 0 && !ftruncate64(fd, large_offset + 4096)); + unsigned value = 0x1234abcd; + assert(pwrite64(fd, &value, sizeof(value), large_offset) == (ssize_t)sizeof(value)); + clear(fd); + unsigned *p = mmap64(NULL, 4096, PROT_READ, MAP_SHARED, fd, large_offset); + assert(p != MAP_FAILED && *p == value); + assert(calls(1) == 1 && calls(0) == 0 && offset(1) == large_offset); + assert(!munmap(p, 4096)); + close(fd); + printf("PASS separate mmap/mmap64 chains (%s), EINVAL and >4GiB offset readback\n", argv[1]); + return 0; +} diff --git a/tools/hybris/patches/0001-dxvk-bc-profile.patch b/tools/hybris/patches/0001-dxvk-bc-profile.patch new file mode 100644 index 0000000000..0076f53f87 --- /dev/null +++ b/tools/hybris/patches/0001-dxvk-bc-profile.patch @@ -0,0 +1,505 @@ +diff --git a/hybris/vulkan/compat/bc_commands.c b/hybris/vulkan/compat/bc_commands.c +index 90dac59..cf62d7d 100644 +--- a/hybris/vulkan/compat/bc_commands.c ++++ b/hybris/vulkan/compat/bc_commands.c +@@ -2,6 +2,7 @@ + #define VK_NO_PROTOTYPES + #include "bc_context.h" + #include <string.h> ++#include <stdio.h> + + #define PROC(name) PFN_vk##name name = (PFN_vk##name)device->resolver(device->handle, "vk" #name) + static VkResult VKAPI_CALL allocate_commands(VkDevice handle, const VkCommandBufferAllocateInfo *info, +@@ -76,6 +77,7 @@ static VkResult VKAPI_CALL end_command(VkCommandBuffer handle) + PROC(EndCommandBuffer); + VkResult result = EndCommandBuffer(handle); + VkResult recorded = command->state.error; ++ if (result != VK_SUCCESS || recorded != VK_SUCCESS) fprintf(stderr, "HYBRIS_BC end: native=%d recorded=%d\n", result, recorded); + if (recorded == VK_SUCCESS) return result; + if (recorded == VK_ERROR_OUT_OF_HOST_MEMORY || recorded == VK_ERROR_OUT_OF_DEVICE_MEMORY || + recorded == VK_ERROR_DEVICE_LOST) return recorded; +@@ -198,6 +200,37 @@ static void VKAPI_CALL push_constants(VkCommandBuffer handle, VkPipelineLayout l + CmdPushConstants(handle, layout, stages, offset, size, values); + if (device->format_mask) hybris_bc_save_push(&command->state, layout, stages, offset, size, values); + } ++static void bind_descriptors2(VkCommandBuffer handle, const VkBindDescriptorSetsInfo *info, const char *name) ++{ ++ struct hybris_bc_device *device; ++ struct hybris_bc_command *command = hybris_bc_command_find(handle, &device); ++ if (!command) return; ++ PFN_vkCmdBindDescriptorSets2 call = (void *)device->resolver(device->handle, name); ++ call(handle, info); ++ if (device->format_mask && (info->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT)) ++ hybris_bc_save_descriptors(&command->state, VK_PIPELINE_BIND_POINT_COMPUTE, ++ info->layout, info->firstSet, info->descriptorSetCount, info->pDescriptorSets, ++ info->dynamicOffsetCount, info->pDynamicOffsets); ++} ++static void VKAPI_CALL bind_descriptors2_core(VkCommandBuffer handle, const VkBindDescriptorSetsInfo *info) ++{ bind_descriptors2(handle, info, "vkCmdBindDescriptorSets2"); } ++static void VKAPI_CALL bind_descriptors2_khr(VkCommandBuffer handle, const VkBindDescriptorSetsInfo *info) ++{ bind_descriptors2(handle, info, "vkCmdBindDescriptorSets2KHR"); } ++static void push_constants2(VkCommandBuffer handle, const VkPushConstantsInfo *info, const char *name) ++{ ++ struct hybris_bc_device *device; ++ struct hybris_bc_command *command = hybris_bc_command_find(handle, &device); ++ if (!command) return; ++ PFN_vkCmdPushConstants2 call = (void *)device->resolver(device->handle, name); ++ call(handle, info); ++ if (device->format_mask) ++ hybris_bc_save_push(&command->state, info->layout, info->stageFlags, ++ info->offset, info->size, info->pValues); ++} ++static void VKAPI_CALL push_constants2_core(VkCommandBuffer handle, const VkPushConstantsInfo *info) ++{ push_constants2(handle, info, "vkCmdPushConstants2"); } ++static void VKAPI_CALL push_constants2_khr(VkCommandBuffer handle, const VkPushConstantsInfo *info) ++{ push_constants2(handle, info, "vkCmdPushConstants2KHR"); } + PFN_vkVoidFunction hybris_bc_commands_proc(const char *name) + { + static const struct { const char *name; PFN_vkVoidFunction function; } commands[] = { +@@ -207,7 +240,9 @@ PFN_vkVoidFunction hybris_bc_commands_proc(const char *name) + ENTRY(ResetCommandBuffer, reset_command), ENTRY(ResetCommandPool, reset_pool), + ENTRY(DestroyCommandPool, destroy_pool), ENTRY(CreatePipelineLayout, create_layout), + ENTRY(DestroyPipelineLayout, destroy_layout), ENTRY(CmdBindPipeline, bind_pipeline), +- ENTRY(CmdBindDescriptorSets, bind_descriptors), ENTRY(CmdPushConstants, push_constants) ++ ENTRY(CmdBindDescriptorSets, bind_descriptors), ENTRY(CmdPushConstants, push_constants), ++ ENTRY(CmdBindDescriptorSets2, bind_descriptors2_core), ENTRY(CmdBindDescriptorSets2KHR, bind_descriptors2_khr), ++ ENTRY(CmdPushConstants2, push_constants2_core), ENTRY(CmdPushConstants2KHR, push_constants2_khr) + #undef ENTRY + }; + for (size_t i = 0; i < sizeof(commands) / sizeof(commands[0]); ++i) +diff --git a/hybris/vulkan/compat/bc_image.c b/hybris/vulkan/compat/bc_image.c +index fe25344..44faaf6 100644 +--- a/hybris/vulkan/compat/bc_image.c ++++ b/hybris/vulkan/compat/bc_image.c +@@ -5,6 +5,19 @@ + + #define PROC(name) PFN_vk##name name = (PFN_vk##name)image->resolver(image->device, "vk" #name) + ++int hybris_bc_srgb_family(VkFormat format) ++{ ++ return (format >= VK_FORMAT_BC1_RGB_UNORM_BLOCK && format <= VK_FORMAT_BC3_SRGB_BLOCK) || ++ format == VK_FORMAT_BC7_UNORM_BLOCK || format == VK_FORMAT_BC7_SRGB_BLOCK; ++} ++int hybris_bc_view_compatible(VkFormat image, VkFormat view) ++{ ++ if (image == view) return 1; ++ return hybris_bc_srgb_family(image) && ++ ((image - VK_FORMAT_BC1_RGB_UNORM_BLOCK) / 2 == ++ (view - VK_FORMAT_BC1_RGB_UNORM_BLOCK) / 2) && hybris_bc_srgb_family(view); ++} ++ + VkFormat hybris_bc_image_format(VkFormat format, unsigned rgb_mask) + { + switch (format) { +@@ -71,19 +84,28 @@ VkResult hybris_bc_image_describe(const VkImageCreateInfo *info, struct hybris_b + info->imageType != VK_IMAGE_TYPE_2D || info->tiling != VK_IMAGE_TILING_OPTIMAL || + info->samples != VK_SAMPLE_COUNT_1_BIT || + (info->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && info->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) || +- (info->flags & ~VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) || ++ (info->flags & ~(VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT | VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) || ++ ((info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) && !hybris_bc_srgb_family(info->format)) || + !info->usage || + (info->usage & ~(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) || + !info->extent.width || !info->extent.height || info->extent.depth != 1 || + !info->mipLevels || info->mipLevels > 32 || !info->arrayLayers) + return VK_ERROR_FORMAT_NOT_SUPPORTED; ++ image->flags = info->flags; ++ image->view_mask = (info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) ? 3 : 1; + /* These chains only constrain views or request no external/swapchain + * binding. The decoded image has the same view restriction in our wrapper. */ + for (const VkBaseInStructure *next = info->pNext; next; next = next->pNext) { + if (next->sType == VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO) { + const VkImageFormatListCreateInfo *list = (const void *)next; +- for (uint32_t i = 0; i < list->viewFormatCount; ++i) +- if (list->pViewFormats[i] != info->format) return VK_ERROR_FORMAT_NOT_SUPPORTED; ++ if (list->viewFormatCount) image->view_mask = 0; ++ for (uint32_t i = 0; i < list->viewFormatCount; ++i) { ++ VkFormat view = list->pViewFormats[i]; ++ if (!hybris_bc_view_compatible(info->format, view) || ++ (view != info->format && !(info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT))) ++ return VK_ERROR_FORMAT_NOT_SUPPORTED; ++ image->view_mask |= view == info->format ? 1u : 2u; ++ } + } else if (next->sType == VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO) { + if (((const VkExternalMemoryImageCreateInfo *)next)->handleTypes) + return VK_ERROR_FORMAT_NOT_SUPPORTED; +diff --git a/hybris/vulkan/compat/bc_image.h b/hybris/vulkan/compat/bc_image.h +index 9e62eb3..c950cc2 100644 +--- a/hybris/vulkan/compat/bc_image.h ++++ b/hybris/vulkan/compat/bc_image.h +@@ -12,10 +12,14 @@ struct hybris_bc_image { + VkMemoryRequirements requirements; + VkBool32 requires_dedicated, prefers_dedicated; + VkFormat format, decoded_format; ++ VkImageCreateFlags flags; ++ unsigned view_mask; + VkExtent3D extent; + uint32_t mip_levels, layers, block_bytes; + VkDeviceSize mip_offset[32], block_size; + }; ++int hybris_bc_srgb_family(VkFormat format); ++int hybris_bc_view_compatible(VkFormat image, VkFormat view); + VkFormat hybris_bc_image_format(VkFormat format, unsigned rgb_mask); + VkResult hybris_bc_image_describe(const VkImageCreateInfo *info, struct hybris_bc_image *image); + void hybris_bc_image_backing_info(const struct hybris_bc_image *image, +diff --git a/hybris/vulkan/compat/bc_policy.c b/hybris/vulkan/compat/bc_policy.c +index c5856f6..3124a25 100644 +--- a/hybris/vulkan/compat/bc_policy.c ++++ b/hybris/vulkan/compat/bc_policy.c +@@ -5,6 +5,7 @@ + #include "bc_context.h" + #include "../layer/layer.h" + #include <stdlib.h> ++#include <stddef.h> + #include <string.h> + #include <sys/auxv.h> + +@@ -16,12 +17,18 @@ static void initialize_policy(void) + const char *value = getenv("HYBRIS_BC_TEXTURES"); + if (!value || !strcmp(value, "missing") || !strcmp(value, "1")) policy = 1; + else if (value && !strcmp(value, "force")) policy = 2; ++ else if (value && !strcmp(value, "dxvk")) policy = 3; + } + int hybris_bc_enabled(void) + { + pthread_once(&policy_once, initialize_policy); + return policy != 0; + } ++static int dxvk_profile(void) ++{ ++ pthread_once(&policy_once, initialize_policy); ++ return policy == 3; ++} + #define PHYSICAL_PROC(name) PFN_vk##name name = (PFN_vk##name)context.resolver(context.instance, "vk" #name) + /* Preserve three-channel border replacement when the native image format + * supports the full sampled/transfer domain. Selection is per physical device; +@@ -52,7 +59,7 @@ unsigned hybris_bc_physical_mask(VkPhysicalDevice physical) + VkPhysicalDeviceProperties properties; + GetPhysicalDeviceProperties(physical, &properties); + /* Core 1.4 includes descriptor-state commands that are not intercepted yet. */ +- if (properties.apiVersion < VK_API_VERSION_1_1 || properties.apiVersion >= VK_MAKE_API_VERSION(0, 1, 4, 0) || ++ if (properties.apiVersion < VK_API_VERSION_1_1 || (!dxvk_profile() && properties.apiVersion >= VK_MAKE_API_VERSION(0, 1, 4, 0)) || + properties.limits.maxStorageBufferRange < 256 || + properties.limits.minStorageBufferOffsetAlignment >= properties.limits.maxStorageBufferRange) return 0; + uint32_t count = 0; +@@ -72,6 +79,9 @@ unsigned hybris_bc_physical_mask(VkPhysicalDevice physical) + unsigned mask = 0; + for (unsigned i = 0; i < 16; ++i) { + VkFormat format = VK_FORMAT_BC1_RGB_UNORM_BLOCK + i; ++ /* D3D uses BC1 RGBA. Keep RGB-only BC1 unadvertised until absent-alpha ++ * border semantics are implemented on devices without RGB8 images. */ ++ if (dxvk_profile() && i < 2) continue; + VkFormat backing = hybris_bc_image_format(format, physical_rgb_mask(physical)); + if (backing == VK_FORMAT_UNDEFINED) continue; + VkFormatProperties native, decoded; +@@ -84,6 +94,33 @@ unsigned hybris_bc_physical_mask(VkPhysicalDevice physical) + } + return mask; + } ++/* The emulation profile implements Vulkan 1.3 plus maintenance6. Do not expose ++ * 1.4 core host-copy/push-descriptor operations that bypass our state tracking. */ ++static void cap_properties(VkPhysicalDevice physical, VkPhysicalDeviceProperties *out) ++{ ++ if (dxvk_profile() && hybris_bc_physical_mask(physical) && out->apiVersion > VK_API_VERSION_1_3) ++ out->apiVersion = VK_API_VERSION_1_3; ++} ++static void VKAPI_CALL properties(VkPhysicalDevice physical, VkPhysicalDeviceProperties *out) ++{ ++ struct hybris_layer_physical context; ++ if (!hybris_layer_lookup_physical(physical, &context)) return; ++ PHYSICAL_PROC(GetPhysicalDeviceProperties); ++ GetPhysicalDeviceProperties(physical, out); ++ cap_properties(physical, out); ++} ++static void properties2(VkPhysicalDevice physical, VkPhysicalDeviceProperties2 *out, const char *name) ++{ ++ struct hybris_layer_physical context; ++ if (!hybris_layer_lookup_physical(physical, &context)) return; ++ PFN_vkGetPhysicalDeviceProperties2 query = (void *)context.resolver(context.instance, name); ++ query(physical, out); ++ cap_properties(physical, &out->properties); ++} ++static void VKAPI_CALL properties2_core(VkPhysicalDevice physical, VkPhysicalDeviceProperties2 *out) ++{ properties2(physical, out, "vkGetPhysicalDeviceProperties2"); } ++static void VKAPI_CALL properties2_khr(VkPhysicalDevice physical, VkPhysicalDeviceProperties2 *out) ++{ properties2(physical, out, "vkGetPhysicalDeviceProperties2KHR"); } + static int emulates(VkPhysicalDevice physical, VkFormat format) + { + return format >= VK_FORMAT_BC1_RGB_UNORM_BLOCK && format <= VK_FORMAT_BC7_SRGB_BLOCK && +@@ -109,10 +146,13 @@ int hybris_bc_extension_allowed(const char *name) + "VK_KHR_maintenance6", "VK_KHR_maintenance8", "VK_EXT_host_image_copy", + "VK_QCOM_rotated_copy_commands", "VK_EXT_device_generated_commands", + "VK_NV_device_generated_commands", "VK_NV_device_generated_commands_compute", +- "VK_NV_dedicated_allocation", "VK_NV_copy_memory_indirect" ++ "VK_NV_dedicated_allocation", "VK_NV_copy_memory_indirect", "VK_NV_per_stage_descriptor_set" + }; + for (size_t i = 0; i < sizeof(unsupported) / sizeof(unsupported[0]); ++i) +- if (!strcmp(name, unsupported[i])) return 0; ++ if (!strcmp(name, unsupported[i])) { ++ if (dxvk_profile() && !strcmp(name, "VK_KHR_maintenance6")) continue; ++ return 0; ++ } + return 1; + } + /* Extension feature queries must agree with the filtered extension list. Each +@@ -121,8 +161,12 @@ static unsigned unsupported_feature_count(VkStructureType type) + { + switch (type) { + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_FEATURES_EXT: return 4; ++ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES: ++ return dxvk_profile() ? (offsetof(VkPhysicalDeviceVulkan14Features, pushDescriptor) - ++ offsetof(VkPhysicalDeviceVulkan14Features, globalPriorityQuery)) / sizeof(VkBool32) + 1 : 0; ++ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_6_FEATURES_KHR: return dxvk_profile() ? 0 : 1; ++ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PER_STAGE_DESCRIPTOR_SET_FEATURES_NV: return 2; + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT: +- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_6_FEATURES_KHR: + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES_EXT: + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COPY_MEMORY_INDIRECT_FEATURES_NV: + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_FEATURES_NV: return 1; +@@ -252,11 +296,12 @@ static void VKAPI_CALL sparse_properties2_core(VkPhysicalDevice physical, const + static void VKAPI_CALL sparse_properties2_khr(VkPhysicalDevice physical, const VkPhysicalDeviceSparseImageFormatInfo2 *info, + uint32_t *count, VkSparseImageFormatProperties2 *out) + { sparse_properties2(physical, info, count, out, "vkGetPhysicalDeviceSparseImageFormatProperties2KHR"); } +-static int image_supported(VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags) ++static int image_supported(VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags) + { + return type == VK_IMAGE_TYPE_2D && tiling == VK_IMAGE_TILING_OPTIMAL && usage && + !(usage & ~(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) && +- !(flags & ~VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT); ++ !(flags & ~(VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT | VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) && ++ (!(flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) || hybris_bc_srgb_family(format)); + } + static VkResult VKAPI_CALL image_properties(VkPhysicalDevice physical, VkFormat format, VkImageType type, + VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties *out) +@@ -265,7 +310,7 @@ static VkResult VKAPI_CALL image_properties(VkPhysicalDevice physical, VkFormat + if (!hybris_layer_lookup_physical(physical, &context)) return VK_ERROR_INITIALIZATION_FAILED; + PHYSICAL_PROC(GetPhysicalDeviceImageFormatProperties); + if (emulates(physical, format)) { +- if (!image_supported(type, tiling, usage, flags)) { *out = (VkImageFormatProperties){0}; return VK_ERROR_FORMAT_NOT_SUPPORTED; } ++ if (!image_supported(format, type, tiling, usage, flags)) { *out = (VkImageFormatProperties){0}; return VK_ERROR_FORMAT_NOT_SUPPORTED; } + VkResult result = GetPhysicalDeviceImageFormatProperties(physical, hybris_bc_image_format(format, physical_rgb_mask(physical)), type, + tiling, usage | VK_IMAGE_USAGE_TRANSFER_DST_BIT, flags, out); + if (result == VK_SUCCESS) out->sampleCounts &= VK_SAMPLE_COUNT_1_BIT; +@@ -282,14 +327,16 @@ static VkResult image_properties2(VkPhysicalDevice physical, const VkPhysicalDev + (PFN_vkGetPhysicalDeviceImageFormatProperties2)context.resolver(context.instance, name); + if (!emulates(physical, info->format)) return query(physical, info, out); + out->imageFormatProperties = (VkImageFormatProperties){0}; +- if (!image_supported(info->type, info->tiling, info->usage, info->flags)) return VK_ERROR_FORMAT_NOT_SUPPORTED; ++ if (!image_supported(info->format, info->type, info->tiling, info->usage, info->flags)) return VK_ERROR_FORMAT_NOT_SUPPORTED; + for (const VkBaseInStructure *node = info->pNext; node; node = node->pNext) { + if (node->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO) { + if (((const VkPhysicalDeviceExternalImageFormatInfo *)node)->handleType) return VK_ERROR_FORMAT_NOT_SUPPORTED; + } else if (node->sType == VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO) { + const VkImageFormatListCreateInfo *list = (const void *)node; + for (uint32_t i = 0; i < list->viewFormatCount; ++i) +- if (list->pViewFormats[i] != info->format) return VK_ERROR_FORMAT_NOT_SUPPORTED; ++ if (!hybris_bc_view_compatible(info->format, list->pViewFormats[i]) || ++ (list->pViewFormats[i] != info->format && !(info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT))) ++ return VK_ERROR_FORMAT_NOT_SUPPORTED; + } else if (node->sType != VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_IMAGE_FORMAT_INFO_EXT) { + return VK_ERROR_FORMAT_NOT_SUPPORTED; + } +@@ -322,6 +369,9 @@ PFN_vkVoidFunction hybris_bc_policy_proc(const char *name) + if (!hybris_bc_enabled()) return NULL; + static const struct { const char *name; PFN_vkVoidFunction function; } commands[] = { + #define ENTRY(name, function) {"vk" #name, (PFN_vkVoidFunction)function} ++ ENTRY(GetPhysicalDeviceProperties, properties), ++ ENTRY(GetPhysicalDeviceProperties2, properties2_core), ++ ENTRY(GetPhysicalDeviceProperties2KHR, properties2_khr), + ENTRY(GetPhysicalDeviceQueueFamilyProperties, queue_properties), + ENTRY(GetPhysicalDeviceQueueFamilyProperties2, queue_properties2_core), + ENTRY(GetPhysicalDeviceQueueFamilyProperties2KHR, queue_properties2_khr), +diff --git a/hybris/vulkan/compat/bc_resources.c b/hybris/vulkan/compat/bc_resources.c +index 526c3f1..74cc0c9 100644 +--- a/hybris/vulkan/compat/bc_resources.c ++++ b/hybris/vulkan/compat/bc_resources.c +@@ -210,8 +210,10 @@ static VkResult VKAPI_CALL create_view(VkDevice handle, const VkImageViewCreateI + struct hybris_bc_resource *resource = hybris_bc_resource_find(device, info->image); + VkImageViewCreateInfo translated = *info; + if (resource && resource->emulated.image) { +- if (info->format != resource->format) return VK_ERROR_FORMAT_NOT_SUPPORTED; +- translated.format = resource->emulated.decoded_format; ++ unsigned bit = info->format == resource->format ? 1u : 2u; ++ if (!hybris_bc_view_compatible(resource->format, info->format) || ++ !(resource->emulated.view_mask & bit)) return VK_ERROR_FORMAT_NOT_SUPPORTED; ++ translated.format = hybris_bc_image_format(info->format, device->rgb_mask); + } + PROC(CreateImageView); + return CreateImageView(handle, &translated, allocator, view); +diff --git a/hybris/vulkan/compat/bc_transfer.c b/hybris/vulkan/compat/bc_transfer.c +index 6edb652..799fb62 100644 +--- a/hybris/vulkan/compat/bc_transfer.c ++++ b/hybris/vulkan/compat/bc_transfer.c +@@ -2,6 +2,7 @@ + #define VK_NO_PROTOTYPES + #include "bc_transfer.h" + #include <stdlib.h> ++#include <stdio.h> + #include <string.h> + + #define PROC(name) PFN_vk##name name = (PFN_vk##name)t->decoder->resolver(t->decoder->device, "vk" #name) +@@ -59,16 +60,29 @@ static VkResult scratch(struct hybris_bc_transfer *t) + if (type == t->memory->memoryTypeCount) type = i; + if (t->memory->memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { type = i; break; } + } +- if (type == t->memory->memoryTypeCount) { result = VK_ERROR_OUT_OF_DEVICE_MEMORY; goto fail; } ++ if (type == t->memory->memoryTypeCount) { ++ fprintf(stderr, "HYBRIS_BC scratch: no memory type (bits=0x%x count=%u size=%llu)\n", ++ requirements.memoryRequirements.memoryTypeBits, t->memory->memoryTypeCount, ++ (unsigned long long)requirements.memoryRequirements.size); ++ result = VK_ERROR_OUT_OF_DEVICE_MEMORY; goto fail; ++ } + VkMemoryDedicatedAllocateInfo owner = { + .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO, .buffer = buffer}; + VkMemoryAllocateInfo allocation = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .pNext = dedicated.requiresDedicatedAllocation || dedicated.prefersDedicatedAllocation ? &owner : NULL, + .allocationSize = requirements.memoryRequirements.size, .memoryTypeIndex = type}; + result = AllocateMemory(device, &allocation, NULL, &memory); +- if (result != VK_SUCCESS) goto fail; ++ if (result != VK_SUCCESS) { ++ fprintf(stderr, "HYBRIS_BC scratch allocation: result=%d size=%llu type=%u bits=0x%x\n", ++ result, (unsigned long long)allocation.allocationSize, type, requirements.memoryRequirements.memoryTypeBits); ++ goto fail; ++ } + result = BindBufferMemory(device, buffer, memory, 0); +- if (result != VK_SUCCESS) goto fail; ++ if (result != VK_SUCCESS) { ++ fprintf(stderr, "HYBRIS_BC scratch bind: result=%d size=%llu type=%u\n", ++ result, (unsigned long long)allocation.allocationSize, type); ++ goto fail; ++ } + t->scratch = buffer; + t->scratch_memory = memory; + t->scratch_size = size; +@@ -193,7 +207,7 @@ VkResult hybris_bc_decode_image(struct hybris_bc_transfer *t, + buffer_barrier(t, command, image->blocks, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); + VkResult result = decode(t, command, image, layout, region); +- if (result != VK_SUCCESS) { state->error = result; return result; } ++ if (result != VK_SUCCESS) { fprintf(stderr, "HYBRIS_BC transfer failed: %d\n", result); state->error = result; return result; } + buffer_barrier(t, command, image->blocks, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_ACCESS_SHADER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT); +diff --git a/hybris/vulkan/compat/shader_policy.c b/hybris/vulkan/compat/shader_policy.c +index a1dcf6d..21a4cc7 100644 +--- a/hybris/vulkan/compat/shader_policy.c ++++ b/hybris/vulkan/compat/shader_policy.c +@@ -92,7 +92,8 @@ static void properties2(VkPhysicalDevice physical, VkPhysicalDeviceProperties2 * + { + struct hybris_layer_physical context; + if (!hybris_layer_lookup_physical(physical, &context)) return; +- PFN_vkGetPhysicalDeviceProperties2 query = (PFN_vkGetPhysicalDeviceProperties2)context.resolver(context.instance, name); ++ PFN_vkGetPhysicalDeviceProperties2 query = (void *)hybris_bc_policy_proc(name); ++ if (!query) query = (void *)context.resolver(context.instance, name); + query(physical, out); + VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *legacy = NULL; + for (VkBaseOutStructure *node = out->pNext; node; node = node->pNext) +diff --git a/tests/baseline/probe_bc_images.c b/tests/baseline/probe_bc_images.c +index 85ba6e6..55e069c 100644 +--- a/tests/baseline/probe_bc_images.c ++++ b/tests/baseline/probe_bc_images.c +@@ -95,9 +95,10 @@ int bc_images_probe(int validate, int route) + } + free(queues); + if (family == UINT32_MAX) return 3; ++ unsigned first_format = getenv("BC_D3D_FORMATS") ? 2 : 0; + VkBool32 linear_filter[BC_IMAGE_FORMAT_COUNT] = {0}; + unsigned unsupported_formats = 0; +- for (unsigned f = 0; f < BC_IMAGE_FORMAT_COUNT; ++f) { ++ for (unsigned f = first_format; f < BC_IMAGE_FORMAT_COUNT; ++f) { + VkFormatProperties format; + p_vkGetPhysicalDeviceFormatProperties(physical, bc_formats[f], &format); + VkFormatProperties2 format2 = {.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; +@@ -164,19 +165,28 @@ int bc_images_probe(int validate, int route) + p_vkGetPhysicalDeviceFeatures2(physical, &queried); + maintenance4 = maintenance.maintenance4; + } +- synchronization.pNext = maintenance4 ? &maintenance : NULL; +- const char *device_extensions[4]; ++ int maintenance6 = getenv("BC_MAINTENANCE6") != NULL; ++ VkPhysicalDeviceMaintenance6FeaturesKHR maintenance_six = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_6_FEATURES_KHR}; ++ if (maintenance6) { ++ VkPhysicalDeviceFeatures2 q = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = &maintenance_six}; ++ p_vkGetPhysicalDeviceFeatures2(physical, &q); ++ if (!maintenance_six.maintenance6) { puts("MISSING maintenance6"); return 3; } ++ } ++ maintenance.pNext = maintenance6 ? &maintenance_six : NULL; ++ synchronization.pNext = maintenance4 ? (void *)&maintenance : maintenance6 ? (void *)&maintenance_six : NULL; ++ const char *device_extensions[5]; + uint32_t device_extension_count = 0; + if (copies2) device_extensions[device_extension_count++] = VK_KHR_COPY_COMMANDS_2_EXTENSION_NAME; + if (sync2) device_extensions[device_extension_count++] = VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME; + if (maintenance4) device_extensions[device_extension_count++] = VK_KHR_MAINTENANCE_4_EXTENSION_NAME; + if (format_list) device_extensions[device_extension_count++] = VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME; ++ if (maintenance6) device_extensions[device_extension_count++] = VK_KHR_MAINTENANCE_6_EXTENSION_NAME; + float priority = 1; + VkDeviceQueueCreateInfo qc = {.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, + .queueFamilyIndex = family, .queueCount = 1, .pQueuePriorities = &priority}; + VkDeviceCreateInfo dc = {.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, + .queueCreateInfoCount = 1, .pQueueCreateInfos = &qc, +- .pNext = sync2 ? (void *)&synchronization : maintenance4 ? (void *)&maintenance : NULL, ++ .pNext = sync2 ? (void *)&synchronization : maintenance4 ? (void *)&maintenance : maintenance6 ? (void *)&maintenance_six : NULL, + .enabledExtensionCount = device_extension_count, .ppEnabledExtensionNames = device_extensions}; + VkDebugUtilsMessengerEXT messenger = VK_NULL_HANDLE; + PFN_vkDestroyDebugUtilsMessengerEXT destroy_messenger = NULL; +@@ -307,8 +317,12 @@ int bc_images_probe(int validate, int route) + VkFenceCreateInfo fence_info = {.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO}; + VkFence fence; + CHECK(p_vkCreateFence(device, &fence_info, NULL, &fence)); ++ PFN_vkCmdBindDescriptorSets2KHR bind2 = (PFN_vkCmdBindDescriptorSets2KHR)p_vkGetDeviceProcAddr(device, "vkCmdBindDescriptorSets2KHR"); ++ PFN_vkCmdPushConstants2KHR push2 = (PFN_vkCmdPushConstants2KHR)p_vkGetDeviceProcAddr(device, "vkCmdPushConstants2KHR"); ++ if (maintenance6 && (!bind2 || !push2)) return 2; ++ printf("BC_EXTENDED maintenance6=%d mutable=%d\n", maintenance6, getenv("BC_MUTABLE") != NULL); + unsigned failures = 0, readbacks = 0, copies2_cases = 0, sync2_cases = 0; +- for (unsigned f = 0; f < BC_IMAGE_FORMAT_COUNT; ++f) { ++ for (unsigned f = first_format; f < BC_IMAGE_FORMAT_COUNT; ++f) { + for (unsigned shape_index = 0; shape_index < 2; ++shape_index) { + uint32_t base_width = shape_index ? 32 : 9, base_height = shape_index ? 32 : 7; + for (uint32_t mip = 0; mip < 4; ++mip) { +@@ -337,6 +351,13 @@ int bc_images_probe(int validate, int route) + (i != 2 ? VK_IMAGE_USAGE_SAMPLED_BIT : 0), .sharingMode = VK_SHARING_MODE_EXCLUSIVE}; + VkImageFormatListCreateInfo formats = {.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO, + .viewFormatCount = 1, .pViewFormats = &image_info.format}; ++ VkFormat paired[2] = {bc_formats[f], bc_formats[f ^ 1]}; ++ if (getenv("BC_MUTABLE") && (f < 8 || (f >= 12 && f < 14)) && i < 2) { ++ image_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; ++ image_info.format = paired[1]; ++ formats.viewFormatCount = 2; ++ formats.pViewFormats = paired; ++ } + if (format_list) image_info.pNext = &formats; + VkMemoryRequirements2 described = {.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2}; + if (maintenance4) { +@@ -414,9 +435,19 @@ int bc_images_probe(int validate, int route) + VkCommandBufferBeginInfo begin = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; + CHECK(p_vkBeginCommandBuffer(command, &begin)); + p_vkCmdBindPipeline(command, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); +- p_vkCmdBindDescriptorSets(command, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout, 0, 1, &descriptors, 1, &dynamic_offset); ++ if (maintenance6) { ++ VkBindDescriptorSetsInfoKHR bind = {.sType = VK_STRUCTURE_TYPE_BIND_DESCRIPTOR_SETS_INFO_KHR, ++ .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, .layout = pipeline_layout, ++ .descriptorSetCount = 1, .pDescriptorSets = &descriptors, ++ .dynamicOffsetCount = 1, .pDynamicOffsets = &dynamic_offset}; ++ bind2(command, &bind); ++ } else p_vkCmdBindDescriptorSets(command, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout, 0, 1, &descriptors, 1, &dynamic_offset); + uint32_t shape[] = {width, height, LAYERS, f >= 14 ? 3 : f >= 8 && f < 12 ? 1 + (f & 1) : 0, linear_filter[f] != 0}; +- p_vkCmdPushConstants(command, pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(shape), shape); ++ if (maintenance6) { ++ VkPushConstantsInfoKHR push = {.sType = VK_STRUCTURE_TYPE_PUSH_CONSTANTS_INFO_KHR, ++ .layout = pipeline_layout, .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, .size = sizeof(shape), .pValues = shape}; ++ push2(command, &push); ++ } else p_vkCmdPushConstants(command, pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(shape), shape); + VkMemoryBarrier before = {.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT}; +@@ -614,7 +645,7 @@ int bc_images_probe(int validate, int route) + p_vkDestroyDevice(device, NULL); + if (destroy_messenger) destroy_messenger(instance, messenger, NULL); + p_vkDestroyInstance(instance, NULL); dlclose(h); +- printf("BC_IMAGES_SUMMARY formats=16 shapes=2 readbacks=%u copy2_cases=%u sync2_cases=%u maintenance4=%u format_list=%u failures=%u validation_errors=%u route=%d\n", +- readbacks, copies2_cases, sync2_cases, maintenance4, format_list, failures, validation.errors, route); +- return failures || validation.errors || readbacks != BC_IMAGE_FORMAT_COUNT * 2 * 4 * 3 ? 2 : 0; ++ printf("BC_IMAGES_SUMMARY formats=%u shapes=2 readbacks=%u copy2_cases=%u sync2_cases=%u maintenance4=%u format_list=%u failures=%u validation_errors=%u route=%d\n", ++ (unsigned)BC_IMAGE_FORMAT_COUNT - first_format, readbacks, copies2_cases, sync2_cases, maintenance4, format_list, failures, validation.errors, route); ++ return failures || validation.errors || readbacks != (BC_IMAGE_FORMAT_COUNT - first_format) * 2 * 4 * 3 ? 2 : 0; + } diff --git a/tools/hybris/powervr-hal-version.patch b/tools/hybris/powervr-hal-version.patch new file mode 100644 index 0000000000..63b72c7599 --- /dev/null +++ b/tools/hybris/powervr-hal-version.patch @@ -0,0 +1,12 @@ +--- a/hybris/vulkan/icd/icd.c ++++ b/hybris/vulkan/icd/icd.c +@@ -71,7 +71,8 @@ + int result = module->methods->open(module, HWVULKAN_DEVICE_0, + (hw_device_t **)&candidate); + if (result || !candidate || candidate->common.tag != HARDWARE_DEVICE_TAG || +- candidate->common.version != HWVULKAN_DEVICE_API_VERSION_0_1 || ++ (candidate->common.version != HWVULKAN_DEVICE_API_VERSION_0_1 && ++ candidate->common.version != HARDWARE_DEVICE_API_VERSION(0, 1)) || + !candidate->CreateInstance || !candidate->GetInstanceProcAddr || + !candidate->EnumerateInstanceExtensionProperties) { + fprintf(stderr, "hybris ICD: incompatible Vulkan HAL device (open=%d)\n", result); diff --git a/tools/hybris/run-proton.py b/tools/hybris/run-proton.py new file mode 100644 index 0000000000..c8c1b0eb46 --- /dev/null +++ b/tools/hybris/run-proton.py @@ -0,0 +1,89 @@ +#!/usr/bin/python3 +"""Select a staged DXVK payload for one DroidDeck Proton game launch. + +Place this script beside dxvk/x32/ and dxvk/x64/, then select its absolute +path with DROIDDECK_PROTON_WRAPPER in the game's environment settings. +Run `python3 run-proton.py --check /path/to/proton` to check the payload and +Proton source layout without starting Proton or changing a game prefix. + +This wrapper does not install the graphics runtime, select Vulkan layers, +change synchronization settings, or provide game-specific workarounds. +""" + +import argparse +import os +from pathlib import Path +import sys + + +DLL_NAMES = ("d3d8.dll", "d3d9.dll", "d3d10core.dll", "d3d11.dll", "dxgi.dll") +PREFIX_MARKER = "droiddeck-dxvk-profile-v1" + + +def prepare(proton, dxvk): + """Validate all inputs and compile an in-memory copy of the Proton script.""" + for architecture in ("x32", "x64"): + for name in DLL_NAMES: + dll = dxvk / architecture / name + if not dll.is_file(): + raise ValueError(f"missing DXVK file: {dll}") + with dll.open("rb") as stream: + if not stream.read(1): + raise ValueError(f"empty DXVK file: {dll}") + + source = proton.read_text(encoding="utf-8") + for is32, architecture in (("False", "x64"), ("True", "x32")): + needle = f'g_proton.arch_pe_dir("wine/dxvk", {is32}) + f + ".dll"' + if source.count(needle) != 1: + raise ValueError(f"unsupported Proton layout: expected one {architecture} DXVK copy expression") + directory = str(dxvk / architecture) + "/" + source = source.replace(needle, repr(directory) + ' + f + ".dll"', 1) + + needle = " # check whether any prefix config has changed" + if source.count(needle) != 1: + raise ValueError("unsupported Proton layout: expected one prefix configuration marker") + # The supported Proton copies DXVK DLLs on every launch. This marker records + # profile activation; it does not need changing whenever the payload changes. + marker = repr("\n" + PREFIX_MARKER) + source = source.replace(needle, f" prefix_info += {marker}\n" + needle, 1) + return compile(source, str(proton), "exec") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--check", action="store_true", help="validate inputs without running Proton") + parser.add_argument("proton", help="selected Proton Python script") + parser.add_argument("proton_args", nargs=argparse.REMAINDER) + args = parser.parse_args() + if not args.check and (len(args.proton_args) < 2 or args.proton_args[0] != "waitforexitandrun"): + parser.error("expected: PROTON waitforexitandrun GAME [ARGUMENTS...]") + + proton = Path(args.proton) + # A sibling payload directory by name (dxvk-2.6.2 for Xclipse); never a path. + name = os.environ.get("DROIDDECK_HYBRIS_DXVK") or "dxvk" + if not name.startswith("dxvk") or "/" in name or name.startswith("."): + print(f"DroidDeck DXVK profile: invalid payload name {name!r}", file=sys.stderr) + return 1 + dxvk = Path(__file__).resolve().parent / name + try: + code = prepare(proton, dxvk) + except (OSError, ValueError, SyntaxError) as error: + print(f"DroidDeck DXVK profile: {error}", file=sys.stderr) + return 1 + + if args.check: + print(f"DroidDeck DXVK profile: payload present and Proton layout supported ({dxvk})") + return 0 + + print(f"DROIDDECK_GRAPHICS profile={PREFIX_MARKER} dxvk={dxvk}", flush=True) + # Preserve the selected Proton path, including symlinks, and its arguments. + # Proton uses argv[0] and sibling Python imports to locate its own depot. + sys.argv = [args.proton, *args.proton_args] + sys.path.insert(0, str(proton.absolute().parent)) + exec(code, {"__name__": "__main__", "__file__": args.proton, + "__package__": None, "__spec__": None}) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/hybris/source.env b/tools/hybris/source.env new file mode 100644 index 0000000000..30dd70e1cf --- /dev/null +++ b/tools/hybris/source.env @@ -0,0 +1,2 @@ +HYBRIS_REVISION=bc8cb3586b79d208fd21b925fa0209b3e432e008 +PROTOCOL_REVISION=c6ae3c22a804da3cda017f4c8eaa6c6a3da55457 diff --git a/tools/linuxfs/check-preloads.sh b/tools/linuxfs/check-preloads.sh index 30f94a96a6..bc7ca42ca4 100644 --- a/tools/linuxfs/check-preloads.sh +++ b/tools/linuxfs/check-preloads.sh @@ -26,5 +26,10 @@ SSBS=$(syms "$D/libssbs.so") for sym in sigaction signal bsd_signal sysv_signal; do grep -qx "$sym" <<<"$SSBS" || { echo "::error::libssbs.so does not export $sym"; exit 1; } done +XCLIPSE=$(syms "$D/usr/local/lib/droiddeck-xclipse/libVkLayer_droiddeck_xclipse.so") +for sym in vkNegotiateLoaderLayerInterfaceVersion vkGetInstanceProcAddr vkGetDeviceProcAddr; do + grep -qx "$sym" <<<"$XCLIPSE" || { echo "::error::the Xclipse layer does not export $sym"; exit 1; } +done +test -f "$D/usr/local/lib/droiddeck-xclipse/VkLayer_droiddeck_xclipse.json" test -f "$D/usr/local/bin/droiddeck-session" test -f "$D/usr/local/bin/droiddeck-proton-extra" diff --git a/tools/linuxfs/desktop/droiddeck-gpu b/tools/linuxfs/desktop/droiddeck-gpu index 886f0d0a0e..012cd30625 100644 --- a/tools/linuxfs/desktop/droiddeck-gpu +++ b/tools/linuxfs/desktop/droiddeck-gpu @@ -6,13 +6,18 @@ if [ -n "${BL_DEBUG_DIR:-}" ]; then fi width=${BL_WIDTH:-1280} height=${BL_HEIGHT:-720} +backend=${BL_GAMESCOPE_BACKEND:-wayland} +case "$backend" in + wayland|sdl) ;; + *) echo "== unsupported gamescope backend: $backend" >&2; exit 64 ;; +esac window=0 -if [ "${BL_DESKTOP_GPU_WINDOW:-1}" != 0 ] && [ -n "${WAYLAND_DISPLAY:-}" ] && [ "$WAYLAND_DISPLAY" != wayland-0 ]; then +if [ "$backend" = wayland ] && [ "${BL_DESKTOP_GPU_WINDOW:-1}" != 0 ] && [ -n "${WAYLAND_DISPLAY:-}" ] && [ "$WAYLAND_DISPLAY" != wayland-0 ]; then window=1 parent=$WAYLAND_DISPLAY args=(--backend sdl --expose-wayland --follow-game-window-mode -W "$width" -H "$height" -w "$width" -h "$height") else - args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height") + args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height") fi if [ "${BL_FPS:-0}" -gt 0 ]; then args+=(-r "$BL_FPS") @@ -27,6 +32,7 @@ else export WAYLAND_DISPLAY=wayland-0 fi export GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb SDL_VIDEODRIVER=x11 +[ "$backend" = sdl ] && export SDL_VIDEODRIVER=wayland unset LIBGL_ALWAYS_SOFTWARE QT_QUICK_BACKEND KWIN_COMPOSE wsi=",${MESA_VK_WSI_DEBUG:-}," while [[ $wsi == *,sw,* ]]; do wsi=${wsi//,sw,/,}; done @@ -40,7 +46,7 @@ if [ "$window" = 1 ]; then export BL_GPU_CHILD_WSI=${MESA_VK_WSI_DEBUG:-} SDL_VIDEODRIVER=wayland MESA_VK_WSI_DEBUG=sw gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@" else - gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@" + gamescope "${args[@]}" -- env SDL_VIDEODRIVER=x11 /usr/local/bin/droiddeck-gpu-window "$@" fi rc=$? echo "== droiddeck-gpu $(date -u +%H:%M:%S): exited $rc" diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index a9dab23a7e..9fb3c39c66 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -524,6 +524,15 @@ def apply_config(env, config, app_id, fixes=None): if dxvk: own = result.get("DXVK_CONFIG", "").strip().rstrip(";").strip() result["DXVK_CONFIG"] = own + "; " + dxvk if own else dxvk + # An open driver pair (PanVK, RADV) on a GPU that is not an Adreno: vkd3d-proton reports the + # driver's own feature level and shader model. The app-wide 12_2 / 6_9 over-promised what PanVK + # has, and an Unreal DX12 game took paths that crashed. A game's own setting still wins. + if env.get("BL_OPEN_DRIVER") == "1": + game = config.get("games", {}).get(app_id, {}) or {} + for name in ("VKD3D_FEATURE_LEVEL", "VKD3D_SHADER_MODEL"): + if name not in game and name in result: + result.pop(name) + result["DROIDDECK_VKD3D_CAPS"] = "driver" return result @@ -995,6 +1004,7 @@ def diagnostic_game_exit(app_id, raw_code, source=None, wrapper_status=None): def start(launch, launch_env, digest, after=None, diagnostic_app_id=None): if len(launch) > 1 and launch[1] == "waitforexitandrun": ubisoft_composition_off(launch[0], launch_env) + launch, launch_env = system_graphics_launch(launch, launch_env) if after or diagnostic_app_id is not None: process = subprocess.Popen(launch, env=launch_env) if diagnostic_app_id is not None: @@ -1022,6 +1032,110 @@ def start(launch, launch_env, digest, after=None, diagnostic_app_id=None): return os.execvpe(launch[0], launch, launch_env) +class SystemGraphicsError(ValueError): + pass + + +def system_graphics_launch(command, env): + """Use the APK's PowerVR compatibility files only for actual Proton game launches.""" + runtime = env.get("DROIDDECK_POWERVR_RUNTIME") + if not runtime or not game_id(env) or len(command) < 3 or command[1] != "waitforexitandrun": + return command, env + directory = Path(runtime) + if not directory.is_absolute(): + raise SystemGraphicsError("system Vulkan runtime path is not absolute") + # run-proton.py picks the same payload by name; Xclipse needs a DXVK within 128 bytes of push data. + payload = env.get("DROIDDECK_HYBRIS_DXVK") or "dxvk" + if not payload.startswith("dxvk") or "/" in payload: + raise SystemGraphicsError("invalid DXVK payload name: %s" % payload) + required = ( + "run-proton.py", "wsi/libVkLayer_window_system_integration.so", + "wsi/VkLayer_window_system_integration.json", "lib/libVkLayer_hybris_compat.so", + *("%s/%s/%s.dll" % (payload, arch, name) for arch in ("x32", "x64") + for name in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi")), + ) + try: + for name in required: + path = directory / name + if not path.is_file() or not path.stat().st_size: + raise SystemGraphicsError("missing system Vulkan component: %s" % name) + wrapper = directory / "run-proton.py" + if not os.access(wrapper, os.X_OK): + raise SystemGraphicsError("system Vulkan Proton wrapper is not executable") + except OSError as error: + raise SystemGraphicsError("system Vulkan component is unreadable: %s" % error) from error + result = dict(env) + layers = "VK_LAYER_window_system_integration:" + env.get("DROIDDECK_HYBRIS_LAYERS", "VK_LAYER_HYBRIS_compat") + result.update({ + "HYBRIS_BC_TEXTURES": "dxvk", + "VK_LAYER_PATH": ":".join(filter(None, (str(directory / "wsi"), str(directory / "lib"), + env.get("DROIDDECK_HYBRIS_LAYER_PATH")))), + "VK_INSTANCE_LAYERS": layers, + "ENABLE_GAMESCOPE_WSI": "0", + "VK_LOADER_LAYERS_DISABLE": "*gamescope*", + "DISABLE_VK_LAYER_VALVE_steam_fossilize_1": "1", + }) + for name in ("DISABLE_WSI_LAYER", "PROTON_USE_WINED3D", "ENABLE_VK_LAYER_VALVE_steam_fossilize_1"): + result.pop(name, None) + return [str(wrapper), *command], result + + +def game_logs(command, env, app_id, now=None): + """Detailed graphics logs for one game launch, in the session's log folder: Proton's own log, + DXVK's and vkd3d-proton's, and the Vulkan driver's startup messages. The app turns this on + (BL_GAME_LOGS=1) on a GPU that is not an Adreno, or with Setup's "Detailed graphics logs".""" + if env.get("BL_GAME_LOGS") != "1" or not env.get("BL_DEBUG_DIR") or len(command) < 3 \ + or command[1] != "waitforexitandrun": + return env + import time + stamp = time.strftime("%Y%m%d-%H%M%S", time.localtime(now)) + name = app_id or re.sub(r"[^A-Za-z0-9._-]+", "_", Path(command[2]).stem)[:40] or "game" + parent = Path(env["BL_DEBUG_DIR"]) / "games" + try: + parent.mkdir(parents=True, exist_ok=True) + folder = Path(tempfile.mkdtemp(prefix=stamp + "-", suffix="-" + name, dir=parent)) + except OSError as error: + print("droiddeck-game-env: no game log folder (%s)" % error, file=sys.stderr) + return env + result = dict(env) + result.update({ + "PROTON_LOG": "1", + "PROTON_LOG_DIR": str(folder), + "DXVK_LOG_PATH": str(folder), + "DXVK_LOG_LEVEL": env.get("DXVK_LOG_LEVEL", "info"), + "VKD3D_LOG_FILE": str(folder / "vkd3d.log"), + "VKD3D_DEBUG": env.get("VKD3D_DEBUG", "warn"), + "VKD3D_SHADER_DEBUG": env.get("VKD3D_SHADER_DEBUG", "none"), + "MESA_LOG_FILE": str(folder / "mesa.log"), + "PANVK_DEBUG": env.get("PANVK_DEBUG", "startup"), + }) + try: + (folder / "launch.txt").write_text("\n".join([ + "app: %s" % (app_id or "-"), + "exe: %s" % command[2], + "proton: %s" % command[0], + "started: %s" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now)), + ] + ["%s=%s" % (key, env[key]) for key in sorted(env) + if key.startswith(("VK_", "BL_VK", "BL_DRM", "BL_OPEN", "MESA_", "PANVK", "DXVK_", "VKD3D", "ZINK", "TU_", "DROIDDECK_VKD3D"))]) + "\n") + except OSError: + pass + # Whether the game's sound reaches PulseAudio: the streams 20 s and 60 s in, without waiting. + try: + subprocess.Popen(["sh", "-c", 'for t in 20 40; do sleep $t; { echo "== $(date +%T)"; ' + 'pactl list sink-inputs 2>&1 | head -80; } >> "$1/audio-streams.txt"; done', "audio", str(folder)], + stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + start_new_session=True) + except OSError: + pass + return result + + +def exec_proton(command, env): + # Synchronization selection has already picked the actual Proton executable. + command, env = system_graphics_launch(command, env) + os.execvpe(command[0], command, env) + + def main(): command = sys.argv[1:] if not command: @@ -1089,6 +1203,7 @@ def main(): print("droiddeck-game-env: OpenGL does not wait for the screen refresh (vblank_mode=0)", file=sys.stderr) if app_id and len(command) > 1 and command[1] == "waitforexitandrun": command = offline_without_anticheat(command, env) + env = game_logs(command, env, app_id) if mic_enabled == "0": env["AUDIO_DIRECT_MIC"] = "0" env = directaudio_settings(env) @@ -1165,4 +1280,8 @@ def main(): if __name__ == "__main__": - sys.exit(main()) + try: + sys.exit(main()) + except SystemGraphicsError as error: + print("droiddeck-game-env: PowerVR graphics runtime unavailable (%s)" % error, file=sys.stderr) + sys.exit(1) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 3edc114c8f..b8137ddc14 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -1,5 +1,15 @@ #!/bin/bash set -u +# A GPU that is not an Adreno (BL_RAISE_NOFILE=1): the open-files limit goes up to the hard limit +# for the whole session tree (gamescope, Steam, games). A Mali PanVK session ran out after ten +# minutes ("Too many open files" importing sync files and dma-bufs) and froze. +if [ "${BL_RAISE_NOFILE:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ]; then + bl_nofile_was="$(ulimit -Sn)/$(ulimit -Hn)" + ulimit -Sn "$(ulimit -Hn)" 2>/dev/null || true + echo "== open files: soft/hard $bl_nofile_was -> soft $(ulimit -Sn)" + [ -n "${BL_DEBUG_DIR:-}" ] && echo "soft/hard $bl_nofile_was -> soft $(ulimit -Sn) (session tree)" > "$BL_DEBUG_DIR/limits.txt" 2>/dev/null + unset bl_nofile_was +fi export HOME=${HOME:-/root} mode=${1:-desktop} shift || true @@ -260,18 +270,78 @@ if [ "${BL_VKBRIDGE:-0}" = 1 ]; then unset TU_DEBUG if [ -z "${BL_INSIDE:-}" ]; then step "vkbridge self-test" - timeout 60 /usr/local/bin/droiddeck-vkbridge-smoke 2>&1 | sed 's/^/== vkbridge: /' + bl_vkb_smoke=$(timeout 60 /usr/local/bin/droiddeck-vkbridge-smoke 2>&1) + printf '%s\n' "$bl_vkb_smoke" | sed 's/^/== vkbridge: /' + bl_vkb_why= + if printf '%s\n' "$bl_vkb_smoke" | grep -qE '^FAIL memory sharing'; then + bl_vkb_why=memory + elif printf '%s\n' "$bl_vkb_smoke" | grep -qE '^FAIL (image clear|draw)'; then + bl_vkb_why=draw + fi + if [ -n "$bl_vkb_why" ] && [ -r "${BL_VKBRIDGE_FALLBACK_ICD:-}" ]; then + export VK_DRIVER_FILES=$BL_VKBRIDGE_FALLBACK_ICD VK_ICD_FILENAMES=$BL_VKBRIDGE_FALLBACK_ICD BL_VKBRIDGE=0 + export BL_OPEN_DRIVER=1 BL_DRM_STANDIN=/dev/mali0 + [ "${BL_STEAM_GPU_COMPOSITING:-0}" = 1 ] || export BL_STEAM_SOFT_COMPOSITING=1 + if [ "$bl_vkb_why" = memory ]; then + echo "== vkbridge: memory sharing = none (no method passed the server's self-test); this session uses the PanVK pair instead ($BL_VKBRIDGE_FALLBACK_ICD)" + else + echo "== vkbridge: self-test failed images or draws; this session uses the PanVK pair instead ($BL_VKBRIDGE_FALLBACK_ICD)" + fi + [ -n "${BL_DEBUG_DIR:-}" ] && printf '%s\n%s\n' "$BL_VKBRIDGE_FALLBACK_ICD" "$bl_vkb_why" > "$BL_DEBUG_DIR/vkbridge-fallback" 2>/dev/null + elif [ -n "$bl_vkb_why" ]; then + echo "== vkbridge: self-test failed ($bl_vkb_why) and no PanVK pair is installed to fall back on; expect a black screen or a lost device - set a Mali driver pair in Setup" + fi + unset bl_vkb_why + unset bl_vkb_smoke if command -v vulkaninfo >/dev/null 2>&1; then timeout 30 vulkaninfo --summary 2>&1 | sed -n '/^Devices:/,$p' | head -40 | sed 's/^/== vulkaninfo: /' fi fi - echo "== vulkan driver: Mali bridge ($bl_vkb_icd, server at $VKBRIDGE_SOCKET)" + [ "${BL_VKBRIDGE:-0}" = 1 ] && echo "== vulkan driver: Mali bridge ($bl_vkb_icd, server at $VKBRIDGE_SOCKET)" else echo "== vulkan driver: Mali bridge requested but NOT usable (icd $bl_vkb_icd, socket ${VKBRIDGE_SOCKET:-unset}; missing:$bl_vkb_missing)" [ -n "${BL_INSIDE:-}" ] || exit 69 fi unset bl_vkb_icd bl_vkb_missing fi +if [ "${BL_VENUS:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ] && command -v vulkaninfo >/dev/null 2>&1; then + if bl_vn_info=$(timeout 30 vulkaninfo 2>/dev/null); then + case $(printf '%s\n' "$bl_vn_info" | grep -m1 'nullDescriptor') in + *true*) echo "== venus: nullDescriptor present (Zink keeps the GPU)" ;; + *) + export GALLIUM_DRIVER=llvmpipe LIBGL_ALWAYS_SOFTWARE=1 + unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2 + echo "== venus: no nullDescriptor on this device even with the Mali compatibility layer; Steam's GL and Xwayland use llvmpipe (software)" + ;; + esac + else + echo "== venus: vulkaninfo failed or timed out; GL left on Zink" + fi + unset bl_vn_info +fi +if [ "${BL_GAME_LOGS:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ] && [ -n "${BL_DEBUG_DIR:-}" ]; then + ( + { + echo "== VK_DRIVER_FILES=${VK_DRIVER_FILES:-} VK_ICD_FILENAMES=${VK_ICD_FILENAMES:-} BL_DRM_STANDIN=${BL_DRM_STANDIN:-}" + if command -v vulkaninfo >/dev/null 2>&1; then + timeout 10 vulkaninfo --summary + echo "== vulkaninfo exit: $?" + if timeout 20 vulkaninfo > "$BL_DEBUG_DIR/vulkan-full.txt" 2>&1; then + echo "== device extensions (full list in vulkan-full.txt):" + sed -n '/^Device Extensions:/,/^$/p' "$BL_DEBUG_DIR/vulkan-full.txt" | grep -o 'VK_[A-Za-z0-9_]*' | sort -u | tr '\n' ' ' | fold -s -w 200 + echo + echo "== key features:" + grep -E '^[[:space:]]+(robustBufferAccess2?|robustImageAccess2?|nullDescriptor|logicOp|fillModeNonSolid|shaderClipDistance|shaderCullDistance|dualSrcBlend|geometryShader|scalarBlockLayout|timelineSemaphore|dynamicRendering|synchronization2|maintenance4|maintenance5|maintenance6|shaderDrawParameters|descriptorIndexing|bufferDeviceAddress|vulkanMemoryModel|hostQueryReset|imagelessFramebuffer|samplerYcbcrConversion|shaderInt64|shaderFloat64|shaderInt16|shaderFloat16|storageBuffer16BitAccess|extendedDynamicState[23]?|vertexInputDynamicState|customBorderColors|customBorderColorWithoutFormat|depthClipEnable|multiViewport|textureCompressionBC|indexTypeUint8|rectangularLines|bresenhamLines|transformFeedback|geometryStreams|graphicsPipelineLibrary|pushDescriptor|primitiveTopologyListRestart|dynamicRenderingLocalRead|shaderDemoteToHelperInvocation|subgroupSizeControl|computeFullSubgroups|inlineUniformBlock|pipelineCreationCacheControl) = ' "$BL_DEBUG_DIR/vulkan-full.txt" | sed 's/^[[:space:]]*/ /' | sort -u + else + echo "== full vulkaninfo failed or timed out (exit $?)" + fi + else + echo "== vulkaninfo is not in this runtime; GPU nodes:" + ls -l /dev/kgsl-3d0 /dev/mali0 /dev/dri 2>&1 + fi + } > "$BL_DEBUG_DIR/vulkan-summary.txt" 2>&1 + ) & +fi export GAMESCOPE_FORCE_VULKAN_REALTIME=${BL_GAMESCOPE_REALTIME:-0} start_agent() { @@ -283,6 +353,38 @@ nap() { [ -n "${bl_nap_fd:-}" ] || exec {bl_nap_fd}<> <(:) read -r -t "$1" -u "$bl_nap_fd" _ 2>/dev/null || : } +# Which program a driver error came from: Mesa's lines ("radv/amdgpu: The CS has been rejected", +# "ZINK: vkQueueWaitIdle failed") carry no process name. For the first three minutes of an open +# driver pair's session, every process that appears goes into processes.txt with the session log's +# line count at that moment, so an error's line number in session.log points at what had just +# started. Pure bash over /proc (no execs: see nap). +watch_processes() { + local out=$BL_DEBUG_DIR/processes.txt log=$BL_DEBUG_DIR/session.log i p pid comm lines + local -a argv new + local -A seen=() + echo "# seconds session.log-lines pid name command line" > "$out" 2>/dev/null || return 0 + for ((i = 0; i < 360; i++)); do + new=() + for p in /proc/[0-9]*; do + pid=${p#/proc/} + [ -n "${seen[$pid]:-}" ] && continue + seen[$pid]=1 + read -r comm < "$p/comm" 2>/dev/null || continue + argv=() + mapfile -d '' -t argv < "$p/cmdline" 2>/dev/null + new+=("$pid"$'\t'"$comm"$'\t'"${argv[*]:0:8}") + done + if [ ${#new[@]} -gt 0 ]; then + lines=0 + [ -r "$log" ] && { mapfile -t argv < "$log"; lines=${#argv[@]}; argv=(); } + for p in "${new[@]}"; do printf '%s\t%s\t%.200s\n' "$SECONDS" "$lines" "$p"; done >> "$out" + fi + nap 0.5 + done +} +if [ "${BL_OPEN_DRIVER:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ] && [ -n "${BL_DEBUG_DIR:-}" ]; then + watch_processes & +fi export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config} export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache} @@ -400,6 +502,12 @@ if [ -z "${BL_INSIDE:-}" ]; then echo "== gamescope: games at ${nested}x${nested_h} stretched to the ${width}x${height} output" fi fi + backend=${BL_GAMESCOPE_BACKEND:-wayland} + case "$backend" in + wayland) ;; + sdl) export SDL_VIDEODRIVER=wayland ;; + *) echo "== unsupported gamescope backend: $backend"; exit 64 ;; + esac if [ "$mode" = steam ] && [ "${BL_CURSOR_COMPOSITE:-0}" = 1 ]; then export gamescope_cursor_composite=2 fi @@ -410,7 +518,7 @@ if [ -z "${BL_INSIDE:-}" ]; then export gamescope_composite_force=1 echo "== gamescope: composites every frame (Mali bridge: the Steam UI flickers on separate planes)" fi - args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h") + args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h") if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then args+=(-S stretch) export BL_STRETCHED=1 @@ -1145,6 +1253,20 @@ case $mode in export STEAM_STEAMRT_RECURSION_GUARD=1 export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} export SDL_VIDEO_X11_DGAMOUSE=0 + bl_steam_path=$PATH + bl_steam_angle=vulkan + bl_steam_presentation=() + if [ "${BL_STEAM_GL_PRESENT:-}" = 1 ]; then + bl_steam_path="/usr/local/libexec/droiddeck-steam:$PATH" + export DISABLE_GAMESCOPE_WSI=1 LIBGL_KOPPER_DISABLE=true + bl_steam_angle=gl + bl_steam_presentation=(-cef-disable-gpu-compositing) + echo "== steam: system PowerVR uses OpenGL/DRI3 through Zink with software CEF compositing" + elif [ "${BL_STEAM_SOFT_COMPOSITING:-}" = 1 ]; then + bl_steam_presentation=(-cef-disable-gpu-compositing) + echo "== steam: open driver pair - software CEF compositing, GPU raster" + fi + _bl_cef=(-cef-force-gpu "${bl_steam_presentation[@]}" -cef-use-gl=angle "-cef-use-angle=$bl_steam_angle") decky_loader=$HOME/homebrew/services/PluginLoader if [ -f "$HOME/.droiddeck-decky-enabled" ] && [ -x "$decky_loader" ]; then decky_arch=$(cat "$HOME/homebrew/services/.droiddeck-decky-arch" 2>/dev/null || echo unknown) @@ -1194,7 +1316,9 @@ case $mode in fi _bl_ui=(-gamepadui) [ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=() - _bl_cef=(-cef-force-gpu -cef-use-gl=angle -cef-use-angle=vulkan) + # bl_steam_angle / bl_steam_presentation (set above) default to the Adreno values (vulkan, + # none); only the system-PowerVR path (BL_STEAM_GL_PRESENT=1) changes them. + _bl_cef=(-cef-force-gpu "${bl_steam_presentation[@]}" -cef-use-gl=angle "-cef-use-angle=${bl_steam_angle:-vulkan}") [ "${steam_cef_gpu:-1}" = 1 ] || _bl_cef=(-cef-disable-gpu) if [ "${BL_DESKTOP:-}" = 1 ] && [ "${BL_STEAM_UI:-}" = desktop ]; then _bl_cef=(-cef-disable-gpu) @@ -1547,6 +1671,36 @@ case $mode in done ) & stop_watcher=$! + if [ "${BL_VENUS:-0}" = 1 ] && [ -x /usr/local/bin/droiddeck-glprobe ] && [ "${GALLIUM_DRIVER:-}" = zink ]; then + LIBGL_DEBUG=verbose MESA_LOG_LEVEL=debug timeout 20 /usr/local/bin/droiddeck-glprobe 2>&1 | grep -v drirc | head -60 | sed 's/^/== glprobe: /' + if [ "${PIPESTATUS[0]}" = 1 ]; then + VK_LOADER_DEBUG=error,warn timeout 20 /usr/local/bin/droiddeck-glprobe 2>&1 | grep -v drirc | head -40 | sed 's/^/== glprobe (loader): /' + DROIDDECK_MALI_COMPAT_TRACE=1 MESA_DEBUG=1 MESA_LOG_LEVEL=debug LIBGL_DEBUG=verbose ZINK_DEBUG=mem VN_DEBUG=init,result,log_ctx_info \ + timeout 30 /usr/local/bin/droiddeck-glprobe > "${BL_DEBUG_DIR:-/tmp}/glprobe-trace.txt" 2>&1 + grep -v drirc "${BL_DEBUG_DIR:-/tmp}/glprobe-trace.txt" | head -120 | sed 's/^/== glprobe (trace): /' + echo "== glprobe (trace): last pre-device query before Zink gave up: $(grep 'droiddeck-mali-compat: trace:' "${BL_DEBUG_DIR:-/tmp}/glprobe-trace.txt" | grep -v 'trace: extensions:' | tail -1)" + command -v vulkaninfo >/dev/null 2>&1 && DROIDDECK_MALI_COMPAT_TRACE=1 timeout 20 vulkaninfo --summary 2>&1 | head -40 | sed 's/^/== glprobe (vulkaninfo): /' + bl_gl_ok= + for bl_variant in "ZINK_DEBUG=" "ZINK_DEBUG= ZINK_DESCRIPTORS=auto" "ZINK_DEBUG= LIBGL_KOPPER_DISABLE=true" "ZINK_DEBUG= DROIDDECK_MALI_COMPAT=0"; do + if env $bl_variant timeout 20 /usr/local/bin/droiddeck-glprobe 2>&1 | grep -v drirc | head -20 | sed "s/^/== glprobe ($bl_variant): /"; [ "${PIPESTATUS[0]}" = 0 ]; then + bl_gl_ok=$bl_variant + break + fi + done + if [ -n "$bl_gl_ok" ] && [ "$bl_gl_ok" != "ZINK_DEBUG= DROIDDECK_MALI_COMPAT=0" ]; then + for bl_kv in $bl_gl_ok; do + case $bl_kv in *=) unset "${bl_kv%=}" ;; *) export "$bl_kv" ;; esac + done + echo "== venus: GL through Zink starts with: $bl_gl_ok (the Steam client gets that)" + else + [ -n "$bl_gl_ok" ] && echo "== venus: Zink starts only without the Mali compatibility layer (then without nullDescriptor); not used" + export GALLIUM_DRIVER=llvmpipe LIBGL_ALWAYS_SOFTWARE=1 + unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2 + echo "== venus: GL through Zink did not start (see glprobe above); the Steam client's GL uses llvmpipe (software)" + fi + unset bl_gl_ok bl_variant bl_kv + fi + fi rm -f "$HOME/.bl-restart-game" "$HOME/.bl-restarted-for" while :; do rm -f "$HOME/.bl-restart-once" "$HOME/.bl-restart-lost" @@ -1572,6 +1726,8 @@ case $mode in desktop_ui_pid=$! fi steam_started=$SECONDS + PATH="$bl_steam_path" \ + BL_STEAM_WEBHELPER="$steam_root/steamrtarm64/steamwebhelper" \ "${steam_client[@]}" "${_bl_ui[@]}" "${_bl_cdp[@]}" "${_bl_lang[@]}" -clientbeta "$steam_channel" \ -no-cef-sandbox -cef-ozone-platform=x11 "${_bl_cef[@]}" "$@" rc=$? diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-taskset b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-taskset new file mode 100644 index 0000000000..8973fc7f51 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-taskset @@ -0,0 +1,17 @@ +#!/bin/bash +# Staged as taskset in a PATH directory used only by the Steam client. +# Valve's ARM64 helper uses `taskset 0x7c /path/to/steamwebhelper ...` and exits +# before starting the browser when Android denies sched_setaffinity. +set -u +if [ "$#" -ge 2 ] && [[ "$1" =~ ^(0[xX])?[0-9a-fA-F]+$ ]] && + [ -n "${BL_STEAM_WEBHELPER:-}" ] && [ "$2" -ef "$BL_STEAM_WEBHELPER" ]; then + mask=$1 + shift + # Pin this wrapper before exec; never retry a helper that has already run. + if ! /usr/bin/taskset -p "$mask" "$$" >/dev/null 2>&1; then + echo "droiddeck: Steam helper CPU pinning unavailable; using the allowed CPUs" >&2 + fi + exec -- "$@" +fi +# Queries, existing-process changes, and other programs retain taskset's behavior. +exec /usr/bin/taskset "$@" diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility index e37cddfbf6..8247201a34 100755 --- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility +++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility @@ -174,6 +174,9 @@ bl_components() { local -A cm_sums=() while IFS=$'\\t' read -r scope t want comp rel sum src; do [ -n "$scope" ] || continue + # The selected system PowerVR runtime supplies DXVK at launch. Keep saved selections + # for a later manual-driver session without rewriting this Proton's bundled files now. + [ "$comp" = dxvk ] && [ -n "${DROIDDECK_POWERVR_RUNTIME:-}" ] && continue cm_rows+=("$comp"$'\\t'"$rel"$'\\t'"$sum"$'\\t'"$src") [ "$src" != "-" ] && [ -f "$base/$rel" ] && cm_files+=("$base/$rel") done <<< "$cm_selected" diff --git a/tools/linuxfs/preload/drm.c b/tools/linuxfs/preload/drm.c index 37784c3d94..9c40a39294 100644 --- a/tools/linuxfs/preload/drm.c +++ b/tools/linuxfs/preload/drm.c @@ -4,6 +4,7 @@ #include <fcntl.h> #include <pthread.h> #include <stdint.h> +#include <string.h> #include <stdlib.h> #include <sys/file.h> #include <sys/ioctl.h> @@ -12,6 +13,10 @@ #include <unistd.h> #define MAX_HANDLES 4096 +#ifndef F_DUPFD_QUERY +#define F_DUPFD_QUERY 1027 +#endif +#define PVR_HANDLE_BIT UINT32_C(0x80000000) struct gem_close { uint32_t handle; @@ -23,11 +28,14 @@ struct handle_entry { uint32_t handle; int dma_fd; int drm_fd; + int owned_drm_fd; /* PowerVR: pin the open file description, not its reusable fd number. */ + int powervr; }; static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static struct handle_entry handle_entries[MAX_HANDLES]; static uint32_t next_handle = 1; +static uint32_t next_pvr_handle = PVR_HANDLE_BIT; static dev_t kgsl_dev; static int kgsl_state; @@ -37,12 +45,40 @@ static int is_kgsl(int fd) { if (kgsl_state == 0) { const char *standin = getenv("BL_DRM_STANDIN"); kgsl_state = stat("/dev/kgsl-3d0", &st) == 0 || (standin && *standin && stat(standin, &st) == 0) ? 1 : -1; - kgsl_dev = st.st_rdev; + if (kgsl_state > 0) kgsl_dev = st.st_rdev; } pthread_mutex_unlock(&lock); return kgsl_state > 0 && fstat(fd, &st) == 0 && S_ISCHR(st.st_mode) && st.st_rdev == kgsl_dev; } +/* Keep the opt-in separate from GPU detection: manual ICDs must retain native DRM behavior. */ +struct bl_drm_version { + int major, minor, patch; + size_t name_len; + char *name; + size_t date_len; + char *date; + size_t desc_len; + char *desc; +}; +#define BL_DRM_VERSION _IOWR('d', 0x00, struct bl_drm_version) + +static int is_powervr(int fd) { + const char *enabled = getenv("BL_POWERVR_DRM_HANDLES"); + if (!enabled || strcmp(enabled, "1")) return 0; + const char *path = getenv("BL_POWERVR_RENDER_NODE"); + if (!path || !*path) return 0; + struct stat node, candidate; + if (stat(path, &node) || fstat(fd, &candidate) || + !S_ISCHR(candidate.st_mode) || !S_ISCHR(node.st_mode) || + candidate.st_rdev != node.st_rdev) return 0; + char name[16] = {0}; + struct bl_drm_version version = {.name_len = sizeof(name) - 1, .name = name}; + /* Bypass the preload's ioctl dispatcher to avoid recursively entering this hook. */ + return syscall(SYS_ioctl, fd, BL_DRM_VERSION, &version) == 0 && + version.name_len == 3 && !memcmp(name, "pvr", 3); +} + static void *real(const char *name) { void *fn = dlsym(RTLD_NEXT, name); if (!fn) { @@ -89,21 +125,86 @@ static int same_file_description(int a, int b) { return ret; } +/* + * Android kernels before 6.10 have no F_DUPFD_QUERY, while the app seccomp policy blocks kcmp. + * F_SETOWN_EX updates the open file description, so a duplicate observes a temporary owner marker + * and an independent open of the same render node does not. Restore the original owner before + * returning; no signal is armed because these DRM descriptors do not have O_ASYNC set. + */ +static int same_owner_description(int owned, int fd) { + struct f_owner_ex original_owned, original_fd, observed; + if (fcntl(owned, F_GETOWN_EX, &original_owned) < 0 || + fcntl(fd, F_GETOWN_EX, &original_fd) < 0) { + return -1; + } + const struct f_owner_ex candidates[] = { + {.type = F_OWNER_TID, .pid = getpid()}, + {.type = F_OWNER_PID, .pid = getpid()}, + {.type = F_OWNER_PGRP, .pid = getpgrp()}, + }; + const struct f_owner_ex *marker = NULL; + for (size_t i = 0; i < sizeof(candidates) / sizeof(candidates[0]); i++) { + if (candidates[i].type != original_fd.type || candidates[i].pid != original_fd.pid) { + marker = &candidates[i]; + break; + } + } + if (!marker || fcntl(owned, F_SETOWN_EX, marker) < 0) return -1; + int observed_result = fcntl(fd, F_GETOWN_EX, &observed); + int observed_errno = errno; + int restore_result = fcntl(owned, F_SETOWN_EX, &original_owned); + int restore_errno = errno; + if (restore_result < 0) { + errno = restore_errno; + return -1; + } + if (observed_result < 0) { + errno = observed_errno; + return -1; + } + return observed.type == marker->type && observed.pid == marker->pid; +} + +static int same_owned_description(int owned, int fd) { + int saved_errno = errno; + int result = fcntl(owned, F_DUPFD_QUERY, fd); + if (result >= 0) { + errno = saved_errno; + return result == 1; + } +#ifdef SYS_kcmp + long compared = syscall(SYS_kcmp, getpid(), getpid(), 0 /* KCMP_FILE */, owned, fd); + if (compared >= 0) { + errno = saved_errno; + return compared == 0; + } +#endif + int owner_match = same_owner_description(owned, fd); + errno = saved_errno; + return owner_match == 1; +} + static int find_handle_locked(int fd, uint32_t handle) { for (int i = 0; i < MAX_HANDLES; i++) { if (handle_entries[i].handle == handle && - same_file_description(handle_entries[i].drm_fd, fd)) { + (handle_entries[i].powervr + ? same_owned_description(handle_entries[i].owned_drm_fd, fd) + : same_file_description(handle_entries[i].drm_fd, fd))) { return i; } } return -1; } -static uint32_t alloc_handle_locked(void) { +static uint32_t alloc_handle_locked(int powervr) { for (int tries = 0; tries <= MAX_HANDLES; tries++) { - uint32_t candidate = next_handle++; - if (next_handle == 0) { - next_handle = 1; + uint32_t candidate; + if (powervr) { + candidate = next_pvr_handle++; + if (!(next_pvr_handle & PVR_HANDLE_BIT)) next_pvr_handle = PVR_HANDLE_BIT; + } else { + candidate = next_handle++; + if (next_handle == PVR_HANDLE_BIT) next_handle = 1; } if (candidate == 0) { continue; @@ -123,25 +224,49 @@ static uint32_t alloc_handle_locked(void) { } int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) { - if (!is_kgsl(fd)) { + int kgsl = is_kgsl(fd); + int powervr = !kgsl && is_powervr(fd); + if (!kgsl) { int (*fn)(int, int, uint32_t *) = (int (*)(int, int, uint32_t *)) real("drmPrimeFDToHandle"); - return fn ? fn(fd, prime_fd, handle) : -ENOSYS; + if (!fn) return -ENOSYS; + int result = fn(fd, prime_fd, handle); + if (!result || !powervr || errno != EINVAL) return result; + } + if (!handle) { errno = EINVAL; return -EINVAL; } + int owner = -1; + if (powervr) { + owner = fcntl(fd, F_DUPFD_CLOEXEC, 0); + if (owner < 0) return -errno; + /* The old-kernel owner probe mutates shared OFD state briefly; serialize it with lookups. */ + pthread_mutex_lock(&lock); + int owner_matches = same_owned_description(owner, fd); + pthread_mutex_unlock(&lock); + if (!owner_matches) { + close(owner); + errno = EOPNOTSUPP; + return -EOPNOTSUPP; + } } int dup_fd = fcntl(prime_fd, F_DUPFD_CLOEXEC, 0); if (dup_fd < 0) { - return -errno; + int error = errno; + if (owner >= 0) close(owner); + errno = error; + return -error; } int ret = -ENOMEM; pthread_mutex_lock(&lock); for (int i = 0; i < MAX_HANDLES; i++) { if (handle_entries[i].handle == 0) { - uint32_t token = alloc_handle_locked(); + uint32_t token = alloc_handle_locked(powervr); if (!token) { break; } handle_entries[i].handle = token; handle_entries[i].dma_fd = dup_fd; handle_entries[i].drm_fd = fd; + handle_entries[i].owned_drm_fd = owner; + handle_entries[i].powervr = powervr; *handle = token; ret = 0; break; @@ -150,24 +275,32 @@ int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) { pthread_mutex_unlock(&lock); if (ret) { close(dup_fd); + if (owner >= 0) close(owner); + errno = -ret; } return ret; } int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd) { - if (!is_kgsl(fd)) { - int (*fn)(int, uint32_t, uint32_t, int *) = (int (*)(int, uint32_t, uint32_t, int *)) real("drmPrimeHandleToFD"); - return fn ? fn(fd, handle, flags, prime_fd) : -ENOSYS; - } + int kgsl = is_kgsl(fd); int ret = -EINVAL; pthread_mutex_lock(&lock); int index = find_handle_locked(fd, handle); if (index >= 0) { - *prime_fd = fcntl(handle_entries[index].dma_fd, F_DUPFD_CLOEXEC, 0); - ret = *prime_fd < 0 ? -errno : 0; + if (!prime_fd || (handle_entries[index].powervr && (flags & ~(O_CLOEXEC | O_RDWR)))) { + errno = EINVAL; + } else { + int command = handle_entries[index].powervr && !(flags & O_CLOEXEC) ? F_DUPFD : F_DUPFD_CLOEXEC; + *prime_fd = fcntl(handle_entries[index].dma_fd, command, 0); + ret = *prime_fd < 0 ? -errno : 0; + } } pthread_mutex_unlock(&lock); - return ret; + if (index >= 0 || kgsl) return ret; + /* Unknown handles (including real PowerVR GEM handles) retain kernel semantics. */ + int (*fn)(int, uint32_t, uint32_t, int *) = + (int (*)(int, uint32_t, uint32_t, int *)) real("drmPrimeHandleToFD"); + return fn ? fn(fd, handle, flags, prime_fd) : -ENOSYS; } static int release_handle(int fd, uint32_t handle) { @@ -176,6 +309,7 @@ static int release_handle(int fd, uint32_t handle) { int index = find_handle_locked(fd, handle); if (index >= 0) { close(handle_entries[index].dma_fd); + if (handle_entries[index].powervr) close(handle_entries[index].owned_drm_fd); handle_entries[index] = (struct handle_entry){0}; found = 1; } @@ -184,22 +318,23 @@ static int release_handle(int fd, uint32_t handle) { } int drmCloseBufferHandle(int fd, uint32_t handle) { - if (!is_kgsl(fd)) { - int (*fn)(int, uint32_t) = (int (*)(int, uint32_t)) real("drmCloseBufferHandle"); - return fn ? fn(fd, handle) : -ENOSYS; - } - return release_handle(fd, handle) ? 0 : -EINVAL; + if (release_handle(fd, handle)) return 0; + if (is_kgsl(fd)) { errno = EINVAL; return -EINVAL; } + int (*fn)(int, uint32_t) = (int (*)(int, uint32_t)) real("drmCloseBufferHandle"); + return fn ? fn(fd, handle) : -ENOSYS; } __attribute__((visibility("hidden"))) int bl_drm_gem_close(int fd, unsigned long request, void *arg, int *rc) { - if (request != GEM_CLOSE || !arg || !is_kgsl(fd)) { + if (request != GEM_CLOSE || !arg) { return 0; } if (release_handle(fd, ((struct gem_close *) arg)->handle)) { *rc = 0; - } else { + } else if (is_kgsl(fd)) { errno = EINVAL; *rc = -1; + } else { + return 0; } return 1; } diff --git a/tools/linuxfs/preload/netif.c b/tools/linuxfs/preload/netif.c index 55da3c21e1..d7f56e32ab 100644 --- a/tools/linuxfs/preload/netif.c +++ b/tools/linuxfs/preload/netif.c @@ -596,6 +596,8 @@ static FILE *synthesize(const char *table) { int bl_status_without_tracer(const char *path, int flags, const void *caller) __attribute__((visibility("hidden"))); +const char *bl_oom_adj_redirect(const char *path, int writing) __attribute__((visibility("hidden"))); + static FILE *open_stream(fopen_fn real, const char *path, const char *mode, const void *caller) { int status = mode && mode[0] == 'r' && !strchr(mode, '+') ? bl_status_without_tracer(path, O_RDONLY | O_CLOEXEC, caller) : -1; @@ -604,6 +606,7 @@ static FILE *open_stream(fopen_fn real, const char *path, const char *mode, cons if (copy == NULL) close(status); return copy; } + path = bl_oom_adj_redirect(path, mode && (mode[0] == 'w' || mode[0] == 'a' || strchr(mode, '+'))); int table = path && mode && mode[0] == 'r' ? denied_table(path) : -1; FILE *f; if (table >= 0 && denied_recently(table, path) && (f = synthesize(net_tables[table])) != NULL) return f; diff --git a/tools/linuxfs/preload/oomadj.c b/tools/linuxfs/preload/oomadj.c new file mode 100644 index 0000000000..19e5f4251d --- /dev/null +++ b/tools/linuxfs/preload/oomadj.c @@ -0,0 +1,47 @@ +/* + * Based on jdmg28's DroidDeck-Mali fork (commit 6be00e00, GPL-3.0): steam-launch-wrapper runs every + * game with --oom-score-adjust 900. Android's lmkd reads 900 as CACHED_APP_MIN_ADJ and kills the + * foreground game first when memory runs short; on Linux 6.1 the raise also becomes the process's + * permanent minimum. An app's processes cannot go below the score they inherit, so the only writes + * that succeed from in here are raises: every write-open of an oom_score_adj file goes to /dev/null. + */ +#define _GNU_SOURCE +#include <errno.h> +#include <string.h> +#include <unistd.h> + +static int is_oom_score_adj(const char *path) { + if (path == NULL || strncmp(path, "/proc/", 6) != 0) return 0; + const char *p = path + 6; + if (strncmp(p, "self/", 5) == 0) { + p += 5; + } else if (strncmp(p, "thread-self/", 12) == 0) { + p += 12; + } else { + const char *digits = p; + while (*p >= '0' && *p <= '9') p++; + if (p == digits || *p != '/') return 0; + p++; + if (strncmp(p, "task/", 5) == 0) { + p += 5; + digits = p; + while (*p >= '0' && *p <= '9') p++; + if (p == digits || *p != '/') return 0; + p++; + } + } + return strcmp(p, "oom_score_adj") == 0 || strcmp(p, "oom_adj") == 0; +} + +__attribute__((visibility("hidden"))) const char *bl_oom_adj_redirect(const char *path, int writing) { + static int logged; + if (!writing || !is_oom_score_adj(path)) return path; + if (!__atomic_exchange_n(&logged, 1, __ATOMIC_RELAXED)) { + static const char msg[] = "droiddeck: an oom_score_adj raise was dropped (Android would treat this program as a cached app)\n"; + int saved = errno; + ssize_t ignored = write(STDERR_FILENO, msg, sizeof(msg) - 1); + (void)ignored; + errno = saved; + } + return "/dev/null"; +} diff --git a/tools/linuxfs/preload/opens.c b/tools/linuxfs/preload/opens.c index 332f9d89a5..4113062cd5 100644 --- a/tools/linuxfs/preload/opens.c +++ b/tools/linuxfs/preload/opens.c @@ -14,6 +14,7 @@ int bl_status_without_tracer(const char *path, int flags, const void *caller) __attribute__((visibility("hidden"))); int bl_writable_retry(int dirfd, const char *path, int flags) __attribute__((visibility("hidden"))); int bl_ntsync_open(const char *path, int flags) __attribute__((visibility("hidden"))); +const char *bl_oom_adj_redirect(const char *path, int writing) __attribute__((visibility("hidden"))); int bl_venc_open(const char *path, int flags) __attribute__((visibility("hidden"))); int bl_vdec_open(const char *path, int flags) __attribute__((visibility("hidden"))); int bl_dircache_create(int dirfd, const char *path, int flags, mode_t mode, @@ -53,6 +54,7 @@ int open(const char *path, int flags, ...) { errno = EACCES; return -1; } + path = bl_oom_adj_redirect(path, (flags & O_ACCMODE) != O_RDONLY); if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd; if ((fd = bl_ntsync_open(path, flags)) != -2) return fd; if ((fd = bl_venc_open(path, flags)) != -2) return fd; @@ -80,6 +82,7 @@ int openat(int dirfd, const char *path, int flags, ...) { errno = EACCES; return -1; } + path = bl_oom_adj_redirect(path, (flags & O_ACCMODE) != O_RDONLY); if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd; if ((fd = bl_ntsync_open(path, flags)) != -2) return fd; if ((fd = bl_venc_open(path, flags)) != -2) return fd; diff --git a/tools/linuxfs/preload/venus.c b/tools/linuxfs/preload/venus.c new file mode 100644 index 0000000000..4feb9ee03a --- /dev/null +++ b/tools/linuxfs/preload/venus.c @@ -0,0 +1,18 @@ +/* + * Zink keeps kopper when the session draws through Venus. + * + * On Mali the session reaches the GPU through Venus over vtest, and Xwayland has no DRM node to + * build glamor on, so it offers no DRI3. Without DRI3, Zink can only present through kopper (its + * Vulkan WSI path). Steam's steamwebhelper.sh exports LIBGL_KOPPER_DISABLE=true for the client + * interface unconditionally, so on Mali every GL context the interface asked for failed and the + * webhelper restarted until Steam gave up on GPU acceleration. Steam restores that script when + * it verifies its install, so the variable is dropped here instead, before Mesa reads it. + */ +#define _GNU_SOURCE 1 +#include <stdlib.h> +#include <string.h> + +__attribute__((constructor)) static void bl_venus_keep_kopper(void) { + const char *debug = getenv("VN_DEBUG"); + if (debug && strstr(debug, "vtest")) unsetenv("LIBGL_KOPPER_DISABLE"); +} diff --git a/tools/linuxfs/xclipse-layer/VkLayer_droiddeck_xclipse.json b/tools/linuxfs/xclipse-layer/VkLayer_droiddeck_xclipse.json new file mode 100644 index 0000000000..888d0a89de --- /dev/null +++ b/tools/linuxfs/xclipse-layer/VkLayer_droiddeck_xclipse.json @@ -0,0 +1,11 @@ +{ + "file_format_version": "1.2.0", + "layer": { + "name": "VK_LAYER_DROIDDECK_xclipse", + "type": "GLOBAL", + "library_path": "./libVkLayer_droiddeck_xclipse.so", + "api_version": "1.3.0", + "implementation_version": "1", + "description": "Workarounds for Samsung Xclipse drivers loaded through libhybris" + } +} diff --git a/tools/linuxfs/xclipse-layer/device_chain.inc b/tools/linuxfs/xclipse-layer/device_chain.inc new file mode 100644 index 0000000000..e8a1314114 --- /dev/null +++ b/tools/linuxfs/xclipse-layer/device_chain.inc @@ -0,0 +1,180 @@ +/* Generated by gen_device_chain.py from Vulkan-Headers 1.3.275; do not edit. */ +DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_DEVICE_MEMORY_REPORT_CREATE_INFO_EXT, VkDeviceDeviceMemoryReportCreateInfoEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV, VkDeviceDiagnosticsConfigCreateInfoNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO, VkDeviceGroupDeviceCreateInfo) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_MEMORY_OVERALLOCATION_CREATE_INFO_AMD, VkDeviceMemoryOverallocationCreateInfoAMD) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_PRIVATE_DATA_CREATE_INFO, VkDevicePrivateDataCreateInfo) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_QUEUE_SHADER_CORE_CONTROL_CREATE_INFO_ARM, VkDeviceQueueShaderCoreControlCreateInfoARM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES, VkPhysicalDevice16BitStorageFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT, VkPhysicalDevice4444FormatsFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES, VkPhysicalDevice8BitStorageFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR, VkPhysicalDeviceAccelerationStructureFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ADDRESS_BINDING_REPORT_FEATURES_EXT, VkPhysicalDeviceAddressBindingReportFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_AMIGO_PROFILING_FEATURES_SEC, VkPhysicalDeviceAmigoProfilingFeaturesSEC) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ASTC_DECODE_FEATURES_EXT, VkPhysicalDeviceASTCDecodeFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ATTACHMENT_FEEDBACK_LOOP_DYNAMIC_STATE_FEATURES_EXT, VkPhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ATTACHMENT_FEEDBACK_LOOP_LAYOUT_FEATURES_EXT, VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT, VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BORDER_COLOR_SWIZZLE_FEATURES_EXT, VkPhysicalDeviceBorderColorSwizzleFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES, VkPhysicalDeviceBufferDeviceAddressFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT, VkPhysicalDeviceBufferDeviceAddressFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CLUSTER_CULLING_SHADER_FEATURES_HUAWEI, VkPhysicalDeviceClusterCullingShaderFeaturesHUAWEI) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COHERENT_MEMORY_FEATURES_AMD, VkPhysicalDeviceCoherentMemoryFeaturesAMD) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COLOR_WRITE_ENABLE_FEATURES_EXT, VkPhysicalDeviceColorWriteEnableFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV, VkPhysicalDeviceComputeShaderDerivativesFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT, VkPhysicalDeviceConditionalRenderingFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR, VkPhysicalDeviceCooperativeMatrixFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_NV, VkPhysicalDeviceCooperativeMatrixFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COPY_MEMORY_INDIRECT_FEATURES_NV, VkPhysicalDeviceCopyMemoryIndirectFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CORNER_SAMPLED_IMAGE_FEATURES_NV, VkPhysicalDeviceCornerSampledImageFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COVERAGE_REDUCTION_MODE_FEATURES_NV, VkPhysicalDeviceCoverageReductionModeFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUBIC_CLAMP_FEATURES_QCOM, VkPhysicalDeviceCubicClampFeaturesQCOM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUBIC_WEIGHTS_FEATURES_QCOM, VkPhysicalDeviceCubicWeightsFeaturesQCOM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUDA_KERNEL_LAUNCH_FEATURES_NV, VkPhysicalDeviceCudaKernelLaunchFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT, VkPhysicalDeviceCustomBorderColorFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEDICATED_ALLOCATION_IMAGE_ALIASING_FEATURES_NV, VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_BIAS_CONTROL_FEATURES_EXT, VkPhysicalDeviceDepthBiasControlFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLAMP_ZERO_ONE_FEATURES_EXT, VkPhysicalDeviceDepthClampZeroOneFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_CONTROL_FEATURES_EXT, VkPhysicalDeviceDepthClipControlFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT, VkPhysicalDeviceDepthClipEnableFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_FEATURES_EXT, VkPhysicalDeviceDescriptorBufferFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES, VkPhysicalDeviceDescriptorIndexingFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_POOL_OVERALLOCATION_FEATURES_NV, VkPhysicalDeviceDescriptorPoolOverallocationFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_SET_HOST_MAPPING_FEATURES_VALVE, VkPhysicalDeviceDescriptorSetHostMappingFeaturesVALVE) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_COMPUTE_FEATURES_NV, VkPhysicalDeviceDeviceGeneratedCommandsComputeFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_FEATURES_NV, VkPhysicalDeviceDeviceGeneratedCommandsFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_MEMORY_REPORT_FEATURES_EXT, VkPhysicalDeviceDeviceMemoryReportFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DIAGNOSTICS_CONFIG_FEATURES_NV, VkPhysicalDeviceDiagnosticsConfigFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES, VkPhysicalDeviceDynamicRenderingFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_UNUSED_ATTACHMENTS_FEATURES_EXT, VkPhysicalDeviceDynamicRenderingUnusedAttachmentsFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXCLUSIVE_SCISSOR_FEATURES_NV, VkPhysicalDeviceExclusiveScissorFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT, VkPhysicalDeviceExtendedDynamicState2FeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_3_FEATURES_EXT, VkPhysicalDeviceExtendedDynamicState3FeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT, VkPhysicalDeviceExtendedDynamicStateFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_SPARSE_ADDRESS_SPACE_FEATURES_NV, VkPhysicalDeviceExtendedSparseAddressSpaceFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_RDMA_FEATURES_NV, VkPhysicalDeviceExternalMemoryRDMAFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FAULT_FEATURES_EXT, VkPhysicalDeviceFaultFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, VkPhysicalDeviceFeatures2) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_2_FEATURES_EXT, VkPhysicalDeviceFragmentDensityMap2FeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_FEATURES_EXT, VkPhysicalDeviceFragmentDensityMapFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_OFFSET_FEATURES_QCOM, VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_BARYCENTRIC_FEATURES_KHR, VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT, VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_ENUMS_FEATURES_NV, VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR, VkPhysicalDeviceFragmentShadingRateFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAME_BOUNDARY_FEATURES_EXT, VkPhysicalDeviceFrameBoundaryFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GLOBAL_PRIORITY_QUERY_FEATURES_KHR, VkPhysicalDeviceGlobalPriorityQueryFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GRAPHICS_PIPELINE_LIBRARY_FEATURES_EXT, VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES_EXT, VkPhysicalDeviceHostImageCopyFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES, VkPhysicalDeviceHostQueryResetFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES, VkPhysicalDeviceImagelessFramebufferFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_2D_VIEW_OF_3D_FEATURES_EXT, VkPhysicalDeviceImage2DViewOf3DFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_FEATURES_EXT, VkPhysicalDeviceImageCompressionControlFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN_FEATURES_EXT, VkPhysicalDeviceImageCompressionControlSwapchainFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_PROCESSING_2_FEATURES_QCOM, VkPhysicalDeviceImageProcessing2FeaturesQCOM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_PROCESSING_FEATURES_QCOM, VkPhysicalDeviceImageProcessingFeaturesQCOM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES, VkPhysicalDeviceImageRobustnessFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_SLICED_VIEW_OF_3D_FEATURES_EXT, VkPhysicalDeviceImageSlicedViewOf3DFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_MIN_LOD_FEATURES_EXT, VkPhysicalDeviceImageViewMinLodFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT, VkPhysicalDeviceIndexTypeUint8FeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INHERITED_VIEWPORT_SCISSOR_FEATURES_NV, VkPhysicalDeviceInheritedViewportScissorFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES, VkPhysicalDeviceInlineUniformBlockFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INVOCATION_MASK_FEATURES_HUAWEI, VkPhysicalDeviceInvocationMaskFeaturesHUAWEI) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LEGACY_DITHERING_FEATURES_EXT, VkPhysicalDeviceLegacyDitheringFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINEAR_COLOR_ATTACHMENT_FEATURES_NV, VkPhysicalDeviceLinearColorAttachmentFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT, VkPhysicalDeviceLineRasterizationFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_4_FEATURES, VkPhysicalDeviceMaintenance4Features) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR, VkPhysicalDeviceMaintenance5FeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_6_FEATURES_KHR, VkPhysicalDeviceMaintenance6FeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_DECOMPRESSION_FEATURES_NV, VkPhysicalDeviceMemoryDecompressionFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT, VkPhysicalDeviceMemoryPriorityFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT, VkPhysicalDeviceMeshShaderFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_NV, VkPhysicalDeviceMeshShaderFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_FEATURES_EXT, VkPhysicalDeviceMultisampledRenderToSingleSampledFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES, VkPhysicalDeviceMultiviewFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PER_VIEW_RENDER_AREAS_FEATURES_QCOM, VkPhysicalDeviceMultiviewPerViewRenderAreasFeaturesQCOM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PER_VIEW_VIEWPORTS_FEATURES_QCOM, VkPhysicalDeviceMultiviewPerViewViewportsFeaturesQCOM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTI_DRAW_FEATURES_EXT, VkPhysicalDeviceMultiDrawFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MUTABLE_DESCRIPTOR_TYPE_FEATURES_EXT, VkPhysicalDeviceMutableDescriptorTypeFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_NESTED_COMMAND_BUFFER_FEATURES_EXT, VkPhysicalDeviceNestedCommandBufferFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_NON_SEAMLESS_CUBE_MAP_FEATURES_EXT, VkPhysicalDeviceNonSeamlessCubeMapFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPACITY_MICROMAP_FEATURES_EXT, VkPhysicalDeviceOpacityMicromapFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPTICAL_FLOW_FEATURES_NV, VkPhysicalDeviceOpticalFlowFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PAGEABLE_DEVICE_LOCAL_MEMORY_FEATURES_EXT, VkPhysicalDevicePageableDeviceLocalMemoryFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_FEATURES_KHR, VkPhysicalDevicePerformanceQueryFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PER_STAGE_DESCRIPTOR_SET_FEATURES_NV, VkPhysicalDevicePerStageDescriptorSetFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES, VkPhysicalDevicePipelineCreationCacheControlFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR, VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_LIBRARY_GROUP_HANDLES_FEATURES_EXT, VkPhysicalDevicePipelineLibraryGroupHandlesFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_PROPERTIES_FEATURES_EXT, VkPhysicalDevicePipelinePropertiesFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_PROTECTED_ACCESS_FEATURES_EXT, VkPhysicalDevicePipelineProtectedAccessFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_ROBUSTNESS_FEATURES_EXT, VkPhysicalDevicePipelineRobustnessFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_BARRIER_FEATURES_NV, VkPhysicalDevicePresentBarrierFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, VkPhysicalDevicePresentIdFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_FEATURES_KHR, VkPhysicalDevicePresentWaitFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVES_GENERATED_QUERY_FEATURES_EXT, VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT, VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES, VkPhysicalDevicePrivateDataFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES, VkPhysicalDeviceProtectedMemoryFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT, VkPhysicalDeviceProvokingVertexFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_EXT, VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR, VkPhysicalDeviceRayQueryFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_INVOCATION_REORDER_FEATURES_NV, VkPhysicalDeviceRayTracingInvocationReorderFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_MAINTENANCE_1_FEATURES_KHR, VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_MOTION_BLUR_FEATURES_NV, VkPhysicalDeviceRayTracingMotionBlurFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR, VkPhysicalDeviceRayTracingPipelineFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR, VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RELAXED_LINE_RASTERIZATION_FEATURES_IMG, VkPhysicalDeviceRelaxedLineRasterizationFeaturesIMG) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RENDER_PASS_STRIPED_FEATURES_ARM, VkPhysicalDeviceRenderPassStripedFeaturesARM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_REPRESENTATIVE_FRAGMENT_TEST_FEATURES_NV, VkPhysicalDeviceRepresentativeFragmentTestFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RGBA10X6_FORMATS_FEATURES_EXT, VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT, VkPhysicalDeviceRobustness2FeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES, VkPhysicalDeviceSamplerYcbcrConversionFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES, VkPhysicalDeviceScalarBlockLayoutFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCHEDULING_CONTROLS_FEATURES_ARM, VkPhysicalDeviceSchedulingControlsFeaturesARM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES, VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_2_FEATURES_EXT, VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT, VkPhysicalDeviceShaderAtomicFloatFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES, VkPhysicalDeviceShaderAtomicInt64Features) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR, VkPhysicalDeviceShaderClockFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_BUILTINS_FEATURES_ARM, VkPhysicalDeviceShaderCoreBuiltinsFeaturesARM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES, VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES, VkPhysicalDeviceShaderDrawParametersFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_EARLY_AND_LATE_FRAGMENT_TESTS_FEATURES_AMD, VkPhysicalDeviceShaderEarlyAndLateFragmentTestsFeaturesAMD) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES, VkPhysicalDeviceShaderFloat16Int8Features) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_IMAGE_ATOMIC_INT64_FEATURES_EXT, VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_IMAGE_FOOTPRINT_FEATURES_NV, VkPhysicalDeviceShaderImageFootprintFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_FEATURES, VkPhysicalDeviceShaderIntegerDotProductFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_FUNCTIONS_2_FEATURES_INTEL, VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_MODULE_IDENTIFIER_FEATURES_EXT, VkPhysicalDeviceShaderModuleIdentifierFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT, VkPhysicalDeviceShaderObjectFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SM_BUILTINS_FEATURES_NV, VkPhysicalDeviceShaderSMBuiltinsFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES, VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_UNIFORM_CONTROL_FLOW_FEATURES_KHR, VkPhysicalDeviceShaderSubgroupUniformControlFlowFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_TERMINATE_INVOCATION_FEATURES, VkPhysicalDeviceShaderTerminateInvocationFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_TILE_IMAGE_FEATURES_EXT, VkPhysicalDeviceShaderTileImageFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADING_RATE_IMAGE_FEATURES_NV, VkPhysicalDeviceShadingRateImageFeaturesNV) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES, VkPhysicalDeviceSubgroupSizeControlFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBPASS_MERGE_FEEDBACK_FEATURES_EXT, VkPhysicalDeviceSubpassMergeFeedbackFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBPASS_SHADING_FEATURES_HUAWEI, VkPhysicalDeviceSubpassShadingFeaturesHUAWEI) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT, VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES, VkPhysicalDeviceSynchronization2Features) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT, VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXTURE_COMPRESSION_ASTC_HDR_FEATURES, VkPhysicalDeviceTextureCompressionASTCHDRFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TILE_PROPERTIES_FEATURES_QCOM, VkPhysicalDeviceTilePropertiesFeaturesQCOM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES, VkPhysicalDeviceTimelineSemaphoreFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT, VkPhysicalDeviceTransformFeedbackFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES, VkPhysicalDeviceUniformBufferStandardLayoutFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES, VkPhysicalDeviceVariablePointersFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_KHR, VkPhysicalDeviceVertexAttributeDivisorFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT, VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VIDEO_MAINTENANCE_1_FEATURES_KHR, VkPhysicalDeviceVideoMaintenance1FeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES, VkPhysicalDeviceVulkan11Features) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, VkPhysicalDeviceVulkan12Features) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES, VkPhysicalDeviceVulkan13Features) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES, VkPhysicalDeviceVulkanMemoryModelFeatures) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_FEATURES_KHR, VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_2_PLANE_444_FORMATS_FEATURES_EXT, VkPhysicalDeviceYcbcr2Plane444FormatsFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_DEGAMMA_FEATURES_QCOM, VkPhysicalDeviceYcbcrDegammaFeaturesQCOM) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT, VkPhysicalDeviceYcbcrImageArraysFeaturesEXT) +DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ZERO_INITIALIZE_WORKGROUP_MEMORY_FEATURES, VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures) diff --git a/tools/linuxfs/xclipse-layer/gen_device_chain.py b/tools/linuxfs/xclipse-layer/gen_device_chain.py new file mode 100755 index 0000000000..3ef47693c6 --- /dev/null +++ b/tools/linuxfs/xclipse-layer/gen_device_chain.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +"""Generate device_chain.inc: the structures a VkDeviceCreateInfo chain may hold, with their sizes. + +The Xclipse layer copies the chain ahead of the VkPhysicalDeviceFeatures2 it edits, and copying a +structure needs its size. Run against the Vulkan-Headers release the build compiles with (Ubuntu +24.04's libvulkan-dev is 1.3.275): + + gen_device_chain.py Vulkan-Headers/registry/vk.xml Vulkan-Headers/include/vulkan/vulkan_core.h +""" +import re +import sys +import xml.etree.ElementTree as ElementTree +from pathlib import Path + + +def main(registry, core_header, output): + core = Path(core_header).read_text() + root = ElementTree.parse(registry).getroot() + entries = [] + for struct in root.iter("type"): + if struct.get("category") != "struct" or struct.get("alias"): + continue + if "VkDeviceCreateInfo" not in (struct.get("structextends") or "").split(","): + continue + name = struct.get("name") + stype = next((member.get("values") for member in struct.findall("member") + if member.findtext("name") == "sType"), None) + # Platform and provisional structures live outside vulkan_core.h; the layer never builds them. + if not stype or not re.search(r"\}\s*" + re.escape(name) + r"\s*;", core): + continue + entries.append((stype, name)) + version = re.search(r"#define VK_HEADER_VERSION (\d+)", core).group(1) + lines = ["/* Generated by gen_device_chain.py from Vulkan-Headers 1.3.%s; do not edit. */" % version] + lines += ["DEVICE_CHAIN(%s, %s)" % entry for entry in sorted(entries)] + Path(output).write_text("\n".join(lines) + "\n") + print("%d structures" % len(entries)) + + +if __name__ == "__main__": + if len(sys.argv) not in (3, 4): + sys.exit(__doc__) + main(sys.argv[1], sys.argv[2], sys.argv[3] if len(sys.argv) == 4 else + Path(__file__).with_name("device_chain.inc")) diff --git a/tools/linuxfs/xclipse-layer/xclipse_layer.c b/tools/linuxfs/xclipse-layer/xclipse_layer.c new file mode 100644 index 0000000000..68c3379dd4 --- /dev/null +++ b/tools/linuxfs/xclipse-layer/xclipse_layer.c @@ -0,0 +1,493 @@ +/* + * VK_LAYER_DROIDDECK_xclipse: workarounds for Samsung's Xclipse driver loaded through libhybris. + * + * 1. bionic environ. A glibc process never initializes bionic's `environ`; the driver's + * AMD-derived shader compiler walks it for AMD_SC_* settings and crashed on the NULL. + * Once instance creation has loaded the driver, point it at a snapshot of ours. + * 2. YCbCr immutable samplers in compute. Compute pipelines whose layout binds an array of + * immutable YCbCr-conversion samplers fail to compile (VK_ERROR_UNKNOWN); gamescope's + * composite shaders all bind one. Such bindings get a plain linear sampler instead, so only + * multi-planar (NV12) layers sample incorrectly. + * 3. Calibrated timestamps. The driver has only VK_EXT_calibrated_timestamps, but the bridge + * lists the KHR names too, and Wine calls those; the loader then aborts (it took down Wine's + * explorer.exe and with it every game window). The KHR entry points forward to the EXT ones. + * 4. BC4/BC5 filtering. The libhybris compat layer emulates BC textures; BC4/BC5 decode into + * R16/R16G16 images, for which this driver advertises no linear filtering, so DXVK would + * treat them as unfilterable. The layer reports linear filtering for BC4/BC5 where they are + * sampled at all (RDNA filters 16-bit normalized formats; at worst they sample unfiltered). + * 5. textureCompressionBC. The compat layer emulates BC formats but keeps the feature bit off; + * DXVK before 3.0 (the last that fits this driver's 128 bytes of push constants) requires + * it. The layer reports it while BC formats are sampleable and clears it at device creation. + * Everything else passes straight through. + */ +#define _GNU_SOURCE +#include <vulkan/vk_layer.h> +#include <vulkan/vulkan.h> +#include <dlfcn.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define EXPORT __attribute__((visibility("default"))) +#define MAX_OBJECTS 64 + +extern char **environ; + +/* The loader's dispatch table pointer heads every dispatchable object: an instance shares it + * with its physical devices, a device with its queues and command buffers. */ +typedef void *dispatch_key; +static dispatch_key key_of(const void *object) { return *(dispatch_key *)object; } + +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +static int debug; + +struct instance_data { + dispatch_key key; + VkInstance handle; + PFN_vkGetInstanceProcAddr next; + PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT time_domains; + PFN_vkGetPhysicalDeviceFeatures features; + PFN_vkGetPhysicalDeviceFeatures2 features2; + PFN_vkGetPhysicalDeviceFormatProperties format_properties; + PFN_vkGetPhysicalDeviceFormatProperties2 format_properties2; +}; +struct device_data { + dispatch_key key; + VkDevice handle; + PFN_vkGetDeviceProcAddr next; + PFN_vkCreateSampler create_sampler; + PFN_vkDestroySampler destroy_sampler; + PFN_vkCreateDescriptorSetLayout create_set_layout; + PFN_vkDestroyDevice destroy_device; + PFN_vkGetCalibratedTimestampsEXT timestamps; + VkSampler fallback; +}; +static struct instance_data instances[MAX_OBJECTS]; +static struct device_data devices[MAX_OBJECTS]; +/* The live YCbCr samplers each device created, so set layouts can recognise them. Guarded by lock. */ +static struct ycbcr_sampler { VkDevice device; VkSampler sampler; } *ycbcr_samplers; +static size_t ycbcr_count, ycbcr_capacity; + +static struct instance_data *instance_by_key(dispatch_key key) { + for (int i = 0; i < MAX_OBJECTS; i++) + if (instances[i].handle && instances[i].key == key) return &instances[i]; + return NULL; +} + +static struct device_data *device_by_key(dispatch_key key) { + for (int i = 0; i < MAX_OBJECTS; i++) + if (devices[i].handle && devices[i].key == key) return &devices[i]; + return NULL; +} + +/* Entries are never freed while their object lives, so a looked-up copy of the pointers is safe. */ +static struct instance_data instance_of(const void *object) { + struct instance_data copy = {0}; + pthread_mutex_lock(&lock); + struct instance_data *data = instance_by_key(key_of(object)); + if (data) copy = *data; + pthread_mutex_unlock(&lock); + return copy; +} + +static struct device_data device_of(const void *object) { + struct device_data copy = {0}; + pthread_mutex_lock(&lock); + struct device_data *data = device_by_key(key_of(object)); + if (data) copy = *data; + pthread_mutex_unlock(&lock); + return copy; +} + +static void fix_bionic_environ(void) { + void *common = dlopen("libhybris-common.so.1", RTLD_NOW | RTLD_NOLOAD); + if (!common) return; /* not a libhybris driver */ + void *(*h_dlopen)(const char *, int) = (void *(*)(const char *, int))dlsym(common, "hybris_dlopen"); + void *(*h_dlsym)(void *, const char *) = (void *(*)(void *, const char *))dlsym(common, "hybris_dlsym"); + if (!h_dlopen || !h_dlsym) return; + void *libc = h_dlopen("libc.so", RTLD_NOW); + char ***bionic_environ = libc ? (char ***)h_dlsym(libc, "environ") : NULL; + if (!bionic_environ || *bionic_environ) return; + size_t count = 0; + while (environ && environ[count]) count++; + char **snapshot = calloc(count + 1, sizeof(*snapshot)); + if (!snapshot) return; + for (size_t i = 0; i < count; i++) snapshot[i] = strdup(environ[i]); + *bionic_environ = snapshot; + if (debug) fprintf(stderr, "xclipse layer: bionic environ set (%zu entries)\n", count); +} + +/* ---- instance ---- */ + +static VkResult VKAPI_CALL create_instance(const VkInstanceCreateInfo *info, const VkAllocationCallbacks *allocator, + VkInstance *instance) { + VkLayerInstanceCreateInfo *chain = (VkLayerInstanceCreateInfo *)info->pNext; + while (chain && !(chain->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && chain->function == VK_LAYER_LINK_INFO)) + chain = (VkLayerInstanceCreateInfo *)chain->pNext; + if (!chain || !chain->u.pLayerInfo) return VK_ERROR_INITIALIZATION_FAILED; + PFN_vkGetInstanceProcAddr next = chain->u.pLayerInfo->pfnNextGetInstanceProcAddr; + chain->u.pLayerInfo = chain->u.pLayerInfo->pNext; + PFN_vkCreateInstance next_create = (PFN_vkCreateInstance)next(NULL, "vkCreateInstance"); + if (!next_create) return VK_ERROR_INITIALIZATION_FAILED; + VkResult result = next_create(info, allocator, instance); + if (result != VK_SUCCESS) return result; + fix_bionic_environ(); + struct instance_data data = { + .key = key_of(*instance), + .handle = *instance, + .next = next, + .time_domains = (PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT) + next(*instance, "vkGetPhysicalDeviceCalibrateableTimeDomainsEXT"), + .features = (PFN_vkGetPhysicalDeviceFeatures)next(*instance, "vkGetPhysicalDeviceFeatures"), + .features2 = (PFN_vkGetPhysicalDeviceFeatures2)next(*instance, "vkGetPhysicalDeviceFeatures2"), + .format_properties = (PFN_vkGetPhysicalDeviceFormatProperties)next(*instance, "vkGetPhysicalDeviceFormatProperties"), + .format_properties2 = (PFN_vkGetPhysicalDeviceFormatProperties2)next(*instance, "vkGetPhysicalDeviceFormatProperties2"), + }; + pthread_mutex_lock(&lock); + for (int i = 0; i < MAX_OBJECTS; i++) + if (!instances[i].handle) { instances[i] = data; break; } + pthread_mutex_unlock(&lock); + return result; +} + +static void VKAPI_CALL destroy_instance(VkInstance instance, const VkAllocationCallbacks *allocator) { + PFN_vkGetInstanceProcAddr next = instance_of(instance).next; + pthread_mutex_lock(&lock); + struct instance_data *data = instance_by_key(key_of(instance)); + if (data) memset(data, 0, sizeof(*data)); + pthread_mutex_unlock(&lock); + PFN_vkDestroyInstance next_destroy = next ? (PFN_vkDestroyInstance)next(instance, "vkDestroyInstance") : NULL; + if (next_destroy) next_destroy(instance, allocator); +} + +static VkResult VKAPI_CALL time_domains_khr(VkPhysicalDevice physical, uint32_t *count, VkTimeDomainEXT *domains) { + PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT ext = instance_of(physical).time_domains; + if (!ext) { *count = 0; return VK_SUCCESS; } + return ext(physical, count, domains); +} + +/* BC formats sampleable below us although the driver's feature bit is off: the compat layer emulates them. */ +static int bc_emulated(VkPhysicalDevice physical) { + struct instance_data data = instance_of(physical); + if (!data.features || !data.format_properties) return 0; + VkPhysicalDeviceFeatures native; + data.features(physical, &native); + if (native.textureCompressionBC) return 0; + VkFormatProperties bc1, bc7; + data.format_properties(physical, VK_FORMAT_BC1_RGBA_UNORM_BLOCK, &bc1); + data.format_properties(physical, VK_FORMAT_BC7_UNORM_BLOCK, &bc7); + return (bc1.optimalTilingFeatures & bc7.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0; +} + +static void VKAPI_CALL get_features(VkPhysicalDevice physical, VkPhysicalDeviceFeatures *features) { + PFN_vkGetPhysicalDeviceFeatures next = instance_of(physical).features; + if (next) next(physical, features); + if (bc_emulated(physical)) features->textureCompressionBC = VK_TRUE; +} + +static void VKAPI_CALL get_features2(VkPhysicalDevice physical, VkPhysicalDeviceFeatures2 *features) { + PFN_vkGetPhysicalDeviceFeatures2 next = instance_of(physical).features2; + if (next) next(physical, features); + if (bc_emulated(physical)) features->features.textureCompressionBC = VK_TRUE; +} + +static int bc45(VkFormat format) { + return format >= VK_FORMAT_BC4_UNORM_BLOCK && format <= VK_FORMAT_BC5_SNORM_BLOCK; +} + +static void VKAPI_CALL get_format_properties(VkPhysicalDevice physical, VkFormat format, VkFormatProperties *out) { + PFN_vkGetPhysicalDeviceFormatProperties next = instance_of(physical).format_properties; + if (next) next(physical, format, out); + if (bc45(format) && (out->optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) + out->optimalTilingFeatures |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT; +} + +static void VKAPI_CALL get_format_properties2(VkPhysicalDevice physical, VkFormat format, VkFormatProperties2 *out) { + PFN_vkGetPhysicalDeviceFormatProperties2 next = instance_of(physical).format_properties2; + if (next) next(physical, format, out); + if (!bc45(format)) return; + if (out->formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) + out->formatProperties.optimalTilingFeatures |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT; + for (VkBaseOutStructure *p = (VkBaseOutStructure *)out->pNext; p; p = p->pNext) { + if (p->sType != VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3) continue; + VkFormatProperties3 *f3 = (VkFormatProperties3 *)p; + if (f3->optimalTilingFeatures & VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT) + f3->optimalTilingFeatures |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_FILTER_LINEAR_BIT; + } +} + +/* ---- device ---- */ + +/* The size of each structure a VkDeviceCreateInfo chain may hold (device_chain.inc, generated from the + * Vulkan registry), plus the loader's own; 0 for anything else. */ +static size_t chain_size(VkStructureType type) { + switch (type) { +#define DEVICE_CHAIN(stype, name) case stype: return sizeof(name); +#include "device_chain.inc" +#undef DEVICE_CHAIN + case VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO: return sizeof(VkLayerDeviceCreateInfo); + default: return 0; + } +} + +struct chain_copy { void **nodes; size_t count; }; + +static void free_chain_copy(struct chain_copy *copy) { + for (size_t i = 0; i < copy->count; i++) free(copy->nodes[i]); + free(copy->nodes); + copy->nodes = NULL; + copy->count = 0; +} + +/* The chain with textureCompressionBC cleared in a copy of the VkPhysicalDeviceFeatures2 that enables + * it: every structure up to it is copied into [copy], the rest is shared. The caller's structures are + * never written. *head_out stays [head] when nothing needs clearing, or when a structure ahead of it + * is unknown to this build (newer than its Vulkan headers); the compat layer then refuses the bit. */ +static VkResult chain_without_bc(const void *head, struct chain_copy *copy, const void **head_out) { + *head_out = head; + const VkBaseInStructure *target = NULL; + size_t count = 0; + for (const VkBaseInStructure *p = head; p && !target; p = p->pNext) { + if (!chain_size(p->sType)) return VK_SUCCESS; + count++; + if (p->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 && + ((const VkPhysicalDeviceFeatures2 *)p)->features.textureCompressionBC) target = p; + } + if (!target) return VK_SUCCESS; + if (!(copy->nodes = calloc(count, sizeof(*copy->nodes)))) return VK_ERROR_OUT_OF_HOST_MEMORY; + VkBaseOutStructure *first = NULL, *last = NULL; + for (const VkBaseInStructure *p = head; ; p = p->pNext) { + size_t size = chain_size(p->sType); + VkBaseOutStructure *node = malloc(size); + if (!node) { free_chain_copy(copy); return VK_ERROR_OUT_OF_HOST_MEMORY; } + copy->nodes[copy->count++] = node; + memcpy(node, p, size); + if (last) last->pNext = node; else first = node; + last = node; + if (p == target) { + ((VkPhysicalDeviceFeatures2 *)node)->features.textureCompressionBC = VK_FALSE; + *head_out = first; /* its pNext still leads to the caller's remaining structures */ + return VK_SUCCESS; + } + } +} + +static VkResult VKAPI_CALL create_device(VkPhysicalDevice physical, const VkDeviceCreateInfo *info, + const VkAllocationCallbacks *allocator, VkDevice *device) { + VkLayerDeviceCreateInfo *chain = (VkLayerDeviceCreateInfo *)info->pNext; + while (chain && !(chain->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && chain->function == VK_LAYER_LINK_INFO)) + chain = (VkLayerDeviceCreateInfo *)chain->pNext; + if (!chain || !chain->u.pLayerInfo) return VK_ERROR_INITIALIZATION_FAILED; + PFN_vkGetInstanceProcAddr next_gipa = chain->u.pLayerInfo->pfnNextGetInstanceProcAddr; + PFN_vkGetDeviceProcAddr next_gdpa = chain->u.pLayerInfo->pfnNextGetDeviceProcAddr; + chain->u.pLayerInfo = chain->u.pLayerInfo->pNext; + PFN_vkCreateDevice next_create = (PFN_vkCreateDevice)next_gipa(NULL, "vkCreateDevice"); + if (!next_create) return VK_ERROR_INITIALIZATION_FAILED; + + VkDeviceCreateInfo patched = *info; + /* An emulated textureCompressionBC never reaches the compat layer, which refuses the bit. */ + int strip_bc = bc_emulated(physical); + VkPhysicalDeviceFeatures plain_features; + if (strip_bc && info->pEnabledFeatures && info->pEnabledFeatures->textureCompressionBC) { + plain_features = *info->pEnabledFeatures; + plain_features.textureCompressionBC = VK_FALSE; + patched.pEnabledFeatures = &plain_features; + } + struct chain_copy copy = {0}; + if (strip_bc) { + VkResult copied = chain_without_bc(info->pNext, ©, &patched.pNext); + if (copied != VK_SUCCESS) return copied; + } + VkResult result = next_create(physical, &patched, allocator, device); + free_chain_copy(©); + if (result != VK_SUCCESS) return result; + + PFN_vkCreateSampler create_sampler = (PFN_vkCreateSampler)next_gdpa(*device, "vkCreateSampler"); + VkSamplerCreateInfo plain = { + .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, + .magFilter = VK_FILTER_LINEAR, .minFilter = VK_FILTER_LINEAR, + .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK, + }; + VkSampler fallback = VK_NULL_HANDLE; + if (create_sampler) create_sampler(*device, &plain, NULL, &fallback); + struct device_data data = { + .key = key_of(*device), + .handle = *device, + .next = next_gdpa, + .create_sampler = create_sampler, + .destroy_sampler = (PFN_vkDestroySampler)next_gdpa(*device, "vkDestroySampler"), + .create_set_layout = (PFN_vkCreateDescriptorSetLayout)next_gdpa(*device, "vkCreateDescriptorSetLayout"), + .destroy_device = (PFN_vkDestroyDevice)next_gdpa(*device, "vkDestroyDevice"), + .timestamps = (PFN_vkGetCalibratedTimestampsEXT)next_gdpa(*device, "vkGetCalibratedTimestampsEXT"), + .fallback = fallback, + }; + pthread_mutex_lock(&lock); + for (int i = 0; i < MAX_OBJECTS; i++) + if (!devices[i].handle) { devices[i] = data; break; } + pthread_mutex_unlock(&lock); + return result; +} + +static void VKAPI_CALL destroy_device(VkDevice device, const VkAllocationCallbacks *allocator) { + struct device_data data = device_of(device); + pthread_mutex_lock(&lock); + struct device_data *entry = device_by_key(key_of(device)); + if (entry) memset(entry, 0, sizeof(*entry)); + for (size_t k = 0; k < ycbcr_count;) + if (ycbcr_samplers[k].device == device) ycbcr_samplers[k] = ycbcr_samplers[--ycbcr_count]; + else k++; + pthread_mutex_unlock(&lock); + if (data.fallback && data.destroy_sampler) data.destroy_sampler(device, data.fallback, NULL); + if (data.destroy_device) data.destroy_device(device, allocator); +} + +static VkResult VKAPI_CALL timestamps_khr(VkDevice device, uint32_t count, const VkCalibratedTimestampInfoEXT *infos, + uint64_t *timestamps, uint64_t *deviation) { + PFN_vkGetCalibratedTimestampsEXT ext = device_of(device).timestamps; + return ext ? ext(device, count, infos, timestamps, deviation) : VK_ERROR_FEATURE_NOT_PRESENT; +} + +static VkResult VKAPI_CALL create_sampler(VkDevice device, const VkSamplerCreateInfo *info, + const VkAllocationCallbacks *allocator, VkSampler *sampler) { + PFN_vkCreateSampler next = device_of(device).create_sampler; + if (!next) return VK_ERROR_INITIALIZATION_FAILED; + VkResult result = next(device, info, allocator, sampler); + if (result != VK_SUCCESS) return result; + int ycbcr = 0; + for (const VkBaseInStructure *p = info->pNext; p && !ycbcr; p = p->pNext) + ycbcr = p->sType == VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO; + if (!ycbcr) return result; + pthread_mutex_lock(&lock); + if (ycbcr_count == ycbcr_capacity) { + size_t capacity = ycbcr_capacity ? ycbcr_capacity * 2 : 16; + struct ycbcr_sampler *grown = realloc(ycbcr_samplers, capacity * sizeof(*grown)); + if (!grown) { + pthread_mutex_unlock(&lock); + /* An untracked YCbCr sampler would reach a compute layout unreplaced: fail instead. */ + PFN_vkDestroySampler destroy = device_of(device).destroy_sampler; + if (destroy) destroy(device, *sampler, allocator); + *sampler = VK_NULL_HANDLE; + return VK_ERROR_OUT_OF_HOST_MEMORY; + } + ycbcr_samplers = grown; + ycbcr_capacity = capacity; + } + ycbcr_samplers[ycbcr_count++] = (struct ycbcr_sampler){device, *sampler}; + pthread_mutex_unlock(&lock); + return result; +} + +static void VKAPI_CALL destroy_sampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks *allocator) { + pthread_mutex_lock(&lock); + for (size_t k = 0; k < ycbcr_count; k++) + if (ycbcr_samplers[k].device == device && ycbcr_samplers[k].sampler == sampler) { + ycbcr_samplers[k] = ycbcr_samplers[--ycbcr_count]; + break; + } + pthread_mutex_unlock(&lock); + PFN_vkDestroySampler next = device_of(device).destroy_sampler; + if (next) next(device, sampler, allocator); +} + +/* Called with lock held. */ +static int is_ycbcr(VkDevice device, VkSampler sampler) { + for (size_t k = 0; sampler && k < ycbcr_count; k++) + if (ycbcr_samplers[k].device == device && ycbcr_samplers[k].sampler == sampler) return 1; + return 0; +} + +static VkResult VKAPI_CALL create_set_layout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *info, + const VkAllocationCallbacks *allocator, VkDescriptorSetLayout *layout) { + struct device_data data = device_of(device); + if (!data.create_set_layout) return VK_ERROR_INITIALIZATION_FAILED; + int replace = 0; + pthread_mutex_lock(&lock); + for (uint32_t b = 0; data.fallback && b < info->bindingCount && !replace; b++) { + const VkDescriptorSetLayoutBinding *binding = &info->pBindings[b]; + if (!(binding->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) || !binding->pImmutableSamplers) continue; + for (uint32_t s = 0; s < binding->descriptorCount; s++) + if (is_ycbcr(device, binding->pImmutableSamplers[s])) { replace = 1; break; } + } + pthread_mutex_unlock(&lock); + if (!replace) return data.create_set_layout(device, info, allocator, layout); + + VkResult result = VK_ERROR_OUT_OF_HOST_MEMORY; + VkDescriptorSetLayoutBinding *bindings = calloc(info->bindingCount, sizeof(*bindings)); + VkSampler **arrays = calloc(info->bindingCount, sizeof(*arrays)); + if (!bindings || !arrays) goto done; + for (uint32_t b = 0; b < info->bindingCount; b++) { + bindings[b] = info->pBindings[b]; + if (!(bindings[b].stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) || !bindings[b].pImmutableSamplers) continue; + /* Without the replacement the driver would see the samplers it cannot compile: fail instead. */ + if (!(arrays[b] = malloc(bindings[b].descriptorCount * sizeof(VkSampler)))) goto done; + pthread_mutex_lock(&lock); + for (uint32_t s = 0; s < bindings[b].descriptorCount; s++) { + VkSampler original = bindings[b].pImmutableSamplers[s]; + arrays[b][s] = is_ycbcr(device, original) ? data.fallback : original; + } + pthread_mutex_unlock(&lock); + bindings[b].pImmutableSamplers = arrays[b]; + } + VkDescriptorSetLayoutCreateInfo patched = *info; + patched.pBindings = bindings; + result = data.create_set_layout(device, &patched, allocator, layout); + if (debug) fprintf(stderr, "xclipse layer: compute YCbCr immutable samplers replaced (%d)\n", result); +done: + for (uint32_t b = 0; arrays && b < info->bindingCount; b++) free(arrays[b]); + free(arrays); + free(bindings); + return result; +} + +/* ---- dispatch ---- */ + +static PFN_vkVoidFunction device_hook(const char *name) { + if (!strcmp(name, "vkGetDeviceProcAddr")) return NULL; /* handled by the caller */ + if (!strcmp(name, "vkDestroyDevice")) return (PFN_vkVoidFunction)destroy_device; + if (!strcmp(name, "vkCreateSampler")) return (PFN_vkVoidFunction)create_sampler; + if (!strcmp(name, "vkDestroySampler")) return (PFN_vkVoidFunction)destroy_sampler; + if (!strcmp(name, "vkCreateDescriptorSetLayout")) return (PFN_vkVoidFunction)create_set_layout; + if (!strcmp(name, "vkGetCalibratedTimestampsKHR")) return (PFN_vkVoidFunction)timestamps_khr; + return NULL; +} + +EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *name) { + if (!strcmp(name, "vkGetDeviceProcAddr")) return (PFN_vkVoidFunction)vkGetDeviceProcAddr; + PFN_vkVoidFunction hook = device_hook(name); + if (hook) return hook; + struct device_data data = device ? device_of(device) : (struct device_data){0}; + return data.next ? data.next(device, name) : NULL; +} + +EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *name) { + if (!strcmp(name, "vkGetInstanceProcAddr")) return (PFN_vkVoidFunction)vkGetInstanceProcAddr; + if (!strcmp(name, "vkCreateInstance")) return (PFN_vkVoidFunction)create_instance; + if (!strcmp(name, "vkDestroyInstance")) return (PFN_vkVoidFunction)destroy_instance; + if (!strcmp(name, "vkCreateDevice")) return (PFN_vkVoidFunction)create_device; + if (!strcmp(name, "vkGetDeviceProcAddr")) return (PFN_vkVoidFunction)vkGetDeviceProcAddr; + if (!strcmp(name, "vkGetPhysicalDeviceFeatures")) return (PFN_vkVoidFunction)get_features; + if (!strcmp(name, "vkGetPhysicalDeviceFeatures2") || !strcmp(name, "vkGetPhysicalDeviceFeatures2KHR")) + return (PFN_vkVoidFunction)get_features2; + if (!strcmp(name, "vkGetPhysicalDeviceCalibrateableTimeDomainsKHR")) return (PFN_vkVoidFunction)time_domains_khr; + if (!strcmp(name, "vkGetPhysicalDeviceFormatProperties")) return (PFN_vkVoidFunction)get_format_properties; + if (!strcmp(name, "vkGetPhysicalDeviceFormatProperties2") || !strcmp(name, "vkGetPhysicalDeviceFormatProperties2KHR")) + return (PFN_vkVoidFunction)get_format_properties2; + PFN_vkVoidFunction hook = device_hook(name); + if (hook) return hook; + PFN_vkGetInstanceProcAddr next = instance ? instance_of(instance).next : NULL; + return next ? next(instance, name) : NULL; +} + +EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *negotiate) { + if (!negotiate || negotiate->loaderLayerInterfaceVersion < 2) return VK_ERROR_INITIALIZATION_FAILED; + debug = getenv("DROIDDECK_XCLIPSE_LAYER_DEBUG") != NULL; + negotiate->loaderLayerInterfaceVersion = 2; + negotiate->pfnGetInstanceProcAddr = vkGetInstanceProcAddr; + negotiate->pfnGetDeviceProcAddr = vkGetDeviceProcAddr; + negotiate->pfnGetPhysicalDeviceProcAddr = NULL; + return VK_SUCCESS; +} diff --git a/tools/local-cross.Dockerfile b/tools/local-cross.Dockerfile index 653ad2b2c3..badaaf5efe 100644 --- a/tools/local-cross.Dockerfile +++ b/tools/local-cross.Dockerfile @@ -3,7 +3,7 @@ FROM ubuntu:24.04 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update \ - && apt-get install -y binutils gcc g++ python3 zstd unzip \ + && apt-get install -y binutils gcc g++ libvulkan-dev python3 zstd unzip \ && if [ "$(uname -m)" = aarch64 ]; then \ for tool in gcc g++ strip readelf objdump ar; do ln -s "$(command -v $tool)" /usr/local/bin/aarch64-linux-gnu-$tool; done; \ else \ diff --git a/tools/mangoapp/mangoapp b/tools/mangoapp/mangoapp index 0a208fef39..755a7e44da 100644 --- a/tools/mangoapp/mangoapp +++ b/tools/mangoapp/mangoapp @@ -8,4 +8,11 @@ if [ "$(wc -l < "$starts")" -gt 5 ]; then echo "mangoapp: started $(wc -l < "$starts") times in 60 s; the performance overlay stays off for this session" >&2 exec sleep infinity fi +# The system PowerVR route (BL_POWERVR_RENDER_NODE): Zink could not make mangoapp a swapchain there +# ("zink: could not create swapchain", then GLXBadCurrentWindow) and it crashed at every start. The +# overlay is a few text lines: llvmpipe draws it. +if [ -n "${BL_POWERVR_RENDER_NODE:-}" ]; then + export GALLIUM_DRIVER=llvmpipe LIBGL_ALWAYS_SOFTWARE=1 + unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2 +fi LD_LIBRARY_PATH=/usr/local/lib/mangoapp${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} exec /usr/local/lib/mangoapp/mangoapp "$@" diff --git a/tools/pixel_reset_diagnostics.py b/tools/pixel_reset_diagnostics.py new file mode 100644 index 0000000000..462b9d4607 --- /dev/null +++ b/tools/pixel_reset_diagnostics.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +"""Read-only reboot projection. Never writes raw Android logs or account data. + +This is evidence collection, not a GPU fault injector or a root-cause oracle. +The optional kernel projection reads only SYSTEM_LAST_KMSG after user unlock. +It emits fixed categories and numeric hardware fields, never arbitrary log lines. +""" +import argparse +from datetime import datetime, timezone +import json +import os +from pathlib import Path +import re +import subprocess +from zoneinfo import ZoneInfo, ZoneInfoNotFoundError + +ENTRY = re.compile(r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\s+(SYSTEM_LAST_KMSG)\b', re.M) +CATEGORIES = ('GNOC', 'PVRSRV', 'watchdog', 'IOMMU', 'S2MPU', 'access control', 'Kernel panic', 'HWR', 'GPU fault') +PRIMARY_USER_STATES = frozenset(('RUNNING_LOCKED', 'RUNNING_UNLOCKING', 'RUNNING_UNLOCKED')) +# Exact canonical reasons plus the vendor reason observed in the bounded Pixel +# tests. Unrecognized/custom suffixes are not diagnostic output categories. +BOOT_REASONS = frozenset(('cold', 'hard', 'warm', 'reboot', 'shutdown', + 'recovery', 'bootloader', 'kernel_panic', 'watchdog', + 'reset,warm,gnoc_error')) + + +def primary_state(text): + match = re.search(r'Started users state: \[0=([A-Z_]+)(?=[,\]])', text) + return match.group(1) if match and match.group(1) in PRIMARY_USER_STATES else 'unknown' + + +def safe_reason(text): + value = text.strip() + return value if value in BOOT_REASONS else 'unknown' + + +def kernel_projection(text, device_timezone, after=None): + entries = list(ENTRY.finditer(text)) + result = {'metadata_dates': [m.group(1) for m in entries], 'raw_body_saved': False, + 'root_cause_proven': False} + if not entries: + result['status'] = 'no_accessible_entry' + return result + latest = max(enumerate(entries), key=lambda row: row[1].group(1)) + index, match = latest + body = text[match.end():entries[index + 1].start() if index + 1 < len(entries) else len(text)] + result['entry_date_device_local'] = match.group(1) + try: + naive = datetime.strptime(match.group(1), '%Y-%m-%d %H:%M:%S') + zone = ZoneInfo(device_timezone) + except (ValueError, ZoneInfoNotFoundError): + result['status'] = 'unknown_device_timezone' + return result + # Dropbox supplies a local wall clock without an offset. Round-trip both + # folds: a repeated hour has two possible instants; a skipped hour has none. + instants = {local.astimezone(timezone.utc) + for fold in (0, 1) + for local in (naive.replace(tzinfo=zone, fold=fold),) + if local.astimezone(timezone.utc).astimezone(zone).replace(tzinfo=None) == naive} + if len(instants) != 1: + result['status'] = ('ambiguous_device_local_time' if instants + else 'nonexistent_device_local_time') + return result + local = instants.pop() + result['entry_date_utc'] = local.isoformat() + if after is not None and local < after: + result['status'] = 'stale_entry_not_attributed_to_current_trial' + return result + result['status'] = 'projected_entry_not_a_root_cause' + result['categories'] = {key: len(re.findall(re.escape(key), body, re.I)) for key in CATEGORIES} + patterns = { + 'gnoc_addresses': r'Error from GNOC at addr (0x[0-9a-fA-F]+)', + 'gnoc_error_types': r'GNOC error type (0x[0-9a-fA-F]+)', + 'firmware_reboot_codes': r'Reboot reason:\s+(0x[0-9a-fA-F]+)', + 'access_control_addresses': r'Access Control Error \((0x[0-9a-fA-F]+)', + } + result['hardware_fields'] = {key: sorted(set(re.findall(pattern, body))) for key, pattern in patterns.items()} + # Read the complete value, not just a recognized-looking prefix. Apply the + # same fixed projection as getprop; no arbitrary kernel reason text escapes. + reasons = re.findall(r'Last boot reason:[ \t]*([^\r\n]*)', body) + result['last_boot_reasons'] = sorted({safe_reason(reason) for reason in reasons}) + return result + + +def collect(adb, serial, include_kernel=False, after=None): + def shell(*args): + try: + process = subprocess.run([adb, '-s', serial, 'shell', *args], capture_output=True, + text=True, timeout=20) + except (OSError, subprocess.TimeoutExpired): + return None, '' + # No command stderr is copied to output: it may contain unrelated data. + return process.returncode, process.stdout if process.returncode == 0 else '' + + result = {'at': datetime.now(timezone.utc).isoformat(), 'read_only': True, + 'raw_logs_saved': False, 'credentials_collected': False} + code, value = shell('settings', 'get', 'global', 'boot_count') + result['boot_count'] = int(value.strip()) if code == 0 and value.strip().isdigit() else None + code, value = shell('getprop', 'ro.boot.bootreason') + result['bootloader_reason'] = safe_reason(value) + code, value = shell('getprop', 'sys.boot.reason') + result['system_boot_reason'] = safe_reason(value) + code, value = shell('dumpsys', 'user') + result['primary_user_state'] = primary_state(value) + code, value = shell('getprop', 'persist.sys.timezone') + device_timezone = value.strip() + try: + ZoneInfo(device_timezone) + result['device_timezone'] = device_timezone + except (ValueError, ZoneInfoNotFoundError): + result['device_timezone'] = 'unknown' + code, value = shell('dumpsys', 'dropbox', 'SYSTEM_LAST_KMSG') + result['kernel_metadata_dates'] = [m.group(1) for m in ENTRY.finditer(value)] + if include_kernel: + if result['primary_user_state'] != 'RUNNING_UNLOCKED': + result['kernel'] = {'status': 'requires_user_unlock', 'raw_body_saved': False} + else: + code, value = shell('dumpsys', 'dropbox', '--print', 'SYSTEM_LAST_KMSG') + result['kernel'] = kernel_projection(value, result['device_timezone'], after) + result['kernel']['read_exit_code'] = code + return result + + +def write_private_output(path, output): + # Exclusive creation also rejects existing symlinks. Set the private mode + # before any bytes are written, rather than chmod after exposing the data. + flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, 'O_NOFOLLOW', 0) + descriptor = os.open(path, flags, 0o600) + with os.fdopen(descriptor, 'w', encoding='utf-8') as stream: + stream.write(output) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--adb', default='adb') + parser.add_argument('--serial', required=True) + parser.add_argument('--kernel', action='store_true') + parser.add_argument('--after', help='Earliest relevant UTC ISO timestamp; excludes stale kernel entries') + parser.add_argument('--output', type=Path, help='New JSON file; refuses to overwrite') + args = parser.parse_args() + after = datetime.fromisoformat(args.after.replace('Z', '+00:00')) if args.after else None + if after is not None and after.tzinfo is None: + parser.error('--after must include a timezone') + result = collect(args.adb, args.serial, args.kernel, after) + output = json.dumps(result, indent=2) + '\n' + if args.output: + write_private_output(args.output, output) + print(output, end='') + + +if __name__ == '__main__': + main() diff --git a/tools/powervr/fetch.py b/tools/powervr/fetch.py new file mode 100644 index 0000000000..75c8b539e0 --- /dev/null +++ b/tools/powervr/fetch.py @@ -0,0 +1,366 @@ +#!/usr/bin/env python3 +"""Assemble the pinned PowerVR components into the APK's isolated Linux runtime. + +Like DirectAudio, APK builds download published components rather than compile +them. Their source, licenses and patches travel with the payload. Build recipes +remain in tools/{hybris,dxvk,vulkan-wsi}; release.json pins their reviewed inputs. +""" +import argparse +import hashlib +import io +import json +import os +from pathlib import Path, PurePosixPath +import posixpath +import re +import stat +import subprocess +import tarfile +import tempfile +from urllib.parse import urlparse +from urllib.request import urlopen +from zipfile import ZipFile + + +ROOT = Path(__file__).resolve().parents[2] +ASSETS = Path("app/src/main/assets/hybris") +REQUIRED_LIBRARIES = ( + "lib/libhybris-vulkan-icd.so.0", "lib/libhybris-common.so.1", + "lib/libhybris/linker/q.so", "lib/libVkLayer_hybris_compat.so", + "wsi/libVkLayer_window_system_integration.so", +) +MAX_UNPACKED = 256 * 1024 * 1024 +BUNDLED_LICENSES = { + 'tools/vulkan-wsi/licenses/Vulkan-Headers/' + name: 'licenses/Vulkan-Headers/' + name + for name in ('LICENSE.md', 'MIT.txt') +} + + +def sha256(data): + return hashlib.sha256(data).hexdigest() + + +def json_bytes(value): + return (json.dumps(value, sort_keys=True, indent=2) + "\n").encode() + + +def safe_name(name): + path = PurePosixPath(name) + if not name or path.is_absolute() or ".." in path.parts or "\\" in name: + raise ValueError("unsafe archive path: " + name) + return str(path) + + +def check_tree(entries): + # Never extract through a symlink, even one pointing inside the tree. + for name, entry in entries.items(): + for parent in PurePosixPath(name).parents: + if str(parent) in entries: + raise ValueError("archive member below a file or symlink: " + name) + if entry[0] == "symlink": + read(entries, name) + + +def read(entries, name, seen=()): + if name in seen or len(seen) > 16: + raise ValueError("runtime symlink cycle: " + name) + if name not in entries: + raise ValueError("missing runtime file: " + name) + kind, mode, data = entries[name] + if kind == "symlink": + if PurePosixPath(data).is_absolute() or "\\" in data: + raise ValueError("unsafe runtime symlink: " + name) + target = safe_name(posixpath.normpath(posixpath.join(posixpath.dirname(name), data))) + return read(entries, target, (*seen, name)) + return data + + +def read_tar(data): + unpacked = subprocess.run(["zstd", "-q", "-dc"], input=data, + capture_output=True, check=True).stdout + if len(unpacked) > MAX_UNPACKED: + raise ValueError("runtime archive exceeds size limit") + entries, seen = {}, set() + with tarfile.open(fileobj=io.BytesIO(unpacked)) as package: + for member in package: + name = safe_name(member.name) + if name in seen: + raise ValueError("duplicate archive path: " + name) + seen.add(name) + if member.isdir(): + continue + if name == ".": + raise ValueError("archive root must be a directory") + if member.issym(): + entries[name] = ("symlink", 0o777, member.linkname) + elif member.isfile(): + entries[name] = ("file", 0o755 if member.mode & 0o111 else 0o644, + package.extractfile(member).read()) + else: + raise ValueError("unsupported archive entry type: " + name) + check_tree(entries) + return entries + + +def tree_digest(entries): + return sha256(json_bytes({name: [kind, mode, sha256(data) if kind == "file" else data] + for name, (kind, mode, data) in sorted(entries.items())})) + + +def load_release(root): + release = json.loads((root / "tools/powervr/release.json").read_bytes()) + if release.get("format") != 1: + raise ValueError("unsupported PowerVR release pins") + # These identify the reviewed recipe, not a new attestation from the old + # producer. The original build metadata is preserved inside the runtime. + for component in [release["hybris"], *release["archives"]]: + for name, expected in component["recipe_inputs"].items(): + if sha256((root / name).read_bytes()) != expected: + raise ValueError("PowerVR component recipe changed; update its release pin: " + name) + return release + + +def assembly_inputs(root): + return {"format": 1, "inputs": { + name: sha256((root / name).read_bytes()) for name in + ("tools/powervr/release.json", "tools/powervr/fetch.py", "tools/hybris/run-proton.py", *BUNDLED_LICENSES)}} + + +def fetch(component, cache): + url = component["url"] + if urlparse(url).scheme != "https": + raise ValueError("component URL must use HTTPS") + cache.mkdir(parents=True, exist_ok=True) + target = cache / (component["sha256"] + "-" + PurePosixPath(urlparse(url).path).name) + + def valid(path): + return (path.is_file() and path.stat().st_size == component["size"] + and sha256(path.read_bytes()) == component["sha256"]) + + if valid(target): + return target.read_bytes() + # No unverified response is ever parsed or promoted into the cache. + with tempfile.NamedTemporaryFile(dir=cache, prefix=".download-", delete=False) as output: + temporary = Path(output.name) + try: + with urlopen(url, timeout=60) as response: + remaining = component["size"] + while block := response.read(min(1024 * 1024, remaining + 1)): + remaining -= len(block) + if remaining < 0: + raise ValueError("component download exceeds pinned size") + output.write(block) + output.flush() + if not valid(temporary): + raise ValueError("component download checksum mismatch: " + url) + os.replace(temporary, target) + finally: + temporary.unlink(missing_ok=True) + return target.read_bytes() + + +def read_zip(data, component): + entries, seen = {}, set() + expected = {item["name"]: item for item in component["files"]} + allowed = set(expected) | set(component["ignored"]) + total = 0 + with ZipFile(io.BytesIO(data)) as archive: + for member in archive.infolist(): + name = safe_name(member.filename) + if name in seen: + raise ValueError("duplicate archive path: " + name) + seen.add(name) + mode = member.external_attr >> 16 + kind = stat.S_IFMT(mode) + if member.is_dir() and kind in (0, stat.S_IFDIR): + continue + if kind not in (0, stat.S_IFREG) or name not in allowed: + raise ValueError("unexpected component archive entry: " + name) + total += member.file_size + if total > MAX_UNPACKED: + raise ValueError("component archive exceeds size limit") + if name not in expected: + continue + pin = expected[name] + content = archive.read(member) + if len(content) != pin["size"] or sha256(content) != pin["sha256"]: + raise ValueError("component member checksum mismatch: " + name) + path = safe_name(pin["path"]) + if path in entries: + raise ValueError("duplicate component destination: " + path) + entries[path] = ("file", pin["mode"], content) + if set(expected) - seen: + raise ValueError("component archive missing files: " + ", ".join(sorted(set(expected) - seen))) + check_tree(entries) + return entries + + +def read_tar_gz(data, component): + """An upstream release tarball, held to the same per-file pins as a CI archive.""" + entries, seen = {}, set() + expected = {item["name"]: item for item in component["files"]} + allowed = set(expected) | set(component["ignored"]) + total = 0 + with tarfile.open(fileobj=io.BytesIO(data), mode="r:gz") as archive: + for member in archive: + name = safe_name(member.name) + if name in seen: + raise ValueError("duplicate archive path: " + name) + seen.add(name) + if member.isdir(): + continue + if not member.isfile() or name not in allowed: + raise ValueError("unexpected component archive entry: " + name) + total += member.size + if total > MAX_UNPACKED: + raise ValueError("component archive exceeds size limit") + if name not in expected: + continue + pin = expected[name] + content = archive.extractfile(member).read() + if len(content) != pin["size"] or sha256(content) != pin["sha256"]: + raise ValueError("component member checksum mismatch: " + name) + path = safe_name(pin["path"]) + if path in entries: + raise ValueError("duplicate component destination: " + path) + entries[path] = ("file", pin["mode"], content) + if set(expected) - seen: + raise ValueError("component archive missing files: " + ", ".join(sorted(set(expected) - seen))) + check_tree(entries) + return entries + + +def read_component(data, component): + kind = component.get("format", "zip") + if kind == "zip": + return read_zip(data, component) + if kind == "tar.gz": + return read_tar_gz(data, component) + raise ValueError("unsupported component archive format: " + kind) + + +def check_bundle(entries, release, root): + check_tree(entries) + if read(entries, "assembly-inputs.json") != json_bytes(assembly_inputs(root)): + raise ValueError("PowerVR assembly inputs changed; run tools/powervr/fetch.py") + if entries["run-proton.py"] != ("file", 0o755, (root / "tools/hybris/run-proton.py").read_bytes()): + raise ValueError("PowerVR Proton wrapper is stale or not executable") + compile(read(entries, "run-proton.py"), "run-proton.py", "exec") + bridge = dict(entries) + del bridge["assembly-inputs.json"], bridge["run-proton.py"] + for source, target in BUNDLED_LICENSES.items(): + if entries.get(target) != ("file", 0o644, (root / source).read_bytes()): + raise ValueError("Vulkan-Headers license missing or stale: " + target) + for component in release["archives"]: + for pin in component["files"]: + content = read(entries, pin["path"]) + if (entries[pin["path"]][:2] != ("file", pin["mode"]) + or len(content) != pin["size"] or sha256(content) != pin["sha256"]): + raise ValueError("PowerVR component mismatch: " + pin["path"]) + del bridge[pin["path"]] + for target in BUNDLED_LICENSES.values(): + bridge.pop(target, None) + if tree_digest(bridge) != release["hybris"]["tree_sha256"]: + raise ValueError("PowerVR bridge differs from the pinned archive") + for name in REQUIRED_LIBRARIES: + content = read(entries, name) + if content[:6] != b"\x7fELF\x02\x01" or content[18:20] != b"\xb7\x00": + raise ValueError("runtime library is not ELF64 AArch64: " + name) + # dxvk/ is the default payload; run-proton.py can select another dxvk-* sibling by name. + payloads = sorted({name.split("/")[0] for name in entries if re.fullmatch(r"dxvk[^/]*/x(32|64)/[^/]+\.dll", name)}) + if "dxvk" not in payloads: + raise ValueError("default DXVK payload missing") + for payload in payloads: + for architecture, machine, magic in (("x32", b"\x4c\x01", b"\x0b\x01"), + ("x64", b"\x64\x86", b"\x0b\x02")): + for name in ("d3d8.dll", "d3d9.dll", "d3d10core.dll", "d3d11.dll", "dxgi.dll"): + path = payload + "/" + architecture + "/" + name + content = read(entries, path) + pe = int.from_bytes(content[60:64], "little") + if (content[:2] != b"MZ" or pe < 64 or content[pe:pe + 4] != b"PE\0\0" + or content[pe + 4:pe + 6] != machine or content[pe + 24:pe + 26] != magic): + raise ValueError("DXVK library has wrong PE architecture: " + path) + + +def pack(entries): + stream = io.BytesIO() + directories = {str(parent) for name in entries for parent in PurePosixPath(name).parents + if str(parent) != "."} + with tarfile.open(fileobj=stream, mode="w", format=tarfile.USTAR_FORMAT) as archive: + for name in sorted(directories | set(entries)): + info = tarfile.TarInfo(name) + info.mtime = info.uid = info.gid = 0 + if name in directories: + info.type, info.mode = tarfile.DIRTYPE, 0o755 + archive.addfile(info) + continue + kind, info.mode, data = entries[name] + if kind == "symlink": + info.type, info.linkname = tarfile.SYMTYPE, data + archive.addfile(info) + else: + info.size = len(data) + archive.addfile(info, io.BytesIO(data)) + return subprocess.run(["zstd", "-q", "-10", "-T1", "-c"], input=stream.getvalue(), + capture_output=True, check=True).stdout + + +def verify_archive(archive, version, root=ROOT): + release = load_release(root) + if sha256(archive) != version.strip(): + raise ValueError("PowerVR runtime archive checksum mismatch") + check_bundle(read_tar(archive), release, root) + + +def verify(root=ROOT): + verify_archive((root / ASSETS / "runtime.tzst").read_bytes(), + (root / ASSETS / "version.txt").read_text(), root) + + +def assemble(root, cache): + release = load_release(root) + entries = read_tar(fetch(release["hybris"], cache)) + if tree_digest(entries) != release["hybris"]["tree_sha256"]: + raise ValueError("PowerVR bridge tree checksum mismatch") + for component in release["archives"]: + additions = read_component(fetch(component, cache), component) + if set(entries) & set(additions): + raise ValueError("component overwrites existing runtime files") + entries.update(additions) + for source, target in BUNDLED_LICENSES.items(): + license_entry = ("file", 0o644, (root / source).read_bytes()) + if target in entries and entries[target] != license_entry: + raise ValueError("bundled license overwrites component file: " + target) + entries[target] = license_entry + entries["run-proton.py"] = ("file", 0o755, (root / "tools/hybris/run-proton.py").read_bytes()) + entries["assembly-inputs.json"] = ("file", 0o644, json_bytes(assembly_inputs(root))) + check_bundle(entries, release, root) + archive = pack(entries) + assets = root / ASSETS + assets.mkdir(parents=True, exist_ok=True) + with tempfile.TemporaryDirectory(dir=assets.parent, prefix=".hybris-") as directory: + stage = Path(directory) + (stage / "runtime.tzst").write_bytes(archive) + (stage / "version.txt").write_text(sha256(archive) + "\n") + # version.txt is the readiness marker; an interrupted replacement fails + # closed instead of presenting a partially updated payload as ready. + (assets / "version.txt").unlink(missing_ok=True) + os.replace(stage / "runtime.tzst", assets / "runtime.tzst") + os.replace(stage / "version.txt", assets / "version.txt") + print("PowerVR runtime prepared: " + sha256(archive)) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--verify", action="store_true") + parser.add_argument("--cache-dir", type=Path, default=Path(os.environ.get( + "DROIDDECK_BUILD_CACHE", str(Path.home() / ".cache/droiddeck-build")))) + args = parser.parse_args() + if args.verify: + verify() + else: + assemble(ROOT, args.cache_dir) + + +if __name__ == "__main__": + main() diff --git a/tools/powervr/release.json b/tools/powervr/release.json new file mode 100644 index 0000000000..749eb2f732 --- /dev/null +++ b/tools/powervr/release.json @@ -0,0 +1,335 @@ +{ + "archives": [ + { + "files": [ + { + "mode": 493, + "name": "x32/d3d8.dll", + "path": "dxvk/x32/d3d8.dll", + "sha256": "c9612be6aac99390156cdcd3b22054fba62cf68bfc948d753cc39282d37f67ab", + "size": 1658894 + }, + { + "mode": 493, + "name": "x32/d3d9.dll", + "path": "dxvk/x32/d3d9.dll", + "sha256": "fbd0e7d7aae39d5d623757ead228930c4be78cb3b16db6f352796577831ce36e", + "size": 7598094 + }, + { + "mode": 493, + "name": "x32/d3d10core.dll", + "path": "dxvk/x32/d3d10core.dll", + "sha256": "cd6052b1f6a02ab94fea5bfa3519e556fb353f585da4b64e3c810ef4cc37c808", + "size": 192526 + }, + { + "mode": 493, + "name": "x32/d3d11.dll", + "path": "dxvk/x32/d3d11.dll", + "sha256": "9bf51b5ab913e1bd84513b2b1608586bc0a651788df9e664b8135840b8c8c54d", + "size": 7942158 + }, + { + "mode": 493, + "name": "x32/dxgi.dll", + "path": "dxvk/x32/dxgi.dll", + "sha256": "d3772dc86267fe94eee7afc30c993f44297fd43b50210f1691f3d03ebf4d4402", + "size": 5738510 + }, + { + "mode": 493, + "name": "x64/d3d8.dll", + "path": "dxvk/x64/d3d8.dll", + "sha256": "cd870a8f5cdbfef33e7ccf7884d6f1c442e2c8ec22d6adea60fea3dbe83c32e2", + "size": 1499136 + }, + { + "mode": 493, + "name": "x64/d3d9.dll", + "path": "dxvk/x64/d3d9.dll", + "sha256": "4f80af96991073bb3dc25f3b93ec2c07ba25fcabb8a6e30ffd5eaae38c8465c7", + "size": 6934528 + }, + { + "mode": 493, + "name": "x64/d3d10core.dll", + "path": "dxvk/x64/d3d10core.dll", + "sha256": "4950e952ca291b13c0645322f1831414e77df87183ed2f81d5dde02c1fd43ff9", + "size": 978944 + }, + { + "mode": 493, + "name": "x64/d3d11.dll", + "path": "dxvk/x64/d3d11.dll", + "sha256": "3497d5f7dc78fa7affdba6777d3ab4aac7ec744d7e2c795fbf07dbff54058e6c", + "size": 7143424 + }, + { + "mode": 493, + "name": "x64/dxgi.dll", + "path": "dxvk/x64/dxgi.dll", + "sha256": "d6e0ca242dba6cb8606106a7fcb65268225520f03c68e36a365f44d65f863e74", + "size": 5230592 + }, + { + "mode": 420, + "name": "LICENSE", + "path": "licenses/dxvk-LICENSE", + "sha256": "a5cb1a6ded7d2d7e92d550ba28edd21be2d1d4044662b399887351023e30ce64", + "size": 1074 + }, + { + "mode": 420, + "name": "source-commit", + "path": "provenance/dxvk-source-commit", + "sha256": "cb748e54f2fcdca516189435647ea001dbd14f97e2df5b36fd2f13fc185a5dbf", + "size": 41 + }, + { + "mode": 420, + "name": "SHA256SUMS", + "path": "provenance/dxvk-SHA256SUMS", + "sha256": "8a106cb90288052cc91768b569980ed7381c89591fb7cea3bc6d0312c6f30a47", + "size": 802 + }, + { + "mode": 420, + "name": "downstream.patch", + "path": "licenses/dxvk-downstream.patch", + "sha256": "e44b8d656a37c3b1059bbf3dcbcf11922a00634301f2509024fb263a45e9f50e", + "size": 3604 + }, + { + "mode": 420, + "name": "source.tar.zst", + "path": "licenses/dxvk-source.tar.zst", + "sha256": "dfdebe8aa71b85af638f2565c1d5abe31417c6db643a827bcf0988e29ded55e7", + "size": 6043001 + }, + { + "mode": 420, + "name": "submodules.txt", + "path": "provenance/dxvk-submodules.txt", + "sha256": "01e74c750ca473590e17f1ca33f204b8272f84898ee6e8a8509be9740919092c", + "size": 472 + } + ], + "id": "dxvk", + "ignored": [ + "x32/d3d10core.dll.a", + "x32/d3d11.dll.a", + "x32/d3d8.dll.a", + "x32/d3d9.dll.a", + "x32/dxgi.dll.a", + "x64/d3d10core.dll.a", + "x64/d3d11.dll.a", + "x64/d3d8.dll.a", + "x64/d3d9.dll.a", + "x64/dxgi.dll.a" + ], + "provenance": { + "ci_run": "https://github.com/wallentx/DroidDeck/actions/runs/38119192562", + "repository_commit": "aee0ebd43557ef9964ba7f6a11d7d30efaf983ac" + }, + "recipe_inputs": { + "tools/dxvk/build.sh": "88b656292a6a8c92974f1c014dd685e104818ef45af5fa4e62b729452c969d6e", + "tools/dxvk/check_present_sync.py": "42e2a590e17c1f53e5cd4100ef3d19a5bdcce31a6d7a18fbf9961f4ef27d5063", + "tools/dxvk/patches/0001-check-direct3d-bc-formats.patch": "d38fc4d773b7974498dcb377dbaa883c9bba36aefa3235b39bca69d6dd220c77", + "tools/dxvk/patches/0002-present-semaphore-per-swapchain-image.patch": "c802789a33099d3efc3413a297e2b752f8eb84c18cbfbdfc04e188f4090410d0", + "tools/dxvk/source.env": "e49b0757f203f88783360c06118f60945242fde8738419e0b27cf2531bf3a365" + }, + "sha256": "d08dd962ced3482883ad9e9eb4903a4d27a3756b4f989a97ecdfcccb53fbee66", + "size": 24063241, + "url": "https://github.com/wallentx/DroidDeck/releases/download/v0.3.2-progress.20261011.3/dxvk-aee0ebd.zip" + }, + { + "files": [ + { + "mode": 420, + "name": "libVkLayer_window_system_integration.so", + "path": "wsi/libVkLayer_window_system_integration.so", + "sha256": "d07b961181b9547fd48ad9f05cc6d3b808b824676eb5a186fe3feb8caa013f19", + "size": 436888 + }, + { + "mode": 420, + "name": "VkLayer_window_system_integration.json", + "path": "wsi/VkLayer_window_system_integration.json", + "sha256": "a1df8b1cee7315015d8fe82534451e373ae4d9cb2adfc232c68346ecbf2818ee", + "size": 3683 + }, + { + "mode": 420, + "name": "LICENSE", + "path": "licenses/wsi-LICENSE", + "sha256": "5eb8d2da52230d2d66ce078a89ae0173aac63e2e73bed5f907a34736d114ea30", + "size": 1086 + }, + { + "mode": 420, + "name": "source-commit", + "path": "provenance/wsi-source-commit", + "sha256": "8367150b20502af36c472651850694a15a3e2a1fd6b6beb1f6e12a85a97824f5", + "size": 41 + }, + { + "mode": 420, + "name": "SHA256SUMS", + "path": "provenance/wsi-SHA256SUMS", + "sha256": "fda6f61028659648801de0e3a6fe1676efd99e1551881a5db8630970eae86158", + "size": 108 + }, + { + "mode": 420, + "name": "downstream.patch", + "path": "licenses/wsi-downstream.patch", + "sha256": "e2ed113d22f05563248ef606c774c22658b184fbc05912229007cd5281027e78", + "size": 769 + }, + { + "mode": 420, + "name": "source.tar.zst", + "path": "licenses/wsi-source.tar.zst", + "sha256": "22ae7c2d8aa3dfffdda601c3442d1966ab53ad225acdfadee69ba38974d0c4c5", + "size": 209468 + }, + { + "mode": 420, + "name": "vulkan-headers-commit", + "path": "provenance/wsi-vulkan-headers-commit", + "sha256": "16706d6cdbeb788426a90d66574dfd71068c4d993d39e76ec5c281b1f30dc7a6", + "size": 41 + } + ], + "id": "wsi", + "ignored": [], + "provenance": { + "ci_run": "https://github.com/wallentx/DroidDeck/actions/runs/38047627963", + "repository_commit": "abe58618a5194f1f15499cbd5f9ec75503782556", + "vulkan_headers_licenses": { + "note": "Added from tracked assembly inputs; the original WSI archive and compiled library are unchanged.", + "revision": "8d6039a455a7ecc7d2a592ff97f62db4e59b70bf", + "source_urls": [ + "https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/8d6039a455a7ecc7d2a592ff97f62db4e59b70bf/LICENSE.md", + "https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/8d6039a455a7ecc7d2a592ff97f62db4e59b70bf/LICENSES/MIT.txt" + ] + } + }, + "recipe_inputs": { + "tools/vulkan-wsi/build.sh": "9e403151c58e6b2ee15241f525c4bacb2495f072191da6a63065e7fcc25b3b3c", + "tools/vulkan-wsi/licenses/Vulkan-Headers/LICENSE.md": "95ad366d23fadf701d355bc45fb8b82ae2d700239471d35d41286ac3b08ff903", + "tools/vulkan-wsi/licenses/Vulkan-Headers/MIT.txt": "1ca3502222d967f3be5751c55f6b7ee735b5383909c3b501495f54b216dbf227", + "tools/vulkan-wsi/patches/0001-link-x11-external-memory.patch": "e2ed113d22f05563248ef606c774c22658b184fbc05912229007cd5281027e78", + "tools/vulkan-wsi/source.env": "71a88087265a09b4ce06e7c9b98ef6799c6a7657cc6ef9084de663e96f5cfe63" + }, + "sha256": "348f9ec42159c1ee6e2baba4312a5e845d26687238f29e3f4a1b0c3c97e13b3c", + "size": 362717, + "url": "https://github.com/wallentx/DroidDeck/releases/download/v0.3.2-progress.20261010.4/wsi-abe5861.zip" + }, + { + "files": [ + { + "mode": 493, + "name": "dxvk-2.6.2/x32/d3d10core.dll", + "path": "dxvk-2.6.2/x32/d3d10core.dll", + "sha256": "b34b479fa0bce29eba6dcff5b1f8584c2ae699d53a123668590f8a2b84e84094", + "size": 176142 + }, + { + "mode": 493, + "name": "dxvk-2.6.2/x32/d3d11.dll", + "path": "dxvk-2.6.2/x32/d3d11.dll", + "sha256": "858d1a848dd5023191cb16cd986e0f00008faf5df8a87b5c835b56cf4b646910", + "size": 4845582 + }, + { + "mode": 493, + "name": "dxvk-2.6.2/x32/d3d8.dll", + "path": "dxvk-2.6.2/x32/d3d8.dll", + "sha256": "617459c8d1239f98687f8157bdaec85738ee4699885ed7d1ff13deb32609c759", + "size": 1658894 + }, + { + "mode": 493, + "name": "dxvk-2.6.2/x32/d3d9.dll", + "path": "dxvk-2.6.2/x32/d3d9.dll", + "sha256": "00bc142e98ddad1e334a4d88fa630038e092b0758b3d79e295172b181a4c772d", + "size": 4460558 + }, + { + "mode": 493, + "name": "dxvk-2.6.2/x32/dxgi.dll", + "path": "dxvk-2.6.2/x32/dxgi.dll", + "sha256": "67d7ca4a4f8f66baabd381c73b52a8e85870083e868ed474a4bc58b7da486883", + "size": 3137550 + }, + { + "mode": 493, + "name": "dxvk-2.6.2/x64/d3d10core.dll", + "path": "dxvk-2.6.2/x64/d3d10core.dll", + "sha256": "565154a0763c6460843fe47e5aaec62e609163d9995a922d5e19e85027fe2f88", + "size": 155662 + }, + { + "mode": 493, + "name": "dxvk-2.6.2/x64/d3d11.dll", + "path": "dxvk-2.6.2/x64/d3d11.dll", + "sha256": "5b63515a432d19302f7dc81dd2ee5bf40043683b5064a2bce03a2b6d27dcce5d", + "size": 4399118 + }, + { + "mode": 493, + "name": "dxvk-2.6.2/x64/d3d8.dll", + "path": "dxvk-2.6.2/x64/d3d8.dll", + "sha256": "dfd837c3467eeb15f69a773e18bbc0550cb69c9e33d5d57b4ea42c5f63bfdc4b", + "size": 1544206 + }, + { + "mode": 493, + "name": "dxvk-2.6.2/x64/d3d9.dll", + "path": "dxvk-2.6.2/x64/d3d9.dll", + "sha256": "01e7ae2b0544b6031fe695fd16fbc76786ded57fdbe3f6bd11eee7c98d2c370d", + "size": 4108302 + }, + { + "mode": 493, + "name": "dxvk-2.6.2/x64/dxgi.dll", + "path": "dxvk-2.6.2/x64/dxgi.dll", + "sha256": "074616e1af172edf175f3fc6ed7ca30f6c685a70875eed3af10797a10840ed39", + "size": 2891790 + } + ], + "format": "tar.gz", + "id": "dxvk-xclipse", + "ignored": [], + "provenance": { + "note": "Unmodified upstream release, selected on Samsung Xclipse: its 128 bytes of push constants predate DXVK 3's 256-byte requirement. Covered by the zlib license already shipped as licenses/dxvk-LICENSE.", + "upstream_release": "https://github.com/doitsujin/dxvk/releases/tag/v2.6.2" + }, + "recipe_inputs": {}, + "sha256": "17761876556afd55736cb895d184f5a1c55d43350f1b1e3b129f8d28706d7992", + "size": 10107492, + "url": "https://github.com/doitsujin/dxvk/releases/download/v2.6.2/dxvk-2.6.2.tar.gz" + } + ], + "format": 1, + "hybris": { + "provenance": { + "apk_ci_run": "https://github.com/wallentx/DroidDeck/actions/runs/38123715308", + "extracted_from_apk": "https://github.com/wallentx/DroidDeck/releases/download/v0.3.2-progress.20261011.3/DroidDeck-0.3.2-1b6185b.apk", + "note": "APK build reused a cached bridge. Original source and compiler metadata are preserved in build-manifest.json; no APK commit is claimed as the bridge producer.", + "upstream_source_commit": "bc8cb3586b79d208fd21b925fa0209b3e432e008" + }, + "recipe_inputs": { + "tools/hybris/build_runtime.sh": "bc83472ecfd886841c8c2c436080cdee0a27ce0d860ffbffe45a75fbc6b2b21d", + "tools/hybris/patches/0001-dxvk-bc-profile.patch": "b90605e51256595de4453352865aa198e59bd2d392ac6b7c2a60f38c57727c9d", + "tools/hybris/powervr-hal-version.patch": "d3ed8ca03e5a874b9dc46651983117760c7490b96127335625d0480a2b85e66f", + "tools/hybris/source.env": "9ae7985f2052dbcc8b9666494bc8a711ec85013f6a27d6d72d9729c32b919dd8" + }, + "sha256": "f4f12c26ed21003c2c98a7cececd76c8a3b332d79ece9d1f963cf3b9e8943978", + "size": 5552486, + "tree_sha256": "de9cc2c4107bf396e4f963d7e91f936a966593fb1df680a0b5d43db0f9fef4e1", + "url": "https://github.com/wallentx/DroidDeck/releases/download/v0.3.2-progress.20261011.3/hybris-runtime-f4f12c26.tzst" + } +} diff --git a/tools/release/check_session_assets.py b/tools/release/check_session_assets.py index 2042e470f7..af31d4c8c9 100644 --- a/tools/release/check_session_assets.py +++ b/tools/release/check_session_assets.py @@ -1,4 +1,5 @@ from pathlib import Path +import importlib.util import re import sys from zipfile import ZipFile @@ -9,7 +10,10 @@ SESSION_FILES = OVERLAY.parents[2] / 'app/src/main/java/com/droiddeck/launcher/s def check_extraction(overlay, source): - deployed = set(re.findall(r'"(usr/local/bin/droiddeck-[^"]+)"\s+to\s+"usr/local/bin/[^"/]+"', source)) + # Extracted into usr/local/bin under any name, or (droiddeck-steam-taskset, which PATH puts in + # front of Steam's own taskset only for the client) into usr/local/libexec/droiddeck-steam. + deployed = set(re.findall( + r'"(usr/local/bin/droiddeck-[^"]+)"\s+to\s+"usr/local/(?:bin|libexec/droiddeck-steam)/[^"/]+"', source)) return ['not extracted at session start: ' + path.relative_to(overlay).as_posix() for path in sorted((overlay / 'usr/local/bin').glob('droiddeck-*')) if path.relative_to(overlay).as_posix() not in deployed] @@ -41,6 +45,16 @@ def check(apk, overlay=OVERLAY): continue if content != source.read_bytes(): errors.append('stale ' + asset) + if overlay == OVERLAY: + spec = importlib.util.spec_from_file_location('powervr_fetch', + OVERLAY.parents[1] / 'powervr/fetch.py') + runtime = importlib.util.module_from_spec(spec) + spec.loader.exec_module(runtime) + try: + runtime.verify_archive(package.read('assets/hybris/runtime.tzst'), + package.read('assets/hybris/version.txt').decode('ascii')) + except (KeyError, ValueError, OSError) as error: + errors.append('invalid PowerVR runtime: ' + str(error)) return errors diff --git a/tools/release/runtime_inputs.py b/tools/release/runtime_inputs.py index b03f5235dd..b14f13eff7 100644 --- a/tools/release/runtime_inputs.py +++ b/tools/release/runtime_inputs.py @@ -1,5 +1,6 @@ import hashlib import gzip +import importlib.util import json from pathlib import Path import subprocess @@ -22,6 +23,7 @@ SOURCE_PATHS = ['app/build.gradle', 'app/src/main/cpp/fakeinput_steam.cpp', 'app 'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio', 'tools/packs', 'tools/gamescope/release.env', 'tools/droiddeck-esync/release.env', 'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/dirt-ws2', 'tools/components', 'tools/ci', 'tools/build_local.sh', + 'tools/powervr', 'tools/hybris', 'tools/dxvk', 'tools/vulkan-wsi', 'tools/release/runtime_inputs.py', 'app/src/main/assets/desktop-removal', 'tools/quest', 'tools/vr/src', 'tools/vr/driver_droiddeck', 'tools/vr/layer', 'tools/vr/build.sh', 'tools/gpuload', @@ -53,7 +55,7 @@ def sources(root): def outputs(root): result = {} - for tree in ['linuxfs', 'directaudio', 'droiddeck-esync', 'desktop-removal']: + for tree in ['linuxfs', 'directaudio', 'droiddeck-esync', 'desktop-removal', 'hybris']: base = root / 'app/src/main/assets' / tree for path in base.rglob('*'): if path.is_file() and not any(part.startswith('.') for part in path.relative_to(base).parts): @@ -85,6 +87,8 @@ def required(): paths += ['assets/linuxfs/i386/libfaultreport.so'] paths += ['assets/linuxfs/usr/local/lib/droiddeck-msitools/' + name for name in ['msiinfo', 'cabextract', '7z', '7z.so', 'libmsi-1.0.so.0', 'libgsf-1.so.114', 'libgcab-1.0.so.0']] + paths += ['assets/linuxfs/usr/local/lib/droiddeck-xclipse/' + name for name in + ['libVkLayer_droiddeck_xclipse.so', 'VkLayer_droiddeck_xclipse.json']] paths += ['assets/linuxfs/usr/local/lib/droiddeck-vr/' + name for name in ['droiddeck/bin/linuxarm64/driver_droiddeck.so', 'droiddeck/bin/linuxarm64/xr-display-mode', 'droiddeck/driver.vrdrivermanifest', @@ -115,9 +119,17 @@ def required(): paths += ['assets/desktop-removal/' + name for name in ['lxqt-r1.tsv.gzip', 'kde-remove.tsv.gzip', 'kde-keep.txt.gzip', 'emulators-keep.txt.gzip', 'versions.txt', 'sources.json']] + paths += ['assets/hybris/runtime.tzst', 'assets/hybris/version.txt'] return paths +def verify_powervr(root): + spec = importlib.util.spec_from_file_location('powervr_fetch', ROOT / 'tools/powervr/fetch.py') + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + module.verify(root) + + def record(root=ROOT): if root == ROOT: from check_session_assets import source_assets @@ -129,6 +141,7 @@ def record(root=ROOT): missing = [name for name in required() if name not in paths or not (root / paths[name]).is_file()] if missing: raise ValueError('Missing runtime inputs:\n' + '\n'.join(missing)) + verify_powervr(root) for name, path in paths.items(): if name.startswith('assets/desktop-removal/') and name.endswith('.gzip'): try: diff --git a/tools/tests/drm_handles_test.c b/tools/tests/drm_handles_test.c new file mode 100644 index 0000000000..08d337f55e --- /dev/null +++ b/tools/tests/drm_handles_test.c @@ -0,0 +1,343 @@ +#define _GNU_SOURCE +#include <assert.h> +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <stdarg.h> +#include <stdatomic.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/syscall.h> +#include <sys/wait.h> +#include <unistd.h> + +/* Only the device/driver boundary is simulated. Descriptors and their lifetimes are real. + * F_DUPFD_QUERY is modelled so this test also runs on older CI kernels; the device probe + * separately exercises the actual query on Android. */ +#define TEST_FD_LIMIT 65536 +static _Atomic unsigned identities[TEST_FD_LIMIT]; +static struct f_owner_ex owners[TEST_FD_LIMIT]; +static unsigned identity_serial = 1; +static int identity_denied, owner_denied, owner_probe_delay, kgsl_present; +static int kernel_error = EINVAL; +static int native_imports, native_exports, native_closes; +static const char *driver_name = "pvr"; +static const char *pvr_node = "/dev/dri/renderD129"; +static int fixture_stat(const char *path, struct stat *st); +static long fixture_syscall(long number, ...); +static int fixture_fcntl(int fd, int op, ...); +static void *fixture_dlsym(void *object, const char *name); +static int fixture_close(int fd); + +#define stat(path, st) fixture_stat(path, st) +#define syscall fixture_syscall +#define fcntl fixture_fcntl +#define dlsym fixture_dlsym +#define close fixture_close +#include "../linuxfs/preload/drm.c" +#undef stat +#undef syscall +#undef fcntl +#undef dlsym +#undef close + +static int test_open(const char *path) { + int fd = open(path, O_RDWR | O_CLOEXEC); + assert(fd >= 0 && fd < TEST_FD_LIMIT); + identities[fd] = identity_serial++; + return fd; +} + +static int fixture_close(int fd) { + if (fd >= 0 && fd < TEST_FD_LIMIT) identities[fd] = 0; + return close(fd); +} + +static int fixture_stat(const char *path, struct stat *st) { + if (!strcmp(path, "/dev/kgsl-3d0")) { + if (kgsl_present) return stat("/dev/zero", st); + errno = ENOENT; + return -1; + } + if (!strcmp(path, pvr_node)) return stat("/dev/null", st); + if (!strcmp(path, "/dev/dri/renderD128")) return stat("/dev/zero", st); + if (!strncmp(path, "/dev/dri/", 9)) { errno = ENOENT; return -1; } + return stat(path, st); +} + +static int fixture_fcntl(int fd, int op, ...) { + va_list ap; + va_start(ap, op); + if (op == F_GETOWN_EX || op == F_SETOWN_EX) { + struct f_owner_ex *owner = va_arg(ap, struct f_owner_ex *); + va_end(ap); + if (owner_denied) { errno = EINVAL; return -1; } + if (fd < 0 || fd >= TEST_FD_LIMIT || !identities[fd] || !owner) { + errno = EBADF; + return -1; + } + if (op == F_GETOWN_EX) { + *owner = owners[identities[fd]]; + } else { + owners[identities[fd]] = *owner; + if (owner_probe_delay && owner->pid) usleep(1000); + } + return 0; + } + int arg = va_arg(ap, int); + va_end(ap); + if (op == F_DUPFD_QUERY) { + if (identity_denied) { errno = EINVAL; return -1; } + if (fd < 0 || arg < 0 || fd >= TEST_FD_LIMIT || arg >= TEST_FD_LIMIT || + !identities[fd] || !identities[arg]) { errno = EBADF; return -1; } + return identities[fd] == identities[arg]; + } + int ret = fcntl(fd, op, arg); + if (ret >= 0 && (op == F_DUPFD || op == F_DUPFD_CLOEXEC)) { + assert(ret < TEST_FD_LIMIT); + identities[ret] = identities[fd]; + } + return ret; +} + +static long fixture_syscall(long number, ...) { + va_list ap; + va_start(ap, number); + if (number == SYS_ioctl) { + (void)va_arg(ap, int); + unsigned long request = va_arg(ap, unsigned long); + struct bl_drm_version *v = va_arg(ap, void *); + assert(request == BL_DRM_VERSION); + snprintf(v->name, v->name_len, "%s", driver_name); + v->name_len = strlen(driver_name); + va_end(ap); + return 0; + } + va_end(ap); + assert(number == SYS_kcmp); + errno = EPERM; + return -1; +} + +static int native_import(int fd, int dma, uint32_t *handle) { + (void)fd; + native_imports++; + if (fcntl(dma, F_GETFD) < 0) return -1; + if (!handle) { errno = EFAULT; return -1; } + if (kernel_error) { errno = kernel_error; return -1; } + *handle = 42; + return 0; +} +static int native_export(int fd, uint32_t handle, uint32_t flags, int *out) { + (void)flags; + native_exports++; + if (handle != 42 || !out) { errno = EINVAL; return -1; } + *out = fixture_fcntl(fd, F_DUPFD_CLOEXEC, 0); + return *out < 0 ? -1 : 0; +} +static int native_close(int fd, uint32_t handle) { + (void)fd; + native_closes++; + if (handle == 42) return 0; + errno = EINVAL; + return -1; +} +static void *fixture_dlsym(void *object, const char *name) { + assert(object == RTLD_NEXT); + if (!strcmp(name, "drmPrimeFDToHandle")) return native_import; + if (!strcmp(name, "drmPrimeHandleToFD")) return native_export; + if (!strcmp(name, "drmCloseBufferHandle")) return native_close; + abort(); +} + +static int count_fds(void) { + int count = 0; + for (int fd = 0; fd < TEST_FD_LIMIT; ++fd) count += identities[fd] != 0; + return count; +} +static void empty_table(void) { + for (int i = 0; i < MAX_HANDLES; ++i) assert(!handle_entries[i].handle); +} + +struct fallback_stress { + int drm; + int dma; + int failures; +}; + +static void *stress_fallback_imports(void *opaque) { + struct fallback_stress *stress = opaque; + for (int i = 0; i < 20; i++) { + uint32_t handle = 0; + if (drmPrimeFDToHandle(stress->drm, stress->dma, &handle) != 0 || + drmCloseBufferHandle(stress->drm, handle) != 0) { + stress->failures++; + } + } + return NULL; +} + +int main(void) { + int drm = test_open("/dev/null"), dma = test_open("/dev/zero"); + uint32_t handle = 0; + unsetenv("BL_POWERVR_DRM_HANDLES"); + setenv("BL_POWERVR_RENDER_NODE", pvr_node, 1); + assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); + setenv("BL_POWERVR_DRM_HANDLES", "yes", 1); + assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); + setenv("BL_POWERVR_DRM_HANDLES", "1", 1); + unsetenv("BL_POWERVR_RENDER_NODE"); + assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); /* no selected node */ + setenv("BL_POWERVR_RENDER_NODE", "", 1); + assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); + setenv("BL_POWERVR_RENDER_NODE", "/dev/dri/renderD128", 1); + assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); /* another GPU owns 128 */ + setenv("BL_POWERVR_RENDER_NODE", "/dev/dri/renderD130", 1); + assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); /* selected node is absent */ + setenv("BL_POWERVR_RENDER_NODE", __FILE__, 1); + assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); /* regular files are not DRM nodes */ + setenv("BL_POWERVR_RENDER_NODE", pvr_node, 1); + driver_name = "other"; + assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); + driver_name = "pvr"; + assert(drmPrimeFDToHandle(dma, dma, &handle) != 0); /* wrong character device */ + kernel_error = EACCES; + assert(drmPrimeFDToHandle(drm, dma, &handle) != 0 && errno == EACCES); + kernel_error = EINVAL; + assert(drmPrimeFDToHandle(drm, -1, &handle) != 0 && errno == EBADF); + empty_table(); + + int baseline = count_fds(); + identity_denied = 1; + assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && (handle & PVR_HANDLE_BIT)); + int denied_alias = fixture_fcntl(drm, F_DUPFD_CLOEXEC, 0), denied_out = -1; + int denied_separate = test_open("/dev/null"); + assert(drmPrimeHandleToFD(denied_separate, handle, O_CLOEXEC, &denied_out) != 0); + assert(drmPrimeHandleToFD(denied_alias, handle, O_CLOEXEC, &denied_out) == 0); + fixture_close(denied_out); + assert(drmCloseBufferHandle(denied_alias, handle) == 0); + fixture_close(denied_alias); + fixture_close(denied_separate); + assert(count_fds() == baseline); + owner_denied = 1; + assert(drmPrimeFDToHandle(drm, dma, &handle) == -EOPNOTSUPP); + assert(count_fds() == baseline); + owner_denied = 0; + + /* Marker changes and restoration must be atomic across concurrent imports of one DRM OFD. */ + owner_probe_delay = 1; + struct fallback_stress stress[8]; + pthread_t workers[8]; + for (int i = 0; i < 8; i++) { + stress[i] = (struct fallback_stress){.drm = drm, .dma = dma}; + assert(pthread_create(&workers[i], NULL, stress_fallback_imports, &stress[i]) == 0); + } + for (int i = 0; i < 8; i++) { + assert(pthread_join(workers[i], NULL) == 0); + assert(stress[i].failures == 0); + } + owner_probe_delay = 0; + assert(owners[identities[drm]].pid == 0); + assert(count_fds() == baseline); + empty_table(); + identity_denied = 0; + + assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && (handle & PVR_HANDLE_BIT)); + assert(count_fds() == baseline + 2); + int alias = fixture_fcntl(drm, F_DUPFD_CLOEXEC, 0), out = -1; + int separate = test_open("/dev/null"); + assert(drmPrimeHandleToFD(separate, handle, O_CLOEXEC | O_RDWR, &out) != 0); + struct gem_close close_request = {.handle = handle}; + int rc = 123; + assert(bl_drm_gem_close(separate, GEM_CLOSE, &close_request, &rc) == 0 && rc == 123); + assert(drmPrimeHandleToFD(alias, handle, O_CLOEXEC | O_RDWR, &out) == 0); + assert(fcntl(out, F_GETFD) & FD_CLOEXEC); + struct stat src, dst; + assert(fstat(dma, &src) == 0 && fstat(out, &dst) == 0); + assert(src.st_dev == dst.st_dev && src.st_ino == dst.st_ino); + fixture_close(out); + assert(drmPrimeHandleToFD(alias, handle, 0, &out) == 0); + assert(!(fcntl(out, F_GETFD) & FD_CLOEXEC)); + fixture_close(out); + assert(drmPrimeHandleToFD(alias, handle, 0x40, &out) == -EINVAL); + + /* A closed-and-reused descriptor must not inherit the old open file's handles. */ + int old_number = drm; + fixture_close(drm); + drm = test_open("/dev/null"); + assert(drm == old_number); + assert(drmPrimeHandleToFD(drm, handle, O_CLOEXEC, &out) != 0); + assert(drmCloseBufferHandle(drm, handle) != 0); + assert(drmPrimeHandleToFD(alias, handle, O_CLOEXEC, &out) == 0); + fixture_close(out); + assert(bl_drm_gem_close(alias, GEM_CLOSE, &close_request, &rc) == 1 && rc == 0); + assert(drmPrimeHandleToFD(alias, handle, O_CLOEXEC, &out) != 0); + fixture_close(alias); + fixture_close(separate); + assert(count_fds() == baseline); + empty_table(); + + /* Real kernel handles and their direct GEM_CLOSE ioctls are never swallowed. */ + kernel_error = 0; + assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && handle == 42); + empty_table(); + assert(drmPrimeHandleToFD(drm, handle, O_CLOEXEC, &out) == 0); + fixture_close(out); + close_request.handle = handle; + assert(bl_drm_gem_close(drm, GEM_CLOSE, &close_request, &rc) == 0); + assert(drmCloseBufferHandle(drm, handle) == 0); + assert(native_imports && native_exports && native_closes); + kernel_error = EINVAL; + + /* Slot reuse must not reuse public tokens or leak either owned descriptor. */ + uint32_t previous = 0; + for (int n = 0; n < 1000; ++n) { + assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && handle != previous); + assert(drmCloseBufferHandle(drm, handle) == 0); + if (previous) assert(drmPrimeHandleToFD(drm, previous, O_CLOEXEC, &out) != 0); + previous = handle; + } + assert(count_fds() == baseline); + empty_table(); + + assert(drmPrimeFDToHandle(drm, dma, &handle) == 0); + pid_t child = fork(); + assert(child >= 0); + if (child == 0) { + assert(drmPrimeHandleToFD(drm, handle, O_CLOEXEC, &out) == 0); + fixture_close(out); + assert(drmCloseBufferHandle(drm, handle) == 0); + _exit(0); + } + int status; + assert(waitpid(child, &status, 0) == child && WIFEXITED(status) && WEXITSTATUS(status) == 0); + assert(drmPrimeHandleToFD(drm, handle, O_CLOEXEC, &out) == 0); + fixture_close(out); + assert(drmCloseBufferHandle(drm, handle) == 0); + + /* Preserve the original device layout when PowerVR owns renderD128. */ + pvr_node = "/dev/dri/renderD128"; + setenv("BL_POWERVR_RENDER_NODE", pvr_node, 1); + assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && (handle & PVR_HANDLE_BIT)); + assert(drmCloseBufferHandle(drm, handle) == 0); + + /* Retain the old KGSL path with the PowerVR opt-in unset. */ + unsetenv("BL_POWERVR_DRM_HANDLES"); + kgsl_present = 1; + kgsl_state = 0; + assert(drmPrimeFDToHandle(dma, drm, &handle) == 0 && !(handle & PVR_HANDLE_BIT)); + assert(drmPrimeHandleToFD(dma, handle, O_CLOEXEC | O_RDWR, &out) == 0); + fixture_close(out); + close_request.handle = handle; + assert(bl_drm_gem_close(dma, GEM_CLOSE, &close_request, &rc) == 1 && rc == 0); + assert(drmCloseBufferHandle(dma, handle) == -EINVAL); + empty_table(); + assert(count_fds() == baseline); + fixture_close(drm); + fixture_close(dma); + puts("DRM adapter scoping, ownership, reuse, fork and kernel-passthrough tests passed"); +} diff --git a/tools/tests/test_drm_handles.py b/tools/tests/test_drm_handles.py new file mode 100644 index 0000000000..5f638a2b4c --- /dev/null +++ b/tools/tests/test_drm_handles.py @@ -0,0 +1,26 @@ +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +class DrmHandleTest(unittest.TestCase): + def test_handle_lifetime_and_device_scope(self): + compiler = shutil.which(os.environ.get("CC", "cc")) + if not compiler: + self.fail("A C compiler is required for the DRM adapter regression test") + source = Path(__file__).with_name("drm_handles_test.c") + with tempfile.TemporaryDirectory(prefix="droiddeck-drm-") as tmp: + program = Path(tmp) / "drm-handles" + built = subprocess.run([compiler, "-std=gnu11", "-Wall", "-Wextra", "-Werror", + "-UNDEBUG", "-pthread", str(source), "-ldl", "-o", str(program)], + capture_output=True, text=True) + self.assertEqual(built.returncode, 0, built.stdout + built.stderr) + ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30) + self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_dxvk_build.py b/tools/tests/test_dxvk_build.py new file mode 100644 index 0000000000..0038d0dc9f --- /dev/null +++ b/tools/tests/test_dxvk_build.py @@ -0,0 +1,121 @@ +"""Exercise output isolation with a synthetic toolchain; no network/DLL build.""" +import hashlib +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[2] + +# Substitute only external source/compiler/archive commands. The real build.sh +# owns output checks, architecture iteration and manifest inputs. +FAKE_TOOL = r''' +import hashlib, json, os +from pathlib import Path +import sys +name = Path(sys.argv[0]).name +args = sys.argv[1:] +with open(os.environ['TOOL_CALLS'], 'a') as stream: + stream.write(name + '\n') +if name == 'git': + if args[0] == 'init': + Path(args[-1]).mkdir() + (Path(args[-1]) / 'LICENSE').write_text('synthetic public license') + elif 'rev-parse' in args: + print(os.environ['TEST_REVISION']) +elif name == 'meson': + if args[0] == 'setup': + p = Path(args[1]); p.mkdir() + p.joinpath('config.json').write_text(json.dumps({ + 'out': args[args.index('--prefix') + 1], + 'arch': args[args.index('--bindir') + 1]})) + elif args[0] == 'install': + config = json.loads(Path(args[2], 'config.json').read_text()) + out = Path(config['out'], config['arch']); out.mkdir(exist_ok=True) + out.joinpath('current.dll').write_bytes(b'synthetic current pinned DLL') + if config['arch'] == os.environ.get('FAIL_INSTALL_ARCH'): + sys.exit(5) +elif name == 'tar': + Path(args[args.index('-cf') + 1]).write_bytes(b'synthetic source archive') +elif name == 'sha256sum': + for arg in args: + print(hashlib.sha256(Path(arg).read_bytes()).hexdigest() + ' ' + arg) +elif name != 'python3': + raise AssertionError(name) +''' + + +class DxvkBuildTest(unittest.TestCase): + def setUp(self): + self.temporary = tempfile.TemporaryDirectory() + self.addCleanup(self.temporary.cleanup) + self.base = Path(self.temporary.name) + self.bin = self.base / 'bin'; self.bin.mkdir() + executable = self.bin / 'fake-tool' + executable.write_text('#!' + sys.executable + '\n' + FAKE_TOOL) + executable.chmod(0o755) + for name in ('git', 'meson', 'tar', 'sha256sum', 'python3'): + (self.bin / name).symlink_to(executable) + self.calls = self.base / 'calls' + self.env = dict(os.environ, PATH=str(self.bin) + os.pathsep + os.environ['PATH'], + TOOL_CALLS=str(self.calls)) + source_env = ROOT / 'tools/dxvk/source.env' + self.env['TEST_REVISION'] = next(line.split('=', 1)[1].strip('"\'') + for line in source_env.read_text().splitlines() + if line.startswith('DXVK_REVISION=')) + self.output = self.base / 'component' + + def build(self): + return subprocess.run(['bash', str(ROOT / 'tools/dxvk/build.sh'), str(self.output)], + env=self.env, capture_output=True, text=True, timeout=10) + + def test_stale_dll_is_rejected_untouched_before_fetch(self): + stale = self.output / 'x32/stale.dll'; stale.parent.mkdir(parents=True) + stale.write_bytes(b'prior pinned build') + result = self.build() + self.assertNotEqual(result.returncode, 0) + self.assertIn('output directory must be empty', result.stderr) + self.assertEqual(stale.read_bytes(), b'prior pinned build') + self.assertFalse(self.calls.exists()) + self.assertFalse((self.output / 'SHA256SUMS').exists()) + + def test_hidden_contents_are_also_rejected(self): + self.output.mkdir(); (self.output / '.previous').write_text('retained') + self.assertNotEqual(self.build().returncode, 0) + self.assertFalse(self.calls.exists()) + self.assertEqual((self.output / '.previous').read_text(), 'retained') + + def test_empty_or_new_output_contains_only_current_dlls(self): + for existing in (False, True): + with self.subTest(existing=existing): + self.output = self.base / ('existing' if existing else 'new') + if existing: self.output.mkdir() + result = self.build() + self.assertEqual(result.returncode, 0, result.stderr) + rows = (self.output / 'SHA256SUMS').read_text().splitlines() + self.assertEqual([row.split(' ')[1] for row in rows], + ['x32/current.dll', 'x64/current.dll']) + for row in rows: + digest, path = row.split(' ') + self.assertEqual(digest, hashlib.sha256((self.output / path).read_bytes()).hexdigest()) + + def test_partial_build_is_not_reused_or_deleted(self): + self.env['FAIL_INSTALL_ARCH'] = 'x64' + result = self.build() + self.assertEqual(result.returncode, 5, result.stderr) + before = {str(p.relative_to(self.output)): p.read_bytes() + for p in self.output.rglob('*') if p.is_file()} + self.calls.unlink(); del self.env['FAIL_INSTALL_ARCH'] + result = self.build() + self.assertNotEqual(result.returncode, 0) + self.assertFalse(self.calls.exists()) + after = {str(p.relative_to(self.output)): p.read_bytes() + for p in self.output.rglob('*') if p.is_file()} + self.assertEqual(after, before) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/tests/test_effects_source_resolution.py b/tools/tests/test_effects_source_resolution.py index 2a229812fd..043f392129 100644 --- a/tools/tests/test_effects_source_resolution.py +++ b/tools/tests/test_effects_source_resolution.py @@ -26,6 +26,7 @@ class EffectsSourceResolutionTest(unittest.TestCase): header = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_present.h').read_text() effects = (REPO / 'app/src/main/cpp/waylandcomp/src/effects_chain.c').read_text() functions = '\n'.join(function(source, signature) for signature in ( + 'static void release_external_client_image(', 'static void release_external_client_draws(', 'static int map_draw(', 'static int draw_to_blit(', 'static int draw_to_scene_blit(', 'static int effects_source_draw(', 'static void effects_source_note(', @@ -37,11 +38,13 @@ class EffectsSourceResolutionTest(unittest.TestCase): image = source[source.index('struct vkp_image {'):source.index('\n};', source.index('struct vkp_image {')) + 3] draw = header[header.index('struct vkp_draw {'):header.index('\n};', header.index('struct vkp_draw {')) + 3] hdr = header[header.index('struct vkp_hdr_frame {'):header.index('\n};', header.index('struct vkp_hdr_frame {')) + 3] - constants = sorted(set(re.findall(r'\bVK_[A-Z0-9_]+\b', functions + image)) - + sync = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_external_image_sync.h').read_text() + sync = re.sub(r'^#(include|ifndef|define|endif).*$', '', sync, flags=re.M) + constants = sorted(set(re.findall(r'\bVK_[A-Z0-9_]+\b', functions + image + sync)) - {'VK_FORMAT_R8G8B8A8_UNORM'}) definitions = '\n'.join(f'#define {name} {0 if name in ("VK_SUCCESS", "VK_NULL_HANDLE") else i + 1}' for i, name in enumerate(constants)) - code = TYPES + definitions + '\n' + image + '\n' + draw + '\n' + hdr + STUBS + functions + CASES + code = TYPES + definitions + '\n' + sync + '\n' + image + '\n' + draw + '\n' + hdr + STUBS + functions + CASES cls.temp = tempfile.TemporaryDirectory(prefix='droiddeck-effects-resolution-') cls.addClassCleanup(cls.temp.cleanup) folder = Path(cls.temp.name) @@ -148,10 +151,12 @@ typedef struct { #define droiddeck_log(...) ((void)0) #define LOGE(...) ((void)0) struct droiddeck_color { uint32_t identity; }; +typedef struct AHardwareBuffer AHardwareBuffer; ''' STUBS = r''' +static void quarantine_pending_work(VkResult result, const char *where) { (void)result; (void)where; } static int noop(int handle, ...) { return VK_SUCCESS; } static VkImageMemoryBarrier recorded_barriers[64]; static int barrier_count; @@ -173,7 +178,7 @@ static struct { int (*EndCommandBuffer)(int, ...), (*ResetFences)(int, ...); int (*QueueSubmit)(int, ...), (*QueuePresentKHR)(int, ...); } g_vk = {noop, noop, note_barriers, noop, noop, noop, noop, noop}; -static int g_dev_state, g_window = 1, g_swapchain, g_swap_extra; +static int g_dev_state = 1, g_window = 1, g_swapchain, g_swap_extra; static int g_colorspace_ext, g_swap_hdr_unavailable, g_swap_is_hdr, g_swap_hdr_want; static int g_plain_frame, g_first_frame_done, g_base_black; static int g_qfam, g_queue, g_dev, g_fence, g_swap_fmt = SCENE_FMT; @@ -195,7 +200,7 @@ static VkImageBlit copied; static struct vkp_draw recorded_draws[16]; static VkImageBlit recorded_blits[16]; static VkImage recorded_targets[16]; -static int recorded_after_effects[16]; +static int recorded_after_effects[16], recorded_barrier_marks[16]; static void vkp_apply_window_request(void) {} static void sc_layer_hide_base(void) {} static void check_surface_changed(void) {} @@ -238,6 +243,7 @@ static void record_draw(int cmd, const struct vkp_draw *draw, const VkImageBlit assert(copy_count < 16); recorded_draws[copy_count] = *draw; recorded_blits[copy_count] = *blit; recorded_targets[copy_count] = target; recorded_after_effects[copy_count] = effects_count > 0; + recorded_barrier_marks[copy_count] = barrier_count; copy_count++; copied = *blit; copied_w = draw->dw; copied_h = draw->dh; target_w = w; target_h = h; } @@ -509,11 +515,16 @@ static void check_overlay_barriers(void) { reset(); struct vkp_draw layers[] = {background_draw(), fullscreen(), cursor_draw()}; run_path(offscreen, layers, 3, NULL); check_input(1280, 720); - int acquired = find_barrier(cursor.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + int acquired = find_barrier(cursor.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); assert(acquired >= 0 && recorded_barriers[acquired].srcQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT); int writable = find_barrier(4, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); int readable = find_barrier(4, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); assert(writable > acquired && readable > writable); + int released = find_barrier(cursor.image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL); + assert(released > acquired && recorded_barriers[released].dstQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT); + int last_cursor_draw = -1; + for (int i = 0; i < copy_count; i++) if (recorded_draws[i].img == &cursor) last_cursor_draw = i; + assert(last_cursor_draw >= 0 && released >= recorded_barrier_marks[last_cursor_draw]); } } static void check_postprocessing(void) { diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index 4a9eb32fad..dfc65de1c7 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -11,6 +11,7 @@ import sys import tempfile from unittest import mock import unittest +from unittest.mock import patch BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin" MODULE = runpy.run_path(str(BIN / "droiddeck-game-env")) @@ -410,6 +411,154 @@ class EgoCorePlanTest(unittest.TestCase): self.assertIn("added a copy of its 4-core plan", result.stderr) +class SystemGraphicsLaunchTest(unittest.TestCase): + def test_start_configures_ubisoft_with_proton_before_wrapping_the_game(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + runtime, _ = self.runtime(root) + prefix = root / "42" / "pfx" + (prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True) + (prefix / "user.reg").write_text("WINE REGISTRY Version 2\n") + env = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": str(prefix.parent)} + command = ["/selected/proton", "waitforexitandrun", "game.exe"] + with mock.patch("subprocess.run") as run, mock.patch("os.execvpe") as execute: + MODULE["start"](command, env, None) + self.assertEqual(run.call_count, 2) + for call in run.call_args_list: + self.assertEqual(call.args[0][:3], ["/selected/proton", "runinprefix", "reg.exe"]) + self.assertEqual(execute.call_args.args[:2], (str(runtime / "run-proton.py"), + [str(runtime / "run-proton.py"), *command])) + + def runtime(self, root): + runtime = root / "system_vulkan" / ("a" * 64) + files = ["run-proton.py", "lib/libVkLayer_hybris_compat.so", + "wsi/libVkLayer_window_system_integration.so", + "wsi/VkLayer_window_system_integration.json"] + files += ["dxvk/%s/%s.dll" % (arch, name) for arch in ("x32", "x64") + for name in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi")] + for name in files: + target = runtime / name + target.parent.mkdir(parents=True, exist_ok=True) + target.write_bytes(b"component") + (runtime / "run-proton.py").chmod(0o755) + return runtime, files + + def test_other_gpus_and_non_game_calls_keep_the_original_launch(self): + command = ["/proton", "waitforexitandrun", "game.exe"] + base = {"STEAM_COMPAT_DATA_PATH": "/compatdata/42", "VK_LAYER_PATH": "original"} + selected = dict(base, DROIDDECK_POWERVR_RUNTIME="/not-installed") + cases = [(command, base), (command, dict(selected, STEAM_COMPAT_DATA_PATH="/compatdata/0")), + (command, dict(selected, STEAM_COMPAT_DATA_PATH="/compatdata/invalid")), + (["/proton", "run", "iscriptevaluator.exe"], selected), + (["/proton", "getcompatpath", "x"], selected), (command[:2], selected)] + for args, env in cases: + with self.subTest(args=args, env=env): + actual, inherited = MODULE["system_graphics_launch"](args, env) + self.assertIs(actual, args) + self.assertIs(inherited, env) + + def test_system_graphics_follow_game_configuration_and_preserve_other_keys(self): + with tempfile.TemporaryDirectory() as tmp: + runtime, _ = self.runtime(Path(tmp)) + base = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": "/compatdata/42"} + config = {"version": 1, "games": {"42": { + "PROTON_USE_WINED3D": "1", "DISABLE_WSI_LAYER": "1", + "ENABLE_VK_LAYER_VALVE_steam_fossilize_1": "1", "HYBRIS_BC_TEXTURES": "0", + "VK_LAYER_PATH": "old", "VK_INSTANCE_LAYERS": "old", "ENABLE_GAMESCOPE_WSI": "1", + "FEX_TSOENABLED": "1", "WINESERVER": "/selected/wineserver", "CUSTOM": "literal $value", + }}} + env = MODULE["apply_config"](base, config, "42") + command = ["/selected/proton", "waitforexitandrun", "game with spaces.exe"] + launch, result = MODULE["system_graphics_launch"](command, env) + self.assertEqual(launch, [str(runtime / "run-proton.py"), *command]) + self.assertEqual(result["HYBRIS_BC_TEXTURES"], "dxvk") + self.assertEqual(result["VK_LAYER_PATH"], f"{runtime}/wsi:{runtime}/lib") + self.assertEqual(result["VK_INSTANCE_LAYERS"], "VK_LAYER_window_system_integration:VK_LAYER_HYBRIS_compat") + self.assertEqual(result["VK_LOADER_LAYERS_DISABLE"], "*gamescope*") + self.assertEqual(result["ENABLE_GAMESCOPE_WSI"], "0") + self.assertEqual(result["DISABLE_VK_LAYER_VALVE_steam_fossilize_1"], "1") + for key in ("PROTON_USE_WINED3D", "DISABLE_WSI_LAYER", "ENABLE_VK_LAYER_VALVE_steam_fossilize_1"): + self.assertNotIn(key, result) + self.assertIn(key, env) + for key in ("FEX_TSOENABLED", "WINESERVER", "CUSTOM"): + self.assertEqual(result[key], env[key]) + + def test_xclipse_selection_adds_its_layers_layer_path_and_dxvk_payload(self): + with tempfile.TemporaryDirectory() as tmp: + runtime, _ = self.runtime(Path(tmp)) + env = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": "/compatdata/42", + "DROIDDECK_HYBRIS_LAYERS": "VK_LAYER_DROIDDECK_xclipse:VK_LAYER_HYBRIS_compat", + "DROIDDECK_HYBRIS_LAYER_PATH": "/usr/local/lib/droiddeck-xclipse", + "DROIDDECK_HYBRIS_DXVK": "dxvk-2.6.2"} + command = ["/proton", "waitforexitandrun", "game.exe"] + # The selected payload is required like the default one. + with self.assertRaises(MODULE["SystemGraphicsError"]): + MODULE["system_graphics_launch"](command, env) + for arch in ("x32", "x64"): + for name in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi"): + target = runtime / "dxvk-2.6.2" / arch / (name + ".dll") + target.parent.mkdir(parents=True, exist_ok=True) + target.write_bytes(b"component") + launch, result = MODULE["system_graphics_launch"](command, env) + self.assertEqual(launch, [str(runtime / "run-proton.py"), *command]) + self.assertEqual(result["VK_INSTANCE_LAYERS"], + "VK_LAYER_window_system_integration:VK_LAYER_DROIDDECK_xclipse:VK_LAYER_HYBRIS_compat") + self.assertEqual(result["VK_LAYER_PATH"], f"{runtime}/wsi:{runtime}/lib:/usr/local/lib/droiddeck-xclipse") + self.assertEqual(result["DROIDDECK_HYBRIS_DXVK"], "dxvk-2.6.2") + for name in ("../dxvk", "other", "dxvk/x"): + with self.subTest(name=name), self.assertRaises(MODULE["SystemGraphicsError"]): + MODULE["system_graphics_launch"](command, dict(env, DROIDDECK_HYBRIS_DXVK=name)) + + def test_incomplete_runtime_fails_before_any_proton_exec(self): + with tempfile.TemporaryDirectory() as tmp: + runtime, files = self.runtime(Path(tmp)) + env = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": "/compatdata/42"} + command = ["/proton", "waitforexitandrun", "game.exe"] + for name in files: + target = runtime / name + original = target.read_bytes() + for missing in (False, True): + with self.subTest(name=name, missing=missing): + target.unlink() if missing else target.write_bytes(b"") + with patch.object(os, "execvpe") as execute: + with self.assertRaises(MODULE["SystemGraphicsError"]): + MODULE["exec_proton"](command, env) + execute.assert_not_called() + target.write_bytes(original) + if name == "run-proton.py": + target.chmod(0o755) + (runtime / "run-proton.py").chmod(0o644) + with self.assertRaises(MODULE["SystemGraphicsError"]): + MODULE["system_graphics_launch"](command, env) + with self.assertRaises(MODULE["SystemGraphicsError"]): + MODULE["system_graphics_launch"](command, dict(env, DROIDDECK_POWERVR_RUNTIME="relative")) + + def test_wrapper_receives_the_sync_selected_proton(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + runtime, _ = self.runtime(root) + env = {"HOME": tmp, "DROIDDECK_POWERVR_RUNTIME": str(runtime), + "STEAM_COMPAT_DATA_PATH": "/compatdata/42"} + command = ["/stock/proton", "waitforexitandrun", "game.exe"] + selected = ["/sync-pack/proton", *command[1:]] + selected_env = dict(env, WINESERVER="/sync-pack/wineserver", BL_SYNC_PACK="selected") + main = MODULE["main"] + with patch.dict(os.environ, env, clear=True), patch.object(sys, "argv", ["game-env", *command]), \ + patch.dict(main.__globals__, {"load_sync": lambda: {}, + "select_sync": lambda *args: (selected, selected_env), + "win_components": lambda *args: ""}), \ + patch.object(os, "execvpe", side_effect=SystemExit(23)) as execute: + with self.assertRaises(SystemExit) as stopped: + main() + self.assertEqual(stopped.exception.code, 23) + execute.assert_called_once() + path, args, actual_env = execute.call_args.args + self.assertEqual(path, str(runtime / "run-proton.py")) + self.assertEqual(args, [path, *selected]) + self.assertEqual(actual_env["WINESERVER"], "/sync-pack/wineserver") + self.assertEqual(actual_env["BL_SYNC_PACK"], "selected") + + class GameDebugLoggingTest(unittest.TestCase): def test_maintenance_precision_survives_run_with_performance_game_settings(self): with tempfile.TemporaryDirectory() as tmp: @@ -807,6 +956,55 @@ class GameEnvironmentTest(unittest.TestCase): subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True) self.assertEqual(target.read_text(), "general") + def test_system_powervr_preserves_dxvk_profiles_without_applying_them(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + home = root / "home" + component_dir = home / ".local/share/droiddeck-components" + component_dir.mkdir(parents=True) + base = root / "proton" + paths = { + "dxvk": "files/lib/wine/dxvk/aarch64-windows/d3d11.dll", + "fex": "files/lib/wine/aarch64-windows/libarm64ecfex.dll", + "vkd3d": "files/lib/wine/vkd3d-proton/aarch64-windows/d3d12.dll", + } + rows = [] + for comp, rel in paths.items(): + target = base / rel + target.parent.mkdir(parents=True, exist_ok=True) + target.write_text("bundled " + comp) + for scope in ("*", "42"): + source = root / (comp + ("-general" if scope == "*" else "-game")) + source.write_text(source.name) + rows.append("%s\tproton\tbuild-1\t%s\t%s\t%s\t%s\n" % ( + scope, comp, rel, hashlib.sha256(source.read_bytes()).hexdigest(), source, + )) + leftover = (base / paths["dxvk"]).with_name("d3d8.dll") + leftover.write_text("bundled d3d8") + rows.append("42\tproton\tbuild-1\tdxvk\t%s\t-\t-\n" % leftover.relative_to(base)) + (base / "version").write_text("1 build-1\n") + selection = component_dir / "desired.tsv" + selection.write_text("".join(rows)) + saved = selection.read_bytes() + script = COMPAT["BL_COMPONENTS_SETUP"] + '\nverb=waitforexitandrun; bl_components "$1"\n' + env = dict(os.environ, HOME=str(home), STEAM_COMPAT_DATA_PATH="/steam/compatdata/42", + DROIDDECK_POWERVR_RUNTIME="/system_vulkan/runtime") + + subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True) + + self.assertEqual((base / paths["dxvk"]).read_text(), "bundled dxvk") + self.assertEqual(leftover.read_text(), "bundled d3d8") + for comp in ("fex", "vkd3d"): + self.assertEqual((base / paths[comp]).read_text(), comp + "-game") + self.assertEqual(selection.read_bytes(), saved) + + # A subsequent manual-driver session still applies the saved per-game DXVK choice. + env.pop("DROIDDECK_POWERVR_RUNTIME") + subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True) + self.assertEqual((base / paths["dxvk"]).read_text(), "dxvk-game") + self.assertFalse(leftover.exists()) + self.assertEqual(selection.read_bytes(), saved) + def test_component_scope_matches_environment_scope_for_shortcut_ids(self): with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) @@ -1294,6 +1492,49 @@ class GameEnvironmentTest(unittest.TestCase): with self.assertRaises(ValueError): MODULE["apply_config"]({}, {**config, "dxvkConfigGames": []}, "42") + def test_game_logs_only_when_asked_and_only_for_game_launches(self): + game_logs = MODULE["game_logs"] + with tempfile.TemporaryDirectory() as tmp: + command = ["/proton", "waitforexitandrun", "/games/Hades/Hades.exe"] + env = {"BL_DEBUG_DIR": tmp, "VK_DRIVER_FILES": "/icd.json"} + self.assertEqual(game_logs(command, env, "1145360", now=0), env) + on = dict(env, BL_GAME_LOGS="1") + self.assertEqual(game_logs(["/proton", "run", "x.exe"], on, "1145360", now=0), on) + result = game_logs(command, on, "1145360", now=0) + folder = Path(result["PROTON_LOG_DIR"]) + self.assertEqual(folder.parent, Path(tmp) / "games") + self.assertTrue(folder.name.endswith("-1145360")) + self.assertEqual(result["DXVK_LOG_PATH"], str(folder)) + self.assertEqual(result["PROTON_LOG"], "1") + launch = (folder / "launch.txt").read_text() + self.assertIn("VK_DRIVER_FILES=/icd.json", launch) + self.assertNotIn("PROTON_LOG", env) + named = game_logs(command, on, None, now=0) + self.assertTrue(Path(named["PROTON_LOG_DIR"]).name.endswith("-Hades")) + + def test_rapid_game_launches_keep_separate_diagnostics(self): + with tempfile.TemporaryDirectory() as tmp, mock.patch("subprocess.Popen"): + env = {"BL_GAME_LOGS": "1", "BL_DEBUG_DIR": tmp} + first = MODULE["game_logs"](["/proton", "waitforexitandrun", "first.exe"], env, "42", now=0) + second = MODULE["game_logs"](["/proton", "waitforexitandrun", "second.exe"], env, "42", now=0) + self.assertNotEqual(first["PROTON_LOG_DIR"], second["PROTON_LOG_DIR"]) + self.assertIn("exe: first.exe", (Path(first["PROTON_LOG_DIR"]) / "launch.txt").read_text()) + self.assertIn("exe: second.exe", (Path(second["PROTON_LOG_DIR"]) / "launch.txt").read_text()) + + def test_open_driver_pairs_report_the_drivers_own_vkd3d_caps(self): + apply = MODULE["apply_config"] + config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2", "VKD3D_SHADER_MODEL": "6_9"}, + "games": {"42": {"VKD3D_SHADER_MODEL": "6_6"}}} + adreno = apply({}, config, "1") + self.assertEqual(adreno["VKD3D_FEATURE_LEVEL"], "12_2") + pair = apply({"BL_OPEN_DRIVER": "1"}, config, "1") + self.assertNotIn("VKD3D_FEATURE_LEVEL", pair) + self.assertNotIn("VKD3D_SHADER_MODEL", pair) + self.assertEqual(pair["DROIDDECK_VKD3D_CAPS"], "driver") + own = apply({"BL_OPEN_DRIVER": "1"}, config, "42") + self.assertEqual(own["VKD3D_SHADER_MODEL"], "6_6") + self.assertNotIn("VKD3D_FEATURE_LEVEL", own) + def test_game_ids_and_probes(self): for prefix in ("", "/compatdata/0", "/compatdata/0-123", "/compatdata/nope", "/compatdata/4294967296"): self.assertIsNone(MODULE["game_id"]({"STEAM_COMPAT_DATA_PATH": prefix})) diff --git a/tools/tests/test_gamescope_backend.py b/tools/tests/test_gamescope_backend.py new file mode 100644 index 0000000000..d9f91bf828 --- /dev/null +++ b/tools/tests/test_gamescope_backend.py @@ -0,0 +1,102 @@ +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + + +SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session" +DESKTOP_GPU = Path(__file__).resolve().parents[1] / "linuxfs/desktop/droiddeck-gpu" + + +class GamescopeBackendTest(unittest.TestCase): + def select(self, backend=None): + source = SESSION.read_text() + start = source.index(' backend=${BL_GAMESCOPE_BACKEND:-wayland}') + end = source.index('\n', source.index(' args=(--backend ', start)) + script = 'width=1280; height=720; nested=1280\n' + source[start:end] + script += '\nprintf "%s\\n" "${args[0]}" "${args[1]}" "${SDL_VIDEODRIVER:-unset}"\n' + env = dict(os.environ) + env.pop("BL_GAMESCOPE_BACKEND", None) + env.pop("SDL_VIDEODRIVER", None) + if backend is not None: + env["BL_GAMESCOPE_BACKEND"] = backend + return subprocess.run(["bash", "-c", script], env=env, text=True, + capture_output=True, timeout=5) + + def test_default_retains_the_wayland_backend(self): + result = self.select() + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual(["--backend", "wayland", "unset"], result.stdout.splitlines()) + + def test_sdl_uses_the_host_wayland_vulkan_swapchain(self): + result = self.select("sdl") + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual(["--backend", "sdl", "wayland"], result.stdout.splitlines()) + + def test_unknown_backend_fails_before_gamescope(self): + result = self.select("drm") + self.assertEqual(64, result.returncode) + self.assertIn("unsupported gamescope backend: drm", result.stdout) + + +class DesktopGamescopeBackendTest(unittest.TestCase): + def launch(self, backend=None): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + capture = root / "gamescope.json" + gamescope = root / "gamescope" + gamescope.write_text( + f"#!{sys.executable}\n" + "import json, os, sys\n" + "from pathlib import Path\n" + "Path(os.environ['GAMESCOPE_CAPTURE']).write_text(json.dumps({\n" + " 'args': sys.argv[1:],\n" + " 'sdl': os.environ.get('SDL_VIDEODRIVER'),\n" + " 'gdk': os.environ.get('GDK_BACKEND'),\n" + " 'qt': os.environ.get('QT_QPA_PLATFORM'),\n" + " 'wayland': os.environ.get('WAYLAND_DISPLAY'),\n" + "}))\n" + ) + gamescope.chmod(0o755) + env = dict(os.environ) + for name in ("BL_GAMESCOPE_BACKEND", "BL_DEBUG_DIR", "BL_FPS", "BL_REFRESH", "BL_HDR"): + env.pop(name, None) + env.update(PATH=f"{root}{os.pathsep}{env.get('PATH', '')}", + GAMESCOPE_CAPTURE=str(capture), WAYLAND_DISPLAY="desktop-0", BL_DESKTOP_GPU_WINDOW="0", + SDL_VIDEODRIVER="dummy", GDK_BACKEND="wayland", QT_QPA_PLATFORM="wayland") + if backend is not None: + env["BL_GAMESCOPE_BACKEND"] = backend + result = subprocess.run(["bash", str(DESKTOP_GPU), "demo", "one argument"], + env=env, text=True, capture_output=True, timeout=5) + return result, json.loads(capture.read_text()) if capture.exists() else None + + def assert_xwayland_application(self, capture): + args = capture["args"] + self.assertEqual(["env", "SDL_VIDEODRIVER=x11", "/usr/local/bin/droiddeck-gpu-window", + "demo", "one argument"], args[args.index("--") + 1:]) + self.assertEqual("x11", capture["gdk"]) + self.assertEqual("xcb", capture["qt"]) + self.assertEqual("wayland-0", capture["wayland"]) + + def test_default_keeps_wayland_and_xwayland_application(self): + result, capture = self.launch() + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual(["--backend", "wayland"], capture["args"][:2]) + self.assertEqual("x11", capture["sdl"]) + self.assert_xwayland_application(capture) + + def test_sdl_uses_wayland_without_leaking_to_the_application(self): + result, capture = self.launch("sdl") + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual(["--backend", "sdl"], capture["args"][:2]) + self.assertEqual("wayland", capture["sdl"]) + self.assert_xwayland_application(capture) + + def test_unknown_backend_fails_before_gamescope(self): + result, capture = self.launch("drm") + self.assertEqual(64, result.returncode) + self.assertIn("unsupported gamescope backend: drm", result.stderr) + self.assertIsNone(capture) diff --git a/tools/tests/test_oom_adj_preload.py b/tools/tests/test_oom_adj_preload.py new file mode 100644 index 0000000000..f6fc25ce16 --- /dev/null +++ b/tools/tests/test_oom_adj_preload.py @@ -0,0 +1,47 @@ +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + +SOURCE = Path(__file__).resolve().parents[1] / "linuxfs/preload/oomadj.c" + +PROGRAM = r""" +#include <stdio.h> +const char *bl_oom_adj_redirect(const char *path, int writing); +int main(int argc, char **argv) { + for (int i = 1; i + 1 < argc; i += 2) printf("%s\n", bl_oom_adj_redirect(argv[i + 1], argv[i][0] == 'w')); + return 0; +} +""" + + +@unittest.skipUnless(shutil.which("cc"), "needs cc") +class OomAdjPreloadTest(unittest.TestCase): + def test_only_writes_to_oom_files_go_to_dev_null(self): + with tempfile.TemporaryDirectory() as tmp: + main = Path(tmp) / "main.c" + main.write_text(PROGRAM) + binary = Path(tmp) / "probe" + subprocess.run(["cc", "-o", str(binary), str(main), str(SOURCE)], check=True) + cases = [ + ("w", "/proc/self/oom_score_adj", "/dev/null"), + ("w", "/proc/123/oom_score_adj", "/dev/null"), + ("w", "/proc/thread-self/oom_score_adj", "/dev/null"), + ("w", "/proc/12/task/34/oom_score_adj", "/dev/null"), + ("w", "/proc/self/oom_adj", "/dev/null"), + ("r", "/proc/self/oom_score_adj", "/proc/self/oom_score_adj"), + ("w", "/proc/self/oom_score", "/proc/self/oom_score"), + ("w", "/proc/abc/oom_score_adj", "/proc/abc/oom_score_adj"), + ("w", "/tmp/oom_score_adj", "/tmp/oom_score_adj"), + ] + args = [str(binary)] + for mode, path, _ in cases: + args += [mode, path] + out = subprocess.run(args, capture_output=True, text=True, check=True) + self.assertEqual(out.stdout.split(), [want for _, _, want in cases]) + self.assertIn("oom_score_adj raise was dropped", out.stderr) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_pixel_reset_diagnostics.py b/tools/tests/test_pixel_reset_diagnostics.py new file mode 100644 index 0000000000..8cb5ba1a0c --- /dev/null +++ b/tools/tests/test_pixel_reset_diagnostics.py @@ -0,0 +1,215 @@ +"""Test freshness, narrow output, and lock handling without accessing a device.""" +from datetime import datetime, timezone +import importlib.util +import json +import io +import os +from pathlib import Path +import stat +import subprocess +import sys +import tempfile +import unittest +from unittest.mock import patch + +spec = importlib.util.spec_from_file_location('reset_projection', Path(__file__).resolve().parents[1] / 'pixel_reset_diagnostics.py') +module = importlib.util.module_from_spec(spec) +spec.loader.exec_module(module) + + +class ResetProjectionTest(unittest.TestCase): + def test_only_primary_state(self): + self.assertEqual(module.primary_state('Private space secret\nStarted users state: [0=RUNNING_UNLOCKED, 10=STOPPED]'), 'RUNNING_UNLOCKED') + self.assertEqual(module.primary_state('State: RUNNING_UNLOCKED'), 'unknown') + + def test_stale_body_not_used(self): + raw = '2026-10-10 20:10:09 SYSTEM_LAST_KMSG (text, 1024 bytes)\nGNOC error type 0x2000' + result = module.kernel_projection(raw, 'America/Toronto', datetime(2026, 10, 11, 21, tzinfo=timezone.utc)) + self.assertEqual(result['status'], 'stale_entry_not_attributed_to_current_trial') + self.assertNotIn('categories', result) + + def test_repeated_dst_hour_is_ambiguous_before_freshness(self): + raw = '2026-11-01 01:30:00 SYSTEM_LAST_KMSG\nGNOC error type 0x2000' + for after in (None, datetime(2026, 11, 1, 6, tzinfo=timezone.utc)): + with self.subTest(after=after): + result = module.kernel_projection(raw, 'America/Toronto', after) + self.assertEqual(result['status'], 'ambiguous_device_local_time') + self.assertNotIn('entry_date_utc', result) + self.assertNotIn('categories', result) + self.assertNotIn('hardware_fields', result) + + def test_skipped_dst_hour_is_not_a_real_instant(self): + raw = '2026-03-08 02:30:00 SYSTEM_LAST_KMSG\nGNOC error type 0x2000' + result = module.kernel_projection(raw, 'America/Toronto') + self.assertEqual(result['status'], 'nonexistent_device_local_time') + self.assertNotIn('entry_date_utc', result) + self.assertNotIn('categories', result) + + def test_unambiguous_times_keep_correct_offsets_and_cutoff(self): + for stamp, expected in (('2026-11-01 00:30:00', '2026-11-01T04:30:00+00:00'), + ('2026-11-01 02:30:00', '2026-11-01T07:30:00+00:00'), + ('2026-03-08 03:30:00', '2026-03-08T07:30:00+00:00')): + with self.subTest(stamp=stamp): + raw = stamp + ' SYSTEM_LAST_KMSG\nGNOC' + result = module.kernel_projection(raw, 'America/Toronto') + self.assertEqual(result['entry_date_utc'], expected) + self.assertEqual(result['status'], 'projected_entry_not_a_root_cause') + cutoff = datetime.fromisoformat(expected) + self.assertEqual(module.kernel_projection(raw, 'America/Toronto', cutoff)['status'], + 'projected_entry_not_a_root_cause') + + def test_latest_entry_and_no_arbitrary_body(self): + raw = ('2026-10-10 20:10:09 SYSTEM_LAST_KMSG (text)\nGNOC error type 0x1111\n' + '2026-10-11 17:35:01 SYSTEM_LAST_KMSG (text)\n' + 'PRIVATE_TEST_VALUE=a_secret_that_must_not_be_emitted\n' + 'Error from GNOC at addr 0x28220000\nGNOC error type 0x2000\n' + 'Reboot reason: 0xc005 - Secret arbitrary description\nLast boot reason: reset,warm,gnoc_error\n') + result = module.kernel_projection(raw, 'America/Toronto', datetime(2026, 10, 11, 21, tzinfo=timezone.utc)) + self.assertEqual(result['entry_date_utc'], '2026-10-11T21:35:01+00:00') + self.assertEqual(result['hardware_fields']['gnoc_error_types'], ['0x2000']) + self.assertNotIn('0x1111', json.dumps(result)) + self.assertNotIn('a_secret', json.dumps(result)) + self.assertNotIn('arbitrary description', json.dumps(result)) + self.assertFalse(result['root_cause_proven']) + + def test_missing_entry_and_timezone(self): + self.assertEqual(module.kernel_projection('Permission denied', 'America/Toronto')['status'], 'no_accessible_entry') + self.assertEqual(module.kernel_projection('2026-10-11 17:00:00 SYSTEM_LAST_KMSG\nGNOC', 'Unknown/Region')['status'], 'unknown_device_timezone') + + def test_reason_rejects_paths_and_urls(self): + self.assertEqual(module.safe_reason('reset,warm,gnoc_error\n'), 'reset,warm,gnoc_error') + self.assertEqual(module.safe_reason('https://private.invalid/login?secret=abc'), 'unknown') + self.assertEqual(module.safe_reason('/data/private'), 'unknown') + + def test_reason_only_recognized_exact_values(self): + for reason in ('cold', 'hard', 'warm', 'reboot', 'shutdown', 'recovery', + 'bootloader', 'kernel_panic', 'watchdog', 'reset,warm,gnoc_error'): + with self.subTest(reason=reason): + self.assertEqual(module.safe_reason(reason + '\n'), reason) + for reason in ('PRIVATE TEST VALUE', 'private_test_value', '123456', + 'reboot,private_test_value', 'reset,warm,gnoc_error,private_test_value', + 'reset,warm,gnoc_error trailing_private_test_value', ''): + with self.subTest(reason=reason): + self.assertEqual(module.safe_reason(reason), 'unknown') + + def test_kernel_reason_uses_same_fixed_projection(self): + raw = ('2026-10-11 17:35:01 SYSTEM_LAST_KMSG (text)\n' + 'Last boot reason: private_test_value\n' + 'Last boot reason: reset,warm,gnoc_error trailing_private_test_value\n' + 'Last boot reason: reset,warm,gnoc_error\n' + 'Last boot reason:\nPRIVATE TEST VALUE\n') + result = module.kernel_projection(raw, 'America/Toronto') + self.assertEqual(result['last_boot_reasons'], ['reset,warm,gnoc_error', 'unknown']) + self.assertNotIn('private_test_value', json.dumps(result)) + self.assertNotIn('PRIVATE TEST VALUE', json.dumps(result)) + + def test_primary_state_uses_fixed_categories(self): + for state in ('RUNNING_LOCKED', 'RUNNING_UNLOCKING', 'RUNNING_UNLOCKED'): + self.assertEqual(module.primary_state('Started users state: [0=' + state + ']'), state) + for state in ('RUNNING_PRIVATE_TEST_VALUE', 'RUNNING_UNLOCKED_PRIVATE', + 'RUNNING_UNLOCKED=private_test_value'): + self.assertEqual(module.primary_state('Started users state: [0=' + state + ']'), 'unknown') + + def test_property_reason_never_exports_custom_text(self): + def run(argv, **kwargs): + if argv[-2:] == ['getprop', 'ro.boot.bootreason']: + text = 'PRIVATE TEST VALUE' + elif argv[-2:] == ['getprop', 'sys.boot.reason']: + text = 'reset,warm,gnoc_error,private_test_value' + elif argv[-1] == 'persist.sys.timezone': + text = 'America/Toronto' + else: + text = '' + return subprocess.CompletedProcess(argv, 0, text, '') + with patch.object(module.subprocess, 'run', side_effect=run): + result = module.collect('adb', 'test-device') + self.assertEqual(result['bootloader_reason'], 'unknown') + self.assertEqual(result['system_boot_reason'], 'unknown') + self.assertNotIn('PRIVATE TEST VALUE', json.dumps(result)) + self.assertNotIn('private_test_value', json.dumps(result)) + + @unittest.skipUnless(os.name == 'posix', 'POSIX private file modes') + def test_cli_output_is_private_before_writing(self): + with tempfile.TemporaryDirectory() as directory: + output = Path(directory) / 'diagnostics.json' + saved_umask = os.umask(0) + original_fdopen = os.fdopen + original_path_open = Path.open + creation_modes = [] + def inspect_stream(stream): + try: + creation_modes.append(stat.S_IMODE(os.fstat(stream.fileno()).st_mode)) + self.assertEqual(os.fstat(stream.fileno()).st_size, 0) + self.assertEqual(creation_modes[-1], 0o600) + except BaseException: + stream.close() + raise + return stream + def inspect_fd(fd, *args, **kwargs): + return inspect_stream(original_fdopen(fd, *args, **kwargs)) + def inspect_path(path, *args, **kwargs): + stream = original_path_open(path, *args, **kwargs) + return inspect_stream(stream) if path == output else stream + try: + with patch.object(sys, 'argv', ['diagnostics', '--serial', 'test-device', + '--output', str(output)]), \ + patch.object(module, 'collect', return_value={'boot_count': 12}), \ + patch.object(os, 'fdopen', side_effect=inspect_fd), \ + patch.object(Path, 'open', new=inspect_path), \ + patch('sys.stdout', new_callable=io.StringIO): + module.main() + finally: + os.umask(saved_umask) + self.assertEqual(creation_modes, [0o600]) + self.assertEqual(stat.S_IMODE(output.stat().st_mode), 0o600) + self.assertEqual(json.loads(output.read_text()), {'boot_count': 12}) + + def test_output_refuses_existing_file(self): + with tempfile.TemporaryDirectory() as directory: + output = Path(directory) / 'diagnostics.json' + output.write_text('existing controlled test data') + with self.assertRaises(FileExistsError): + module.write_private_output(output, '{"replacement":true}\n') + self.assertEqual(output.read_text(), 'existing controlled test data') + + @unittest.skipUnless(os.name == 'posix', 'POSIX symlink behavior') + def test_output_refuses_symlink_without_touching_target(self): + with tempfile.TemporaryDirectory() as directory: + target = Path(directory) / 'target.json' + target.write_text('existing controlled test data') + output = Path(directory) / 'diagnostics.json' + output.symlink_to(target) + with self.assertRaises(FileExistsError): + module.write_private_output(output, '{"replacement":true}\n') + self.assertTrue(output.is_symlink()) + self.assertEqual(target.read_text(), 'existing controlled test data') + + def test_locked_skips_kernel_body(self): + commands = [] + def run(argv, **kwargs): + commands.append(argv) + if argv[-2:] == ['dumpsys', 'user']: + text = 'Started users state: [0=RUNNING_LOCKED]' + elif argv[-1] == 'persist.sys.timezone': + text = 'America/Toronto' + elif argv[-3:] == ['get', 'global', 'boot_count']: + text = '12' + else: + text = '' + return subprocess.CompletedProcess(argv, 0, text, 'PRIVATE_STDERR') + with patch.object(module.subprocess, 'run', side_effect=run): + result = module.collect('adb', 'test-device', True) + self.assertEqual(result['kernel']['status'], 'requires_user_unlock') + self.assertFalse(any('--print' in command for command in commands)) + self.assertNotIn('PRIVATE_STDERR', json.dumps(result)) + + def test_command_failure_does_not_export_stderr(self): + with patch.object(module.subprocess, 'run', return_value=subprocess.CompletedProcess([], 1, 'UNRELATED_DATA', 'PRIVATE_STDERR')): + result = module.collect('adb', 'test-device', True) + self.assertIsNone(result['boot_count']) + self.assertNotIn('UNRELATED_DATA', json.dumps(result)) + self.assertNotIn('PRIVATE_STDERR', json.dumps(result)) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/tests/test_powervr_runtime.py b/tools/tests/test_powervr_runtime.py new file mode 100644 index 0000000000..475f899279 --- /dev/null +++ b/tools/tests/test_powervr_runtime.py @@ -0,0 +1,291 @@ +import importlib.util +import io +import json +from pathlib import Path +import subprocess +import tarfile +import tempfile +import unittest +from unittest.mock import patch +from zipfile import ZipFile, ZipInfo + + +spec = importlib.util.spec_from_file_location('powervr_fetch', + Path(__file__).resolve().parents[1] / 'powervr/fetch.py') +runtime = importlib.util.module_from_spec(spec) +spec.loader.exec_module(runtime) + + +def elf(): + content = bytearray(64) + content[:6], content[18:20] = b'\x7fELF\x02\x01', b'\xb7\x00' + return bytes(content) + + +def pe(architecture): + content = bytearray(128) + content[:2], content[60:64], content[64:68] = b'MZ', (64).to_bytes(4, 'little'), b'PE\0\0' + content[68:70] = b'\x4c\x01' if architecture == 'x32' else b'\x64\x86' + content[88:90] = b'\x0b\x01' if architecture == 'x32' else b'\x0b\x02' + return bytes(content) + + +def tar(entries): + stream = io.BytesIO() + with tarfile.open(fileobj=stream, mode='w') as archive: + for name, kind, content in entries: + info = tarfile.TarInfo(name) + info.type = kind + if kind in (tarfile.SYMTYPE, tarfile.LNKTYPE): + info.linkname = content + archive.addfile(info) + elif kind == tarfile.REGTYPE: + info.size = len(content) + archive.addfile(info, io.BytesIO(content)) + else: + archive.addfile(info) + return subprocess.run(['zstd', '-q', '-c'], input=stream.getvalue(), + capture_output=True, check=True).stdout + + +def tar_gz(entries): + stream = io.BytesIO() + with tarfile.open(fileobj=stream, mode='w:gz') as archive: + for name, kind, content in entries: + info = tarfile.TarInfo(name) + info.type = kind + if kind == tarfile.SYMTYPE: + info.linkname = content + archive.addfile(info) + elif kind == tarfile.REGTYPE: + info.size = len(content) + archive.addfile(info, io.BytesIO(content)) + else: + archive.addfile(info) + return stream.getvalue() + + +def upstream_dxvk(version, architecture_of=lambda arch: arch): + return {'dxvk-%s/%s/%s' % (version, arch, name): pe(architecture_of(arch)) + for arch in ('x32', 'x64') + for name in ('d3d8.dll', 'd3d9.dll', 'd3d10core.dll', 'd3d11.dll', 'dxgi.dll')} + + +class PowerVRRuntimeTest(unittest.TestCase): + def setUp(self): + self.temporary = tempfile.TemporaryDirectory() + self.addCleanup(self.temporary.cleanup) + self.root = Path(self.temporary.name) + self.cache = self.root / 'cache' + self.cache.mkdir() + for name, content in { + 'tools/powervr/fetch.py': b'fixture assembler', + 'tools/hybris/run-proton.py': b'print("fixture Proton wrapper")\n', + 'tools/hybris/source.env': b'HYBRIS_REVISION=fixture\n', + 'tools/vulkan-wsi/licenses/Vulkan-Headers/LICENSE.md': b'Khronos headers attribution\n', + 'tools/vulkan-wsi/licenses/Vulkan-Headers/MIT.txt': b'MIT license fixture\n', + }.items(): + path = self.root / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_bytes(content) + bridge = {name: ('file', 0o755, elf()) for name in runtime.REQUIRED_LIBRARIES if name.startswith('lib/')} + bridge['lib/libhybris-common.so.1.0.0'] = bridge.pop('lib/libhybris-common.so.1') + bridge['lib/libhybris-common.so.1'] = ('symlink', 0o777, 'libhybris-common.so.1.0.0') + data = runtime.pack(bridge) + self.release = {'format': 1, 'hybris': self.component('bridge.tzst', data), 'archives': []} + self.release['hybris'].update({ + 'tree_sha256': runtime.tree_digest(bridge), + 'recipe_inputs': {'tools/hybris/source.env': runtime.sha256((self.root / 'tools/hybris/source.env').read_bytes())}}) + files = {'dxvk/' + arch + '/' + name: pe(arch) + for arch in ('x32', 'x64') + for name in ('d3d8.dll', 'd3d9.dll', 'd3d10core.dll', 'd3d11.dll', 'dxgi.dll')} + files['wsi/libVkLayer_window_system_integration.so'] = elf() + stream = io.BytesIO() + with ZipFile(stream, 'w') as archive: + for name, content in files.items(): + archive.writestr(name, content) + component = self.component('graphics.zip', stream.getvalue()) + component.update({'ignored': [], 'files': [ + {'name': name, 'path': name, 'size': len(content), 'sha256': runtime.sha256(content), 'mode': 0o644} + for name, content in files.items()]}) + self.release['archives'].append(component) + self.pins = self.root / 'tools/powervr/release.json' + self.pins.write_bytes(runtime.json_bytes(self.release)) + + def component(self, name, data): + component = {'url': 'https://example.invalid/' + name, 'size': len(data), + 'sha256': runtime.sha256(data), 'recipe_inputs': {}} + (self.cache / (component['sha256'] + '-' + name)).write_bytes(data) + return component + + def add_upstream_dxvk(self, files): + top = next(iter(files)).split('/')[0] + data = tar_gz([(top, tarfile.DIRTYPE, None)] + + [(name, tarfile.REGTYPE, content) for name, content in files.items()]) + component = self.component('dxvk-upstream.tar.gz', data) + component.update({'format': 'tar.gz', 'ignored': [], 'files': [ + {'name': name, 'path': name, 'size': len(content), 'sha256': runtime.sha256(content), 'mode': 0o755} + for name, content in files.items()]}) + self.release['archives'].append(component) + self.pins.write_bytes(runtime.json_bytes(self.release)) + return component + + def assembled(self): + runtime.assemble(self.root, self.cache) + return runtime.read_tar((self.root / runtime.ASSETS / 'runtime.tzst').read_bytes()) + + def test_complete_payload_preserves_symlinks_and_is_reproducible(self): + self.assembled() + first = (self.root / runtime.ASSETS / 'runtime.tzst').read_bytes() + runtime.verify(self.root) + self.assembled() + self.assertEqual(first, (self.root / runtime.ASSETS / 'runtime.tzst').read_bytes()) + self.assertEqual(runtime.read_tar(first)['lib/libhybris-common.so.1'][0], 'symlink') + + def test_upstream_tarball_adds_a_second_dxvk_payload(self): + files = upstream_dxvk('2.6.2') + self.add_upstream_dxvk(files) + entries = self.assembled() + runtime.verify(self.root) + for name, content in files.items(): + self.assertEqual(entries[name], ('file', 0o755, content)) + self.assertIn('dxvk/x64/d3d9.dll', entries) + + def test_second_dxvk_payload_with_wrong_pe_architecture_is_rejected(self): + self.add_upstream_dxvk(upstream_dxvk('2.6.2', lambda arch: 'x64' if arch == 'x32' else 'x32')) + with self.assertRaisesRegex(ValueError, 'wrong PE architecture: dxvk-2.6.2/'): + self.assembled() + + def test_tar_gz_rejects_symlinks_unknown_members_and_changed_files(self): + pin = {'name': 'dxvk-1/x64/d3d9.dll', 'path': 'dxvk-1/x64/d3d9.dll', 'size': 4, + 'sha256': runtime.sha256(b'good'), 'mode': 0o755} + component = {'files': [pin], 'ignored': []} + cases = [ + [('dxvk-1/x64/d3d9.dll', tarfile.SYMTYPE, '../../outside')], + [('dxvk-1/x64/d3d9.dll', tarfile.REGTYPE, b'good'), ('dxvk-1/extra.dll', tarfile.REGTYPE, b'x')], + [('dxvk-1/x64/d3d9.dll', tarfile.REGTYPE, b'evil')], + [], + ] + for entries in cases: + with self.subTest(entries=[name for name, _, _ in entries]), self.assertRaises(ValueError): + runtime.read_tar_gz(tar_gz(entries), component) + self.assertEqual(runtime.read_tar_gz(tar_gz([('dxvk-1/x64/d3d9.dll', tarfile.REGTYPE, b'good')]), component), + {'dxvk-1/x64/d3d9.dll': ('file', 0o755, b'good')}) + with self.assertRaisesRegex(ValueError, 'unsupported component archive format'): + runtime.read_component(b'', {'format': 'rar'}) + + def test_stale_wrapper_cannot_pass_with_an_updated_archive_checksum(self): + self.assembled() + (self.root / 'tools/hybris/run-proton.py').write_text('print("new wrapper")\n') + with self.assertRaisesRegex(ValueError, 'assembly inputs changed'): + runtime.verify(self.root) + + def test_header_licenses_are_bundled_verbatim(self): + entries = self.assembled() + for source, target in runtime.BUNDLED_LICENSES.items(): + self.assertEqual(runtime.read(entries, target), (self.root / source).read_bytes()) + + def test_missing_or_modified_header_license_is_rejected(self): + original = self.assembled() + target = 'licenses/Vulkan-Headers/MIT.txt' + for replacement in (None, ('file', 0o644, b'stale license')): + with self.subTest(replacement=replacement): + entries = dict(original) + if replacement is None: + del entries[target] + else: + entries[target] = replacement + with self.assertRaisesRegex(ValueError, 'license missing or stale'): + runtime.check_bundle(entries, self.release, self.root) + + def test_changed_tracked_header_license_rejects_old_bundle(self): + self.assembled() + source = next(iter(runtime.BUNDLED_LICENSES)) + (self.root / source).write_bytes(b'changed license text') + with self.assertRaisesRegex(ValueError, 'assembly inputs changed'): + runtime.verify(self.root) + + def test_changed_component_recipe_requires_new_release_pin(self): + self.assembled() + (self.root / 'tools/hybris/source.env').write_text('HYBRIS_REVISION=new-source\n') + with self.assertRaisesRegex(ValueError, 'recipe changed'): + runtime.verify(self.root) + + def test_old_dxvk_cannot_pass_by_updating_only_the_bundle_checksum(self): + entries = self.assembled() + entries['dxvk/x64/d3d11.dll'] = ('file', 0o644, pe('x64') + b'old DLL') + archive = runtime.pack(entries) + with self.assertRaisesRegex(ValueError, 'component mismatch'): + runtime.verify_archive(archive, runtime.sha256(archive), self.root) + + def test_wrong_pe_architecture_rejected_even_with_matching_member_pin(self): + entries = self.assembled() + name = 'dxvk/x32/d3d11.dll' + entries[name] = ('file', 0o644, pe('x64')) + pin = next(item for item in self.release['archives'][0]['files'] if item['path'] == name) + pin['sha256'] = runtime.sha256(pe('x64')) + with self.assertRaisesRegex(ValueError, 'wrong PE architecture'): + runtime.check_bundle(entries, self.release, self.root) + + def test_unpinned_bridge_file_is_rejected(self): + entries = self.assembled() + entries['lib/extra-loader.so'] = ('file', 0o755, elf()) + with self.assertRaisesRegex(ValueError, 'bridge differs'): + runtime.check_bundle(entries, self.release, self.root) + + def test_failed_download_leaves_the_previous_payload_ready(self): + self.assembled() + before = (self.root / runtime.ASSETS / 'version.txt').read_bytes() + component = self.release['archives'][0] + (self.cache / (component['sha256'] + '-graphics.zip')).write_bytes(b'bad cache') + with patch.object(runtime, 'urlopen', return_value=io.BytesIO(b'corrupt response')): + with self.assertRaisesRegex(ValueError, 'checksum mismatch'): + runtime.assemble(self.root, self.cache) + self.assertEqual(before, (self.root / runtime.ASSETS / 'version.txt').read_bytes()) + runtime.verify(self.root) + + def test_tar_rejects_traversal_duplicate_special_files_and_symlink_escape(self): + cases = [ + [('../escape', tarfile.REGTYPE, b'x')], + [('file', tarfile.REGTYPE, b'x'), ('./file', tarfile.REGTYPE, b'y')], + [('device', tarfile.CHRTYPE, b'')], + [('file', tarfile.LNKTYPE, 'other')], + [('lib/link', tarfile.SYMTYPE, '../../outside')], + [('lib/link', tarfile.SYMTYPE, '/absolute')], + [('lib/a', tarfile.SYMTYPE, 'b'), ('lib/b', tarfile.SYMTYPE, 'a')], + [('lib', tarfile.SYMTYPE, 'target'), ('target', tarfile.REGTYPE, b'x'), + ('lib/child', tarfile.REGTYPE, b'x')], + ] + for members in cases: + with self.subTest(members=members): + with self.assertRaises(ValueError): + runtime.read_tar(tar(members)) + + def test_relative_symlink_that_stays_inside_runtime_is_preserved(self): + entries = runtime.read_tar(tar([ + ('lib/a', tarfile.REGTYPE, b'library'), ('lib/child/link', tarfile.SYMTYPE, '../a')])) + self.assertEqual(runtime.read(entries, 'lib/child/link'), b'library') + + def test_zip_rejects_symlink_even_if_name_is_allowed(self): + stream = io.BytesIO() + with ZipFile(stream, 'w') as archive: + info = ZipInfo('allowed') + info.create_system = 3 + info.external_attr = 0o120777 << 16 + archive.writestr(info, '../outside') + with self.assertRaisesRegex(ValueError, 'unexpected component archive entry'): + runtime.read_zip(stream.getvalue(), {'files': [], 'ignored': ['allowed']}) + + def test_zip_rejects_unknown_and_duplicate_members(self): + for names in (['unexpected'], ['allowed', 'allowed'], ['../escape']): + with self.subTest(names=names): + stream = io.BytesIO() + with ZipFile(stream, 'w') as archive: + for name in names: + archive.writestr(name, b'file') + with self.assertRaises(ValueError): + runtime.read_zip(stream.getvalue(), {'files': [], 'ignored': ['allowed']}) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/tests/test_proton_wrapper.py b/tools/tests/test_proton_wrapper.py new file mode 100644 index 0000000000..175d4600a5 --- /dev/null +++ b/tools/tests/test_proton_wrapper.py @@ -0,0 +1,228 @@ +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + + +TOOLS = Path(__file__).resolve().parents[1] +WRAPPER_SOURCE = TOOLS / "hybris/run-proton.py" +DLL_NAMES = ("d3d8.dll", "d3d9.dll", "d3d10core.dll", "d3d11.dll", "dxgi.dll") +DXVK_X64_ANCHOR = 'g_proton.arch_pe_dir("wine/dxvk", False) + f + ".dll"' +DXVK_X32_ANCHOR = 'g_proton.arch_pe_dir("wine/dxvk", True) + f + ".dll"' +PREFIX_ANCHOR = " # check whether any prefix config has changed" + + +PROTON_SOURCE = '''import json +import os +from pathlib import Path +import sys + +from neighbor import NEIGHBOR + + +class Proton: + def arch_pe_dir(self, directory, is32): + return str(Path(__file__).parent / "stock" / ("x32" if is32 else "x64")) + "/" + + +g_proton = Proton() + + +def prefix_marker(): + if True: + prefix_info = "stock" + # check whether any prefix config has changed + return prefix_info + + +def payloads(): + result = {"x64": {}, "x32": {}} + for f in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi"): + x64 = g_proton.arch_pe_dir("wine/dxvk", False) + f + ".dll" + x32 = g_proton.arch_pe_dir("wine/dxvk", True) + f + ".dll" + result["x64"][f + ".dll"] = Path(x64).read_text() + result["x32"][f + ".dll"] = Path(x32).read_text() + return result + + +def main(): + record = { + "argv0": sys.argv[0], + "argv": sys.argv[1:], + "file": __file__, + "neighbor": NEIGHBOR, + "prefix": prefix_marker(), + "payloads": payloads(), + "openvr": g_proton.arch_pe_dir("wine/dxvk", False) + "openvr_api_dxvk.dll", + } + Path(os.environ["PROBE"]).write_text(json.dumps(record)) + raise SystemExit(int(os.environ.get("PROTON_EXIT", "0"))) + + +main() +''' + + +class ProtonWrapperTest(unittest.TestCase): + def fixture(self, root): + wrapper_dir = root / 'DXVK profile "quotes" $dollar `backticks`' + wrapper_dir.mkdir(parents=True) + wrapper = wrapper_dir / "run-proton.py" + shutil.copy2(WRAPPER_SOURCE, wrapper) + + dxvk = wrapper_dir / "dxvk" + for architecture in ("x32", "x64"): + payload = dxvk / architecture + payload.mkdir(parents=True) + for name in DLL_NAMES: + (payload / name).write_text(f"{architecture}:{name}") + + depot = root / "Proton depot with spaces" + depot.mkdir() + proton = depot / "selected proton.py" + proton.write_text(PROTON_SOURCE) + (depot / "neighbor.py").write_text('NEIGHBOR = "imported from selected depot"\n') + return {"wrapper": wrapper, "dxvk": dxvk, "depot": depot, "proton": proton, + "probe": root / "proton-ran.json"} + + def run_wrapper(self, fixture, *proton_args, check=False, exit_status=0, env=None): + command = [sys.executable, str(fixture["wrapper"])] + if check: + command.append("--check") + command.extend((str(fixture["proton"]), *proton_args)) + return subprocess.run( + command, + cwd=fixture["wrapper"].parent, + env={"PATH": os.defpath, "PROBE": str(fixture["probe"]), + "PROTON_EXIT": str(exit_status), **(env or {})}, + text=True, + capture_output=True, + ) + + def test_launch_uses_both_staged_payloads_and_selected_proton_context(self): + with tempfile.TemporaryDirectory() as tmp: + fixture = self.fixture(Path(tmp)) + original_source = fixture["proton"].read_bytes() + arguments = ("waitforexitandrun", "game with spaces.exe", 'quoted "value"', + "$literal-dollar", "`literal-backticks`") + result = self.run_wrapper(fixture, *arguments) + + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(fixture["proton"].read_bytes(), original_source) + record = json.loads(fixture["probe"].read_text()) + self.assertEqual(record["argv0"], str(fixture["proton"])) + self.assertEqual(record["argv"], list(arguments)) + self.assertEqual(record["file"], str(fixture["proton"])) + self.assertEqual(record["neighbor"], "imported from selected depot") + self.assertEqual(record["prefix"], "stock\ndroiddeck-dxvk-profile-v1") + self.assertEqual(record["openvr"], str(fixture["depot"] / "stock/x64/openvr_api_dxvk.dll")) + for architecture in ("x32", "x64"): + self.assertEqual( + record["payloads"][architecture], + {name: f"{architecture}:{name}" for name in DLL_NAMES}, + ) + + def test_named_sibling_payload_replaces_the_default(self): + with tempfile.TemporaryDirectory() as tmp: + fixture = self.fixture(Path(tmp)) + for architecture in ("x32", "x64"): + payload = fixture["wrapper"].parent / "dxvk-2.6.2" / architecture + payload.mkdir(parents=True) + for name in DLL_NAMES: + (payload / name).write_text(f"2.6.2 {architecture}:{name}") + result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe", + env={"DROIDDECK_HYBRIS_DXVK": "dxvk-2.6.2"}) + + self.assertEqual(result.returncode, 0, result.stderr) + record = json.loads(fixture["probe"].read_text()) + for architecture in ("x32", "x64"): + self.assertEqual( + record["payloads"][architecture], + {name: f"2.6.2 {architecture}:{name}" for name in DLL_NAMES}, + ) + + def test_payload_names_outside_the_wrapper_directory_are_refused(self): + for name in ("../dxvk", "dxvk/../../x", "/tmp/dxvk", "other", ".dxvk"): + with self.subTest(name=name), tempfile.TemporaryDirectory() as tmp: + fixture = self.fixture(Path(tmp)) + result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe", + env={"DROIDDECK_HYBRIS_DXVK": name}) + + self.assertEqual(result.returncode, 1) + self.assertIn("invalid payload name", result.stderr) + self.assertFalse(fixture["probe"].exists()) + + def test_check_validates_without_executing_proton(self): + with tempfile.TemporaryDirectory() as tmp: + fixture = self.fixture(Path(tmp)) + result = self.run_wrapper(fixture, check=True) + + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("payload present and Proton layout supported", result.stdout) + self.assertFalse(fixture["probe"].exists()) + + def test_check_rejects_malformed_source_before_its_top_level_code_runs(self): + with tempfile.TemporaryDirectory() as tmp: + fixture = self.fixture(Path(tmp)) + source = fixture["proton"].read_text() + source = source.replace( + "import sys\n", 'import sys\n\nPath(os.environ["PROBE"]).write_text("top-level")\n', 1) + fixture["proton"].write_text(source + "\nthis is not valid =\n") + result = self.run_wrapper(fixture, check=True) + + self.assertEqual(result.returncode, 1, result.stderr) + self.assertIn("DroidDeck DXVK profile:", result.stderr) + self.assertFalse(fixture["probe"].exists()) + + def test_preflight_rejects_each_missing_or_empty_payload_before_proton_runs(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + for state in ("missing", "empty"): + for architecture in ("x32", "x64"): + for name in DLL_NAMES: + with self.subTest(state=state, architecture=architecture, name=name): + fixture = self.fixture(root / f"{state}-{architecture}-{name}") + payload = fixture["dxvk"] / architecture / name + if state == "missing": + payload.unlink() + else: + payload.write_bytes(b"") + result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe") + self.assertEqual(result.returncode, 1, result.stderr) + self.assertIn(f"{state} DXVK file", result.stderr) + self.assertFalse(fixture["probe"].exists()) + + def test_preflight_rejects_changed_proton_layout_or_syntax_before_proton_runs(self): + mutations = [] + for label, anchor in (("x64", DXVK_X64_ANCHOR), ("x32", DXVK_X32_ANCHOR), + ("prefix", PREFIX_ANCHOR)): + mutations.extend(((f"missing-{label}", lambda text, anchor=anchor: text.replace(anchor, "missing_anchor", 1)), + (f"duplicate-{label}", lambda text, anchor=anchor: text + "\n# " + anchor + "\n"))) + mutations.append(("syntax-error", lambda text: text + "\nthis is not valid =\n")) + + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + for label, mutate in mutations: + with self.subTest(layout=label): + fixture = self.fixture(root / label) + fixture["proton"].write_text(mutate(fixture["proton"].read_text())) + result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe") + self.assertEqual(result.returncode, 1, result.stderr) + self.assertIn("DroidDeck DXVK profile:", result.stderr) + self.assertFalse(fixture["probe"].exists()) + + def test_proton_exit_status_is_propagated(self): + with tempfile.TemporaryDirectory() as tmp: + fixture = self.fixture(Path(tmp)) + result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe", exit_status=23) + + self.assertEqual(result.returncode, 23, result.stderr) + self.assertTrue(fixture["probe"].exists()) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_runtime_inputs.py b/tools/tests/test_runtime_inputs.py index ebb6cf97ee..e747f3320f 100644 --- a/tools/tests/test_runtime_inputs.py +++ b/tools/tests/test_runtime_inputs.py @@ -6,6 +6,7 @@ import subprocess import tarfile import tempfile import unittest +from unittest.mock import patch from unittest import mock from zipfile import ZipFile @@ -20,6 +21,10 @@ class RuntimeInputsTest(unittest.TestCase): self.temp = tempfile.TemporaryDirectory() self.addCleanup(self.temp.cleanup) self.root = Path(self.temp.name) + # Component archive validation has its own binary/archive fixtures. + component_check = patch.object(runtime, 'verify_powervr') + component_check.start() + self.addCleanup(component_check.stop) paths = runtime.outputs(self.root) for name in runtime.required(): path = self.root / paths.get(name, 'app/src/main/' + name) @@ -115,6 +120,20 @@ class RuntimeInputsTest(unittest.TestCase): with self.assertRaisesRegex(ValueError, 'quest1.tzst'): runtime.record(self.root) + def test_changed_powervr_wrapper_rejects_old_outputs(self): + wrapper = self.root / 'tools/hybris/run-proton.py' + wrapper.parent.mkdir(parents=True) + wrapper.write_text('current wrapper') + runtime.record(self.root) + wrapper.write_text('changed wrapper') + with self.assertRaisesRegex(ValueError, 'sources changed'): + runtime.verify(self.root) + + def test_missing_powervr_bundle_cannot_be_attested(self): + (self.root / 'app/src/main/assets/hybris/runtime.tzst').unlink() + with self.assertRaisesRegex(ValueError, 'assets/hybris/runtime.tzst'): + runtime.record(self.root) + def test_modified_prebuilt_binary_is_rejected(self): runtime.record(self.root) (self.root / 'app/src/main/jniLibs/arm64-v8a/libproot.so').write_bytes(b'old APK binary') diff --git a/tools/tests/test_steam_helper_affinity.py b/tools/tests/test_steam_helper_affinity.py new file mode 100644 index 0000000000..97549ac05d --- /dev/null +++ b/tools/tests/test_steam_helper_affinity.py @@ -0,0 +1,91 @@ +import json +import os +from pathlib import Path +import shlex +import subprocess +import sys +import tempfile +import unittest + +WRAPPER = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-steam-taskset" + + +class SteamHelperAffinityTest(unittest.TestCase): + def launch(self, status, form="helper", configured=True): + with tempfile.TemporaryDirectory(prefix="droiddeck-helper-") as temporary: + root = Path(temporary) + helper = root / "steamwebhelper" + helper.write_text(f"#!{sys.executable}\n" + + 'import json, os, sys\n' + 'with open(os.environ["STARTS"],"a") as f: f.write(json.dumps(sys.argv[1:])+"\\n")\n' + 'sys.exit(23)\n') + helper.chmod(0o755) + real = root / "real-taskset" + real.write_text(f"#!{sys.executable}\n" + + 'import json, os, sys\n' + 'with open(os.environ["TRACE"],"a") as f: f.write(json.dumps(sys.argv[1:])+"\\n")\n' + f'sys.exit({status})\n') + real.chmod(0o755) + wrapper = root / "taskset" + wrapper.write_text(WRAPPER.read_text().replace("/usr/bin/taskset", shlex.quote(str(real)))) + helper_path = helper + if form == "alias": + helper_path = root / "helper symlink" + helper_path.symlink_to(helper) + elif form == "other": + helper_path = root / "other/steamwebhelper" + helper_path.parent.mkdir() + helper_path.write_text(helper.read_text()) + helper_path.chmod(0o755) + args = ["0x7c", str(helper_path), "arg with spaces", "--literal=$HOME"] + if form == "query": + args = ["-p", "12345"] + elif form == "invalid": + args[0] = "not-a-mask" + elif form == "empty": + args = [] + env = dict(os.environ, TRACE=str(root / "trace"), STARTS=str(root / "starts")) + env.pop("BL_STEAM_WEBHELPER", None) + if configured: + env["BL_STEAM_WEBHELPER"] = str(helper) + result = subprocess.run(["bash", str(wrapper), *args], env=env, + capture_output=True, text=True, timeout=5) + trace = [json.loads(x) for x in (root / "trace").read_text().splitlines()] + starts = ([json.loads(x) for x in (root / "starts").read_text().splitlines()] + if (root / "starts").exists() else []) + return result, trace, starts, args + + def test_denied_pinning_still_executes_helper_once(self): + result, trace, starts, args = self.launch(1) + self.assertEqual(result.returncode, 23) + self.assertEqual(starts, [args[2:]]) + self.assertEqual(len(trace), 1) + self.assertEqual(trace[0][:2], ["-p", "0x7c"]) + self.assertRegex(trace[0][2], r"^[1-9][0-9]*$") + self.assertIn("using the allowed CPUs", result.stderr) + + def test_successful_pinning_preserves_helper_exit_status(self): + result, trace, starts, args = self.launch(0) + self.assertEqual(result.returncode, 23) + self.assertEqual(starts, [args[2:]]) + self.assertEqual(trace[0][:2], ["-p", "0x7c"]) + self.assertNotIn("pinning unavailable", result.stderr) + + def test_symlink_to_actual_helper_is_recognized(self): + result, _, starts, args = self.launch(1, "alias") + self.assertEqual(result.returncode, 23) + self.assertEqual(starts, [args[2:]]) + + def test_other_taskset_forms_and_targets_pass_through(self): + for form, configured in [("other", True), ("query", True), ("invalid", True), + ("empty", True), ("helper", False)]: + with self.subTest(form=form, configured=configured): + result, trace, starts, args = self.launch(47, form, configured) + self.assertEqual(result.returncode, 47) + self.assertEqual(trace, [args]) + self.assertEqual(starts, []) + self.assertNotIn("pinning unavailable", result.stderr) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_steam_presentation.py b/tools/tests/test_steam_presentation.py new file mode 100644 index 0000000000..fc1b6fec35 --- /dev/null +++ b/tools/tests/test_steam_presentation.py @@ -0,0 +1,75 @@ +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + +SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session" + + +class SteamPresentationTest(unittest.TestCase): + def launch(self, enabled=None, inherited=None): + source = SESSION.read_text() + begin = source.index(" bl_steam_path=$PATH") + end = source.index("\n decky_loader=", begin) + command = source.index(' PATH="$bl_steam_path"') + command_end = source.index("\n rc=$?", command) + script = (source[begin:end] + '\n_bl_ui=(-gamepadui); _bl_cdp=(); _bl_lang=()\n' + # 0.5.0 launches through steam_client (the arm64 client, or the x86-64 one under FEX). + + 'steam_client=("$steam_root/steamrtarm64/steam")\n' + + source[command:command_end]) + env = dict(os.environ) + for key in ("BL_STEAM_GL_PRESENT", "DISABLE_GAMESCOPE_WSI", "LIBGL_KOPPER_DISABLE"): + env.pop(key, None) + if enabled is not None: + env["BL_STEAM_GL_PRESENT"] = enabled + env.update(inherited or {}) + with tempfile.TemporaryDirectory(prefix="droiddeck-steam-gl-") as tmp: + program = Path(tmp) / "steamrtarm64/steam" + program.parent.mkdir() + program.write_text(f"#!{sys.executable}\n" + + 'import json, os, sys\nprint(json.dumps({"args":sys.argv[1:],' + '"disable":os.getenv("DISABLE_GAMESCOPE_WSI"),' + '"kopper":os.getenv("LIBGL_KOPPER_DISABLE"),' + '"path":os.getenv("PATH"),' + '"helper":os.getenv("BL_STEAM_WEBHELPER")}))\n') + program.chmod(0o755) + env.update(steam_root=tmp, steam_channel="steamdeck_publicbeta") + result = subprocess.run(["bash", "-c", script, "test", "steam://open/main"], + env=env, capture_output=True, text=True, timeout=5) + self.assertEqual(result.returncode, 0, result.stderr) + launch = json.loads(result.stdout.splitlines()[-1]) + self.assertEqual(enabled == "1", launch["path"].startswith("/usr/local/libexec/droiddeck-steam:")) + self.assertEqual(launch["helper"], str(Path(tmp) / "steamrtarm64/steamwebhelper")) + return launch + + def test_default_keeps_vulkan(self): + result = self.launch() + self.assertIn("-cef-use-angle=vulkan", result["args"]) + self.assertNotIn("-cef-disable-gpu-compositing", result["args"]) + self.assertIsNone(result["disable"]) + self.assertIsNone(result["kopper"]) + + def test_system_powervr_keeps_gpu_gl_with_software_web_compositing(self): + result = self.launch("1") + self.assertIn("-cef-use-angle=gl", result["args"]) + self.assertIn("-cef-use-gl=angle", result["args"]) + self.assertIn("-cef-force-gpu", result["args"]) + self.assertIn("-cef-disable-gpu-compositing", result["args"]) + self.assertNotIn("-cef-disable-gpu", result["args"]) + self.assertEqual(result["disable"], "1") + self.assertEqual(result["kopper"], "true") + self.assertEqual(result["args"][-1], "steam://open/main") + + def test_disabled_option_preserves_existing_environment(self): + result = self.launch("0", {"DISABLE_GAMESCOPE_WSI": "0", "LIBGL_KOPPER_DISABLE": "false"}) + self.assertIn("-cef-use-angle=vulkan", result["args"]) + self.assertNotIn("-cef-disable-gpu-compositing", result["args"]) + self.assertEqual(result["disable"], "0") + self.assertEqual(result["kopper"], "false") + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_vk_dmabuf_quarantine.py b/tools/tests/test_vk_dmabuf_quarantine.py new file mode 100644 index 0000000000..aeafada3ef --- /dev/null +++ b/tools/tests/test_vk_dmabuf_quarantine.py @@ -0,0 +1,120 @@ +"""Exercise production DMA-BUF release/ownership paths without a GPU. + +Wayland resources and OS timer/Android AHB endpoints are fake; list macros and +the compositor/AHB lifecycle functions come directly from the repository. +""" +import os +from pathlib import Path +import re +import shutil +import subprocess +import tempfile +import unittest + +from test_vk_pending_completion import function + +ROOT = Path(__file__).resolve().parents[2] +SRC = ROOT / 'app/src/main/cpp/waylandcomp/src' + + +class VkDmabufQuarantineTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cc = shutil.which(os.environ.get('CC', 'cc')) + if not cc: + raise AssertionError('C compiler required') + # Optional old-head input allows a genuine negative control using the + # identical harness, rather than a model of the previous behaviour. + source_dir = Path(os.environ.get('DROIDDECK_DMABUF_TEST_SOURCE', SRC)) + comp = (source_dir / 'compositor.c').read_text() + ahb = (source_dir / 'ahb_swapchain.c').read_text() + vk = (source_dir / 'vk_present.c').read_text() + names = ['get_dmabuf', 'pending_release_free', + 'pending_releases_forget_surface', 'on_pending_release_buffer_destroyed', + 'arm_release_timer', 'on_release_timer', 'release_buffer', + 'dmabuf_buffer_unref', 'drop_dmabuf', 'on_dmabuf_destroyed', + 'droiddeck_dmabuf_ahb_slot', 'droiddeck_dmabuf_unref', + 'droiddeck_release_buffer'] + helpers = [] + if re.search(r'\bstatic int buffer_release_blocked\(', comp): + helpers = [function(comp, 'buffer_release_blocked')] + if re.search(r'\bstatic void send_buffer_release_at\(', comp): + # send_buffer_release is a macro over send_buffer_release_at (with buffer tracing). + helpers += ['static void buf_trace_release(struct wl_resource *b, int line) { (void)b; (void)line; }', + '#define send_buffer_release(b) send_buffer_release_at((b), __LINE__)', + function(comp, 'send_buffer_release_at')] + else: + helpers += [function(comp, 'send_buffer_release')] + else: + helpers = ['static int __attribute__((unused)) buffer_release_blocked(struct wl_resource *b) { (void)b; return 0; }'] + if re.search(r'\bstatic int buffer_shown_elsewhere\(', comp): + # One surface per buffer in these scenarios: never shown elsewhere. + helpers += ['static int buffer_shown_elsewhere(struct wl_resource *b, const struct surface *e) ' + '{ (void)b; (void)e; return 0; }'] + if re.search(r'\bvolatile int g_release_unpaced;', comp): + # Releases stay paced in these scenarios (fps limit -1 sends them at once). + helpers.insert(0, 'static int g_release_unpaced;') + query = function(vk, 'vkp_completion_unknown') if 'int vkp_completion_unknown(' in vk else \ + 'int vkp_completion_unknown(void) { return g_dev_state == -3; }' + comp_functions = [function(comp, names[0])] + helpers + [function(comp, n) for n in names[1:]] + ahb_functions = [function(ahb, n) for n in ('buf_free', 'maybe_free', + 'on_buffer_resource_destroyed', 'send_deferred_release', + 'on_fence_readable', 'ahb_swapchain_defer_release', + 'ahb_swapchain_surface_gone')] + structs = re.search(r'struct pending_release \{.*?\n\};', comp, re.S).group() + '\n' + \ + re.search(r'struct ahb_buf \{.*?\n\};', ahb, re.S).group() + harness = Path(__file__).with_name('vk_dmabuf_quarantine_test.c').read_text() + harness = harness.replace('/* PRODUCTION_STRUCTS */', structs) + harness = harness.replace('/* PRODUCTION_FUNCTIONS */', '\n'.join([query] + comp_functions + ahb_functions)) + cls.tmp = tempfile.TemporaryDirectory(prefix='droiddeck-dmabuf-') + cls.addClassCleanup(cls.tmp.cleanup) + probe = Path(cls.tmp.name) / 'probe.c' + probe.write_text(harness) + cls.binary = probe.with_suffix('') + built = subprocess.run([cc, '-std=c11', '-Wall', '-Wextra', '-Werror', + '-Wno-unused-parameter', '-UNDEBUG', + '-I', str(SRC.parent / 'prebuilt/include'), + str(probe), '-o', str(cls.binary)], capture_output=True, text=True) + if built.returncode: + raise AssertionError(built.stdout + built.stderr) + + def run_scenario(self, name): + result = subprocess.run([str(self.binary), name], capture_output=True, text=True, timeout=10) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + + def test_replacement_retains_reference_and_release(self): + self.run_scenario('replacement') + + def test_surface_destroy_retains_reference_and_release(self): + self.run_scenario('surface-gone') + + def test_queued_release_is_held_and_timer_disarmed(self): + self.run_scenario('queued') + + def test_mixed_queue_releases_only_copied_shm(self): + self.run_scenario('mixed') + + def test_client_destroy_retains_backing_fd(self): + self.run_scenario('client-gone') + + def test_ahb_callback_retains_ownership_and_release(self): + self.run_scenario('ahb') + + def test_active_client_destroy_retains_reference(self): + self.run_scenario('active-client-gone') + + def test_healthy_ahb_callback_and_cleanup(self): + self.run_scenario('ahb-healthy') + + def test_device_lost_ahb_callback_and_cleanup(self): + self.run_scenario('ahb-device-lost') + + def test_healthy_release_and_reference_cleanup(self): + self.run_scenario('healthy') + + def test_genuine_device_loss_keeps_existing_cleanup(self): + self.run_scenario('device-lost') + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/tests/test_vk_external_image_sync.py b/tools/tests/test_vk_external_image_sync.py new file mode 100644 index 0000000000..a82dac25de --- /dev/null +++ b/tools/tests/test_vk_external_image_sync.py @@ -0,0 +1,63 @@ +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +def vulkan_include_args(): + candidates = [] + for name in ("ANDROID_NDK_HOME", "ANDROID_NDK_ROOT"): + if os.environ.get(name): + candidates.append(Path(os.environ[name])) + + android_home = os.environ.get("ANDROID_HOME") + if android_home: + ndk_root = Path(android_home) / "ndk" + version = os.environ.get("NDK_VERSION") + if version: + candidates.append(ndk_root / version) + if ndk_root.is_dir(): + candidates.extend(sorted(ndk_root.iterdir(), reverse=True)) + + for ndk in candidates: + include = ndk / "toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" + if (include / "vulkan/vulkan.h").is_file(): + return ["-idirafter", str(include)] + return [] + + +class VkExternalImageSyncTest(unittest.TestCase): + def test_client_barrier_pair(self): + compiler = shutil.which(os.environ.get("CC", "cc")) + if not compiler: + self.fail("A C compiler is required for the Vulkan image-sync regression test") + + tests = Path(__file__).resolve().parent + source = tests / "vk_external_image_sync_test.c" + includes = tests.parents[1] / "app/src/main/cpp/waylandcomp/src" + with tempfile.TemporaryDirectory(prefix="droiddeck-vk-sync-") as tmp: + program = Path(tmp) / "vk-external-image-sync" + command = [ + compiler, + "-std=c11", + "-Wall", + "-Wextra", + "-Werror", + "-UNDEBUG", + "-I", + str(includes), + *vulkan_include_args(), + str(source), + "-o", + str(program), + ] + built = subprocess.run(command, capture_output=True, text=True) + self.assertEqual(built.returncode, 0, built.stdout + built.stderr) + ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30) + self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_vk_pending_completion.py b/tools/tests/test_vk_pending_completion.py new file mode 100644 index 0000000000..d0a4ad594c --- /dev/null +++ b/tools/tests/test_vk_pending_completion.py @@ -0,0 +1,187 @@ +"""Fault-inject the production fence wait and imported-image destructor. + +No GPU is wedged: a fake dispatch table returns the same result a timed-out +submit would return. The compiled functions come from vk_present.c itself. +""" +import os +from pathlib import Path +import re +import shutil +import subprocess +import tempfile +import unittest + +SOURCE = Path(__file__).resolve().parents[2] / 'app/src/main/cpp/waylandcomp/src/vk_present.c' + + +def function(text, name): + match = re.search(r'^(?:static )?[^\n;]+\b' + name + r'\([^;]*?\)\s*\{', text, re.M) + if not match: + raise AssertionError('Production function not found: ' + name) + start = match.start() + pos = text.index('{', match.start()) + depth = 1 + end = pos + 1 + while depth: + depth += (text[end] == '{') - (text[end] == '}') + end += 1 + return text[start:end] + + +HARNESS = r''' +#include <assert.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdarg.h> +typedef int VkResult; +typedef uintptr_t VkFence; +#define VK_TRUE 1 +#define VK_SUCCESS 0 +#define VK_TIMEOUT 2 +#define VK_ERROR_DEVICE_LOST -4 +#define VK_ERROR_OUT_OF_HOST_MEMORY -1 +#define VK_ERROR_UNKNOWN -13 +static int g_dev_state, g_base_black; +static uintptr_t g_dev = 1; +static struct { int64_t wait_ns, wait_max_ns; unsigned waits; } g_perf; +static VkResult answer; +static unsigned destroyed, unmapped, freed_memory, forgotten, errors; +static int64_t perf_now(void) { return 10; } +static void perf_add(int64_t *s, int64_t *m, unsigned *c, int64_t d) { *s+=d; *m=d; ++*c; } +static void __attribute__((unused)) droiddeck_log(const char *tag, const char *fmt, ...) { (void)tag; (void)fmt; ++errors; } +#define LOGE(...) droiddeck_log("error", __VA_ARGS__) +static VkResult wait_fn(uintptr_t dev, unsigned n, const VkFence *f, int all, uint64_t timeout) { + (void)dev; (void)n; (void)f; (void)all; (void)timeout; return answer; +} +static void unmap_fn(uintptr_t dev, uintptr_t mem) { (void)dev; (void)mem; ++unmapped; } +static void destroy_fn(uintptr_t dev, uintptr_t img, void *allocator) { (void)dev; (void)img; (void)allocator; ++destroyed; } +static void free_fn(uintptr_t dev, uintptr_t mem, void *allocator) { (void)dev; (void)mem; (void)allocator; ++freed_memory; } +static struct { + VkResult (*WaitForFences)(uintptr_t, unsigned, const VkFence *, int, uint64_t); + void (*UnmapMemory)(uintptr_t, uintptr_t); + void (*DestroyImage)(uintptr_t, uintptr_t, void *); + void (*FreeMemory)(uintptr_t, uintptr_t, void *); +} g_vk = {wait_fn, unmap_fn, destroy_fn, free_fn}; +typedef struct AHardwareBuffer AHardwareBuffer; +static int released_buffers; +static void AHardwareBuffer_release(AHardwareBuffer *b) { (void)b; ++released_buffers; } +struct vkp_image { uintptr_t image, mem; void *map; AHardwareBuffer *android_buffer; }; +static void blendp_forget_image(uintptr_t image) { (void)image; ++forgotten; } +/* PRODUCTION_FUNCTIONS */ +static struct vkp_image *image(void) { + struct vkp_image *p = calloc(1, sizeof(*p)); assert(p); + p->image=1; p->mem=2; p->map=p; return p; +} +int main(void) { + g_dev_state=1; answer=VK_SUCCESS; + assert(timed_wait(1, 1000)==VK_SUCCESS); + assert(g_dev_state==1); + vkp_image_destroy(image()); + assert(destroyed==1 && unmapped==1 && freed_memory==1 && forgotten==1); + + g_dev_state=1; g_base_black=1; answer=VK_TIMEOUT; + assert(timed_wait(1, 1000)==VK_TIMEOUT); + assert(g_dev_state!=1 && g_dev_state!=-2); /* pending work is not DEVICE_LOST */ + struct vkp_image *pending=image(); + vkp_image_destroy(pending); + assert(destroyed==1 && unmapped==1 && freed_memory==1 && forgotten==1); + unsigned first_errors=errors; + assert(first_errors>0); + assert(timed_wait(1, 1000)==VK_ERROR_UNKNOWN); + assert(errors==first_errors); /* one terminal diagnostic, no repeated recovery */ + free(pending); /* fake GPU exists only in this test */ + + g_dev_state=1; answer=VK_ERROR_OUT_OF_HOST_MEMORY; + assert(timed_wait(1, 1000)==VK_ERROR_OUT_OF_HOST_MEMORY); + assert(g_dev_state!=1 && g_dev_state!=-2); + pending=image(); vkp_image_destroy(pending); + assert(destroyed==1 && unmapped==1 && freed_memory==1 && forgotten==1); + free(pending); + + g_dev_state=1; answer=VK_ERROR_DEVICE_LOST; + assert(timed_wait(1, 1000)==VK_ERROR_DEVICE_LOST); + assert(g_dev_state==1); /* existing caller performs genuine device-loss cleanup */ + return 0; +} +''' + +SWAPCHAIN_HARNESS = r''' +#include <assert.h> +#include <stdint.h> +#include <stdlib.h> +typedef int VkResult; +#define VK_SUCCESS 0 +#define VK_ERROR_DEVICE_LOST -4 +#define VK_ERROR_OUT_OF_HOST_MEMORY -1 +#define VK_NULL_HANDLE 0 +static int g_dev_state, g_base_black, g_swap_md_identity; +static uintptr_t g_dev=1, g_inst=1, g_swapchain, g_surface, *g_images; +static uint32_t g_nimg; +static unsigned resets, forgotten, destroyed, errors, lost; +static VkResult answer; +#define LOGE(...) (++errors) +static VkResult idle_fn(uintptr_t dev) { (void)dev; return answer; } +static void destroy_fn(uintptr_t dev, uintptr_t obj, void *alloc) { + (void)dev; (void)obj; (void)alloc; ++destroyed; +} +static struct { + VkResult (*DeviceWaitIdle)(uintptr_t); + void (*DestroySwapchainKHR)(uintptr_t, uintptr_t, void *); + void (*DestroySurfaceKHR)(uintptr_t, uintptr_t, void *); +} g_vk={idle_fn, destroy_fn, destroy_fn}; +static void reset_sync(void) { ++resets; } +static void blendp_forget_image(uintptr_t img) { (void)img; ++forgotten; } +static void device_lost(const char *where) { (void)where; ++lost; g_dev_state=-2; } +/* PRODUCTION_FUNCTIONS */ +static void setup(void) { + g_dev_state=1; g_base_black=1; g_swap_md_identity=1; + g_swapchain=2; g_surface=3; g_nimg=1; + g_images=calloc(1,sizeof(*g_images)); assert(g_images); *g_images=4; +} +int main(void) { + setup(); answer=VK_SUCCESS; destroy_swapchain(); + assert(resets==1 && destroyed==2 && forgotten==1); + assert(!g_swapchain && !g_surface && !g_images && !g_nimg && !g_swap_md_identity); + setup(); answer=VK_ERROR_OUT_OF_HOST_MEMORY; destroy_swapchain(); + assert(g_dev_state==-3 && errors==1); + assert(resets==1 && destroyed==2 && forgotten==1); + assert(g_swapchain && g_surface && g_images && g_nimg); + destroy_swapchain(); + assert(errors==1 && resets==1 && destroyed==2); + free(g_images); /* fake GPU resources only */ + setup(); answer=VK_ERROR_DEVICE_LOST; destroy_swapchain(); + assert(lost==1 && g_dev_state==-2); + assert(resets==1 && destroyed==2 && forgotten==1); + free(g_images); + return 0; +} +''' + + +class VkPendingCompletionTest(unittest.TestCase): + def compile_and_run(self, harness, names): + cc = shutil.which(os.environ.get('CC', 'cc')) + self.assertIsNotNone(cc, 'A C compiler is required') + text = SOURCE.read_text() + production = '\n'.join(function(text, n) for n in names) + with tempfile.TemporaryDirectory(prefix='droiddeck-pending-') as tmp: + source=Path(tmp)/'probe.c'; binary=Path(tmp)/'probe' + source.write_text(harness.replace('/* PRODUCTION_FUNCTIONS */', production)) + built=subprocess.run([cc,'-std=c11','-Wall','-Wextra','-Werror','-UNDEBUG',str(source),'-o',str(binary)],capture_output=True,text=True) + self.assertEqual(built.returncode,0,built.stdout+built.stderr) + ran=subprocess.run([str(binary)],capture_output=True,text=True,timeout=10) + self.assertEqual(ran.returncode,0,ran.stdout+ran.stderr) + + def test_unknown_completion_retains_gpu_resources(self): + self.compile_and_run(HARNESS, ['quarantine_pending_work', 'timed_wait', 'vkp_image_destroy']) + + def test_failed_device_idle_does_not_destroy_swapchain(self): + # LOGE's arguments must be evaluated as real production logging does. + harness = SWAPCHAIN_HARNESS.replace('#define LOGE(...) (++errors)', + 'static void log_error(const char *fmt, int result, const char *where) { ' + '(void)fmt; (void)result; (void)where; ++errors; }\n#define LOGE(...) log_error(__VA_ARGS__)') + self.compile_and_run(harness, ['quarantine_pending_work', 'destroy_swapchain']) + + +if __name__=='__main__': + unittest.main() diff --git a/tools/tests/test_vk_terminal_callers.py b/tools/tests/test_vk_terminal_callers.py new file mode 100644 index 0000000000..f0c7294ca2 --- /dev/null +++ b/tools/tests/test_vk_terminal_callers.py @@ -0,0 +1,140 @@ +"""Fault-inject complete production render/blit/upload callers, without a GPU. + +Uses Vulkan-Headers from the Android NDK (as installed by APK CI), or the host +Vulkan development package. Only Android platform declarations and the external +effect/frame-generation modules are mocked; vk_present.c is compiled unmodified. +""" +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + +from test_vk_pending_completion import function + +ROOT = Path(__file__).resolve().parents[2] +SOURCE = ROOT / 'app/src/main/cpp/waylandcomp/src/vk_present.c' + + +def vulkan_include(): + candidates = [Path(p) for p in [os.environ.get('DROIDDECK_VULKAN_INCLUDE', ''), + '/usr/include', '/usr/local/include'] if p] + for name in ('ANDROID_HOME', 'ANDROID_SDK_ROOT', 'ANDROID_NDK_HOME', 'NDK'): + if os.environ.get(name): + root = Path(os.environ[name]) + candidates += sorted(root.glob('ndk/*/toolchains/llvm/prebuilt/*/sysroot/usr/include'), reverse=True) + candidates += list(root.glob('toolchains/llvm/prebuilt/*/sysroot/usr/include')) + return next((p for p in candidates if (p / 'vulkan/vulkan.h').is_file()), None) + + +class VkTerminalCallersTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + headers = vulkan_include() + if headers is None: + raise unittest.SkipTest('NDK or host Vulkan-Headers required for full production-C caller tests') + cc = shutil.which(os.environ.get('CC', 'cc')) + if not cc: + raise AssertionError('C compiler required') + cls.tmp = tempfile.TemporaryDirectory(prefix='droiddeck-callers-') + cls.addClassCleanup(cls.tmp.cleanup) + tmp = Path(cls.tmp.name) + (tmp / 'android').mkdir() + (tmp / 'android/native_window.h').write_text(''' +#pragma once +#include <stdint.h> +typedef struct ANativeWindow ANativeWindow; +int32_t ANativeWindow_getWidth(ANativeWindow *); +int32_t ANativeWindow_getHeight(ANativeWindow *); +void ANativeWindow_release(ANativeWindow *); +''') + (tmp / 'android/hardware_buffer.h').write_text(''' +#pragma once +#include <stdint.h> +typedef struct AHardwareBuffer AHardwareBuffer; +typedef struct AHardwareBuffer_Desc { + uint32_t width, height, layers, format; + uint64_t usage; + uint32_t stride, rfu0; + uint64_t rfu1; +} AHardwareBuffer_Desc; +#define AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE (1ULL << 8) +#define AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT (1ULL << 14) +#define AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE (1ULL << 26) +static inline void AHardwareBuffer_describe(const AHardwareBuffer *b, AHardwareBuffer_Desc *d) { (void)b; *d = (AHardwareBuffer_Desc){0}; } +static inline void AHardwareBuffer_acquire(AHardwareBuffer *b) { (void)b; } +static inline void AHardwareBuffer_release(AHardwareBuffer *b) { (void)b; } +''') + (tmp / 'sys').mkdir() + (tmp / 'sys/system_properties.h').write_text(''' +#pragma once +#define PROP_VALUE_MAX 92 +static inline int __system_property_get(const char *name, char *value) { (void)name; value[0] = 0; return 0; } +''') + (tmp / 'android/log.h').write_text(''' +#pragma once +#define ANDROID_LOG_INFO 4 +int __android_log_print(int, const char *, const char *, ...); +''') + (tmp / 'wayland-server.h').write_text('#pragma once\nstruct wl_display; struct wl_resource; struct wl_client;\n') + compositor = (SOURCE.parent / 'compositor.c').read_text() + # send_buffer_release is a macro over send_buffer_release_at (with buffer tracing). + callers = ('static void buf_trace_release(struct wl_resource *b, int line) { (void)b; (void)line; }\n' + + '#define send_buffer_release(b) send_buffer_release_at((b), __LINE__)\n' + + '\n'.join(function(compositor, n) for n in ('buffer_release_blocked', 'send_buffer_release_at', 'take_shm', 'take_pixel'))) + harness = (Path(__file__).with_name('vk_terminal_callers_test.c')).read_text() + probe = tmp / 'probe.c' + probe.write_text(harness.replace('/* COMPOSITOR_CALLERS */', callers)) + cls.binary = tmp / 'probe' + built = subprocess.run([cc, '-std=c11', '-Wall', '-Wextra', '-Werror', + '-Wno-unused-parameter', '-Wno-missing-field-initializers', '-UNDEBUG', + '-I', str(tmp), '-idirafter', str(headers), '-I', str(SOURCE.parent), + str(probe), '-pthread', '-o', str(cls.binary)], + capture_output=True, text=True) + if built.returncode: + raise AssertionError(built.stdout + built.stderr) + + def run_scenario(self, name): + ran = subprocess.run([str(self.binary), name], capture_output=True, text=True, timeout=10) + self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr) + + def test_first_acquire_idle_failure(self): + self.run_scenario('first-out-of-date') + + def test_first_surface_lost_idle_failure(self): + self.run_scenario('first-surface-lost') + + def test_later_framegen_acquire_idle_failure(self): + self.run_scenario('later-out-of-date') + + def test_later_framegen_surface_lost_idle_failure(self): + self.run_scenario('later-surface-lost') + + def test_finite_blit_timeout_same_size_shm_upload(self): + self.run_scenario('shm-timeout') + + def test_finite_blit_timeout_same_size_pixel_upload(self): + self.run_scenario('pixel-timeout') + + def test_normal_present(self): + self.run_scenario('normal') + + def test_normal_framegen_present(self): + self.run_scenario('framegen') + + def test_healthy_later_acquire_timeout_drains_work(self): + self.run_scenario('later-timeout') + + def test_real_device_lost_on_acquire(self): + self.run_scenario('acquire-device-lost') + + def test_real_device_lost_on_present(self): + self.run_scenario('present-device-lost') + + def test_pass_copy_and_abort_terminal_entry(self): + self.run_scenario('pass-terminal') + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/tests/test_xclipse_layer.py b/tools/tests/test_xclipse_layer.py new file mode 100644 index 0000000000..36042c9c7e --- /dev/null +++ b/tools/tests/test_xclipse_layer.py @@ -0,0 +1,47 @@ +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +TOOLS = Path(__file__).resolve().parents[1] +LAYER = TOOLS / "linuxfs/xclipse-layer" + + +class XclipseLayerTest(unittest.TestCase): + def test_layer_against_a_mock_loader_and_driver(self): + compiler = shutil.which(os.environ.get("CC", "cc")) + if not compiler: + self.fail("A C compiler is required for the Xclipse layer regression test") + # The build compiles the layer against the distribution's headers (libvulkan-dev); + # VULKAN_INCLUDE points elsewhere, e.g. a Vulkan-Headers checkout on macOS. + include = Path(os.environ.get("VULKAN_INCLUDE", "/usr/include")) + if not (include / "vulkan/vk_layer.h").is_file(): + self.fail("Vulkan headers are required: install libvulkan-dev or set VULKAN_INCLUDE") + with tempfile.TemporaryDirectory(prefix="droiddeck-xclipse-") as tmp: + program = Path(tmp) / "xclipse-layer" + built = subprocess.run([compiler, "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-parameter", + "-UNDEBUG", "-pthread", "-I", str(LAYER), "-I", str(include), + str(Path(__file__).with_name("xclipse_layer_test.c")), "-ldl", "-o", str(program)], + capture_output=True, text=True) + self.assertEqual(built.returncode, 0, built.stdout + built.stderr) + ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30) + self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr) + self.assertIn("xclipse layer ok", ran.stdout) + + def test_device_chain_table_matches_its_generator(self): + registry = os.environ.get("VULKAN_REGISTRY") + if not registry: + self.skipTest("set VULKAN_REGISTRY to a Vulkan-Headers 1.3.275 checkout to recheck device_chain.inc") + with tempfile.TemporaryDirectory(prefix="droiddeck-chain-") as tmp: + output = Path(tmp) / "device_chain.inc" + subprocess.run(["python3", str(LAYER / "gen_device_chain.py"), str(Path(registry) / "registry/vk.xml"), + str(Path(registry) / "include/vulkan/vulkan_core.h"), str(output)], + check=True, capture_output=True) + self.assertEqual(output.read_text(), (LAYER / "device_chain.inc").read_text()) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/vk_dmabuf_quarantine_test.c b/tools/tests/vk_dmabuf_quarantine_test.c new file mode 100644 index 0000000000..cbcf724b19 --- /dev/null +++ b/tools/tests/vk_dmabuf_quarantine_test.c @@ -0,0 +1,199 @@ +/* Production lifecycle functions are inserted verbatim by Python. No GPU, + * Android app, external client or real timer is involved in this probe. */ +#define _POSIX_C_SOURCE 200809L +#include <assert.h> +#include <errno.h> +#include <fcntl.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> +#include <wayland-util.h> +#ifndef __linux__ +struct itimerspec { struct timespec it_interval, it_value; }; +#endif + +struct wl_listener { struct wl_list link; void (*notify)(struct wl_listener *, void *); }; +struct wl_resource { int dma; void *user_data; struct wl_list listeners; unsigned releases; }; +struct wl_client; +struct wl_event_source { int unused; }; +typedef struct AHardwareBuffer { int unused; } AHardwareBuffer; +struct vkp_image { int unused; }; +struct dmabuf_buffer { + int refs, n_planes, fd[4]; + struct vkp_image *img; + void *ahb_state; +}; +struct surface { + struct wl_resource *dmabuf; + struct dmabuf_buffer *dmabuf_buf; + struct wl_listener dmabuf_destroy; + int releases_pending; + int64_t next_release_ns; +}; +/* PRODUCTION_STRUCTS */ +static int g_dev_state, g_fps_limit, g_release_timer_fd; +static int64_t g_refresh_ns; +static struct wl_list g_pending_releases, g_bufs; +static void *g_display; +static unsigned image_destroys, ahb_releases, source_removes; +static struct itimerspec last_timer; +static const int wl_buffer_interface = 1, dbuf_buffer_impl = 2; +#define TFD_TIMER_ABSTIME 1 + +/* List operations use the real Wayland layouts/macros. OS/IPC endpoints alone + * are fakes, so no event is sent and no process or hardware is touched. */ +void wl_list_init(struct wl_list *l) { l->prev = l; l->next = l; } +void wl_list_insert(struct wl_list *l, struct wl_list *e) { + e->next = l->next; e->prev = l; l->next->prev = e; l->next = e; +} +void wl_list_remove(struct wl_list *e) { e->next->prev = e->prev; e->prev->next = e->next; } +static int wl_resource_instance_of(struct wl_resource *r, const void *i, const void *impl) { return r->dma; } +static void *wl_resource_get_user_data(struct wl_resource *r) { return r->user_data; } +static void wl_resource_add_destroy_listener(struct wl_resource *r, struct wl_listener *l) { + wl_list_insert(r->listeners.prev, &l->link); +} +static void wl_buffer_send_release(struct wl_resource *r) { ++r->releases; } +static void wl_display_flush_clients(void *d) {} +static int timerfd_settime(int fd, int flags, const struct itimerspec *v, void *old) { last_timer = *v; return 0; } +static void perf_note_release(int64_t since) {} +static int64_t now_ns(void) { return 1000000000LL; } +static void vkp_image_destroy(struct vkp_image *img) { ++image_destroys; } +static void AHardwareBuffer_release(AHardwareBuffer *ahb) { ++ahb_releases; } +static int wl_event_source_remove(struct wl_event_source *src) { ++source_removes; return 0; } +static struct dmabuf_buffer *get_dmabuf(struct wl_resource *r); +int ahb_swapchain_defer_release(struct dmabuf_buffer *, struct wl_resource *, struct surface *, int); +/* PRODUCTION_FUNCTIONS */ + +static void init_resource(struct wl_resource *r, struct dmabuf_buffer *b) { + *r = (struct wl_resource){.dma = b != NULL, .user_data = b}; + wl_list_init(&r->listeners); +} +static struct dmabuf_buffer *init_buffer(struct surface *s, struct wl_resource *r) { + struct dmabuf_buffer *b = calloc(1, sizeof(*b)); assert(b); + b->refs = 2; b->n_planes = 1; + int fds[2]; assert(pipe(fds) == 0); b->fd[0] = fds[0]; close(fds[1]); + init_resource(r, b); + assert(get_dmabuf(r) == b); + *s = (struct surface){.dmabuf = r, .dmabuf_buf = b}; + s->dmabuf_destroy.notify = on_dmabuf_destroyed; + wl_resource_add_destroy_listener(r, &s->dmabuf_destroy); + return b; +} +static void destroy_resource(struct wl_resource *r) { + while (r->listeners.next != &r->listeners) { + struct wl_listener *l = wl_container_of(r->listeners.next, l, link); + l->notify(l, r); + } + if (r->dma) dmabuf_buffer_unref(r->user_data); + r->user_data = NULL; +} +static void fire_timer(void) { + int fd[2]; uint64_t expirations = 1; + assert(pipe(fd) == 0 && write(fd[1], &expirations, sizeof(expirations)) == sizeof(expirations)); + on_release_timer(fd[0], 0, NULL); close(fd[0]); close(fd[1]); +} +static void assert_retained(struct dmabuf_buffer *b, int refs) { + assert(b->refs == refs && fcntl(b->fd[0], F_GETFD) >= 0 && !image_destroys); +} +static void test_drop(int paced) { + struct surface s; struct wl_resource r; + struct dmabuf_buffer *b = init_buffer(&s, &r); + g_dev_state = -3; drop_dmabuf(&s, paced); + assert(!s.dmabuf && !s.dmabuf_buf && !r.releases && !s.releases_pending); + assert(r.listeners.next == &r.listeners); /* no listener into a dead surface */ + assert_retained(b, 2); + destroy_resource(&r); assert_retained(b, 2); + close(b->fd[0]); free(b); /* fake GPU only */ +} +static void test_queue(int mixed, int client_gone) { + struct surface s; struct wl_resource r, shm; + struct dmabuf_buffer *b = init_buffer(&s, &r); + g_release_timer_fd = 123; g_refresh_ns = 100000; + drop_dmabuf(&s, 1); assert(s.releases_pending == 1 && !r.releases); + assert(last_timer.it_value.tv_sec || last_timer.it_value.tv_nsec); + if (mixed) { init_resource(&shm, NULL); release_buffer(&s, &shm, now_ns()); } + pending_releases_forget_surface(&s); + g_dev_state = -3; + fire_timer(); + assert(!r.releases && g_pending_releases.next != &g_pending_releases); + if (mixed) assert(shm.releases == 1); + assert(!last_timer.it_value.tv_sec && !last_timer.it_value.tv_nsec); + assert_retained(b, 1); + if (client_gone) { + destroy_resource(&r); + assert(g_pending_releases.next == &g_pending_releases); + assert_retained(b, 1); + } + close(b->fd[0]); free(b); /* fake GPU only */ +} +static void test_active_client_destroy(void) { + struct surface s; struct wl_resource r; + struct dmabuf_buffer *b = init_buffer(&s, &r); + g_dev_state = -3; + destroy_resource(&r); + assert(!s.dmabuf && s.dmabuf_buf == b && !r.releases); + drop_dmabuf(&s, 0); assert(!s.dmabuf_buf); + assert_retained(b, 2); + close(b->fd[0]); free(b); /* fake GPU only */ +} +static void test_ahb(int terminal, int lost) { + struct surface s; struct wl_resource r; + struct dmabuf_buffer *b = init_buffer(&s, &r); + struct ahb_buf *ab = calloc(1, sizeof(*ab)); assert(ab); + AHardwareBuffer ahb; + *ab = (struct ahb_buf){.b = b, .ahb = &ahb, .resource = &r, .on_layer = 1, .fence_fd = -1}; + b->ahb_state = ab; ++b->refs; + ab->resource_destroy.notify = on_buffer_resource_destroyed; + wl_resource_add_destroy_listener(&r, &ab->resource_destroy); + wl_list_insert(&g_bufs, &ab->link); + drop_dmabuf(&s, 1); assert(ab->release_pending && ab->surface == &s); + int backing_fd = b->fd[0]; + g_dev_state = terminal ? -3 : lost ? -2 : 1; + ahb_swapchain_surface_gone(&s); assert(!ab->surface); + /* Actual event-loop callback after the display's fence becomes readable. */ + struct wl_event_source source; int fds[2]; assert(pipe(fds) == 0); + ab->on_layer = 0; ab->fence_src = &source; ab->fence_fd = fds[0]; + on_fence_readable(fds[0], 0, ab); close(fds[1]); + assert(source_removes == 1 && ab->fence_fd == -1 && !ab->fence_src); + assert(r.releases == (terminal ? 0u : 1u)); + assert(ab->release_pending == terminal && !ahb_releases); + destroy_resource(&r); + if (terminal) { + assert(!ab->resource && b->ahb_state == ab && !ahb_releases); + assert_retained(b, 2); + close(b->fd[0]); free(ab); free(b); /* fake GPU only */ + } else { + assert(ahb_releases == 1 && image_destroys == 1); + errno = 0; assert(fcntl(backing_fd, F_GETFD) == -1 && errno == EBADF); + } +} +static void test_cleanup(int lost) { + struct surface s; struct wl_resource r; + struct dmabuf_buffer *b = init_buffer(&s, &r); + int fd = b->fd[0]; g_dev_state = lost ? -2 : 1; + assert(!vkp_completion_unknown()); + drop_dmabuf(&s, 0); + assert(r.releases == 1 && b->refs == 1 && !image_destroys); + destroy_resource(&r); assert(image_destroys == 1); + errno = 0; assert(fcntl(fd, F_GETFD) == -1 && errno == EBADF); +} +int main(int argc, char **argv) { + assert(argc == 2); + wl_list_init(&g_pending_releases); wl_list_init(&g_bufs); + g_dev_state = 1; g_release_timer_fd = -1; + if (!strcmp(argv[1], "replacement")) test_drop(1); + else if (!strcmp(argv[1], "surface-gone")) test_drop(0); + else if (!strcmp(argv[1], "queued")) test_queue(0, 0); + else if (!strcmp(argv[1], "mixed")) test_queue(1, 0); + else if (!strcmp(argv[1], "client-gone")) test_queue(0, 1); + else if (!strcmp(argv[1], "ahb")) test_ahb(1, 0); + else if (!strcmp(argv[1], "ahb-healthy")) test_ahb(0, 0); + else if (!strcmp(argv[1], "ahb-device-lost")) test_ahb(0, 1); + else if (!strcmp(argv[1], "active-client-gone")) test_active_client_destroy(); + else if (!strcmp(argv[1], "healthy")) test_cleanup(0); + else if (!strcmp(argv[1], "device-lost")) test_cleanup(1); + else assert(0 && "unknown scenario"); + return 0; +} diff --git a/tools/tests/vk_external_image_sync_test.c b/tools/tests/vk_external_image_sync_test.c new file mode 100644 index 0000000000..c6114d2572 --- /dev/null +++ b/tools/tests/vk_external_image_sync_test.c @@ -0,0 +1,63 @@ +#include <assert.h> +#include <stdint.h> +#include <string.h> + +#include "vk_external_image_sync.h" + +static void check_external_pair(const struct vkp_external_client_barrier_pair *pair, + VkImage image, uint32_t queue_family) { + assert(pair->acquire.sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER); + assert(pair->acquire.oldLayout == VK_IMAGE_LAYOUT_GENERAL); + assert(pair->acquire.newLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + assert(pair->acquire.srcQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT); + assert(pair->acquire.dstQueueFamilyIndex == queue_family); + assert(pair->acquire.image == image); + assert(pair->acquire.srcAccessMask == 0); + assert(pair->acquire.dstAccessMask == VK_ACCESS_TRANSFER_READ_BIT); + assert(pair->acquire.subresourceRange.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT); + assert(pair->acquire.subresourceRange.baseMipLevel == 0); + assert(pair->acquire.subresourceRange.levelCount == 1); + assert(pair->acquire.subresourceRange.baseArrayLayer == 0); + assert(pair->acquire.subresourceRange.layerCount == 1); + + assert(pair->release.sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER); + assert(pair->release.oldLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + assert(pair->release.newLayout == VK_IMAGE_LAYOUT_GENERAL); + assert(pair->release.srcQueueFamilyIndex == queue_family); + assert(pair->release.dstQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT); + assert(pair->release.image == image); + assert(pair->release.srcAccessMask == VK_ACCESS_MEMORY_READ_BIT); + assert(pair->release.dstAccessMask == 0); + assert(pair->release.subresourceRange.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT); + assert(pair->release.subresourceRange.levelCount == 1); + assert(pair->release.subresourceRange.layerCount == 1); +} + +int main(void) { + const VkImage image = (VkImage)(uintptr_t)0x1234; + const VkImage ahb_image = (VkImage)(uintptr_t)0x5678; + const uint32_t queue_family = 7; + struct vkp_external_client_barrier_pair generic, ahb; + + assert(vkp_external_client_barrier_pair(image, queue_family, 1, 0, &generic)); + check_external_pair(&generic, image, queue_family); + + /* AHardwareBuffer imports deliberately use the same client flags and lifecycle. */ + assert(vkp_external_client_barrier_pair(ahb_image, queue_family, 1, 0, &ahb)); + check_external_pair(&ahb, ahb_image, queue_family); + + unsigned char untouched[sizeof(generic)]; + memset(&generic, 0xa5, sizeof(generic)); + memcpy(untouched, &generic, sizeof(generic)); + assert(!vkp_external_client_barrier_pair(image, queue_family, 0, 0, &generic)); + assert(memcmp(&generic, untouched, sizeof(generic)) == 0); + assert(!vkp_is_external_client_image(0, 0)); + + memset(&generic, 0x5a, sizeof(generic)); + memcpy(untouched, &generic, sizeof(generic)); + assert(!vkp_external_client_barrier_pair(image, queue_family, 1, 1, &generic)); + assert(memcmp(&generic, untouched, sizeof(generic)) == 0); + assert(!vkp_is_external_client_image(1, 1)); + assert(vkp_is_external_client_image(1, 0)); + return 0; +} diff --git a/tools/tests/vk_terminal_callers_test.c b/tools/tests/vk_terminal_callers_test.c new file mode 100644 index 0000000000..b2764c0da7 --- /dev/null +++ b/tools/tests/vk_terminal_callers_test.c @@ -0,0 +1,290 @@ +/* Compiled with the complete, unmodified production translation unit. The + * compositor's take_shm/take_pixel functions are inserted verbatim by Python. */ +#include "vk_present.c" +#include <assert.h> + +struct vk_api g_vk; +static unsigned operations, acquires, submits, markers, waits, idle_calls, resets; +static unsigned destroys, releases, lost_notifications, presented_notifications; +static VkResult idle_answer, fence_answer, acquire_answer, present_answer; +static unsigned fail_acquire_at; +static int generated; + +/* Every work-issuing callback is an oracle: no GPU operation after a terminal + * result. Object destruction is counted separately for genuine device loss. */ +static void live(void) { assert(g_dev_state == 1); ++operations; } +static VkResult acquire(VkDevice d, VkSwapchainKHR s, uint64_t t, VkSemaphore a, VkFence f, uint32_t *i) { + live(); ++acquires; *i = 0; + return acquires == fail_acquire_at ? acquire_answer : VK_SUCCESS; +} +static VkResult idle(VkDevice d) { live(); ++idle_calls; return idle_answer; } +static VkResult wait_fences(VkDevice d, uint32_t n, const VkFence *f, VkBool32 all, uint64_t t) { + live(); ++waits; return fence_answer; +} +static VkResult submit(VkQueue q, uint32_t n, const VkSubmitInfo *s, VkFence f) { + live(); ++submits; if (!s->commandBufferCount) ++markers; return VK_SUCCESS; +} +static VkResult present(VkQueue q, const VkPresentInfoKHR *p) { live(); return present_answer; } +static VkResult reset_cmd(VkCommandBuffer c, VkCommandBufferResetFlags f) { live(); ++resets; return VK_SUCCESS; } +static VkResult reset_fence(VkDevice d, uint32_t n, const VkFence *f) { live(); ++resets; return VK_SUCCESS; } +static VkResult begin_cmd(VkCommandBuffer c, const VkCommandBufferBeginInfo *b) { live(); return VK_SUCCESS; } +static VkResult end_cmd(VkCommandBuffer c) { live(); return VK_SUCCESS; } +static void barrier(VkCommandBuffer c, VkPipelineStageFlags s, VkPipelineStageFlags d, VkDependencyFlags f, + uint32_t nm, const VkMemoryBarrier *m, uint32_t nb, const VkBufferMemoryBarrier *b, + uint32_t ni, const VkImageMemoryBarrier *i) { live(); } +static void clear(VkCommandBuffer c, VkImage i, VkImageLayout l, const VkClearColorValue *v, + uint32_t n, const VkImageSubresourceRange *r) { live(); } +static void blit(VkCommandBuffer c, VkImage s, VkImageLayout sl, VkImage d, VkImageLayout dl, + uint32_t n, const VkImageBlit *b, VkFilter f) { live(); } +static void destroy_swap(VkDevice d, VkSwapchainKHR s, const VkAllocationCallbacks *a) { ++destroys; } +static void destroy_surface(VkInstance i, VkSurfaceKHR s, const VkAllocationCallbacks *a) { ++destroys; } +static void destroy_sem(VkDevice d, VkSemaphore s, const VkAllocationCallbacks *a) { live(); ++destroys; } +static VkResult create_sem(VkDevice d, const VkSemaphoreCreateInfo *c, const VkAllocationCallbacks *a, VkSemaphore *s) { + live(); *s = (VkSemaphore)(uintptr_t)1; return VK_SUCCESS; +} +static void destroy_image(VkDevice d, VkImage i, const VkAllocationCallbacks *a) { ++destroys; } +static void free_memory(VkDevice d, VkDeviceMemory m, const VkAllocationCallbacks *a) { ++destroys; } +static void unmap(VkDevice d, VkDeviceMemory m) { ++destroys; } + +/* External modules are not the subject of this fault injection. Their declared + * signatures remain checked by the production headers. */ +int __android_log_print(int p, const char *t, const char *f, ...) { return 0; } +void droiddeck_log(const char *t, const char *f, ...) {} +void droiddeck_on_first_frame(void) {} +int32_t ANativeWindow_getWidth(ANativeWindow *w) { return 64; } +int32_t ANativeWindow_getHeight(ANativeWindow *w) { return 64; } +void ANativeWindow_release(ANativeWindow *w) {} +void sc_layer_window_gone(void) {} +int sc_layer_present_pass(const struct vkp_draw *d, int n, int w, int h) { return 0; } +void sc_layer_hide(void) {} +int sc_layer_base_black(int w, int h) { return 0; } +void sc_layer_hide_base(void) {} +void sc_layer_hide_overlay(void) {} +void vkp_cardboard_bind_device(VkDevice d, const VkPhysicalDeviceMemoryProperties *m) {} +int vkp_cardboard_active(void) { return 0; } +void vkp_cardboard_begin_frame(void) {} +VkImage vkp_cardboard_run(VkCommandBuffer c, VkImage s, int sw, int sh, int ow, int oh) { return s; } +int vk_loader_open(const char *a, const char *b, const char *c) { assert(0); return -1; } +void vk_loader_load_instance(VkInstance i) { assert(0); } +void vk_loader_load_device(VkDevice d) { assert(0); } +PFN_vkGetInstanceProcAddr vk_loader_gipa(void) { return NULL; } +void vkp_effects_bind_device(VkDevice d, VkPhysicalDevice p, const VkPhysicalDeviceMemoryProperties *m) {} +int vkp_effects_active(void) { return 0; } +int vkp_effects_upscaling(void) { return 0; } +int vkp_effects_postprocessing(void) { return 0; } +VkFilter vkp_effects_blit_filter(void) { return VK_FILTER_NEAREST; } +void vkp_effects_set_formats(VkFormat a, VkFormat b) {} +VkImage vkp_effects_run(VkCommandBuffer c, VkImage i, int w, int h, int ow, int oh, int *rw, int *rh) { + *rw = w; *rh = h; return i; +} +const void *vkp_framegen_device_features(VkInstance i, PFN_vkGetInstanceProcAddr p, VkPhysicalDevice d) { return NULL; } +void vkp_framegen_device_ready(VkDevice d, VkQueue q, uint32_t f, int e) {} +void vkp_framegen_device_lost(void) { ++lost_notifications; } +int vkp_framegen_active(void) { return generated != 0; } +int vkp_framegen_extra_images(void) { return generated; } +int vkp_framegen_format_ok(VkFormat f) { return 0; } +int vkp_framegen_run(VkCommandBuffer c, VkImage s, VkImageView v, int w, int h, + VkFormat f, VkImage images[VKP_FG_MAX_GENERATIONS]) { + for (int i = 0; i < generated; ++i) images[i] = s; + return generated; +} +void vkp_framegen_presented(int n) { ++presented_notifications; } +void vkp_gpu_busy_device(VkPhysicalDevice p, VkDevice d, uint32_t f) {} +void vkp_gpu_busy_device_lost(void) {} +void hdrc_bind_device(VkDevice d, const VkPhysicalDeviceMemoryProperties *m) {} +void hdrc_forget_image(VkImage i) {} +int hdrc_encode(VkCommandBuffer c, VkImage a, VkImage b, VkFormat f, int w, int h, const struct hdrc_params *p) { return -1; } +void blendp_bind_device(VkDevice d) {} +void blendp_forget_image(VkImage i) {} +void vkp_effects_forget_image(VkImage i) {} +void blendp_begin_frame(void) {} +int blendp_draw(VkCommandBuffer c, VkImage s, VkFormat sf, int sw, int sh, int sg, + VkImage d, VkFormat df, int dw, int dh, const VkImageBlit *b) { return -1; } +int droiddeck_color_requested(void) { return 0; } +float droiddeck_color_sdr_white(void) { return 203.0f; } + +enum surface_role { ROLE_NONE, ROLE_TOPLEVEL }; +struct damage_list { int n; }; +struct surface { + struct vkp_image *shm_img; + struct wl_resource *resource; + int buf_w, buf_h, buf_alpha, has_content; + /* Read by take_shm's game-frame detection; with no damage it stays off here. */ + int src_set; float src[4]; + struct damage_list damage_buf, damage_local; + struct surface *parent; enum surface_role role; int mapped; +}; +static void surface_size(const struct surface *s, int *w, int *h) { *w = s->buf_w; *h = s->buf_h; } +static void scene_size(int *w, int *h) { *w = *h = 0; } +static int64_t damage_area(const struct damage_list *d, int bound_w, int bound_h) { return 0; } +static int64_t now_ns(void) { return 0; } +static struct surface *g_hud_surface, *g_hud_shm; +static int64_t g_hud_shm_ns, g_hud_last_ns; +static int g_hud_new; +static void droiddeck_on_game_frame(void) {} +struct client_info { int asked_feedback, shm_frames; }; +struct wl_shm_buffer { int w, h, stride; const void *data; }; +#define WL_SHM_FORMAT_ARGB8888 0 +static unsigned g_stat_shm; +static int wl_shm_buffer_get_width(struct wl_shm_buffer *b) { return b->w; } +static int wl_shm_buffer_get_height(struct wl_shm_buffer *b) { return b->h; } +static int wl_shm_buffer_get_stride(struct wl_shm_buffer *b) { return b->stride; } +static int wl_shm_buffer_get_format(struct wl_shm_buffer *b) { return WL_SHM_FORMAT_ARGB8888; } +static const void *wl_shm_buffer_get_data(struct wl_shm_buffer *b) { return b->data; } +static void wl_shm_buffer_begin_access(struct wl_shm_buffer *b) {} +static void wl_shm_buffer_end_access(struct wl_shm_buffer *b) {} +struct wl_resource { int dmabuf; }; +static struct wl_resource *expected_release; +static void wl_buffer_send_release(struct wl_resource *b) { assert(b && b == expected_release); ++releases; } +static struct wl_client *wl_resource_get_client(struct wl_resource *r) { return NULL; } +static struct client_info *client_info_of(struct wl_client *c) { return NULL; } +struct dmabuf_buffer { int unused; }; +static struct dmabuf_buffer dmabuf_fixture; +static struct dmabuf_buffer *get_dmabuf(struct wl_resource *buffer) { + assert(buffer); + return buffer->dmabuf ? &dmabuf_fixture : NULL; +} +/* COMPOSITOR_CALLERS */ + +static void setup(int extra) { + g_vk = (struct vk_api){.AcquireNextImageKHR = acquire, .DeviceWaitIdle = idle, + .WaitForFences = wait_fences, .QueueSubmit = submit, .QueuePresentKHR = present, + .ResetCommandBuffer = reset_cmd, .ResetFences = reset_fence, .BeginCommandBuffer = begin_cmd, + .EndCommandBuffer = end_cmd, .CmdPipelineBarrier = barrier, .CmdClearColorImage = clear, + .CmdBlitImage = blit, .DestroySwapchainKHR = destroy_swap, .DestroySurfaceKHR = destroy_surface, + .DestroySemaphore = destroy_sem, .CreateSemaphore = create_sem, + .DestroyImage = destroy_image, .FreeMemory = free_memory, .UnmapMemory = unmap}; + idle_answer = fence_answer = acquire_answer = present_answer = VK_SUCCESS; + generated = g_swap_extra = extra; + g_dev_state = 1; + g_dev = (VkDevice)(uintptr_t)1; g_inst = (VkInstance)(uintptr_t)1; + g_window = (ANativeWindow *)(uintptr_t)1; g_queue = (VkQueue)(uintptr_t)1; + g_swapchain = (VkSwapchainKHR)(uintptr_t)2; g_surface = (VkSurfaceKHR)(uintptr_t)3; + g_images = calloc(1, sizeof(*g_images)); assert(g_images); + *g_images = (VkImage)(uintptr_t)4; g_nimg = 1; + g_extent = g_caps_extent = (VkExtent2D){64, 64}; + g_surface_checked_ns = INT64_MAX; /* no simulated geometry change */ + g_scene.img = (VkImage)(uintptr_t)5; g_scene.mem = (VkDeviceMemory)(uintptr_t)6; + g_scene.w = g_scene.h = 64; + for (int k = 0; k < MAX_PRESENTS; ++k) { + g_cmds[k] = (VkCommandBuffer)(uintptr_t)(10 + k); + g_acqs[k] = (VkSemaphore)(uintptr_t)(20 + k); + g_rnds[k] = (VkSemaphore)(uintptr_t)(30 + k); + } + g_fence = (VkFence)(uintptr_t)40; +} + +/* Probe the public GPU entry points after a terminal result. This includes an + * active off-screen pass and consumed release fds, not just the render guard. */ +static void assert_stopped(void) { + unsigned before = operations, before_destroys = destroys; + struct vkp_image src = {.image = (VkImage)(uintptr_t)7, .w = 1, .h = 1}; + struct vkp_image dst = {.image = (VkImage)(uintptr_t)8, .w = 1, .h = 1, .blit_dst = 1}; + uint32_t pixel = 0; uint64_t mod = 0; + assert(vkp_render(64, 64, NULL, 0) == -1); + assert(vkp_render_plain(64, 64) == -1); + assert(vkp_render_hdr(64, 64, NULL, 0, NULL, NULL) == -1); + assert(vkp_base_black(64, 64) == -1); + assert(vkp_update_map(64, 64) == -1); + assert(vkp_ready() == -1); + assert(vkp_image_create_shm(1, 1) == NULL); + assert(vkp_image_import_dmabuf(-1, 0, VKP_MOD_LINEAR, 1, 1, 4, 0, 0) == NULL); + assert(vkp_dmabuf_modifiers(0, &mod, 1) == 0); + assert(vkp_image_readback(&src, &pixel, 1) == -1); + assert(vkp_pass_begin(64, 64, NULL, 0, NULL, NULL) == -1); + int fd[2]; assert(pipe(fd) == 0); + assert(vkp_blit_image(&src, &dst, fd[0]) == -1); + errno = 0; assert(close(fd[0]) == -1 && errno == EBADF); close(fd[1]); + g_pass.active = 1; + assert(pipe(fd) == 0); + assert(vkp_pass_copy_to(&dst, fd[0]) == -1 && !g_pass.active); + errno = 0; assert(close(fd[0]) == -1 && errno == EBADF); close(fd[1]); + g_pass.active = 1; vkp_pass_abort(); assert(!g_pass.active); + assert(timed_wait(g_fence, UINT64_MAX) != VK_SUCCESS); + assert(operations == before && destroys == before_destroys); +} + +static void acquire_failure(int later, VkResult result) { + setup(later ? 1 : 0); + fail_acquire_at = later ? 2 : 1; acquire_answer = result; + idle_answer = VK_ERROR_OUT_OF_HOST_MEMORY; + VkImage *retained = g_images; + assert(vkp_render(64, 64, NULL, 0) == -1); + assert(g_dev_state == -3 && vkp_completion_unknown() && !vkp_device_lost()); + assert(acquires == fail_acquire_at && idle_calls == 1); + assert(submits == (unsigned)later && markers == 0 && waits == 0); + assert(destroys == 0 && g_images == retained && g_nimg == 1); + assert(g_swapchain && g_surface && g_fence && g_scene.img && g_scene.mem); + assert_stopped(); + free(g_images); /* test-owned fake resources only */ +} + +static void upload_timeout(int single_pixel) { + setup(0); + uint8_t bytes[48], saved[48], data[16]; + memset(bytes, 0xa5, sizeof(bytes)); memset(data, 0x3c, sizeof(data)); + struct vkp_image *img = calloc(1, sizeof(*img)); assert(img); + *img = (struct vkp_image){.image = (VkImage)(uintptr_t)7, .mem = (VkDeviceMemory)(uintptr_t)8, + .map = bytes, .offset = 3, .row_pitch = 16, + .w = single_pixel ? 1 : 2, .h = single_pixel ? 1 : 2}; + struct surface s = {.shm_img = img}; + struct wl_shm_buffer b = {.w = img->w, .h = img->h, .stride = img->w * 4, .data = data}; + struct wl_resource resource = {0}; + expected_release = &resource; + if (single_pixel) take_pixel(&s, data, &resource); else take_shm(&s, &b, &resource); + assert(bytes[3] == 0x3c && bytes[0] == 0xa5 && releases == 1); + memcpy(saved, bytes, sizeof(saved)); + struct vkp_image dst = {.image = (VkImage)(uintptr_t)9, .blit_dst = 1, .w = img->w, .h = img->h}; + fence_answer = VK_TIMEOUT; + assert(vkp_blit_image(img, &dst, -1) == -1); + assert(g_dev_state == -3 && submits == 1 && waits == 1); + memset(data, 0x7e, sizeof(data)); + if (single_pixel) take_pixel(&s, data, &resource); else take_shm(&s, &b, &resource); + assert(s.shm_img == img && memcmp(saved, bytes, sizeof(saved)) == 0 && releases == 2); + struct wl_resource dmabuf = {.dmabuf = 1}; + expected_release = &dmabuf; + assert(buffer_release_blocked(&dmabuf)); + send_buffer_release(&dmabuf); + assert(releases == 2); + vkp_image_destroy(img); + assert(destroys == 0 && img->map == bytes && img->image && img->mem); + assert_stopped(); + g_dev_state = 1; + assert(!buffer_release_blocked(&dmabuf)); + send_buffer_release(&dmabuf); + assert(releases == 3); + free(img); free(g_images); /* fake resources only, not production cleanup */ +} + +int main(int argc, char **argv) { + assert(argc == 2); + const char *name = argv[1]; + if (!strcmp(name, "first-out-of-date")) acquire_failure(0, VK_ERROR_OUT_OF_DATE_KHR); + else if (!strcmp(name, "first-surface-lost")) acquire_failure(0, VK_ERROR_SURFACE_LOST_KHR); + else if (!strcmp(name, "later-out-of-date")) acquire_failure(1, VK_ERROR_OUT_OF_DATE_KHR); + else if (!strcmp(name, "later-surface-lost")) acquire_failure(1, VK_ERROR_SURFACE_LOST_KHR); + else if (!strcmp(name, "shm-timeout")) upload_timeout(0); + else if (!strcmp(name, "pixel-timeout")) upload_timeout(1); + else if (!strcmp(name, "pass-terminal")) { setup(0); g_dev_state = -3; assert_stopped(); free(g_images); } + else if (!strcmp(name, "normal") || !strcmp(name, "framegen")) { + int extra = !strcmp(name, "framegen"); setup(extra); + assert(vkp_render(64, 64, NULL, 0) == 0 && g_dev_state == 1); + assert(acquires == (unsigned)(1 + extra) && submits == (unsigned)(1 + extra)); + assert(waits == 1 && markers == 0 && idle_calls == 0 && destroys == 0); + assert(presented_notifications == (unsigned)extra); free(g_images); + } else if (!strcmp(name, "later-timeout")) { + setup(1); fail_acquire_at = 2; acquire_answer = VK_TIMEOUT; + assert(vkp_render(64, 64, NULL, 0) == -1 && g_dev_state == 1); + assert(acquires == 2 && submits == 2 && markers == 1 && waits == 1); free(g_images); + } else if (!strcmp(name, "acquire-device-lost") || !strcmp(name, "present-device-lost")) { + setup(1); + if (!strcmp(name, "acquire-device-lost")) { fail_acquire_at = 2; acquire_answer = VK_ERROR_DEVICE_LOST; } + else present_answer = VK_ERROR_DEVICE_LOST; + assert(vkp_render(64, 64, NULL, 0) == -1 && vkp_device_lost()); + assert(!vkp_completion_unknown()); + assert(g_dev_state == -2 && lost_notifications == 1 && markers == 0 && waits == 0); + assert(!g_images && !g_swapchain && !g_surface && destroys == 2); + assert_stopped(); + } else assert(0 && "unknown scenario"); + return 0; +} diff --git a/tools/tests/xclipse_layer_test.c b/tools/tests/xclipse_layer_test.c new file mode 100644 index 0000000000..26105d69f2 --- /dev/null +++ b/tools/tests/xclipse_layer_test.c @@ -0,0 +1,217 @@ +/* The Xclipse layer between a simulated loader and a mock driver. The driver refuses what the compat + * layer and Samsung's driver refuse: textureCompressionBC, and a compute layout holding an immutable + * YCbCr sampler. Built by test_xclipse_layer.py with the layer source included directly. */ +#include "xclipse_layer.c" +#include <assert.h> + +struct object { void *dispatch; }; +static int instance_table, device_table[4]; +static struct object mock_instance = {&instance_table}, mock_physical = {&instance_table}; +static struct object mock_devices[4] = {{&device_table[0]}, {&device_table[1]}, {&device_table[2]}, {&device_table[3]}}; +static int devices_created; + +/* What the driver last saw. */ +static int driver_saw_bc, driver_saw_layout_sampler_count; +static VkSampler driver_layout_samplers[16]; +static uint64_t next_sampler = 0x100; +static VkSampler driver_ycbcr[16]; +static int driver_ycbcr_count; + +static VkResult VKAPI_CALL mock_create_instance(const VkInstanceCreateInfo *info, const VkAllocationCallbacks *allocator, + VkInstance *instance) { + *instance = (VkInstance)&mock_instance; + return VK_SUCCESS; +} + +static void VKAPI_CALL mock_features(VkPhysicalDevice physical, VkPhysicalDeviceFeatures *features) { + memset(features, 0, sizeof(*features)); +} + +static void VKAPI_CALL mock_features2(VkPhysicalDevice physical, VkPhysicalDeviceFeatures2 *features) { + mock_features(physical, &features->features); +} + +/* The compat layer's emulation: BC formats sample, the feature bit stays off. */ +static void VKAPI_CALL mock_format_properties(VkPhysicalDevice physical, VkFormat format, VkFormatProperties *out) { + memset(out, 0, sizeof(*out)); + if (format >= VK_FORMAT_BC1_RGB_UNORM_BLOCK && format <= VK_FORMAT_BC7_SRGB_BLOCK) + out->optimalTilingFeatures = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; +} + +static void VKAPI_CALL mock_format_properties2(VkPhysicalDevice physical, VkFormat format, VkFormatProperties2 *out) { + mock_format_properties(physical, format, &out->formatProperties); +} + +static VkResult VKAPI_CALL mock_time_domains(VkPhysicalDevice physical, uint32_t *count, VkTimeDomainEXT *domains) { + if (domains) { domains[0] = VK_TIME_DOMAIN_DEVICE_EXT; domains[1] = VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT; } + *count = 2; + return VK_SUCCESS; +} + +static VkResult VKAPI_CALL mock_create_device(VkPhysicalDevice physical, const VkDeviceCreateInfo *info, + const VkAllocationCallbacks *allocator, VkDevice *device) { + driver_saw_bc = info->pEnabledFeatures && info->pEnabledFeatures->textureCompressionBC; + for (const VkBaseInStructure *p = info->pNext; p; p = p->pNext) + if (p->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 && + ((const VkPhysicalDeviceFeatures2 *)p)->features.textureCompressionBC) driver_saw_bc = 1; + if (driver_saw_bc) return VK_ERROR_FEATURE_NOT_PRESENT; + assert(devices_created < 4); + *device = (VkDevice)&mock_devices[devices_created++]; + return VK_SUCCESS; +} + +static VkResult VKAPI_CALL mock_create_sampler(VkDevice device, const VkSamplerCreateInfo *info, + const VkAllocationCallbacks *allocator, VkSampler *sampler) { + *sampler = (VkSampler)next_sampler++; + for (const VkBaseInStructure *p = info->pNext; p; p = p->pNext) + if (p->sType == VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO) driver_ycbcr[driver_ycbcr_count++] = *sampler; + return VK_SUCCESS; +} + +static void VKAPI_CALL mock_destroy_sampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks *allocator) { + for (int i = 0; i < driver_ycbcr_count; i++) + if (driver_ycbcr[i] == sampler) driver_ycbcr[i] = driver_ycbcr[--driver_ycbcr_count]; +} + +static VkResult VKAPI_CALL mock_create_set_layout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *info, + const VkAllocationCallbacks *allocator, VkDescriptorSetLayout *layout) { + driver_saw_layout_sampler_count = 0; + for (uint32_t b = 0; b < info->bindingCount; b++) { + const VkDescriptorSetLayoutBinding *binding = &info->pBindings[b]; + for (uint32_t s = 0; binding->pImmutableSamplers && s < binding->descriptorCount; s++) { + VkSampler sampler = binding->pImmutableSamplers[s]; + driver_layout_samplers[driver_saw_layout_sampler_count++] = sampler; + for (int i = 0; i < driver_ycbcr_count; i++) + if ((binding->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) && driver_ycbcr[i] == sampler) + return VK_ERROR_UNKNOWN; + } + } + *layout = (VkDescriptorSetLayout)0x5000; + return VK_SUCCESS; +} + +static void VKAPI_CALL mock_destroy_device(VkDevice device, const VkAllocationCallbacks *allocator) {} + +static VkResult VKAPI_CALL mock_timestamps(VkDevice device, uint32_t count, const VkCalibratedTimestampInfoEXT *infos, + uint64_t *timestamps, uint64_t *deviation) { + for (uint32_t i = 0; i < count; i++) timestamps[i] = 42; + *deviation = 1; + return VK_SUCCESS; +} + +#define MOCK(name, function) if (!strcmp(requested, name)) return (PFN_vkVoidFunction)function +static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL mock_gipa(VkInstance instance, const char *requested) { + MOCK("vkCreateInstance", mock_create_instance); + MOCK("vkCreateDevice", mock_create_device); + MOCK("vkGetPhysicalDeviceFeatures", mock_features); + MOCK("vkGetPhysicalDeviceFeatures2", mock_features2); + MOCK("vkGetPhysicalDeviceFormatProperties", mock_format_properties); + MOCK("vkGetPhysicalDeviceFormatProperties2", mock_format_properties2); + MOCK("vkGetPhysicalDeviceCalibrateableTimeDomainsEXT", mock_time_domains); + return NULL; +} + +static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL mock_gdpa(VkDevice device, const char *requested) { + MOCK("vkCreateSampler", mock_create_sampler); + MOCK("vkDestroySampler", mock_destroy_sampler); + MOCK("vkCreateDescriptorSetLayout", mock_create_set_layout); + MOCK("vkDestroyDevice", mock_destroy_device); + MOCK("vkGetCalibratedTimestampsEXT", mock_timestamps); + return NULL; +} + +/* The loader's link for one vkCreateDevice call, then the caller's own chain. */ +static VkResult create(const void *chain, const VkPhysicalDeviceFeatures *enabled, VkDevice *device) { + VkLayerDeviceLink link = {NULL, mock_gipa, mock_gdpa}; + VkLayerDeviceCreateInfo loader = {VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO, chain, VK_LAYER_LINK_INFO, {&link}}; + VkDeviceCreateInfo info = {VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, &loader, 0, 0, NULL, 0, NULL, 0, NULL, enabled}; + PFN_vkCreateDevice create_device = (PFN_vkCreateDevice)vkGetInstanceProcAddr((VkInstance)&mock_instance, "vkCreateDevice"); + return create_device((VkPhysicalDevice)&mock_physical, &info, NULL, device); +} + +int main(void) { + VkNegotiateLayerInterface negotiate = {LAYER_NEGOTIATE_INTERFACE_STRUCT, NULL, 2, NULL, NULL, NULL}; + assert(vkNegotiateLoaderLayerInterfaceVersion(&negotiate) == VK_SUCCESS); + + VkLayerInstanceLink instance_link = {NULL, mock_gipa, NULL}; + VkLayerInstanceCreateInfo instance_loader = {VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO, NULL, VK_LAYER_LINK_INFO, + {&instance_link}}; + VkInstanceCreateInfo instance_info = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pNext = &instance_loader}; + VkInstance instance; + PFN_vkCreateInstance create_instance_fn = (PFN_vkCreateInstance)vkGetInstanceProcAddr(NULL, "vkCreateInstance"); + assert(create_instance_fn(&instance_info, NULL, &instance) == VK_SUCCESS); + + /* The emulated bit is reported... */ + VkPhysicalDeviceFeatures features; + ((PFN_vkGetPhysicalDeviceFeatures)vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceFeatures"))( + (VkPhysicalDevice)&mock_physical, &features); + assert(features.textureCompressionBC); + + /* ...and cleared before the driver, through pEnabledFeatures... */ + VkDevice device; + VkPhysicalDeviceFeatures legacy = {.textureCompressionBC = VK_TRUE}; + assert(create(NULL, &legacy, &device) == VK_SUCCESS && !driver_saw_bc && legacy.textureCompressionBC); + + /* ...and through a VkPhysicalDeviceFeatures2 behind another structure, leaving the caller's chain intact. */ + VkPhysicalDeviceVulkan12Features vk12 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; + VkPhysicalDeviceFeatures2 features2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &vk12, + {.textureCompressionBC = VK_TRUE}}; + VkPhysicalDeviceTimelineSemaphoreFeatures timeline = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES, + &features2, VK_TRUE}; + VkPhysicalDeviceFeatures2 features2_before = features2; + VkPhysicalDeviceTimelineSemaphoreFeatures timeline_before = timeline; + VkDevice chained; + assert(create(&timeline, NULL, &chained) == VK_SUCCESS && !driver_saw_bc); + assert(!memcmp(&features2, &features2_before, sizeof(features2))); + assert(!memcmp(&timeline, &timeline_before, sizeof(timeline))); + + /* A structure newer than the headers this was built with cannot be copied: the chain passes as it + * is and the driver refuses the bit, without the caller's structures being written. */ + struct { VkStructureType sType; const void *pNext; uint32_t payload; } future = {(VkStructureType)0x7ffffff0, &features2, 7}; + VkDevice unused; + assert(create(&future, NULL, &unused) == VK_ERROR_FEATURE_NOT_PRESENT); + assert(!memcmp(&features2, &features2_before, sizeof(features2)) && future.pNext == &features2); + + /* Compute layouts get a plain sampler in place of a YCbCr one. */ + PFN_vkCreateSampler create_sampler_fn = (PFN_vkCreateSampler)vkGetDeviceProcAddr(device, "vkCreateSampler"); + PFN_vkDestroySampler destroy_sampler_fn = (PFN_vkDestroySampler)vkGetDeviceProcAddr(device, "vkDestroySampler"); + PFN_vkCreateDescriptorSetLayout create_layout = (PFN_vkCreateDescriptorSetLayout)vkGetDeviceProcAddr(device, "vkCreateDescriptorSetLayout"); + VkSamplerYcbcrConversionInfo conversion = {VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO, NULL, (VkSamplerYcbcrConversion)1}; + VkSamplerCreateInfo ycbcr_info = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .pNext = &conversion}; + VkSamplerCreateInfo plain_info = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO}; + VkSampler ycbcr; + assert(create_sampler_fn(device, &ycbcr_info, NULL, &ycbcr) == VK_SUCCESS); + VkSampler immutable[2] = {ycbcr, ycbcr}; + VkDescriptorSetLayoutBinding binding = {4, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, VK_SHADER_STAGE_COMPUTE_BIT, immutable}; + VkDescriptorSetLayoutCreateInfo layout_info = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, NULL, 0, 1, &binding}; + VkDescriptorSetLayout layout; + assert(create_layout(device, &layout_info, NULL, &layout) == VK_SUCCESS); + assert(driver_layout_samplers[0] != ycbcr && immutable[0] == ycbcr); + + /* A destroyed YCbCr sampler's handle, reused for a plain sampler, is left alone. */ + destroy_sampler_fn(device, ycbcr, NULL); + next_sampler = (uint64_t)ycbcr; + VkSampler reused; + assert(create_sampler_fn(device, &plain_info, NULL, &reused) == VK_SUCCESS && reused == ycbcr); + immutable[0] = immutable[1] = reused; + assert(create_layout(device, &layout_info, NULL, &layout) == VK_SUCCESS && driver_layout_samplers[0] == reused); + + /* Registrations belong to their device and go with it. */ + VkSampler other; + assert(create_sampler_fn(chained, &ycbcr_info, NULL, &other) == VK_SUCCESS && ycbcr_count == 1); + ((PFN_vkDestroyDevice)vkGetDeviceProcAddr(chained, "vkDestroyDevice"))(chained, NULL); + assert(ycbcr_count == 0); + + /* The KHR calibrated-timestamp entry points reach the EXT ones. */ + uint32_t domains = 0; + PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT time_domains = (PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT) + vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceCalibrateableTimeDomainsKHR"); + assert(time_domains((VkPhysicalDevice)&mock_physical, &domains, NULL) == VK_SUCCESS && domains == 2); + VkCalibratedTimestampInfoEXT stamp = {VK_STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT, NULL, VK_TIME_DOMAIN_DEVICE_EXT}; + uint64_t value = 0, deviation = 0; + PFN_vkGetCalibratedTimestampsEXT timestamps = (PFN_vkGetCalibratedTimestampsEXT)vkGetDeviceProcAddr(device, "vkGetCalibratedTimestampsKHR"); + assert(timestamps(device, 1, &stamp, &value, &deviation) == VK_SUCCESS && value == 42); + + puts("xclipse layer ok"); + return 0; +} diff --git a/tools/venus/addr2line.sh b/tools/venus/addr2line.sh new file mode 100644 index 0000000000..e9f6e5f52f --- /dev/null +++ b/tools/venus/addr2line.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Function, source line and disassembly at offsets into an aarch64 library, with the NDK's tools. +# Run in WSL: bash addr2line.sh <library> <offset>... +# The offset is the crash pc minus the library's start in the process's maps (tools/venus/watch-maps.sh). +LIB=${1:?library} +shift +B=/home/delo/android-sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/bin +md5sum "$LIB" +$B/llvm-addr2line -f -C -i -e "$LIB" "$@" +for a in "$@"; do + start=$(printf "0x%x" $((a - 48))) + stop=$(printf "0x%x" $((a + 16))) + $B/llvm-objdump -d --no-show-raw-insn --start-address=$start --stop-address=$stop "$LIB" | tail -n +7 +done diff --git a/tools/venus/ci-build.sh b/tools/venus/ci-build.sh new file mode 100755 index 0000000000..a06f3b73b7 --- /dev/null +++ b/tools/venus/ci-build.sh @@ -0,0 +1,146 @@ +#!/bin/bash +# Builds the Mali (Venus) component in CI, from David Cimo's tools/venus recipes (build-venus-icd.sh, +# build-virgl-android.sh, build-layer.sh), into venus.tzst rooted at app/src/main: +# jniLibs/arm64-v8a/ libvirgl_test_server.so, libvirgl_render_server.so, libvirglrenderer.so, +# libepoxy.so (bionic: the vtest server the app runs over the phone's Vulkan) +# assets/venus/ libvulkan_virtio.so (glibc: Mesa's Venus ICD for the session) +# assets/linuxfs/usr/local/... the Mali compatibility layer and its manifest +# Needs: docker (Debian trixie for the glibc parts), the NDK in $ANDROID_NDK_HOME, meson, ninja. +set -euo pipefail +REPO=$(cd "$(dirname "$0")/../.." && pwd) +W=${WORK:-$PWD/venus-work} +OUT=$W/out +rm -rf "$OUT" && mkdir -p "$OUT/jniLibs/arm64-v8a" "$OUT/assets/venus" \ + "$OUT/assets/linuxfs/usr/local/lib/droiddeck-mali" "$OUT/assets/linuxfs/usr/local/share/vulkan/implicit_layer.d" + +# --- Linux side: Mesa 26.2.5's Venus ICD and the Mali compatibility layer (aarch64 glibc) --- +docker run --rm --platform linux/amd64 -v "$W":/w -v "$REPO/tools/venus":/venus:ro -w /tmp debian:trixie bash -c ' +set -euo pipefail +export DEBIAN_FRONTEND=noninteractive +dpkg --add-architecture arm64 +apt-get update -qq +apt-get install -y -qq --no-install-recommends git ca-certificates curl crossbuild-essential-arm64 meson ninja-build \ + pkg-config python3-mako python3-yaml python3-packaging bison flex glslang-tools libwayland-bin wayland-protocols \ + libdrm-dev:arm64 libwayland-dev:arm64 libx11-dev:arm64 libx11-xcb-dev:arm64 libxcb1-dev:arm64 \ + libxcb-dri3-dev:arm64 libxcb-present-dev:arm64 libxcb-randr0-dev:arm64 libxcb-shm0-dev:arm64 \ + libxcb-sync-dev:arm64 libxcb-xfixes0-dev:arm64 libxshmfence-dev:arm64 libxrandr-dev:arm64 \ + libexpat1-dev:arm64 zlib1g-dev:arm64 libzstd-dev:arm64 >/dev/null +cat > /tmp/arm64.ini <<EOC +[binaries] +c = '"'"'aarch64-linux-gnu-gcc'"'"' +cpp = '"'"'aarch64-linux-gnu-g++'"'"' +ar = '"'"'aarch64-linux-gnu-ar'"'"' +strip = '"'"'aarch64-linux-gnu-strip'"'"' +nm = '"'"'aarch64-linux-gnu-nm'"'"' +pkg-config = '"'"'pkg-config'"'"' +[properties] +pkg_config_libdir = ['"'"'/usr/lib/aarch64-linux-gnu/pkgconfig'"'"', '"'"'/usr/share/pkgconfig'"'"'] +[host_machine] +system = '"'"'linux'"'"' +cpu_family = '"'"'aarch64'"'"' +cpu = '"'"'armv8-a'"'"' +endian = '"'"'little'"'"' +EOC +git clone -q --depth 1 -b mesa-26.2.5 https://gitlab.freedesktop.org/mesa/mesa.git +(cd mesa && git apply /venus/mesa-venus-vtest.patch) +meson setup venus-build mesa --cross-file /tmp/arm64.ini --prefix=/usr --libdir=lib \ + --buildtype=release -Db_ndebug=true \ + -Dvulkan-drivers=virtio -Dgallium-drivers= -Dplatforms=x11,wayland \ + -Dllvm=disabled -Dglx=disabled -Degl=disabled -Dgbm=disabled -Dopengl=false -Dgles1=disabled -Dgles2=disabled \ + -Dvideo-codecs= -Dvulkan-layers= -Dtools= -Dbuild-tests=false -Dvalgrind=disabled -Dlibunwind=disabled \ + -Dzstd=enabled -Dshared-glapi=disabled >/dev/null +ninja -C venus-build src/virtio/vulkan/libvulkan_virtio.so +aarch64-linux-gnu-strip --strip-unneeded -o /w/out/assets/venus/libvulkan_virtio.so venus-build/src/virtio/vulkan/libvulkan_virtio.so +echo "venus icd min glibc: $(aarch64-linux-gnu-objdump -T /w/out/assets/venus/libvulkan_virtio.so | grep -o "GLIBC_[0-9.]*" | sort -Vu | tail -1)" +SDK=vulkan-sdk-1.4.357.0 +git -c advice.detachedHead=false clone -q --depth 1 -b $SDK https://github.com/KhronosGroup/Vulkan-Headers.git /tmp/vulkan +git -c advice.detachedHead=false clone -q --depth 1 -b $SDK https://github.com/KhronosGroup/SPIRV-Headers.git /tmp/spirv +mkdir -p /tmp/bcdec +curl -sSfL -o /tmp/bcdec/bcdec.h https://raw.githubusercontent.com/iOrange/bcdec/80859ed3b7afb1c527a2a99d70c61457bea72d0c/bcdec.h +L=/w/out/assets/linuxfs/usr/local +aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -Wextra -Wno-unused-parameter -fvisibility=hidden -pthread \ + -I/tmp/vulkan/include -I/tmp/spirv/include -I/tmp/bcdec \ + -o $L/lib/droiddeck-mali/libVkLayer_droiddeck_mali_compat.so /venus/layer/*.c +aarch64-linux-gnu-strip --strip-unneeded $L/lib/droiddeck-mali/libVkLayer_droiddeck_mali_compat.so +cp /venus/layer/VkLayer_droiddeck_mali_compat.json $L/share/vulkan/implicit_layer.d/ +chmod -R a+rwX /w/out +' + +# --- Android side: libepoxy + virglrenderer 1.3.0 (venus, vtest) for arm64 with the NDK --- +NDK=${ANDROID_NDK_HOME:?} +TC=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin +API=29 +A=$W/android +AOUT=$A/out +mkdir -p "$A/cross" "$A/compat/log" "$A/compat/cutils" "$AOUT/lib/pkgconfig" +cd "$A" +git clone -q --depth 1 -b 1.5.10 https://github.com/anholt/libepoxy.git +git clone -q --depth 1 -b v1.4.365 https://github.com/KhronosGroup/Vulkan-Headers.git +git clone -q --depth 1 -b virglrenderer-1.3.0 https://gitlab.freedesktop.org/virgl/virglrenderer.git +git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-android.patch" +git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-destroy-unknown-pipeline.patch" +git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-destroy-mutex-after-objects.patch" +cat > compat/log/log.h <<'EOC' +#pragma once +#include <android/log.h> +#define LOG_PRI(prio, tag, ...) __android_log_print(prio, tag, __VA_ARGS__) +EOC +cat > compat/cutils/properties.h <<'EOC' +#pragma once +#include <string.h> +#include <sys/system_properties.h> +#define PROPERTY_VALUE_MAX PROP_VALUE_MAX +#define PROPERTY_KEY_MAX 32 +static inline int property_get(const char *key, char *value, const char *def) +{ + int len = __system_property_get(key, value); + if (len <= 0 && def) { strcpy(value, def); len = (int)strlen(def); } + return len; +} +EOC +cat > "$AOUT/lib/pkgconfig/vulkan.pc" <<EOC +prefix=$A/Vulkan-Headers +includedir=\${prefix}/include +Name: vulkan +Description: Vulkan headers +Version: 1.4.365 +Cflags: -I\${includedir} +Libs: -lvulkan +EOC +cat > cross/android.ini <<EOC +[binaries] +c = '$TC/aarch64-linux-android$API-clang' +cpp = '$TC/aarch64-linux-android$API-clang++' +ar = '$TC/llvm-ar' +strip = '$TC/llvm-strip' +pkg-config = '/usr/bin/pkg-config' +[built-in options] +c_args = ['-I$A/Vulkan-Headers/include', '-I$A/compat'] +c_link_args = ['-llog', '-lnativewindow', '-Wl,-rpath=\$ORIGIN', '-Wl,-z,max-page-size=16384'] +cpp_link_args = ['-Wl,-rpath=\$ORIGIN', '-Wl,-z,max-page-size=16384'] +[properties] +pkg_config_libdir = '$AOUT/lib/pkgconfig' +[host_machine] +system = 'android' +cpu_family = 'aarch64' +cpu = 'armv8' +endian = 'little' +EOC +export PKG_CONFIG_LIBDIR=$AOUT/lib/pkgconfig PKG_CONFIG_PATH= +meson setup epoxy-build libepoxy --cross-file cross/android.ini --prefix="$AOUT" --libdir=lib \ + --buildtype=release -Degl=yes -Dglx=no -Dx11=false -Dtests=false >/dev/null +ninja -C epoxy-build install >/dev/null +meson setup virgl-build virglrenderer --cross-file cross/android.ini --prefix="$AOUT" --libdir=lib \ + --buildtype=release -Dvenus=true -Dplatforms=auto -Drender-server-worker=thread \ + -Dvulkan-dload=true -Dcheck-gl-errors=false -Dtests=false >/dev/null +ninja -C virgl-build install >/dev/null +J=$OUT/jniLibs/arm64-v8a +cp "$AOUT/bin/virgl_test_server" "$J/libvirgl_test_server.so" +cp "$AOUT/libexec/virgl_render_server" "$J/libvirgl_render_server.so" +cp "$AOUT/lib/libvirglrenderer.so" "$AOUT/lib/libepoxy.so" "$J/" +for f in "$J"/*.so; do "$TC/llvm-strip" --strip-unneeded "$f"; done + +cd "$OUT" +find . -type f | sort +tar --owner=0 --group=0 --numeric-owner --sort=name -cf - . | zstd -19 -T0 -q -o "$W/venus.tzst" +sha256sum "$W/venus.tzst" | tee "$W/venus.tzst.sha256" diff --git a/tools/venus/glprobe.c b/tools/venus/glprobe.c new file mode 100644 index 0000000000..da044311d7 --- /dev/null +++ b/tools/venus/glprobe.c @@ -0,0 +1,69 @@ +/* + * droiddeck-glprobe: does OpenGL through GLX start on this session's display, the way the Steam + * client's first window asks for it (glXChooseVisual, then a context)? Run once before the client + * on the Mali (Venus) route, where Zink failed on a Mali-G615 with nothing but "failed to load + * driver: zink" and the client gave up ("UpdateUI GL not available"). Exit 0 when a visual and a + * context come back, 1 when GL does not start, 2 when there is no X display or no libGL. + * libX11 and libGL are opened at run time, so this builds without their headers. + */ +#include <dlfcn.h> +#include <stdio.h> + +typedef void *(*open_display_fn)(const char *); +typedef int (*close_display_fn)(void *); +typedef int (*default_screen_fn)(void *); +typedef void *(*choose_visual_fn)(void *, int, int *); +typedef void *(*create_context_fn)(void *, void *, void *, int); +typedef void (*destroy_context_fn)(void *, void *); +typedef int (*free_fn)(void *); + +#define GLX_RGBA 4 +#define GLX_DOUBLEBUFFER 5 +#define GLX_RED_SIZE 8 +#define GLX_GREEN_SIZE 9 +#define GLX_BLUE_SIZE 10 + +int main(void) +{ + void *x11 = dlopen("libX11.so.6", RTLD_NOW | RTLD_GLOBAL); + void *gl = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL); + if (!x11 || !gl) { + printf("glprobe: cannot open %s: %s\n", x11 ? "libGL.so.1" : "libX11.so.6", dlerror()); + return 2; + } + open_display_fn open_display = (open_display_fn)dlsym(x11, "XOpenDisplay"); + close_display_fn close_display = (close_display_fn)dlsym(x11, "XCloseDisplay"); + default_screen_fn default_screen = (default_screen_fn)dlsym(x11, "XDefaultScreen"); + free_fn x_free = (free_fn)dlsym(x11, "XFree"); + choose_visual_fn choose_visual = (choose_visual_fn)dlsym(gl, "glXChooseVisual"); + create_context_fn create_context = (create_context_fn)dlsym(gl, "glXCreateContext"); + destroy_context_fn destroy_context = (destroy_context_fn)dlsym(gl, "glXDestroyContext"); + if (!open_display || !close_display || !default_screen || !x_free || !choose_visual || !create_context || + !destroy_context) { + printf("glprobe: missing X11/GLX entry points\n"); + return 2; + } + void *dpy = open_display(NULL); + if (!dpy) { + printf("glprobe: no X display\n"); + return 2; + } + int attrs[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, 0}; + void *visual = choose_visual(dpy, default_screen(dpy), attrs); + if (!visual) { + printf("glprobe: FAIL glXChooseVisual\n"); + close_display(dpy); + return 1; + } + void *ctx = create_context(dpy, visual, NULL, 1); + x_free(visual); + if (!ctx) { + printf("glprobe: FAIL glXCreateContext\n"); + close_display(dpy); + return 1; + } + destroy_context(dpy, ctx); + close_display(dpy); + printf("glprobe: OK (visual and context)\n"); + return 0; +} diff --git a/tools/venus/guest-vulkaninfo.sh b/tools/venus/guest-vulkaninfo.sh new file mode 100644 index 0000000000..124c5fb268 --- /dev/null +++ b/tools/venus/guest-vulkaninfo.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# vulkaninfo as the session's Linux processes see the GPU: through Venus, and through the Mali +# compatibility layer when DROIDDECK_MALI_COMPAT is 1. Needs a running session (the vtest server). +# Run from Git Bash: MSYS_NO_PATHCONV=1 bash tools/venus/guest-vulkaninfo.sh [0|1] > vulkaninfo.txt +set -euo pipefail +COMPAT=${1:-1} +A=/c/Users/derab/tools/platform-tools/adb.exe +PKG=com.droiddeck.launcher +F=/data/user/0/$PKG/files +APK=$($A shell pm path $PKG | head -1 | tr -d '\r' | sed 's/^package://') +L=${APK%/base.apk}/lib/arm64 +$A exec-out "run-as $PKG sh -c 'PROOT_TMP_DIR=/data/user/0/$PKG/cache PROOT_LOADER=$L/libproot-loader.so \ + $L/libproot.so -r $F/linuxfs -w /root -b /dev -b /proc -b /sys -b $F /usr/bin/env -i HOME=/root \ + PATH=/usr/bin:/bin DROIDDECK_MALI_COMPAT=$COMPAT VK_ICD_FILENAMES=$F/venus/virtio_icd.json VN_DEBUG=vtest \ + VTEST_SOCKET_NAME=$F/venus/vtest.sock vulkaninfo 2>&1'" diff --git a/tools/venus/layer/VkLayer_droiddeck_mali_compat.json b/tools/venus/layer/VkLayer_droiddeck_mali_compat.json new file mode 100644 index 0000000000..e1efa4c159 --- /dev/null +++ b/tools/venus/layer/VkLayer_droiddeck_mali_compat.json @@ -0,0 +1,17 @@ +{ + "file_format_version": "1.2.0", + "layer": { + "name": "VK_LAYER_DROIDDECK_mali_compat", + "type": "GLOBAL", + "library_path": "/usr/local/lib/droiddeck-mali/libVkLayer_droiddeck_mali_compat.so", + "api_version": "1.4.357", + "implementation_version": "1", + "description": "Features DXVK requires and Mali lacks, made up for", + "functions": { + "vkNegotiateLoaderLayerInterfaceVersion": "vkNegotiateLoaderLayerInterfaceVersion" + }, + "disable_environment": { + "DROIDDECK_MALI_COMPAT_DISABLE": "1" + } + } +} diff --git a/tools/venus/layer/bc.c b/tools/venus/layer/bc.c new file mode 100644 index 0000000000..328b68169d --- /dev/null +++ b/tools/venus/layer/bc.c @@ -0,0 +1,869 @@ +/* + * BC1-BC7 textures on a GPU without them: each BC image is created in an uncompressed format, and + * every upload into one is decoded on the CPU while the copy is recorded. The decoded texels go + * through a staging buffer of the layer's own, which lives until the command buffer is reset. + * Uploads must come from memory the application has mapped, as DXVK's staging memory always is. + */ +#include "mali_compat.h" + +#include <stdlib.h> +#include <string.h> + +#define BCDEC_IMPLEMENTATION +#define BCDEC_STATIC +#define BCDEC_BC4BC5_PRECISE +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-function" +#include "bcdec.h" +#pragma GCC diagnostic pop + +#define HANDLE(h) ((uint64_t)(uintptr_t)(h)) +#define STAGING_BLOCK_SIZE (16u << 20) +#define STAGING_KEPT (64u << 20) + +enum bc_kind { BC1, BC2, BC3, BC4, BC5, BC6H, BC7 }; + +struct bc_format { + VkFormat format; + VkFormat substitute; + enum bc_kind kind; + uint32_t block_bytes; + uint32_t texel_bytes; + bool is_signed; + /* BC1's RGB formats have no alpha; its 1-bit transparency must read as opaque. */ + bool opaque; +}; + +static const struct bc_format bc_formats[] = { + {VK_FORMAT_BC1_RGB_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC1, 8, 4, false, true}, + {VK_FORMAT_BC1_RGB_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC1, 8, 4, false, true}, + {VK_FORMAT_BC1_RGBA_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC1, 8, 4, false, false}, + {VK_FORMAT_BC1_RGBA_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC1, 8, 4, false, false}, + {VK_FORMAT_BC2_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC2, 16, 4, false, false}, + {VK_FORMAT_BC2_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC2, 16, 4, false, false}, + {VK_FORMAT_BC3_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC3, 16, 4, false, false}, + {VK_FORMAT_BC3_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC3, 16, 4, false, false}, + {VK_FORMAT_BC4_UNORM_BLOCK, VK_FORMAT_R8_UNORM, BC4, 8, 1, false, false}, + {VK_FORMAT_BC4_SNORM_BLOCK, VK_FORMAT_R8_SNORM, BC4, 8, 1, true, false}, + {VK_FORMAT_BC5_UNORM_BLOCK, VK_FORMAT_R8G8_UNORM, BC5, 16, 2, false, false}, + {VK_FORMAT_BC5_SNORM_BLOCK, VK_FORMAT_R8G8_SNORM, BC5, 16, 2, true, false}, + {VK_FORMAT_BC6H_UFLOAT_BLOCK, VK_FORMAT_R16G16B16A16_SFLOAT, BC6H, 16, 8, false, false}, + {VK_FORMAT_BC6H_SFLOAT_BLOCK, VK_FORMAT_R16G16B16A16_SFLOAT, BC6H, 16, 8, true, false}, + {VK_FORMAT_BC7_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC7, 16, 4, false, false}, + {VK_FORMAT_BC7_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC7, 16, 4, false, false}, +}; + +static const struct bc_format *find_bc(VkFormat format) +{ + for (size_t i = 0; i < sizeof(bc_formats) / sizeof(bc_formats[0]); i++) { + if (bc_formats[i].format == format) + return &bc_formats[i]; + } + return NULL; +} + +VkFormat bc_substitute(VkFormat format) +{ + const struct bc_format *bc = find_bc(format); + return bc ? bc->substitute : VK_FORMAT_UNDEFINED; +} + +/* What a real BC format allows: sampling and copies. */ +#define BC_FEATURES \ + (VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT | \ + VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | \ + VK_FORMAT_FEATURE_TRANSFER_DST_BIT | VK_FORMAT_FEATURE_BLIT_SRC_BIT) +#define BC_USAGE (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT) + +static const struct bc_format *physical_bc(VkPhysicalDevice physical_device, VkFormat format, struct instance **inst) +{ + *inst = instance_from_handle(physical_device); + if (!(physical_device_gaps(*inst, physical_device) & GAP_BC)) + return NULL; + return find_bc(format); +} + +VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties(VkPhysicalDevice physical_device, VkFormat format, + VkFormatProperties *properties) +{ + struct instance *inst; + const struct bc_format *bc = physical_bc(physical_device, format, &inst); + inst->GetPhysicalDeviceFormatProperties(physical_device, bc ? bc->substitute : format, properties); + if (bc) { + properties->optimalTilingFeatures &= BC_FEATURES; + properties->linearTilingFeatures = 0; + properties->bufferFeatures = 0; + } +} + +VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physical_device, VkFormat format, + VkFormatProperties2 *properties) +{ + struct instance *inst; + const struct bc_format *bc = physical_bc(physical_device, format, &inst); + inst->GetPhysicalDeviceFormatProperties2(physical_device, bc ? bc->substitute : format, properties); + if (!bc) + return; + properties->formatProperties.optimalTilingFeatures &= BC_FEATURES; + properties->formatProperties.linearTilingFeatures = 0; + properties->formatProperties.bufferFeatures = 0; + for (VkBaseOutStructure *s = properties->pNext; s; s = s->pNext) { + if (s->sType == VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3) { + VkFormatProperties3 *p3 = (VkFormatProperties3 *)s; + p3->optimalTilingFeatures &= (VkFormatFeatureFlags2)BC_FEATURES; + p3->linearTilingFeatures = 0; + p3->bufferFeatures = 0; + } else if (s->sType == VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT) { + ((VkDrmFormatModifierPropertiesListEXT *)s)->drmFormatModifierCount = 0; + } else if (s->sType == VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_2_EXT) { + ((VkDrmFormatModifierPropertiesList2EXT *)s)->drmFormatModifierCount = 0; + } + } +} + +VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties( + VkPhysicalDevice physical_device, VkFormat format, VkImageType type, VkImageTiling tiling, + VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties *properties) +{ + struct instance *inst; + const struct bc_format *bc = physical_bc(physical_device, format, &inst); + if (!bc) + return inst->GetPhysicalDeviceImageFormatProperties(physical_device, format, type, tiling, usage, flags, + properties); + if (tiling != VK_IMAGE_TILING_OPTIMAL || (usage & ~BC_USAGE)) + return VK_ERROR_FORMAT_NOT_SUPPORTED; + return inst->GetPhysicalDeviceImageFormatProperties(physical_device, bc->substitute, type, tiling, usage, + flags & ~VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT, + properties); +} + +/* A view format list naming BC formats, as one naming their substitutes. */ +struct format_list { + VkImageFormatListCreateInfo *list; + const VkFormat *original; + VkFormat formats[16]; +}; + +static void substitute_format_list(const void *chain, VkFormat substitute, struct format_list *saved) +{ + saved->list = NULL; + for (const VkBaseInStructure *s = chain; s; s = s->pNext) { + if (s->sType != VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO) + continue; + VkImageFormatListCreateInfo *list = (VkImageFormatListCreateInfo *)s; + uint32_t count = 0; + saved->formats[count++] = substitute; + for (uint32_t i = 0; i < list->viewFormatCount && count < 16; i++) { + VkFormat format = bc_substitute(list->pViewFormats[i]); + /* Uncompressed views of the compressed blocks have nothing to alias any more. */ + if (format == VK_FORMAT_UNDEFINED) + continue; + bool seen = false; + for (uint32_t k = 0; k < count; k++) + seen |= saved->formats[k] == format; + if (!seen) + saved->formats[count++] = format; + } + saved->list = list; + saved->original = list->pViewFormats; + list->pViewFormats = saved->formats; + list->viewFormatCount = count; + return; + } +} + +static void restore_format_list(struct format_list *saved, uint32_t original_count) +{ + if (saved->list) { + saved->list->pViewFormats = saved->original; + saved->list->viewFormatCount = original_count; + } +} + +static uint32_t format_list_count(const void *chain) +{ + for (const VkBaseInStructure *s = chain; s; s = s->pNext) { + if (s->sType == VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO) + return ((const VkImageFormatListCreateInfo *)s)->viewFormatCount; + } + return 0; +} + +VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties2( + VkPhysicalDevice physical_device, const VkPhysicalDeviceImageFormatInfo2 *info, + VkImageFormatProperties2 *properties) +{ + struct instance *inst; + const struct bc_format *bc = physical_bc(physical_device, info->format, &inst); + if (!bc) + return inst->GetPhysicalDeviceImageFormatProperties2(physical_device, info, properties); + if (info->tiling != VK_IMAGE_TILING_OPTIMAL || (info->usage & ~BC_USAGE)) + return VK_ERROR_FORMAT_NOT_SUPPORTED; + VkPhysicalDeviceImageFormatInfo2 copy = *info; + copy.format = bc->substitute; + copy.flags &= ~VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT; + uint32_t list_count = format_list_count(info->pNext); + struct format_list saved; + substitute_format_list(info->pNext, bc->substitute, &saved); + VkResult result = inst->GetPhysicalDeviceImageFormatProperties2(physical_device, ©, properties); + restore_format_list(&saved, list_count); + return result; +} + +struct bc_image { + const struct bc_format *format; + uint32_t array_layers; +}; + +static void substitute_image_info(const struct bc_format *bc, VkImageCreateInfo *info) +{ + info->format = bc->substitute; + info->flags &= ~VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT; + info->usage &= BC_USAGE; +} + +VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateInfo *info, + const VkAllocationCallbacks *allocator, VkImage *image) +{ + struct device *dev = device_from_handle(device); + const struct bc_format *bc = find_bc(info->format); + if (!bc) + return dev->CreateImage(device, info, allocator, image); + + VkImageCreateInfo copy = *info; + substitute_image_info(bc, ©); + uint32_t list_count = format_list_count(info->pNext); + struct format_list saved; + substitute_format_list(info->pNext, bc->substitute, &saved); + VkResult result = dev->CreateImage(device, ©, allocator, image); + restore_format_list(&saved, list_count); + if (result != VK_SUCCESS) + return result; + + struct bc_image *tracked = malloc(sizeof(*tracked)); + tracked->format = bc; + tracked->array_layers = info->arrayLayers; + pthread_mutex_lock(&dev->lock); + map_put(&dev->images, HANDLE(*image), tracked); + pthread_mutex_unlock(&dev->lock); + return VK_SUCCESS; +} + +VKAPI_ATTR void VKAPI_CALL DestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *allocator) +{ + struct device *dev = device_from_handle(device); + pthread_mutex_lock(&dev->lock); + free(map_remove(&dev->images, HANDLE(image))); + pthread_mutex_unlock(&dev->lock); + dev->DestroyImage(device, image, allocator); +} + +static const struct bc_image *tracked_image(struct device *dev, VkImage image) +{ + pthread_mutex_lock(&dev->lock); + const struct bc_image *tracked = map_get(&dev->images, HANDLE(image)); + pthread_mutex_unlock(&dev->lock); + return tracked; +} + +VKAPI_ATTR VkResult VKAPI_CALL CreateImageView(VkDevice device, const VkImageViewCreateInfo *info, + const VkAllocationCallbacks *allocator, VkImageView *view) +{ + struct device *dev = device_from_handle(device); + const struct bc_image *tracked = tracked_image(dev, info->image); + if (!tracked) + return dev->CreateImageView(device, info, allocator, view); + VkImageViewCreateInfo copy = *info; + VkFormat format = bc_substitute(info->format); + copy.format = format != VK_FORMAT_UNDEFINED ? format : tracked->format->substitute; + return dev->CreateImageView(device, ©, allocator, view); +} + +VKAPI_ATTR void VKAPI_CALL GetDeviceImageMemoryRequirements(VkDevice device, + const VkDeviceImageMemoryRequirements *info, + VkMemoryRequirements2 *requirements) +{ + struct device *dev = device_from_handle(device); + const struct bc_format *bc = find_bc(info->pCreateInfo->format); + if (!bc) { + dev->GetDeviceImageMemoryRequirements(device, info, requirements); + return; + } + VkImageCreateInfo image = *info->pCreateInfo; + substitute_image_info(bc, &image); + VkDeviceImageMemoryRequirements copy = *info; + copy.pCreateInfo = ℑ + dev->GetDeviceImageMemoryRequirements(device, ©, requirements); +} + +VKAPI_ATTR void VKAPI_CALL GetDeviceImageSparseMemoryRequirements( + VkDevice device, const VkDeviceImageMemoryRequirements *info, uint32_t *count, + VkSparseImageMemoryRequirements2 *requirements) +{ + struct device *dev = device_from_handle(device); + const struct bc_format *bc = find_bc(info->pCreateInfo->format); + if (!bc) { + dev->GetDeviceImageSparseMemoryRequirements(device, info, count, requirements); + return; + } + VkImageCreateInfo image = *info->pCreateInfo; + substitute_image_info(bc, &image); + VkDeviceImageMemoryRequirements copy = *info; + copy.pCreateInfo = ℑ + dev->GetDeviceImageSparseMemoryRequirements(device, ©, count, requirements); +} + +VKAPI_ATTR void VKAPI_CALL GetDeviceImageSubresourceLayout(VkDevice device, + const VkDeviceImageSubresourceInfo *info, + VkSubresourceLayout2 *layout) +{ + struct device *dev = device_from_handle(device); + const struct bc_format *bc = find_bc(info->pCreateInfo->format); + if (!bc) { + dev->GetDeviceImageSubresourceLayout(device, info, layout); + return; + } + VkImageCreateInfo image = *info->pCreateInfo; + substitute_image_info(bc, &image); + VkDeviceImageSubresourceInfo copy = *info; + copy.pCreateInfo = ℑ + dev->GetDeviceImageSubresourceLayout(device, ©, layout); +} + +struct bound_buffer { + VkDeviceMemory memory; + VkDeviceSize offset; +}; + +static void track_binding(struct device *dev, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize offset) +{ + struct bound_buffer *bound = malloc(sizeof(*bound)); + bound->memory = memory; + bound->offset = offset; + pthread_mutex_lock(&dev->lock); + free(map_remove(&dev->buffers, HANDLE(buffer))); + map_put(&dev->buffers, HANDLE(buffer), bound); + pthread_mutex_unlock(&dev->lock); +} + +VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, + VkDeviceSize offset) +{ + struct device *dev = device_from_handle(device); + VkResult result = dev->BindBufferMemory(device, buffer, memory, offset); + if (result == VK_SUCCESS) + track_binding(dev, buffer, memory, offset); + return result; +} + +VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory2(VkDevice device, uint32_t count, const VkBindBufferMemoryInfo *infos) +{ + struct device *dev = device_from_handle(device); + VkResult result = dev->BindBufferMemory2(device, count, infos); + if (result == VK_SUCCESS) { + for (uint32_t i = 0; i < count; i++) + track_binding(dev, infos[i].buffer, infos[i].memory, infos[i].memoryOffset); + } + return result; +} + +VKAPI_ATTR void VKAPI_CALL DestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *allocator) +{ + struct device *dev = device_from_handle(device); + pthread_mutex_lock(&dev->lock); + free(map_remove(&dev->buffers, HANDLE(buffer))); + pthread_mutex_unlock(&dev->lock); + dev->DestroyBuffer(device, buffer, allocator); +} + +/* The memory's start as the application sees it mapped. */ +static void track_mapping(struct device *dev, VkDeviceMemory memory, VkDeviceSize offset, void *data) +{ + pthread_mutex_lock(&dev->lock); + map_put(&dev->memories, HANDLE(memory), (uint8_t *)data - offset); + pthread_mutex_unlock(&dev->lock); +} + +static void forget_mapping(struct device *dev, VkDeviceMemory memory) +{ + pthread_mutex_lock(&dev->lock); + map_remove(&dev->memories, HANDLE(memory)); + pthread_mutex_unlock(&dev->lock); +} + +VKAPI_ATTR VkResult VKAPI_CALL MapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, + VkDeviceSize size, VkMemoryMapFlags flags, void **data) +{ + struct device *dev = device_from_handle(device); + VkResult result = dev->MapMemory(device, memory, offset, size, flags, data); + if (result == VK_SUCCESS) + track_mapping(dev, memory, offset, *data); + return result; +} + +VKAPI_ATTR VkResult VKAPI_CALL MapMemory2(VkDevice device, const VkMemoryMapInfo *info, void **data) +{ + struct device *dev = device_from_handle(device); + VkResult result = dev->MapMemory2(device, info, data); + if (result == VK_SUCCESS) + track_mapping(dev, info->memory, info->offset, *data); + return result; +} + +VKAPI_ATTR void VKAPI_CALL UnmapMemory(VkDevice device, VkDeviceMemory memory) +{ + struct device *dev = device_from_handle(device); + forget_mapping(dev, memory); + dev->UnmapMemory(device, memory); +} + +VKAPI_ATTR VkResult VKAPI_CALL UnmapMemory2(VkDevice device, const VkMemoryUnmapInfo *info) +{ + struct device *dev = device_from_handle(device); + forget_mapping(dev, info->memory); + return dev->UnmapMemory2(device, info); +} + +VKAPI_ATTR void VKAPI_CALL FreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks *allocator) +{ + struct device *dev = device_from_handle(device); + forget_mapping(dev, memory); + dev->FreeMemory(device, memory, allocator); +} + +struct staging_block { + VkBuffer buffer; + VkDeviceMemory memory; + uint8_t *data; + VkDeviceSize size; + VkDeviceSize used; + struct staging_block *next; +}; + +struct command_buffer { + VkCommandPool pool; + struct staging_block *staging; +}; + +static void destroy_block(struct device *dev, struct staging_block *block) +{ + dev->DestroyBuffer(dev->handle, block->buffer, NULL); + dev->FreeMemory(dev->handle, block->memory, NULL); + free(block); +} + +static struct staging_block *create_block(struct device *dev, VkDeviceSize size) +{ + struct staging_block *block = calloc(1, sizeof(*block)); + block->size = size; + VkBufferCreateInfo buffer_info = { + .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, + .size = size, + .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT, + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, + }; + if (dev->CreateBuffer(dev->handle, &buffer_info, NULL, &block->buffer) != VK_SUCCESS) { + free(block); + return NULL; + } + VkMemoryRequirements requirements; + dev->GetBufferMemoryRequirements(dev->handle, block->buffer, &requirements); + const VkMemoryPropertyFlags wanted = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + uint32_t type = UINT32_MAX; + for (uint32_t i = 0; i < dev->memory_properties.memoryTypeCount && type == UINT32_MAX; i++) { + if ((requirements.memoryTypeBits & (1u << i)) && + (dev->memory_properties.memoryTypes[i].propertyFlags & wanted) == wanted) + type = i; + } + VkMemoryAllocateInfo allocate_info = { + .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .allocationSize = requirements.size, + .memoryTypeIndex = type, + }; + void *data = NULL; + if (type == UINT32_MAX || dev->AllocateMemory(dev->handle, &allocate_info, NULL, &block->memory) != VK_SUCCESS) { + dev->DestroyBuffer(dev->handle, block->buffer, NULL); + free(block); + return NULL; + } + if (dev->BindBufferMemory(dev->handle, block->buffer, block->memory, 0) != VK_SUCCESS || + dev->MapMemory(dev->handle, block->memory, 0, VK_WHOLE_SIZE, 0, &data) != VK_SUCCESS) { + destroy_block(dev, block); + return NULL; + } + block->data = data; + return block; +} + +/* Called with the device lock held: the command buffer is done with its staging. */ +static void recycle_staging(struct device *dev, struct command_buffer *state) +{ + VkDeviceSize kept = 0; + for (struct staging_block *b = dev->free_staging; b; b = b->next) + kept += b->size; + while (state->staging) { + struct staging_block *block = state->staging; + state->staging = block->next; + if (kept + block->size > STAGING_KEPT) { + destroy_block(dev, block); + continue; + } + block->used = 0; + block->next = dev->free_staging; + dev->free_staging = block; + kept += block->size; + } +} + +/* Room for `size` bytes in a staging buffer that lives as long as the command buffer's recording. */ +static struct staging_block *staging_for(struct device *dev, VkCommandBuffer cmd, VkDeviceSize size, + VkDeviceSize *offset) +{ + pthread_mutex_lock(&dev->lock); + struct command_buffer *state = map_get(&dev->command_buffers, HANDLE(cmd)); + if (!state) { + state = calloc(1, sizeof(*state)); + map_put(&dev->command_buffers, HANDLE(cmd), state); + } + struct staging_block *block = state->staging; + VkDeviceSize start = block ? (block->used + 63) & ~(VkDeviceSize)63 : 0; + if (!block || start + size > block->size) { + struct staging_block **link = &dev->free_staging; + while (*link && (*link)->size < size) + link = &(*link)->next; + block = *link; + if (block) + *link = block->next; + else + block = create_block(dev, size > STAGING_BLOCK_SIZE ? size : STAGING_BLOCK_SIZE); + if (block) { + block->next = state->staging; + state->staging = block; + } + start = 0; + } + if (block) + block->used = start + size; + pthread_mutex_unlock(&dev->lock); + *offset = start; + return block; +} + +/* Where the application has the buffer's contents mapped, or NULL. */ +static const uint8_t *mapped_buffer(struct device *dev, VkBuffer buffer) +{ + pthread_mutex_lock(&dev->lock); + const struct bound_buffer *bound = map_get(&dev->buffers, HANDLE(buffer)); + const uint8_t *base = bound ? map_get(&dev->memories, HANDLE(bound->memory)) : NULL; + const uint8_t *data = base ? base + bound->offset : NULL; + pthread_mutex_unlock(&dev->lock); + return data; +} + +static void decode_block(const struct bc_format *bc, const uint8_t *block, uint8_t *texels) +{ + switch (bc->kind) { + case BC1: + bcdec_bc1(block, texels, 16); + if (bc->opaque) { + for (int i = 0; i < 16; i++) + texels[i * 4 + 3] = 0xff; + } + break; + case BC2: + bcdec_bc2(block, texels, 16); + break; + case BC3: + bcdec_bc3(block, texels, 16); + break; + case BC4: + bcdec_bc4(block, texels, 4, bc->is_signed); + break; + case BC5: + bcdec_bc5(block, texels, 8, bc->is_signed); + break; + case BC6H: { + uint16_t rgb[16 * 3]; + bcdec_bc6h_half(block, rgb, 12, bc->is_signed); + uint16_t *rgba = (uint16_t *)texels; + for (int i = 0; i < 16; i++) { + rgba[i * 4 + 0] = rgb[i * 3 + 0]; + rgba[i * 4 + 1] = rgb[i * 3 + 1]; + rgba[i * 4 + 2] = rgb[i * 3 + 2]; + rgba[i * 4 + 3] = 0x3c00; + } + break; + } + case BC7: + bcdec_bc7(block, texels, 16); + break; + } +} + +struct upload { + VkDeviceSize offset; + uint32_t row_length; + uint32_t image_height; + VkImageSubresourceLayers subresource; + VkOffset3D image_offset; + VkExtent3D extent; +}; + +static uint32_t warned; + +static void warn_once(uint32_t bit, const char *message) +{ + if (!(__atomic_fetch_or(&warned, bit, __ATOMIC_RELAXED) & bit)) + layer_log("%s", message); +} + +static void upload_region(struct device *dev, VkCommandBuffer cmd, const struct bc_image *image, + const uint8_t *source, VkImage dst, VkImageLayout layout, const struct upload *region) +{ + const struct bc_format *bc = image->format; + uint32_t width = region->extent.width, height = region->extent.height; + uint32_t layers = region->subresource.layerCount; + if (layers == VK_REMAINING_ARRAY_LAYERS) + layers = image->array_layers - region->subresource.baseArrayLayer; + uint32_t slices = region->extent.depth * layers; + uint32_t row_texels = region->row_length ? region->row_length : width; + uint32_t height_texels = region->image_height ? region->image_height : height; + size_t source_row = (size_t)((row_texels + 3) / 4) * bc->block_bytes; + size_t source_slice = (size_t)((height_texels + 3) / 4) * source_row; + size_t row_bytes = (size_t)width * bc->texel_bytes; + VkDeviceSize size = (VkDeviceSize)row_bytes * height * slices; + if (!size) + return; + + VkDeviceSize offset; + struct staging_block *block = staging_for(dev, cmd, size, &offset); + if (!block) { + warn_once(1u << 0, "out of staging memory for BC texture uploads; textures left empty"); + return; + } + uint8_t *out = block->data + offset; + const uint8_t *in = source + region->offset; + uint8_t texels[16 * 8]; + for (uint32_t s = 0; s < slices; s++) { + for (uint32_t by = 0; by < (height + 3) / 4; by++) { + for (uint32_t bx = 0; bx < (width + 3) / 4; bx++) { + decode_block(bc, in + s * source_slice + by * source_row + (size_t)bx * bc->block_bytes, texels); + for (uint32_t y = 0; y < 4 && by * 4 + y < height; y++) { + uint32_t columns = width - bx * 4 < 4 ? width - bx * 4 : 4; + memcpy(out + ((size_t)s * height + by * 4 + y) * row_bytes + (size_t)bx * 4 * bc->texel_bytes, + texels + (size_t)y * 4 * bc->texel_bytes, (size_t)columns * bc->texel_bytes); + } + } + } + } + + VkBufferImageCopy copy = { + .bufferOffset = offset, + .imageSubresource = region->subresource, + .imageOffset = region->image_offset, + .imageExtent = region->extent, + }; + copy.imageSubresource.layerCount = layers; + dev->CmdCopyBufferToImage(cmd, block->buffer, dst, layout, 1, ©); +} + +VKAPI_ATTR void VKAPI_CALL CmdCopyBufferToImage(VkCommandBuffer cmd, VkBuffer buffer, VkImage image, + VkImageLayout layout, uint32_t count, + const VkBufferImageCopy *regions) +{ + struct device *dev = device_from_handle(cmd); + const struct bc_image *tracked = tracked_image(dev, image); + if (!tracked) { + dev->CmdCopyBufferToImage(cmd, buffer, image, layout, count, regions); + return; + } + const uint8_t *source = mapped_buffer(dev, buffer); + if (!source) { + warn_once(1u << 1, "BC texture upload from memory that is not mapped; texture left empty"); + return; + } + for (uint32_t i = 0; i < count; i++) { + struct upload region = {regions[i].bufferOffset, regions[i].bufferRowLength, regions[i].bufferImageHeight, + regions[i].imageSubresource, regions[i].imageOffset, regions[i].imageExtent}; + upload_region(dev, cmd, tracked, source, image, layout, ®ion); + } +} + +VKAPI_ATTR void VKAPI_CALL CmdCopyBufferToImage2(VkCommandBuffer cmd, const VkCopyBufferToImageInfo2 *info) +{ + struct device *dev = device_from_handle(cmd); + const struct bc_image *tracked = tracked_image(dev, info->dstImage); + if (!tracked) { + dev->CmdCopyBufferToImage2(cmd, info); + return; + } + const uint8_t *source = mapped_buffer(dev, info->srcBuffer); + if (!source) { + warn_once(1u << 1, "BC texture upload from memory that is not mapped; texture left empty"); + return; + } + for (uint32_t i = 0; i < info->regionCount; i++) { + const VkBufferImageCopy2 *r = &info->pRegions[i]; + struct upload region = {r->bufferOffset, r->bufferRowLength, r->bufferImageHeight, + r->imageSubresource, r->imageOffset, r->imageExtent}; + upload_region(dev, cmd, tracked, source, info->dstImage, info->dstImageLayout, ®ion); + } +} + +/* Reading compressed blocks back would hand out decoded texels the buffer has no room for. */ +VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer(VkCommandBuffer cmd, VkImage image, VkImageLayout layout, + VkBuffer buffer, uint32_t count, const VkBufferImageCopy *regions) +{ + struct device *dev = device_from_handle(cmd); + if (tracked_image(dev, image)) { + warn_once(1u << 2, "BC texture read back into a buffer; skipped"); + return; + } + dev->CmdCopyImageToBuffer(cmd, image, layout, buffer, count, regions); +} + +VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer2(VkCommandBuffer cmd, const VkCopyImageToBufferInfo2 *info) +{ + struct device *dev = device_from_handle(cmd); + if (tracked_image(dev, info->srcImage)) { + warn_once(1u << 2, "BC texture read back into a buffer; skipped"); + return; + } + dev->CmdCopyImageToBuffer2(cmd, info); +} + +/* Between two BC images the texels line up; between BC and anything else they cannot. */ +VKAPI_ATTR void VKAPI_CALL CmdCopyImage(VkCommandBuffer cmd, VkImage src, VkImageLayout src_layout, VkImage dst, + VkImageLayout dst_layout, uint32_t count, const VkImageCopy *regions) +{ + struct device *dev = device_from_handle(cmd); + if (!tracked_image(dev, src) != !tracked_image(dev, dst)) { + warn_once(1u << 3, "copy between a BC texture and an uncompressed one; skipped"); + return; + } + dev->CmdCopyImage(cmd, src, src_layout, dst, dst_layout, count, regions); +} + +VKAPI_ATTR void VKAPI_CALL CmdCopyImage2(VkCommandBuffer cmd, const VkCopyImageInfo2 *info) +{ + struct device *dev = device_from_handle(cmd); + if (!tracked_image(dev, info->srcImage) != !tracked_image(dev, info->dstImage)) { + warn_once(1u << 3, "copy between a BC texture and an uncompressed one; skipped"); + return; + } + dev->CmdCopyImage2(cmd, info); +} + +VKAPI_ATTR VkResult VKAPI_CALL AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *info, + VkCommandBuffer *buffers) +{ + struct device *dev = device_from_handle(device); + VkResult result = dev->AllocateCommandBuffers(device, info, buffers); + if (result != VK_SUCCESS) + return result; + pthread_mutex_lock(&dev->lock); + for (uint32_t i = 0; i < info->commandBufferCount; i++) { + struct command_buffer *state = calloc(1, sizeof(*state)); + state->pool = info->commandPool; + map_put(&dev->command_buffers, HANDLE(buffers[i]), state); + } + pthread_mutex_unlock(&dev->lock); + return result; +} + +VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool pool, uint32_t count, + const VkCommandBuffer *buffers) +{ + struct device *dev = device_from_handle(device); + pthread_mutex_lock(&dev->lock); + for (uint32_t i = 0; i < count; i++) { + struct command_buffer *state = buffers[i] ? map_remove(&dev->command_buffers, HANDLE(buffers[i])) : NULL; + if (state) { + recycle_staging(dev, state); + free(state); + } + } + pthread_mutex_unlock(&dev->lock); + dev->FreeCommandBuffers(device, pool, count, buffers); +} + +static void recycle_command_buffer(struct device *dev, VkCommandBuffer cmd) +{ + pthread_mutex_lock(&dev->lock); + struct command_buffer *state = map_get(&dev->command_buffers, HANDLE(cmd)); + if (state) + recycle_staging(dev, state); + pthread_mutex_unlock(&dev->lock); +} + +VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer cmd, const VkCommandBufferBeginInfo *info) +{ + struct device *dev = device_from_handle(cmd); + recycle_command_buffer(dev, cmd); + return dev->BeginCommandBuffer(cmd, info); +} + +VKAPI_ATTR VkResult VKAPI_CALL ResetCommandBuffer(VkCommandBuffer cmd, VkCommandBufferResetFlags flags) +{ + struct device *dev = device_from_handle(cmd); + recycle_command_buffer(dev, cmd); + return dev->ResetCommandBuffer(cmd, flags); +} + +/* Every command buffer of the pool is done with its staging; `forget` drops them as well. */ +static void recycle_pool(struct device *dev, VkCommandPool pool, bool forget) +{ + pthread_mutex_lock(&dev->lock); + struct handle_map *map = &dev->command_buffers; + for (uint32_t i = 0; i < map->capacity;) { + struct command_buffer *state = map->values[i]; + if (!map->keys[i] || state->pool != pool) { + i++; + continue; + } + recycle_staging(dev, state); + if (forget) { + /* Removal shifts a later entry into this slot, so look at it again. */ + free(map_remove(map, map->keys[i])); + continue; + } + i++; + } + pthread_mutex_unlock(&dev->lock); +} + +VKAPI_ATTR VkResult VKAPI_CALL ResetCommandPool(VkDevice device, VkCommandPool pool, VkCommandPoolResetFlags flags) +{ + struct device *dev = device_from_handle(device); + recycle_pool(dev, pool, false); + return dev->ResetCommandPool(device, pool, flags); +} + +VKAPI_ATTR void VKAPI_CALL DestroyCommandPool(VkDevice device, VkCommandPool pool, + const VkAllocationCallbacks *allocator) +{ + struct device *dev = device_from_handle(device); + recycle_pool(dev, pool, true); + dev->DestroyCommandPool(device, pool, allocator); +} + +void bc_destroy_device(struct device *dev) +{ + struct handle_map *maps[] = {&dev->images, &dev->buffers, &dev->command_buffers}; + for (size_t m = 0; m < sizeof(maps) / sizeof(maps[0]); m++) { + for (uint32_t i = 0; i < maps[m]->capacity; i++) { + if (!maps[m]->keys[i]) + continue; + if (maps[m] == &dev->command_buffers) + recycle_staging(dev, maps[m]->values[i]); + free(maps[m]->values[i]); + } + map_free(maps[m]); + } + map_free(&dev->memories); + while (dev->free_staging) { + struct staging_block *block = dev->free_staging; + dev->free_staging = block->next; + destroy_block(dev, block); + } +} diff --git a/tools/venus/layer/draw.c b/tools/venus/layer/draw.c new file mode 100644 index 0000000000..f3621355b2 --- /dev/null +++ b/tools/venus/layer/draw.c @@ -0,0 +1,452 @@ +/* + * The Mali compatibility layer's draw and descriptor emulation (added to David Cimo's layer): + * + * - multiDrawIndirect: an indirect draw with drawCount > 1 is recorded as drawCount single draws + * at offset + i * stride. Mali-G57 (Bifrost/Valhall v9) has none, and DXVK refuses the device. + * - robustness2's nullDescriptor: VK_NULL_HANDLE buffers, image views and vertex buffers in + * descriptor writes (plain, template and push) and vertex-buffer binds are replaced with small + * stand-ins the layer owns. robustBufferAccess2 itself maps to robustBufferAccess (layer.c). + * A null texel-buffer view gets an RGBA8 (uniform) or R32_UINT (storage) view of the stand-in + * buffer: its format is not known here, but Zink leaves them unbound and never reads them. + */ +#include <stdlib.h> +#include <string.h> + +#include "mali_compat.h" + +/* --- multiDrawIndirect --- */ + +VKAPI_ATTR void VKAPI_CALL CmdDrawIndirect(VkCommandBuffer cmd, VkBuffer buffer, VkDeviceSize offset, + uint32_t draw_count, uint32_t stride) +{ + struct device *dev = device_from_handle(cmd); + if (draw_count <= 1) { + dev->CmdDrawIndirect(cmd, buffer, offset, draw_count, stride); + return; + } + for (uint32_t i = 0; i < draw_count; i++) + dev->CmdDrawIndirect(cmd, buffer, offset + (VkDeviceSize)i * stride, 1, stride); +} + +VKAPI_ATTR void VKAPI_CALL CmdDrawIndexedIndirect(VkCommandBuffer cmd, VkBuffer buffer, VkDeviceSize offset, + uint32_t draw_count, uint32_t stride) +{ + struct device *dev = device_from_handle(cmd); + if (draw_count <= 1) { + dev->CmdDrawIndexedIndirect(cmd, buffer, offset, draw_count, stride); + return; + } + for (uint32_t i = 0; i < draw_count; i++) + dev->CmdDrawIndexedIndirect(cmd, buffer, offset + (VkDeviceSize)i * stride, 1, stride); +} + +/* --- nullDescriptor stand-ins --- */ + +/* A template's entries, to find the null handles in the data it is given. */ +struct template_info { + uint32_t count; + VkDescriptorUpdateTemplateEntry *entries; + size_t size; /* bytes the data spans */ +}; + +#define NULL_BUFFER_SIZE 65536 + +static uint32_t memory_type(const struct device *dev, uint32_t bits, VkMemoryPropertyFlags want) +{ + for (uint32_t i = 0; i < dev->memory_properties.memoryTypeCount; i++) + if ((bits & (1u << i)) && (dev->memory_properties.memoryTypes[i].propertyFlags & want) == want) + return i; + for (uint32_t i = 0; i < dev->memory_properties.memoryTypeCount; i++) + if (bits & (1u << i)) + return i; + return 0; +} + +/* Made once per device, under its lock, the first time a null descriptor is seen. */ +static bool null_resources(struct device *dev) +{ + if (dev->null_ready) + return dev->null_ready > 0; + dev->null_ready = -1; + + VkBufferCreateInfo binfo = { + .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, + .size = NULL_BUFFER_SIZE, + .usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | + VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | + VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, + }; + if (dev->CreateBuffer(dev->handle, &binfo, NULL, &dev->null_buffer) != VK_SUCCESS) + return false; + VkMemoryRequirements breq; + dev->GetBufferMemoryRequirements(dev->handle, dev->null_buffer, &breq); + VkMemoryAllocateInfo balloc = { + .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .allocationSize = breq.size, + .memoryTypeIndex = memory_type(dev, breq.memoryTypeBits, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), + }; + if (dev->AllocateMemory(dev->handle, &balloc, NULL, &dev->null_buffer_memory) != VK_SUCCESS) + return false; + dev->BindBufferMemory(dev->handle, dev->null_buffer, dev->null_buffer_memory, 0); + /* A null buffer reads as zeros. */ + void *data = NULL; + if ((dev->memory_properties.memoryTypes[balloc.memoryTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) && + dev->MapMemory(dev->handle, dev->null_buffer_memory, 0, VK_WHOLE_SIZE, 0, &data) == VK_SUCCESS) { + memset(data, 0, (size_t)breq.size); + dev->UnmapMemory(dev->handle, dev->null_buffer_memory); + } + + VkImageCreateInfo iinfo = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, + .imageType = VK_IMAGE_TYPE_2D, + .format = VK_FORMAT_R8G8B8A8_UNORM, + .extent = {1, 1, 1}, + .mipLevels = 1, + .arrayLayers = 1, + .samples = VK_SAMPLE_COUNT_1_BIT, + .tiling = VK_IMAGE_TILING_OPTIMAL, + .usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, + .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, + }; + if (dev->CreateImage(dev->handle, &iinfo, NULL, &dev->null_image) != VK_SUCCESS) + return false; + VkMemoryRequirements ireq; + dev->GetImageMemoryRequirements(dev->handle, dev->null_image, &ireq); + VkMemoryAllocateInfo ialloc = { + .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .allocationSize = ireq.size, + .memoryTypeIndex = memory_type(dev, ireq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), + }; + if (dev->AllocateMemory(dev->handle, &ialloc, NULL, &dev->null_image_memory) != VK_SUCCESS) + return false; + dev->BindImageMemory(dev->handle, dev->null_image, dev->null_image_memory, 0); + VkImageViewCreateInfo vinfo = { + .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, + .image = dev->null_image, + .viewType = VK_IMAGE_VIEW_TYPE_2D, + .format = VK_FORMAT_R8G8B8A8_UNORM, + .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}, + }; + if (dev->CreateImageView(dev->handle, &vinfo, NULL, &dev->null_view) != VK_SUCCESS) + return false; + /* Texel views are optional: a write that needs one and has none keeps its null. */ + VkBufferViewCreateInfo tinfo = { + .sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, + .buffer = dev->null_buffer, + .format = VK_FORMAT_R8G8B8A8_UNORM, + .range = VK_WHOLE_SIZE, + }; + if (dev->CreateBufferView(dev->handle, &tinfo, NULL, &dev->null_uniform_texel) != VK_SUCCESS) + dev->null_uniform_texel = VK_NULL_HANDLE; + tinfo.format = VK_FORMAT_R32_UINT; + if (dev->CreateBufferView(dev->handle, &tinfo, NULL, &dev->null_storage_texel) != VK_SUCCESS) + dev->null_storage_texel = VK_NULL_HANDLE; + dev->null_ready = 1; + layer_log("nullDescriptor: stand-in buffer and 1x1 image ready"); + return true; +} + +void null_resources_destroy(struct device *dev) +{ + for (uint32_t i = 0; i < dev->templates.capacity; i++) { + struct template_info *t = dev->templates.values ? dev->templates.values[i] : NULL; + if (t) { + free(t->entries); + free(t); + } + } + map_free(&dev->templates); + if (dev->null_uniform_texel) dev->DestroyBufferView(dev->handle, dev->null_uniform_texel, NULL); + if (dev->null_storage_texel) dev->DestroyBufferView(dev->handle, dev->null_storage_texel, NULL); + if (dev->null_view) dev->DestroyImageView(dev->handle, dev->null_view, NULL); + if (dev->null_image) dev->DestroyImage(dev->handle, dev->null_image, NULL); + if (dev->null_image_memory) dev->FreeMemory(dev->handle, dev->null_image_memory, NULL); + if (dev->null_buffer) dev->DestroyBuffer(dev->handle, dev->null_buffer, NULL); + if (dev->null_buffer_memory) dev->FreeMemory(dev->handle, dev->null_buffer_memory, NULL); +} + +static bool is_buffer_type(VkDescriptorType t) +{ + return t == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || t == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER || + t == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || t == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; +} + +static bool is_image_type(VkDescriptorType t) +{ + return t == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE || t == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE || + t == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER || t == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; +} + +static bool is_texel_type(VkDescriptorType t) +{ + return t == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER || t == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; +} + +static void fix_texel(struct device *dev, VkDescriptorType t, VkBufferView *view) +{ + if (*view != VK_NULL_HANDLE || !null_resources(dev)) + return; + *view = t == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER ? dev->null_storage_texel : dev->null_uniform_texel; +} + +static void fix_buffer(struct device *dev, VkDescriptorBufferInfo *info) +{ + if (info->buffer != VK_NULL_HANDLE || !null_resources(dev)) + return; + info->buffer = dev->null_buffer; + info->offset = 0; + info->range = VK_WHOLE_SIZE; +} + +static void fix_image(struct device *dev, VkDescriptorImageInfo *info) +{ + if (info->imageView != VK_NULL_HANDLE || !null_resources(dev)) + return; + info->imageView = dev->null_view; +} + +/* Copies of the writes with stand-ins for null handles; NULL when nothing needed changing. */ +static VkWriteDescriptorSet *fix_writes(struct device *dev, uint32_t count, const VkWriteDescriptorSet *writes, + void ***scratch, uint32_t *scratch_count) +{ + VkWriteDescriptorSet *copies = NULL; + for (uint32_t i = 0; i < count; i++) { + const VkWriteDescriptorSet *w = &writes[i]; + bool null_found = false; + for (uint32_t j = 0; j < w->descriptorCount && !null_found; j++) { + if (is_buffer_type(w->descriptorType) && w->pBufferInfo && w->pBufferInfo[j].buffer == VK_NULL_HANDLE) + null_found = true; + if (is_image_type(w->descriptorType) && w->pImageInfo && w->pImageInfo[j].imageView == VK_NULL_HANDLE && + w->descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) + null_found = true; + if (is_texel_type(w->descriptorType) && w->pTexelBufferView && w->pTexelBufferView[j] == VK_NULL_HANDLE) + null_found = true; + } + if (!null_found) + continue; + if (!copies) { + copies = malloc(count * sizeof(*copies)); + memcpy(copies, writes, count * sizeof(*copies)); + *scratch = calloc(count, sizeof(void *)); + } + if (is_buffer_type(w->descriptorType)) { + VkDescriptorBufferInfo *b = malloc(w->descriptorCount * sizeof(*b)); + memcpy(b, w->pBufferInfo, w->descriptorCount * sizeof(*b)); + for (uint32_t j = 0; j < w->descriptorCount; j++) + fix_buffer(dev, &b[j]); + copies[i].pBufferInfo = b; + (*scratch)[(*scratch_count)++] = b; + } else if (is_texel_type(w->descriptorType)) { + VkBufferView *v = malloc(w->descriptorCount * sizeof(*v)); + memcpy(v, w->pTexelBufferView, w->descriptorCount * sizeof(*v)); + for (uint32_t j = 0; j < w->descriptorCount; j++) + fix_texel(dev, w->descriptorType, &v[j]); + copies[i].pTexelBufferView = v; + (*scratch)[(*scratch_count)++] = v; + } else { + VkDescriptorImageInfo *im = malloc(w->descriptorCount * sizeof(*im)); + memcpy(im, w->pImageInfo, w->descriptorCount * sizeof(*im)); + for (uint32_t j = 0; j < w->descriptorCount; j++) + fix_image(dev, &im[j]); + copies[i].pImageInfo = im; + (*scratch)[(*scratch_count)++] = im; + } + } + return copies; +} + +static void free_scratch(void **scratch, uint32_t count) +{ + for (uint32_t i = 0; i < count; i++) + free(scratch[i]); + free(scratch); +} + +VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t write_count, const VkWriteDescriptorSet *writes, + uint32_t copy_count, const VkCopyDescriptorSet *copies) +{ + struct device *dev = device_from_handle(device); + pthread_mutex_lock(&dev->lock); + void **scratch = NULL; + uint32_t scratch_count = 0; + VkWriteDescriptorSet *fixed = fix_writes(dev, write_count, writes, &scratch, &scratch_count); + pthread_mutex_unlock(&dev->lock); + dev->UpdateDescriptorSets(device, write_count, fixed ? fixed : writes, copy_count, copies); + free(fixed); + free_scratch(scratch, scratch_count); +} + +VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSet(VkCommandBuffer cmd, VkPipelineBindPoint bind_point, + VkPipelineLayout layout, uint32_t set, uint32_t write_count, + const VkWriteDescriptorSet *writes) +{ + struct device *dev = device_from_handle(cmd); + pthread_mutex_lock(&dev->lock); + void **scratch = NULL; + uint32_t scratch_count = 0; + VkWriteDescriptorSet *fixed = fix_writes(dev, write_count, writes, &scratch, &scratch_count); + pthread_mutex_unlock(&dev->lock); + dev->CmdPushDescriptorSet(cmd, bind_point, layout, set, write_count, fixed ? fixed : writes); + free(fixed); + free_scratch(scratch, scratch_count); +} + +static size_t entry_size(VkDescriptorType t) +{ + if (is_buffer_type(t)) + return sizeof(VkDescriptorBufferInfo); + if (is_image_type(t) || t == VK_DESCRIPTOR_TYPE_SAMPLER) + return sizeof(VkDescriptorImageInfo); + if (t == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK) + return 1; + return sizeof(uint64_t); +} + +VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorUpdateTemplate(VkDevice device, + const VkDescriptorUpdateTemplateCreateInfo *info, + const VkAllocationCallbacks *allocator, + VkDescriptorUpdateTemplate *tmpl) +{ + struct device *dev = device_from_handle(device); + VkResult result = dev->CreateDescriptorUpdateTemplate(device, info, allocator, tmpl); + if (result != VK_SUCCESS) + return result; + struct template_info *t = calloc(1, sizeof(*t)); + t->count = info->descriptorUpdateEntryCount; + t->entries = malloc(t->count * sizeof(*t->entries)); + memcpy(t->entries, info->pDescriptorUpdateEntries, t->count * sizeof(*t->entries)); + for (uint32_t i = 0; i < t->count; i++) { + const VkDescriptorUpdateTemplateEntry *e = &t->entries[i]; + size_t end = e->descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK + ? e->offset + e->descriptorCount + : e->offset + (e->descriptorCount ? (e->descriptorCount - 1) * e->stride : 0) + entry_size(e->descriptorType); + if (end > t->size) + t->size = end; + } + pthread_mutex_lock(&dev->lock); + map_put(&dev->templates, (uint64_t)*tmpl, t); + pthread_mutex_unlock(&dev->lock); + return VK_SUCCESS; +} + +VKAPI_ATTR void VKAPI_CALL DestroyDescriptorUpdateTemplate(VkDevice device, VkDescriptorUpdateTemplate tmpl, + const VkAllocationCallbacks *allocator) +{ + struct device *dev = device_from_handle(device); + pthread_mutex_lock(&dev->lock); + struct template_info *t = map_remove(&dev->templates, (uint64_t)tmpl); + pthread_mutex_unlock(&dev->lock); + if (t) { + free(t->entries); + free(t); + } + dev->DestroyDescriptorUpdateTemplate(device, tmpl, allocator); +} + +/* A copy of the template's data with stand-ins for null handles; NULL when nothing changed. */ +static void *fix_template_data(struct device *dev, VkDescriptorUpdateTemplate tmpl, const void *data) +{ + pthread_mutex_lock(&dev->lock); + struct template_info *t = map_get(&dev->templates, (uint64_t)tmpl); + void *copy = NULL; + if (t && data) { + for (uint32_t i = 0; i < t->count; i++) { + const VkDescriptorUpdateTemplateEntry *e = &t->entries[i]; + bool buffer = is_buffer_type(e->descriptorType); + bool image = is_image_type(e->descriptorType); + bool texel = is_texel_type(e->descriptorType); + if (!buffer && !image && !texel) + continue; + for (uint32_t j = 0; j < e->descriptorCount; j++) { + size_t at = e->offset + (size_t)j * e->stride; + const char *src = (const char *)(copy ? copy : data) + at; + bool null_handle = buffer ? ((const VkDescriptorBufferInfo *)src)->buffer == VK_NULL_HANDLE + : texel ? *(const VkBufferView *)src == VK_NULL_HANDLE + : ((const VkDescriptorImageInfo *)src)->imageView == VK_NULL_HANDLE; + if (!null_handle) + continue; + if (!copy) { + copy = malloc(t->size); + memcpy(copy, data, t->size); + } + if (buffer) + fix_buffer(dev, (VkDescriptorBufferInfo *)((char *)copy + at)); + else if (texel) + fix_texel(dev, e->descriptorType, (VkBufferView *)((char *)copy + at)); + else + fix_image(dev, (VkDescriptorImageInfo *)((char *)copy + at)); + } + } + } + pthread_mutex_unlock(&dev->lock); + return copy; +} + +VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet set, + VkDescriptorUpdateTemplate tmpl, const void *data) +{ + struct device *dev = device_from_handle(device); + void *fixed = fix_template_data(dev, tmpl, data); + dev->UpdateDescriptorSetWithTemplate(device, set, tmpl, fixed ? fixed : data); + free(fixed); +} + +VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetWithTemplate(VkCommandBuffer cmd, VkDescriptorUpdateTemplate tmpl, + VkPipelineLayout layout, uint32_t set, const void *data) +{ + struct device *dev = device_from_handle(cmd); + void *fixed = fix_template_data(dev, tmpl, data); + dev->CmdPushDescriptorSetWithTemplate(cmd, tmpl, layout, set, fixed ? fixed : data); + free(fixed); +} + +/* Null vertex buffers read as zeros: bound to the stand-in at offset 0. */ +VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers(VkCommandBuffer cmd, uint32_t first, uint32_t count, + const VkBuffer *buffers, const VkDeviceSize *offsets) +{ + struct device *dev = device_from_handle(cmd); + VkBuffer fixed[64]; + VkDeviceSize fixed_offsets[64]; + bool any = false; + for (uint32_t i = 0; i < count && i < 64; i++) any |= buffers[i] == VK_NULL_HANDLE; + if (!any || count > 64) { + dev->CmdBindVertexBuffers(cmd, first, count, buffers, offsets); + return; + } + pthread_mutex_lock(&dev->lock); + bool ready = null_resources(dev); + pthread_mutex_unlock(&dev->lock); + for (uint32_t i = 0; i < count; i++) { + fixed[i] = buffers[i] == VK_NULL_HANDLE && ready ? dev->null_buffer : buffers[i]; + fixed_offsets[i] = buffers[i] == VK_NULL_HANDLE ? 0 : offsets[i]; + } + dev->CmdBindVertexBuffers(cmd, first, count, fixed, fixed_offsets); +} + +VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers2(VkCommandBuffer cmd, uint32_t first, uint32_t count, + const VkBuffer *buffers, const VkDeviceSize *offsets, + const VkDeviceSize *sizes, const VkDeviceSize *strides) +{ + struct device *dev = device_from_handle(cmd); + VkBuffer fixed[64]; + VkDeviceSize fixed_offsets[64], fixed_sizes[64]; + bool any = false; + for (uint32_t i = 0; i < count && i < 64; i++) any |= buffers[i] == VK_NULL_HANDLE; + if (!any || count > 64) { + dev->CmdBindVertexBuffers2(cmd, first, count, buffers, offsets, sizes, strides); + return; + } + pthread_mutex_lock(&dev->lock); + bool ready = null_resources(dev); + pthread_mutex_unlock(&dev->lock); + for (uint32_t i = 0; i < count; i++) { + bool null_buffer = buffers[i] == VK_NULL_HANDLE; + fixed[i] = null_buffer && ready ? dev->null_buffer : buffers[i]; + fixed_offsets[i] = null_buffer ? 0 : offsets[i]; + fixed_sizes[i] = sizes ? (null_buffer ? NULL_BUFFER_SIZE : sizes[i]) : 0; + } + dev->CmdBindVertexBuffers2(cmd, first, count, fixed, fixed_offsets, sizes ? fixed_sizes : NULL, strides); +} diff --git a/tools/venus/layer/layer.c b/tools/venus/layer/layer.c new file mode 100644 index 0000000000..4df8a54ad1 --- /dev/null +++ b/tools/venus/layer/layer.c @@ -0,0 +1,812 @@ +#define _GNU_SOURCE +#include "mali_compat.h" + +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define LAYER_NAME "VK_LAYER_DROIDDECK_mali_compat" + +static pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER; +static struct instance *instances; +static struct device *devices; + +void layer_log(const char *format, ...) +{ + char line[512]; + va_list args; + va_start(args, format); + vsnprintf(line, sizeof(line), format, args); + va_end(args); + fprintf(stderr, "droiddeck-mali-compat: %s\n", line); +} + +/* The loader's dispatch table pointer: shared by an instance and its physical devices, and by a + * device and its queues and command buffers. */ +static void *dispatch_key(const void *dispatchable) +{ + return *(void *const *)dispatchable; +} + +struct instance *instance_from_handle(const void *dispatchable) +{ + void *key = dispatch_key(dispatchable); + pthread_mutex_lock(&global_lock); + struct instance *inst = instances; + while (inst && inst->key != key) + inst = inst->next; + pthread_mutex_unlock(&global_lock); + return inst; +} + +struct device *device_from_handle(const void *dispatchable) +{ + void *key = dispatch_key(dispatchable); + pthread_mutex_lock(&global_lock); + struct device *dev = devices; + while (dev && dev->key != key) + dev = dev->next; + pthread_mutex_unlock(&global_lock); + return dev; +} + +static uint64_t hash(uint64_t key) +{ + key ^= key >> 33; + key *= 0xff51afd7ed558ccdull; + key ^= key >> 33; + return key; +} + +void *map_get(const struct handle_map *map, uint64_t key) +{ + if (!map->capacity) + return NULL; + for (uint32_t i = hash(key) & (map->capacity - 1);; i = (i + 1) & (map->capacity - 1)) { + if (map->keys[i] == key) + return map->values[i]; + if (!map->keys[i]) + return NULL; + } +} + +static void map_grow(struct handle_map *map) +{ + struct handle_map bigger = { + .capacity = map->capacity ? map->capacity * 2 : 64, + }; + bigger.keys = calloc(bigger.capacity, sizeof(*bigger.keys)); + bigger.values = calloc(bigger.capacity, sizeof(*bigger.values)); + for (uint32_t i = 0; i < map->capacity; i++) { + if (map->keys[i]) + map_put(&bigger, map->keys[i], map->values[i]); + } + free(map->keys); + free(map->values); + *map = bigger; +} + +void map_put(struct handle_map *map, uint64_t key, void *value) +{ + if ((map->count + 1) * 4 > map->capacity * 3) + map_grow(map); + uint32_t i = hash(key) & (map->capacity - 1); + while (map->keys[i] && map->keys[i] != key) + i = (i + 1) & (map->capacity - 1); + if (!map->keys[i]) + map->count++; + map->keys[i] = key; + map->values[i] = value; +} + +void *map_remove(struct handle_map *map, uint64_t key) +{ + if (!map->capacity) + return NULL; + uint32_t mask = map->capacity - 1; + uint32_t i = hash(key) & mask; + while (map->keys[i] != key) { + if (!map->keys[i]) + return NULL; + i = (i + 1) & mask; + } + void *value = map->values[i]; + map->count--; + /* Backward-shift deletion keeps every remaining key reachable from its home slot. */ + for (uint32_t j = (i + 1) & mask; map->keys[j]; j = (j + 1) & mask) { + uint32_t home = hash(map->keys[j]) & mask; + if (((j - home) & mask) >= ((j - i) & mask)) { + map->keys[i] = map->keys[j]; + map->values[i] = map->values[j]; + i = j; + } + } + map->keys[i] = 0; + map->values[i] = NULL; + return value; +} + +void map_free(struct handle_map *map) +{ + free(map->keys); + free(map->values); + *map = (struct handle_map){0}; +} + +/* Wine processes by default. DROIDDECK_MALI_COMPAT=1 (the app's Venus route) turns it on everywhere + * but gamescope, so Zink in the Steam client and Xwayland gets robustness2's nullDescriptor, which it + * requires; gamescope runs fine on the driver's own features. =all includes gamescope too. */ +static bool wanted(void) +{ + const char *setting = getenv("DROIDDECK_MALI_COMPAT"); + if (setting) { + if (strcmp(setting, "0") == 0) + return false; + if (strcmp(setting, "all") == 0) + return true; + return strcmp(program_invocation_short_name, "gamescope") != 0; + } + return getenv("WINEPREFIX") != NULL; +} + +/* DROIDDECK_MALI_COMPAT_TRACE=1: what an application asks before it creates a device (Zink on a + * Mali-G615 through Venus gave up before vkCreateDevice without a word). */ +static bool tracing(void) +{ + static int on = -1; + if (on < 0) { + const char *v = getenv("DROIDDECK_MALI_COMPAT_TRACE"); + on = v && *v && strcmp(v, "0") != 0; + } + return on; +} + +static bool has_extension(struct instance *inst, VkPhysicalDevice physical_device, const char *name) +{ + uint32_t count = 0; + inst->EnumerateDeviceExtensionProperties(physical_device, NULL, &count, NULL); + VkExtensionProperties *extensions = calloc(count, sizeof(*extensions)); + inst->EnumerateDeviceExtensionProperties(physical_device, NULL, &count, extensions); + bool found = false; + for (uint32_t i = 0; i < count && !found; i++) + found = strcmp(extensions[i].extensionName, name) == 0; + free(extensions); + return found; +} + +uint32_t physical_device_gaps(struct instance *inst, VkPhysicalDevice physical_device) +{ + pthread_mutex_lock(&inst->lock); + for (uint32_t i = 0; i < inst->physical_device_count; i++) { + if (inst->physical_devices[i].handle == physical_device) { + uint32_t gaps = inst->physical_devices[i].gaps; + pthread_mutex_unlock(&inst->lock); + return gaps; + } + } + pthread_mutex_unlock(&inst->lock); + + bool robustness2 = has_extension(inst, physical_device, "VK_EXT_robustness2"); + VkPhysicalDeviceRobustness2FeaturesEXT robust = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT, + }; + VkPhysicalDeviceFeatures2 features = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, + .pNext = robustness2 ? &robust : NULL, + }; + inst->GetPhysicalDeviceFeatures2(physical_device, &features); + uint32_t gaps = 0; + if (!features.features.fillModeNonSolid) + gaps |= GAP_FILL_MODE; + if (!features.features.multiViewport) + gaps |= GAP_MULTI_VIEWPORT; + if (!features.features.shaderClipDistance) + gaps |= GAP_CLIP_DISTANCE; + if (!features.features.shaderCullDistance) + gaps |= GAP_CULL_DISTANCE; + if (!features.features.textureCompressionBC) + gaps |= GAP_BC; + if (robustness2 && !robust.robustBufferAccess2) + gaps |= GAP_ROBUSTNESS2; + if (!features.features.multiDrawIndirect) + gaps |= GAP_MULTI_DRAW; + if (!has_extension(inst, physical_device, VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME)) + gaps |= GAP_DEPTH_CLIP; + /* No robustness2 at all: the extension is offered with robustBufferAccess2 (as robustBufferAccess) + * and nullDescriptor (stand-ins, draw.c). */ + if (!robustness2) + gaps |= GAP_ROBUSTNESS2 | GAP_NULL_DESCRIPTOR; + + pthread_mutex_lock(&inst->lock); + if (inst->physical_device_count < sizeof(inst->physical_devices) / sizeof(inst->physical_devices[0])) { + inst->physical_devices[inst->physical_device_count++] = + (struct physical_device){.handle = physical_device, .gaps = gaps}; + } + pthread_mutex_unlock(&inst->lock); + return gaps; +} + +/* Structures of extensions the driver does not have are taken out of a chain for the call down and + * put back after it: the driver (and Venus) must not see them. */ +struct unlinked { + VkBaseOutStructure *prev, *node; +}; + +static uint32_t unlink_types(void *head, const VkStructureType *types, uint32_t type_count, + struct unlinked *out, uint32_t max) +{ + uint32_t n = 0; + VkBaseOutStructure *prev = head; + while (prev && prev->pNext && n < max) { + VkBaseOutStructure *s = prev->pNext; + bool drop = false; + for (uint32_t i = 0; i < type_count; i++) + drop |= s->sType == types[i]; + if (drop) { + out[n++] = (struct unlinked){prev, s}; + prev->pNext = s->pNext; + } else { + prev = s; + } + } + return n; +} + +static void relink(struct unlinked *list, uint32_t n) +{ + while (n--) + list[n].prev->pNext = list[n].node; +} + +static uint32_t foreign_types(uint32_t gaps, VkStructureType *types) +{ + uint32_t n = 0; + if (gaps & GAP_DEPTH_CLIP) + types[n++] = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT; + if (gaps & GAP_NULL_DESCRIPTOR) + types[n++] = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT; + return n; +} + +static void report_features(VkPhysicalDeviceFeatures *features, uint32_t gaps) +{ + if (gaps & GAP_FILL_MODE) + features->fillModeNonSolid = VK_TRUE; + if (gaps & GAP_MULTI_VIEWPORT) + features->multiViewport = VK_TRUE; + if (gaps & GAP_CLIP_DISTANCE) + features->shaderClipDistance = VK_TRUE; + if (gaps & GAP_CULL_DISTANCE) + features->shaderCullDistance = VK_TRUE; + if (gaps & GAP_BC) + features->textureCompressionBC = VK_TRUE; + if (gaps & GAP_MULTI_DRAW) + features->multiDrawIndirect = VK_TRUE; +} + +/* Which made-up features the application asked for, and off with them before the driver sees them. */ +static uint32_t take_features(VkPhysicalDeviceFeatures *features, uint32_t gaps) +{ + uint32_t requested = 0; + if ((gaps & GAP_FILL_MODE) && features->fillModeNonSolid) { + requested |= GAP_FILL_MODE; + features->fillModeNonSolid = VK_FALSE; + } + if ((gaps & GAP_MULTI_VIEWPORT) && features->multiViewport) { + requested |= GAP_MULTI_VIEWPORT; + features->multiViewport = VK_FALSE; + } + if ((gaps & GAP_CLIP_DISTANCE) && features->shaderClipDistance) { + requested |= GAP_CLIP_DISTANCE; + features->shaderClipDistance = VK_FALSE; + } + if ((gaps & GAP_CULL_DISTANCE) && features->shaderCullDistance) { + requested |= GAP_CULL_DISTANCE; + features->shaderCullDistance = VK_FALSE; + } + if ((gaps & GAP_BC) && features->textureCompressionBC) { + requested |= GAP_BC; + features->textureCompressionBC = VK_FALSE; + } + if ((gaps & GAP_MULTI_DRAW) && features->multiDrawIndirect) { + requested |= GAP_MULTI_DRAW; + features->multiDrawIndirect = VK_FALSE; + } + return requested; +} + +static void report_limits(VkPhysicalDeviceLimits *limits, uint32_t gaps) +{ + if (gaps & GAP_MULTI_VIEWPORT) + limits->maxViewports = 16; + if ((gaps & GAP_MULTI_DRAW) && limits->maxDrawIndirectCount < (1u << 30)) + limits->maxDrawIndirectCount = 1u << 30; + if (gaps & GAPS_SHADER) { + limits->maxClipDistances = 8; + limits->maxCullDistances = 8; + limits->maxCombinedClipAndCullDistances = 8; + } +} + +static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures(VkPhysicalDevice physical_device, + VkPhysicalDeviceFeatures *features) +{ + struct instance *inst = instance_from_handle(physical_device); + inst->GetPhysicalDeviceFeatures(physical_device, features); + report_features(features, physical_device_gaps(inst, physical_device)); +} + +static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures2(VkPhysicalDevice physical_device, + VkPhysicalDeviceFeatures2 *features) +{ + struct instance *inst = instance_from_handle(physical_device); + uint32_t gaps = physical_device_gaps(inst, physical_device); + VkStructureType types[4]; + struct unlinked dropped[8]; + uint32_t dropped_count = unlink_types(features, types, foreign_types(gaps, types), dropped, 8); + inst->GetPhysicalDeviceFeatures2(physical_device, features); + relink(dropped, dropped_count); + report_features(&features->features, gaps); + if (tracing()) { + char chain[512] = ""; + size_t used = 0; + for (VkBaseOutStructure *s = features->pNext; s && used + 16 < sizeof(chain); s = s->pNext) + used += (size_t)snprintf(chain + used, sizeof(chain) - used, " %d", (int)s->sType); + layer_log("trace: vkGetPhysicalDeviceFeatures2 (gaps 0x%x, %u structures held back), chain:%s", gaps, dropped_count, chain); + } + for (VkBaseOutStructure *s = features->pNext; s; s = s->pNext) { + if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT && (gaps & GAP_ROBUSTNESS2)) { + ((VkPhysicalDeviceRobustness2FeaturesEXT *)s)->robustBufferAccess2 = VK_TRUE; + if (gaps & GAP_NULL_DESCRIPTOR) + ((VkPhysicalDeviceRobustness2FeaturesEXT *)s)->nullDescriptor = VK_TRUE; + } + if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT && (gaps & GAP_DEPTH_CLIP)) + ((VkPhysicalDeviceDepthClipEnableFeaturesEXT *)s)->depthClipEnable = VK_TRUE; + } +} + +static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties(VkPhysicalDevice physical_device, + VkPhysicalDeviceProperties *properties) +{ + struct instance *inst = instance_from_handle(physical_device); + inst->GetPhysicalDeviceProperties(physical_device, properties); + report_limits(&properties->limits, physical_device_gaps(inst, physical_device)); +} + +static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties2(VkPhysicalDevice physical_device, + VkPhysicalDeviceProperties2 *properties) +{ + struct instance *inst = instance_from_handle(physical_device); + inst->GetPhysicalDeviceProperties2(physical_device, properties); + report_limits(&properties->properties.limits, physical_device_gaps(inst, physical_device)); + if (tracing()) + layer_log("trace: vkGetPhysicalDeviceProperties2: %s, Vulkan %u.%u.%u, type %d", properties->properties.deviceName, + VK_API_VERSION_MAJOR(properties->properties.apiVersion), VK_API_VERSION_MINOR(properties->properties.apiVersion), + VK_API_VERSION_PATCH(properties->properties.apiVersion), (int)properties->properties.deviceType); +} + +/* The extensions the layer stands in for, added to the driver's list. */ +static VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device, + const char *layer_name, uint32_t *count, + VkExtensionProperties *properties) +{ + struct instance *inst = instance_from_handle(physical_device); + if (layer_name) + return inst->EnumerateDeviceExtensionProperties(physical_device, layer_name, count, properties); + uint32_t gaps = physical_device_gaps(inst, physical_device); + VkExtensionProperties extra[2]; + uint32_t extra_count = 0; + if (gaps & GAP_DEPTH_CLIP) + extra[extra_count++] = (VkExtensionProperties){VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME, 1}; + if (gaps & GAP_NULL_DESCRIPTOR) + extra[extra_count++] = (VkExtensionProperties){VK_EXT_ROBUSTNESS_2_EXTENSION_NAME, 1}; + uint32_t own = 0; + VkResult result = inst->EnumerateDeviceExtensionProperties(physical_device, NULL, &own, NULL); + if (result != VK_SUCCESS) + return result; + if (!properties) { + *count = own + extra_count; + return VK_SUCCESS; + } + VkExtensionProperties *all = calloc(own + extra_count, sizeof(*all)); + inst->EnumerateDeviceExtensionProperties(physical_device, NULL, &own, all); + memcpy(all + own, extra, extra_count * sizeof(*extra)); + uint32_t total = own + extra_count; + if (tracing()) { + layer_log("trace: vkEnumerateDeviceExtensionProperties: %u from the driver, %u added by the layer", own, extra_count); + trace_extension_names(all, total); + } + uint32_t n = *count < total ? *count : total; + memcpy(properties, all, n * sizeof(*all)); + free(all); + *count = n; + return n < total ? VK_INCOMPLETE : VK_SUCCESS; +} + +static VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *info, + const VkAllocationCallbacks *allocator, VkInstance *instance) +{ + VkLayerInstanceCreateInfo *link = (VkLayerInstanceCreateInfo *)info->pNext; + while (link && !(link->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && link->function == VK_LAYER_LINK_INFO)) + link = (VkLayerInstanceCreateInfo *)link->pNext; + if (!link) + return VK_ERROR_INITIALIZATION_FAILED; + PFN_vkGetInstanceProcAddr gipa = link->u.pLayerInfo->pfnNextGetInstanceProcAddr; + link->u.pLayerInfo = link->u.pLayerInfo->pNext; + + PFN_vkCreateInstance create = (PFN_vkCreateInstance)gipa(VK_NULL_HANDLE, "vkCreateInstance"); + VkResult result = create(info, allocator, instance); + if (tracing()) + layer_log("trace: vkCreateInstance for %s (API %u.%u): %d, layer %s", info->pApplicationInfo && info->pApplicationInfo->pApplicationName ? + info->pApplicationInfo->pApplicationName : "?", info->pApplicationInfo ? VK_API_VERSION_MAJOR(info->pApplicationInfo->apiVersion) : 0, + info->pApplicationInfo ? VK_API_VERSION_MINOR(info->pApplicationInfo->apiVersion) : 0, (int)result, wanted() ? "active" : "idle"); + if (result != VK_SUCCESS) + return result; + + struct instance *inst = calloc(1, sizeof(*inst)); + inst->key = dispatch_key(*instance); + inst->handle = *instance; + inst->active = wanted(); + inst->gipa = gipa; + pthread_mutex_init(&inst->lock, NULL); +#define LOAD(name) inst->name = (PFN_vk##name)gipa(*instance, "vk" #name); +#define LOAD_KHR(name) \ + if (!inst->name) \ + inst->name = (PFN_vk##name)gipa(*instance, "vk" #name "KHR"); + LOAD(DestroyInstance) + LOAD(EnumerateDeviceExtensionProperties) + LOAD(GetPhysicalDeviceFeatures) + LOAD(GetPhysicalDeviceFeatures2) + LOAD_KHR(GetPhysicalDeviceFeatures2) + LOAD(GetPhysicalDeviceProperties) + LOAD(GetPhysicalDeviceProperties2) + LOAD_KHR(GetPhysicalDeviceProperties2) + LOAD(GetPhysicalDeviceMemoryProperties) + LOAD(GetPhysicalDeviceFormatProperties) + LOAD(GetPhysicalDeviceFormatProperties2) + LOAD_KHR(GetPhysicalDeviceFormatProperties2) + LOAD(GetPhysicalDeviceImageFormatProperties) + LOAD(GetPhysicalDeviceImageFormatProperties2) + LOAD_KHR(GetPhysicalDeviceImageFormatProperties2) +#undef LOAD +#undef LOAD_KHR + if (tracing()) + trace_load(inst); + /* Without the Vulkan 1.1 queries there is no way to answer the chained ones. */ + if (!inst->GetPhysicalDeviceFeatures2 || !inst->GetPhysicalDeviceProperties2 || + !inst->GetPhysicalDeviceFormatProperties2 || !inst->GetPhysicalDeviceImageFormatProperties2) + inst->active = false; + + pthread_mutex_lock(&global_lock); + inst->next = instances; + instances = inst; + pthread_mutex_unlock(&global_lock); + return VK_SUCCESS; +} + +static VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *allocator) +{ + void *key = dispatch_key(instance); + pthread_mutex_lock(&global_lock); + struct instance **link = &instances; + while (*link && (*link)->key != key) + link = &(*link)->next; + struct instance *inst = *link; + if (inst) + *link = inst->next; + pthread_mutex_unlock(&global_lock); + if (!inst) + return; + inst->DestroyInstance(instance, allocator); + pthread_mutex_destroy(&inst->lock); + free(inst); +} + +static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physical_device, const VkDeviceCreateInfo *info, + const VkAllocationCallbacks *allocator, VkDevice *device) +{ + VkLayerDeviceCreateInfo *link = (VkLayerDeviceCreateInfo *)info->pNext; + while (link && !(link->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && link->function == VK_LAYER_LINK_INFO)) + link = (VkLayerDeviceCreateInfo *)link->pNext; + if (!link) + return VK_ERROR_INITIALIZATION_FAILED; + PFN_vkGetInstanceProcAddr gipa = link->u.pLayerInfo->pfnNextGetInstanceProcAddr; + PFN_vkGetDeviceProcAddr gdpa = link->u.pLayerInfo->pfnNextGetDeviceProcAddr; + link->u.pLayerInfo = link->u.pLayerInfo->pNext; + + struct instance *inst = instance_from_handle(physical_device); + PFN_vkCreateDevice create = (PFN_vkCreateDevice)gipa(inst->handle, "vkCreateDevice"); + uint32_t gaps = inst->active ? physical_device_gaps(inst, physical_device) : 0; + + /* The application's own structures are put back after the call: DXVK reads its enabled + * features again later, and must keep seeing what it asked for. */ + VkDeviceCreateInfo copy = *info; + VkPhysicalDeviceFeatures features; + VkPhysicalDeviceFeatures2 *features2 = NULL; + VkPhysicalDeviceRobustness2FeaturesEXT *robust = NULL; + for (VkBaseOutStructure *s = (VkBaseOutStructure *)info->pNext; s; s = s->pNext) { + if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2) + features2 = (VkPhysicalDeviceFeatures2 *)s; + else if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT) + robust = (VkPhysicalDeviceRobustness2FeaturesEXT *)s; + } + VkPhysicalDeviceFeatures *enabled = NULL; + VkPhysicalDeviceFeatures saved_features = {0}; + if (info->pEnabledFeatures) { + features = *info->pEnabledFeatures; + copy.pEnabledFeatures = &features; + enabled = &features; + } else if (features2) { + saved_features = features2->features; + enabled = &features2->features; + } + uint32_t requested = enabled ? take_features(enabled, gaps) : 0; + VkBool32 saved_robust = robust ? robust->robustBufferAccess2 : VK_FALSE; + if (robust && (gaps & GAP_ROBUSTNESS2) && robust->robustBufferAccess2) { + requested |= GAP_ROBUSTNESS2; + robust->robustBufferAccess2 = VK_FALSE; + /* The first version of robust buffer access is the nearest the driver has. */ + if (enabled) + enabled->robustBufferAccess = VK_TRUE; + } + + /* The extensions the layer stands in for leave the list, and their structures the chain. */ + const char **names = NULL; + if (gaps & (GAP_DEPTH_CLIP | GAP_NULL_DESCRIPTOR)) { + names = malloc((info->enabledExtensionCount ? info->enabledExtensionCount : 1) * sizeof(*names)); + copy.enabledExtensionCount = 0; + for (uint32_t i = 0; i < info->enabledExtensionCount; i++) { + const char *name = info->ppEnabledExtensionNames[i]; + if ((gaps & GAP_DEPTH_CLIP) && !strcmp(name, VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME)) { + requested |= GAP_DEPTH_CLIP; + continue; + } + if ((gaps & GAP_NULL_DESCRIPTOR) && !strcmp(name, VK_EXT_ROBUSTNESS_2_EXTENSION_NAME)) { + requested |= GAP_NULL_DESCRIPTOR; + if (enabled) + enabled->robustBufferAccess = VK_TRUE; + continue; + } + names[copy.enabledExtensionCount++] = name; + } + copy.ppEnabledExtensionNames = names; + } + VkStructureType foreign[4]; + struct unlinked dropped[8]; + uint32_t dropped_count = unlink_types(©, foreign, foreign_types(gaps, foreign), dropped, 8); + + VkResult result = create(physical_device, ©, allocator, device); + + relink(dropped, dropped_count); + free(names); + if (features2 && !info->pEnabledFeatures) + features2->features = saved_features; + if (robust) + robust->robustBufferAccess2 = saved_robust; + if (result != VK_SUCCESS) + return result; + + struct device *dev = calloc(1, sizeof(*dev)); + dev->key = dispatch_key(*device); + dev->handle = *device; + dev->gdpa = gdpa; + dev->emulated = requested; + pthread_mutex_init(&dev->lock, NULL); +#define LOAD(name) \ + dev->name = (PFN_vk##name)gdpa(*device, "vk" #name); \ + if (!dev->name) \ + dev->name = (PFN_vk##name)gdpa(*device, "vk" #name "KHR"); \ + if (!dev->name) \ + dev->name = (PFN_vk##name)gdpa(*device, "vk" #name "EXT"); + DEVICE_FUNCTIONS(LOAD) +#undef LOAD + inst->GetPhysicalDeviceMemoryProperties(physical_device, &dev->memory_properties); + VkPhysicalDeviceProperties properties; + inst->GetPhysicalDeviceProperties(physical_device, &properties); + uint32_t components = properties.limits.maxVertexOutputComponents; + if (properties.limits.maxFragmentInputComponents < components) + components = properties.limits.maxFragmentInputComponents; + dev->max_varying_locations = components / 4; + + pthread_mutex_lock(&global_lock); + dev->next = devices; + devices = dev; + pthread_mutex_unlock(&global_lock); + + if (requested) { + layer_log("emulating%s%s%s%s%s%s%s%s%s for %s", (requested & GAP_FILL_MODE) ? " fillModeNonSolid" : "", + (requested & GAP_MULTI_VIEWPORT) ? " multiViewport" : "", + (requested & GAP_CLIP_DISTANCE) ? " shaderClipDistance" : "", + (requested & GAP_CULL_DISTANCE) ? " shaderCullDistance" : "", + (requested & GAP_ROBUSTNESS2) ? " robustBufferAccess2" : "", + (requested & GAP_BC) ? " textureCompressionBC" : "", + (requested & GAP_MULTI_DRAW) ? " multiDrawIndirect" : "", + (requested & GAP_DEPTH_CLIP) ? " depthClipEnable" : "", + (requested & GAP_NULL_DESCRIPTOR) ? " nullDescriptor" : "", properties.deviceName); + } + return VK_SUCCESS; +} + +static VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *allocator) +{ + void *key = dispatch_key(device); + pthread_mutex_lock(&global_lock); + struct device **link = &devices; + while (*link && (*link)->key != key) + link = &(*link)->next; + struct device *dev = *link; + if (dev) + *link = dev->next; + pthread_mutex_unlock(&global_lock); + if (!dev) + return; + bc_destroy_device(dev); + null_resources_destroy(dev); + dev->DestroyDevice(device, allocator); + for (uint32_t i = 0; i < dev->shader_modules.capacity; i++) { + struct spirv_code *code = dev->shader_modules.values[i]; + if (code) { + free(code->words); + free(code); + } + } + map_free(&dev->shader_modules); + pthread_mutex_destroy(&dev->lock); + free(dev); +} + +struct hook { + const char *name; + PFN_vkVoidFunction function; + uint32_t gaps; +}; + +#define HOOK(name, gaps) {"vk" #name, (PFN_vkVoidFunction)name, gaps} +#define HOOK_ALIAS(name, alias, gaps) {"vk" #alias, (PFN_vkVoidFunction)name, gaps} + +static const struct hook device_hooks[] = { + HOOK(CreateShaderModule, GAPS_SHADER), + HOOK(DestroyShaderModule, GAPS_SHADER), + HOOK(CreateGraphicsPipelines, GAPS_PIPELINE), + HOOK(CmdSetViewport, GAP_MULTI_VIEWPORT), + HOOK(CmdSetScissor, GAP_MULTI_VIEWPORT), + HOOK(CmdSetViewportWithCount, GAP_MULTI_VIEWPORT), + HOOK_ALIAS(CmdSetViewportWithCount, CmdSetViewportWithCountEXT, GAP_MULTI_VIEWPORT), + HOOK(CmdSetScissorWithCount, GAP_MULTI_VIEWPORT), + HOOK_ALIAS(CmdSetScissorWithCount, CmdSetScissorWithCountEXT, GAP_MULTI_VIEWPORT), + HOOK(CreateImage, GAP_BC), + HOOK(DestroyImage, GAP_BC), + HOOK(CreateImageView, GAP_BC), + HOOK(GetDeviceImageMemoryRequirements, GAP_BC), + HOOK_ALIAS(GetDeviceImageMemoryRequirements, GetDeviceImageMemoryRequirementsKHR, GAP_BC), + HOOK(GetDeviceImageSparseMemoryRequirements, GAP_BC), + HOOK_ALIAS(GetDeviceImageSparseMemoryRequirements, GetDeviceImageSparseMemoryRequirementsKHR, GAP_BC), + HOOK(GetDeviceImageSubresourceLayout, GAP_BC), + HOOK_ALIAS(GetDeviceImageSubresourceLayout, GetDeviceImageSubresourceLayoutKHR, GAP_BC), + HOOK(CmdCopyBufferToImage, GAP_BC), + HOOK(CmdCopyBufferToImage2, GAP_BC), + HOOK_ALIAS(CmdCopyBufferToImage2, CmdCopyBufferToImage2KHR, GAP_BC), + HOOK(CmdCopyImageToBuffer, GAP_BC), + HOOK(CmdCopyImageToBuffer2, GAP_BC), + HOOK_ALIAS(CmdCopyImageToBuffer2, CmdCopyImageToBuffer2KHR, GAP_BC), + HOOK(CmdCopyImage, GAP_BC), + HOOK(CmdCopyImage2, GAP_BC), + HOOK_ALIAS(CmdCopyImage2, CmdCopyImage2KHR, GAP_BC), + HOOK(BindBufferMemory, GAP_BC), + HOOK(BindBufferMemory2, GAP_BC), + HOOK_ALIAS(BindBufferMemory2, BindBufferMemory2KHR, GAP_BC), + HOOK(DestroyBuffer, GAP_BC), + HOOK(FreeMemory, GAP_BC), + HOOK(MapMemory, GAP_BC), + HOOK(MapMemory2, GAP_BC), + HOOK_ALIAS(MapMemory2, MapMemory2KHR, GAP_BC), + HOOK(UnmapMemory, GAP_BC), + HOOK(UnmapMemory2, GAP_BC), + HOOK_ALIAS(UnmapMemory2, UnmapMemory2KHR, GAP_BC), + HOOK(AllocateCommandBuffers, GAP_BC), + HOOK(FreeCommandBuffers, GAP_BC), + HOOK(BeginCommandBuffer, GAP_BC), + HOOK(ResetCommandBuffer, GAP_BC), + HOOK(ResetCommandPool, GAP_BC), + HOOK(DestroyCommandPool, GAP_BC), + HOOK(CmdDrawIndirect, GAP_MULTI_DRAW), + HOOK(CmdDrawIndexedIndirect, GAP_MULTI_DRAW), + HOOK(UpdateDescriptorSets, GAP_NULL_DESCRIPTOR), + HOOK(CmdPushDescriptorSet, GAP_NULL_DESCRIPTOR), + HOOK_ALIAS(CmdPushDescriptorSet, CmdPushDescriptorSetKHR, GAP_NULL_DESCRIPTOR), + HOOK(CreateDescriptorUpdateTemplate, GAP_NULL_DESCRIPTOR), + HOOK_ALIAS(CreateDescriptorUpdateTemplate, CreateDescriptorUpdateTemplateKHR, GAP_NULL_DESCRIPTOR), + HOOK(DestroyDescriptorUpdateTemplate, GAP_NULL_DESCRIPTOR), + HOOK_ALIAS(DestroyDescriptorUpdateTemplate, DestroyDescriptorUpdateTemplateKHR, GAP_NULL_DESCRIPTOR), + HOOK(UpdateDescriptorSetWithTemplate, GAP_NULL_DESCRIPTOR), + HOOK_ALIAS(UpdateDescriptorSetWithTemplate, UpdateDescriptorSetWithTemplateKHR, GAP_NULL_DESCRIPTOR), + HOOK(CmdPushDescriptorSetWithTemplate, GAP_NULL_DESCRIPTOR), + HOOK_ALIAS(CmdPushDescriptorSetWithTemplate, CmdPushDescriptorSetWithTemplateKHR, GAP_NULL_DESCRIPTOR), + HOOK(CmdBindVertexBuffers, GAP_NULL_DESCRIPTOR), + HOOK(CmdBindVertexBuffers2, GAP_NULL_DESCRIPTOR), + HOOK_ALIAS(CmdBindVertexBuffers2, CmdBindVertexBuffers2EXT, GAP_NULL_DESCRIPTOR), +}; + +static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *name); + +static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *name) +{ + if (!strcmp(name, "vkGetDeviceProcAddr")) + return (PFN_vkVoidFunction)GetDeviceProcAddr; + struct device *dev = device_from_handle(device); + if (!dev) + return NULL; + if (!strcmp(name, "vkDestroyDevice")) + return (PFN_vkVoidFunction)DestroyDevice; + PFN_vkVoidFunction next = dev->gdpa(device, name); + if (!next) + return NULL; + for (size_t i = 0; i < sizeof(device_hooks) / sizeof(device_hooks[0]); i++) { + if ((dev->emulated & device_hooks[i].gaps) && !strcmp(name, device_hooks[i].name)) + return device_hooks[i].function; + } + return next; +} + +static const struct hook physical_device_hooks[] = { + HOOK(EnumerateDeviceExtensionProperties, 0), + HOOK(GetPhysicalDeviceFeatures, 0), + HOOK(GetPhysicalDeviceFeatures2, 0), + HOOK_ALIAS(GetPhysicalDeviceFeatures2, GetPhysicalDeviceFeatures2KHR, 0), + HOOK(GetPhysicalDeviceProperties, 0), + HOOK(GetPhysicalDeviceProperties2, 0), + HOOK_ALIAS(GetPhysicalDeviceProperties2, GetPhysicalDeviceProperties2KHR, 0), + HOOK(GetPhysicalDeviceFormatProperties, 0), + HOOK(GetPhysicalDeviceFormatProperties2, 0), + HOOK_ALIAS(GetPhysicalDeviceFormatProperties2, GetPhysicalDeviceFormatProperties2KHR, 0), + HOOK(GetPhysicalDeviceImageFormatProperties, 0), + HOOK(GetPhysicalDeviceImageFormatProperties2, 0), + HOOK_ALIAS(GetPhysicalDeviceImageFormatProperties2, GetPhysicalDeviceImageFormatProperties2KHR, 0), +}; + +static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *name) +{ + if (!strcmp(name, "vkGetInstanceProcAddr")) + return (PFN_vkVoidFunction)GetInstanceProcAddr; + if (!strcmp(name, "vkCreateInstance")) + return (PFN_vkVoidFunction)CreateInstance; + if (!strcmp(name, "vkGetDeviceProcAddr")) + return (PFN_vkVoidFunction)GetDeviceProcAddr; + if (!instance) + return NULL; + struct instance *inst = instance_from_handle(instance); + if (!inst) + return NULL; + if (!strcmp(name, "vkDestroyInstance")) + return (PFN_vkVoidFunction)DestroyInstance; + /* Always ours, even when inactive: each layer moves the device chain one link on. */ + if (!strcmp(name, "vkCreateDevice")) + return (PFN_vkVoidFunction)CreateDevice; + PFN_vkVoidFunction next = inst->gipa(instance, name); + if (next && tracing()) { + PFN_vkVoidFunction traced = trace_hook(inst, name); + if (traced) + return traced; + } + if (!next || !inst->active) + return next; + for (size_t i = 0; i < sizeof(physical_device_hooks) / sizeof(physical_device_hooks[0]); i++) { + if (!strcmp(name, physical_device_hooks[i].name)) + return physical_device_hooks[i].function; + } + return next; +} + +__attribute__((visibility("default"))) VKAPI_ATTR VkResult VKAPI_CALL +vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *interface) +{ + if (interface->loaderLayerInterfaceVersion < 2) + return VK_ERROR_INITIALIZATION_FAILED; + interface->loaderLayerInterfaceVersion = 2; + interface->pfnGetInstanceProcAddr = GetInstanceProcAddr; + interface->pfnGetDeviceProcAddr = GetDeviceProcAddr; + interface->pfnGetPhysicalDeviceProcAddr = NULL; + return VK_SUCCESS; +} diff --git a/tools/venus/layer/mali_compat.h b/tools/venus/layer/mali_compat.h new file mode 100644 index 0000000000..055034ab65 --- /dev/null +++ b/tools/venus/layer/mali_compat.h @@ -0,0 +1,301 @@ +/* + * VK_LAYER_DROIDDECK_mali_compat: makes up for what Mali lacks and DXVK requires. + * + * DXVK refuses any GPU without fillModeNonSolid, multiViewport, shaderClipDistance, + * shaderCullDistance, textureCompressionBC and robustBufferAccess2, and Mali has none of them. + * The layer reports each missing feature as supported, keeps it out of the driver's device, and + * handles what uses it: polygon modes draw filled, only the first viewport is kept, clip distances + * become a varying the fragment shader discards on, cull distances are dropped, and BC textures + * are decoded on the CPU into uncompressed images as they are uploaded. + */ +#ifndef MALI_COMPAT_H +#define MALI_COMPAT_H + +#include <pthread.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> +#include <vulkan/vk_layer.h> +#include <vulkan/vulkan.h> + +enum gap { + GAP_FILL_MODE = 1u << 0, + GAP_MULTI_VIEWPORT = 1u << 1, + GAP_CLIP_DISTANCE = 1u << 2, + GAP_CULL_DISTANCE = 1u << 3, + GAP_ROBUSTNESS2 = 1u << 4, + GAP_BC = 1u << 5, + /* draw.c and pipeline.c (added for Mali-G57 and drivers without these, on top of David Cimo's six) */ + GAP_MULTI_DRAW = 1u << 6, /* multiDrawIndirect: indirect draws looped one by one */ + GAP_DEPTH_CLIP = 1u << 7, /* VK_EXT_depth_clip_enable: depthClipEnable off becomes depth clamp */ + GAP_NULL_DESCRIPTOR = 1u << 8, /* VK_EXT_robustness2 missing entirely: nullDescriptor stand-ins */ +}; + +#define GAPS_SHADER (GAP_CLIP_DISTANCE | GAP_CULL_DISTANCE) +#define GAPS_PIPELINE (GAP_FILL_MODE | GAP_MULTI_VIEWPORT | GAPS_SHADER | GAP_DEPTH_CLIP) + +void layer_log(const char *format, ...) __attribute__((format(printf, 1, 2))); + +/* Open addressing from a Vulkan handle to a pointer. Not locked: the owner holds its lock. */ +struct handle_map { + uint64_t *keys; + void **values; + uint32_t capacity; + uint32_t count; +}; + +void *map_get(const struct handle_map *map, uint64_t key); +void map_put(struct handle_map *map, uint64_t key, void *value); +void *map_remove(struct handle_map *map, uint64_t key); +void map_free(struct handle_map *map); + +struct physical_device { + VkPhysicalDevice handle; + uint32_t gaps; +}; + +struct instance { + void *key; + VkInstance handle; + bool active; + PFN_vkGetInstanceProcAddr gipa; + PFN_vkDestroyInstance DestroyInstance; + PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties; + PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures; + PFN_vkGetPhysicalDeviceFeatures2 GetPhysicalDeviceFeatures2; + PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties; + PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2; + PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties; + PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties; + PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysicalDeviceFormatProperties2; + PFN_vkGetPhysicalDeviceImageFormatProperties GetPhysicalDeviceImageFormatProperties; + PFN_vkGetPhysicalDeviceImageFormatProperties2 GetPhysicalDeviceImageFormatProperties2; + PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; + PFN_vkGetPhysicalDeviceMemoryProperties2 GetPhysicalDeviceMemoryProperties2; + PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties; + PFN_vkGetPhysicalDeviceQueueFamilyProperties2 GetPhysicalDeviceQueueFamilyProperties2; + PFN_vkGetPhysicalDeviceExternalBufferProperties GetPhysicalDeviceExternalBufferProperties; + PFN_vkGetPhysicalDeviceExternalSemaphoreProperties GetPhysicalDeviceExternalSemaphoreProperties; + PFN_vkGetPhysicalDeviceExternalFenceProperties GetPhysicalDeviceExternalFenceProperties; + pthread_mutex_t lock; + struct physical_device physical_devices[8]; + uint32_t physical_device_count; + struct instance *next; +}; + +#define DEVICE_FUNCTIONS(X) \ + X(DestroyDevice) \ + X(CreateShaderModule) \ + X(DestroyShaderModule) \ + X(CreateGraphicsPipelines) \ + X(CmdSetViewport) \ + X(CmdSetScissor) \ + X(CmdSetViewportWithCount) \ + X(CmdSetScissorWithCount) \ + X(CreateImage) \ + X(DestroyImage) \ + X(CreateImageView) \ + X(GetDeviceImageMemoryRequirements) \ + X(GetDeviceImageSparseMemoryRequirements) \ + X(GetDeviceImageSubresourceLayout) \ + X(CmdCopyBufferToImage) \ + X(CmdCopyBufferToImage2) \ + X(CmdCopyImageToBuffer) \ + X(CmdCopyImageToBuffer2) \ + X(CmdCopyImage) \ + X(CmdCopyImage2) \ + X(CreateBuffer) \ + X(DestroyBuffer) \ + X(GetBufferMemoryRequirements) \ + X(BindBufferMemory) \ + X(BindBufferMemory2) \ + X(AllocateMemory) \ + X(FreeMemory) \ + X(MapMemory) \ + X(MapMemory2) \ + X(UnmapMemory) \ + X(UnmapMemory2) \ + X(AllocateCommandBuffers) \ + X(FreeCommandBuffers) \ + X(BeginCommandBuffer) \ + X(ResetCommandBuffer) \ + X(ResetCommandPool) \ + X(DestroyCommandPool) \ + X(CmdDrawIndirect) \ + X(CmdDrawIndexedIndirect) \ + X(GetImageMemoryRequirements) \ + X(BindImageMemory) \ + X(DestroyImageView) \ + X(CreateBufferView) \ + X(DestroyBufferView) \ + X(UpdateDescriptorSets) \ + X(CmdPushDescriptorSet) \ + X(CreateDescriptorUpdateTemplate) \ + X(DestroyDescriptorUpdateTemplate) \ + X(UpdateDescriptorSetWithTemplate) \ + X(CmdPushDescriptorSetWithTemplate) \ + X(CmdBindVertexBuffers) \ + X(CmdBindVertexBuffers2) + +struct staging_block; + +struct device { + void *key; + VkDevice handle; + PFN_vkGetDeviceProcAddr gdpa; + /* The gaps the application enabled a made-up feature for. */ + uint32_t emulated; + /* Locations a clip distance varying may use, from the vertex output and fragment input limits. */ + uint32_t max_varying_locations; + VkPhysicalDeviceMemoryProperties memory_properties; +#define DECLARE(name) PFN_vk##name name; + DEVICE_FUNCTIONS(DECLARE) +#undef DECLARE + pthread_mutex_t lock; + struct handle_map shader_modules; /* VkShaderModule -> struct spirv_code, for modules with distances */ + struct handle_map images; /* VkImage -> struct bc_image */ + struct handle_map buffers; /* VkBuffer -> struct bound_buffer */ + struct handle_map memories; /* VkDeviceMemory -> struct mapped_memory */ + struct handle_map command_buffers; /* VkCommandBuffer -> struct command_buffer */ + struct staging_block *free_staging; + struct handle_map templates; /* VkDescriptorUpdateTemplate -> struct template_info (draw.c) */ + /* nullDescriptor stand-ins (draw.c): 0 not made yet, 1 ready, -1 failed. */ + int null_ready; + VkBuffer null_buffer; + VkDeviceMemory null_buffer_memory; + VkImage null_image; + VkDeviceMemory null_image_memory; + VkImageView null_view; + /* Texel-buffer stand-ins: RGBA8 for uniform (sampled) texel buffers, R32_UINT for storage. */ + VkBufferView null_uniform_texel; + VkBufferView null_storage_texel; + struct device *next; +}; + +struct device *device_from_handle(const void *dispatchable); + +struct spirv_code { + uint32_t *words; + size_t count; +}; + +/* spirv.c */ +bool spirv_uses_distances(const uint32_t *words, size_t count); +/* The module with clip and cull distances taken out; false when it cannot be rewritten. */ +bool spirv_strip_distances(const uint32_t *words, size_t count, struct spirv_code *out); + +enum clip_role { CLIP_STRIP, CLIP_PRODUCER, CLIP_CONSUMER }; + +struct clip_info { + bool has_clip; /* a standalone ClipDistance variable this stage could hand on */ + uint32_t clip_count; /* its array length */ + uint32_t locations_used; /* one past the highest varying location, outputs or inputs per role */ +}; + +void spirv_clip_info(const uint32_t *words, size_t count, enum clip_role role, struct clip_info *info); +/* + * Producer: the last stage before rasterization writes its clip distances to `location` instead. + * Consumer: the fragment shader reads them there and discards when any is negative. + * Both drop cull distances. False when the module cannot be rewritten. + */ +bool spirv_emulate_clip(const uint32_t *words, size_t count, enum clip_role role, uint32_t location, + uint32_t clip_count, struct spirv_code *out); + +/* pipeline.c */ +VKAPI_ATTR VkResult VKAPI_CALL CreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *info, + const VkAllocationCallbacks *allocator, VkShaderModule *module); +VKAPI_ATTR void VKAPI_CALL DestroyShaderModule(VkDevice device, VkShaderModule module, + const VkAllocationCallbacks *allocator); +VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipelineCache cache, uint32_t count, + const VkGraphicsPipelineCreateInfo *infos, + const VkAllocationCallbacks *allocator, VkPipeline *pipelines); +VKAPI_ATTR void VKAPI_CALL CmdSetViewport(VkCommandBuffer cmd, uint32_t first, uint32_t count, + const VkViewport *viewports); +VKAPI_ATTR void VKAPI_CALL CmdSetScissor(VkCommandBuffer cmd, uint32_t first, uint32_t count, + const VkRect2D *scissors); +VKAPI_ATTR void VKAPI_CALL CmdSetViewportWithCount(VkCommandBuffer cmd, uint32_t count, + const VkViewport *viewports); +VKAPI_ATTR void VKAPI_CALL CmdSetScissorWithCount(VkCommandBuffer cmd, uint32_t count, const VkRect2D *scissors); + +/* bc.c */ +VkFormat bc_substitute(VkFormat format); +VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties(VkPhysicalDevice physical_device, VkFormat format, + VkFormatProperties *properties); +VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physical_device, VkFormat format, + VkFormatProperties2 *properties); +VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties( + VkPhysicalDevice physical_device, VkFormat format, VkImageType type, VkImageTiling tiling, + VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties *properties); +VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties2( + VkPhysicalDevice physical_device, const VkPhysicalDeviceImageFormatInfo2 *info, + VkImageFormatProperties2 *properties); +VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateInfo *info, + const VkAllocationCallbacks *allocator, VkImage *image); +VKAPI_ATTR void VKAPI_CALL DestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *allocator); +VKAPI_ATTR VkResult VKAPI_CALL CreateImageView(VkDevice device, const VkImageViewCreateInfo *info, + const VkAllocationCallbacks *allocator, VkImageView *view); +VKAPI_ATTR void VKAPI_CALL GetDeviceImageMemoryRequirements(VkDevice device, + const VkDeviceImageMemoryRequirements *info, + VkMemoryRequirements2 *requirements); +VKAPI_ATTR void VKAPI_CALL GetDeviceImageSparseMemoryRequirements( + VkDevice device, const VkDeviceImageMemoryRequirements *info, uint32_t *count, + VkSparseImageMemoryRequirements2 *requirements); +VKAPI_ATTR void VKAPI_CALL GetDeviceImageSubresourceLayout(VkDevice device, + const VkDeviceImageSubresourceInfo *info, + VkSubresourceLayout2 *layout); +VKAPI_ATTR void VKAPI_CALL CmdCopyBufferToImage(VkCommandBuffer cmd, VkBuffer buffer, VkImage image, + VkImageLayout layout, uint32_t count, + const VkBufferImageCopy *regions); +VKAPI_ATTR void VKAPI_CALL CmdCopyBufferToImage2(VkCommandBuffer cmd, const VkCopyBufferToImageInfo2 *info); +VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer(VkCommandBuffer cmd, VkImage image, VkImageLayout layout, + VkBuffer buffer, uint32_t count, const VkBufferImageCopy *regions); +VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer2(VkCommandBuffer cmd, const VkCopyImageToBufferInfo2 *info); +VKAPI_ATTR void VKAPI_CALL CmdCopyImage(VkCommandBuffer cmd, VkImage src, VkImageLayout src_layout, VkImage dst, + VkImageLayout dst_layout, uint32_t count, const VkImageCopy *regions); +VKAPI_ATTR void VKAPI_CALL CmdCopyImage2(VkCommandBuffer cmd, const VkCopyImageInfo2 *info); +VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, + VkDeviceSize offset); +VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory2(VkDevice device, uint32_t count, + const VkBindBufferMemoryInfo *infos); +VKAPI_ATTR void VKAPI_CALL DestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *allocator); +VKAPI_ATTR void VKAPI_CALL FreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks *allocator); +VKAPI_ATTR VkResult VKAPI_CALL MapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, + VkDeviceSize size, VkMemoryMapFlags flags, void **data); +VKAPI_ATTR VkResult VKAPI_CALL MapMemory2(VkDevice device, const VkMemoryMapInfo *info, void **data); +VKAPI_ATTR void VKAPI_CALL UnmapMemory(VkDevice device, VkDeviceMemory memory); +VKAPI_ATTR VkResult VKAPI_CALL UnmapMemory2(VkDevice device, const VkMemoryUnmapInfo *info); +VKAPI_ATTR VkResult VKAPI_CALL AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *info, + VkCommandBuffer *buffers); +VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool pool, uint32_t count, + const VkCommandBuffer *buffers); +VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer cmd, const VkCommandBufferBeginInfo *info); +VKAPI_ATTR VkResult VKAPI_CALL ResetCommandBuffer(VkCommandBuffer cmd, VkCommandBufferResetFlags flags); +VKAPI_ATTR VkResult VKAPI_CALL ResetCommandPool(VkDevice device, VkCommandPool pool, VkCommandPoolResetFlags flags); +VKAPI_ATTR void VKAPI_CALL DestroyCommandPool(VkDevice device, VkCommandPool pool, + const VkAllocationCallbacks *allocator); +void bc_destroy_device(struct device *dev); + +/* layer.c */ +struct instance *instance_from_handle(const void *dispatchable); +/* What the GPU lacks of the features the layer can make up for. */ +uint32_t physical_device_gaps(struct instance *inst, VkPhysicalDevice physical_device); + +/* trace.c (DROIDDECK_MALI_COMPAT_TRACE=1) */ +void trace_load(struct instance *inst); +PFN_vkVoidFunction trace_hook(struct instance *inst, const char *name); +void trace_extension_names(const VkExtensionProperties *ext, uint32_t n); + + +/* draw.c */ +VKAPI_ATTR void VKAPI_CALL CmdDrawIndirect(VkCommandBuffer cmd, VkBuffer buffer, VkDeviceSize offset, uint32_t draw_count, uint32_t stride); +VKAPI_ATTR void VKAPI_CALL CmdDrawIndexedIndirect(VkCommandBuffer cmd, VkBuffer buffer, VkDeviceSize offset, uint32_t draw_count, uint32_t stride); +VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t write_count, const VkWriteDescriptorSet *writes, uint32_t copy_count, const VkCopyDescriptorSet *copies); +VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSet(VkCommandBuffer cmd, VkPipelineBindPoint bind_point, VkPipelineLayout layout, uint32_t set, uint32_t write_count, const VkWriteDescriptorSet *writes); +VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorUpdateTemplate(VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *info, const VkAllocationCallbacks *allocator, VkDescriptorUpdateTemplate *tmpl); +VKAPI_ATTR void VKAPI_CALL DestroyDescriptorUpdateTemplate(VkDevice device, VkDescriptorUpdateTemplate tmpl, const VkAllocationCallbacks *allocator); +VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet set, VkDescriptorUpdateTemplate tmpl, const void *data); +VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetWithTemplate(VkCommandBuffer cmd, VkDescriptorUpdateTemplate tmpl, VkPipelineLayout layout, uint32_t set, const void *data); +VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers(VkCommandBuffer cmd, uint32_t first, uint32_t count, const VkBuffer *buffers, const VkDeviceSize *offsets); +VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers2(VkCommandBuffer cmd, uint32_t first, uint32_t count, const VkBuffer *buffers, const VkDeviceSize *offsets, const VkDeviceSize *sizes, const VkDeviceSize *strides); +void null_resources_destroy(struct device *dev); +#endif diff --git a/tools/venus/layer/pipeline.c b/tools/venus/layer/pipeline.c new file mode 100644 index 0000000000..a749c21d3e --- /dev/null +++ b/tools/venus/layer/pipeline.c @@ -0,0 +1,308 @@ +#include "mali_compat.h" + +#include <stdlib.h> +#include <string.h> + +#define HANDLE(h) ((uint64_t)(uintptr_t)(h)) +#define MAX_STAGES 8 + +/* A module with distances goes to the driver without them; its original stays here, for the + * pipeline that can emulate its clip distances. */ +VKAPI_ATTR VkResult VKAPI_CALL CreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *info, + const VkAllocationCallbacks *allocator, VkShaderModule *module) +{ + struct device *dev = device_from_handle(device); + size_t count = info->codeSize / sizeof(uint32_t); + if (!spirv_uses_distances(info->pCode, count)) + return dev->CreateShaderModule(device, info, allocator, module); + + struct spirv_code stripped; + if (!spirv_strip_distances(info->pCode, count, &stripped)) { + layer_log("could not take the clip and cull distances out of a shader module"); + return dev->CreateShaderModule(device, info, allocator, module); + } + VkShaderModuleCreateInfo copy = *info; + copy.pCode = stripped.words; + copy.codeSize = stripped.count * sizeof(uint32_t); + VkResult result = dev->CreateShaderModule(device, ©, allocator, module); + free(stripped.words); + if (result != VK_SUCCESS) + return result; + + struct spirv_code *original = malloc(sizeof(*original)); + original->count = count; + original->words = malloc(info->codeSize); + memcpy(original->words, info->pCode, info->codeSize); + pthread_mutex_lock(&dev->lock); + map_put(&dev->shader_modules, HANDLE(*module), original); + pthread_mutex_unlock(&dev->lock); + return VK_SUCCESS; +} + +VKAPI_ATTR void VKAPI_CALL DestroyShaderModule(VkDevice device, VkShaderModule module, + const VkAllocationCallbacks *allocator) +{ + struct device *dev = device_from_handle(device); + pthread_mutex_lock(&dev->lock); + struct spirv_code *original = map_remove(&dev->shader_modules, HANDLE(module)); + pthread_mutex_unlock(&dev->lock); + if (original) { + free(original->words); + free(original); + } + dev->DestroyShaderModule(device, module, allocator); +} + +struct stage_code { + const uint32_t *words; + size_t count; + /* The application's own, when the code comes inline in the stage. */ + VkShaderModuleCreateInfo *inline_info; + /* A module whose distances were already taken out at creation. */ + bool stripped_module; +}; + +static void find_stage_code(struct device *dev, const VkPipelineShaderStageCreateInfo *stage, struct stage_code *code) +{ + memset(code, 0, sizeof(*code)); + for (const VkBaseInStructure *s = stage->pNext; s; s = s->pNext) { + if (s->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO) { + code->inline_info = (VkShaderModuleCreateInfo *)s; + code->words = code->inline_info->pCode; + code->count = code->inline_info->codeSize / sizeof(uint32_t); + return; + } + } + if (stage->module == VK_NULL_HANDLE) + return; + pthread_mutex_lock(&dev->lock); + struct spirv_code *original = map_get(&dev->shader_modules, HANDLE(stage->module)); + pthread_mutex_unlock(&dev->lock); + if (original) { + code->words = original->words; + code->count = original->count; + code->stripped_module = true; + } +} + +struct pipeline_rewrite { + VkPipelineRasterizationStateCreateInfo rasterization; + /* VK_EXT_depth_clip_enable's state, taken out of the application's chain for the call. */ + VkBaseOutStructure *clip_prev, *clip_node; + VkPipelineViewportStateCreateInfo viewport; + VkPipelineShaderStageCreateInfo stages[MAX_STAGES]; + VkShaderModuleCreateInfo modules[MAX_STAGES]; + struct spirv_code code[MAX_STAGES]; + VkShaderModule temporary[MAX_STAGES]; + /* Rewritten where they are, when they are not first in their stage's chain. */ + VkShaderModuleCreateInfo *in_place[MAX_STAGES]; + const uint32_t *in_place_code[MAX_STAGES]; + size_t in_place_size[MAX_STAGES]; +}; + +static void use_code(struct device *dev, VkGraphicsPipelineCreateInfo *info, struct pipeline_rewrite *rw, + const struct stage_code *code, uint32_t i) +{ + if (info->pStages != rw->stages) { + memcpy(rw->stages, info->pStages, info->stageCount * sizeof(*rw->stages)); + info->pStages = rw->stages; + } + const struct spirv_code *out = &rw->code[i]; + if (code->inline_info && rw->stages[i].pNext == code->inline_info) { + rw->modules[i] = *code->inline_info; + rw->modules[i].pCode = out->words; + rw->modules[i].codeSize = out->count * sizeof(uint32_t); + rw->stages[i].pNext = &rw->modules[i]; + } else if (code->inline_info) { + rw->in_place[i] = code->inline_info; + rw->in_place_code[i] = code->inline_info->pCode; + rw->in_place_size[i] = code->inline_info->codeSize; + code->inline_info->pCode = out->words; + code->inline_info->codeSize = out->count * sizeof(uint32_t); + } else { + VkShaderModuleCreateInfo module_info = { + .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, + .codeSize = out->count * sizeof(uint32_t), + .pCode = out->words, + }; + if (dev->CreateShaderModule(dev->handle, &module_info, NULL, &rw->temporary[i]) == VK_SUCCESS) + rw->stages[i].module = rw->temporary[i]; + } +} + +static int stage_index(const VkGraphicsPipelineCreateInfo *info, VkShaderStageFlagBits stage) +{ + for (uint32_t i = 0; i < info->stageCount; i++) { + if (info->pStages[i].stage == stage) + return (int)i; + } + return -1; +} + +/* + * Clip distances are emulated when the last stage before rasterization is the only one that + * hands them on: a vertex shader feeding a geometry shader would need a varying of its own. + * Anywhere else they are dropped, along with every cull distance. + */ +static void rewrite_shaders(struct device *dev, VkGraphicsPipelineCreateInfo *info, struct pipeline_rewrite *rw) +{ + uint32_t n = info->stageCount; + if (!n || n > MAX_STAGES || !info->pStages) + return; + struct stage_code code[MAX_STAGES]; + bool uses[MAX_STAGES]; + bool any = false; + for (uint32_t i = 0; i < n; i++) { + find_stage_code(dev, &info->pStages[i], &code[i]); + uses[i] = code[i].words && spirv_uses_distances(code[i].words, code[i].count); + any |= uses[i]; + } + if (!any) + return; + + int producer = stage_index(info, VK_SHADER_STAGE_GEOMETRY_BIT); + if (producer < 0) + producer = stage_index(info, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT); + if (producer < 0) + producer = stage_index(info, VK_SHADER_STAGE_VERTEX_BIT); + int consumer = stage_index(info, VK_SHADER_STAGE_FRAGMENT_BIT); + bool emulate = (dev->emulated & GAP_CLIP_DISTANCE) && producer >= 0 && consumer >= 0 && uses[producer] && + code[consumer].words; + for (uint32_t i = 0; i < n && emulate; i++) { + if ((int)i != producer && (int)i != consumer && uses[i]) + emulate = false; + } + if (emulate) { + struct clip_info produced, consumed; + spirv_clip_info(code[producer].words, code[producer].count, CLIP_PRODUCER, &produced); + spirv_clip_info(code[consumer].words, code[consumer].count, CLIP_CONSUMER, &consumed); + uint32_t location = produced.locations_used > consumed.locations_used ? produced.locations_used + : consumed.locations_used; + emulate = produced.has_clip && location != UINT32_MAX && + location + produced.clip_count <= dev->max_varying_locations && + spirv_emulate_clip(code[producer].words, code[producer].count, CLIP_PRODUCER, location, + produced.clip_count, &rw->code[producer]) && + spirv_emulate_clip(code[consumer].words, code[consumer].count, CLIP_CONSUMER, location, + produced.clip_count, &rw->code[consumer]); + if (!emulate) { + free(rw->code[producer].words); + free(rw->code[consumer].words); + rw->code[producer] = rw->code[consumer] = (struct spirv_code){0}; + } + } + + for (uint32_t i = 0; i < n; i++) { + if (!rw->code[i].words && uses[i] && !code[i].stripped_module && + !spirv_strip_distances(code[i].words, code[i].count, &rw->code[i])) { + layer_log("could not take the clip and cull distances out of a pipeline's shader"); + } + if (rw->code[i].words) + use_code(dev, info, rw, &code[i], i); + } +} + +static void rewrite_pipeline(struct device *dev, VkGraphicsPipelineCreateInfo *info, struct pipeline_rewrite *rw) +{ + if ((dev->emulated & GAP_FILL_MODE) && info->pRasterizationState && + info->pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) { + rw->rasterization = *info->pRasterizationState; + rw->rasterization.polygonMode = VK_POLYGON_MODE_FILL; + info->pRasterizationState = &rw->rasterization; + } + /* No VK_EXT_depth_clip_enable: depth clipping off is the nearest the driver has as depth clamp. */ + if ((dev->emulated & GAP_DEPTH_CLIP) && info->pRasterizationState) { + VkBaseOutStructure *prev = (VkBaseOutStructure *)info->pRasterizationState; + while (prev->pNext && prev->pNext->sType != VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT) + prev = prev->pNext; + VkBaseOutStructure *node = prev->pNext; + if (node) { + bool clip = ((VkPipelineRasterizationDepthClipStateCreateInfoEXT *)node)->depthClipEnable; + if (info->pRasterizationState != &rw->rasterization) { + rw->rasterization = *info->pRasterizationState; + if (prev == (VkBaseOutStructure *)info->pRasterizationState) + prev = (VkBaseOutStructure *)&rw->rasterization; + info->pRasterizationState = &rw->rasterization; + } + if (!clip) + rw->rasterization.depthClampEnable = VK_TRUE; + if (prev != (VkBaseOutStructure *)&rw->rasterization) { + rw->clip_prev = prev; + rw->clip_node = node; + } + prev->pNext = node->pNext; + } + } + if ((dev->emulated & GAP_MULTI_VIEWPORT) && info->pViewportState && + (info->pViewportState->viewportCount > 1 || info->pViewportState->scissorCount > 1)) { + rw->viewport = *info->pViewportState; + if (rw->viewport.viewportCount > 1) + rw->viewport.viewportCount = 1; + if (rw->viewport.scissorCount > 1) + rw->viewport.scissorCount = 1; + info->pViewportState = &rw->viewport; + } + if (dev->emulated & GAPS_SHADER) + rewrite_shaders(dev, info, rw); +} + +static void undo_rewrite(struct device *dev, struct pipeline_rewrite *rw) +{ + if (rw->clip_prev) + rw->clip_prev->pNext = rw->clip_node; + for (uint32_t i = 0; i < MAX_STAGES; i++) { + if (rw->in_place[i]) { + rw->in_place[i]->pCode = rw->in_place_code[i]; + rw->in_place[i]->codeSize = rw->in_place_size[i]; + } + if (rw->temporary[i] != VK_NULL_HANDLE) + dev->DestroyShaderModule(dev->handle, rw->temporary[i], NULL); + free(rw->code[i].words); + } +} + +VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipelineCache cache, uint32_t count, + const VkGraphicsPipelineCreateInfo *infos, + const VkAllocationCallbacks *allocator, VkPipeline *pipelines) +{ + struct device *dev = device_from_handle(device); + VkGraphicsPipelineCreateInfo *copies = malloc(count * sizeof(*copies)); + struct pipeline_rewrite *rewrites = calloc(count, sizeof(*rewrites)); + for (uint32_t i = 0; i < count; i++) { + copies[i] = infos[i]; + rewrite_pipeline(dev, &copies[i], &rewrites[i]); + } + VkResult result = dev->CreateGraphicsPipelines(device, cache, count, copies, allocator, pipelines); + for (uint32_t i = 0; i < count; i++) + undo_rewrite(dev, &rewrites[i]); + free(rewrites); + free(copies); + return result; +} + +/* The driver has one viewport and one scissor; anything past the first is left out. */ +VKAPI_ATTR void VKAPI_CALL CmdSetViewport(VkCommandBuffer cmd, uint32_t first, uint32_t count, + const VkViewport *viewports) +{ + struct device *dev = device_from_handle(cmd); + if (first == 0 && count > 0) + dev->CmdSetViewport(cmd, 0, 1, viewports); +} + +VKAPI_ATTR void VKAPI_CALL CmdSetScissor(VkCommandBuffer cmd, uint32_t first, uint32_t count, const VkRect2D *scissors) +{ + struct device *dev = device_from_handle(cmd); + if (first == 0 && count > 0) + dev->CmdSetScissor(cmd, 0, 1, scissors); +} + +VKAPI_ATTR void VKAPI_CALL CmdSetViewportWithCount(VkCommandBuffer cmd, uint32_t count, const VkViewport *viewports) +{ + struct device *dev = device_from_handle(cmd); + dev->CmdSetViewportWithCount(cmd, count > 1 ? 1 : count, viewports); +} + +VKAPI_ATTR void VKAPI_CALL CmdSetScissorWithCount(VkCommandBuffer cmd, uint32_t count, const VkRect2D *scissors) +{ + struct device *dev = device_from_handle(cmd); + dev->CmdSetScissorWithCount(cmd, count > 1 ? 1 : count, scissors); +} diff --git a/tools/venus/layer/spirv.c b/tools/venus/layer/spirv.c new file mode 100644 index 0000000000..734d5ce2d9 --- /dev/null +++ b/tools/venus/layer/spirv.c @@ -0,0 +1,833 @@ +/* + * Clip and cull distances out of SPIR-V, for a GPU without either. + * + * Stripping: every ClipDistance or CullDistance variable becomes a Private one, so the shader still + * writes and reads it but the rasterizer never sees it. Members of a gl_PerVertex block stay + * declared (as glslang declares them unused anyway) and their accesses move to a Private stand-in. + * Emulating: the last stage before rasterization writes its clip distances to a free varying + * location instead, and the fragment shader reads them there and discards when one is negative. + */ +#include "mali_compat.h" + +#include <spirv/unified1/spirv.h> +#include <stdlib.h> +#include <string.h> + +#define OPCODE(word) ((word) & 0xffffu) +#define LENGTH(word) ((word) >> 16) +#define VERSION_1_4 0x00010400u + +struct words { + uint32_t *data; + size_t count; + size_t capacity; +}; + +static void push(struct words *words, uint32_t word) +{ + if (words->count == words->capacity) { + words->capacity = words->capacity ? words->capacity * 2 : 64; + words->data = realloc(words->data, words->capacity * sizeof(uint32_t)); + } + words->data[words->count++] = word; +} + +static void emit(struct words *words, SpvOp op, size_t count, const uint32_t *operands) +{ + push(words, (uint32_t)(count + 1) << 16 | op); + for (size_t i = 0; i < count; i++) + push(words, operands[i]); +} + +#define EMIT(words, op, ...) \ + do { \ + const uint32_t operands_[] = {__VA_ARGS__}; \ + emit(words, op, sizeof(operands_) / sizeof(operands_[0]), operands_); \ + } while (0) + +enum place { BEFORE, INSTEAD, AFTER }; + +struct edit { + size_t offset; + enum place place; + struct words words; +}; + +struct new_type { + SpvOp op; + uint32_t operands[3]; + uint32_t count; + uint32_t id; +}; + +struct module { + uint32_t *w; + size_t count; + uint32_t version; + uint32_t original_bound; + uint32_t bound; + size_t *def; + size_t first_declaration; + size_t first_function; + struct edit *edits; + size_t edit_count; + struct new_type *new_types; + size_t new_type_count; + struct words globals; + uint8_t *private_ids; + uint32_t *interface_add; + size_t interface_add_count; + uint8_t *interface_remove; + bool failed; +}; + +static bool declares_result_first(uint32_t op) +{ + return (op >= SpvOpTypeVoid && op <= SpvOpTypePipe) || op == SpvOpLabel || op == SpvOpExtInstImport || + op == SpvOpString; +} + +static bool declares_result_second(uint32_t op) +{ + switch (op) { + case SpvOpConstantTrue: + case SpvOpConstantFalse: + case SpvOpConstant: + case SpvOpConstantComposite: + case SpvOpConstantNull: + case SpvOpSpecConstantTrue: + case SpvOpSpecConstantFalse: + case SpvOpSpecConstant: + case SpvOpSpecConstantComposite: + case SpvOpSpecConstantOp: + case SpvOpUndef: + case SpvOpVariable: + case SpvOpFunction: + return true; + default: + return false; + } +} + +static bool is_declaration(uint32_t op) +{ + return (op >= SpvOpTypeVoid && op <= SpvOpTypeForwardPointer) || declares_result_second(op); +} + +static void unload(struct module *m) +{ + free(m->w); + free(m->def); + for (size_t i = 0; i < m->edit_count; i++) + free(m->edits[i].words.data); + free(m->edits); + free(m->new_types); + free(m->globals.data); + free(m->private_ids); + free(m->interface_add); + free(m->interface_remove); +} + +static bool load(struct module *m, const uint32_t *words, size_t count) +{ + memset(m, 0, sizeof(*m)); + if (count < 5 || words[0] != SpvMagicNumber || words[3] == 0 || words[3] > (1u << 22)) + return false; + m->w = malloc(count * sizeof(uint32_t)); + memcpy(m->w, words, count * sizeof(uint32_t)); + m->count = count; + m->version = words[1]; + m->original_bound = m->bound = words[3]; + m->def = calloc(m->bound, sizeof(size_t)); + /* Room for every id the rewrite can add. */ + m->private_ids = calloc(m->bound + 4096, 1); + m->interface_remove = calloc(m->bound, 1); + for (size_t i = 5; i < count;) { + uint32_t length = LENGTH(m->w[i]); + uint32_t op = OPCODE(m->w[i]); + if (length == 0 || i + length > count) { + unload(m); + return false; + } + uint32_t result = 0; + if (declares_result_first(op) && length > 1) + result = m->w[i + 1]; + else if (declares_result_second(op) && length > 2) + result = m->w[i + 2]; + if (result && result < m->bound) + m->def[result] = i; + if (!m->first_declaration && is_declaration(op)) + m->first_declaration = i; + if (!m->first_function && op == SpvOpFunction) + m->first_function = i; + i += length; + } + if (!m->first_declaration || !m->first_function) { + unload(m); + return false; + } + return true; +} + +static struct words *edit(struct module *m, size_t offset, enum place place) +{ + m->edits = realloc(m->edits, (m->edit_count + 1) * sizeof(*m->edits)); + struct edit *e = &m->edits[m->edit_count++]; + *e = (struct edit){.offset = offset, .place = place}; + return &e->words; +} + +static uint32_t new_id(struct module *m) +{ + return m->bound++; +} + +static bool is_private(const struct module *m, uint32_t id) +{ + return id < m->original_bound + 4096 && m->private_ids[id]; +} + +static void mark_private(struct module *m, uint32_t id) +{ + if (id < m->original_bound + 4096) + m->private_ids[id] = 1; + else + m->failed = true; +} + +/* The defining instruction of an id from the original module, or 0. */ +static size_t definition(const struct module *m, uint32_t id) +{ + return id < m->original_bound ? m->def[id] : 0; +} + +static uint32_t find_type(struct module *m, SpvOp op, const uint32_t *operands, uint32_t count) +{ + for (size_t i = 5; i < m->first_function; i += LENGTH(m->w[i])) { + if (OPCODE(m->w[i]) == op && LENGTH(m->w[i]) == count + 2 && + !memcmp(&m->w[i + 2], operands, count * sizeof(uint32_t))) + return m->w[i + 1]; + } + for (size_t i = 0; i < m->new_type_count; i++) { + struct new_type *t = &m->new_types[i]; + if (t->op == op && t->count == count && !memcmp(t->operands, operands, count * sizeof(uint32_t))) + return t->id; + } + return 0; +} + +static uint32_t add_type(struct module *m, struct words *where, SpvOp op, const uint32_t *operands, uint32_t count) +{ + uint32_t id = new_id(m); + push(where, (count + 2) << 16 | op); + push(where, id); + for (uint32_t i = 0; i < count; i++) + push(where, operands[i]); + m->new_types = realloc(m->new_types, (m->new_type_count + 1) * sizeof(*m->new_types)); + struct new_type *t = &m->new_types[m->new_type_count++]; + *t = (struct new_type){.op = op, .count = count, .id = id}; + memcpy(t->operands, operands, count * sizeof(uint32_t)); + return id; +} + +/* Right after its pointee, so a global variable declared before the end of the types can use it. */ +static uint32_t pointer_type(struct module *m, uint32_t storage, uint32_t pointee) +{ + uint32_t operands[2] = {storage, pointee}; + uint32_t id = find_type(m, SpvOpTypePointer, operands, 2); + if (id) + return id; + size_t pointee_def = definition(m, pointee); + struct words *where = pointee_def ? edit(m, pointee_def, AFTER) : &m->globals; + return add_type(m, where, SpvOpTypePointer, operands, 2); +} + +static uint32_t scalar_type(struct module *m, SpvOp op, const uint32_t *operands, uint32_t count) +{ + uint32_t id = find_type(m, op, operands, count); + return id ? id : add_type(m, &m->globals, op, operands, count); +} + +static uint32_t float_type(struct module *m) +{ + const uint32_t width = 32; + return scalar_type(m, SpvOpTypeFloat, &width, 1); +} + +static uint32_t uint_type(struct module *m) +{ + const uint32_t operands[2] = {32, 0}; + return scalar_type(m, SpvOpTypeInt, operands, 2); +} + +static uint32_t bool_type(struct module *m) +{ + return scalar_type(m, SpvOpTypeBool, NULL, 0); +} + +static uint32_t constant(struct module *m, uint32_t type, uint32_t value) +{ + for (size_t i = 5; i < m->first_function; i += LENGTH(m->w[i])) { + if (OPCODE(m->w[i]) == SpvOpConstant && LENGTH(m->w[i]) == 4 && m->w[i + 1] == type && m->w[i + 3] == value) + return m->w[i + 2]; + } + uint32_t id = new_id(m); + EMIT(&m->globals, SpvOpConstant, type, id, value); + return id; +} + +static bool constant_value(const struct module *m, uint32_t id, uint32_t *value) +{ + size_t d = definition(m, id); + if (!d || OPCODE(m->w[d]) != SpvOpConstant || LENGTH(m->w[d]) != 4) + return false; + *value = m->w[d + 3]; + return true; +} + +/* What a pointer type points to, and where. */ +static bool pointer_parts(const struct module *m, uint32_t pointer, uint32_t *storage, uint32_t *pointee) +{ + size_t d = definition(m, pointer); + if (!d || OPCODE(m->w[d]) != SpvOpTypePointer) + return false; + *storage = m->w[d + 2]; + *pointee = m->w[d + 3]; + return true; +} + +static bool is_float32(const struct module *m, uint32_t type) +{ + size_t d = definition(m, type); + return d && OPCODE(m->w[d]) == SpvOpTypeFloat && m->w[d + 2] == 32; +} + +/* Varying locations a type takes up. */ +static uint32_t location_span(const struct module *m, uint32_t type, int depth) +{ + size_t d = definition(m, type); + if (!d || depth > 8) + return 1; + uint32_t value; + switch (OPCODE(m->w[d])) { + case SpvOpTypeArray: + return constant_value(m, m->w[d + 3], &value) ? value * location_span(m, m->w[d + 2], depth + 1) : 1; + case SpvOpTypeMatrix: + return m->w[d + 3] * location_span(m, m->w[d + 2], depth + 1); + case SpvOpTypeStruct: { + uint32_t span = 0; + for (uint32_t i = 2; i < LENGTH(m->w[d]); i++) + span += location_span(m, m->w[d + i], depth + 1); + return span; + } + case SpvOpTypeVector: { + size_t component = definition(m, m->w[d + 2]); + bool wide = component && m->w[component + 2] == 64; + return wide && m->w[d + 3] > 2 ? 2 : 1; + } + default: + return 1; + } +} + +struct distance_var { + uint32_t id; + uint32_t built_in; + uint32_t storage; + size_t decoration; +}; + +struct distance_member { + uint32_t structure; + uint32_t member; +}; + +struct analysis { + struct distance_var vars[8]; + uint32_t var_count; + struct distance_member members[8]; + uint32_t member_count; + bool member_locations; +}; + +static bool is_distance(uint32_t built_in) +{ + return built_in == SpvBuiltInClipDistance || built_in == SpvBuiltInCullDistance; +} + +static void analyze(struct module *m, struct analysis *a) +{ + memset(a, 0, sizeof(*a)); + for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) { + uint32_t op = OPCODE(m->w[i]); + if (op == SpvOpDecorate && LENGTH(m->w[i]) == 4 && m->w[i + 2] == SpvDecorationBuiltIn && + is_distance(m->w[i + 3])) { + uint32_t storage, pointee; + size_t d = definition(m, m->w[i + 1]); + if (a->var_count < 8 && d && OPCODE(m->w[d]) == SpvOpVariable && + pointer_parts(m, m->w[d + 1], &storage, &pointee)) { + a->vars[a->var_count++] = + (struct distance_var){.id = m->w[i + 1], .built_in = m->w[i + 3], .storage = storage, .decoration = i}; + } else { + m->failed = true; + } + } else if (op == SpvOpMemberDecorate && LENGTH(m->w[i]) == 5 && m->w[i + 3] == SpvDecorationBuiltIn && + is_distance(m->w[i + 4])) { + if (a->member_count < 8) + a->members[a->member_count++] = (struct distance_member){m->w[i + 1], m->w[i + 2]}; + else + m->failed = true; + } else if (op == SpvOpMemberDecorate && LENGTH(m->w[i]) >= 5 && m->w[i + 3] == SpvDecorationLocation) { + a->member_locations = true; + } + } +} + +static bool uses_distances(const uint32_t *words, size_t count) +{ + for (size_t i = 5; i + 1 < count && LENGTH(words[i]); i += LENGTH(words[i])) { + uint32_t op = OPCODE(words[i]); + if (op == SpvOpCapability && (words[i + 1] == SpvCapabilityClipDistance || words[i + 1] == SpvCapabilityCullDistance)) + return true; + if (op != SpvOpCapability && op != SpvOpExtension && op != SpvOpExtInstImport && op != SpvOpMemoryModel) + break; + } + return false; +} + +bool spirv_uses_distances(const uint32_t *words, size_t count) +{ + return count > 5 && words[0] == SpvMagicNumber && uses_distances(words, count); +} + +static void remove_capabilities(struct module *m) +{ + for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) { + if (OPCODE(m->w[i]) == SpvOpCapability && + (m->w[i + 1] == SpvCapabilityClipDistance || m->w[i + 1] == SpvCapabilityCullDistance)) + edit(m, i, INSTEAD); + } +} + +static void add_to_interface(struct module *m, uint32_t id) +{ + m->interface_add = realloc(m->interface_add, (m->interface_add_count + 1) * sizeof(uint32_t)); + m->interface_add[m->interface_add_count++] = id; +} + +/* A standalone distance variable becomes Private, and its decorations go. */ +static void privatize(struct module *m, const struct distance_var *var) +{ + size_t d = definition(m, var->id); + uint32_t storage, pointee; + pointer_parts(m, m->w[d + 1], &storage, &pointee); + m->w[d + 1] = pointer_type(m, SpvStorageClassPrivate, pointee); + m->w[d + 3] = SpvStorageClassPrivate; + mark_private(m, var->id); + /* Before SPIR-V 1.4 an entry point lists only its inputs and outputs. */ + if (m->version < VERSION_1_4) + m->interface_remove[var->id] = 1; + for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) { + if (OPCODE(m->w[i]) == SpvOpDecorate && m->w[i + 1] == var->id) + edit(m, i, INSTEAD); + } +} + +struct block_var { + uint32_t id; + uint32_t structure; + bool arrayed; + uint32_t array_length; +}; + +struct stand_in { + uint32_t block; + uint32_t member; + uint32_t variable; +}; + +/* Every variable of a block type with a distance member, and a Private stand-in per member. */ +static uint32_t make_stand_ins(struct module *m, const struct analysis *a, struct stand_in *stand_ins, uint32_t max) +{ + uint32_t count = 0; + for (size_t i = m->first_declaration; i < m->first_function; i += LENGTH(m->w[i])) { + if (OPCODE(m->w[i]) != SpvOpVariable) + continue; + uint32_t storage, pointee; + if (!pointer_parts(m, m->w[i + 1], &storage, &pointee)) + continue; + struct block_var var = {.id = m->w[i + 2], .structure = pointee}; + size_t d = definition(m, pointee); + if (d && OPCODE(m->w[d]) == SpvOpTypeArray) { + var.arrayed = true; + var.structure = m->w[d + 2]; + var.array_length = m->w[d + 3]; + } + for (uint32_t k = 0; k < a->member_count; k++) { + if (a->members[k].structure != var.structure) + continue; + if (count == max) { + m->failed = true; + return count; + } + size_t s = definition(m, var.structure); + uint32_t member_type = m->w[s + 2 + a->members[k].member]; + uint32_t type = member_type; + if (var.arrayed) { + const uint32_t operands[2] = {member_type, var.array_length}; + type = add_type(m, &m->globals, SpvOpTypeArray, operands, 2); + } + uint32_t variable = new_id(m); + EMIT(&m->globals, SpvOpVariable, pointer_type(m, SpvStorageClassPrivate, type), variable, + SpvStorageClassPrivate); + if (m->version >= VERSION_1_4) + add_to_interface(m, variable); + stand_ins[count++] = (struct stand_in){var.id, a->members[k].member, variable}; + } + } + return count; +} + +static const struct stand_in *find_stand_in(const struct module *m, const struct stand_in *stand_ins, uint32_t count, + uint32_t base, uint32_t member_index) +{ + uint32_t member; + if (!constant_value(m, member_index, &member)) + return NULL; + for (uint32_t i = 0; i < count; i++) { + if (stand_ins[i].block == base && stand_ins[i].member == member) + return &stand_ins[i]; + } + return NULL; +} + +static bool is_arrayed_block(const struct module *m, uint32_t variable) +{ + size_t d = definition(m, variable); + uint32_t storage, pointee; + if (!d || !pointer_parts(m, m->w[d + 1], &storage, &pointee)) + return false; + size_t p = definition(m, pointee); + return p && OPCODE(m->w[p]) == SpvOpTypeArray; +} + +/* + * One pass over the function bodies: accesses to a distance member go to its stand-in, and every + * pointer derived from a Private one becomes Private too. A Private pointer handed to a function + * or merged through a phi would need its types changed beyond this, so that fails the rewrite. + */ +static void retarget_accesses(struct module *m, const struct stand_in *stand_ins, uint32_t stand_in_count) +{ + for (size_t i = m->first_function; i < m->count; i += LENGTH(m->w[i])) { + uint32_t op = OPCODE(m->w[i]); + uint32_t length = LENGTH(m->w[i]); + switch (op) { + case SpvOpAccessChain: + case SpvOpInBoundsAccessChain: { + uint32_t base = m->w[i + 3]; + bool arrayed = is_arrayed_block(m, base); + uint32_t member_position = arrayed ? 5 : 4; + const struct stand_in *stand_in = + length > member_position + ? find_stand_in(m, stand_ins, stand_in_count, base, m->w[i + member_position]) + : NULL; + uint32_t storage, pointee; + if (stand_in) { + if (!pointer_parts(m, m->w[i + 1], &storage, &pointee)) { + m->failed = true; + break; + } + /* Before edit(): a new pointer type is an edit too, and would move the chain's buffer. */ + uint32_t type = pointer_type(m, SpvStorageClassPrivate, pointee); + struct words *chain = edit(m, i, INSTEAD); + push(chain, (length - 1) << 16 | op); + push(chain, type); + push(chain, m->w[i + 2]); + push(chain, stand_in->variable); + for (uint32_t k = 4; k < length; k++) { + if (k != member_position) + push(chain, m->w[i + k]); + } + mark_private(m, m->w[i + 2]); + } else if (is_private(m, base)) { + if (!pointer_parts(m, m->w[i + 1], &storage, &pointee)) { + m->failed = true; + break; + } + m->w[i + 1] = pointer_type(m, SpvStorageClassPrivate, pointee); + mark_private(m, m->w[i + 2]); + } + break; + } + case SpvOpPtrAccessChain: + case SpvOpCopyObject: + if (is_private(m, m->w[i + 3])) { + uint32_t storage, pointee; + if (!pointer_parts(m, m->w[i + 1], &storage, &pointee)) { + m->failed = true; + break; + } + m->w[i + 1] = pointer_type(m, SpvStorageClassPrivate, pointee); + mark_private(m, m->w[i + 2]); + } + break; + case SpvOpFunctionCall: + for (uint32_t k = 4; k < length; k++) { + if (is_private(m, m->w[i + k])) + m->failed = true; + } + break; + case SpvOpPhi: + case SpvOpSelect: + for (uint32_t k = 3; k < length; k++) { + if (is_private(m, m->w[i + k])) + m->failed = true; + } + break; + default: + break; + } + } +} + +static uint32_t string_words(const uint32_t *words, uint32_t available) +{ + for (uint32_t i = 0; i < available; i++) { + uint32_t word = words[i]; + if (!(word & 0xff) || !(word & 0xff00) || !(word & 0xff0000) || !(word & 0xff000000)) + return i + 1; + } + return available; +} + +static void rewrite_interfaces(struct module *m) +{ + for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) { + if (OPCODE(m->w[i]) != SpvOpEntryPoint) + continue; + uint32_t length = LENGTH(m->w[i]); + uint32_t first = 3 + string_words(&m->w[i + 3], length - 3); + struct words *entry = edit(m, i, INSTEAD); + push(entry, 0); + for (uint32_t k = 1; k < first; k++) + push(entry, m->w[i + k]); + for (uint32_t k = first; k < length; k++) { + uint32_t id = m->w[i + k]; + if (id >= m->original_bound || !m->interface_remove[id]) + push(entry, id); + } + for (size_t k = 0; k < m->interface_add_count; k++) + push(entry, m->interface_add[k]); + entry->data[0] = (uint32_t)entry->count << 16 | SpvOpEntryPoint; + } +} + +static void emit_edits(const struct module *m, struct words *out, size_t offset, enum place place, bool *replaced) +{ + for (size_t k = 0; k < m->edit_count; k++) { + const struct edit *e = &m->edits[k]; + if (e->offset != offset || e->place != place) + continue; + for (size_t j = 0; j < e->words.count; j++) + push(out, e->words.data[j]); + if (replaced) + *replaced = true; + } +} + +static bool finish(struct module *m, struct spirv_code *out) +{ + if (m->failed) + return false; + rewrite_interfaces(m); + struct words result = {0}; + for (int i = 0; i < 5; i++) + push(&result, m->w[i]); + result.data[3] = m->bound; + for (size_t i = 5; i < m->count; i += LENGTH(m->w[i])) { + if (i == m->first_function) { + for (size_t j = 0; j < m->globals.count; j++) + push(&result, m->globals.data[j]); + } + emit_edits(m, &result, i, BEFORE, NULL); + bool replaced = false; + emit_edits(m, &result, i, INSTEAD, &replaced); + if (!replaced) { + for (uint32_t j = 0; j < LENGTH(m->w[i]); j++) + push(&result, m->w[i + j]); + } + emit_edits(m, &result, i, AFTER, NULL); + } + out->words = result.data; + out->count = result.count; + return true; +} + +static void strip(struct module *m, const struct analysis *a, uint32_t keep) +{ + for (uint32_t i = 0; i < a->var_count; i++) { + if (a->vars[i].id != keep) + privatize(m, &a->vars[i]); + } + struct stand_in stand_ins[16]; + uint32_t count = make_stand_ins(m, a, stand_ins, 16); + retarget_accesses(m, stand_ins, count); + remove_capabilities(m); +} + +bool spirv_strip_distances(const uint32_t *words, size_t count, struct spirv_code *out) +{ + struct module m; + if (!load(&m, words, count)) + return false; + struct analysis a; + analyze(&m, &a); + strip(&m, &a, 0); + bool done = finish(&m, out); + unload(&m); + return done; +} + +static const struct distance_var *clip_output(const struct module *m, const struct analysis *a, uint32_t *length) +{ + for (uint32_t i = 0; i < a->var_count; i++) { + const struct distance_var *var = &a->vars[i]; + if (var->built_in != SpvBuiltInClipDistance || var->storage != SpvStorageClassOutput) + continue; + uint32_t storage, pointee; + pointer_parts(m, m->w[definition(m, var->id) + 1], &storage, &pointee); + size_t d = definition(m, pointee); + if (d && OPCODE(m->w[d]) == SpvOpTypeArray && is_float32(m, m->w[d + 2]) && + constant_value(m, m->w[d + 3], length)) + return var; + } + return NULL; +} + +void spirv_clip_info(const uint32_t *words, size_t count, enum clip_role role, struct clip_info *info) +{ + memset(info, 0, sizeof(*info)); + struct module m; + if (!load(&m, words, count)) { + info->locations_used = UINT32_MAX; + return; + } + struct analysis a; + analyze(&m, &a); + if (role == CLIP_PRODUCER) + info->has_clip = clip_output(&m, &a, &info->clip_count) != NULL; + uint32_t storage_wanted = role == CLIP_PRODUCER ? SpvStorageClassOutput : SpvStorageClassInput; + for (size_t i = 5; i < m.first_declaration; i += LENGTH(m.w[i])) { + if (OPCODE(m.w[i]) != SpvOpDecorate || LENGTH(m.w[i]) != 4 || m.w[i + 2] != SpvDecorationLocation) + continue; + size_t d = definition(&m, m.w[i + 1]); + uint32_t storage, pointee; + if (!d || OPCODE(m.w[d]) != SpvOpVariable || !pointer_parts(&m, m.w[d + 1], &storage, &pointee) || + storage != storage_wanted) + continue; + uint32_t end = m.w[i + 3] + location_span(&m, pointee, 0); + if (end > info->locations_used) + info->locations_used = end; + } + if (a.member_locations || m.failed) + info->locations_used = UINT32_MAX; + unload(&m); +} + +/* Fragment shader: read the clip distances at `location` and discard when any is negative. */ +static void add_clip_test(struct module *m, uint32_t location, uint32_t clip_count) +{ + uint32_t float_id = float_type(m); + uint32_t uint_id = uint_type(m); + uint32_t bool_id = bool_type(m); + const uint32_t array_operands[2] = {float_id, constant(m, uint_id, clip_count)}; + uint32_t array_id = add_type(m, &m->globals, SpvOpTypeArray, array_operands, 2); + uint32_t input_pointer = pointer_type(m, SpvStorageClassInput, array_id); + uint32_t element_pointer = pointer_type(m, SpvStorageClassInput, float_id); + uint32_t zero = constant(m, float_id, 0); + uint32_t indices[8]; + for (uint32_t i = 0; i < clip_count; i++) + indices[i] = constant(m, uint_id, i); + uint32_t input = new_id(m); + EMIT(&m->globals, SpvOpVariable, input_pointer, input, SpvStorageClassInput); + EMIT(edit(m, m->first_declaration, BEFORE), SpvOpDecorate, input, SpvDecorationLocation, location); + add_to_interface(m, input); + + for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) { + if (OPCODE(m->w[i]) != SpvOpEntryPoint || m->w[i + 1] != SpvExecutionModelFragment) + continue; + size_t function = definition(m, m->w[i + 2]); + if (!function) { + m->failed = true; + return; + } + size_t label = function + LENGTH(m->w[function]); + if (label >= m->count || OPCODE(m->w[label]) != SpvOpLabel) { + m->failed = true; + return; + } + /* Function variables must open the entry block, so the test goes after them. */ + size_t last = label; + for (size_t k = label + LENGTH(m->w[label]); k < m->count; k += LENGTH(m->w[k])) { + uint32_t op = OPCODE(m->w[k]); + if (op != SpvOpVariable && op != SpvOpLine && op != SpvOpNoLine) + break; + last = k; + } + uint32_t original_label = m->w[label + 1]; + uint32_t entry = new_id(m), kill = new_id(m), join = new_id(m); + EMIT(edit(m, label, INSTEAD), SpvOpLabel, entry); + struct words *test = edit(m, last, AFTER); + uint32_t any = 0; + for (uint32_t c = 0; c < clip_count; c++) { + uint32_t pointer = new_id(m), value = new_id(m), negative = new_id(m); + EMIT(test, SpvOpAccessChain, element_pointer, pointer, input, indices[c]); + EMIT(test, SpvOpLoad, float_id, value, pointer); + EMIT(test, SpvOpFOrdLessThan, bool_id, negative, value, zero); + if (any) { + uint32_t either = new_id(m); + EMIT(test, SpvOpLogicalOr, bool_id, either, any, negative); + any = either; + } else { + any = negative; + } + } + EMIT(test, SpvOpSelectionMerge, join, SpvSelectionControlMaskNone); + EMIT(test, SpvOpBranchConditional, any, kill, join); + EMIT(test, SpvOpLabel, kill); + push(test, 1u << 16 | SpvOpKill); + EMIT(test, SpvOpLabel, join); + EMIT(test, SpvOpBranch, original_label); + EMIT(test, SpvOpLabel, original_label); + } +} + +bool spirv_emulate_clip(const uint32_t *words, size_t count, enum clip_role role, uint32_t location, + uint32_t clip_count, struct spirv_code *out) +{ + if (clip_count == 0 || clip_count > 8) + return false; + struct module m; + if (!load(&m, words, count)) + return false; + struct analysis a; + analyze(&m, &a); + uint32_t keep = 0; + if (role == CLIP_PRODUCER) { + uint32_t length = 0; + const struct distance_var *clip = clip_output(&m, &a, &length); + if (!clip || length != clip_count) { + unload(&m); + return false; + } + keep = clip->id; + m.w[clip->decoration + 2] = SpvDecorationLocation; + m.w[clip->decoration + 3] = location; + } + strip(&m, &a, keep); + if (role == CLIP_CONSUMER) + add_clip_test(&m, location, clip_count); + bool done = finish(&m, out); + unload(&m); + return done; +} diff --git a/tools/venus/layer/trace.c b/tools/venus/layer/trace.c new file mode 100644 index 0000000000..f02bab5c9e --- /dev/null +++ b/tools/venus/layer/trace.c @@ -0,0 +1,233 @@ +/* + * DROIDDECK_MALI_COMPAT_TRACE=1: the physical-device queries an application makes before + * vkCreateDevice, logged as they pass through. Zink on Venus over an older Mali driver gave up + * after vkGetPhysicalDeviceProperties2 without a word (its release builds print nothing there), + * so the last query in the log is where it stopped. + */ +#include "mali_compat.h" + +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static uint32_t format_queries; + +static bool format_worth_logging(uint32_t n, VkFormatFeatureFlags linear, VkFormatFeatureFlags optimal, VkFormatFeatureFlags buffer) +{ + return n == 1 || n % 25 == 0 || (!linear && !optimal && !buffer); +} + +static VKAPI_ATTR VkResult VKAPI_CALL TraceEnumeratePhysicalDevices(VkInstance instance, uint32_t *count, VkPhysicalDevice *devices) +{ + struct instance *inst = instance_from_handle(instance); + VkResult r = inst->EnumeratePhysicalDevices(instance, count, devices); + layer_log("trace: vkEnumeratePhysicalDevices (%s): %d, %u device(s)", devices ? "list" : "count", (int)r, count ? *count : 0); + return r; +} + +static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceMemoryProperties(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties *p) +{ + struct instance *inst = instance_from_handle(pd); + inst->GetPhysicalDeviceMemoryProperties(pd, p); + char types[384] = ""; + size_t o = 0; + for (uint32_t i = 0; i < p->memoryTypeCount && o + 16 < sizeof(types); i++) + o += (size_t)snprintf(types + o, sizeof(types) - o, " %u:h%u/0x%x", i, p->memoryTypes[i].heapIndex, + (unsigned)p->memoryTypes[i].propertyFlags); + layer_log("trace: vkGetPhysicalDeviceMemoryProperties: %u heaps, %u types:%s", p->memoryHeapCount, p->memoryTypeCount, types); +} + +static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceMemoryProperties2(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties2 *p) +{ + struct instance *inst = instance_from_handle(pd); + inst->GetPhysicalDeviceMemoryProperties2(pd, p); + char chain[160] = ""; + size_t o = 0; + for (VkBaseOutStructure *s = p->pNext; s && o + 16 < sizeof(chain); s = s->pNext) + o += (size_t)snprintf(chain + o, sizeof(chain) - o, " %d", (int)s->sType); + layer_log("trace: vkGetPhysicalDeviceMemoryProperties2: %u heaps, %u types, chain:%s", p->memoryProperties.memoryHeapCount, + p->memoryProperties.memoryTypeCount, chain); +} + +static void log_queue_families(const char *what, uint32_t n, const VkQueueFamilyProperties *(*at)(const void *, uint32_t), const void *arr) +{ + char fams[256] = ""; + size_t o = 0; + for (uint32_t i = 0; arr && i < n && o + 24 < sizeof(fams); i++) { + const VkQueueFamilyProperties *q = at(arr, i); + o += (size_t)snprintf(fams + o, sizeof(fams) - o, " %u:0x%x*%u", i, (unsigned)q->queueFlags, q->queueCount); + } + layer_log("trace: %s: %u famil%s%s", what, n, n == 1 ? "y" : "ies", fams); +} + +static const VkQueueFamilyProperties *qf1(const void *a, uint32_t i) { return &((const VkQueueFamilyProperties *)a)[i]; } +static const VkQueueFamilyProperties *qf2(const void *a, uint32_t i) { return &((const VkQueueFamilyProperties2 *)a)[i].queueFamilyProperties; } + +static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice pd, uint32_t *n, VkQueueFamilyProperties *p) +{ + struct instance *inst = instance_from_handle(pd); + inst->GetPhysicalDeviceQueueFamilyProperties(pd, n, p); + log_queue_families("vkGetPhysicalDeviceQueueFamilyProperties", n ? *n : 0, qf1, p); +} + +static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice pd, uint32_t *n, VkQueueFamilyProperties2 *p) +{ + struct instance *inst = instance_from_handle(pd); + inst->GetPhysicalDeviceQueueFamilyProperties2(pd, n, p); + log_queue_families("vkGetPhysicalDeviceQueueFamilyProperties2", n ? *n : 0, qf2, p); +} + +static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceFormatProperties(VkPhysicalDevice pd, VkFormat format, VkFormatProperties *p) +{ + struct instance *inst = instance_from_handle(pd); + if (inst->active) GetPhysicalDeviceFormatProperties(pd, format, p); + else inst->GetPhysicalDeviceFormatProperties(pd, format, p); + uint32_t n = __atomic_add_fetch(&format_queries, 1, __ATOMIC_RELAXED); + if (format_worth_logging(n, p->linearTilingFeatures, p->optimalTilingFeatures, p->bufferFeatures)) + layer_log("trace: vkGetPhysicalDeviceFormatProperties #%u: format %d linear 0x%x optimal 0x%x buffer 0x%x", n, (int)format, + (unsigned)p->linearTilingFeatures, (unsigned)p->optimalTilingFeatures, (unsigned)p->bufferFeatures); +} + +static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceFormatProperties2(VkPhysicalDevice pd, VkFormat format, VkFormatProperties2 *p) +{ + struct instance *inst = instance_from_handle(pd); + if (inst->active) GetPhysicalDeviceFormatProperties2(pd, format, p); + else inst->GetPhysicalDeviceFormatProperties2(pd, format, p); + uint32_t n = __atomic_add_fetch(&format_queries, 1, __ATOMIC_RELAXED); + const VkFormatProperties *f = &p->formatProperties; + if (format_worth_logging(n, f->linearTilingFeatures, f->optimalTilingFeatures, f->bufferFeatures)) + layer_log("trace: vkGetPhysicalDeviceFormatProperties2 #%u: format %d linear 0x%x optimal 0x%x buffer 0x%x", n, (int)format, + (unsigned)f->linearTilingFeatures, (unsigned)f->optimalTilingFeatures, (unsigned)f->bufferFeatures); +} + +static VKAPI_ATTR VkResult VKAPI_CALL TraceGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice pd, VkFormat format, VkImageType type, + VkImageTiling tiling, VkImageUsageFlags usage, + VkImageCreateFlags flags, VkImageFormatProperties *p) +{ + struct instance *inst = instance_from_handle(pd); + VkResult r = inst->active ? GetPhysicalDeviceImageFormatProperties(pd, format, type, tiling, usage, flags, p) + : inst->GetPhysicalDeviceImageFormatProperties(pd, format, type, tiling, usage, flags, p); + if (r != VK_SUCCESS) + layer_log("trace: vkGetPhysicalDeviceImageFormatProperties: format %d type %d tiling %d usage 0x%x flags 0x%x -> %d", (int)format, + (int)type, (int)tiling, (unsigned)usage, (unsigned)flags, (int)r); + return r; +} + +static VKAPI_ATTR VkResult VKAPI_CALL TraceGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice pd, const VkPhysicalDeviceImageFormatInfo2 *info, + VkImageFormatProperties2 *p) +{ + struct instance *inst = instance_from_handle(pd); + VkResult r = inst->active ? GetPhysicalDeviceImageFormatProperties2(pd, info, p) : inst->GetPhysicalDeviceImageFormatProperties2(pd, info, p); + if (r != VK_SUCCESS) + layer_log("trace: vkGetPhysicalDeviceImageFormatProperties2: format %d type %d tiling %d usage 0x%x flags 0x%x -> %d", (int)info->format, + (int)info->type, (int)info->tiling, (unsigned)info->usage, (unsigned)info->flags, (int)r); + return r; +} + +static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice pd, const VkPhysicalDeviceExternalBufferInfo *info, + VkExternalBufferProperties *p) +{ + struct instance *inst = instance_from_handle(pd); + inst->GetPhysicalDeviceExternalBufferProperties(pd, info, p); + layer_log("trace: vkGetPhysicalDeviceExternalBufferProperties: handle 0x%x usage 0x%x -> features 0x%x", (unsigned)info->handleType, + (unsigned)info->usage, (unsigned)p->externalMemoryProperties.externalMemoryFeatures); +} + +static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice pd, + const VkPhysicalDeviceExternalSemaphoreInfo *info, + VkExternalSemaphoreProperties *p) +{ + struct instance *inst = instance_from_handle(pd); + inst->GetPhysicalDeviceExternalSemaphoreProperties(pd, info, p); + layer_log("trace: vkGetPhysicalDeviceExternalSemaphoreProperties: handle 0x%x -> features 0x%x", (unsigned)info->handleType, + (unsigned)p->externalSemaphoreFeatures); +} + +static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice pd, const VkPhysicalDeviceExternalFenceInfo *info, + VkExternalFenceProperties *p) +{ + struct instance *inst = instance_from_handle(pd); + inst->GetPhysicalDeviceExternalFenceProperties(pd, info, p); + layer_log("trace: vkGetPhysicalDeviceExternalFenceProperties: handle 0x%x -> features 0x%x", (unsigned)info->handleType, + (unsigned)p->externalFenceFeatures); +} + +void trace_extension_names(const VkExtensionProperties *ext, uint32_t n) +{ + char line[400]; + size_t o = 0; + line[0] = 0; + for (uint32_t i = 0; i < n; i++) { + size_t len = strlen(ext[i].extensionName); + if (o && o + len + 2 > sizeof(line)) { + layer_log("trace: extensions:%s", line); + o = 0; + line[0] = 0; + } + o += (size_t)snprintf(line + o, sizeof(line) - o, " %s", ext[i].extensionName); + } + if (o) layer_log("trace: extensions:%s", line); +} + +void trace_load(struct instance *inst) +{ +#define T_LOAD(name) inst->name = (PFN_vk##name)inst->gipa(inst->handle, "vk" #name); +#define T_LOAD_KHR(name) \ + if (!inst->name) \ + inst->name = (PFN_vk##name)inst->gipa(inst->handle, "vk" #name "KHR"); + T_LOAD(EnumeratePhysicalDevices) + T_LOAD(GetPhysicalDeviceMemoryProperties2) + T_LOAD_KHR(GetPhysicalDeviceMemoryProperties2) + T_LOAD(GetPhysicalDeviceQueueFamilyProperties) + T_LOAD(GetPhysicalDeviceQueueFamilyProperties2) + T_LOAD_KHR(GetPhysicalDeviceQueueFamilyProperties2) + T_LOAD(GetPhysicalDeviceExternalBufferProperties) + T_LOAD_KHR(GetPhysicalDeviceExternalBufferProperties) + T_LOAD(GetPhysicalDeviceExternalSemaphoreProperties) + T_LOAD_KHR(GetPhysicalDeviceExternalSemaphoreProperties) + T_LOAD(GetPhysicalDeviceExternalFenceProperties) + T_LOAD_KHR(GetPhysicalDeviceExternalFenceProperties) +#undef T_LOAD +#undef T_LOAD_KHR +} + +struct trace_hook { + const char *name; + PFN_vkVoidFunction function; + size_t next_offset; +}; + +#define TH(fn, field) {"vk" #fn, (PFN_vkVoidFunction)Trace##field, offsetof(struct instance, field)} + +static const struct trace_hook trace_hooks[] = { + TH(EnumeratePhysicalDevices, EnumeratePhysicalDevices), + TH(GetPhysicalDeviceMemoryProperties, GetPhysicalDeviceMemoryProperties), + TH(GetPhysicalDeviceMemoryProperties2, GetPhysicalDeviceMemoryProperties2), + TH(GetPhysicalDeviceMemoryProperties2KHR, GetPhysicalDeviceMemoryProperties2), + TH(GetPhysicalDeviceQueueFamilyProperties, GetPhysicalDeviceQueueFamilyProperties), + TH(GetPhysicalDeviceQueueFamilyProperties2, GetPhysicalDeviceQueueFamilyProperties2), + TH(GetPhysicalDeviceQueueFamilyProperties2KHR, GetPhysicalDeviceQueueFamilyProperties2), + TH(GetPhysicalDeviceFormatProperties, GetPhysicalDeviceFormatProperties), + TH(GetPhysicalDeviceFormatProperties2, GetPhysicalDeviceFormatProperties2), + TH(GetPhysicalDeviceFormatProperties2KHR, GetPhysicalDeviceFormatProperties2), + TH(GetPhysicalDeviceImageFormatProperties, GetPhysicalDeviceImageFormatProperties), + TH(GetPhysicalDeviceImageFormatProperties2, GetPhysicalDeviceImageFormatProperties2), + TH(GetPhysicalDeviceImageFormatProperties2KHR, GetPhysicalDeviceImageFormatProperties2), + TH(GetPhysicalDeviceExternalBufferProperties, GetPhysicalDeviceExternalBufferProperties), + TH(GetPhysicalDeviceExternalBufferPropertiesKHR, GetPhysicalDeviceExternalBufferProperties), + TH(GetPhysicalDeviceExternalSemaphoreProperties, GetPhysicalDeviceExternalSemaphoreProperties), + TH(GetPhysicalDeviceExternalSemaphorePropertiesKHR, GetPhysicalDeviceExternalSemaphoreProperties), + TH(GetPhysicalDeviceExternalFenceProperties, GetPhysicalDeviceExternalFenceProperties), + TH(GetPhysicalDeviceExternalFencePropertiesKHR, GetPhysicalDeviceExternalFenceProperties), +}; + +PFN_vkVoidFunction trace_hook(struct instance *inst, const char *name) +{ + for (size_t i = 0; i < sizeof(trace_hooks) / sizeof(trace_hooks[0]); i++) { + if (strcmp(name, trace_hooks[i].name)) continue; + void *next = *(void **)((char *)inst + trace_hooks[i].next_offset); + return next ? trace_hooks[i].function : NULL; + } + return NULL; +} diff --git a/tools/venus/measure-present.patch b/tools/venus/measure-present.patch new file mode 100644 index 0000000000..5d8eb87cf5 --- /dev/null +++ b/tools/venus/measure-present.patch @@ -0,0 +1,153 @@ +diff --git a/src/virtio/vulkan/vn_wsi.c b/src/virtio/vulkan/vn_wsi.c +index f0b41b1..5c08312 100644 +--- a/src/virtio/vulkan/vn_wsi.c ++++ b/src/virtio/vulkan/vn_wsi.c +@@ -23,6 +23,33 @@ + #define DRM_FORMAT_MOD_LINEAR 0 + #endif + ++/* MEASURE: async present costs, logged every 120 presents. */ ++static struct { ++ uint32_t presents, fence_waits, flushes; ++ int64_t present_sum, present_max, fence_sum, fence_max, flush_sum, flush_max; ++} vn_measure; ++ ++#define VN_MEASURE_ADD(name, ns) \ ++ do { \ ++ vn_measure.name##_sum += (ns); \ ++ vn_measure.name##_max = MAX2(vn_measure.name##_max, (ns)); \ ++ } while (0) ++ ++static void ++vn_measure_present(int64_t ns) ++{ ++ VN_MEASURE_ADD(present, ns); ++ if (++vn_measure.presents < 120) ++ return; ++ fprintf(stderr, "MEASURE vn: present thread %.2f/%.2f ms | fence wait %.2f/%.2f ms (%u) | app blocked in flush %.2f/%.2f ms (%u)\n", ++ vn_measure.present_sum / 120 / 1e6, vn_measure.present_max / 1e6, ++ vn_measure.fence_waits ? vn_measure.fence_sum / vn_measure.fence_waits / 1e6 : 0.0, ++ vn_measure.fence_max / 1e6, vn_measure.fence_waits, ++ vn_measure.flushes ? vn_measure.flush_sum / vn_measure.flushes / 1e6 : 0.0, ++ vn_measure.flush_max / 1e6, vn_measure.flushes); ++ memset(&vn_measure, 0, sizeof(vn_measure)); ++} ++ + /* The common WSI support makes some assumptions about the driver. + * + * In wsi_device_init, it assumes VK_EXT_pci_bus_info is available. In +@@ -331,6 +358,7 @@ vn_wsi_memory_type_index(const struct vn_device *dev, + !(type_bits & BITFIELD_BIT(readback_type))) + return alloc_info->memoryTypeIndex; + ++ fprintf(stderr, "MEASURE vn: WSI readback buffer in memory type %d\n", readback_type); + return readback_type; + } + +@@ -479,8 +507,11 @@ vn_wsi_fence_wait(VkQueue queue_handle) + simple_mtx_unlock(&queue->async_present.queue_mutex); + vn_wsi_chains_unlock(dev, queue->async_present.info, /*all=*/false); + ++ int64_t measure_start = os_time_get_nano(); + result = vn_WaitForFences(dev_handle, 1, &queue->async_present.fence, true, + UINT64_MAX); ++ VN_MEASURE_ADD(fence, os_time_get_nano() - measure_start); ++ vn_measure.fence_waits++; + + vn_wsi_chains_lock(dev, queue->async_present.info, /*all=*/false); + if (can_unlock_queue) +@@ -537,8 +568,11 @@ vn_wsi_flush(VkQueue queue_handle) + /* Being able to acquire the lock ensures async present queue access + * has completed. + */ ++ int64_t measure_start = os_time_get_nano(); + simple_mtx_lock(&queue->async_present.queue_mutex); + simple_mtx_unlock(&queue->async_present.queue_mutex); ++ VN_MEASURE_ADD(flush, os_time_get_nano() - measure_start); ++ vn_measure.flushes++; + } + + static VkPresentInfoKHR * +@@ -811,9 +845,11 @@ vn_wsi_present_thread(void *data) + + queue->async_present.pending = false; + ++ int64_t measure_start = os_time_get_nano(); + queue->async_present.result = + wsi_common_queue_present(queue_vk->base.device->physical->wsi_device, + queue_vk, queue->async_present.info); ++ vn_measure_present(os_time_get_nano() - measure_start); + + vn_wsi_chains_unlock(dev, queue->async_present.info, /*all=*/true); + simple_mtx_unlock(&queue->async_present.queue_mutex); +diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c +index 047c8b3..a153a39 100644 +--- a/src/vulkan/wsi/wsi_common_wayland.c ++++ b/src/vulkan/wsi/wsi_common_wayland.c +@@ -3277,6 +3277,38 @@ set_timestamp(struct wsi_wl_swapchain *chain, + return true; + } + ++/* MEASURE: per-frame cost of the shm copy, logged every 120 presents. */ ++static struct { ++ uint32_t frames; ++ int64_t last_present, interval_sum, interval_max, copy_sum, copy_max, total_sum, total_max; ++} wl_measure; ++ ++static void ++wl_measure_frame(struct wsi_wl_swapchain *chain, int64_t start, int64_t copy_ns, int64_t end) ++{ ++ if (wl_measure.last_present) { ++ int64_t interval = start - wl_measure.last_present; ++ wl_measure.interval_sum += interval; ++ wl_measure.interval_max = MAX2(wl_measure.interval_max, interval); ++ } ++ wl_measure.last_present = start; ++ wl_measure.copy_sum += copy_ns; ++ wl_measure.copy_max = MAX2(wl_measure.copy_max, copy_ns); ++ wl_measure.total_sum += end - start; ++ wl_measure.total_max = MAX2(wl_measure.total_max, end - start); ++ if (++wl_measure.frames < 120) ++ return; ++ fprintf(stderr, "MEASURE wl: %ux%u type %d | interval %.2f/%.2f ms | copy %.2f/%.2f ms (%u KB) | present %.2f/%.2f ms\n", ++ chain->extent.width, chain->extent.height, chain->buffer_type, ++ wl_measure.interval_sum / 119 / 1e6, wl_measure.interval_max / 1e6, ++ wl_measure.copy_sum / 120 / 1e6, wl_measure.copy_max / 1e6, ++ chain->images[0].base.row_pitches[0] * chain->extent.height / 1024, ++ wl_measure.total_sum / 120 / 1e6, wl_measure.total_max / 1e6); ++ int64_t last = wl_measure.last_present; ++ memset(&wl_measure, 0, sizeof(wl_measure)); ++ wl_measure.last_present = last; ++} ++ + static VkResult + wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain, + uint32_t image_index, +@@ -3286,6 +3318,7 @@ wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain, + struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)wsi_chain; + bool timestamped = false; + bool queue_dispatched = false; ++ int64_t measure_start = os_time_get_nano(), measure_copy = 0; + + MESA_TRACE_FUNC_FLOW(&chain->images[image_index].wayland_buffer.flow); + +@@ -3314,9 +3347,11 @@ wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain, + + if (chain->buffer_type == WSI_WL_BUFFER_SHM_MEMCPY) { + struct wsi_wl_image *image = &chain->images[image_index]; ++ int64_t copy_start = os_time_get_nano(); + wsi_image_invalidate_cpu_map(&chain->base, &image->base); + memcpy(image->shm_ptr, image->base.cpu_map, + image->base.row_pitches[0] * chain->extent.height); ++ measure_copy = os_time_get_nano() - copy_start; + } + + VkResult ret = wsi_wl_swapchain_update_colorspace(chain); +@@ -3515,6 +3550,7 @@ wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain, + + memset(&chain->timing_request, 0, sizeof(chain->timing_request)); + ++ wl_measure_frame(chain, measure_start, measure_copy, os_time_get_nano()); + return VK_SUCCESS; + } + diff --git a/tools/venus/memtypes.c b/tools/venus/memtypes.c new file mode 100644 index 0000000000..39520298a4 --- /dev/null +++ b/tools/venus/memtypes.c @@ -0,0 +1,40 @@ +// Prints the system Vulkan driver's memory types and heaps, as Android apps see them; Venus +// rewrites them for the guest. Build in WSL and run over ADB (from Git Bash, MSYS_NO_PATHCONV=1): +// /home/delo/android-sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android31-clang \ +// -O1 -o memtypes memtypes.c -lvulkan +// adb push memtypes /data/local/tmp/ && adb shell "chmod 755 /data/local/tmp/memtypes && /data/local/tmp/memtypes" +#include <stdio.h> +#include <vulkan/vulkan.h> + +int main(void) +{ + VkApplicationInfo app = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_1 }; + VkInstanceCreateInfo ici = { .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &app }; + VkInstance inst; + if (vkCreateInstance(&ici, NULL, &inst) != VK_SUCCESS) { + printf("vkCreateInstance failed\n"); + return 1; + } + uint32_t count = 1; + VkPhysicalDevice pd; + vkEnumeratePhysicalDevices(inst, &count, &pd); + VkPhysicalDeviceProperties props; + vkGetPhysicalDeviceProperties(pd, &props); + printf("%s\n", props.deviceName); + VkPhysicalDeviceMemoryProperties mp; + vkGetPhysicalDeviceMemoryProperties(pd, &mp); + for (uint32_t i = 0; i < mp.memoryHeapCount; i++) + printf("heap %u: %llu MiB flags 0x%x\n", i, (unsigned long long)(mp.memoryHeaps[i].size >> 20), mp.memoryHeaps[i].flags); + for (uint32_t i = 0; i < mp.memoryTypeCount; i++) { + VkMemoryPropertyFlags f = mp.memoryTypes[i].propertyFlags; + printf("type %u: heap %u flags 0x%x%s%s%s%s%s%s\n", i, mp.memoryTypes[i].heapIndex, f, + f & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ? " DEVICE_LOCAL" : "", + f & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ? " HOST_VISIBLE" : "", + f & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT ? " HOST_COHERENT" : "", + f & VK_MEMORY_PROPERTY_HOST_CACHED_BIT ? " HOST_CACHED" : "", + f & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT ? " LAZY" : "", + f & VK_MEMORY_PROPERTY_PROTECTED_BIT ? " PROTECTED" : ""); + } + vkDestroyInstance(inst, NULL); + return 0; +} diff --git a/tools/venus/mesa-venus-vtest.patch b/tools/venus/mesa-venus-vtest.patch new file mode 100644 index 0000000000..e2b5699750 --- /dev/null +++ b/tools/venus/mesa-venus-vtest.patch @@ -0,0 +1,541 @@ +diff --git a/src/virtio/vulkan/vn_device.c b/src/virtio/vulkan/vn_device.c +index f42b9f9..6ed3051 100644 +--- a/src/virtio/vulkan/vn_device.c ++++ b/src/virtio/vulkan/vn_device.c +@@ -45,6 +45,7 @@ vn_queue_fini(struct vn_queue *queue) + if (queue->wait_fence != VK_NULL_HANDLE) { + vn_DestroyFence(dev_handle, queue->wait_fence, NULL); + } ++ simple_mtx_destroy(&queue->submit_mutex); + vn_cached_storage_fini(&queue->storage); + vn_queue_base_fini(&queue->base); + } +@@ -65,6 +66,7 @@ vn_queue_init(struct vn_device *dev, + queue->index = array_index; + + vn_cached_storage_init(&queue->storage, &dev->base.vk.alloc); ++ simple_mtx_init(&queue->submit_mutex, mtx_plain); + + if (dev->physical_device->emulate_second_queue == + queue_info->queueFamilyIndex && +diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c +index 8b6eb4c..be146b6 100644 +--- a/src/virtio/vulkan/vn_device_memory.c ++++ b/src/virtio/vulkan/vn_device_memory.c +@@ -93,11 +93,12 @@ vn_device_memory_bo_init(struct vn_device *dev, struct vn_device_memory *mem) + } + + const struct vk_device_memory *mem_vk = &mem->base.vk; +- const VkMemoryType *mem_type = &dev->physical_device->memory_properties +- .memoryTypes[mem_vk->memory_type_index]; ++ /* The renderer's flags: WSI maps a type the app sees as not mappable. */ ++ const VkMemoryPropertyFlags flags = ++ dev->physical_device->renderer_memory_flags[mem_vk->memory_type_index]; + return vn_renderer_bo_create_from_device_memory( +- dev->renderer, batch, mem_vk->size, mem->base.id, +- mem_type->propertyFlags, mem_vk->export_handle_types, &mem->base_bo); ++ dev->renderer, batch, mem_vk->size, mem->base.id, flags, ++ mem_vk->export_handle_types, &mem->base_bo); + } + + static inline void +@@ -374,6 +375,14 @@ vn_AllocateMemory(VkDevice device, + { + struct vn_device *dev = vn_device_from_handle(device); + ++ VkMemoryAllocateInfo local_alloc_info; ++ const uint32_t type_index = vn_wsi_memory_type_index(dev, pAllocateInfo); ++ if (type_index != pAllocateInfo->memoryTypeIndex) { ++ local_alloc_info = *pAllocateInfo; ++ local_alloc_info.memoryTypeIndex = type_index; ++ pAllocateInfo = &local_alloc_info; ++ } ++ + struct vn_device_memory *mem = vk_device_memory_create( + &dev->base.vk, pAllocateInfo, pAllocator, sizeof(*mem)); + if (!mem) +diff --git a/src/virtio/vulkan/vn_physical_device.c b/src/virtio/vulkan/vn_physical_device.c +index f3581aa..c9c50e5 100644 +--- a/src/virtio/vulkan/vn_physical_device.c ++++ b/src/virtio/vulkan/vn_physical_device.c +@@ -982,6 +982,7 @@ vn_physical_device_init_memory_properties( + ring, vn_physical_device_to_handle(physical_dev), &props2); + + physical_dev->memory_properties = props2.memoryProperties; ++ physical_dev->wsi_readback_memory_type = -1; + + /* Kernel makes every mapping coherent. If a memory type is truly + * incoherent, it's better to remove the host-visible flag than silently +@@ -996,12 +997,18 @@ vn_physical_device_init_memory_properties( + VkMemoryPropertyFlags *flags = &props->memoryTypes[i].propertyFlags; + const bool coherent = *flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + const bool cached = *flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT; ++ physical_dev->renderer_memory_flags[i] = *flags; + if (coherent) { + if (first_coherent == VK_MAX_MEMORY_TYPES) + first_coherent = i; + if (cached) + has_coherent_cached = true; + } else if (cached) { ++ /* vtest maps the renderer's dma-buf itself and can sync the CPU ++ * cache around a read, which WSI does before copying a frame out. ++ */ ++ if (VN_DEBUG(VTEST) && physical_dev->wsi_readback_memory_type < 0) ++ physical_dev->wsi_readback_memory_type = i; + *flags &= ~(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_CACHED_BIT); + } +@@ -1060,7 +1067,9 @@ vn_physical_device_init_external_fence_handles( + { + physical_dev->external_fence_handles = 0; + +- if (physical_dev->instance->renderer->info.has_external_sync) { ++ /* Over vtest an export waits on the CPU and returns -1 (vn_sync.c). */ ++ if (physical_dev->instance->renderer->info.has_external_sync || ++ VN_DEBUG(VTEST)) { + #if !DETECT_OS_WINDOWS + physical_dev->external_fence_handles = + VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT; +@@ -1095,7 +1104,8 @@ vn_physical_device_init_external_semaphore_handles( + physical_dev->external_binary_semaphore_handles = 0; + physical_dev->external_timeline_semaphore_handles = 0; + +- if (physical_dev->instance->renderer->info.has_external_sync) { ++ if (physical_dev->instance->renderer->info.has_external_sync || ++ VN_DEBUG(VTEST)) { + #if !DETECT_OS_WINDOWS + physical_dev->external_binary_semaphore_handles = + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; +@@ -1173,7 +1183,8 @@ vn_physical_device_get_native_extensions( + exts->KHR_map_memory2 = true; + #if !DETECT_OS_WINDOWS + exts->EXT_map_memory_placed = true; +- exts->EXT_physical_device_drm = true; ++ /* Over vtest there is no DRM device behind Venus. */ ++ exts->EXT_physical_device_drm = !VN_DEBUG(VTEST); + #endif + /* use common implementation */ + exts->EXT_tooling_info = true; +diff --git a/src/virtio/vulkan/vn_physical_device.h b/src/virtio/vulkan/vn_physical_device.h +index 2c2f4a9..c002a84 100644 +--- a/src/virtio/vulkan/vn_physical_device.h ++++ b/src/virtio/vulkan/vn_physical_device.h +@@ -112,6 +112,12 @@ struct vn_physical_device { + int emulate_second_queue; + + VkPhysicalDeviceMemoryProperties memory_properties; ++ /* The renderer's flags, before memory_properties hides the host-visible ++ * bit of cached types that are not coherent. ++ */ ++ VkMemoryPropertyFlags renderer_memory_flags[VK_MAX_MEMORY_TYPES]; ++ /* A hidden cached type for the CPU copy of WSI images, or -1. */ ++ int wsi_readback_memory_type; + + struct { + VkExternalMemoryHandleTypeFlagBits renderer_handle_type; +diff --git a/src/virtio/vulkan/vn_queue.c b/src/virtio/vulkan/vn_queue.c +index 057842a..dee1244 100644 +--- a/src/virtio/vulkan/vn_queue.c ++++ b/src/virtio/vulkan/vn_queue.c +@@ -1049,11 +1049,16 @@ vn_queue_submission_init_syncs(struct vn_queue_submission *submit) + assert(fence->payload->type == VN_SYNC_TYPE_SYNC); + + submit->temp.syncs[sync_index] = fence->payload->sync; +- submit->temp.sync_vals[sync_index] = 1; ++ submit->temp.sync_vals[sync_index++] = 1; + + /* fence is backed by renderer sync without renderer object */ + submit->fence_handle = VK_NULL_HANDLE; + } ++ ++ /* A signal semaphore counted for an imported sync_file has no renderer ++ * sync to fill in, and the slot would hand vtest stale storage. ++ */ ++ submit->sync_count = sync_index; + } + + static VkResult +@@ -1248,9 +1253,13 @@ vn_queue_submit(struct vn_queue_submission *submit) + struct vn_device *dev = vn_device_from_vk(queue->base.vk.base.device); + VkResult result; + ++ simple_mtx_lock(&queue->submit_mutex); ++ + result = vn_queue_submission_prepare_submit(submit); +- if (result != VK_SUCCESS) ++ if (result != VK_SUCCESS) { ++ simple_mtx_unlock(&queue->submit_mutex); + return vn_error(dev->instance, result); ++ } + + result = vn_queue_submission_do_submit(submit); + if (result != VK_SUCCESS) +@@ -1260,6 +1269,7 @@ vn_queue_submit(struct vn_queue_submission *submit) + + out_cleanup: + vn_queue_submission_cleanup(submit); ++ simple_mtx_unlock(&queue->submit_mutex); + return vn_result(dev->instance, result); + } + +diff --git a/src/virtio/vulkan/vn_queue.h b/src/virtio/vulkan/vn_queue.h +index 3ea6d9d..4160e56 100644 +--- a/src/virtio/vulkan/vn_queue.h ++++ b/src/virtio/vulkan/vn_queue.h +@@ -52,6 +52,11 @@ struct vn_queue { + /* for vn_queue_submission storage */ + struct vn_cached_storage storage; + ++ /* Serializes submissions. The async present thread submits to this queue ++ * while the application does, after vn_wsi_fence_wait drops queue_mutex. ++ */ ++ simple_mtx_t submit_mutex; ++ + /* for async queue present */ + struct { + /* Protects VkQueue host access except async present states. */ +diff --git a/src/virtio/vulkan/vn_renderer_vtest.c b/src/virtio/vulkan/vn_renderer_vtest.c +index fc59d32..c7b20f5 100644 +--- a/src/virtio/vulkan/vn_renderer_vtest.c ++++ b/src/virtio/vulkan/vn_renderer_vtest.c +@@ -13,9 +13,11 @@ + #include <sys/mman.h> + #include <sys/socket.h> + #include <sys/types.h> ++#include <sys/ioctl.h> + #include <sys/un.h> + #include <unistd.h> + ++#include "drm-uapi/dma-buf.h" + #include "drm-uapi/virtgpu_drm.h" + #include "util/os_file.h" + #include "util/os_misc.h" +@@ -38,8 +40,10 @@ struct vtest_bo { + struct vn_renderer_bo base; + + uint32_t blob_flags; +- /* might be closed after mmap */ ++ /* might be closed after mmap, but not when the memory is incoherent */ + int res_fd; ++ /* the CPU cache is synced through the dma-buf on flush and invalidate */ ++ bool incoherent; + }; + + struct vtest_sync { +@@ -607,13 +611,35 @@ vtest_sync_create(struct vn_renderer *renderer, + return VK_SUCCESS; + } + ++/* The guest maps the renderer's dma-buf, so a CPU cache sync on it covers the ++ * mapping. Coherent memory needs none. ++ */ ++static void ++vtest_bo_sync_cpu_cache(struct vtest *vtest, ++ struct vtest_bo *bo, ++ uint64_t direction) ++{ ++ if (!bo->incoherent || bo->res_fd < 0) ++ return; ++ ++ struct dma_buf_sync sync = { .flags = DMA_BUF_SYNC_START | direction }; ++ int ret = ioctl(bo->res_fd, DMA_BUF_IOCTL_SYNC, &sync); ++ if (!ret) { ++ sync.flags = DMA_BUF_SYNC_END | direction; ++ ret = ioctl(bo->res_fd, DMA_BUF_IOCTL_SYNC, &sync); ++ } ++ if (ret) ++ vn_log(vtest->instance, "dma-buf cache sync failed: %s", strerror(errno)); ++} ++ + static void + vtest_bo_invalidate(struct vn_renderer *renderer, + struct vn_renderer_bo *bo, + VkDeviceSize offset, + VkDeviceSize size) + { +- /* nop */ ++ vtest_bo_sync_cpu_cache((struct vtest *)renderer, (struct vtest_bo *)bo, ++ DMA_BUF_SYNC_READ); + } + + static void +@@ -622,7 +648,8 @@ vtest_bo_flush(struct vn_renderer *renderer, + VkDeviceSize offset, + VkDeviceSize size) + { +- /* nop */ ++ vtest_bo_sync_cpu_cache((struct vtest *)renderer, (struct vtest_bo *)bo, ++ DMA_BUF_SYNC_WRITE); + } + + static void * +@@ -651,7 +678,7 @@ vtest_bo_map(struct vn_renderer *renderer, + } else { + bo->base.mmap_ptr = ptr; + /* we don't need the fd anymore */ +- if (!shareable) { ++ if (!shareable && !bo->incoherent) { + close(bo->res_fd); + bo->res_fd = -1; + } +@@ -735,6 +762,8 @@ vtest_bo_create_from_device_memory( + }, + .res_fd = res_fd, + .blob_flags = blob_flags, ++ .incoherent = (flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) && ++ !(flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), + }; + + *out_bo = &bo->base; +diff --git a/src/virtio/vulkan/vn_sync.c b/src/virtio/vulkan/vn_sync.c +index ee0a539..4687520 100644 +--- a/src/virtio/vulkan/vn_sync.c ++++ b/src/virtio/vulkan/vn_sync.c +@@ -26,7 +26,8 @@ vn_sync_payload_release_internal(struct vn_device *dev, + vn_renderer_sync_destroy(dev->renderer, payload->sync); + break; + case VN_SYNC_TYPE_TIMELINE_SYNC: +- for (uint32_t i = 0; i < dev->queue_count; i++) ++ /* One sync per queue plus one for host signals. */ ++ for (uint32_t i = 0; i <= dev->queue_count; i++) + vn_renderer_sync_destroy(dev->renderer, payload->syncs[i]); + vk_free2(&dev->base.vk.alloc, alloc, payload->syncs); + break; +@@ -49,6 +50,24 @@ vn_sync_payload_release(struct vn_device *dev, + vn_sync_payload_release_internal(dev, payload, NULL); + } + ++/* vtest cannot export a sync_file: wait for the payload on the CPU and ++ * return -1, the sync fd that stands for an already signaled payload. ++ */ ++static int ++vn_sync_export_signaled(struct vn_device *dev, struct vn_renderer_sync *sync) ++{ ++ uint64_t val = 1; ++ const struct vn_renderer_wait wait = { ++ .timeout = UINT64_MAX, ++ .syncs = &sync, ++ .sync_values = &val, ++ .sync_count = 1, ++ }; ++ vn_renderer_wait(dev->renderer, &wait); ++ vn_renderer_sync_reset(dev->renderer, sync); ++ return -1; ++} ++ + /* fence commands */ + + static VkResult +@@ -298,7 +317,10 @@ vn_GetFenceFdKHR(VkDevice device, + assert(sync_file); + + int fd = -1; +- if (payload->type == VN_SYNC_TYPE_SYNC) { ++ if (payload->type == VN_SYNC_TYPE_SYNC && ++ !dev->renderer->info.has_external_sync) { ++ fd = vn_sync_export_signaled(dev, payload->sync); ++ } else if (payload->type == VN_SYNC_TYPE_SYNC) { + fd = vn_renderer_sync_export_syncobj(dev->renderer, + fence->payload->sync, sync_file); + vn_renderer_sync_reset(dev->renderer, fence->payload->sync); +@@ -830,7 +852,11 @@ vn_GetSemaphoreFdKHR(VkDevice device, + assert(sync_file); + + int fd = -1; +- if (payload->type == VN_SYNC_TYPE_SYNC) { ++ if (payload->type == VN_SYNC_TYPE_SYNC && ++ !dev->renderer->info.has_external_sync) { ++ assert(sem->sync_fd_export); ++ fd = vn_sync_export_signaled(dev, payload->sync); ++ } else if (payload->type == VN_SYNC_TYPE_SYNC) { + assert(sem->sync_fd_export); + fd = vn_renderer_sync_export_syncobj(dev->renderer, payload->sync, + sync_file); +diff --git a/src/virtio/vulkan/vn_wsi.c b/src/virtio/vulkan/vn_wsi.c +index e73ab48..f0b41b1 100644 +--- a/src/virtio/vulkan/vn_wsi.c ++++ b/src/virtio/vulkan/vn_wsi.c +@@ -287,6 +287,53 @@ vn_wsi_memory_info_init(struct vn_device_memory *mem, + } + } + ++/* The buffer WSI copies each frame into for the CPU (software presentation) ++ * gets the hidden cached type: on vtest the host-visible type the app sees is ++ * uncached, and reading a frame from it took most of a present. WSI ++ * invalidates the buffer before each read. ++ */ ++uint32_t ++vn_wsi_memory_type_index(const struct vn_device *dev, ++ const VkMemoryAllocateInfo *alloc_info) ++{ ++ const struct vn_physical_device *physical_dev = dev->physical_device; ++ const int readback_type = physical_dev->wsi_readback_memory_type; ++ if (readback_type < 0 || !physical_dev->wsi_device.sw) ++ return alloc_info->memoryTypeIndex; ++ ++ const VkMemoryDedicatedAllocateInfo *dedicated_info = NULL; ++ bool wsi = false; ++ vk_foreach_struct_const(pnext, alloc_info->pNext) { ++ switch ((uint32_t)pnext->sType) { ++ case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO: ++ dedicated_info = (const void *)pnext; ++ break; ++ case VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA: ++ wsi = true; ++ break; ++ case VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO: ++ case VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT: ++ return alloc_info->memoryTypeIndex; ++ default: ++ break; ++ } ++ } ++ if (!wsi || !dedicated_info || dedicated_info->buffer == VK_NULL_HANDLE) ++ return alloc_info->memoryTypeIndex; ++ ++ const VkMemoryPropertyFlags flags = ++ physical_dev->memory_properties.memoryTypes[alloc_info->memoryTypeIndex] ++ .propertyFlags; ++ const struct vn_buffer *buf = vn_buffer_from_handle(dedicated_info->buffer); ++ const uint32_t type_bits = ++ buf->requirements.memory.memoryRequirements.memoryTypeBits; ++ if (!(flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) || ++ !(type_bits & BITFIELD_BIT(readback_type))) ++ return alloc_info->memoryTypeIndex; ++ ++ return readback_type; ++} ++ + static uint32_t + vn_modifier_plane_count(struct vn_physical_device *physical_dev, + VkFormat format, +diff --git a/src/virtio/vulkan/vn_wsi.h b/src/virtio/vulkan/vn_wsi.h +index 2231556..1429feb 100644 +--- a/src/virtio/vulkan/vn_wsi.h ++++ b/src/virtio/vulkan/vn_wsi.h +@@ -34,6 +34,10 @@ void + vn_wsi_memory_info_init(struct vn_device_memory *mem, + const VkMemoryAllocateInfo *alloc_info); + ++uint32_t ++vn_wsi_memory_type_index(const struct vn_device *dev, ++ const VkMemoryAllocateInfo *alloc_info); ++ + bool + vn_wsi_validate_image_format_info( + struct vn_physical_device *physical_dev, +@@ -77,6 +81,13 @@ vn_wsi_memory_info_init(struct vn_device_memory *mem, + { + } + ++static inline uint32_t ++vn_wsi_memory_type_index(const struct vn_device *dev, ++ const VkMemoryAllocateInfo *alloc_info) ++{ ++ return alloc_info->memoryTypeIndex; ++} ++ + static inline bool + vn_wsi_validate_image_format_info(struct vn_physical_device *physical_dev, + const VkPhysicalDeviceImageFormatInfo2 *info) +diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c +index 411ee3e..ae38115 100644 +--- a/src/vulkan/wsi/wsi_common.c ++++ b/src/vulkan/wsi/wsi_common.c +@@ -235,6 +235,7 @@ wsi_device_init(struct wsi_device *wsi, + WSI_GET_CB(WaitForFences); + WSI_GET_CB(MapMemory); + WSI_GET_CB(UnmapMemory); ++ WSI_GET_CB(InvalidateMappedMemoryRanges); + if (wsi->has_present_wait) + WSI_GET_CB(WaitSemaphores); + #undef WSI_GET_CB +@@ -3577,6 +3578,22 @@ wsi_create_cpu_linear_image_mem(const struct wsi_swapchain *chain, + return VK_SUCCESS; + } + ++void ++wsi_image_invalidate_cpu_map(const struct wsi_swapchain *chain, ++ const struct wsi_image *image) ++{ ++ /* A driver may back the CPU image with cached memory that is not ++ * coherent; for coherent memory this does nothing. ++ */ ++ const VkMappedMemoryRange range = { ++ .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, ++ .memory = image->blit.memory != VK_NULL_HANDLE ? image->blit.memory ++ : image->memory, ++ .size = VK_WHOLE_SIZE, ++ }; ++ chain->wsi->InvalidateMappedMemoryRanges(chain->device, 1, &range); ++} ++ + static VkResult + wsi_create_cpu_buffer_image_mem(const struct wsi_swapchain *chain, + const struct wsi_image_info *info, +diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h +index 803d140..432ba43 100644 +--- a/src/vulkan/wsi/wsi_common.h ++++ b/src/vulkan/wsi/wsi_common.h +@@ -247,6 +247,7 @@ struct wsi_device { + WSI_CB(WaitForFences); + WSI_CB(MapMemory); + WSI_CB(UnmapMemory); ++ WSI_CB(InvalidateMappedMemoryRanges); + WSI_CB(WaitSemaphores); + #undef WSI_CB + +diff --git a/src/vulkan/wsi/wsi_common_drm.c b/src/vulkan/wsi/wsi_common_drm.c +index dbf65b2..2a6b701 100644 +--- a/src/vulkan/wsi/wsi_common_drm.c ++++ b/src/vulkan/wsi/wsi_common_drm.c +@@ -204,6 +204,10 @@ wsi_signal_dma_buf_from_semaphore(const struct wsi_swapchain *chain, + if (result != VK_SUCCESS) + return result; + ++ /* -1 is an already signaled payload: there is nothing to attach. */ ++ if (sync_file_fd < 0) ++ return VK_SUCCESS; ++ + result = wsi_dma_buf_import_sync_file(image->dma_buf_fd, sync_file_fd); + close(sync_file_fd); + return result; +diff --git a/src/vulkan/wsi/wsi_common_private.h b/src/vulkan/wsi/wsi_common_private.h +index 3d2cd7d..e469414 100644 +--- a/src/vulkan/wsi/wsi_common_private.h ++++ b/src/vulkan/wsi/wsi_common_private.h +@@ -410,6 +410,10 @@ wsi_configure_cpu_image(const struct wsi_swapchain *chain, + const struct wsi_cpu_image_params *params, + struct wsi_image_info *info); + ++void ++wsi_image_invalidate_cpu_map(const struct wsi_swapchain *chain, ++ const struct wsi_image *image); ++ + VkResult + wsi_create_buffer_blit_context(const struct wsi_swapchain *chain, + const struct wsi_image_info *info, +diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c +index 33a4059..047c8b3 100644 +--- a/src/vulkan/wsi/wsi_common_wayland.c ++++ b/src/vulkan/wsi/wsi_common_wayland.c +@@ -3314,6 +3314,7 @@ wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain, + + if (chain->buffer_type == WSI_WL_BUFFER_SHM_MEMCPY) { + struct wsi_wl_image *image = &chain->images[image_index]; ++ wsi_image_invalidate_cpu_map(&chain->base, &image->base); + memcpy(image->shm_ptr, image->base.cpu_map, + image->base.row_pitches[0] * chain->extent.height); + } +diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c +index a077afe..579ba13 100644 +--- a/src/vulkan/wsi/wsi_common_x11.c ++++ b/src/vulkan/wsi/wsi_common_x11.c +@@ -1854,6 +1854,7 @@ x11_present_to_x11_sw(struct x11_swapchain *chain, uint32_t image_index) + xcb_get_geometry_cookie_t geom_cookie = xcb_get_geometry(chain->conn, chain->window); + + xcb_void_cookie_t cookie; ++ wsi_image_invalidate_cpu_map(&chain->base, &image->base); + void *myptr = image->base.cpu_map; + size_t hdr_len = sizeof(xcb_put_image_request_t); + int stride_b = image->base.row_pitches[0]; diff --git a/tools/venus/release.env b/tools/venus/release.env new file mode 100644 index 0000000000..5da556c28b --- /dev/null +++ b/tools/venus/release.env @@ -0,0 +1,3 @@ +VENUS_REPO=The412Banner/droiddeck-nonadreno-drivers +VENUS_TAG=venus-proto13-e24ed8ab +VENUS_SHA256=25f236bbc32c8490fc61c20a6016b0bea4a8c3267a69de6b91496da2afe6bc04 diff --git a/tools/venus/virglrenderer-android.patch b/tools/venus/virglrenderer-android.patch new file mode 100644 index 0000000000..9cf1a02484 --- /dev/null +++ b/tools/venus/virglrenderer-android.patch @@ -0,0 +1,322 @@ +diff --git a/src/venus/vkr_device_memory.c b/src/venus/vkr_device_memory.c +index ffe621b..01cd811 100644 +--- a/src/venus/vkr_device_memory.c ++++ b/src/venus/vkr_device_memory.c +@@ -227,6 +227,136 @@ vkr_gbm_get_fd_info_from_allocation_info(UNUSED struct vkr_physical_device *phys + + #endif /* ENABLE_GBM_ALLOCATION */ + ++#ifdef __ANDROID__ ++#include <android/hardware_buffer.h> ++#include <fcntl.h> ++#include <linux/dma-heap.h> ++#include <sys/ioctl.h> ++#include <sys/socket.h> ++ ++static int vkr_dma_heap_fd = -1; ++static int vkr_dma_heap_cached_fd = -1; ++ ++/* Uncached for coherent memory types: nobody brackets CPU access with ++ * DMA_BUF_IOCTL_SYNC (the guest maps the memory as host-coherent), so on a ++ * cached heap the CPU and the GPU see each other's writes torn at cache-line ++ * granularity. Cached for cached types, which are not coherent: whoever maps ++ * them syncs the CPU cache through the dma-buf. ++ */ ++static void ++vkr_dma_heap_init_once(void) ++{ ++ vkr_dma_heap_cached_fd = open("/dev/dma_heap/system", O_RDONLY | O_CLOEXEC); ++ vkr_dma_heap_fd = open("/dev/dma_heap/system-uncached", O_RDONLY | O_CLOEXEC); ++ if (vkr_dma_heap_fd < 0) { ++ vkr_log("no uncached dma-buf heap (%s): using the cached one", strerror(errno)); ++ vkr_dma_heap_fd = vkr_dma_heap_cached_fd; ++ } ++ if (vkr_dma_heap_fd < 0) ++ vkr_log("no dma-buf heap (%s): allocating AHardwareBuffers", strerror(errno)); ++} ++ ++/* An AHardwareBuffer's dma-buf: the first fd of its native handle, which the ++ * NDK hands out only through a unix socket. ++ */ ++static int ++vkr_ahb_alloc_dma_buf(size_t size) ++{ ++ const AHardwareBuffer_Desc desc = { ++ .width = (uint32_t)size, ++ .height = 1, ++ .layers = 1, ++ .format = AHARDWAREBUFFER_FORMAT_BLOB, ++ .usage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN | ++ AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER, ++ }; ++ AHardwareBuffer *ahb = NULL; ++ if (AHardwareBuffer_allocate(&desc, &ahb)) { ++ vkr_log("AHardwareBuffer_allocate of %zu failed", size); ++ return -1; ++ } ++ ++ int fd = -1; ++ int sv[2]; ++ if (!socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv)) { ++ if (!AHardwareBuffer_sendHandleToUnixSocket(ahb, sv[0])) { ++ char data[4096]; ++ char control[CMSG_SPACE(sizeof(int) * 16)]; ++ struct iovec iov = { .iov_base = data, .iov_len = sizeof(data) }; ++ struct msghdr msg = { ++ .msg_iov = &iov, ++ .msg_iovlen = 1, ++ .msg_control = control, ++ .msg_controllen = sizeof(control), ++ }; ++ if (recvmsg(sv[1], &msg, MSG_CMSG_CLOEXEC) > 0) { ++ struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); ++ if (cmsg && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { ++ const int count = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int); ++ const int *fds = (const int *)CMSG_DATA(cmsg); ++ for (int i = 0; i < count; i++) { ++ if (i == 0) ++ fd = fds[i]; ++ else ++ close(fds[i]); ++ } ++ } ++ } ++ } ++ close(sv[0]); ++ close(sv[1]); ++ } ++ AHardwareBuffer_release(ahb); ++ if (fd < 0) ++ vkr_log("could not get the dma-buf of an AHardwareBuffer"); ++ return fd; ++} ++ ++static VkResult ++vkr_android_get_fd_info_from_allocation_info(const VkMemoryAllocateInfo *alloc_info, ++ bool cached, ++ int *out_dma_buf_fd, ++ VkImportMemoryFdInfoKHR *out_fd_info) ++{ ++ static once_flag dma_heap_once_flag = ONCE_FLAG_INIT; ++ call_once(&dma_heap_once_flag, vkr_dma_heap_init_once); ++ ++ const size_t size = align(alloc_info->allocationSize, getpagesize()); ++ const int heap_fd = ++ cached && vkr_dma_heap_cached_fd >= 0 ? vkr_dma_heap_cached_fd : vkr_dma_heap_fd; ++ int dma_buf_fd = -1; ++ if (heap_fd >= 0) { ++ struct dma_heap_allocation_data data = { ++ .len = size, ++ .fd_flags = O_RDWR | O_CLOEXEC, ++ }; ++ if (!ioctl(heap_fd, DMA_HEAP_IOCTL_ALLOC, &data)) ++ dma_buf_fd = data.fd; ++ else ++ vkr_log("dma-buf heap allocation of %zu failed (%s)", size, strerror(errno)); ++ } ++ if (dma_buf_fd < 0) ++ dma_buf_fd = vkr_ahb_alloc_dma_buf(size); ++ if (dma_buf_fd < 0) ++ return VK_ERROR_OUT_OF_DEVICE_MEMORY; ++ ++ const int fd = os_dupfd_cloexec(dma_buf_fd); ++ if (fd < 0) { ++ close(dma_buf_fd); ++ return VK_ERROR_OUT_OF_HOST_MEMORY; ++ } ++ ++ *out_dma_buf_fd = dma_buf_fd; ++ *out_fd_info = (VkImportMemoryFdInfoKHR){ ++ .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR, ++ .pNext = alloc_info->pNext, ++ .fd = fd, ++ .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, ++ }; ++ return VK_SUCCESS; ++} ++#endif /* __ANDROID__ */ ++ + static void + vkr_dispatch_vkAllocateMemory(struct vn_dispatch_context *dispatch, + struct vn_command_vkAllocateMemory *args) +@@ -281,7 +411,14 @@ vkr_dispatch_vkAllocateMemory(struct vn_dispatch_context *dispatch, + int udmabuf_fd = -1; + void *gbm_bo = NULL; + VkExportMemoryAllocateInfo local_export_info; +- if ((property_flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) && !res_info) { ++ /* Android without driver export: a dma-buf export of any memory type is ++ * served by a dma-buf the server allocates and imports. ++ */ ++ const bool android_export = ++ physical_dev->android_dma_buf_import && export_info && ++ (export_info->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT); ++ if (((property_flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) || android_export) && ++ !res_info) { + /* An implementation can support dma_buf import along with opaque fd export/import. + * If the client driver is using external memory and requesting dma_buf, without + * dma_buf fd export support, we must use gbm bo import path instead of forcing +@@ -346,6 +483,13 @@ vkr_dispatch_vkAllocateMemory(struct vn_dispatch_context *dispatch, + */ + args->ret = vkr_udmabuf_get_fd_info_from_allocation_info( + physical_dev, alloc_info, &udmabuf_fd, &local_import_info); ++#ifdef __ANDROID__ ++ } else if (physical_dev->android_dma_buf_import) { ++ /* Kept in udmabuf_fd: exported and closed the same way. */ ++ args->ret = vkr_android_get_fd_info_from_allocation_info( ++ alloc_info, property_flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT, ++ &udmabuf_fd, &local_import_info); ++#endif + } else { + args->ret = vkr_gbm_get_fd_info_from_allocation_info( + physical_dev, alloc_info, &gbm_bo, &local_import_info); +@@ -367,6 +511,12 @@ vkr_dispatch_vkAllocateMemory(struct vn_dispatch_context *dispatch, + + struct vkr_device_memory *mem = vkr_device_memory_create_and_add(ctx, args); + if (!mem) { ++ vkr_log("vkAllocateMemory failed (%d): type %u flags 0x%x size %" PRIu64 "%s", ++ args->ret, mem_type_index, property_flags, ++ (uint64_t)alloc_info->allocationSize, ++ udmabuf_fd >= 0 ? ", imported dma-buf" : ""); ++ if (udmabuf_fd >= 0) ++ close(udmabuf_fd); + if (local_import_info.fd >= 0) + close(local_import_info.fd); + if (gbm_bo) +diff --git a/src/venus/vkr_physical_device.c b/src/venus/vkr_physical_device.c +index e2c3baa..69ec875 100644 +--- a/src/venus/vkr_physical_device.c ++++ b/src/venus/vkr_physical_device.c +@@ -207,31 +207,54 @@ vkr_physical_device_init_memory_properties(struct vkr_physical_device *physical_ + .sType = VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES, + }; + ++ /* Exportable and compatible with itself is enough. Requiring the type in ++ * exportFromImportedHandleTypes as well rules out drivers (Mali on Android) ++ * that export fine but do not re-export imported memory. ++ */ + if (physical_dev->EXT_external_memory_dma_buf) { + info.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + vk->GetPhysicalDeviceExternalBufferProperties(handle, &info, &props); ++ const VkExternalMemoryProperties *p = &props.externalMemoryProperties; ++ vkr_log("dma_buf buffer: features 0x%x exportFrom 0x%x compatible 0x%x", ++ p->externalMemoryFeatures, p->exportFromImportedHandleTypes, ++ p->compatibleHandleTypes); + physical_dev->is_dma_buf_fd_export_supported = +- (props.externalMemoryProperties.externalMemoryFeatures & +- VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) && +- (props.externalMemoryProperties.exportFromImportedHandleTypes & ++ (p->externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) && ++ ((p->exportFromImportedHandleTypes | p->compatibleHandleTypes) & + VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT); + } + + if (physical_dev->KHR_external_memory_fd) { + info.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT, + vk->GetPhysicalDeviceExternalBufferProperties(handle, &info, &props); ++ const VkExternalMemoryProperties *p = &props.externalMemoryProperties; ++ vkr_log("opaque_fd buffer: features 0x%x exportFrom 0x%x compatible 0x%x", ++ p->externalMemoryFeatures, p->exportFromImportedHandleTypes, ++ p->compatibleHandleTypes); + physical_dev->is_opaque_fd_export_supported = +- (props.externalMemoryProperties.externalMemoryFeatures & +- VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) && +- (props.externalMemoryProperties.exportFromImportedHandleTypes & ++ (p->externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) && ++ ((p->exportFromImportedHandleTypes | p->compatibleHandleTypes) & + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT); + } ++ vkr_log("memory export: dma_buf %d opaque_fd %d", ++ physical_dev->is_dma_buf_fd_export_supported, ++ physical_dev->is_opaque_fd_export_supported); + + /* fallback to gbm allocation with dma-buf import */ ++ physical_dev->android_dma_buf_import = false; ++#ifdef __ANDROID__ ++ if (!physical_dev->is_dma_buf_fd_export_supported && ++ !physical_dev->is_opaque_fd_export_supported && ++ physical_dev->EXT_external_memory_dma_buf) { ++ physical_dev->android_dma_buf_import = true; ++ vkr_log("memory export: none; allocating dma-bufs and importing them"); ++ } ++#else + if (!physical_dev->is_dma_buf_fd_export_supported && + !physical_dev->is_opaque_fd_export_supported && + physical_dev->EXT_external_memory_dma_buf) + physical_dev->gbm_device = vkr_physical_device_get_gbm_device(); ++#endif + + physical_dev->udmabuf_dev_fd = -1; + if (VKR_DEBUG(UDMABUF)) { +@@ -703,6 +726,25 @@ vkr_dispatch_vkGetPhysicalDeviceFormatProperties2( + args->pFormatProperties); + } + ++/* Android without driver export: the server allocates a dma-buf and imports ++ * it (vkr_device_memory.c), so a dma-buf the driver can import, the guest ++ * can export. ++ */ ++static void ++vkr_android_dma_buf_export_fixup(const struct vkr_physical_device *physical_dev, ++ VkExternalMemoryHandleTypeFlagBits handle_type, ++ VkExternalMemoryProperties *props) ++{ ++ if (!physical_dev->android_dma_buf_import || ++ handle_type != VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT || ++ !(props->externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT)) ++ return; ++ ++ props->externalMemoryFeatures |= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT; ++ props->exportFromImportedHandleTypes |= VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT; ++ props->compatibleHandleTypes |= VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT; ++} ++ + static void + vkr_dispatch_vkGetPhysicalDeviceImageFormatProperties2( + UNUSED struct vn_dispatch_context *dispatch, +@@ -715,6 +757,20 @@ vkr_dispatch_vkGetPhysicalDeviceImageFormatProperties2( + vn_replace_vkGetPhysicalDeviceImageFormatProperties2_args_handle(args); + args->ret = vk->GetPhysicalDeviceImageFormatProperties2( + args->physicalDevice, args->pImageFormatInfo, args->pImageFormatProperties); ++ ++ const VkPhysicalDeviceExternalImageFormatInfo *external_info = vkr_find_struct( ++ args->pImageFormatInfo->pNext, ++ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO); ++ VkExternalImageFormatProperties *external_props = vkr_find_struct( ++ args->pImageFormatProperties->pNext, VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES); ++ if (physical_dev->android_dma_buf_import && external_info && external_props) { ++ if (args->ret == VK_SUCCESS) ++ vkr_android_dma_buf_export_fixup(physical_dev, external_info->handleType, ++ &external_props->externalMemoryProperties); ++ else ++ vkr_log("image format %d tiling %d: no external memory (%d)", ++ args->pImageFormatInfo->format, args->pImageFormatInfo->tiling, args->ret); ++ } + } + + static void +@@ -743,6 +799,10 @@ vkr_dispatch_vkGetPhysicalDeviceExternalBufferProperties( + vn_replace_vkGetPhysicalDeviceExternalBufferProperties_args_handle(args); + vk->GetPhysicalDeviceExternalBufferProperties( + args->physicalDevice, args->pExternalBufferInfo, args->pExternalBufferProperties); ++ ++ vkr_android_dma_buf_export_fixup( ++ physical_dev, args->pExternalBufferInfo->handleType, ++ &args->pExternalBufferProperties->externalMemoryProperties); + } + + static void +diff --git a/src/venus/vkr_physical_device.h b/src/venus/vkr_physical_device.h +index b0b6691..28ba0b7 100644 +--- a/src/venus/vkr_physical_device.h ++++ b/src/venus/vkr_physical_device.h +@@ -33,6 +33,10 @@ struct vkr_physical_device { + bool is_opaque_fd_export_supported; + void *gbm_device; + int udmabuf_dev_fd; ++ /* Android: host-visible memory is a dma-buf the server allocates (dma-buf ++ * heap, else AHardwareBuffer) and imports, since the driver cannot export. ++ */ ++ bool android_dma_buf_import; + + VkQueueFamilyProperties *queue_family_properties; + uint32_t queue_family_property_count; diff --git a/tools/venus/virglrenderer-destroy-mutex-after-objects.patch b/tools/venus/virglrenderer-destroy-mutex-after-objects.patch new file mode 100644 index 0000000000..a36fb6e802 --- /dev/null +++ b/tools/venus/virglrenderer-destroy-mutex-after-objects.patch @@ -0,0 +1,30 @@ +venus: destroy a device's object mutex after the objects that lock it + +From BattleTempest's DroidDeck-Pixel (kevinbryant551-ux/DroidDeck-Pixel, GPL-3.0), +tools/venus/patches/0103-destroy-object-mutex-after-objects.patch. Bionic aborts on locking a +destroyed mutex ("pthread_mutex_lock called on a destroyed mutex", seen on a Tab S9 FE G68 +and a Pixel 9a), so a client that exited holding objects took the render worker down. + +diff --git a/src/venus/vkr_device.c b/src/venus/vkr_device.c +index 9144180..7b7c904 100644 +--- a/src/venus/vkr_device.c ++++ b/src/venus/vkr_device.c +@@ -324,13 +324,16 @@ vkr_device_destroy(struct vkr_context *ctx, struct vkr_device *dev, bool destroy + vkr_log("vkDeviceWaitIdle(%p) failed(%d)", dev, (int32_t)result); + } + +- mtx_destroy(&dev->object_mutex); +- ++ /* The leftover objects are removed under object_mutex: destroy it after them. glibc lets a ++ * destroyed mutex be locked; bionic aborts ("pthread_mutex_lock called on a destroyed mutex"), ++ * so every client that exited holding objects took its render worker down. */ + if (!list_is_empty(&dev->objects)) { + list_for_each_entry_safe (struct vkr_object, obj, &dev->objects, track_head) + vkr_device_object_destroy(ctx, dev, obj); + } + ++ mtx_destroy(&dev->object_mutex); ++ + list_for_each_entry_safe (struct vkr_queue, queue, &dev->queues, base.track_head) + vkr_queue_destroy(ctx, queue); + diff --git a/tools/venus/virglrenderer-destroy-unknown-pipeline.patch b/tools/venus/virglrenderer-destroy-unknown-pipeline.patch new file mode 100644 index 0000000000..60c8ead7aa --- /dev/null +++ b/tools/venus/virglrenderer-destroy-unknown-pipeline.patch @@ -0,0 +1,54 @@ +diff --git a/src/venus/venus-protocol/vn_protocol_renderer_pipeline.h b/src/venus/venus-protocol/vn_protocol_renderer_pipeline.h +index ce82e59..8798de9 100644 +--- a/src/venus/venus-protocol/vn_protocol_renderer_pipeline.h ++++ b/src/venus/venus-protocol/vn_protocol_renderer_pipeline.h +@@ -3290,7 +3290,11 @@ static inline void vn_encode_vkCreateComputePipelines_reply(struct vn_cs_encoder + static inline void vn_decode_vkDestroyPipeline_args_temp(struct vn_cs_decoder *dec, struct vn_command_vkDestroyPipeline *args) + { + vn_decode_VkDevice_lookup(dec, &args->device); +- vn_decode_VkPipeline_lookup(dec, &args->pipeline); ++ { ++ uint64_t id; ++ vn_decode_uint64_t(dec, &id); ++ args->pipeline = (VkPipeline)(uintptr_t)vkr_cs_decoder_lookup_object_for_destroy((const struct vkr_cs_decoder *)dec, id, VK_OBJECT_TYPE_PIPELINE); ++ } + if (vn_decode_simple_pointer(dec)) { + vn_cs_decoder_set_fatal(dec); + } else { +diff --git a/src/venus/vkr_cs.h b/src/venus/vkr_cs.h +index c72c5cc..b45061f 100644 +--- a/src/venus/vkr_cs.h ++++ b/src/venus/vkr_cs.h +@@ -324,6 +324,32 @@ vkr_cs_decoder_lookup_object(const struct vkr_cs_decoder *dec, + return obj; + } + ++/* For a destroy command only: an id the renderer never created (the driver refused the create, ++ * which the guest may not have waited for) is logged and destroyed as VK_NULL_HANDLE, a no-op, ++ * instead of marking the whole context fatal - that took the vtest server down (exit 137) when ++ * gamescope destroyed a compute pipeline a Mali-G615 had refused. */ ++static inline struct vkr_object * ++vkr_cs_decoder_lookup_object_for_destroy(const struct vkr_cs_decoder *dec, ++ vkr_object_id id, ++ VkObjectType type) ++{ ++ struct vkr_object *obj; ++ ++ if (!id) ++ return NULL; ++ ++ mtx_lock(dec->object_mutex); ++ const struct hash_entry *entry = ++ _mesa_hash_table_search((struct hash_table *)dec->object_table, &id); ++ obj = likely(entry) ? entry->data : NULL; ++ mtx_unlock(dec->object_mutex); ++ if (unlikely(!obj || obj->type != type)) { ++ vkr_log("destroy of unknown object %" PRIu64 " of type %d ignored", id, type); ++ return NULL; ++ } ++ return obj; ++} ++ + static inline void + vkr_cs_decoder_reset_temp_pool(struct vkr_cs_decoder *dec) + { diff --git a/tools/venus/watch-maps.sh b/tools/venus/watch-maps.sh new file mode 100644 index 0000000000..2850147b13 --- /dev/null +++ b/tools/venus/watch-maps.sh @@ -0,0 +1,19 @@ +#!/system/bin/sh +# Keeps the memory map of a running game process in the app's cache directory, so a crash address +# in Wine's log (handle_syscall_fault pc=...) can be matched to a library afterwards. +# On the phone, as the app (from Git Bash, with MSYS_NO_PATHCONV=1): +# adb push tools/venus/watch-maps.sh /data/local/tmp/ +# adb shell "run-as com.droiddeck.launcher sh /data/local/tmp/watch-maps.sh 'Hollow Knight Silksong.exe'" +# Runs 15 minutes. Then: adb exec-out "run-as com.droiddeck.launcher cat cache/game-maps.txt" > maps.txt +name=${1:?process name, as ps shows it} +cd /data/user/0/com.droiddeck.launcher || exit 1 +rm -f cache/game-maps.txt +i=0 +while [ $i -lt 900 ]; do + p=$(ps -A -o PID,NAME | grep -F "$name" | grep -v Crash | head -1 | awk '{print $1}') + if [ -n "$p" ]; then + cat /proc/$p/maps > cache/game-maps.tmp 2>/dev/null && mv cache/game-maps.tmp cache/game-maps.txt + fi + sleep 1 + i=$((i + 1)) +done diff --git a/tools/vulkan-wsi/build.sh b/tools/vulkan-wsi/build.sh new file mode 100755 index 0000000000..cf5a1c3560 --- /dev/null +++ b/tools/vulkan-wsi/build.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# CI build of a vendor-neutral X11 surface/swapchain layer. +set -euo pipefail +root=$(cd "$(dirname "$0")/../.." && pwd) +. "$root/tools/vulkan-wsi/source.env" +mkdir -p "${1:?output directory required}" +out=$(cd "$1" && pwd) +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +fetch() { + git init -q "$3" + git -C "$3" fetch --depth=1 "$1" "$2" + git -C "$3" checkout -q --detach FETCH_HEAD + test "$(git -C "$3" rev-parse HEAD)" = "$2" +} +fetch https://github.com/ginkage/vulkan-wsi-layer.git "$WSI_REVISION" "$work/source" +fetch https://github.com/KhronosGroup/Vulkan-Headers.git "$VULKAN_HEADERS_REVISION" "$work/headers" +git -C "$work/source" apply --check "$root/tools/vulkan-wsi/patches/0001-link-x11-external-memory.patch" +git -C "$work/source" apply "$root/tools/vulkan-wsi/patches/0001-link-x11-external-memory.patch" +cmake -S "$work/source" -B "$work/build" -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr -DVULKAN_CXX_INCLUDE="$work/headers/include" \ + -DBUILD_WSI_HEADLESS=OFF -DBUILD_WSI_WAYLAND=OFF -DBUILD_WSI_DISPLAY=OFF -DBUILD_WSI_X11=ON \ + -DSELECT_EXTERNAL_ALLOCATOR=dma_buf_heaps -DWSIALLOC_MEMORY_HEAP_NAME=system -DKERNEL_HEADER_DIR=/usr/include +cmake --build "$work/build" --parallel 4 +DESTDIR="$work/stage" cmake --install "$work/build" +cp "$work/stage/usr/share/vulkan/implicit_layer.d/"* "$out/" +cp "$root/tools/vulkan-wsi/patches/0001-link-x11-external-memory.patch" "$out/downstream.patch" +cp "$work/source/LICENSE" "$out/LICENSE" +mkdir -p "$out/licenses/Vulkan-Headers" +cp "$root/tools/vulkan-wsi/licenses/Vulkan-Headers/"* "$out/licenses/Vulkan-Headers/" +printf '%s\n' "$WSI_REVISION" > "$out/source-commit" +printf '%s\n' "$VULKAN_HEADERS_REVISION" > "$out/vulkan-headers-commit" +tar --exclude-vcs --zstd -cf "$out/source.tar.zst" -C "$work/source" . +(cd "$out" && sha256sum ./*.so > SHA256SUMS) diff --git a/tools/vulkan-wsi/licenses/Vulkan-Headers/LICENSE.md b/tools/vulkan-wsi/licenses/Vulkan-Headers/LICENSE.md new file mode 100644 index 0000000000..17cf4a17d6 --- /dev/null +++ b/tools/vulkan-wsi/licenses/Vulkan-Headers/LICENSE.md @@ -0,0 +1,19 @@ +Copyright 2015-2026 The Khronos Group Inc. + +Files in this repository fall under one of these licenses: + +- `Apache-2.0` +- `MIT` + +Note: With the exception of `parse_dependency.py`, which is based on an +external file, files using the `MIT` license also fall under `Apache-2.0`. +Example: + +``` +SPDX-License-Identifier: Apache-2.0 OR MIT +``` + +Full license text of these licenses is available at: + + * Apache-2.0: https://opensource.org/licenses/Apache-2.0 + * MIT: https://opensource.org/licenses/MIT diff --git a/tools/vulkan-wsi/licenses/Vulkan-Headers/MIT.txt b/tools/vulkan-wsi/licenses/Vulkan-Headers/MIT.txt new file mode 100644 index 0000000000..8495fe9e90 --- /dev/null +++ b/tools/vulkan-wsi/licenses/Vulkan-Headers/MIT.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2015-2023 The Khronos Group Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/tools/vulkan-wsi/patches/0001-link-x11-external-memory.patch b/tools/vulkan-wsi/patches/0001-link-x11-external-memory.patch new file mode 100644 index 0000000000..da605feaaa --- /dev/null +++ b/tools/vulkan-wsi/patches/0001-link-x11-external-memory.patch @@ -0,0 +1,16 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -421,6 +421,13 @@ + cp ${PROJECT_SOURCE_DIR}/layer/VkLayer_window_system_integration.json ${CMAKE_CURRENT_BINARY_DIR} + ${JSON_COMMANDS}) + ++# X11 DRI3 uses these shared sources even when Wayland and display are disabled. ++if(BUILD_WSI_X11 AND NOT BUILD_WSI_WAYLAND AND NOT BUILD_WSI_DISPLAY) ++ target_sources(${PROJECT_NAME} PRIVATE ++ wsi/extensions/external_memory_extension.cpp ++ wsi/image_backing_memory_external.cpp) ++endif() ++ + # Install the layer and its manifest into a Vulkan implicit layer directory. Upstream leaves this to + # manual copying; the fork adds install rules so the Debian package picks up the .so and JSON. + install(TARGETS ${PROJECT_NAME} DESTINATION share/vulkan/implicit_layer.d/) diff --git a/tools/vulkan-wsi/source.env b/tools/vulkan-wsi/source.env new file mode 100644 index 0000000000..4c6e9f7a3b --- /dev/null +++ b/tools/vulkan-wsi/source.env @@ -0,0 +1,2 @@ +WSI_REVISION=40cfec09d0e2d42c5e1f2642cf4cba11e7008112 +VULKAN_HEADERS_REVISION=8d6039a455a7ecc7d2a592ff97f62db4e59b70bf From 4cbd7722f87553c28ab490abe59e5d1d30e93daf Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 22:58:10 -0500 Subject: [PATCH 84/85] feat: the PowerVR runtime is a downloaded add-on pack, not bundled in the APK (#2157) * feat: the PowerVR runtime is a downloaded add-on pack, not bundled in the APK * fix: a stopped session cancels the PowerVR pack download * fix: a session stopped during runtime unpacking ends before staging * fix: a failed PowerVR pack download ends the session with a message --- .github/workflows/build.yml | 4 +++- .github/workflows/publish-packs.yml | 2 +- app/build.gradle | 4 ++-- .../java/com/droiddeck/launcher/core/AddonPack.kt | 3 +++ .../launcher/gpu/SystemVulkanDriver.java | 12 +++++++++--- .../droiddeck/launcher/session/SessionService.kt | 15 ++++++++++++++- app/src/main/res/values-ar/strings.xml | 1 + app/src/main/res/values-b+es+419/strings.xml | 1 + app/src/main/res/values-bg/strings.xml | 1 + app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values-da/strings.xml | 1 + app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-el/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fi/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-hi/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 1 + app/src/main/res/values-in/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-ko/strings.xml | 1 + app/src/main/res/values-ms/strings.xml | 1 + app/src/main/res/values-nb/strings.xml | 1 + app/src/main/res/values-nl/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values-ro/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-th/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values-uk/strings.xml | 1 + app/src/main/res/values-vi/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + tools/packs/build.sh | 1 + tools/release/check_session_assets.py | 7 ++++--- tools/release/runtime_inputs.py | 4 ++-- tools/tests/test_runtime_inputs.py | 5 +++++ 43 files changed, 77 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 083c052500..fcb30d8ac1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -548,7 +548,9 @@ jobs: key: pack-inputs-v1-${{ hashFiles('tools/packs/build.sh', 'tools/packs/fetch-verified.sh', 'tools/packs/tracking/release.env') }} restore-keys: pack-inputs-v1- - name: Build the add-on packs - run: bash tools/packs/build.sh app/build/packs + run: | + python3 tools/powervr/fetch.py + bash tools/packs/build.sh app/build/packs - name: Pin the Syncthing source id: syncthing-src diff --git a/.github/workflows/publish-packs.yml b/.github/workflows/publish-packs.yml index de4adb3b21..ca61616d18 100644 --- a/.github/workflows/publish-packs.yml +++ b/.github/workflows/publish-packs.yml @@ -55,7 +55,7 @@ jobs: jq -r --arg n "$2" '.assets // [] | .[] | select(.name == $n) | .digest // empty' } commit=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$BUILD_RUN" --jq .head_sha 2>/dev/null || echo "$GITHUB_SHA") - for name in proot directaudio tracking xbox comet butler; do + for name in proot directaudio tracking xbox comet butler powervr; do file="packs/$name.tar.zst" [ -f "$file" ] || { echo "::error::$name.tar.zst is missing from Build APK run $BUILD_RUN"; exit 1; } sha=$(sha256sum "$file" | cut -d' ' -f1) diff --git a/app/build.gradle b/app/build.gradle index 65353df279..743ad2a847 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -93,7 +93,7 @@ def trackingPack = rootProject.file('tools/packs/tracking/release.env').readLine def prootPackPin = rootProject.file('tools/packs/proot/release.env').readLines() .findAll { it.contains('=') && !it.startsWith('#') } .collectEntries { def kv = it.split('=', 2); [(kv[0].trim()): kv[1].trim()] } -def addonPacks = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler'].collectEntries { name -> +def addonPacks = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler', 'powervr'].collectEntries { name -> def pack = file("build/packs/${name}.tar.zst") if (!pack.isFile()) { if (ciBuild) throw new GradleException("Add-on pack ${pack} is missing: run tools/packs/build.sh app/build/packs") @@ -205,7 +205,7 @@ android { } androidResources { - ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~:<dir>droiddeck-xbox:<dir>droiddeck-comet:<dir>directaudio' + ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~:<dir>droiddeck-xbox:<dir>droiddeck-comet:<dir>directaudio:<dir>hybris' } packagingOptions { diff --git a/app/src/main/java/com/droiddeck/launcher/core/AddonPack.kt b/app/src/main/java/com/droiddeck/launcher/core/AddonPack.kt index 383dd98bbd..4f88d90e34 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/AddonPack.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/AddonPack.kt @@ -149,5 +149,8 @@ internal class AddonPack( listOf("version", "comet")) val BUTLER = AddonPack("butler", BuildConfig.PACK_BUTLER_SHA256, BuildConfig.PACK_BUTLER_SIZE, listOf("version", "butler", "7z.so", "libc7zip.so")) + @JvmField + val POWERVR = AddonPack("powervr", BuildConfig.PACK_POWERVR_SHA256, BuildConfig.PACK_POWERVR_SIZE, + listOf("runtime.tzst", "version.txt")) } } diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/SystemVulkanDriver.java b/app/src/main/java/com/droiddeck/launcher/gpu/SystemVulkanDriver.java index 07ba47cd16..25a6e363c6 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/SystemVulkanDriver.java +++ b/app/src/main/java/com/droiddeck/launcher/gpu/SystemVulkanDriver.java @@ -5,9 +5,11 @@ import android.os.Build; import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; +import com.droiddeck.launcher.core.AddonPack; import com.droiddeck.launcher.core.FileUtils; import com.droiddeck.launcher.core.TarZst; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -21,7 +23,6 @@ import org.json.JSONObject; /** Isolated glibc-to-Android Vulkan bridge. It does not replace the rootfs's Mesa libraries. */ public final class SystemVulkanDriver { - private static final String ASSET = "hybris/runtime.tzst"; /** Vendor HALs the bridge loads. Samsung Xclipse (Exynos, sgpu) is experimental. */ private static final String[] HALS = { "/vendor/lib64/hw/vulkan.powervr.so", @@ -144,13 +145,17 @@ public final class SystemVulkanDriver { if (!isPowerVr()) throw new IOException("System PowerVR Vulkan driver is unavailable"); if (!renderNodeAvailable()) throw new IOException( "System PowerVR requires an identifiable, readable and writable DRM render node"); + if (!AddonPack.POWERVR.await(context)) throw new IOException( + "Couldn't download the PowerVR graphics runtime. Check your connection and try again."); File target = runtimeDirectory(context); File base = target.getParentFile(); if (complete(target)) return target; if (!base.isDirectory() && !base.mkdirs()) throw new IOException("Cannot create system Vulkan directory"); File staged = new File(base, ".stage-" + UUID.randomUUID()); try { - if (!TarZst.extractAsset(context, ASSET, staged)) throw new IOException("Cannot unpack system Vulkan runtime"); + try (FileInputStream archive = new FileInputStream(AddonPack.POWERVR.file(context, "runtime.tzst"))) { + if (!TarZst.extract(archive, staged)) throw new IOException("Cannot unpack system Vulkan runtime"); + } for (String name : REQUIRED) if (!present(staged, name)) throw new IOException("Missing system Vulkan component: " + name); if (!new File(staged, "run-proton.py").canExecute()) @@ -175,8 +180,9 @@ public final class SystemVulkanDriver { /** The current APK's versioned runtime path, without extracting or modifying it. */ public static File runtimeDirectory(Context context) throws IOException { String version; + if (!AddonPack.POWERVR.installed(context)) throw new IOException("PowerVR graphics runtime is not installed"); try (BufferedReader input = new BufferedReader(new InputStreamReader( - context.getAssets().open("hybris/version.txt"), StandardCharsets.US_ASCII))) { + new FileInputStream(AddonPack.POWERVR.file(context, "version.txt")), StandardCharsets.US_ASCII))) { version = input.readLine(); } if (version == null || !version.matches("[0-9a-f]{64}")) throw new IOException("Invalid system Vulkan runtime version"); 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 72e5543d3e..cc67bc800d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -476,10 +476,19 @@ class SessionService : Service() { val stillStarting = { gen == sessionGen && SessionState.running } val prootPack = LinuxRuntime.patchedProot(this) || AddonPack.PROOT.await(this, stillStarting) val directAudioPack = AddonPack.DIRECTAUDIO.await(this, stillStarting) + val systemVulkan = SystemVulkanDriver.usesDefault(SessionPrefs.linuxDriver(this)) + val powerVrPack = !systemVulkan || (stillStarting() && AddonPack.POWERVR.await(this, stillStarting)) if (!stillStarting()) { Log.i(TAG, "session stopped while add-on packs were downloading") return } + if (!powerVrPack) { + val message = getString(R.string.session_powervr_missing) + Log.e(TAG, "powervr pack unavailable; the system graphics runtime cannot be prepared") + failSession(gen, "POWERVR_MISSING", message, -1) + stopSession(-1, gen) + return + } if (!directAudioPack) { Log.w(TAG, "directaudio pack unavailable; game audio drivers will not be staged") mainHandler.post { @@ -501,8 +510,12 @@ class SessionService : Service() { .onFailure { Log.w(TAG, "agent environment skipped", it) } .getOrDefault(emptyList()) try { - if (SystemVulkanDriver.usesDefault(SessionPrefs.linuxDriver(this))) { + if (systemVulkan) { SystemVulkanDriver.prepare(this) + if (!stillStarting()) { + Log.i(TAG, "session stopped while the system graphics runtime was unpacking") + return + } pruneSystemVulkanRuntime() } SessionFiles.stage(this, root, startsSession = true) diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index c891154b5d..834abdfe30 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s عبر FEX</string> <string name="app_fex_not_ready">هذا البرنامج مبني لأجهزة كمبيوتر %1$s ويعمل عبر FEX، الذي لم يتم إعداده بعد. افتح Steam مرة واحدة أثناء تسجيل الدخول: سيجعله DroidDeck يُنزّل FEX وSteam Linux Runtime اللازمة، ثم يُفتح هذا البرنامج.</string> <string name="session_proot_missing">تعذّر تنزيل proot الخاص بـ DroidDeck. تحقّق من الاتصال وحاول مرة أخرى. لم تبدأ الجلسة لأن proot الاحتياطي أبطأ من أن يصلح للعب.</string> + <string name="session_powervr_missing">تعذّر تنزيل بيئة رسومات PowerVR. تحقق من الاتصال وحاول مرة أخرى.</string> <string name="session_directaudio_missing">تعذّر تنزيل DirectAudio، لذا يستخدم صوت الألعاب المسار الأبطأ في هذه الجلسة.</string> <string name="session_end_program">هذا البرنامج</string> <string name="session_end_steam_download">تعذّر تنزيل عميل Steam. قد تكون شبكتك أو VPN تحظر خوادم Steam؛ تحقّق من الاتصال وحاول مرة أخرى.</string> diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index df69655077..0ed75155df 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s con FEX</string> <string name="app_fex_not_ready">Este programa está hecho para PC %1$s y se ejecuta con FEX, que aún no está listo. Abre Steam una vez con tu sesión iniciada: DroidDeck hará que descargue FEX y el Steam Linux Runtime que necesita, y después se abrirá.</string> <string name="session_proot_missing">No se pudo descargar el proot de DroidDeck. Revisa la conexión e inténtalo de nuevo. La sesión no se inició porque el proot alternativo es demasiado lento para jugar.</string> + <string name="session_powervr_missing">No se pudo descargar el entorno gráfico de PowerVR. Revisa la conexión e inténtalo de nuevo.</string> <string name="session_directaudio_missing">No se pudo descargar DirectAudio, así que el audio de los juegos usa la ruta más lenta en esta sesión.</string> <string name="session_end_program">Este programa</string> <string name="session_end_steam_download">No se pudo descargar el cliente de Steam. Es posible que tu red o VPN esté bloqueando los servidores de Steam; revisa la conexión e inténtalo de nuevo.</string> diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index a12a74bc8e..60892c4e26 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s през FEX</string> <string name="app_fex_not_ready">Тази програма е компилирана за %1$s компютри и се стартира през FEX, който още не е настроен. Отворете Steam веднъж, докато сте влезли: DroidDeck ще изтегли FEX и необходимата Steam Linux Runtime, след което тя ще се отвори.</string> <string name="session_proot_missing">proot на DroidDeck не можа да бъде изтеглен. Проверете връзката и опитайте пак. Сесията не беше стартирана, защото резервният proot е твърде бавен за игра.</string> + <string name="session_powervr_missing">Графичната среда за PowerVR не можа да бъде изтеглена. Проверете връзката и опитайте отново.</string> <string name="session_directaudio_missing">DirectAudio не можа да бъде изтеглен, затова звукът на игрите използва по-бавния път в тази сесия.</string> <string name="session_end_program">Тази програма</string> <string name="session_end_steam_download">Клиентът на Steam не можа да бъде изтеглен. Мрежата или VPN връзката ви може да блокира сървърите на Steam; проверете връзката и опитайте отново.</string> diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index f66fb31fb7..cd16bb55a5 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s přes FEX</string> <string name="app_fex_not_ready">Tento program je sestaven pro PC %1$s a běží přes FEX, který ještě není nastaven. Jednou spusťte přihlášený Steam: DroidDeck tím stáhne FEX a Steam Linux Runtime, který potřebuje, a pak se tento program otevře.</string> <string name="session_proot_missing">Proot od DroidDeck se nepodařilo stáhnout. Zkontrolujte připojení a zkuste to znovu. Relace nebyla spuštěna, protože záložní proot je na hraní příliš pomalý.</string> + <string name="session_powervr_missing">Grafické prostředí PowerVR se nepodařilo stáhnout. Zkontrolujte připojení a zkuste to znovu.</string> <string name="session_directaudio_missing">DirectAudio se nepodařilo stáhnout, takže zvuk her v této relaci používá pomalejší cestu.</string> <string name="session_end_program">Tento program</string> <string name="session_end_steam_download">Klienta Steam se nepodařilo stáhnout. Vaše síť nebo VPN možná blokuje servery Steamu; zkontrolujte připojení a zkuste to znovu.</string> diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index ab5f0859c0..5cd13422dc 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s via FEX</string> <string name="app_fex_not_ready">Dette program er bygget til %1$s-pc’er og køres via FEX, som ikke er sat op endnu. Åbn Steam én gang, mens du er logget ind: DroidDeck downloader så FEX og den Steam Linux Runtime, det kræver, hvorefter dette åbner.</string> <string name="session_proot_missing">DroidDecks proot kunne ikke downloades. Tjek forbindelsen, og prøv igen. Sessionen blev ikke startet, fordi reserve-proot er for langsom at spille på.</string> + <string name="session_powervr_missing">PowerVR-grafikmiljøet kunne ikke hentes. Tjek forbindelsen, og prøv igen.</string> <string name="session_directaudio_missing">DirectAudio kunne ikke downloades, så spillyd bruger den langsommere vej i denne session.</string> <string name="session_end_program">Dette program</string> <string name="session_end_steam_download">Steam-klienten kunne ikke downloades. Dit netværk eller din VPN blokerer muligvis Steams servere; tjek forbindelsen, og prøv igen.</string> diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index e4bfaa32b7..1d018727b0 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s über FEX</string> <string name="app_fex_not_ready">Dieses Programm ist für %1$s-PCs gebaut und läuft über FEX, das noch nicht eingerichtet ist. Öffne Steam einmal, während du angemeldet bist: DroidDeck lässt es FEX und die nötige Steam Linux Runtime herunterladen, danach lässt sich das Programm öffnen.</string> <string name="session_proot_missing">DroidDecks proot konnte nicht heruntergeladen werden. Prüfe die Verbindung und versuch es erneut. Die Sitzung wurde nicht gestartet, da das Ersatz-proot zum Spielen zu langsam ist.</string> + <string name="session_powervr_missing">Die PowerVR-Grafikumgebung konnte nicht heruntergeladen werden. Prüfe die Verbindung und versuch es erneut.</string> <string name="session_directaudio_missing">DirectAudio konnte nicht heruntergeladen werden, daher nutzt der Spielton in dieser Sitzung den langsameren Weg.</string> <string name="session_end_program">Dieses Programm</string> <string name="session_end_steam_download">Der Steam-Client konnte nicht heruntergeladen werden. Dein Netzwerk oder VPN blockiert möglicherweise die Server von Steam; prüfe die Verbindung und versuche es erneut.</string> diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 806ba09726..c707441971 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s μέσω FEX</string> <string name="app_fex_not_ready">Αυτό το πρόγραμμα είναι χτισμένο για υπολογιστές %1$s και εκτελείται μέσω FEX, το οποίο δεν έχει ρυθμιστεί ακόμα. Ανοίξτε το Steam μία φορά ενώ είστε συνδεδεμένοι: το DroidDeck κάνει λήψη του FEX και του Steam Linux Runtime που χρειάζεται, και μετά αυτό ανοίγει.</string> <string name="session_proot_missing">Δεν ήταν δυνατή η λήψη του proot του DroidDeck. Ελέγξτε τη σύνδεση και δοκιμάστε ξανά. Η συνεδρία δεν ξεκίνησε, επειδή το εναλλακτικό proot είναι πολύ αργό για παιχνίδι.</string> + <string name="session_powervr_missing">Δεν ήταν δυνατή η λήψη του γραφικού περιβάλλοντος PowerVR. Ελέγξτε τη σύνδεση και δοκιμάστε ξανά.</string> <string name="session_directaudio_missing">Δεν ήταν δυνατή η λήψη του DirectAudio, οπότε ο ήχος των παιχνιδιών χρησιμοποιεί την πιο αργή διαδρομή σε αυτή τη συνεδρία.</string> <string name="session_end_program">Αυτό το πρόγραμμα</string> <string name="session_end_steam_download">Δεν ήταν δυνατή η λήψη του πελάτη Steam. Το δίκτυο ή το VPN σας ίσως αποκλείει τους διακομιστές του Steam· ελέγξτε τη σύνδεση και δοκιμάστε ξανά.</string> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 25fe78e325..515377e570 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s con FEX</string> <string name="app_fex_not_ready">Este programa está hecho para PC %1$s y se ejecuta con FEX, que aún no está listo. Abre Steam una vez con tu sesión iniciada: DroidDeck hará que descargue FEX y el Steam Linux Runtime que necesita, y después se abrirá.</string> <string name="session_proot_missing">No se ha podido descargar el proot de DroidDeck. Comprueba la conexión y vuelve a intentarlo. La sesión no se ha iniciado porque el proot alternativo es demasiado lento para jugar.</string> + <string name="session_powervr_missing">No se pudo descargar el entorno gráfico de PowerVR. Comprueba la conexión e inténtalo de nuevo.</string> <string name="session_directaudio_missing">No se ha podido descargar DirectAudio, así que el audio de los juegos usa la ruta más lenta en esta sesión.</string> <string name="session_end_program">Este programa</string> <string name="session_end_steam_download">No se ha podido descargar el cliente de Steam. Puede que tu red o VPN esté bloqueando los servidores de Steam; comprueba la conexión y vuelve a intentarlo.</string> diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 22732a6733..117684b0e9 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s FEXin kautta</string> <string name="app_fex_not_ready">Tämä ohjelma on tehty %1$s-tietokoneille ja käynnistyy FEXin kautta, jota ei ole vielä määritetty. Avaa Steam kerran kirjautuneena: DroidDeck lataa sen myötä FEXin ja tarvittavan Steam Linux Runtimen, jonka jälkeen tämä avautuu.</string> <string name="session_proot_missing">DroidDeckin proota ei voitu ladata. Tarkista yhteys ja yritä uudelleen. Istuntoa ei käynnistetty, koska varaproot on liian hidas pelaamiseen.</string> + <string name="session_powervr_missing">PowerVR-grafiikkaympäristöä ei voitu ladata. Tarkista yhteys ja yritä uudelleen.</string> <string name="session_directaudio_missing">DirectAudiota ei voitu ladata, joten pelin ääni käyttää tässä istunnossa hitaampaa reittiä.</string> <string name="session_end_program">Tämä ohjelma</string> <string name="session_end_steam_download">Steam-asiakasohjelmaa ei voitu ladata. Verkkosi tai VPN saattaa estää Steamin palvelimet; tarkista yhteys ja yritä uudelleen.</string> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index f7cf229421..ddfb37df98 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s via FEX</string> <string name="app_fex_not_ready">Ce programme est conçu pour les PC %1$s et s\'exécute via FEX, qui n\'est pas encore configuré. Ouvrez Steam une fois en étant connecté : DroidDeck lui fait télécharger FEX et le Steam Linux Runtime nécessaires, puis ce programme s\'ouvre.</string> <string name="session_proot_missing">Impossible de télécharger le proot de DroidDeck. Vérifiez la connexion et réessayez. La session n\'a pas été démarrée, car le proot de secours est trop lent pour jouer.</string> + <string name="session_powervr_missing">L\'environnement graphique PowerVR n\'a pas pu être téléchargé. Vérifiez la connexion et réessayez.</string> <string name="session_directaudio_missing">Impossible de télécharger DirectAudio ; l\'audio des jeux utilise le chemin plus lent pour cette session.</string> <string name="session_end_program">Ce programme</string> <string name="session_end_steam_download">Impossible de télécharger le client Steam. Votre réseau ou votre VPN bloque peut-être les serveurs de Steam ; vérifiez la connexion et réessayez.</string> diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 97a501f42f..0a0352c9c0 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">FEX के ज़रिए %1$s</string> <string name="app_fex_not_ready">यह प्रोग्राम %1$s पीसी के लिए बना है और FEX के ज़रिए चलता है, जो अभी सेट नहीं है। साइन इन रहते हुए Steam एक बार खोलें: DroidDeck इससे FEX और ज़रूरी Steam Linux Runtime डाउनलोड करवा लेगा, फिर यह खुल जाएगा।</string> <string name="session_proot_missing">DroidDeck का proot डाउनलोड नहीं हो सका। कनेक्शन जांचें और फिर कोशिश करें। सेशन शुरू नहीं किया गया, क्योंकि बैकअप proot खेलने के लिए बहुत धीमा है।</string> + <string name="session_powervr_missing">PowerVR ग्राफ़िक्स एनवायरमेंट डाउनलोड नहीं हो सका। कनेक्शन जाँचें और फिर कोशिश करें।</string> <string name="session_directaudio_missing">DirectAudio डाउनलोड नहीं हो सका, इसलिए इस सेशन में गेम ऑडियो धीमा पाथ इस्तेमाल करता है।</string> <string name="session_end_program">यह प्रोग्राम</string> <string name="session_end_steam_download">Steam क्लाइंट डाउनलोड नहीं हो सका। हो सकता है आपका नेटवर्क या VPN Steam के सर्वर ब्लॉक कर रहा हो; कनेक्शन जांचें और फिर से कोशिश करें।</string> diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 9106d8a271..f874f6ec3f 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s a FEX-en keresztül</string> <string name="app_fex_not_ready">Ez a program %1$s PC-khez készült, és a FEX-en keresztül fut, amely még nincs beállítva. Nyissa meg egyszer a Steamet bejelentkezve: a DroidDeck ekkor letölti a FEX-et és a szükséges Steam Linux Runtime-ot, majd ez megnyílik.</string> <string name="session_proot_missing">A DroidDeck proot nem tölthető le. Ellenőrizze a kapcsolatot, és próbálja újra. A munkamenet nem indult el, mert a tartalék proot túl lassú a játékhoz.</string> + <string name="session_powervr_missing">A PowerVR grafikus környezetet nem sikerült letölteni. Ellenőrizd a kapcsolatot, és próbáld újra.</string> <string name="session_directaudio_missing">A DirectAudio nem tölthető le, ezért a játékhang ebben a munkamenetben a lassabb útvonalat használja.</string> <string name="session_end_program">Ez a program</string> <string name="session_end_steam_download">A Steam-klienst nem sikerült letölteni. Lehet, hogy a hálózat vagy a VPN blokkolja a Steam szervereit; ellenőrizd a kapcsolatot, és próbáld újra.</string> diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 5746a1ed6d..d4533a63df 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s melalui FEX</string> <string name="app_fex_not_ready">Program ini dibuat untuk PC %1$s dan berjalan melalui FEX, yang belum disiapkan. Buka Steam sekali saat masuk: DroidDeck akan mengunduh FEX dan Steam Linux Runtime yang diperlukan, lalu ini akan terbuka.</string> <string name="session_proot_missing">proot DroidDeck tidak dapat diunduh. Periksa koneksi lalu coba lagi. Sesi tidak dimulai karena proot cadangan terlalu lambat untuk bermain.</string> + <string name="session_powervr_missing">Lingkungan grafis PowerVR tidak dapat diunduh. Periksa koneksi dan coba lagi.</string> <string name="session_directaudio_missing">DirectAudio tidak dapat diunduh, jadi audio gim menggunakan jalur yang lebih lambat di sesi ini.</string> <string name="session_end_program">Program ini</string> <string name="session_end_steam_download">Tidak dapat mengunduh klien Steam. Jaringan atau VPN Anda mungkin memblokir server Steam; periksa koneksi lalu coba lagi.</string> diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 64ef998189..7f961d5b2e 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s tramite FEX</string> <string name="app_fex_not_ready">Questo programma è compilato per PC %1$s e viene eseguito tramite FEX, che non è ancora configurato. Apri Steam una volta dopo aver eseguito l\'accesso: DroidDeck gli farà scaricare FEX e lo Steam Linux Runtime necessario, poi il programma si aprirà.</string> <string name="session_proot_missing">Impossibile scaricare il proot di DroidDeck. Controlla la connessione e riprova. La sessione non è stata avviata perché il proot di riserva è troppo lento per giocare.</string> + <string name="session_powervr_missing">Non è stato possibile scaricare l\'ambiente grafico PowerVR. Controlla la connessione e riprova.</string> <string name="session_directaudio_missing">Impossibile scaricare DirectAudio, quindi l\'audio dei giochi usa il percorso più lento in questa sessione.</string> <string name="session_end_program">Questo programma</string> <string name="session_end_steam_download">Impossibile scaricare il client Steam. La rete o la VPN potrebbe bloccare i server di Steam; controlla la connessione e riprova.</string> diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index a2bb315e02..d65ec2dd54 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s(FEX経由)</string> <string name="app_fex_not_ready">このプログラムは%1$s PC向けにビルドされており、FEX経由で実行されますが、FEXはまだセットアップされていません。ログインした状態で一度Steamを開いてください。DroidDeckがFEXと必要なSteam Linux Runtimeをダウンロードした後、このプログラムが開きます。</string> <string name="session_proot_missing">DroidDeckのprootをダウンロードできませんでした。接続を確認して、もう一度お試しください。代替のprootではプレイするには遅すぎるため、セッションは開始されませんでした。</string> + <string name="session_powervr_missing">PowerVRのグラフィックス環境をダウンロードできませんでした。接続を確認して、もう一度お試しください。</string> <string name="session_directaudio_missing">DirectAudioをダウンロードできなかったため、このセッションではゲーム音声に低速な経路を使用します。</string> <string name="session_end_program">このプログラム</string> <string name="session_end_steam_download">Steamクライアントをダウンロードできませんでした。ネットワークまたはVPNがSteamのサーバーをブロックしている可能性があります。接続を確認して、もう一度お試しください。</string> diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 2772a9ce1a..616b3ac824 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">FEX로 실행되는 %1$s</string> <string name="app_fex_not_ready">이 프로그램은 %1$s PC용으로 빌드되어 FEX를 통해 실행되지만, FEX가 아직 설정되지 않았습니다. 로그인한 상태로 Steam을 한 번 열면 DroidDeck이 FEX와 필요한 Steam Linux Runtime을 다운로드한 후 이 프로그램을 엽니다.</string> <string name="session_proot_missing">DroidDeck의 proot를 다운로드할 수 없습니다. 연결을 확인하고 다시 시도하세요. 대체 proot는 플레이하기에 너무 느리므로 세션을 시작하지 않았습니다.</string> + <string name="session_powervr_missing">PowerVR 그래픽 환경을 다운로드하지 못했습니다. 연결을 확인하고 다시 시도하세요.</string> <string name="session_directaudio_missing">DirectAudio를 다운로드할 수 없어 이번 세션에서는 게임 오디오가 더 느린 경로를 사용합니다.</string> <string name="session_end_program">이 프로그램</string> <string name="session_end_steam_download">Steam 클라이언트를 다운로드할 수 없습니다. 네트워크나 VPN이 Steam 서버를 차단하고 있을 수 있습니다. 연결을 확인하고 다시 시도하세요.</string> diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 604346d7f2..36f616f735 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s melalui FEX</string> <string name="app_fex_not_ready">Program ini dibina untuk PC %1$s dan berjalan melalui FEX, yang belum disediakan lagi. Buka Steam sekali semasa anda log masuk: DroidDeck akan memuat turun FEX dan Steam Linux Runtime yang diperlukan, kemudian ini akan dibuka.</string> <string name="session_proot_missing">proot DroidDeck tidak dapat dimuat turun. Semak sambungan dan cuba lagi. Sesi tidak dimulakan kerana proot sandaran terlalu perlahan untuk bermain.</string> + <string name="session_powervr_missing">Persekitaran grafik PowerVR tidak dapat dimuat turun. Semak sambungan dan cuba lagi.</string> <string name="session_directaudio_missing">DirectAudio tidak dapat dimuat turun, jadi audio permainan menggunakan laluan yang lebih perlahan untuk sesi ini.</string> <string name="session_end_program">Program ini</string> <string name="session_end_steam_download">Tidak dapat memuat turun klien Steam. Rangkaian atau VPN anda mungkin menyekat pelayan Steam; semak sambungan dan cuba lagi.</string> diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 91921ebcaa..77e3064058 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s via FEX</string> <string name="app_fex_not_ready">Dette programmet er bygget for %1$s-PC-er og kjører via FEX, som ikke er satt opp ennå. Åpne Steam én gang mens du er innlogget: DroidDeck lar den laste ned FEX og Steam Linux Runtime den trenger, og så åpnes dette.</string> <string name="session_proot_missing">Kunne ikke laste ned DroidDecks proot. Sjekk tilkoblingen og prøv igjen. Sesjonen ble ikke startet, fordi reserve-proot er for treg til å spille på.</string> + <string name="session_powervr_missing">PowerVR-grafikkmiljøet kunne ikke lastes ned. Sjekk tilkoblingen og prøv igjen.</string> <string name="session_directaudio_missing">Kunne ikke laste ned DirectAudio, så spillyd bruker den tregere veien i denne sesjonen.</string> <string name="session_end_program">Dette programmet</string> <string name="session_end_steam_download">Kunne ikke laste ned Steam-klienten. Nettverket eller VPN-en din blokkerer kanskje Steams servere; sjekk tilkoblingen og prøv igjen.</string> diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index cc6cafe928..9362590926 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s via FEX</string> <string name="app_fex_not_ready">Dit programma is gemaakt voor %1$s-pc’s en draait via FEX, dat nog niet is ingesteld. Open Steam één keer terwijl je bent ingelogd: DroidDeck laat het dan FEX en de benodigde Steam Linux Runtime downloaden. Daarna opent dit.</string> <string name="session_proot_missing">De proot van DroidDeck kon niet worden gedownload. Controleer de verbinding en probeer het opnieuw. De sessie is niet gestart, omdat de reserve-proot te traag is om op te spelen.</string> + <string name="session_powervr_missing">De PowerVR-grafische omgeving kon niet worden gedownload. Controleer de verbinding en probeer het opnieuw.</string> <string name="session_directaudio_missing">DirectAudio kon niet worden gedownload, dus gamegeluid gebruikt deze sessie de tragere route.</string> <string name="session_end_program">Dit programma</string> <string name="session_end_steam_download">De Steam-client kon niet worden gedownload. Je netwerk of VPN blokkeert mogelijk de servers van Steam; controleer de verbinding en probeer het opnieuw.</string> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index a7f13dc4e6..659e20825e 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s przez FEX</string> <string name="app_fex_not_ready">Ten program jest zbudowany dla komputerów %1$s i działa przez FEX, który nie jest jeszcze skonfigurowany. Otwórz raz Steam po zalogowaniu: DroidDeck pobierze wtedy FEX i potrzebne Steam Linux Runtime, a potem program się otworzy.</string> <string name="session_proot_missing">Nie udało się pobrać proot DroidDeck. Sprawdź połączenie i spróbuj ponownie. Sesja nie została uruchomiona, bo zapasowy proot jest zbyt wolny do grania.</string> + <string name="session_powervr_missing">Nie udało się pobrać środowiska graficznego PowerVR. Sprawdź połączenie i spróbuj ponownie.</string> <string name="session_directaudio_missing">Nie udało się pobrać DirectAudio, więc w tej sesji dźwięk gier używa wolniejszej ścieżki.</string> <string name="session_end_program">Ten program</string> <string name="session_end_steam_download">Nie udało się pobrać klienta Steam. Twoja sieć lub VPN może blokować serwery Steam; sprawdź połączenie i spróbuj ponownie.</string> diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index d546126ad8..3d75d649b4 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s através do FEX</string> <string name="app_fex_not_ready">Este programa foi compilado para PCs %1$s e é executado através do FEX, que ainda não está configurado. Abra o Steam uma vez com a sessão iniciada: o DroidDeck transfere o FEX e o Steam Linux Runtime necessários e, depois, este programa abre.</string> <string name="session_proot_missing">Não foi possível transferir o proot do DroidDeck. Verifique a ligação e tente novamente. A sessão não foi iniciada, porque o proot alternativo é demasiado lento para jogar.</string> + <string name="session_powervr_missing">Não foi possível transferir o ambiente gráfico PowerVR. Verifique a ligação e tente novamente.</string> <string name="session_directaudio_missing">Não foi possível transferir o DirectAudio, por isso o áudio dos jogos utiliza o caminho mais lento nesta sessão.</string> <string name="session_end_program">Este programa</string> <string name="session_end_steam_download">Não foi possível transferir o cliente Steam. A sua rede ou VPN pode estar a bloquear os servidores da Steam; verifique a ligação e tente novamente.</string> diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 2d16517905..7968e00e17 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s pelo FEX</string> <string name="app_fex_not_ready">Este programa é feito para PCs %1$s e roda pelo FEX, que ainda não está configurado. Abra a Steam uma vez com a sessão iniciada: o DroidDeck faz com que ela baixe o FEX e o Steam Linux Runtime necessários, e então isto abre.</string> <string name="session_proot_missing">Não foi possível baixar o proot do DroidDeck. Verifique a conexão e tente novamente. A sessão não foi iniciada, porque o proot alternativo é lento demais para jogar.</string> + <string name="session_powervr_missing">Não foi possível baixar o ambiente gráfico PowerVR. Verifique a conexão e tente novamente.</string> <string name="session_directaudio_missing">Não foi possível baixar o DirectAudio, então o áudio dos jogos usa o caminho mais lento nesta sessão.</string> <string name="session_end_program">Este programa</string> <string name="session_end_steam_download">Não foi possível baixar o cliente Steam. Sua rede ou VPN pode estar bloqueando os servidores da Steam; verifique a conexão e tente novamente.</string> diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index acb7d2aaef..3421e379f6 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s prin FEX</string> <string name="app_fex_not_ready">Acest program este compilat pentru PC-uri %1$s și rulează prin FEX, care nu este încă configurat. Deschide Steam o dată, fiind autentificat: DroidDeck îl pune să descarce FEX și Steam Linux Runtime de care are nevoie, apoi acesta se deschide.</string> <string name="session_proot_missing">Proot-ul DroidDeck nu a putut fi descărcat. Verifică conexiunea și încearcă din nou. Sesiunea nu a fost pornită, deoarece proot-ul de rezervă este prea lent pentru jocuri.</string> + <string name="session_powervr_missing">Mediul grafic PowerVR nu a putut fi descărcat. Verifică conexiunea și încearcă din nou.</string> <string name="session_directaudio_missing">DirectAudio nu a putut fi descărcat, așa că sunetul jocurilor folosește calea mai lentă în această sesiune.</string> <string name="session_end_program">Acest program</string> <string name="session_end_steam_download">Clientul Steam nu a putut fi descărcat. Rețeaua sau VPN-ul tău poate bloca serverele Steam; verifică conexiunea și încearcă din nou.</string> diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index dd904460a5..f5d7878aa0 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s через FEX</string> <string name="app_fex_not_ready">Эта программа собрана для ПК на %1$s и работает через FEX, который еще не настроен. Откройте Steam один раз, войдя в аккаунт: DroidDeck скачает через него FEX и нужную Steam Linux Runtime, после чего программа откроется.</string> <string name="session_proot_missing">Не удалось скачать proot DroidDeck. Проверьте подключение и повторите попытку. Сессия не запущена, так как резервный proot слишком медленный для игры.</string> + <string name="session_powervr_missing">Не удалось скачать графическую среду PowerVR. Проверьте подключение и повторите попытку.</string> <string name="session_directaudio_missing">Не удалось скачать DirectAudio, поэтому в этой сессии звук игр идёт по более медленному пути.</string> <string name="session_end_program">Эта программа</string> <string name="session_end_steam_download">Не удалось скачать клиент Steam. Возможно, ваша сеть или VPN блокирует серверы Steam; проверьте подключение и повторите попытку.</string> diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index c9d57f28e1..5ac758d35d 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s via FEX</string> <string name="app_fex_not_ready">Programmet är byggt för %1$s-datorer och körs via FEX, som inte har konfigurerats än. Öppna Steam en gång medan du är inloggad: DroidDeck låter Steam ladda ned FEX och den Steam Linux Runtime som behövs, sedan öppnas detta.</string> <string name="session_proot_missing">Det gick inte att ladda ned DroidDecks proot. Kontrollera anslutningen och försök igen. Sessionen startades inte eftersom reserv-proot är för långsam att spela på.</string> + <string name="session_powervr_missing">PowerVR-grafikmiljön kunde inte laddas ned. Kontrollera anslutningen och försök igen.</string> <string name="session_directaudio_missing">Det gick inte att ladda ned DirectAudio, så spelljudet använder den långsammare vägen den här sessionen.</string> <string name="session_end_program">Det här programmet</string> <string name="session_end_steam_download">Det gick inte att ladda ned Steam-klienten. Ditt nätverk eller din VPN kanske blockerar Steams servrar; kontrollera anslutningen och försök igen.</string> diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index fa9ab354bf..056bc0fabf 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s ผ่าน FEX</string> <string name="app_fex_not_ready">โปรแกรมนี้สร้างมาสำหรับพีซี %1$s และรันผ่าน FEX ซึ่งยังไม่ได้ตั้งค่า เปิด Steam สักครั้งขณะลงชื่อเข้าใช้: DroidDeck จะดาวน์โหลด FEX และ Steam Linux Runtime ที่จำเป็น จากนั้นโปรแกรมนี้จะเปิดขึ้น</string> <string name="session_proot_missing">ดาวน์โหลด proot ของ DroidDeck ไม่ได้ ตรวจสอบการเชื่อมต่อแล้วลองใหม่ เซสชันไม่ได้เริ่มเพราะ proot สำรองช้าเกินกว่าจะเล่นได้</string> + <string name="session_powervr_missing">ดาวน์โหลดสภาพแวดล้อมกราฟิก PowerVR ไม่สำเร็จ ตรวจสอบการเชื่อมต่อแล้วลองอีกครั้ง</string> <string name="session_directaudio_missing">ดาวน์โหลด DirectAudio ไม่ได้ เสียงเกมในเซสชันนี้จึงใช้เส้นทางที่ช้ากว่า</string> <string name="session_end_program">โปรแกรมนี้</string> <string name="session_end_steam_download">ดาวน์โหลดไคลเอนต์ Steam ไม่ได้ เครือข่ายหรือ VPN ของคุณอาจบล็อกเซิร์ฟเวอร์ของ Steam ตรวจสอบการเชื่อมต่อแล้วลองอีกครั้ง</string> diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 9015b0d890..215f70eb33 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">FEX ile %1$s</string> <string name="app_fex_not_ready">Bu program %1$s PC\'ler için derlenmiş ve FEX ile çalışır, ancak FEX henüz kurulmadı. Oturum açmışken Steam\'i bir kez açın: DroidDeck, FEX\'i ve gereken Steam Linux Runtime\'ı indirtir, ardından bu program açılır.</string> <string name="session_proot_missing">DroidDeck\'in proot\'u indirilemedi. Bağlantıyı kontrol edip tekrar deneyin. Yedek proot oynamak için fazla yavaş olduğundan oturum başlatılmadı.</string> + <string name="session_powervr_missing">PowerVR grafik ortamı indirilemedi. Bağlantıyı kontrol edip tekrar deneyin.</string> <string name="session_directaudio_missing">DirectAudio indirilemedi, bu yüzden oyun sesi bu oturumda daha yavaş yolu kullanıyor.</string> <string name="session_end_program">Bu program</string> <string name="session_end_steam_download">Steam istemcisi indirilemedi. Ağınız veya VPN\'iniz Steam sunucularını engelliyor olabilir; bağlantıyı kontrol edip yeniden deneyin.</string> diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 7b9d82f355..2ab7524fe0 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s через FEX</string> <string name="app_fex_not_ready">Цю програму зібрано для ПК з архітектурою %1$s, і вона працює через FEX, який ще не налаштовано. Один раз відкрийте Steam, увійшовши в обліковий запис: DroidDeck завантажить FEX і потрібний йому Steam Linux Runtime, після чого програма відкриється.</string> <string name="session_proot_missing">Не вдалося завантажити proot DroidDeck. Перевірте зʼєднання та спробуйте ще раз. Сеанс не запущено, бо резервний proot занадто повільний для гри.</string> + <string name="session_powervr_missing">Не вдалося завантажити графічне середовище PowerVR. Перевірте підключення й повторіть спробу.</string> <string name="session_directaudio_missing">Не вдалося завантажити DirectAudio, тому в цьому сеансі звук ігор іде повільнішим шляхом.</string> <string name="session_end_program">Ця програма</string> <string name="session_end_steam_download">Не вдалося завантажити клієнт Steam. Можливо, ваша мережа або VPN блокує сервери Steam; перевірте з’єднання та спробуйте ще раз.</string> diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 8541e9c792..20a229dbc8 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s qua FEX</string> <string name="app_fex_not_ready">Chương trình này được build cho PC %1$s và chạy qua FEX, hiện chưa được thiết lập. Mở Steam một lần khi đã đăng nhập: DroidDeck sẽ tải FEX và Steam Linux Runtime cần thiết, sau đó ứng dụng này sẽ mở.</string> <string name="session_proot_missing">Không thể tải proot của DroidDeck. Hãy kiểm tra kết nối rồi thử lại. Phiên chưa được khởi động vì proot dự phòng quá chậm để chơi.</string> + <string name="session_powervr_missing">Không thể tải môi trường đồ họa PowerVR. Hãy kiểm tra kết nối rồi thử lại.</string> <string name="session_directaudio_missing">Không thể tải DirectAudio, nên âm thanh game dùng đường chậm hơn trong phiên này.</string> <string name="session_end_program">Chương trình này</string> <string name="session_end_steam_download">Không thể tải xuống client Steam. Mạng hoặc VPN của bạn có thể đang chặn máy chủ Steam; hãy kiểm tra kết nối rồi thử lại.</string> diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 3c64d969fa..eb1a16a5b0 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s 经由 FEX</string> <string name="app_fex_not_ready">此程序面向 %1$s PC 构建,需经由 FEX 运行,而 FEX 尚未配置。请在登录状态下打开一次 Steam:DroidDeck 会让其下载 FEX 及所需的 Steam Linux Runtime,之后即可打开。</string> <string name="session_proot_missing">无法下载 DroidDeck 的 proot。请检查网络连接后重试。由于备用 proot 太慢无法流畅游玩,会话未启动。</string> + <string name="session_powervr_missing">无法下载 PowerVR 图形环境。请检查网络连接后重试。</string> <string name="session_directaudio_missing">无法下载 DirectAudio,本次会话的游戏音频将使用较慢的路径。</string> <string name="session_end_program">此程序</string> <string name="session_end_steam_download">无法下载 Steam 客户端。你的网络或 VPN 可能屏蔽了 Steam 的服务器;请检查网络连接后重试。</string> diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index b864d4bf14..8372aa2b25 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">%1$s,透過 FEX</string> <string name="app_fex_not_ready">此程式是為 %1$s 電腦而設,需透過 FEX 執行,但 FEX 尚未設定。請在登入狀態下開啟一次 Steam:DroidDeck 會讓它下載 FEX 及所需的 Steam Linux Runtime,之後便會開啟此程式。</string> <string name="session_proot_missing">無法下載 DroidDeck 的 proot。請檢查連線後再試一次。會話未啟動,因為備用 proot 太慢,無法用來玩遊戲。</string> + <string name="session_powervr_missing">無法下載 PowerVR 圖形環境。請檢查網絡連線後再試。</string> <string name="session_directaudio_missing">無法下載 DirectAudio,因此本次會話的遊戲音訊會使用較慢的路徑。</string> <string name="session_end_program">此程式</string> <string name="session_end_steam_download">無法下載 Steam 用戶端。你的網絡或 VPN 可能封鎖了 Steam 的伺服器;請檢查連線後再試。</string> diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index e2988446ec..582f999643 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -180,6 +180,7 @@ <string name="app_fex_x86">透過 FEX 執行 %1$s</string> <string name="app_fex_not_ready">此程式是為 %1$s 電腦組建的,需透過 FEX 執行,但 FEX 尚未設定。請在登入狀態下開啟一次 Steam:DroidDeck 會讓它下載 FEX 和所需的 Steam Linux Runtime,之後就能開啟此程式。</string> <string name="session_proot_missing">無法下載 DroidDeck 的 proot。請檢查連線後再試一次。工作階段未啟動,因為備用 proot 太慢,無法用來玩遊戲。</string> + <string name="session_powervr_missing">無法下載 PowerVR 圖形環境。請檢查網路連線後再試。</string> <string name="session_directaudio_missing">無法下載 DirectAudio,因此本次工作階段的遊戲音訊會使用較慢的路徑。</string> <string name="session_end_program">此程式</string> <string name="session_end_steam_download">無法下載 Steam 用戶端。你的網路或 VPN 可能封鎖了 Steam 的伺服器;請檢查連線後再試一次。</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0bb1673a0f..bd341f6477 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -208,6 +208,7 @@ <string name="app_fex_x86">%1$s through FEX</string> <string name="app_fex_not_ready">This program is built for %1$s PCs and runs through FEX, which is not set up yet. Open Steam once while signed in: DroidDeck has it download FEX and the Steam Linux Runtime it needs, then this opens.</string> <string name="session_proot_missing">DroidDeck\'s proot could not be downloaded. Check the connection and try again. The session was not started, because the fallback proot is too slow to play on.</string> + <string name="session_powervr_missing">The PowerVR graphics runtime could not be downloaded. Check the connection and try again.</string> <string name="session_directaudio_missing">DirectAudio could not be downloaded, so game audio uses the slower path this session.</string> <string name="session_end_program">This program</string> <string name="session_end_present_fault">The session could not draw to the screen: %1$s. This screen shows why instead of a black one; the session logs have the details.</string> diff --git a/tools/packs/build.sh b/tools/packs/build.sh index 41dc7e03c0..7b7e7e76fd 100755 --- a/tools/packs/build.sh +++ b/tools/packs/build.sh @@ -76,6 +76,7 @@ pack tracking "$work/tracking" hand_landmarker.task hand_landmarker_lite.task po libopencv_java4.so libmediapipe_tasks_jni.so pack xbox "$linuxfs/droiddeck-xbox" version xodus-cli xodus-service pack comet "$linuxfs/droiddeck-comet" version comet +pack powervr "$repo/app/src/main/assets/hybris" runtime.tzst version.txt mkdir "$work/butler" fetch "https://broth.itch.zone/butler/linux-arm64/${BUTLER_VERSION}/archive/default" \ diff --git a/tools/release/check_session_assets.py b/tools/release/check_session_assets.py index af31d4c8c9..940e722481 100644 --- a/tools/release/check_session_assets.py +++ b/tools/release/check_session_assets.py @@ -51,9 +51,10 @@ def check(apk, overlay=OVERLAY): runtime = importlib.util.module_from_spec(spec) spec.loader.exec_module(runtime) try: - runtime.verify_archive(package.read('assets/hybris/runtime.tzst'), - package.read('assets/hybris/version.txt').decode('ascii')) - except (KeyError, ValueError, OSError) as error: + bundle = OVERLAY.parents[2] / 'app/src/main/assets/hybris' + runtime.verify_archive((bundle / 'runtime.tzst').read_bytes(), + (bundle / 'version.txt').read_text('ascii')) + except (ValueError, OSError) as error: errors.append('invalid PowerVR runtime: ' + str(error)) return errors diff --git a/tools/release/runtime_inputs.py b/tools/release/runtime_inputs.py index b14f13eff7..806c49f79e 100644 --- a/tools/release/runtime_inputs.py +++ b/tools/release/runtime_inputs.py @@ -14,11 +14,11 @@ ROOT = Path(__file__).resolve().parents[2] MANIFEST = Path('app/build/runtime-inputs.json') PACKS = Path('app/build/packs') PACKED = {'assets/linuxfs/usr/local/lib/droiddeck-xbox/': 'xbox', 'assets/linuxfs/usr/local/lib/droiddeck-comet/': 'comet', - 'assets/directaudio/': 'directaudio'} + 'assets/directaudio/': 'directaudio', 'assets/hybris/': 'powervr'} PACKED_FILES = {'lib/arm64-v8a/libproot.so': ('proot', 'libproot.so'), 'lib/arm64-v8a/libproot-loader.so': ('proot', 'libproot-loader.so')} PACKED_LIBRARIES = ['lib/arm64-v8a/libopencv_java4.so', 'lib/arm64-v8a/libmediapipe_tasks_jni.so'] -PACK_NAMES = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler'] +PACK_NAMES = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler', 'powervr'] SOURCE_PATHS = ['app/build.gradle', 'app/src/main/cpp/fakeinput_steam.cpp', 'app/src/main/assets/pulseaudio.tzst', 'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio', 'tools/packs', 'tools/gamescope/release.env', 'tools/droiddeck-esync/release.env', diff --git a/tools/tests/test_runtime_inputs.py b/tools/tests/test_runtime_inputs.py index e747f3320f..60c0fc9920 100644 --- a/tools/tests/test_runtime_inputs.py +++ b/tools/tests/test_runtime_inputs.py @@ -179,6 +179,11 @@ class RuntimeInputsTest(unittest.TestCase): with self.assertRaisesRegex(ValueError, 'xbox pack provides'): runtime.check_apk(apk, self.root) + def test_an_apk_still_carrying_the_powervr_runtime_is_rejected(self): + apk = self.current_apk(self.root / 'bundled.apk', {'assets/hybris/runtime.tzst': b'runtime'}) + with self.assertRaisesRegex(ValueError, 'powervr pack provides'): + runtime.check_apk(apk, self.root) + def test_an_apk_still_carrying_tracking_libraries_is_rejected(self): apk = self.current_apk(self.root / 'bundled.apk', {runtime.PACKED_LIBRARIES[0]: b'library'}) with self.assertRaisesRegex(ValueError, 'tracking pack provides'): From bf693d7f7125c8af797893910a1ebabd8112d378 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 5 Nov 2026 23:06:06 -0500 Subject: [PATCH 85/85] fix: Auto picks the upstream RADV pair on Xclipse 950 and 960 (#2158) * fix: Auto picks the upstream RADV pair on Xclipse 950 and 960 * fix: Auto reads the Xclipse model after the Vulkan query * fix: Auto treats an unnamed Xclipse like the 950 and 960 * fix: Auto reads any three digit Xclipse model number --- .../main/java/com/droiddeck/launcher/DriverMenus.kt | 1 + .../java/com/droiddeck/launcher/gpu/DriverPairs.kt | 11 ++++++++++- .../com/droiddeck/launcher/gpu/DriverPairsTest.kt | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt index 5fa92865fb..35a043c1ff 100644 --- a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt +++ b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt @@ -340,6 +340,7 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl runCatching { com.droiddeck.launcher.gpu.VulkanInfo.query() } ui.post { releaseChecking = false + if (gpu.family == GpuInfo.Family.POWERVR) gpu = GpuInfo.detect() refreshReleaseRows() refreshPairs() val pairs = DriverPairs.from(TurnipReleases.cached(activity)) diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/DriverPairs.kt b/app/src/main/java/com/droiddeck/launcher/gpu/DriverPairs.kt index 367a747b3c..ce7572bba4 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/DriverPairs.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/DriverPairs.kt @@ -17,6 +17,7 @@ object DriverPairs { const val NAD_RADV_XCLIPSE = "nad:radv-xclipse" /** RADV-Xclipse rebased on JimVulkan's upstream: a manual choice, never Auto. */ const val NAD_RADV_XCLIPSE_UPSTREAM = "nad:radv-xclipse-upstream" + private val XCLIPSE_MODEL = Regex("""(?i)xclipse\s*(\d{3})\b""") const val NAD_MALI_JM = "nad:panvk-mali-jm" const val NAD_MALI_G710 = "nad:panvk-mali-g710" const val NAD_MALI_G615 = "nad:panvk-mali-g615" @@ -111,13 +112,21 @@ object DriverPairs { } } + /** 950 and 960 panic on the older build; a name without a model number is treated the same way. */ + private fun xclipseNeedsUpstream(name: String): Boolean = + XCLIPSE_MODEL.find(name)?.groupValues?.get(1).let { it == null || it == "950" || it == "960" } + fun recommendedKey( gpu: GpuInfo, pairs: List<DriverPair>, rules: List<AutoPicks.Rule> = AutoPicks.BUILT_IN, bad: Set<String> = emptySet(), sdk: Int = android.os.Build.VERSION.SDK_INT, blob: Int? = null, ): String? { when (gpu.family) { - Family.POWERVR -> return NAD_RADV_XCLIPSE.takeIf { gpu.name.contains("Xclipse", ignoreCase = true) } + Family.POWERVR -> return when { + !gpu.name.contains("Xclipse", ignoreCase = true) -> null + xclipseNeedsUpstream(gpu.name) && pairs.any { it.key == NAD_RADV_XCLIPSE_UPSTREAM } -> NAD_RADV_XCLIPSE_UPSTREAM + else -> NAD_RADV_XCLIPSE + } Family.MALI_OTHER, Family.NOT_ADRENO -> return null Family.MALI_JM, Family.MALI_G610_G710, Family.MALI_G615, Family.MALI_G720, Family.MALI_LATEST -> return maliKey(gpu, pairs, sdk) 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 514afac36d..d1c048b61b 100644 --- a/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt @@ -217,7 +217,14 @@ class DriverPairsTest { assertFalse(upstream.suits(GpuInfo("PowerVR", 0, Family.POWERVR, "", false))) assertEquals("RADV upstream · Samsung Xclipse", upstream.name) assertEquals(DriverPairs.NAD_RADV_XCLIPSE, DriverPairs.recommendedKey(xclipse, pairs)) + for (name in listOf("Samsung Xclipse 530", "Samsung Xclipse 540", "Samsung Xclipse 920")) + assertEquals(DriverPairs.NAD_RADV_XCLIPSE, DriverPairs.recommendedKey(GpuInfo(name, 0, Family.POWERVR, "", false), pairs)) assertTrue(DriverPairs.isNonAdreno("RADV-Xclipse-upstream")) + for (name in listOf("Samsung Xclipse 950", "Samsung Xclipse 960", "Xclipse")) { + val newer = GpuInfo(name, 0, Family.POWERVR, "", false) + assertEquals(DriverPairs.NAD_RADV_XCLIPSE_UPSTREAM, DriverPairs.recommendedKey(newer, pairs)) + assertEquals(DriverPairs.NAD_RADV_XCLIPSE, DriverPairs.recommendedKey(newer, pairs.filter { it.key != DriverPairs.NAD_RADV_XCLIPSE_UPSTREAM })) + } } @Test