Skip to content
Merged
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
9 changes: 8 additions & 1 deletion d3d12/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,14 @@ still reaches.
cap, ray tracing, Smooth Motion, console profile, graphics card, and the
speed switches. Lines marked LIVE change at once; the others are saved to
`leonida-settings.txt` and apply at the next start, which "SAVE AND RESTART
NOW" does for you. F3 shows the numbers panel.
NOW" does for you. F3 shows the numbers panel. The last choice wins, one
setting at a time: a switch you type (`-Resolution`, `-SeriesS`,
`-Fullscreen` ...) wins over what the menu saved for the same setting, the
menu file drops that value, and the menu shows the command line's; every
setting you did not type keeps the menu's. "SAVE AND RESTART NOW" keeps the
menu's values, since they were chosen after the switches it starts with
again. Each start says which values came from the menu and which the command
line replaced.
- **DLSS frame generation** (NVIDIA Streamline), 2x to 6x, from the menu. The
amount changes while playing. Frames are only generated while the game's
window has the focus.
Expand Down
7 changes: 6 additions & 1 deletion d3d12/crates/leonida-gpu/src/host/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ const ITEMS: &[Item] = &[
Item { var: "LEONIDA_UPSCALE", label: "UPSCALER", values: &[("dlss", "DLSS"), ("stretch", "STRETCH"), ("", "GAME OWN (S: FSR SLOW)")], live: false },
// DLSS's mode is its render height: of the output's lines 2/3 (quality), 0.6 (balanced), 1/2 (performance), 1/3
// (ultra performance). Unset: Series S renders its own 2/3; the launcher gives Series X 2/3 with DLSS.
Item { var: "LEONIDA_RENDER_SCALE", label: "RENDER SCALE (DLSS MODE)", values: &[("", "GAME"), ("0.6667", "0.667 QUALITY"), ("0.6", "0.6 BALANCED"), ("0.5", "0.5 PERFORMANCE"), ("0.3333", "0.333 ULTRA PERF."), ("0.75", "0.75")], live: false },
// 1 is what -Resolution makes at the output's own height (1440 on Series X). On Series S it ended the title at
// its own breakpoint on the loading screen (2026-12-01, RTX 3060), hence the note.
Item { var: "LEONIDA_RENDER_SCALE", label: "RENDER SCALE (DLSS MODE)", values: &[("", "GAME"), ("0.6667", "0.667 QUALITY"), ("0.6", "0.6 BALANCED"), ("0.5", "0.5 PERFORMANCE"), ("0.3333", "0.333 ULTRA PERF."), ("0.75", "0.75"), ("1", "1 NATIVE (SERIES X)")], live: false },
// The lowest scale of the title's own dynamic resolution (-Lowest; the loader's hooks.rs): it picks the scale
// above it by itself. The render scale above wins over it when both are set.
Item { var: "LEONIDA_RENDER_SCALE_MIN", label: "LOWEST SCALE (DYNAMIC RES)", values: &[("", "GAME"), ("0.75", "0.75 (1080 OF 1440)"), ("0.6667", "0.667"), ("0.5", "0.5")], live: false },
// On Series X the launcher turns DLSS on with it: the generator's depth and motion vectors come from that upscale.
Item { var: "LEONIDA_FRAME_GEN", label: "FRAME GEN (NOT WITH RAY TR.)", values: &[("", "OFF"), ("2", "2X"), ("3", "3X"), ("4", "4X"), ("5", "5X"), ("6", "6X (MOST)")], live: false },
// Leonida: AMD's FSR 3 frame generation (crate::fsr), 2X, for cards without DLSS frame generation (RTX 20 and 30).
Expand Down
114 changes: 103 additions & 11 deletions d3d12/scripts/play-nvidia.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# nvidia-sdk\. Without them the game runs with its picture stretched to the screen instead.
# The layer is built here if it is not built yet, and built again with DLSS once those files are there.
# In the game: F1 = settings (arrows pick and change, Enter saves; kept in leonida-settings.txt next to this
# folder), F3 = the numbers panel.
# folder), F3 = the numbers panel. The last choice wins, one setting at a time: a switch typed for a start wins over
# the menu's saved value of what it sets (and the menu file drops that value); every other setting keeps the menu's.
# -NoSmoothMotion run target\<build>\leonida.exe itself. By default a copy named leonida_sm.exe is started instead,
# so a Smooth Motion profile set for that exe in the NVIDIA App applies every time.
# -NoDlss no DLSS: the picture is stretched (fast, softer)
Expand Down Expand Up @@ -89,7 +90,12 @@ param(
[hashtable]$More = @{},
[string]$PcGlyphs,
[uint32]$WindowsBarMB,
[switch]$DryRun
[switch]$DryRun,
# The switches the user typed, by this script's names, when another script starts this one with switches of its
# own (scripts\play-d3d12.ps1's Series X default): they win over the F1 menu's saved values. Unset: this start's.
[string[]]$Typed,
# Set by the F1 menu's SAVE AND RESTART: the switches are the last start's again, so the menu's values win.
[switch]$MenuRestart
)
$root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
if (-not (Test-Path $Exe)) { Write-Host "No $Exe."; return }
Expand Down Expand Up @@ -507,16 +513,98 @@ if ($PSBoundParameters.ContainsKey('WindowsBarMB')) {
}
}

# What the F1 menu saved (leonida-settings.txt, git-ignored), over the settings above. An empty value unsets one.
# What the F1 menu saved (leonida-settings.txt, git-ignored) and the command line: the user's last choice wins, one
# setting at a time. A setting a switch typed for this start makes (-Resolution, -SeriesS, -Fullscreen ...: $Typed,
# which scripts\play-d3d12.ps1 passes, else this start's own switches) was chosen now: it wins over the menu's, and
# the menu file drops that value, so F1 shows and saves the command line's. Every other setting keeps the menu's, which
# was chosen after the defaults. A start that the menu's SAVE AND RESTART made (-MenuRestart) replays the switches of
# the start before, so there the menu's values win: they were chosen after them. An empty value unsets a setting.
# -More wins over the menu like a typed switch.
function Read-SettingsFile([string]$path) {
$read = [ordered]@{}
if (Test-Path $path) {
foreach ($line in Get-Content $path) {
if ($line -match '^\s*(LEONIDA_[A-Z0-9_]+)\s*=(.*)$') { $read[$Matches[1]] = $Matches[2].Trim() }
}
}
$read
}
# The settings each switch makes; a switch not listed makes none the menu holds.
$switchSettings = @{
SeriesX = 'LEONIDA_MENU_CONSOLE'
NoSmoothMotion = 'LEONIDA_MENU_SMOOTH_MOTION'
Resolution = 'LEONIDA_RENDER_SCALE', 'LEONIDA_RENDER_SCALE_MIN', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_UPSCALE', 'LEONIDA_FSR_UPSCALER', 'LEONIDA_OUTPUT'
Lowest = 'LEONIDA_RENDER_SCALE', 'LEONIDA_RENDER_SCALE_MIN', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_UPSCALE', 'LEONIDA_FSR_UPSCALER', 'LEONIDA_OUTPUT'
Dlss = 'LEONIDA_RENDER_SCALE', 'LEONIDA_RENDER_SCALE_MIN', 'LEONIDA_UPSCALE', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_FSR_UPSCALER', 'LEONIDA_OUTPUT'
NoDlss = 'LEONIDA_UPSCALE'
# DLSS's and FSR 3's frame generation are one choice (never both, below): a typed one replaces the menu's other.
FrameGen = 'LEONIDA_FRAME_GEN', 'LEONIDA_FSR_FRAMEGEN'
NoFrameGen = 'LEONIDA_FRAME_GEN'
FsrFrameGen = 'LEONIDA_FSR_FRAMEGEN', 'LEONIDA_FRAME_GEN'
Fullscreen = 'LEONIDA_FULLSCREEN'
Aspect = 'LEONIDA_ASPECT'
PresentScale = 'LEONIDA_PRESENT_SCALE'
Adapter = 'LEONIDA_ADAPTER'
RayTracing = 'LEONIDA_BVH_BUILDER', 'LEONIDA_AMBIENT'
Quality = 'LEONIDA_RELAY', 'LEONIDA_CARD_STEPS'
}
$typedNames = if ($PSBoundParameters.ContainsKey('Typed')) { @($Typed) } else { @($PSBoundParameters.Keys) }
$chosenNow = @{}
if (-not $MenuRestart) {
foreach ($name in $typedNames) {
# -SeriesS reaches this script as the console's switch, SeriesX.
# play-d3d12.ps1's -SeriesS and -SmoothMotion reach this script as SeriesX and NoSmoothMotion.
$said = switch ($name) {
'SeriesX' { '-SeriesS/-SeriesX' }
'NoSmoothMotion' { '-SmoothMotion/-NoSmoothMotion' }
default { "-$name" }
}
foreach ($k in @($switchSettings[$name])) { if ($k) { $chosenNow[$k] = $said } }
}
foreach ($k in $More.Keys) { $chosenNow[$k] = '-More' }
}
$menuFile = Join-Path $root 'leonida-settings.txt'
$smooth = -not $NoSmoothMotion
if (Test-Path $menuFile) {
foreach ($line in Get-Content $menuFile) {
if ($line -notmatch '^\s*(LEONIDA_[A-Z0-9_]+)\s*=(.*)$') { continue }
$k = $Matches[1]; $v = $Matches[2].Trim()
if ($k -eq 'LEONIDA_MENU_SMOOTH_MOTION') { $smooth = $v -ne '0'; continue }
if ($k -eq 'LEONIDA_MENU_CONSOLE') { if ($v) { $console = $v }; continue }
if ($v) { $settings[$k] = $v } else { $settings.Remove($k) }
# The menu's console and Smooth Motion lines stand for $console and $smooth here.
$fromLine = @{} + $settings
$fromLine.LEONIDA_MENU_CONSOLE = $console
$fromLine.LEONIDA_MENU_SMOOTH_MOTION = if ($smooth) { '1' } else { '0' }
# -More is applied over the settings below; its values are what replaces the menu's.
foreach ($k in $More.Keys) { $fromLine[$k] = "$($More[$k])" }
$menu = Read-SettingsFile $menuFile
$menuRead = $menu.Count
$fromMenu = @(); $replaced = @()
foreach ($k in @($menu.Keys)) {
$v = $menu[$k]
if ($chosenNow.ContainsKey($k)) {
$now = "$($fromLine[$k])"
if ($now -ne $v) { $replaced += "$k $(if ($v) { $v } else { '(unset)' }) -> $(if ($now) { $now } else { '(unset)' }) ($($chosenNow[$k]))" }
$menu.Remove($k)
continue
}
$fromMenu += "$k=$(if ($v) { $v } else { '(unset)' })"
if ($k -eq 'LEONIDA_MENU_SMOOTH_MOTION') { $smooth = $v -ne '0'; continue }
if ($k -eq 'LEONIDA_MENU_CONSOLE') { if ($v) { $console = $v }; continue }
if ($v) { $settings[$k] = $v } else { $settings.Remove($k) }
}
if ($fromMenu) { Write-Host "F1 menu settings (leonida-settings.txt, for what the command line did not set): $($fromMenu -join ', ')" }
if ($replaced) { Write-Host "Command line over the F1 menu's saved values: $($replaced -join ', ')" }
# The menu file keeps the rest as it was; a value the command line set leaves it. If the file cannot be written, this
# start still runs with the command line's values and the file stays whole, so nothing saved is lost.
if (-not $DryRun -and $menu.Count -ne $menuRead) {
$tmp = "$menuFile.tmp"
$wrote = $false
try {
# CRLF, as the menu writes the file (host/menu.rs).
$text = "# Saved by the F1 menu; play.ps1 applies these after its own settings (an empty value: unset).`r`n" +
(($menu.Keys | ForEach-Object { "$_=$($menu[$_])`r`n" }) -join '')
[IO.File]::WriteAllText($tmp, $text, [Text.UTF8Encoding]::new($false))
$wrote = $true
Move-Item -LiteralPath $tmp -Destination $menuFile -Force -ErrorAction Stop
} catch {
# Only the file this start wrote goes: whatever stood at that name before is left alone.
if ($wrote) { Remove-Item -LiteralPath $tmp -ErrorAction SilentlyContinue }
Write-Host "The F1 menu file was not updated ($($_.Exception.Message)): this start runs with the command line's values, and the file keeps the menu's."
}
}
# Leonida: the runs write down the pipelines the title creates (pipeline/known.rs), for the precompile below.
Expand Down Expand Up @@ -591,13 +679,17 @@ $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', 'SeriesX', 'Quality', 'RayTracing', 'FsrFrameGen', 'NoPrecompile', 'Log', 'Capture', 'Fullscreen') {
foreach ($s in 'NoSmoothMotion', 'MotionBlur', 'NoDlss', 'NoFrameGen', 'SeriesX', 'Quality', 'RayTracing', 'FsrFrameGen', 'NoPrecompile', 'Log', 'Capture', 'Fullscreen') {
if ($PSBoundParameters[$s]) { $again += "-$s" }
}
foreach ($s in 'Resolution', 'Lowest', 'Dlss', 'FrameGen', 'Aspect', 'PresentScale', 'Adapter', 'DlssDir', 'StreamlineDir', 'FidelityFxDir') {
if ($PSBoundParameters[$s]) { $again += "-$s '$($PSBoundParameters[$s] -replace "'", "''")'" }
}
if ($PSBoundParameters.ContainsKey('WindowsBarMB')) { $again += "-WindowsBarMB $WindowsBarMB" }
# The menu's SAVE AND RESTART starts this script again with these switches, the ones this start was given (not the
# settings they made), and -MenuRestart: the menu's values, saved after these switches were typed, win over them there
# (see "What the F1 menu saved" above). Without it a typed -Resolution would undo the scale the menu had just saved.
$again += '-MenuRestart'
$settings.LEONIDA_MENU_ARGS = $again -join ' '

$scaled = if ($settings.LEONIDA_RENDER_SCALE) { " from render scale $($settings.LEONIDA_RENDER_SCALE)" } else { '' }
Expand Down
5 changes: 4 additions & 1 deletion docs/mod-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ The cap, the sharpness, the panel and the recorder are the renderer's own settin
(`knobs::Owned`). The first three are in the F1 menu too: the two menus change the same thing, and each shows what
the other set (the F1 menu reads its live settings again when it opens; the trainer looks twice a second while
open). The F1 menu saves to `leonida-settings.txt`; what the trainer changes lasts for the run unless the F1 menu
is opened afterwards and saves it.
is opened afterwards and saves it. At the next start the launcher applies the saved settings, except those a switch
typed for that start sets (`-Resolution`, `-SeriesS` ...): those take the command line's value and leave the menu
file, so the last choice wins either way. The menu's SAVE AND RESTART passes `-MenuRestart` with the switches it
replays, and there the menu's values win.

Game speed is experimental and not verified in game: the runtime serves the title's `QueryPerformanceCounter`
import (from `api-ms-win-core-profile-l1-1-0.dll`) and scales it continuously, so the title's time never jumps.
Expand Down
5 changes: 5 additions & 0 deletions scripts/play-d3d12.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ if ($Resolution) { $launch.Resolution = $Resolution }
if ($Lowest) { $launch.Lowest = $Lowest }
if ($Adapter) { $launch.Adapter = $Adapter }
if ($PcGlyphs) { $launch.PcGlyphs = (Resolve-Path $PcGlyphs).Path }
# The switches typed here, by play-nvidia.ps1's names: those win over the F1 menu's saved values, while the Series X
# default and its -Lowest 1080 above, which nobody typed, leave the menu's choice standing.
$launch.Typed = @($PSBoundParameters.Keys | ForEach-Object {
switch ($_) { 'SeriesS' { 'SeriesX' } 'SmoothMotion' { 'NoSmoothMotion' } default { $_ } }
})
& (Join-Path $runtime "scripts\play-nvidia.ps1") @launch
Loading
Loading