Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 3 additions & 1 deletion d3d12/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <the title's shaders.rpf>` 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
Expand Down
38 changes: 36 additions & 2 deletions d3d12/apps/leonida/src/warm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,28 @@ pub fn run(jobs: Option<usize>, limit: Option<usize>, 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
Expand Down Expand Up @@ -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));
}
}
17 changes: 15 additions & 2 deletions d3d12/scripts/play-nvidia.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,6 +87,7 @@ param(
[string]$DlssDir,
[string]$StreamlineDir,
[switch]$NoPrecompile,
[switch]$PrecompileAll,
[switch]$Log,
[switch]$Capture,
[hashtable]$More = @{},
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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 "<file>" (older launchers) or "<file> <bytes>".
Expand Down
2 changes: 1 addition & 1 deletion docs/launcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion scripts/play-d3d12.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,6 +72,7 @@ param(
[switch]$RayTracing,
[switch]$Capture,
[switch]$NoPrecompile,
[switch]$PrecompileAll,
[switch]$Log,
[switch]$DryRun,
[string]$PcGlyphs = ''
Expand Down Expand Up @@ -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 }
Expand Down
9 changes: 8 additions & 1 deletion tests/test_leonida_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions tools/leonida_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <height>, empty = the default path
Expand Down Expand Up @@ -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"]:
Expand Down Expand Up @@ -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 "
Expand Down