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
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,13 @@ that stage has finished rebuilding `vk_pipeline_check`, so it can overlap the re
translated shader on your GPU driver, reports any it has to skip, and saves a pipeline cache to `pipeline_cache.bin`
in `--out`, which also holds `gta6rt.exe` after the `runtime` stage. The runtime seeds its Vulkan pipeline cache
from the file beside the executable when its header matches the device and pipeline cache UUID. It falls back to
an empty cache if the file is missing, incompatible, or rejected by the driver. Shader translation is the longest
CPU step. It runs on `--jobs` processes (half the CPU threads by default). When shaders and assets share the machine,
that budget is split between them and passed to `rpf9dump` as `--jobs`. A solo assets run still lets `rpf9dump` use
every core. Progress lines include percent and a rough ETA for translation shards, asset steps, and overall stage
completion.
an empty cache if the file is missing, incompatible, or rejected by the driver. `pipeline_done.json` beside the cache
lists the shaders already built for this GPU, driver and checker, so a later run only builds the ones whose SPIR-V
changed ([docs/pipeline_check.md](docs/pipeline_check.md#shard-caches-and-the-done-list)). Shader translation is the
longest CPU step. It runs on `--jobs` processes (half the CPU threads by default). When shaders and assets share the
machine, that budget is split between them and passed to `rpf9dump` as `--jobs`. A solo assets run still lets
`rpf9dump` use every core. Progress lines include percent and a rough ETA for translation shards, asset steps, and
overall stage completion.

On an interactive terminal, a LEONIDA setup screen lets you set jobs and whether stages overlap, then a key-switchable
per-stage log view (`1`–`4` / `Tab`) keeps parallel output demuxed; full stage logs go under `work/logs/`. Use
Expand Down
69 changes: 67 additions & 2 deletions docs/pipeline_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ Build with `make_game.py --stages shaders --compact-spirv` to run SPIRV-Tools lo
| `--isolate` | POSIX only: check in child processes, `--isolate-batch N` modules at a time (default 256), so a crashing module is recorded as `MODULE CRASH` and the pass continues. Not compatible with `--stats`. |
| `--inflight-file F` | Keep the modules currently in the driver in F as `name<TAB>phase` lines. It is rewritten by the watchdog and when a large module enters or leaves, and emptied at the end; `make_game.py`'s pipelines stage reads it. |
| `--skip-file F` | Do not compile modules named one per line in F; each is reported as `MODULE CRASH` and counted as a failed pipeline. `make_game.py` writes F after a crash so the next run checks the rest. |
| `--names-file F` | Check only the index entries named one per line in F (applied before `--start`/`--count`); a name the index lacks is a usage error. |
| `--done-file F` | At the end, write the modules that passed to F, one per line and sorted: module created, and pipeline created or skipped for a missing feature or stub, with the cache saved. Not with `--isolate`. |

Two other modes take no spirv dir:

| Command | Meaning |
|---|---|
| `vk_pipeline_check --device-info` | Print `device-info vendor=… device=… driver=… api=… uuid=<pipelineCacheUUID> name=…` for the device a check would use (`LEONIDA_VK_DEVICE` applies). |
| `vk_pipeline_check --merge <out> <in>...` | Load `<out>` if it exists, add each input with `vkMergePipelineCaches` and save `<out>` atomically. An input whose header names another vendor, device or `pipelineCacheUUID` (`runtime/test/pipeline_cache_header.h`), or that cannot be read, fails the merge with exit 1 and leaves `<out>` as it was; an `<out>` of another device is replaced. |

`--isolate-child` is internal to the parent/child protocol and is not meant to be passed directly. A module with a missing partner stub is skipped; without `--isolate`, a driver crash ends the run.

Expand Down Expand Up @@ -347,8 +356,10 @@ that size. Which threads the game creates pipelines on is not known without its
## Build-stage batches (BUILD-1030)

`make_game.py` runs the pipelines stage in fresh checker processes over at most **500 index entries** each, on
Windows and POSIX. The ranges partition the same name-sorted index as `--start` / `--count`, including the final
short range. Each finished process saves to the same `pipeline_cache.bin`, and the next loads that checkpoint.
Windows and POSIX. The ranges partition the name-sorted list of modules still to check (with a checker before
`--merge`, the whole index, selected by `--start` / `--count`), including the final short range. Each process writes
its own shard cache, merged into `pipeline_cache.bin` at the end (next section); with a checker before `--merge`,
each finished process saves to the same `pipeline_cache.bin`, and the next loads that checkpoint.
This bounds each invocation to a range that can be split further if concurrent heavy compiles exceed available
memory. A work folder with at most 500 entries keeps the single invocation. An older checker without the range
options keeps the older invocation; rebuild the runtime to get batching.
Expand Down Expand Up @@ -378,6 +389,60 @@ bounded coverage and cache checkpoints, collective memory-crash recovery, a genu
failures, interruptions, setup failures, inconclusive probes and compatibility with older checkers. It needs no
game files or GPU.

## Shard caches and the done-list

With one shared `pipeline_cache.bin`, every one of the 53 processes of a full run loaded the whole cache and saved it
back: on an RTX 4070 SUPER (NVIDIA 621.01) the full set's cache is 9.6 GB, and that load and save took 1-2 minutes per
process. A run after a translator change also checked all 26,503 modules again, even the unchanged ones (they compile
from the cache, but each process still pays the load and save). With a checker that has `--merge`, the stage instead:

- gives each process (and each single-module crash probe and each pass over an extra set) its own empty cache,
`pipeline_shards/NNNNN.bin` in `--out`, and its batch through `--names-file`;
- merges the shards into `pipeline_cache.bin` once at the end (`--merge`), then removes them. A run that was stopped
(Ctrl+C, a setup error, the crash retries running out) keeps its shards, and the next run merges them. A run with a
validation failure still merges what was built, as each process's own cache save did before;
- records each module its `--done-file` names in `pipeline_done.json` in `--out`, with the SHA-256 of its `.spv` and
of its index entry and the shard it went to. A later run skips the modules recorded with the same hashes, so after
a translator change only the modules whose SPIR-V (or index entry) changed are built;
- after the main set, checks the extra sets the runtime seed needs, each whole in one process: `bvh/`
(XboxBvhBuilder), `fspx/` (the FidelityFX DLL's compute programs) and `exe/` (the executable's own programs). Each
is recorded under `extras` by a hash of its `index.json` and `.spv` files, so an unchanged corpus starts no process
and needs no merge. `library/` and `fspx_gfx/` are not checked: on NVIDIA the seed does not hit for them ([#1608](https://github.com/ubiquitarianism/leonida/issues/1608)). A
set that fails is not recorded and fails the stage, but the other sets and the merge still run.

The whole list is tied to one identity: vendor and device ID, driver version and `pipelineCacheUUID`
(`--device-info`), the checker, the partner stubs in `stubs/` and the list's format. A change of any of them checks
every module again. A new GPU or driver also drops leftover shards and starts from empty caches (the old cache is of
no use to it). A new checker or new stubs on the same driver instead checkpoint into the existing `pipeline_cache.bin`
for that one run, as the first run does, so the pipelines it holds compile from it; leftover shards are merged. The checker is named by the SHA-256 of its sources when it is the
current build in this checkout's `runtime/build` (the `cl.exe` fallback of `scripts/build_runtime.ps1` relinks it on
every runtime stage), otherwise by the SHA-256 of the executable. Entries already merged into `pipeline_cache.bin`
are kept when something else writes to it (a checker run straight into it only adds pipelines), and dropped, with a
line saying why, only when the cache is gone or empty, is smaller than the last merge left it, or its header names
another vendor, device or `pipelineCacheUUID`; deleting the cache builds everything again. A module that failed, crashed the driver or was not checked is not on the list, so it is checked on every run
as before. The first run over a `pipeline_cache.bin` from before the done-list keeps the old per-process load and save,
so what that cache holds still compiles from it; later runs use shards.

The cache holds the same pipelines as before: each module's pipeline is created by the same checker with the same
device setup, only into a smaller cache that is merged afterwards. `runtime/test/check_vk_pipeline_merge.py` (CTest
`vk_pipeline_check_merge`) checks this on the GPU: two caches of three synthetic compute shaders each, merged, seed a
run over all six with six application-cache hits, and the first cache alone with three. `pipeline_cache_header` tests
the header check without a device, and `tests/test_make_game_pipeline_batches.py` runs the stage's crash recovery with
both checker generations plus the done-list cases (resume, changed module, changed driver or checker, failed merge).

Measured on an RTX 4070 SUPER (NVIDIA 621.01, Windows 11), `--jobs 2`, `__GL_SHADER_DISK_CACHE=0`, 400 synthetic compute
shaders in batches of 50 (8 processes), seconds, two runs each:

| | Full run | Rerun, nothing changed | Rerun, 20 modules changed |
|---|---:|---:|---:|
| one shared cache | 2.9 / 3.0 | 2.3 / 2.4 | 2.2 / 2.5 |
| shards + done-list | 3.2 / 3.5 | 0.22 / 0.25 | 0.76 / 0.86 |

That cache is 2.8 MB, so this measures the per-process and per-module work, not the cache I/O, which is what dominates
the real corpus: the stage no longer loads or saves the cache per process, and merges once. The checker also reads
its seed cache in one call now; loading a 2 GiB cache file took 21.6 s before (a character-by-character copy) and
1.7 s after, on the same machine.

## Crash isolation (`--isolate`)

A driver that dies while compiling one module (for example the RADV `SIGFPE` in
Expand Down
Loading
Loading