Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/linux_proton.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ What it does:
- **Limits:** a hard time limit (`--seconds`, then SIGTERM and SIGKILL 10 s later), a lock so one run happens at a
time (`--lock`, by default in `XDG_RUNTIME_DIR`), and teardown of Wine and the whole session on exit, time-out or
signal.
- **Shader cache:** the session's `XDG_CACHE_HOME`, where NVIDIA's `GLCache` and Mesa's shader cache go, is the
caller's when it is set, or the folder `--cache DIR` names; both are kept from run to run, so a later launch does
not compile every pipeline in the driver again. Without either, or with `--cache fresh`, it is a new folder in the
run folder, for a cold-cache run. The summary's first line says which (`shader cache: kept in DIR` or `fresh`).
- **Traces:** `gta6rt --run` with `--trace` and `--trace-d3d12`, a fresh `--overlay` and save folder in the run
folder. Every other `LEONIDA_*` variable reaches the runtime unchanged, so `LEONIDA_INPUT_SCRIPT=a@210,a@240`
presses A as above. Arguments after `--` go to `gta6rt`.
Expand Down
15 changes: 13 additions & 2 deletions scripts/run_game_wine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Options:
--device VID:DID the Vulkan device, as MESA_VK_DEVICE_SELECT=VID:DID! (e.g. 1002:744c); without it Mesa picks
--screenshot-every S capture the game window into <out>/shots every S seconds (needs ImageMagick's import and
xprop); the shots are game content and stay local
--cache DIR|fresh XDG_CACHE_HOME of the run, where the drivers keep their shader caches (NVIDIA's GLCache,
Mesa's shader cache): DIR is kept from run to run, fresh is a new one in the run folder
(default: the caller's XDG_CACHE_HOME when it is set, otherwise fresh)
--lock FILE the lock that allows one run at a time (default $XDG_RUNTIME_DIR/leonida-run-game-wine.lock,
or <out>/run.lock without XDG_RUNTIME_DIR)
-h, --help this text
Expand Down Expand Up @@ -103,7 +106,7 @@ if [ "${1:-}" = --inner ]; then
fi

# ---- arguments ----
SRC= BUILD_DIR= OUT= PREFIX=${WINEPREFIX:-} LIMIT=600 VISIBLE=0 DEVICE= SHOT_EVERY=0 LOCK=
SRC= BUILD_DIR= OUT= PREFIX=${WINEPREFIX:-} LIMIT=600 VISIBLE=0 DEVICE= SHOT_EVERY=0 LOCK= CACHE=${XDG_CACHE_HOME:-fresh}
EXE=${LEONIDA_GAME_EXE:-} GAME=${LEONIDA_GAME_DIR:-} SHADERS=${LEONIDA_SHADERS:-}
need() { [ $# -ge 2 ] && [ -n "$2" ] || die "$1 needs a value (see --help)"; }
while [ $# -gt 0 ]; do
Expand All @@ -121,6 +124,7 @@ while [ $# -gt 0 ]; do
--device) need "$@"; DEVICE=$2; shift 2 ;;
--screenshot-every) need "$@"; SHOT_EVERY=$2; shift 2 ;;
--lock) need "$@"; LOCK=$2; shift 2 ;;
--cache) need "$@"; CACHE=$2; shift 2 ;;
--) shift; break ;;
*) die "unknown argument: $1 (see --help)" ;;
esac
Expand All @@ -138,6 +142,10 @@ if [ -n "$DEVICE" ] && ! [[ $DEVICE =~ ^[0-9a-fA-F]{4}:[0-9a-fA-F]{4}$ ]]; then
fi
[ -f "$EXE" ] || die "no game executable at $EXE"
[ -d "$GAME" ] || die "no package folder at $GAME"
if [ "$CACHE" != fresh ]; then
mkdir -p "$CACHE" || die "cannot create the cache folder $CACHE"
CACHE=$(readlink -f "$CACHE")
fi
if [ "$SHADERS" != none ]; then
SHADERS=${SHADERS#Z:}
[ -d "$SHADERS" ] || die "no shader library at $SHADERS"
Expand Down Expand Up @@ -205,9 +213,12 @@ unset LEONIDA_GAME_EXE LEONIDA_GAME_DIR # launcher inputs; LEONIDA_GAME_DIR als
export WINE
export XDG_RUNTIME_DIR=$RUN/xdg
rm -rf "$XDG_RUNTIME_DIR"; mkdir -p -m 700 "$XDG_RUNTIME_DIR"
export XDG_CONFIG_HOME=$RUN/session/config XDG_DATA_HOME=$RUN/session/data XDG_CACHE_HOME=$RUN/session/cache \
# The cache folder alone may outlive the run: a fresh one makes every launch compile its pipelines again in the driver.
if [ "$CACHE" = fresh ]; then XDG_CACHE_HOME=$RUN/session/cache; else XDG_CACHE_HOME=$CACHE; fi
export XDG_CONFIG_HOME=$RUN/session/config XDG_DATA_HOME=$RUN/session/data XDG_CACHE_HOME \
XDG_STATE_HOME=$RUN/session/state
mkdir -p "$XDG_CONFIG_HOME" "$XDG_DATA_HOME" "$XDG_CACHE_HOME" "$XDG_STATE_HOME"
if [ "$CACHE" = fresh ]; then echo "shader cache: fresh"; else echo "shader cache: kept in $CACHE"; fi >> "$RUN/session.txt"
unset WAYLAND_DISPLAY WAYLAND_SOCKET DBUS_SESSION_BUS_ADDRESS
if [ "$VISIBLE" = 1 ]; then
if command -v xdpyinfo >/dev/null 2>&1 && ! xdpyinfo >/dev/null 2>&1; then
Expand Down
40 changes: 37 additions & 3 deletions tests/test_run_game_wine.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
WINE_STUB = """#!/bin/sh
if [ "$1" = wineboot ]; then exit 0; fi
for a in "$@"; do printf '%s\\n' "$a"; done > "$STUB_LOG/wine.args"
env | grep -E '^(LEONIDA_|MESA_VK|WINEDLL|WINEPREFIX|PULSE_SERVER|PIPEWIRE_REMOTE|DISPLAY)' | sort > "$STUB_LOG/wine.env"
env | grep -E '^(LEONIDA_|MESA_VK|WINEDLL|WINEPREFIX|PULSE_SERVER|PIPEWIRE_REMOTE|DISPLAY|XDG_CACHE_HOME)' | sort > "$STUB_LOG/wine.env"
pwd > "$STUB_LOG/wine.cwd"
if [ -n "${XDG_CACHE_HOME:-}" ]; then mkdir -p "$XDG_CACHE_HOME/nvidia" && echo x >> "$XDG_CACHE_HOME/nvidia/GLCache"; fi
echo "[rt] audio: serving the silent output endpoint (LEONIDA_AUDIO=silent): 48 kHz float 7.1" >&2
echo "[d3d12-trace] #1 XboxID3D12CommandQueue::PresentX ok" >&2
exit 0
Expand Down Expand Up @@ -85,8 +86,8 @@ def inputs(self, **drop):
flat += [flag, str(value)]
return flat

def run_script(self, *args, display=":99"):
env = {"PATH": str(self.bin), "HOME": str(self.tmp), "STUB_LOG": str(self.log)}
def run_script(self, *args, display=":99", **extra):
env = {"PATH": str(self.bin), "HOME": str(self.tmp), "STUB_LOG": str(self.log), **extra}
if display:
env["DISPLAY"] = display
return subprocess.run([str(self.bin / "bash"), str(SCRIPT), *args], cwd=self.tmp, env=env, capture_output=True, text=True,
Expand Down Expand Up @@ -200,6 +201,39 @@ def test_without_a_device_it_warns(self):
env = (self.log / "wine.env").read_text(encoding="utf-8")
self.assertNotIn("MESA_VK_DEVICE_SELECT", env)

def wine_env(self):
return dict(line.split("=", 1) for line in (self.log / "wine.env").read_text(encoding="utf-8").splitlines())

def run_with_cache(self, out, *args, **extra):
self.out = self.tmp / out
p = self.run_script(*self.inputs(), "--visible", "--device", "1002:744C", "--seconds", "30", *args, **extra)
self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
return p, self.wine_env()["XDG_CACHE_HOME"]

def test_without_a_cache_each_run_gets_a_fresh_one(self):
p, cache = self.run_with_cache("run1")
self.assertEqual(cache, str(self.tmp / "run1" / "session" / "cache"))
self.assertIn("shader cache: fresh", p.stdout)

def test_the_callers_cache_is_kept_from_run_to_run(self):
# The drivers' shader caches (NVIDIA's GLCache here) live under XDG_CACHE_HOME: a caller's one is used, so
# the second launch finds what the first compiled.
kept = self.tmp / "cache"
for n in (1, 2):
p, cache = self.run_with_cache(f"run{n}", XDG_CACHE_HOME=str(kept))
self.assertEqual(cache, str(kept))
self.assertIn(f"shader cache: kept in {kept}", p.stdout)
self.assertEqual((kept / "nvidia" / "GLCache").read_text(encoding="utf-8"), "x\nx\n")

def test_cache_option_names_the_folder_or_fresh(self):
named = self.tmp / "named-cache"
_, cache = self.run_with_cache("run1", "--cache", str(named), XDG_CACHE_HOME=str(self.tmp / "other"))
self.assertEqual(cache, str(named))
self.assertTrue((named / "nvidia" / "GLCache").is_file())
_, cache = self.run_with_cache("run2", "--cache", "fresh", XDG_CACHE_HOME=str(self.tmp / "other"))
self.assertEqual(cache, str(self.tmp / "run2" / "session" / "cache"))
self.assertFalse((self.tmp / "other").exists())


if __name__ == "__main__":
unittest.main()
Loading