Compare commits

...
Author SHA1 Message Date
The412Banner 94a4e04e47 perf(vkbridge): default the acquire switch in the bridge server so game presets still win 2026-11-25 17:39:41 +00:00
The412Banner 610aa67f94 perf(session): signal bridge acquires and write its queue without a per-frame round trip 2026-11-25 17:30:23 +00:00
a8df9a7ae1 fix(game-env): non-Adreno graphics logs no longer turn on Wine debug tracing (#2730)
* fix(game-env): non-Adreno graphics logs no longer turn on Wine debug tracing

* test(game-env): graphics-log tests use the session's DD_ variable names

---------

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
Co-authored-by: maxjivi05 <maxjividen@gmail.com>
2026-11-25 11:26:24 -05:00
6 changed files with 157 additions and 2 deletions

No files matched your search

@@ -2,6 +2,7 @@ package com.droiddeck.launcher.gpu
import android.content.Context
import android.os.Process
import android.system.Os
import android.util.Log
import com.droiddeck.launcher.core.HostProcess
import com.droiddeck.launcher.core.SessionPart
@@ -21,6 +22,7 @@ class VkBridgeComponent(private val socket: File, private val logFile: File) : S
socket.parentFile?.mkdirs()
val cacheDir = cacheDir(app())
writeMode(cacheDir, com.droiddeck.launcher.session.SessionPrefs.vkBridgeMode(app()))
applyServerDefaults()
if (VkBridgeNative.start(app(), socket, logFile, cacheDir)) {
Log.i(TAG, "server ready in the app's process at $socket")
return
@@ -30,7 +32,7 @@ class VkBridgeComponent(private val socket: File, private val logFile: File) : S
val cmd = listOf(binary.absolutePath, "--socket", socket.absolutePath, "--log", logFile.absolutePath,
"--cache-dir", cacheDir.absolutePath)
.joinToString(" ") { it.replace("\\", "\\\\").replace(" ", "\\ ") }
val env = arrayOf("HOME=" + app().filesDir)
val env = serverEnv(app().filesDir.path, Os::getenv)
pid = HostProcess.start(cmd, env, app().filesDir, { status ->
exited = true
Log.w(TAG, "server exited with status $status")
@@ -61,6 +63,16 @@ class VkBridgeComponent(private val socket: File, private val logFile: File) : S
private const val TAG = "VkBridge"
private const val CACHE_DIR = "vkbridge-pipelines"
private const val MODE_FILE = "mode"
internal val SERVER_DEFAULTS = mapOf("VKBRIDGE_ASYNC_ACQUIRE" to "1")
internal fun serverEnv(home: String, getenv: (String) -> String?): Array<String> =
arrayOf("HOME=$home") + SERVER_DEFAULTS.map { (key, value) -> "$key=${getenv(key) ?: value}" }
private fun applyServerDefaults() {
for ((key, value) in SERVER_DEFAULTS) {
runCatching { Os.setenv(key, value, false) }.onFailure { Log.w(TAG, "setenv $key failed: $it") }
}
}
fun cacheDir(context: Context): File {
val dir = File(context.filesDir, CACHE_DIR)
@@ -0,0 +1,21 @@
package com.droiddeck.launcher.gpu
import org.junit.Assert.assertArrayEquals
import org.junit.Test
class VkBridgeComponentTest {
@Test fun theServerSignalsAcquiresWithoutARoundTripByDefault() {
assertArrayEquals(arrayOf("HOME=/data/files", "VKBRIDGE_ASYNC_ACQUIRE=1"),
VkBridgeComponent.serverEnv("/data/files") { null })
}
@Test fun aValueTheAppWasStartedWithIsKept() {
val env = mapOf("VKBRIDGE_ASYNC_ACQUIRE" to "0")
assertArrayEquals(arrayOf("HOME=/data/files", "VKBRIDGE_ASYNC_ACQUIRE=0"),
VkBridgeComponent.serverEnv("/data/files") { env[it] })
}
@Test fun theServerGetsNoOtherSwitch() {
assertArrayEquals(arrayOf("VKBRIDGE_ASYNC_ACQUIRE"), VkBridgeComponent.SERVER_DEFAULTS.keys.toTypedArray())
}
}
@@ -1530,9 +1530,13 @@ def game_logs(command, env, app_id, now=None):
except OSError as error:
print("droiddeck-game-env: no game log folder (%s)" % error, file=sys.stderr)
return env
proton_log = env.get("PROTON_LOG", "")
asked = proton_log not in ("", "0")
result = dict(env)
if not asked:
result.setdefault("WINEDEBUG", "-all,err+all")
result.update({
"PROTON_LOG": "1",
"PROTON_LOG": proton_log if asked else "1",
"PROTON_LOG_DIR": str(folder),
"DXVK_LOG_PATH": str(folder),
"DXVK_LOG_LEVEL": env.get("DXVK_LOG_LEVEL", "info"),
@@ -278,6 +278,7 @@ if [ "${DD_VKBRIDGE:-0}" = 1 ]; then
if [ -z "$dd_vkb_missing" ]; then
export VK_DRIVER_FILES=$dd_vkb_icd VK_ICD_FILENAMES=$dd_vkb_icd
export VKBRIDGE_SOCKET VKBRIDGE_CLIENT_LOG
export VKBRIDGE_AQ_LOCKED_WRITES=${VKBRIDGE_AQ_LOCKED_WRITES:-0}
if [ -r /root/.vkbridge-env ]; then
while IFS='=' read -r _k _v; do
case "$_k" in VKBRIDGE_*|DD_VKBRIDGE_*) export "$_k=$_v" ;; esac
+47
View File
@@ -2199,6 +2199,53 @@ class GameEnvironmentTest(unittest.TestCase):
named = game_logs(command, on, None, now=0)
self.assertTrue(Path(named["PROTON_LOG_DIR"]).name.endswith("-Hades"))
def test_graphics_logs_trace_wine_only_when_asked(self):
game_logs = MODULE["game_logs"]
command = ["/proton", "waitforexitandrun", "/games/Hades/Hades.exe"]
with tempfile.TemporaryDirectory() as tmp, mock.patch("subprocess.Popen"):
on = {"DD_GAME_LOGS": "1", "DD_DEBUG_DIR": tmp}
for given in ({}, {"PROTON_LOG": "0"}, {"PROTON_LOG": ""}):
with self.subTest(given=given):
result = game_logs(command, {**on, **given}, "42", now=0)
self.assertEqual(result["PROTON_LOG"], "1")
self.assertEqual(result["WINEDEBUG"], "-all,err+all")
own = game_logs(command, {**on, "WINEDEBUG": "+relay"}, "42", now=0)
self.assertEqual(own["WINEDEBUG"], "+relay")
for value in ("1", "+relay"):
with self.subTest(proton_log=value):
user = game_logs(command, {**on, "PROTON_LOG": value}, "42", now=0)
self.assertEqual(user["PROTON_LOG"], value)
self.assertNotIn("WINEDEBUG", user)
config = {"version": 1, "gameDebugLogs": True}
debug = game_logs(command, MODULE["apply_game_debug_logs"](on, config, tmp), "42", now=0)
self.assertEqual(debug["PROTON_LOG"], "1")
self.assertEqual(debug["WINEDEBUG"], MODULE["game_debug_channels"]())
def test_game_debug_switch_controls_wine_traces_with_graphics_logs_on(self):
with tempfile.TemporaryDirectory() as tmp:
home = Path(tmp)
config_path = home / ".config/droiddeck/game-environment.json"
config_path.parent.mkdir(parents=True)
probe = home / "proton"
probe.write_text("#!" + sys.executable + "\nimport json, os\n"
"print(json.dumps({k: os.environ.get(k) for k in ('PROTON_LOG', 'WINEDEBUG')}))\n")
probe.chmod(0o755)
env = {**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/599140"),
"DD_DEBUG_DIR": tmp, "DD_GAME_LOGS": "1"}
for name in ("PROTON_LOG", "WINEDEBUG"):
env.pop(name, None)
for enabled in (True, False, True):
with self.subTest(enabled=enabled):
config_path.write_text(json.dumps({"version": 1, "gameDebugLogs": enabled}))
result = json.loads(subprocess.run(
[sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun", "game.exe"],
env=env, text=True, capture_output=True, check=True).stdout)
self.assertEqual(result["PROTON_LOG"], "1")
if enabled:
self.assertIn("+seh", result["WINEDEBUG"].split(","))
else:
self.assertEqual(result["WINEDEBUG"], "-all,err+all")
def test_rapid_game_launches_keep_separate_diagnostics(self):
with tempfile.TemporaryDirectory() as tmp, mock.patch("subprocess.Popen"):
env = {"DD_GAME_LOGS": "1", "DD_DEBUG_DIR": tmp}
@@ -0,0 +1,70 @@
import re
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session"
SWITCHES = ("VKBRIDGE_ASYNC_ACQUIRE", "VKBRIDGE_AQ_LOCKED_WRITES")
GUEST_DEFAULTS = {"VKBRIDGE_ASYNC_ACQUIRE": "unset", "VKBRIDGE_AQ_LOCKED_WRITES": "0"}
def bridge_block():
match = re.search(r'^if \[ "\$\{DD_VKBRIDGE:-0\}" = 1 \]; then\n.*?^fi\n', SESSION.read_text(), re.M | re.S)
return match.group(0) if match else None
def defaults_and_overrides(block):
start = block.index(" export VKBRIDGE_AQ_LOCKED_WRITES=")
match = re.compile(r"^ if \[ -r /root/\.vkbridge-env \]; then\n.*?^ fi\n", re.M | re.S).search(block, start)
return block[start:match.end()] if match else None
class VkBridgeSwitchesTest(unittest.TestCase):
def setUp(self):
self.block = bridge_block()
self.assertIsNotNone(self.block)
self.snippet = defaults_and_overrides(self.block)
self.assertIsNotNone(self.snippet, "the bridge block lacks its switch defaults or the .vkbridge-env loop")
self.root = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, self.root, True)
self.env_file = self.root / "vkbridge-env"
def run_snippet(self, env=None, env_file=None):
if env_file is not None:
self.env_file.write_text(env_file)
script = "set -u\nDD_INSIDE=1\n" + self.snippet.replace("/root/.vkbridge-env", str(self.env_file))
script += "".join('printf "%s=%%s\\n" "${%s-unset}"\n' % (k, k) for k in SWITCHES)
out = subprocess.run(["env", "-i", "PATH=/usr/bin:/bin"] + ["%s=%s" % kv for kv in (env or {}).items()]
+ ["bash", "-c", script], capture_output=True, text=True, timeout=10, check=True).stdout
return dict(line.split("=", 1) for line in out.splitlines() if line.split("=", 1)[0] in SWITCHES)
def test_a_bridge_session_writes_outside_the_lock_and_leaves_the_acquire_to_the_server(self):
self.assertEqual(GUEST_DEFAULTS, self.run_snippet())
def test_a_value_the_session_was_started_with_is_kept(self):
got = self.run_snippet(env={"VKBRIDGE_ASYNC_ACQUIRE": "0", "VKBRIDGE_AQ_LOCKED_WRITES": "1"})
self.assertEqual({"VKBRIDGE_ASYNC_ACQUIRE": "0", "VKBRIDGE_AQ_LOCKED_WRITES": "1"}, got)
def test_the_development_settings_file_still_wins(self):
got = self.run_snippet(env_file="VKBRIDGE_ASYNC_ACQUIRE=0\nVKBRIDGE_AQ_LOCKED_WRITES=1\n")
self.assertEqual({"VKBRIDGE_ASYNC_ACQUIRE": "0", "VKBRIDGE_AQ_LOCKED_WRITES": "1"}, got)
def test_a_development_file_without_them_keeps_the_defaults(self):
self.assertEqual(GUEST_DEFAULTS, self.run_snippet(env_file="VKBRIDGE_HITCH_MS=50\n"))
def test_only_a_usable_bridge_gets_them(self):
usable = self.block.index('if [ -z "$dd_vkb_missing" ]; then')
self.assertLess(usable, self.block.index("export VKBRIDGE_AQ_LOCKED_WRITES="))
text = SESSION.read_text()
self.assertEqual(1, text.count("VKBRIDGE_AQ_LOCKED_WRITES=${VKBRIDGE_AQ_LOCKED_WRITES:-"))
self.assertIn("VKBRIDGE_AQ_LOCKED_WRITES=${VKBRIDGE_AQ_LOCKED_WRITES:-", self.block)
def test_the_guest_never_sets_the_acquire_switch_ahead_of_the_bridge_presets(self):
self.assertNotIn("VKBRIDGE_ASYNC_ACQUIRE", SESSION.read_text())
if __name__ == "__main__":
unittest.main()