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/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 26862777f5..1257142350 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,17 @@ 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 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, 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 " ". 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/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/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) 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 "