# The in-game gate One command runs the D3D12 runtime (`leonida.exe`) in the game for a set time in the world and says PASS, FAIL or ERROR. The same way on every machine. It is what a change to the render path needs before merge ("300 s in the world, no device loss"). It also gives the numbers an A/B compares: one `summary.json` per run, in one format. The script is `scripts/game-gate.ps1` (Windows, PowerShell 7). The parser is `tools/game_gate.py` (standard library only). The tests are in `tests/test_game_gate.py`. ## Running it It needs PowerShell 7 (`pwsh`). Windows PowerShell 5.1 (`powershell.exe`) refuses the script with a message before anything runs, from its `#Requires -Version 7.0` line. Build the runtime first (`d3d12\scripts\build-nvidia.ps1`). The gate refuses to start without `d3d12\target\diag\leonida.exe`, because the play script would build it inside the timed run. For the same reason it refuses a build noted as made without DLSS (`built-with.txt`) once NVIDIA's SDK is in `d3d12\nvidia-sdk`: the play script makes that build again with DLSS at its next start (not with `-NoDlss` in `-PlayArgs`, and not without cargo). Make a data template once: 1. Play to the place the runs should start from. 2. Let the title save, and close the game cleanly. 3. Copy `\data\` (its `saves` and `storage`) into a folder outside the checkout. Each run gets a copy of it, so your own saves are never touched. A save is game data: never share or commit it. ```powershell pwsh -NoProfile -File scripts\game-gate.ps1 run -Game <game folder> -Data <data folder> -DataTemplate <template> ` -Name base [-PlayArgs '<play-d3d12.ps1 switches>'] [-More 'LEONIDA_X=1;LEONIDA_KEYS=40:Enter,60:Enter'] [-WorldSeconds 300] pwsh -NoProfile -File scripts\game-gate.ps1 start <same options> # detached: returns at once, prints the run folder pwsh -NoProfile -File scripts\game-gate.ps1 stop -RunDir <run folder> ``` - **The play script's switches.** `-PlayArgs` passes them on as they are, for example `-SeriesS -NoFrameGen`. - **Reaching the world.** The gate does not drive the menus. Pass key presses with `LEONIDA_KEYS`; they are timed from the start of the process, so allow for the precompile. - **The caches.** `-Data` keeps its caches (`cache-2`); only the saves are copied. The first start after a translator change translates every shader again: run once before measuring. - **Ending the run.** It stops when the time in the world reaches `-WorldSeconds`, when a `STOP` file appears in the run folder (`stop`), or after `-MaxMinutes` (45). It checks every 5 s. When two reasons come at the same check, the first of these wins: the title relaunched, the world time (`target`), the memory stop (below), the `STOP` file, the time limit. So a `STOP` file and the world time at the same check give `target`. - **Memory stop.** It also stops the run, the same clean way and with the reason `memory`, before memory runs out. A memory pile-up has taken a PC's whole Windows down, not only the device. It reads the runtime's memory lines (every 5 s, builds with diagnostics) and stops when: - the game's private bytes pass `-StopPrivateMB` (default: the lower of 90 % of this PC's commit limit and 1.25 times its physical memory; with a large page file the limit is far above what a PC survives, and two Windows crashes came at about 100 GB private on a PC with 64 GB); - the PC has less than `-StopCommitLeftMB` left to commit for 20 s (default: the larger of 128 MB and 0.25 % of the limit; on a PC with no page file a normal run can leave a few hundred MB); - video memory stays over the system's budget for `-StopOverBudgetSeconds` (60). 0 turns a limit off. The limits go into `run.json` (`memory_stop`) and the summary (`memory.stop_limits`). A run that reaches `-WorldSeconds` at the same check as a limit stops with `target`: it is a measurement, and its memory peaks are in the summary all the same. - **How it stops.** With `WM_SYSCOMMAND`/`SC_CLOSE`, the runtime's own end: the title is suspended and the pipeline cache saved. It kills the game only if it has not ended 60 s later. - **Exit code.** 0 PASS, 1 FAIL, 2 ERROR. `start` exits when the detached run is created. The run folder (under `-RunRoot`, by default `<Data>\gate-runs`, refused inside a checkout) holds: | File | What | | --- | --- | | `run.json` | Name, start time, commit, exe hash, build features, card, driver, options | | `launch.ps1` | How the game was started | | `settings.txt` | The play script's `-DryRun` | | `leonida-settings.txt` | The F1 menu file, when there was one (it changes every run, so the summary warns) | | `launcher.txt` | The play script's output, with the precompile lines | | `leonida.log` | The runtime's log, with `LEONIDA_LOG=info,leonida_gpu::frame=debug` (one line per present) | | `events.jsonl` | What the gate did and saw: the game found, the stop asked for and why, a kill, the exit code | | `data\` | The run's copy of the template, and the runtime's `crashes.log` | | `summary.json` | The result, below | | `memory.csv` | One row per runtime memory line (every 5 s, builds with diagnostics): time, private bytes, of them in physical memory, the PC's memory free and left to commit, the card's video memory budget and in use, the shared memory in use, the objects let go that wait for their submissions, and the reaper thread's queue. Its header is `t_s,private_mb,in_memory_mb,pc_free_mb,pc_commit_left_mb,vram_budget_mb,vram_in_use_mb,shared_in_use_mb,waiting_objects,reaper_queue`. The video memory columns come from the video memory line nearest the memory line, and the last two from the census line nearest it, each within 2 s; a cell is empty when there is none. Only when the run has memory lines: a summary made again from a log without them removes an older `memory.csv` | ## summary.json (`leonida-gate-summary/1`) Times are seconds since the run started. The summary holds numbers, switch names and verdicts only. It never holds a path, a user or machine name, or text the title printed. A fault is told by the kind of module it was in, not by its name or address. | Field | Meaning | | --- | --- | | `run` | Name, start time, commit, `dirty` (a tracked file changed), `untracked` (how many files git does not track), exe hash (16 hex), build features, card, driver, play arguments, `world_seconds` | | `settings` | The `LEONIDA_*` settings from the runtime's `settings` line, as it shows them (folders hidden). Empty, with a warning, from a runtime without that line | | `precompile` | From the launcher: shaders in the cache and the seconds that took, pipelines known, made before, to make, made, their seconds and median ms | | `times.world_at_s` | The world: the first of two frame lines in a row with 500 draws a frame or more. Cutscenes count: a save that opens on one is in the world. Like every time here, it counts from the gate's start, so the precompile is in it (its seconds are `precompile.shaders_s` and `precompile.made_s`) | | `times.warm_at_s` | From then on, 60 s in the world with no pipeline being made and no wait for one that ran out. Draws dropped for a pipeline the host never has go on all run long and do not count | | `times.world_s` | Seconds from `world_at_s` to the stop request | | `fps` | From the presents, after the first 60 s in the world: frames, median, p5, frame p95 (ms), median of the last 60 s (`end_median`), the first second with fewer than 2 frames, from 60 s in the world on too (`under_2_at_s`), the longest gap with no frame presented from the world on (`longest_present_gap_s`, `longest_gap_at_s`; on purpose from the world on: a freeze on pipeline compiles comes right after arrival, and 10 s with no frame is what a player sees), draws a frame. Without the present lines (a build without diagnostics), the median and p5 come from the frame lines, with a warning | | `pipelines` | Waits that ran out (`missed_waits`), the most pipelines being made at once | | `memory` | Peaks over the whole run, from the runtime's memory line and video memory line (every 5 s; builds with diagnostics only, otherwise `source` is null): the process's private bytes and when (`private_max_mb`, `private_max_at_s`), the most of them in physical memory, the least the PC had left to commit and when, the card's video memory in use at its most and when, with the budget the system gave then (`vram_in_use_max_mb`, `vram_max_at_s`, `vram_budget_at_max_mb`), the seconds spent over that budget, and the most of the PC's memory shared with the card in use. The video memory is what the system counts for this process, less than a tool like `nvidia-smi` shows for the whole card. `stop_limits` holds the memory stop's limits from `run.json` (null from a gate without the memory stop). Also, from the runtime's census line, the reaper thread's queue at its longest and when (`reaper_queue_max`, `reaper_queue_max_at_s`) and the most objects let go that wait for their submissions (`waiting_objects_max`); how fast the private bytes grew in the world in MB a minute (`private_mb_per_min_in_world`, a least-squares slope over the memory lines from `world_at_s` to the stop request: on a short run it is the loading's climb, on a long one a pile-up's slope; null with fewer than 3 lines there); and `series`, the name of `memory.csv` (null without memory lines, or when the file could not be written, for example open in another program: `game_gate.py` says so on stderr and writes `summary.json` all the same). The video memory peak and the time over the budget count every video memory line: the one written with each memory line, and the ones the runtime writes right before and after it makes the swap chain, right after the swap chain's buffers are made again for another size or format, and right after the system changes the card's budget by 256 MB or more. `memory.csv` has only the one nearest each memory line, so the summary's peak can come from a line with no row there | | `crash` | `kind` is `none`, `device_lost`, `panic` or `fault`. It also gives the time, the code, the module kind (`runtime`, `title`, `driver`, `system`, `unknown`) and the access (read/write). `title_watchdog` marks a write at address 0 in the title more than 25 s after the last frame line. `count` is the number of crashes | | `exit` | The game's exit code, and its kind: `clean`, `device_lost` (0x887A0005), `killed` or `other` | | `stop` | Why it was stopped (`target`, `stop_file`, `timeout`, `relaunched` or `memory`), whether it was killed, whether the cache was saved, whether the suspend was in time. After a memory stop, `memory_why` is the gate's whole sentence for it, with its numbers: `private bytes 31000 MB, over 30000 MB`, `the PC had under 200 MB left to commit for 25 s` or `video memory over its budget for 60 s`, for example. It is null for the other reasons | | `verdict` | `result`, `reasons`, `warnings`, `min_world_s` | ## The verdict **PASS** needs all of these: - at least `-WorldSeconds` (300) in the world; - no device loss and no panic; - no fault before the stop request; - no gap over 10 s with no frame presented once in the world, so a run frozen on a pipeline compile does not pass; - the game alive at the stop request: a frame line less than 30 s old. **FAIL** comes with one or more reasons: - `device_lost`: a host GPU failure, an out-of-memory command list that did not close, or exit 0x887A0005; - `panic`; - `fault_before_stop`; - `exited_before_stop`; - `present_gap`; - `world_time_short`: the time limit came first; - `memory_stop`: the memory stop ended the run, which was on its way to running out. `world_time_short` and `world_not_reached` are not added to it: the stop is why the run was short; - `not_alive_at_stop`; - `world_not_reached`, when the game ended before reaching the world. **ERROR** means the gate could not judge the build: - `not_started`; - `relaunched`: the title restarted itself; - `stopped_early`: a STOP file before the time; - `world_not_reached`, when the game was still in the menus at the time limit. A crash after the stop request is a warning, except a device loss or a panic, which stay FAIL. A kill, a cache not saved and a late suspend are warnings too. ## Not in this version - A driver for the menus and a fixed route (a Lua mod). - An ABBA runner over several runs. - A "memory rising" warning. - The distance walked. - The Vulkan runtime (`gta6rt`).