Skip to content

startup: run a package with shared presets (console, OS, GPU) - #3378

Open
pigalot wants to merge 8 commits into
R0Y00:mainfrom
pigalot:startup/run-presets
Open

pigalot wants to merge 8 commits into
R0Y00:mainfrom
pigalot:startup/run-presets

Conversation

@pigalot

@pigalot pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Change

Adds tools/startup/run_preset.py, a launcher for runs of a local package. It has three choices: console (x or s), GPU (nvidia or amd) and OS (win11, win10 or linux; the host by default). Every other setting comes from tools/startup/run_presets.json, which is applied in layers: base, then OS, console, GPU. Each layer says why its settings are there and gives the measured run behind them.

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

The launcher also:

  • stages the executable folder's PE files in the run folder, hard-linked where the volume allows and copied otherwise, so the package is never written;
  • gives each run an empty storage folder;
  • maps the package on G: with subst for the run and removes the mapping afterwards. It refuses a letter that is taken, unless subst already maps it onto this package;
  • writes the merged settings to settings.json, starts run.ps1 (or run.sh on Linux) and prints triage_run.py for the logs.

--print shows the merged settings and the exact command without starting anything.

The base layer sets:

AGENTS.md gets a short section that points to the launcher and asks contributors to keep the presets current, with evidence for each change.

Why subst and not run.ps1 -MapDrive: -MapDrive rewrites only opens that pass through the debugger's file hooks. With it, a real-package run stayed on its first screens, with 11 pipelines translated in 420 s. The same settings on a subst drive kept loading and reached 76.

Refs #870, #3331

Verification

Build: 4d1b42bd (this branch on aec2e084), release, Windows 11 Pro 26200, NVIDIA.

  • python -B tests/startup_run_preset_check.py: OK: 12 preset choices, staging and controls. The check covers:

    • every console × OS × GPU choice against the real run.ps1/run.sh switch names;
    • the layer merge rules;
    • staging on a synthetic package, checking the package is left unchanged;
    • subst handling with a fake subst.

    Negative controls, each of which must be refused or caught:

    • a misspelt switch, an unknown key, a non-X2W env name, a number as an env value, an empty choice list and an unknown choice;
    • a letter mapped elsewhere or held by a volume, and a failing subst;
    • a config without an Executable.

    Taking X2W_HIDE_TITLE_WINDOW out of base fails all 12 choices.

  • python -B tests/startup_run_ps1_check.py: exit 0.

  • python -B tests/docs_links_check.py: Checked 156 Markdown files and 681 links.

  • tests/startup_run_sh_check.py skips on Windows (POSIX launcher), so it was not run.

Real-package runs (local data, not reproducible from this repository), Series X / NVIDIA preset, 420 s, same input script and seed storage on every run:

Build Settings Result
ec71c290 + #3332 previous shared settings, holding off alive, 75,028 translated draws, 62 pipelines
ec71c290 + #3332 this preset with -MapDrive alive, 73,780 draws, 11 pipelines
ec71c290 + #3332 this preset with subst, before PROBE_PRECHECK=0 alive, 162,303 draws, 74 pipelines, 2,134 textures
ec71c290 + #3332 + X2W_PROBE_PRECHECK=0 alive, 1,142,089 draws, 78 pipelines, 5,372 textures
ec71c290 + #3332 + X2W_HIDE_TITLE_WINDOW=1 alive, title window hidden once and not shown again, 975,488 draws, 77 pipelines
4d1b42bd (this branch) as committed alive, title window hidden once, ConsoleMode 0x64, input first read at 52 s, 655,334 draws, 79 / 482 pipelines translated / missing, 4,247 textures

The Series S preset (--console s) on ec71c290 + #3332 was also alive at 420 s, with 1,008,389 draws and 75 pipelines.

With one run per configuration, the draw counts vary a lot from run to run: the two Series X runs with the same settings drew 975k and 1.14M. The table supports "runs to the timeout with these settings", not a ranking of small differences.

Evidence and follow-up

Not measured: AMD, Linux (Wine/Proton) and Windows 10. The AMD and NVIDIA layers are deliberately identical. They exist so that a measured difference has somewhere to go. The Linux layer copies run.sh's defaults and the lazy-commit pair from the one reported Linux run (#1198, #2911).

Left out on purpose:

Whether keyboard input reaches the title after its window is hidden is still unmeasured. The output window belongs to the same process, so the input stand-in's focus check still sees the process in front. The runs above used the input script.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

This pull request was AI-assisted.

tools/startup/run_preset.py takes three choices (--console x|s, --gpu nvidia|amd, --os win11|win10|linux,
default this host) and reads every other setting from tools/startup/run_presets.json: a base layer, then
one layer per choice, each entry with the reason it is there. The launcher stages the executable's PE files
(hard links, else copies) so the package is never written, gives every run an empty storage folder, maps the
package on its drive letter with subst for the run, starts run.ps1 or run.sh, and runs triage_run.py.

The base layer turns off R0Y00#1408's thread holding (run.ps1 -SuspendOthers 0, R0Y00#3332) and uses subst rather
than run.ps1 -MapDrive; the measurements behind both, and behind the D3D12 switches it sets, are in the
preset's "why" text and docs/startup-runtime.md.

tests/startup_run_preset_check.py checks all 12 choices against the switches run.ps1 and run.sh define,
the layer rules, drive mapping through a fake subst, and staging on a synthetic package, with refusal
controls. Registered in CTest and the python-linux check list.
X2W_PROBE_PRECHECK=0 (R0Y00#3313) skips the VirtualQuery the stand-ins run before each probe and copy while a
debugger is attached; title runs always start under debug_launch.py. Same package, input and 420 s, NVIDIA,
Windows 11, ec71c29: 1,142,089 vs 162,303 translated draws, 80,175 vs 15,001 executes, 5,372 vs 2,134
textures uploaded. The reason is recorded in run_presets.json and docs/startup-runtime.md.
The base layer now sets X2W_HIDE_TITLE_WINDOW=1 on every host, so once
presents reach the output window the title's own window, which nothing
presents to, is hidden. Dialogs stay visible and the window comes back
when a present misses the output window. The Linux layer's
hide_title_window switch is dropped: run.sh's flag only exports the same
variable.

The preset check asserts the variable for all 12 choices; removing it
from base fails all 12.

Real run (420 s, Series X / NVIDIA preset, Windows 11, ec71c29): the
stand-in logged that it hid one title window and never showed it again,
the run was alive at the timeout, and the title read input from 58 s.
Translated draws were 975,488 (1,142,089 in the run before this change).
…m current

AGENTS.md now says to start package runs with tools/startup/run_preset.py, and to keep tools/startup/run_presets.json current: add a helpful opt-in switch to its layer, change a setting when a measured run shows it, put the evidence in the layer's why, and leave out switches that main does not read yet.

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4d1b42bd by its diff.

The package folder can be written. stage() in tools/startup/run_preset.py hard-links every .exe/.dll of the executable's folder into the stage (os.link(f, target), copy only on OSError), and the command runs the staged executable. run.ps1 then copies the 8 stand-ins into that folder ($runDir = Split-Path -Parent $Exe, Copy-Item ... -Force, tools/startup/run.ps1:43-47), and run.sh does the same with cp -f (run.sh:99-102). If the executable's folder holds a file with a stand-in's name and the stage is on the same volume, the staged entry is a hard link to the package's file. cp -f truncates and rewrites an existing destination in place, so on Linux the copy writes into the package's file when it is writable; Copy-Item -Force likely does the same on Windows (not measured). The docs say "the package folder itself is never written", and the stage() docstring "Nothing under the package is written". Fix: do not link a file whose name is one of the stand-ins (copy or skip it), or copy instead of linking, and add a test with such a file that checks the package copy is unchanged.

Caller environment is not recorded. The child starts from dict(os.environ) and the layers are applied on top (env = dict(os.environ); env.update(settings["env"])). An X2W_* already set in the caller's shell reaches the run, settings.json (choice, run, env, layers, command) does not record it, and an env: null in a layer cannot remove it, because null only drops values from earlier layers. Fix: record the inherited X2W_* values in settings.json and make null remove the variable from the child's environment. If inherited values are dropped instead, keep the ones run.sh reads from the caller (X2W_WIN_PYTHON, X2W_FXC, X2W_HOST_PYTHON).

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for this. Checked at 4d1b42b: the trial merge onto main aec2e08 is clean (git merge-tree --write-tree, rc 0), CI is 3/3 green, startup_run_preset_check.py prints OK: 12 preset choices, staging and controls, the run.sh/run.ps1 text checks, docs links and check fragments pass, 11 of 11 mutations of the new check fail it, and nothing under src/ changes. I'd ask for one change before merge.

MUST: run.sh writes into the package through the hard link. stage() calls os.link for every .exe/.dll in the executable's folder. run.sh then runs cp -f "$build_dir/$dll.dll" "$run_dir/" for the 8 stand-in names. That rewrites the linked file in place, so a package that ships one of those names gets modified, even though the docs say the package is never written. To reproduce on a synthetic package (Linux, repo root):

P=/tmp/p; mkdir -p $P/pkg/bin $P/build && printf 'MZ pkg' >$P/pkg/bin/xg_xs.dll && printf 'MZ exe' >$P/pkg/bin/t.exe && printf 'MZ stand-in' >$P/build/xg_xs.dll
python3 -c "import sys; sys.path.insert(0, 'tools/startup'); import run_preset as r; from pathlib import Path as P; print(r.stage(P('$P/pkg'), P('$P/pkg/bin/t.exe'), P('$P/run/stage'))[1:])"
cp -f $P/build/xg_xs.dll $P/run/stage/bin/ && cat $P/pkg/bin/xg_xs.dll

This prints (2, 0), so both files were linked, and then MZ stand-in: the package's own file was replaced. run.ps1's Copy-Item … -Force probably does the same on NTFS, but I didn't run it on Windows. I also haven't measured whether a real package ships any of these names. This would show it: ls <exe folder> | grep -ixE '(xmem|d3d12_xs|AcpHal|XCRDAPI|chad|xapu|xg_xs|GameInput)\.dll'. The check's "package unchanged" test covers only stage(), and its fixture has no stand-in name. Suggested fix: copy (or skip) the stand-in names instead of linking them, and add one to the fixture along with a run.sh-style copy step.

SHOULD: the check AMD and NVIDIA differ without a recorded reason fails on exactly the edit that the PR body ("so that a measured difference has somewhere to go") and the new AGENTS.md text ("put it in that host's layer") invite. Adding "env": {"X2W_SPLIT_INDIRECT_DISPATCH": "1"} to gpu.amd, with the reason in its why, makes python3 tests/startup_run_preset_check.py exit 1 with FAIL: win11: AMD and NVIDIA differ without a recorded reason (win10 and linux fail the same way). Could it either be dropped, or accept a difference whose key is named in that layer's why?

Minor: Linux --suspend-others 0 is never asserted (only Windows -SuspendOthers is), and removing -StoragePath crashes the check in cmd.index (ValueError) instead of giving a named FAIL.

This comment was AI-assisted.

run.ps1 (Copy-Item -Force) and run.sh (cp -f) copy the 8 stand-ins next to the staged executable and
rewrite an existing file in place. A package file with a stand-in's name was hard-linked into the stage,
so that copy wrote into the package. Measured on NTFS with a synthetic package: after Copy-Item -Force
under pwsh 7.7 and Windows PowerShell 5.1, the package's linked xg_xs.dll held the stand-in's bytes.

stage() now always copies a file whose name (any case) is one of STAND_INS. The check stages a package
with GameInput.dll and XMEM.dll, rewrites the stand-ins over the stage the way the scripts do, and
compares the package; a control with the names linked must change it. STAND_INS is checked against the
lists in run.ps1 and run.sh.
The run's environment starts from the caller's shell. An X2W_* value set there reached the run without
appearing in settings.json, and a layer's null only dropped an earlier layer's value, not the caller's.

merge() now also returns `unset`, the keys whose last value is null, and child_env() removes them from
the child's environment before the layers apply. The X2W_* and WINE* values that reach the run unchanged
are recorded in settings.json as `inherited_env` and listed by --print, so the variables run.sh reads from
the caller (X2W_WIN_PYTHON, X2W_FXC, X2W_HOST_PYTHON) are kept and shown. The check covers child_env()
and a run with the child start replaced: the environment it is given and what settings.json records.
The check refused any difference between the AMD and NVIDIA merges, so the edit the docs ask for (a
measured switch in that host's layer, with its reason) failed it: adding X2W_SPLIT_INDIRECT_DISPATCH to
gpu.amd printed "AMD and NVIDIA differ without a recorded reason".

A difference in env or run between GPU choices is now accepted when each GPU layer that sets the key
names it in its `why`, for every OS and console. Controls: that same edit passes, and an unnamed env value
plus an unnamed run option fail on every OS and console. AGENTS.md and docs/startup-runtime.md say to name
the switch in the layer's why.
…he preset check

The Linux commands were never checked for --suspend-others 0, only the Windows -SuspendOthers. A command
without -StoragePath, --storage, -SuspendOthers or -Seconds raised ValueError in cmd.index instead of a
named FAIL. arg_after() returns None for a missing flag. Mutations: dropping -StoragePath gives 8 named
FAILs (per-run storage), and leaving --suspend-others out of run.sh commands gives 4.
@pigalot

pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @Leyukaka and @JohnConnorNPC. Pushed four commits on top of 4d1b42bd; the branch still merges
cleanly onto current main (git merge-tree --write-tree, rc 0) and nothing under src/ changes.

Package written through the hard link (both of you). Confirmed on Windows too: on NTFS, with a synthetic
package, Copy-Item -Force over a hard-linked xg_xs.dll replaced the package's file under pwsh 7.7 and
Windows PowerShell 5.1. Fixed in 6d656cdf: stage() always copies a file whose name (any case) is one of
the 8 stand-ins, and links only the rest. STAND_INS in run_preset.py is checked against the lists in
run.ps1 and run.sh. The check now stages a package with GameInput.dll and XMEM.dll, rewrites the
stand-ins over the stage the way the scripts do (an in-place write), and compares the package; a control with
those names linked must change it. John's repro on the new head prints (1, 1) and then MZ pkg.

Caller environment (Leyukaka). d2215885: merge() also returns unset (keys whose last value is
null), and those are removed from the child's environment, so null now also drops a value set in the
caller's shell. Caller X2W_* and WINE* values that reach the run are kept (so X2W_WIN_PYTHON, X2W_FXC,
X2W_HOST_PYTHON still work), written to settings.json as inherited_env, and listed by --print. The
check covers it end to end with the child start replaced: the environment it gets and what settings.json
records.

GPU check vs. the documented edit (John, SHOULD). 5f28d9b2: a difference between GPU choices (env or
run) is now accepted when each GPU layer that sets the key names it in its why, for every OS and console.
Your edit (X2W_SPLIT_INDIRECT_DISPATCH in gpu.amd) passes; an unnamed env value and an unnamed run option
fail. AGENTS.md and the docs say to name the switch in the layer's why.

Minor (John). 30fdfe5e: Linux commands are checked for --suspend-others 0, and a missing flag gives a
named FAIL instead of a ValueError (dropping -StoragePath now gives 8 per-run storage FAILs).

After each commit: startup_run_preset_check.py (OK: 12 preset choices, staging and controls, also under
Linux), startup_run_ps1_check.py and docs_links_check.py pass. Each new check was mutation-tested: the old
linking, the old environment handling, a missing -StoragePath and a missing --suspend-others each fail it.

This reply was AI-assisted.

@pigalot
pigalot requested a review from Leyukaka November 28, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants