mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +00:00
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
This commit is contained in:
1 parent
1a29c65d4f
commit
b891019b87
3 files changed
+159
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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()
|
||||
Reference in new issue
Block a user