From b891019b87a8257e4de73839eb84d1c0ae8e89b4 Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Sun, 22 Nov 2026 14:16:34 -0500 Subject: [PATCH] fix(steam-x64): keep the session's GL thunk for the x86 web helper (#3027) * fix(steam-x64): keep the session's GL thunk for the x86 web helper FEX's global AppConfig for steamwebhelper turns the GL thunk off and is read after FEX_THUNKCONFIG, so the x86 helper used the rootfs's x86 Mesa. Steam's browser compositor creates its window through SDL3 and GLX in the helper's browser process, x86 Mesa faulted in driCreateNewScreen3 (SIGSEGV) about 11 s after each start, and the client restarted the helper every 12 s. For every global FEX AppConfig that turns off a thunk the session uses, the launcher writes a local AppConfig with the session's thunk set. It leaves local files with other content alone and removes its own files when the client runs in software. * fix(steam-x64): write FEX AppConfig overrides atomically * fix(steam-x64): stage AppConfig overrides in a unique temporary file * fix(steam-x64): publish AppConfig overrides without replacing a newer file --- docs/development/x86-64-steam-client.md | 12 +++ .../overlay/usr/local/bin/droiddeck-steam-x64 | 60 ++++++++++++- .../tests/test_steam_x64_thunk_appconfigs.py | 89 +++++++++++++++++++ 3 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 tools/tests/test_steam_x64_thunk_appconfigs.py diff --git a/docs/development/x86-64-steam-client.md b/docs/development/x86-64-steam-client.md index d8845742b..87b92e5ac 100644 --- a/docs/development/x86-64-steam-client.md +++ b/docs/development/x86-64-steam-client.md @@ -131,6 +131,18 @@ The client's web helper draws its whole UI. There are two: blank. `LinuxRuntime` binds an empty folder over `/sys/bus/pci/devices` on such devices; device: 0 GPU process exits, ANGLE on zink and Turnip. +FEX ships per-program AppConfigs, and `/usr/local/share/fex-emu/AppConfig/steamwebhelper.json` turns +the GL thunk off for every program named `steamwebhelper`. A program's AppConfig is read after +`FEX_THUNKCONFIG`, so the x86 helper got the rootfs's x86 Mesa while the client next to it had the +thunk. Steam's browser compositor creates its output window through SDL3 and GLX in the helper's +browser process, and x86 Mesa's `driCreateNewScreen3` (kisak libgallium 26.1.6) faulted there +(SIGSEGV, exit 139) about 11 s after every start; the client restarted it each time (device: 57 +restarts in 11 minutes). `x64_env` therefore writes, for every global AppConfig that turns off a +thunk the session uses, a local AppConfig (`$X64_HOME/.config/fex-emu/AppConfig/.json`, read +after the global one) with the session's thunk set. It never touches a local file with other content, +so a user's own AppConfig wins, and removes its own files when the client runs in software. Device: +helper up for over 10 minutes with no restart, ANGLE on zink and Turnip through the thunk. + The session shim (`preload/net.c`) turns `steamrt64/steamwebhelper.sh`'s exec of `./steamwebhelper` into `DD_X64_ARM_WEBHELPER`. Nothing in the client's folder is edited: the client checksums its files as it starts and reinstalled itself over an edited launcher (2-3 minutes) on every start. diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 index 2c77626a1..97185184c 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 @@ -713,14 +713,67 @@ x64_webhelper_gpu() { x64_gpu && [ "${DD_X64_CLIENT_SOFTWARE:-0}" != 1 ] && [ "${DD_X64_CEF_GPU:-1}" != 0 ] } +x64_thunk_appconfigs() { + python3 - "$1" "$2" "$3" "$4" <<'PY' || true +import json, os, sys, tempfile +src, dst, cfg, on = sys.argv[1:5] +want = json.loads(cfg) +try: + names = sorted(os.listdir(src)) +except OSError: + names = [] +for name in names: + if not name.endswith(".json"): + continue + try: + db = json.load(open(os.path.join(src, name), encoding="utf-8")).get("ThunksDB") or {} + if not any(k in want["ThunksDB"] and not v for k, v in db.items()): + continue + except (OSError, ValueError, AttributeError): + continue + path = os.path.join(dst, name) + try: + cur = json.load(open(path, encoding="utf-8")) + except FileNotFoundError: + cur = None + except (OSError, ValueError): + continue + if cur is not None and cur != want: + continue + if on == "1" and cur is None: + try: + os.makedirs(dst, exist_ok=True) + fd, tmp = tempfile.mkstemp(dir=dst, prefix=".fex", suffix=".tmp") + except OSError: + continue + try: + with os.fdopen(fd, "w", encoding="utf-8") as f: + f.write(cfg + "\n") + os.link(tmp, path) + except OSError: + pass + finally: + try: + os.remove(tmp) + except OSError: + pass + elif on != "1" and cur is not None: + try: + os.remove(path) + except OSError: + pass +PY +} + x64_env() { export -p | grep -v -E '^declare -x (PWD|OLDPWD|SHLVL|_)=' > "$X64_HOME/arm-session.env.new" || true mv -f "$X64_HOME/arm-session.env.new" "$X64_HOME/arm-session.env" unset LD_LIBRARY_PATH LD_PRELOAD STEAM_RUNTIME STEAM_RUNTIME_PREFER_HOST_LIBRARIES gpu_vars="GALLIUM_DRIVER MESA_LOADER_DRIVER_OVERRIDE VK_ICD_FILENAMES VK_DRIVER_FILES LIBGL_KOPPER_DRI2 ZINK_DEBUG ZINK_DESCRIPTORS TU_DEBUG MESA_NO_ERROR mesa_glthread" +thunk_cfg='{"ThunksDB": {"GL": 1, "Vulkan": 1}}' rm -f "$X64_HOME/game-gpu.env" if x64_gpu; then - printf '{"ThunksDB": {"GL": 1, "Vulkan": 1}}\n' > "$X64_HOME/thunks.json" + printf '%s\n' "$thunk_cfg" > "$X64_HOME/thunks.json" { echo "export FEX_THUNKCONFIG='$X64_HOME/thunks.json'" echo "unset LIBGL_ALWAYS_SOFTWARE LIBGL_DRI3_DISABLE GALLIUM_DRIVER" @@ -729,7 +782,10 @@ if x64_gpu; then done } > "$X64_HOME/game-gpu.env" fi -if x64_gpu && [ "${DD_X64_CLIENT_SOFTWARE:-0}" != 1 ]; then +client_thunks=0 +x64_gpu && [ "${DD_X64_CLIENT_SOFTWARE:-0}" != 1 ] && client_thunks=1 +x64_thunk_appconfigs /usr/local/share/fex-emu/AppConfig "$X64_HOME/.config/fex-emu/AppConfig" "$thunk_cfg" "$client_thunks" +if [ "$client_thunks" = 1 ]; then export FEX_THUNKCONFIG=$X64_HOME/thunks.json unset LIBGL_ALWAYS_SOFTWARE LIBGL_DRI3_DISABLE else diff --git a/tools/tests/test_steam_x64_thunk_appconfigs.py b/tools/tests/test_steam_x64_thunk_appconfigs.py new file mode 100644 index 000000000..a949a5d75 --- /dev/null +++ b/tools/tests/test_steam_x64_thunk_appconfigs.py @@ -0,0 +1,89 @@ +import json +import os +from pathlib import Path +import re +import subprocess +import tempfile +import unittest + + +SCRIPT = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steam-x64' +SOURCE = SCRIPT.read_text() +FUNCTION = re.search(r'^x64_thunk_appconfigs\(\) \{\n.*?^\}\n', SOURCE, re.M | re.S).group() +CFG = '{"ThunksDB": {"GL": 1, "Vulkan": 1}}' + + +class SteamX64ThunkAppConfigsTest(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + root = Path(self.temp.name) + self.src = root / 'global' + self.dst = root / 'local' + self.src.mkdir() + + def write_global(self, name, data): + (self.src / name).write_text(json.dumps(data)) + + def run_fn(self, on): + shell = FUNCTION + 'x64_thunk_appconfigs "$SRC" "$DST" "$CFG" "$ON"\n' + env = dict(os.environ, SRC=str(self.src), DST=str(self.dst), CFG=CFG, ON=on) + result = subprocess.run(['bash', '-eu', '-c', shell], env=env, capture_output=True, text=True, timeout=20) + self.assertEqual(0, result.returncode, result.stderr) + + def test_program_with_a_disabled_thunk_gets_the_session_thunks(self): + self.write_global('anyprogram.json', {'Comment': 'x', 'ThunksDB': {'GL': 0}}) + self.run_fn('1') + self.assertEqual(json.loads(CFG), json.loads((self.dst / 'anyprogram.json').read_text())) + + def test_disabled_vulkan_counts_too(self): + self.write_global('other.json', {'ThunksDB': {'Vulkan': 0}}) + self.run_fn('1') + self.assertTrue((self.dst / 'other.json').exists()) + + def test_programs_without_a_thunk_opt_out_are_untouched(self): + self.write_global('client.json', {'Config': {'HideHypervisorBit': '1'}}) + self.write_global('enabled.json', {'ThunksDB': {'GL': 1}}) + self.write_global('unrelated.json', {'ThunksDB': {'asound': 0}}) + self.run_fn('1') + self.assertFalse(self.dst.exists()) + + def test_user_override_is_kept(self): + self.write_global('anyprogram.json', {'ThunksDB': {'GL': 0}}) + self.dst.mkdir() + user = {'ThunksDB': {'GL': 0}, 'Config': {'Multiblock': '0'}} + (self.dst / 'anyprogram.json').write_text(json.dumps(user)) + self.run_fn('1') + self.assertEqual(user, json.loads((self.dst / 'anyprogram.json').read_text())) + self.run_fn('0') + self.assertEqual(user, json.loads((self.dst / 'anyprogram.json').read_text())) + + def test_software_mode_removes_only_the_written_file(self): + self.write_global('anyprogram.json', {'ThunksDB': {'GL': 0}}) + self.run_fn('1') + self.run_fn('0') + self.assertFalse((self.dst / 'anyprogram.json').exists()) + + def test_software_mode_writes_nothing(self): + self.write_global('anyprogram.json', {'ThunksDB': {'GL': 0}}) + self.run_fn('0') + self.assertFalse(self.dst.exists()) + + def test_broken_global_configs_do_not_fail(self): + (self.src / 'broken.json').write_text('{') + self.write_global('list.json', [1, 2]) + self.run_fn('1') + self.assertFalse(self.dst.exists()) + + def test_missing_global_dir_does_not_fail(self): + self.src = self.src / 'missing' + self.run_fn('1') + self.assertFalse(self.dst.exists()) + + def test_launcher_applies_it_to_the_fex_app_config_dirs(self): + self.assertIn('x64_thunk_appconfigs /usr/local/share/fex-emu/AppConfig "$X64_HOME/.config/fex-emu/AppConfig" "$thunk_cfg" "$client_thunks"', SOURCE) + self.assertIn('''printf '%s\\n' "$thunk_cfg" > "$X64_HOME/thunks.json"''', SOURCE) + + +if __name__ == '__main__': + unittest.main()