Skip to content
Closed
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
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ method, scope and caveats. No game data is included.
| [boot_leads.md](boot_leads.md) | Open leads that may move the retail boot further (TLS at module index 0, feature level at device creation, command-list replay, descriptor words, shader corpus count, frame pacing), each with where it lands, how to implement it and how to test it. Hypotheses, not measurements. |
| [rpf.md](rpf.md) | RPF9 archive layout, the carve tools and the unreadable encrypted TOC. |
| [linux.md](linux.md) | Linux in one page: what runs natively and what runs under Wine or Proton, the Ubuntu packages, `Build.sh`, the runtime cross-build, and why there is no native Linux `gta6rt`. |
| [linux_proton.md](linux_proton.md) | The boot scripts in `scripts/linux-boot`: the cross-build configure, booting the loader under Wine or Proton with the network off, and a `systemd --user` unit that samples memory and writes a digest of how the boot ended. |
| [testing.md](testing.md) | Running the GPU tests on your own GPU: setup per OS, wave64 emulation, running without a GPU on Mesa llvmpipe, and known problems. |
| [gpu_test_results.md](gpu_test_results.md) | Published GPU test results by hardware, driver and commit, with pass, skip and failure counts. |
| [modding.md](modding.md) | The mod format: `mods/<folder>/mod.json`, checked and loaded in name order by `gta6rt`; a swap takes effect once the game's archetype lookup is hooked (needs the executable, RT-5). A mod names game models and holds no game data. |
Expand Down
98 changes: 70 additions & 28 deletions docs/linux_proton.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,82 @@ Windows A reaches every stage three to five times faster than the Linux machine
~180 s, story load from ~110 s against ~240-300 s), so it is the better machine for iterating on the world phase;
the Linux machine is the one that shows what 16 GB of RAM allows.

## Building on Linux
## Building from a checkout

The runtime is a Windows executable. On Linux it is cross-built with clang-cl against an [xwin](https://github.com/Jake-Shadle/xwin)
copy of the Windows SDK:
The runtime is a Windows program. On Linux it is cross-built with clang-cl against an
[xwin](https://github.com/Jake-Shadle/xwin) copy of the Windows SDK ([linux.md](linux.md) has the packages and the
one-time `xwin` command):

```sh
scripts/linux-boot/configure-worktree.sh <checkout> # XWIN_DIR=<sdk>, SDL3_SRC=<SDL3 tree> for an offline configure
scripts/linux-boot/configure-worktree.sh <checkout> # XWIN_DIR=<sdk>; SDL3_SRC=<an SDL3 source tree> configures offline
cmake --build <checkout>/runtime/build/boot --target gta6rt -j6
```

`gta6rt_tls_host.dll` is built with the `gta6rt` target and must stay next to the executable. Unit tests are Windows
executables too and run under Wine (`scripts/run_wine_tests.py`, or directly with the same `wine` binary and a
prefix of their own: sharing the game's prefix with tests breaks its window).

## Booting on Linux

`scripts/linux-boot/boot.sh` is the plain launcher and `run-boot.sh` wraps it as a `systemd --user` unit with a
memory sampler, a GPU lock, a build lock (no compile while the game runs) and a digest after the boot. They assume
the layout the comments at their top describe (`/opt/leonida` for traces, overlay and caches; the package under
`/opt/gta6`); adjust the paths at the top to yours. What matters:

- **Wine:** Proton Experimental's `files/bin/wine` with its own prefix (`WINEPREFIX`), `WINEDLLOVERRIDES="mscoree,mshtml="`.
- **No network:** the title runs inside `unshare -rn` (new user and network namespace). Nothing is online.
- **Backend:** `LEONIDA_D3D12=vulkan`, `LEONIDA_SHADERS=<translated library>`.
- **NVIDIA shader cache:** `__GL_SHADER_DISK_CACHE_SIZE` raised (the library is ~19 GB of SPIR-V) and
`__GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1`.
- **Input:** a pad through GameInput/SDL3, or the keyboard pad (`LEONIDA_KEYBOARD_PAD=always`), or a script:
`LEONIDA_INPUT_SCRIPT=a@210,a@240` presses A at those seconds (any length since this branch; it was cut at 63
characters before).
- **Window:** frames are presented in the title's own window; `LEONIDA_PRESENT_WINDOW=own|hidden` chooses otherwise.

Three setup mistakes each give a blank or empty picture without an error: the executable's embedded shaders missing
from the library (`exe/index.json`), a build without SDL3 (no pad), and a BCPack predictor file that was never
generated (`tools/build_dstorage_history.py`; without it the loading art and most BC7 textures stay empty).
`configure-worktree.sh` configures a Ninja Release build in `<checkout>/runtime/build/boot` with
`runtime/cmake/clang-cl-xwin.cmake`. `gta6rt_tls_host.dll` is built with the `gta6rt` target and must stay next to the
executable: without it the title gets no module TLS index and exits at once, so `run-boot.sh` refuses to start.

## Booting

`boot.sh` is the plain launcher. `run-boot.sh` wraps it as a `systemd --user` unit.

```sh
export LEONIDA_GAME_DIR=<your copy of the package> # the folder with game_scarlett_master.exe
export LEONIDA_SHADERS=<work>/shaders/spirv # the translated library make_game.py built
scripts/linux-boot/boot.sh dry-run # imports only
scripts/linux-boot/boot.sh init # TLS callbacks and DLL initialization
scripts/linux-boot/boot.sh run 150 # start the title, stop it after 150 s
scripts/linux-boot/run-boot.sh first runtime/build/boot/gta6rt.exe 150 LEONIDA_ARENA_MB=2048
```

| Variable | Default | Meaning |
|---|---|---|
| `LEONIDA_GAME_DIR` | none, required | The folder of your copy of the package. It is read in place. |
| `LEONIDA_SHADERS` | none, required for `run` | The translated shader library. |
| `LEONIDA_BOOT_DIR` | `~/.local/share/leonida-boot` | Where traces, the overlay (the title's writes), the driver's shader cache, the locks and the runs go. |
| `GTA6RT` | `runtime/build/boot/gta6rt.exe` of the checkout | The loader `boot.sh` starts. `run-boot.sh` takes it as its second argument. |
| `WINE` | Proton Experimental's `files/bin/wine` when Steam has it, else `wine` | The Wine to use. **One Wine per prefix, always.** A Proton prefix links to files inside the Proton installation, and another Wine version that starts in it updates the prefix by writing through those links. On the machine below that overwrote about 1,200 of Proton's own files, and every Proton start failed afterwards; the tool's files then have to be verified or reinstalled through Steam. |
| `WINEPREFIX` | `~/.local/share/leonida-boot-prefix` | A prefix for boots alone. |
| `LEONIDA_BOOT_MIN_FREE_MB` | `6500` | `run-boot.sh` waits up to ten minutes for this much memory before it boots. |

What the scripts set, and why:

- **No network.** The loader runs inside `unshare -rn`, a new user and network namespace that needs no root. The
title has no network at all, which is the project's rule (nothing online) enforced by the kernel.
- **Wine.** `WINEDLLOVERRIDES="mscoree,mshtml=;winedbg.exe=d"`: a new prefix does not ask to install Mono and Gecko,
and a process that crashes ends instead of starting `winedbg`. With the Wine installation broken as the table
above describes, `winedbg` started for a crashing Wine service crashed as well and was started again for itself,
about ten thousand times, until memory ran out; the loader's own trace already records the title's exceptions.
Keep the
boot prefix apart from the one unit tests use. On the machine below, a test's `wineserver` that was still alive
(started without a display) was joined by the next boot, which then had no window.
- **Backend.** `LEONIDA_D3D12=vulkan` and `LEONIDA_SHADERS` for `run`.
- **NVIDIA's shader disk cache** is moved under `LEONIDA_BOOT_DIR` and its size limit raised
(`__GL_SHADER_DISK_CACHE_SIZE`, 20 GiB unless you set it), with `__GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1`, so that
the pipelines one boot compiled are still there for the next.
- **Traces.** `--trace` always and `--trace-d3d12` for `run`; `tools/boot_trace.py` summarises them next to the logs.

Other switches pass through: any `KEY=VALUE` after the seconds of `run-boot.sh` is set in the unit, for example
`LEONIDA_KEYBOARD_PAD=always` ([gameinput.md](gameinput.md)) or `LEONIDA_SKIP_INT3=1` ([boot.md](boot.md)).

## What `run-boot.sh` adds

- The boot runs outside your shell's process tree, with `OOMScoreAdjust=900`: when memory runs out the kernel takes
the game, not the session that started it.
- It waits for memory headroom and for swap below 70 %, then holds a GPU lock (one boot at a time) and a build lock
for the whole boot. A build that takes the same lock never competes with the game for memory:
`flock "$LEONIDA_BOOT_DIR/.build.lock" cmake --build ...`.
- RAM, swap, the unit's own memory and VRAM (`nvidia-smi`, when present) are sampled every 2 s into `resources.tsv`.
- A frame capture is on (`LEONIDA_CAPTURE`, every 4800th presented frame) and so is Wine's error channel.
- A second small unit waits for the boot to end, also when `systemd-oomd` or the kernel killed it, and writes
`digest.txt`: the verdict (`OK`, `EXITED WITH ERROR`, `KILLED BY OOM`, `KILLED BY SIGNAL`), how long it queued and
ran, counts from the D3D12 trace, captured frames and how many are not black, memory peaks, kernel events (OOM,
NVIDIA Xid, segfaults), every distinct error line with its count, and the last lines of the trace. One line per
boot is appended to `boots.tsv`.

Everything is in `$LEONIDA_BOOT_DIR/runs/<name>/` and `$LEONIDA_BOOT_DIR/traces/`. `run-boot.sh` prints the digest
and exits 0 only for `OK`. **Traces, logs and digests can quote the title's own text. Keep them on the machine that
produced them**: no trace, log or capture goes into a commit, an issue or a pull request.

## What a healthy boot looks like (Linux machine)

Expand Down
66 changes: 33 additions & 33 deletions scripts/linux-boot/boot-digest.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
#!/bin/bash
# ExecStopPost of a leonida-boot-* unit: runs after the boot ends however it ended (exit, crash, oomd kill, timeout).
# Writes /opt/leonida/work/<agent>/boot-<n>.digest.txt and appends a line to /opt/leonida/work/boots.tsv.
# Local only: digests quote trace lines, so they never go into commits or PRs.
# usage: boot-digest.sh <name> (run-boot.sh starts it when the leonida-boot-<name> unit has ended)
# Runs after the boot however it ended (exit, crash, oomd kill, time limit). Writes
# $LEONIDA_BOOT_DIR/runs/<name>/digest.txt and appends one line to $LEONIDA_BOOT_DIR/boots.tsv.
# Local only: a digest quotes trace lines, so it never goes into a commit, an issue or a pull request.
set -u
AGENT=$1; N=$2; WORK=/opt/leonida/work/$AGENT; LOG=$WORK/boot-$N.log; RES=$WORK/boot-$N.resources.tsv
META=$WORK/boot-$N.meta; OUT=$WORK/boot-$N.digest.txt; LEDGER=/opt/leonida/work/boots.tsv
NAME=${1:?name}; BASE=${LEONIDA_BOOT_DIR:-$HOME/.local/share/leonida-boot}; RUN=$BASE/runs/$NAME
LOG=$RUN/boot.log; RES=$RUN/resources.tsv; META=$RUN/meta; OUT=$RUN/digest.txt; LEDGER=$BASE/boots.tsv
START=$(sed -n 's/^start_epoch=//p' "$META" 2>/dev/null); BOOT=$(sed -n 's/^boot_epoch=//p' "$META" 2>/dev/null)
START=${START:-$(date +%s)}; BOOT=${BOOT:-$START}; END=$(date +%s)
RESULT=${SERVICE_RESULT:-?}; ECODE=${EXIT_CODE:-?}; ESTAT=${EXIT_STATUS:-?}
RESULT=${SERVICE_RESULT:-?}
D3D=$(grep -o 'd3d12=[^ ]*' "$LOG" 2>/dev/null | tail -1 | cut -d= -f2)
STDOUT=${D3D/d3d12-run-/stdout-run-}
CAP=/opt/leonida/capture/$AGENT-$N
CAP=$RUN/capture

verdict=OK
# systemd-oomd can kill the unit's processes without the unit ending in "oom-kill" (boot.sh then exits on its own).
if journalctl --user -u "leonida-boot-$AGENT-$N" --since "@$START" -q --no-pager 2>/dev/null | grep -q 'systemd-oomd killed'; then RESULT=oom-kill; fi
if journalctl --user -u "leonida-boot-$NAME" --since "@$START" -q --no-pager 2>/dev/null | grep -q 'systemd-oomd killed'; then RESULT=oom-kill; fi
# The loader's own exit code, as boot-inner.sh logged it (124 is the time limit and was turned into 0 there).
RC=$(sed -n 's/^\[run-boot\] .* boot\.sh exit \([0-9]*\)$/\1/p' "$LOG" 2>/dev/null | tail -1)
[ "$RESULT" = success ] && [ -n "$RC" ] && [ "$RC" != 0 ] && [ "$RC" != 124 ] && RESULT=exit-code
case "$RESULT" in
oom-kill) verdict="KILLED BY OOM (systemd-oomd or kernel): memory, not a crash" ;;
timeout) verdict="TIMEOUT" ;;
exit-code) verdict="EXITED WITH ERROR (code $ECODE status $ESTAT)" ;;
signal|core-dump) verdict="KILLED BY SIGNAL ($ESTAT)" ;;
exit-code) verdict="EXITED WITH ERROR (boot.sh exit ${RC:-?})" ;;
signal|core-dump) verdict="KILLED BY SIGNAL" ;;
success) verdict="OK (ran to its time limit or exited cleanly)" ;;
esac
grep -q 'time limit reached' "$LOG" 2>/dev/null && [ "$RESULT" = success ] && verdict="OK (ran its full time limit)"

cnt() { local c=0; [ -f "$D3D" ] && c=$(grep -a -c -E "$@" "$D3D"); echo "${c:-0}"; }
{
echo "== leonida boot $AGENT-$N: $verdict"
echo "unit result=$RESULT exit_code=$ECODE exit_status=$ESTAT"
echo "== leonida boot $NAME: $verdict"
echo "unit result=$RESULT"
echo "queued $((BOOT-START)) s, ran $((END-BOOT)) s; trace $D3D"
sed -n '/^LEONIDA_\|^WINEDEBUG\|^unit=/p' "$META" 2>/dev/null | tr '\n' ' '; echo
echo
echo "-- counts"
echo "PresentX ok $(cnt 'XboxPresentation::PresentX ok') refused $(cnt 'XboxPresentation::PresentX failed')"
echo "CreatePipelineState failed $(cnt 'CreatePipelineState failed') FSPX compute misses $(cnt 'no translated compute shader for FSPX') slot-67 failed $(cnt 'slot 67 call .* failed')"
echo "E_NOTIMPL $(cnt 'E_NOTIMPL') wine err: lines $(cnt '^[0-9a-f]{4}:err:|:err:') exceptions $(cnt -i 'exception|unhandled|page fault|access violation')"
grep -a -m1 -E 'translated shaders \(' "$D3D" 2>/dev/null
grep -a 'present-probe: source frame .* via' "$D3D" 2>/dev/null | tail -1 | sed 's/.*via/source via/' | cut -c1-120
echo "-- counts in the D3D12 trace"
echo "no translated shader $(cnt 'no translated ') E_NOTIMPL $(cnt 'E_NOTIMPL') failed with an HRESULT $(cnt 'failed with 0x8')"
echo "Wine err: lines $(cnt ':err:') exceptions $(cnt -i 'exception|unhandled|page fault|access violation')"
echo
echo "-- frames (swapchain; then the title's own backbuffer when LEONIDA_CAPTURE_SOURCE=1)"
[ -f "$CAP/index.txt" ] && { echo "$(wc -l < "$CAP/index.txt") captured; last: $(tail -1 "$CAP/index.txt" | cut -c1-110)"; awk '{m=$(NF-2)+$(NF-1)+$NF; if (m>0) n++} END{print n+0 " of " NR " frames non-black"}' "$CAP/index.txt"; } || echo "no capture index"
grep -a 'present-probe: source frame .* mean' "$D3D" 2>/dev/null | tail -2 | sed 's/.*source frame/source frame/' | cut -c1-140
echo "-- frames (every LEONIDA_CAPTURE_EVERY-th presented frame of the swapchain)"
if [ -f "$CAP/index.txt" ]; then
echo "$(wc -l < "$CAP/index.txt") captured; last: $(tail -1 "$CAP/index.txt" | cut -c1-110)"
awk '{m=$(NF-2)+$(NF-1)+$NF; if (m>0) n++} END{print n+0 " of " NR " frames non-black"}' "$CAP/index.txt"
else
echo "none captured"
fi
echo
echo "-- resources (2 s samples)"
[ -s "$RES" ] && awk -F'\t' 'NR>1{ if(min==""||$2<min)min=$2; if($3>sw)sw=$3; if($4>um)um=$4; if($5>us)us=$5; if($6+0>gm)gm=$6 } END{printf "min RAM available %s MB, max swap used %s MB, game peak %s MB RAM + %s MB swap, VRAM peak %s MB\n",min,sw,um,us,gm}' "$RES" || echo "no samples"
journalctl --user -u "leonida-boot-$AGENT-$N" --since "@$START" -q --no-pager 2>/dev/null | grep -E 'Consumed|oom|Failed' | sed 's/^.*\]: //' | sort -u | cut -c1-200
# Compare with other boots instead of guessing: on the console (Series S) path the title itself grows to ~20 GB of
# RAM+swap by ~130 s (fsdraw-6: 9.9 GB + 11.2 GB), mostly zero pages that zram compresses well.
[ -s "$RES" ] && awk -F'\t' 'NR>1{t=$4+$5; if(t>m)m=t} END{printf "game peak RAM+swap %.1f GB (console-path baseline ~20 GB at 130 s; oomd kills when zram swap passes 98%%)\n", m/1024}' "$RES"
[ -s "$RES" ] && awk -F'\t' 'NR>1{ if(min==""||$2<min)min=$2; if($3>sw)sw=$3; if($4>um)um=$4; if($5>us)us=$5; if($6+0>gm)gm=$6 } END{printf "min RAM available %d MB, max swap used %d MB, game peak %d MB RAM + %d MB swap, VRAM peak %d MB\n", min, sw, um, us, gm}' "$RES"
journalctl --user -u "leonida-boot-$NAME" --since "@$START" -q --no-pager 2>/dev/null | grep -E 'Consumed|oom|Failed' | sed 's/^.*\]: //' | sort -u | cut -c1-200
echo
echo "-- system events during the boot (OOM, GPU Xid, segfaults)"
{ journalctl --since "@$BOOT" -q --no-pager 2>/dev/null | grep -i -E 'systemd-oomd.*(Marked|killed)|oom-kill|out of memory|NVRM: Xid|segfault|gta6rt|wineserver.*crash' ; } | cut -c1-200 | tail -15
Expand All @@ -61,15 +63,13 @@ cnt() { local c=0; [ -f "$D3D" ] && c=$(grep -a -c -E "$@" "$D3D"); echo "${c:-0
echo
echo "-- where the trace ended"
[ -f "$D3D" ] && tail -n 8 "$D3D" | cut -c1-200
} > "$OUT" 2>&1
} > "$OUT.tmp" 2>&1
mv "$OUT.tmp" "$OUT"

frames=$( [ -f "$CAP/index.txt" ] && awk '{m=$(NF-2)+$(NF-1)+$NF; if (m>0) n++} END{print (n+0) "/" NR}' "$CAP/index.txt" || echo "-")
peak=$( [ -s "$RES" ] && awk -F'\t' 'NR>1{if($4>u)u=$4} END{print u+0}' "$RES" || echo "-")
exec 7>>"$LEDGER"; flock 7
# Both the unit's ExecStopPost and the outer wrapper call this; the first one to finish records the boot.
grep -q -P "^[^\t]*\t$AGENT\t$N\t" "$LEDGER" 2>/dev/null && exit 0
[ -s "$LEDGER" ] || printf 'end\tagent\tn\tresult\tran_s\tpresentx_ok\tpso_failed\tfspx_miss\tnonblack_frames\tpeak_mb\tgta6rt\n' >&7
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$(date '+%F %T')" "$AGENT" "$N" "$RESULT" "$((END-BOOT))" \
"$(cnt 'XboxPresentation::PresentX ok')" "$(cnt 'CreatePipelineState failed')" "$(cnt 'no translated compute shader for FSPX')" \
"$frames" "$peak" "$(sed -n 's/^unit=.*gta6rt=\([^ ]*\).*/\1/p' "$META")" >&7
[ -s "$LEDGER" ] || printf 'end\tname\tresult\tran_s\tnonblack_frames\tpeak_mb\tgta6rt\n' >&7
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$(date '+%F %T')" "$NAME" "$RESULT" "$((END-BOOT))" "$frames" "$peak" \
"$(sed -n 's/^unit=.*gta6rt=\([^ ]*\).*/\1/p' "$META")" >&7
exit 0
Loading
Loading