From c6f253705d81fbd0326cf2da816dc34d5637ee21 Mon Sep 17 00:00:00 2001 From: TheStonedGamer Date: Tue, 1 Dec 2026 15:53:59 -0500 Subject: [PATCH 1/3] Launcher: option to precompile every known pipeline (-PrecompileAll) The precompile makes only the pipelines earlier runs drew with (warm --used). -PrecompileAll (launcher: "Precompile every pipeline", off by default) makes every pipeline the title has created, as foxhound's launcher does: fewer stalls in places not drawn in yet, at the cost of an hour or more and gigabytes the first time. Kept across the F1 menu's restart. Co-Authored-By: Claude Opus 5.5 --- d3d12/scripts/play-nvidia.ps1 | 12 ++++++++++-- scripts/play-d3d12.ps1 | 5 ++++- tools/leonida_launcher.py | 10 +++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index 26862777f5..4b4f351e14 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -52,6 +52,8 @@ # pipelines earlier runs drew with are made before the title starts (minutes the first time # and after a change of the layer, seconds otherwise), so that the world does not come up # half drawn or stall while they are made. +# -PrecompileAll every pipeline the title has created in earlier runs, not only those drawn with (as foxhound's +# launcher): fewer stalls in new places; an hour or more and gigabytes the first time. # -Log the layer's log goes to a file in %LOCALAPPDATA%\Leonida\logs instead of this window # -Capture F9 in the game saves that frame and the pictures it drew, in %LOCALAPPDATA%\Leonida\captures # -WindowsBarMB maximum MiB of title memory windows in CPU-mapped VRAM, which needs resizable BAR (by default @@ -85,6 +87,7 @@ param( [string]$DlssDir, [string]$StreamlineDir, [switch]$NoPrecompile, + [switch]$PrecompileAll, [switch]$Log, [switch]$Capture, [hashtable]$More = @{}, @@ -690,7 +693,7 @@ $settings.LEONIDA_MENU_CONSOLE = $console $settings.LEONIDA_MENU_FILE = $menuFile $settings.LEONIDA_MENU_PLAY = $MyInvocation.MyCommand.Path $again = @("-Exe '$($Exe -replace "'", "''")'", "-Build $Build") -foreach ($s in 'NoSmoothMotion', 'MotionBlur', 'NoDlss', 'NoFrameGen', 'SeriesX', 'Quality', 'RayTracing', 'FsrFrameGen', 'NoPrecompile', 'Log', 'Capture', 'Fullscreen') { +foreach ($s in 'NoSmoothMotion', 'MotionBlur', 'NoDlss', 'NoFrameGen', 'SeriesX', 'Quality', 'RayTracing', 'FsrFrameGen', 'NoPrecompile', 'PrecompileAll', 'Log', 'Capture', 'Fullscreen') { if ($PSBoundParameters[$s]) { $again += "-$s" } } foreach ($s in 'Resolution', 'Lowest', 'Dlss', 'FrameGen', 'Aspect', 'PresentScale', 'Adapter', 'DlssDir', 'StreamlineDir', 'FidelityFxDir') { @@ -870,7 +873,12 @@ if (-not $NoPrecompile) { } $pipelineDir = if ($cacheRoot) { Join-Path $cacheRoot 'pipelines' } else { $null } $dxNoted = if ($pipelineDir) { Join-Path $pipelineDir 'driver-cache-files.txt' } else { $null } - $warmArgs = @('warm', '--used') + # Leonida: -PrecompileAll makes every pipeline the title has created in any earlier run + # (known-pipelines.bin), as foxhound's launcher does, not only those drawn with: places and effects not yet + # drawn in then have theirs ready too. Some 88,000 against 4,000: long the first time, and gigabytes. + $warmArgs = @('warm') + if (-not $PrecompileAll) { $warmArgs += '--used' } + else { Write-Host ' -PrecompileAll: every pipeline the title has created (long the first time).' } $gone = @() if ($dxNoted -and (Test-Path $dxNoted)) { # Lines are "" (older launchers) or " ". diff --git a/scripts/play-d3d12.ps1 b/scripts/play-d3d12.ps1 index caaa53736a..37e28a7466 100644 --- a/scripts/play-d3d12.ps1 +++ b/scripts/play-d3d12.ps1 @@ -37,6 +37,8 @@ # -Capture F9 in the game saves that frame and the pictures it drew # -NoPrecompile start at once: by default every shader is translated and the pipelines earlier runs drew with are # made before the title starts (minutes the first time, seconds after) +# -PrecompileAll every pipeline the title has created in earlier runs, not only those drawn with (as foxhound): +# fewer stalls in new places; an hour or more and gigabytes the first time # -Log the runtime's log goes to a file under %LOCALAPPDATA%\Leonida\logs # -DryRun prints the settings this start would run with and stops: nothing is built or started # -PcGlyphs a folder of your own pictures for the keyboard-and-mouse button prompts instead of the built-in key @@ -70,6 +72,7 @@ param( [switch]$RayTracing, [switch]$Capture, [switch]$NoPrecompile, + [switch]$PrecompileAll, [switch]$Log, [switch]$DryRun, [string]$PcGlyphs = '' @@ -105,7 +108,7 @@ if ($Dlss) { $launch.Dlss = $Dlss } if ($FrameGen) { $launch.FrameGen = $FrameGen } if ($Aspect) { $launch.Aspect = $Aspect } if ($PresentScale) { $launch.PresentScale = $PresentScale } -foreach ($switch in 'Quality', 'NoDlss', 'NoFrameGen', 'MotionBlur', 'RayTracing', 'Capture', 'NoPrecompile', 'Log', 'DryRun', 'FsrFrameGen', 'Fullscreen') { +foreach ($switch in 'Quality', 'NoDlss', 'NoFrameGen', 'MotionBlur', 'RayTracing', 'Capture', 'NoPrecompile', 'PrecompileAll', 'Log', 'DryRun', 'FsrFrameGen', 'Fullscreen') { if ($PSBoundParameters[$switch]) { $launch[$switch] = $true } } if ($Resolution) { $launch.Resolution = $Resolution } diff --git a/tools/leonida_launcher.py b/tools/leonida_launcher.py index 67944f9b81..7937fad4d7 100644 --- a/tools/leonida_launcher.py +++ b/tools/leonida_launcher.py @@ -47,6 +47,7 @@ "ray_tracing": False, # -RayTracing "smooth_motion": False, # -SmoothMotion "precompile": True, # off = -NoPrecompile + "precompile_all": False, # -PrecompileAll "series_x": False, # -SeriesX "quality": False, # -Quality "resolution": "", # -Resolution , empty = the default path @@ -143,6 +144,8 @@ def switch_args(settings: dict) -> list[str]: args.append("-SmoothMotion") if not settings["precompile"]: args.append("-NoPrecompile") + elif settings["precompile_all"]: + args.append("-PrecompileAll") if settings["series_x"] and not settings["series_s"]: args.append("-SeriesX") if settings["quality"]: @@ -683,17 +686,18 @@ def build_settings(self): ("series_x", "Series X profile (-SeriesX, much slower)"), ("quality", "Quality (-Quality, slower)"), ("capture", "Capture: F9 saves a frame (-Capture)"), - ("log", "Log to a file (-Log)")) + ("log", "Log to a file (-Log)"), + ("precompile_all", "Precompile every pipeline (-PrecompileAll, very long the first time)")) for index, (key, text) in enumerate(checks): var = tk.BooleanVar(value=self.settings[key]) self.vars[key] = var ttk.Checkbutton(options, text=text, variable=var).grid(row=index // 2, column=index % 2, sticky="w", pady=3) - ttk.Label(options, text="Resolution (-Resolution)").grid(row=4, column=0, sticky="w", pady=(10, 0)) + ttk.Label(options, text="Resolution (-Resolution)").grid(row=5, column=0, sticky="w", pady=(10, 0)) res = tk.StringVar(value=self.settings["resolution"] or "default") self.vars["resolution"] = res ttk.Combobox(options, textvariable=res, state="readonly", width=12, - values=["default"] + [r for r in RESOLUTIONS if r]).grid(row=4, column=1, sticky="w", + values=["default"] + [r for r in RESOLUTIONS if r]).grid(row=5, column=1, sticky="w", pady=(10, 0)) if not WINDOWS: ttk.Label(inner, text="On Linux the launcher starts scripts/play-linux.sh, which takes the " From 32f0fe3ad9a052cefe30b10f37f13a6a661d91f7 Mon Sep 17 00:00:00 2001 From: TheStonedGamer Date: Tue, 1 Dec 2026 17:23:49 -0500 Subject: [PATCH 2/3] leonida warm: only pipelines drawn with go into the pipeline library With -PrecompileAll every known pipeline is made (some 88,000 against 4,000 drawn with). Those never drawn with now stay in the driver's cache alone and are kept out of the pipeline library: the driver checks an entry of its own cache against the pipeline asked for and compiles again where they differ, while a library entry is taken as it was stored. With them in the library (1.5 GB, 91,525 entries) the device was removed twice during a burst of first loads in a new place (RTX 3060, driver 621.40): no hang, no page fault, the library file whole. With them kept out, a run of the same settings stayed up. The cause inside the driver is not known. The rule is into_library(), with a unit test that fails without it. Co-Authored-By: Claude Opus 5.5 --- d3d12/apps/leonida/src/warm.rs | 38 ++++++++++++++++++++++++++++++++-- d3d12/scripts/play-nvidia.ps1 | 9 ++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/d3d12/apps/leonida/src/warm.rs b/d3d12/apps/leonida/src/warm.rs index b07789148b..5954e2cfc9 100644 --- a/d3d12/apps/leonida/src/warm.rs +++ b/d3d12/apps/leonida/src/warm.rs @@ -150,15 +150,28 @@ pub fn run(jobs: Option, limit: Option, again: bool, used: bool, t .filter(|&n| { let key = keys[n].as_str(); let (made, kept) = (made_now.contains(key), in_library.contains(key)); - (made || kept) && (again || !(made && kept)) && !bad.contains(key) && (!used || early.contains(key)) + into_library(made, kept, again, bad.contains(key), early.contains(key)) }) .collect(); - todo.sort_by_key(|&n| (!early.contains(keys[n].as_str()), &keys[n])); + todo.sort_by_key(|&n| &keys[n]); todo.truncate(limit.unwrap_or(usize::MAX)); store_in_library(&dir, &fingerprint, &mark, &keys, &todo); Ok(()) } +/// Leonida: whether a pipeline goes through the library step: made here or kept there, not both unless `again` +/// (the driver's cache was emptied), not one that failed, and only one an earlier run drew with +/// (`early-pipelines.txt`), also when every known one was made above (without `--used`, -PrecompileAll). +/// Those never drawn with stay in the driver's cache alone: the driver checks an entry of its own cache +/// against the pipeline asked for and compiles again where they differ, while a library entry is taken as it +/// was stored. With some 85,000 never-drawn pipelines put in the library, the device was removed (no hang, +/// no page fault, the library file whole) during a burst of their first loads in a new place, twice (RTX 3060, +/// driver 621.40, 2026-12-01); with them kept out, a run of the same settings stayed up. The cause inside +/// the driver is not known. +fn into_library(made: bool, kept: bool, again: bool, bad: bool, early: bool) -> bool { + (made || kept) && (again || !(made && kept)) && !bad && early +} + /// Leonida: what `warm-done.txt` notes pipelines made by: the translation's fingerprint, with the /// executable's name after it where that is not `leonida` (the driver's cache on disk is the name's; /// the launcher's Smooth Motion copy runs as `leonida_sm.exe`). `leonida.exe` keeps the bare @@ -411,3 +424,24 @@ fn make(dir: &Path, these: &str) -> Result<()> { let _ = out.flush(); std::process::exit(0) } + +#[cfg(test)] +mod tests { + use super::into_library; + + #[test] + fn only_pipelines_drawn_with_go_into_the_library() { + // Made here, drawn with in an earlier run: stored. + assert!(into_library(true, false, false, false, true)); + // Made here by -PrecompileAll, never drawn with: the driver's cache only. + assert!(!into_library(true, false, false, false, false)); + assert!(!into_library(true, false, true, false, false)); + // Already in the library and made here: nothing to do unless the driver's cache was emptied. + assert!(!into_library(true, true, false, false, true)); + assert!(into_library(true, true, true, false, true)); + // One that failed before is left out. + assert!(!into_library(true, false, false, true, true)); + // Neither made nor kept: nothing to store. + assert!(!into_library(false, false, true, false, true)); + } +} diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index 4b4f351e14..1257142350 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -875,10 +875,15 @@ if (-not $NoPrecompile) { $dxNoted = if ($pipelineDir) { Join-Path $pipelineDir 'driver-cache-files.txt' } else { $null } # Leonida: -PrecompileAll makes every pipeline the title has created in any earlier run # (known-pipelines.bin), as foxhound's launcher does, not only those drawn with: places and effects not yet - # drawn in then have theirs ready too. Some 88,000 against 4,000: long the first time, and gigabytes. + # drawn in then find theirs in the driver's cache instead of compiling while the game waits. Those never drawn + # with go into the driver's cache only, not the pipeline library (warm.rs). Some 88,000 against 4,000: an hour + # or more the first time, and more than the driver's default 4 GB cache (the warning below). $warmArgs = @('warm') if (-not $PrecompileAll) { $warmArgs += '--used' } - else { Write-Host ' -PrecompileAll: every pipeline the title has created (long the first time).' } + else { + Write-Host ' -PrecompileAll: every pipeline the title has created, into the driver''s cache. An hour or more the' + Write-Host ' first time; set NVIDIA''s Shader Cache Size to Unlimited, or what does not fit is compiled in the game.' + } $gone = @() if ($dxNoted -and (Test-Path $dxNoted)) { # Lines are "" (older launchers) or " ". From afe0b798f453e7c707f5177275be1b72f862a3a5 Mon Sep 17 00:00:00 2001 From: TheStonedGamer Date: Tue, 1 Dec 2026 17:28:47 -0500 Subject: [PATCH 3/3] Launcher tests and docs for -PrecompileAll - tests: -PrecompileAll is among the switches checked against play-d3d12.ps1, and it is passed only with the precompile on. - README.md, docs/launcher.md, d3d12/README.md: the switch. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + d3d12/README.md | 4 +++- docs/launcher.md | 2 +- tests/test_leonida_launcher.py | 9 ++++++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0ab58ddfe1..a6303bd72c 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ Useful switches of `scripts\play-d3d12.ps1` (the launcher's Settings page has th | `-SeriesS` | the lighter Series S profile (720p rendered, DLSS to 1080p) | | `-RayTracing` | the game's real ray tracing: slower, shaders build for minutes the first time, not with frame generation | | `-NoPrecompile` | start at once, without translating the shaders first | +| `-PrecompileAll` | before the start, compile every pipeline the game has created in earlier runs into the driver's cache, not only those drawn with (an hour or more the first time; set NVIDIA's Shader Cache Size to Unlimited) | | `-Capture` | F9 in the game saves that frame | | `-Log` | the runtime's log goes to `%LOCALAPPDATA%\Leonida\logs` | | `-DryRun` | print the settings a start would use, and stop | diff --git a/d3d12/README.md b/d3d12/README.md index d730b36e59..6ab9b83d16 100644 --- a/d3d12/README.md +++ b/d3d12/README.md @@ -69,7 +69,9 @@ measurements and what is still wrong in the picture are in the [top-level README ## Shaders and pipelines are made before the title starts `scripts/play-d3d12.ps1` (through `d3d12/scripts/play-nvidia.ps1`) precompiles before it starts the title, as -Hookshot's release builds do; `-NoPrecompile` skips it. +Hookshot's release builds do; `-NoPrecompile` skips it. `-PrecompileAll` makes every pipeline the title has created in +earlier runs, not only those drawn with; those never drawn with go into the driver's cache only, not the pipeline +library. 1. `leonida shaders ` translates every shader into the cache with the settings of this start. That takes minutes the first time and after a change of the translator or of a setting a translation diff --git a/docs/launcher.md b/docs/launcher.md index d58929f72c..238983db86 100644 --- a/docs/launcher.md +++ b/docs/launcher.md @@ -23,7 +23,7 @@ Standard library only (`tools/leonida_launcher.py`). confirmation, ends the process and everything it started (`taskkill /T /F`; on Linux the process group). - **Settings**: the game folder (a picker, and a check that `game_scarlett_master.exe` is in it), the data folder (empty = the script's default), the mods folder, and the options of `play-d3d12.ps1`: DLSS (off is `-NoDlss`), - `-RayTracing`, `-SmoothMotion`, shader preparation (off is `-NoPrecompile`), `-SeriesX`, `-Quality`, `-Resolution` + `-RayTracing`, `-SmoothMotion`, shader preparation (off is `-NoPrecompile`), precompiling every pipeline (`-PrecompileAll`), `-SeriesX`, `-Quality`, `-Resolution` (default = none), `-Capture`, `-Log`. On Linux only the game folder and Series X are used. - **Mods**: the `mods\*\mod.json` of the mods folder (this repository's `mods` unless changed), with the enabled flag written back as the mod manager does it (`tools/leonida_mods.py`); a button opens that manager. diff --git a/tests/test_leonida_launcher.py b/tests/test_leonida_launcher.py index 4317cd5998..82c4d5d8b7 100644 --- a/tests/test_leonida_launcher.py +++ b/tests/test_leonida_launcher.py @@ -99,13 +99,20 @@ def test_switches_exist_in_the_script(self): every = settings(dlss=False, ray_tracing=True, smooth_motion=True, precompile=False, series_x=True, quality=True, resolution="720", capture=True, log=True, aspect="32:9", present_scale="fit", adapter="#1", frame_gen=2) - newer = settings(series_s=True, dlss_mode="quality") + newer = settings(series_s=True, dlss_mode="quality", precompile_all=True) for arg in launcher.switch_args(every) + launcher.switch_args(newer): if arg.startswith("-") and arg[1:].isalpha(): self.assertIn("$" + arg[1:], text, arg) self.assertIn("$Game", text) self.assertIn("$Data", text) + def test_precompile_all_only_with_the_precompile(self): + self.assertIn("-PrecompileAll", launcher.switch_args(settings(precompile_all=True))) + off = launcher.switch_args(settings(precompile=False, precompile_all=True)) + self.assertIn("-NoPrecompile", off) + self.assertNotIn("-PrecompileAll", off) + self.assertNotIn("-PrecompileAll", launcher.switch_args(settings())) + def test_linux_command(self): command = launcher.play_command(settings(game_dir="/g", series_x=True, dlss=False), repo="/r", windows=False)