Skip to content
Open
33 changes: 33 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,39 @@ python3 -m venv out/pe-env
and the local `llvm-mc`, `llvm-objcopy` and `libLLVM` paths. CI uses LLVM 15;
newer versions may print a different `exp` spelling.

## Run settings for packages

Start runs of a local package with the shared presets rather than a
hand-written `run.ps1` or `run.sh` line:

```powershell
.\out\pe-env\Scripts\python.exe -B tools\startup\run_preset.py --package <package root> --console x --gpu nvidia
```

The launcher asks only for the console (`x` or `s`), the GPU (`nvidia` or `amd`)
and the OS (`win11`, `win10` or `linux`; the host by default). All other
settings come from `tools/startup/run_presets.json`, applied in layers: base,
then OS, console and GPU. `--print` shows the merged settings and the command
without starting anything. See
[Run with the shared presets](docs/startup-runtime.md#run-with-the-shared-presets).

Keep the presets current. They are only useful while they hold the best
settings on main:

- When a pull request adds an opt-in switch or setting that helps package runs,
add it to the right layer in the same pull request or in a follow-up.
- When a measured run shows that a preset setting is better, worse or no longer
needed, change it.
- Give each change its evidence in the layer's `why`: commit, host, GPU,
duration, and the counters before and after.
- When a host needs a setting that no layer covers, such as a GPU generation, a
driver or an OS, put it in that host's layer with the run that showed it, and
name the switch in that layer's `why` (the check refuses a GPU difference it
does not name). Do not add a launcher option.
- Leave out switches that main does not read yet, such as one from an open pull
request.
- After editing, run `tests/startup_run_preset_check.py`.

## Repository map

| Path | Purpose |
Expand Down
58 changes: 58 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,64 @@ It writes:
| `<log>/files.txt` | every file the process opened |
| `<log>/translate.txt` | with `-Translate`: one line per shader request translated during the run |

### Run with the shared presets

`tools/startup/run_preset.py` starts a run with the settings kept in `tools/startup/run_presets.json`
instead of a hand-picked set of switches. It takes three choices and the package root:

```powershell
.\out\pe-env\Scripts\python.exe -B tools\startup\run_preset.py --package <package root> --console x --gpu nvidia
```

| Choice | Values | Default |
|---|---|---|
| `--console` | `x` (Series X), `s` (Series S) | required |
| `--gpu` | `nvidia`, `amd` | required |
| `--os` | `win11`, `win10`, `linux` | this host |

The settings file has a `base` layer and one layer per choice. They apply in the order base, OS,
console, GPU. A later layer overrides an earlier one, and an `env` value of `null` unsets it, also when
the caller's shell set it. Each entry
records why it is there. To change what everyone runs with, change the file and cite the run that
supports the change. Do not add a launcher option for it. `--print` shows the merged switches, the
environment and the command without staging or starting anything.

The launcher:

- reads the executable's path from the package's `MicrosoftGame.config`;
- stages the PE files of that executable's folder in `<run>/stage`, hard-linked where the volume
allows and copied otherwise. `run.ps1` and `run.sh` copy the stand-ins next to the executable, so
the package folder itself is never written. A package file named like a stand-in (`xg_xs.dll`,
`GameInput.dll`, ...) is always copied: `Copy-Item -Force` and `cp -f` rewrite an existing file in
place, so through a hard link they would write into the package;
- gives every run an empty storage folder (`<run>/storage`);
- maps the package on its console drive letter with `subst` for the run and removes the mapping
afterwards. A letter that is taken is refused, unless `subst` already maps it onto this package. It
does not use `run.ps1 -MapDrive`: that rewrites only opens that pass through the debugger's file
hooks, and a real-title run with it stayed on its first screens where the same settings on a `subst`
drive went on loading. Under Wine, link `dosdevices/g:` in the prefix yourself;
- turns off the debugger's thread holding (`run.ps1 -SuspendOthers 0`, #3332). With holding on, real
runs on main stopped before the first input poll; a bisect points at #1408. The base layer also
sets `X2W_PROBE_PRECHECK=0` (#3313), because title runs always start under the debugger. On the
same 420 s input it raised translated draws from 162,303 to 1,142,089;
- hides the title's own window (`X2W_HIDE_TITLE_WINDOW=1`, see [Output window and fallback diagnostics](#output-window-and-fallback-diagnostics))
once presents reach the output window, so only the output window stays on screen;
- starts `run.ps1`, or `run.sh` on Linux, then prints `tools/startup/triage_run.py` for the run's logs.

Runs go to `out/startup/runs/<time>-<console>-<os>-<gpu>/`, which holds `log/`, `stage/`, `storage/`
and `settings.json`: the merged settings, the exact command, and under `inherited_env` the `X2W_*` and
`WINE*` values from the caller's shell that reach the run (`X2W_WIN_PYTHON`, `X2W_FXC` and
`X2W_HOST_PYTHON` for `run.sh`, for example); `--print` lists them too. Input comes from the keyboard and
XInput pad 0 while the output window has focus; `input_script` in the settings file (or
[Input script](#input-script)) replays a fixed sequence instead. No AMD or NVIDIA entry
changes a switch today: no stand-in branches on the vendor, and no reported AMD run needed a
different one. The two entries are there so that a measured difference has a place to go: name the
switch in that entry's `why`, because `tests/startup_run_preset_check.py` refuses a GPU difference
whose switch the `why` of the layer that sets it does not name.
`tests/startup_run_preset_check.py` checks every choice against the switches that `run.ps1` and
`run.sh` define, and checks staging on a synthetic package. It also checks refusals: a misspelt
switch, an unknown key, a non-string value, an unknown choice, and a package without an executable.

### Package on another volume

A console executable opens its package at a fixed drive letter, so a package that lives on another
Expand Down
2 changes: 2 additions & 0 deletions tests/checks/python-linux/run_preset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Shared run presets: every console x OS x GPU choice against run.ps1/run.sh, staging on a synthetic package.
tests/startup_run_preset_check.py
7 changes: 7 additions & 0 deletions tests/cmake/startup_run_preset.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Shared run presets (tools/startup/run_preset.py, tools/startup/run_presets.json): every console x OS x GPU
# choice names only switches that run.ps1 and run.sh define; staging is checked on a synthetic package.
if(EXISTS "${INTAKE_PYTHON}")
add_test(NAME startup_run_preset COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_run_preset_check.py")
set_tests_properties(startup_run_preset PROPERTIES TIMEOUT 60)
endif()
Loading
Loading