startup: run a package with shared presets (console, OS, GPU) #3378
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3378"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T17:00:32Z.
Change
Adds
tools/startup/run_preset.py, a launcher for runs of a local package. It has three choices: console (xors), GPU (nvidiaoramd) and OS (win11,win10orlinux; the host by default). Every other setting comes fromtools/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.The launcher also:
G:withsubstfor the run and removes the mapping afterwards. It refuses a letter that is taken, unlesssubstalready maps it onto this package;settings.json, startsrun.ps1(orrun.shon Linux) and printstriage_run.pyfor the logs.--printshows the merged settings and the exact command without starting anything.The base layer sets:
-SuspendOthers 0(#3332);X2W_PROBE_PRECHECK=0(#3313);X2W_D3D12_RING_RELEASE_AT_SUBMIT(#2949),X2W_D3D12_ROOT_SRV_AT_DRAW(#3028) andX2W_D3D12_TABLE_ALIAS(#2977);X2W_HIDE_TITLE_WINDOW=1, so only the output window stays on screen;AGENTS.mdgets a short section that points to the launcher and asks contributors to keep the presets current, with evidence for each change.Why
substand notrun.ps1 -MapDrive:-MapDriverewrites 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 asubstdrive kept loading and reached 76.Refs #870, #3331
Verification
Build:
4d1b42bd(this branch onaec2e084), release, Windows 11 Pro 26200, NVIDIA.python -B tests/startup_run_preset_check.py:OK: 12 preset choices, staging and controls. The check covers:run.ps1/run.shswitch names;substhandling with a fakesubst.Negative controls, each of which must be refused or caught:
subst;Executable.Taking
X2W_HIDE_TITLE_WINDOWout 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.pyskips 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:
ec71c290+ #3332ec71c290+ #3332-MapDriveec71c290+ #3332subst, beforePROBE_PRECHECK=0ec71c290+ #3332X2W_PROBE_PRECHECK=0ec71c290+ #3332X2W_HIDE_TITLE_WINDOW=14d1b42bd(this branch)The Series S preset (
--console s) onec71c290+ #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:
X2W_D3D12_VIEW_TOKEN_GUARDED(#3097), because main does not read it yet;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 was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T17:13:00Z.
Review: CHANGES_REQUESTED
Reviewed
4d1b42bdby its diff.The package folder can be written.
stage()intools/startup/run_preset.pyhard-links every.exe/.dllof the executable's folder into the stage (os.link(f, target), copy only onOSError), and the command runs the staged executable.run.ps1then copies the 8 stand-ins into that folder ($runDir = Split-Path -Parent $Exe,Copy-Item ... -Force,tools/startup/run.ps1:43-47), andrun.shdoes the same withcp -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 -ftruncates and rewrites an existing destination in place, so on Linux the copy writes into the package's file when it is writable;Copy-Item -Forcelikely does the same on Windows (not measured). The docs say "the package folder itself is never written", and thestage()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"])). AnX2W_*already set in the caller's shell reaches the run,settings.json(choice,run,env,layers,command) does not record it, and anenv: nullin a layer cannot remove it, becausenullonly drops values from earlier layers. Fix: record the inheritedX2W_*values insettings.jsonand makenullremove the variable from the child's environment. If inherited values are dropped instead, keep the onesrun.shreads from the caller (X2W_WIN_PYTHON,X2W_FXC,X2W_HOST_PYTHON).Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T17:15:23Z.
Thanks for this. Checked at
4d1b42bd: the trial merge onto mainaec2e084is clean (git merge-tree --write-tree, rc 0), CI is 3/3 green,startup_run_preset_check.pyprintsOK: 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 undersrc/changes. I'd ask for one change before merge.MUST: run.sh writes into the package through the hard link.
stage()callsos.linkfor every .exe/.dll in the executable's folder. run.sh then runscp -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):This prints
(2, 0), so both files were linked, and thenMZ stand-in: the package's own file was replaced. run.ps1'sCopy-Item … -Forceprobably 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 onlystage(), 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 reasonfails 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"}togpu.amd, with the reason in itswhy, makespython3 tests/startup_run_preset_check.pyexit 1 withFAIL: 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'swhy?Minor: Linux
--suspend-others 0is never asserted (only Windows-SuspendOthersis), and removing-StoragePathcrashes the check incmd.index(ValueError) instead of giving a named FAIL.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T17:42:40Z.
Thanks @Leyukaka and @JohnConnorNPC. Pushed four commits on top of
4d1b42bd; the branch still mergescleanly onto current main (
git merge-tree --write-tree, rc 0) and nothing undersrc/changes.Package written through the hard link (both of you). Confirmed on Windows too: on NTFS, with a synthetic
package,
Copy-Item -Forceover a hard-linkedxg_xs.dllreplaced the package's file under pwsh 7.7 andWindows PowerShell 5.1. Fixed in
6d656cdf:stage()always copies a file whose name (any case) is one ofthe 8 stand-ins, and links only the rest.
STAND_INSinrun_preset.pyis checked against the lists inrun.ps1andrun.sh. The check now stages a package withGameInput.dllandXMEM.dll, rewrites thestand-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 thenMZ pkg.Caller environment (Leyukaka).
d2215885:merge()also returnsunset(keys whose last value isnull), and those are removed from the child's environment, sonullnow also drops a value set in thecaller's shell. Caller
X2W_*andWINE*values that reach the run are kept (soX2W_WIN_PYTHON,X2W_FXC,X2W_HOST_PYTHONstill work), written tosettings.jsonasinherited_env, and listed by--print. Thecheck covers it end to end with the child start replaced: the environment it gets and what
settings.jsonrecords.
GPU check vs. the documented edit (John, SHOULD).
5f28d9b2: a difference between GPU choices (env orrun) 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_DISPATCHingpu.amd) passes; an unnamed env value and an unnamed run optionfail. 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 anamed FAIL instead of a
ValueError(dropping-StoragePathnow gives 8per-run storageFAILs).After each commit:
startup_run_preset_check.py(OK: 12 preset choices, staging and controls, also underLinux),
startup_run_ps1_check.pyanddocs_links_check.pypass. Each new check was mutation-tested: the oldlinking, the old environment handling, a missing
-StoragePathand a missing--suspend-otherseach fail it.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T20:39:11Z.
Review: APPROVED
LGTM — well-structured launcher with solid test coverage.
run_preset.pyandrun_presets.jsonreplace hand-written run lines with layered settings (base → OS → console → GPU). Each entry carries itswhy. Staging hard-links PE files while protecting stand-in-named DLLs from in-place rewrite. Drive mapping viasubst(not-MapDrive) avoids debugger file hook issues. The Python fixture covers all console/OS/GPU combos, staging, refusals, and the --print path.Ready to land.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T21:06:48Z.
Review: APPROVED
LGTM — well-structured launcher with layered config and thorough tests.
run_preset.py starts a package run with settings from run_presets.json: base, OS, console, GPU layers merge in order; null unsets; strict validation (no unknown keys, no non-X2W env, string values only). Launcher stages PE files (hard-linked, stand-ins always copied), maps package on subst drive, disables thread holding, hides title window, runs run.ps1/run.sh, and prints triage. Presets file documents every setting with why, runs, and measured results. Test covers layer merging, GPU unexplained differences check, drive mapping, staging, and negative controls.
Ready to land.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T21:17:01Z.
Review: APPROVED
LGTM — clean launcher for shared real-run settings.
run_preset.py picks console (x/s), GPU (nvidia/amd), OS (win11/win10/linux) and merges layered settings from run_presets.json (base → OS → console → GPU). Each layer records why it exists. Null env values unset earlier settings. Staging hard-links PE files (copies stand-in-named ones), maps the package via subst (not run.ps1 -MapDrive), disables thread holding (#1408), and hides the title window once presents reach the output window.
run_presets.json ships measured settings: RING_RELEASE_AT_SUBMIT, ROOT_SRV_AT_DRAW, TABLE_ALIAS, RUNTIME_LOCAL, PROBE_PRECHECK=0, etc. with cited evidence. GPU layers are documented with why fields.
Tests cover layer merging, null unsets, caller env recording, drive mapping (fake subst), staging (hard links, stand-in copies, synthetic package), validation (unknown keys, misspelt switches, non-X2W env names), and --print output.
Documentation in AGENTS.md and startup-runtime.md explains the workflow and maintenance rules.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T21:57:16Z.
Review: APPROVED
LGTM — clean launcher for shared real-run settings.
run_preset.py picks console (x/s), GPU (nvidia/amd), OS (win11/win10/linux) and merges layered settings from run_presets.json (base → OS → console → GPU). Each layer records why it exists. Null env values unset earlier settings. Staging hard-links PE files (copies stand-in-named ones), maps the package via subst (not run.ps1 -MapDrive), disables thread holding (#1408), and hides the title window once presents reach the output window.
run_presets.json ships measured settings: RING_RELEASE_AT_SUBMIT, ROOT_SRV_AT_DRAW, TABLE_ALIAS, RUNTIME_LOCAL, PROBE_PRECHECK=0, etc. with cited evidence. GPU layers are documented with why fields.
Tests cover layer merging, null unsets, caller env recording, drive mapping (fake subst), staging (hard links, stand-in copies, synthetic package), validation (unknown keys, misspelt switches, non-X2W env names), and --print output.
Documentation in AGENTS.md and startup-runtime.md explains the workflow and maintenance rules.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-29T00:09:53Z.
Not a blocker. On "lazy commit on Windows, because our runs with it crashed at about 190 to 250 s": do you still have one of those run folders?
triage_run.pyon it shows how it ended. If not, a lazy on/off pair on the same build would show whether lazy is the cause.What we saw: before #2209's fix (
c40e3dac), lazy-on runs stopped with access violations in the title's code at 315–430 s (3 of 3), while the lazy-off control ran 600 s. The cause was a block released while the fault handler was committing it. Since that fix, withX2W_XMEM_LAZY_COMMIT=1+X2W_XMEM_LAZY_STARTUP=1(Windows 10, 16 GB RAM, RTX 3080 Ti), 189 runs ran to their timeout (171 past 190 s), and none ended inxmem.dll.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T07:34:41Z.
Review: APPROVED
Re-reviewed at
30fdfe5eby the diff from4d1b42bd. This replaces my earlier review; both points are fixed.stage()copies a file named like one of the 8 stand-ins (any case) and links only the rest.STAND_INSis compared with the lists inrun.ps1andrun.sh. The check stages a package holdingGameInput.dllandXMEM.dll, rewrites the stand-ins in place over the stage and compares the package (bytes and mtime); the control withSTAND_INS = ()must change the package where links work.nullnow removes the caller's value (unset,child_env()), and callerX2W_*/WINE*values that reach the run are written tosettings.jsonasinherited_envand listed by--print.X2W_WIN_PYTHON,X2W_FXCandX2W_HOST_PYTHONare kept. Covered bychild_env()directly and by amain()run with the child start replaced.Minor, not blocking:
unexplained_gpu_differences()accepts a key withkey not in why, a plain substring test, so arunkey such asrenderorsecondspasses on anywhythat contains the word, andX2W_Apasses when thewhynamesX2W_AB.git merge-tree --write-treeontoorigin/main212d4b5f: clean.