From c8eea9466f75795940da3f537d8122afd9f4b4b7 Mon Sep 17 00:00:00 2001 From: Alfredo Peres Date: Tue, 1 Dec 2026 10:53:26 -0300 Subject: [PATCH 1/4] d3d12: the last choice wins between the command line and the F1 menu (D3D12-MENU-LAST-CHOICE-WINS) play-nvidia.ps1 applied leonida-settings.txt (what F1 saved) over the command line at every start. An empty value there removed what the command line set, so a later -Resolution, -Dlss or -SeriesS was lost without a word. Now leonida-launch.txt (git-ignored) keeps what the last start's command line made: - A setting this command line makes otherwise than that start's did wins. The menu file drops its value, so F1 shows and saves the new one. - A setting it makes as before keeps the menu's value, the newer choice. - Each start says which values came from the menu and which the command line replaced. - A dry run writes neither file. The F1 menu gets the native render scale (1, which -Resolution makes at the output's height) and the dynamic resolution's lowest scale (LEONIDA_RENDER_SCALE_MIN, from -Lowest). Co-Authored-By: Claude Opus 5.5 --- d3d12/.gitignore | 1 + d3d12/README.md | 6 +- d3d12/crates/leonida-gpu/src/host/menu.rs | 7 +- d3d12/scripts/play-nvidia.ps1 | 57 ++++++++-- docs/mod-menu.md | 4 +- tests/test_play_nvidia_menu_choice.py | 124 ++++++++++++++++++++++ 6 files changed, 187 insertions(+), 12 deletions(-) create mode 100644 tests/test_play_nvidia_menu_choice.py diff --git a/d3d12/.gitignore b/d3d12/.gitignore index 621ffa2551..3780e34803 100644 --- a/d3d12/.gitignore +++ b/d3d12/.gitignore @@ -82,3 +82,4 @@ Thumbs.db /nvidia-sdk/ # What the F1 menu saved /leonida-settings.txt +/leonida-launch.txt diff --git a/d3d12/README.md b/d3d12/README.md index 7f149eae5e..8f749399b0 100644 --- a/d3d12/README.md +++ b/d3d12/README.md @@ -330,7 +330,11 @@ 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 setting you change on the command line after saving it + in the menu takes the command line's value, the menu file drops its own, and + the menu shows the new one; settings the command line leaves as they were + keep the menu's. Each start says which came from the menu. - **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. diff --git a/d3d12/crates/leonida-gpu/src/host/menu.rs b/d3d12/crates/leonida-gpu/src/host/menu.rs index b8f63af88f..b60bae46db 100644 --- a/d3d12/crates/leonida-gpu/src/host/menu.rs +++ b/d3d12/crates/leonida-gpu/src/host/menu.rs @@ -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). diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index 298e9f6b98..a005f5c7e7 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -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 setting this command line changes +# since the last start wins over the menu's saved one (leonida-launch.txt keeps the last start's), the others keep it. # -NoSmoothMotion run target\\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) @@ -507,17 +508,55 @@ 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 settings above: the user's last choice wins, one +# setting at a time. leonida-launch.txt (git-ignored, beside it) keeps what the last start's command line made. A +# setting this command line makes otherwise than that start's did was chosen now: it wins, and the menu file drops its +# value, so F1 shows and saves this one. A setting the command line makes as before keeps the menu's value, the newer +# choice. With no leonida-launch.txt yet (the first start with this launcher) the menu's values win, as before. An +# empty value unsets a setting. -More still wins over both. +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 +} +function Write-SettingsFile([string]$path, [string]$header, $values) { + # CRLF, as the menu writes the file (host/menu.rs). + $text = "# $header`r`n" + (($values.Keys | ForEach-Object { "$_=$($values[$_])`r`n" }) -join '') + [IO.File]::WriteAllText($path, $text, [Text.UTF8Encoding]::new($false)) +} $menuFile = Join-Path $root 'leonida-settings.txt' +$lastFile = Join-Path $root 'leonida-launch.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' } +$menu = Read-SettingsFile $menuFile +$last = if (Test-Path $lastFile) { Read-SettingsFile $lastFile } else { $null } +$fromMenu = @(); $replaced = @() +foreach ($k in @($menu.Keys)) { + $v = $menu[$k]; $now = "$($fromLine[$k])" + if ($null -ne $last -and "$($last[$k])" -ne $now) { + $replaced += "$k $(if ($v) { $v } else { '(unset)' }) -> $(if ($now) { $now } else { '(unset)' })" + $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, newer than the command line): $($fromMenu -join ', ')" } +if ($replaced) { Write-Host "Command line over the F1 menu's (changed since the last start): $($replaced -join ', ')" } +if (-not $DryRun) { + if ($replaced) { Write-SettingsFile $menuFile 'Saved by the F1 menu; play.ps1 applies these after its own settings (an empty value: unset).' $menu } + $lines = [ordered]@{} + foreach ($k in $fromLine.Keys | Sort-Object) { $lines[$k] = $fromLine[$k] } + Write-SettingsFile $lastFile 'What the last start''s command line made (play-nvidia.ps1): a setting it makes otherwise next time wins over the F1 menu''s.' $lines } # Leonida: the runs write down the pipelines the title creates (pipeline/known.rs), for the precompile below. if (-not $NoPrecompile) { $settings.LEONIDA_PIPELINE_BOOK = '1' } diff --git a/docs/mod-menu.md b/docs/mod-menu.md index 9ac70e56f0..ab5c4b9ba8 100644 --- a/docs/mod-menu.md +++ b/docs/mod-menu.md @@ -119,7 +119,9 @@ 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 one the command +line changed since the start before (`leonida-launch.txt` keeps what that start's command line made): that one takes +the command line's value and leaves the menu file, so the last choice wins either way. 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. diff --git a/tests/test_play_nvidia_menu_choice.py b/tests/test_play_nvidia_menu_choice.py new file mode 100644 index 0000000000..4393aa1063 --- /dev/null +++ b/tests/test_play_nvidia_menu_choice.py @@ -0,0 +1,124 @@ +"""d3d12/scripts/play-nvidia.ps1: the F1 menu's saved settings and the command line, the user's last choice winning +one setting at a time (D3D12-MENU-LAST-CHOICE-WINS). The launcher's block is run alone in Windows PowerShell with +the settings a command line made, against a menu file and a last-start file in a temporary folder.""" + +import json +import os +import subprocess +import tempfile +import unittest +from pathlib import Path + +SCRIPT = Path(__file__).resolve().parents[1] / "d3d12" / "scripts" / "play-nvidia.ps1" +BEGIN = "# What the F1 menu saved (leonida-settings.txt" +END = "# Leonida: the runs write down the pipelines" + + +def block() -> str: + text = SCRIPT.read_text(encoding="utf-8-sig") + return text[text.index(BEGIN):text.index(END)] + + +@unittest.skipUnless(os.name == "nt", "Windows PowerShell launcher") +class MenuChoiceTests(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.root = Path(self.tmp.name) + self.menu = self.root / "leonida-settings.txt" + self.last = self.root / "leonida-launch.txt" + + def tearDown(self): + self.tmp.cleanup() + + def start(self, line: dict, console: str = "series-s", dry: bool = False) -> dict: + """One start: `line` is what the command line made; returns what the start runs with.""" + pairs = "; ".join(f"'{k}' = '{v}'" for k, v in line.items()) + driver = self.root / "driver.ps1" + driver.write_text( + "$ErrorActionPreference = 'Stop'\n" + f"$root = '{self.root}'\n" + f"$settings = @{{ {pairs} }}\n" + f"$console = '{console}'\n" + "$NoSmoothMotion = $true\n" + f"$DryRun = ${'true' if dry else 'false'}\n" + + block() + + "\n[pscustomobject]@{ settings = $settings; console = $console; smooth = $smooth } | ConvertTo-Json -Compress\n", + encoding="utf-8-sig", + ) + res = subprocess.run( + ["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", str(driver)], + capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=60, + ) + self.assertEqual(res.returncode, 0, res.stderr) + out = res.stdout.strip().splitlines() + ran = json.loads(out[-1]) + ran["said"] = "\n".join(out[:-1]) + return ran + + def saved(self, path: Path) -> dict: + lines = path.read_text(encoding="utf-8").splitlines() if path.exists() else [] + return dict(l.split("=", 1) for l in lines if l.startswith("LEONIDA_")) + + def test_the_first_start_keeps_the_menu_values_and_notes_the_command_line(self): + self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_RENDER_SCALE": "1"}) + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.6") + self.assertEqual(self.saved(self.last)["LEONIDA_RENDER_SCALE"], "1") + self.assertIn("F1 menu settings", ran["said"]) + + def test_a_menu_choice_after_the_same_command_line_wins(self): + self.start({"LEONIDA_RENDER_SCALE": "1"}) + self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_RENDER_SCALE": "1"}) + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.6") + self.assertEqual(self.saved(self.menu), {"LEONIDA_RENDER_SCALE": "0.6"}) + + def test_a_command_line_changed_after_the_menu_wins_and_the_menu_file_follows(self): + self.start({"LEONIDA_RENDER_SCALE": "1"}) + self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\nLEONIDA_FPS_LINE=0\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_RENDER_SCALE": "0.5"}) + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.5") + self.assertEqual(ran["settings"]["LEONIDA_FPS_LINE"], "0", "a setting the command line left alone keeps F1's") + self.assertEqual(self.saved(self.menu), {"LEONIDA_FPS_LINE": "0"}) + self.assertIn("LEONIDA_RENDER_SCALE 0.6 -> 0.5", ran["said"]) + # And the start after it, with the same command line, has nothing left to replace. + again = self.start({"LEONIDA_RENDER_SCALE": "0.5"}) + self.assertEqual(again["settings"]["LEONIDA_RENDER_SCALE"], "0.5") + self.assertNotIn("Command line over", again["said"]) + + def test_a_setting_the_command_line_drops_wins_over_the_menu_value(self): + self.start({"LEONIDA_RENDER_SCALE": "1", "LEONIDA_OWN_UPSCALER": "1"}) + self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_UPSCALE": "dlss"}) + self.assertNotIn("LEONIDA_RENDER_SCALE", ran["settings"]) + self.assertIn("LEONIDA_RENDER_SCALE 0.6 -> (unset)", ran["said"]) + + def test_the_console_follows_the_last_choice(self): + self.start({}, console="series-s") + self.menu.write_text("LEONIDA_MENU_CONSOLE=series-x\r\n", encoding="utf-8") + self.assertEqual(self.start({}, console="series-s")["console"], "series-x", "F1 chose after that command line") + ran = self.start({}, console="series-x") + self.assertEqual(ran["console"], "series-x") + ran = self.start({}, console="series-s") + self.assertEqual(ran["console"], "series-s", "-SeriesS given after F1's choice") + self.assertNotIn("LEONIDA_MENU_CONSOLE", self.saved(self.menu)) + + def test_an_empty_menu_value_still_unsets(self): + self.start({"LEONIDA_PANEL": "1"}) + self.menu.write_text("LEONIDA_PANEL=\r\n", encoding="utf-8") + self.assertNotIn("LEONIDA_PANEL", self.start({"LEONIDA_PANEL": "1"})["settings"]) + + def test_a_dry_run_writes_neither_file(self): + self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8") + self.start({"LEONIDA_RENDER_SCALE": "1"}, dry=True) + self.assertFalse(self.last.exists()) + self.start({"LEONIDA_RENDER_SCALE": "1"}) + before = self.menu.read_bytes() + ran = self.start({"LEONIDA_RENDER_SCALE": "0.5"}, dry=True) + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.5") + self.assertEqual(self.menu.read_bytes(), before) + self.assertEqual(self.saved(self.last)["LEONIDA_RENDER_SCALE"], "1") + + +if __name__ == "__main__": + unittest.main() From cf15c2c6ed80ef8226a30cb4ac3deab128737266 Mon Sep 17 00:00:00 2001 From: Alfredo Peres Date: Tue, 1 Dec 2026 11:20:54 -0300 Subject: [PATCH 2/4] d3d12: a typed switch wins over the F1 menu, not a value that changed (D3D12-MENU-LAST-CHOICE-WINS) Review of the first version: a value that differs from the last start's command line was taken for the user's new choice. That lost an explicit flag on the first start after an upgrade, never let the same flag typed again win, and dropped a menu value the command line never mentioned when leonida-launch.txt lacked the key. The menu file was also rewritten before the history, so a failed history write had already lost a saved choice. Now the rule follows what the user typed: - A switch typed for this start wins over the menu's saved value of each setting it makes. The menu file drops that value, so F1 shows the command line's. scripts\play-d3d12.ps1 passes the switches typed there as -Typed, so its Series X default and -Lowest 1080 leave the menu's choice standing. A start by hand counts its own switches, and -More wins like a typed switch. - Every other setting keeps the menu's value. - The menu's SAVE AND RESTART adds -MenuRestart to the switches it replays (LEONIDA_MENU_ARGS), so there the menu's values, saved after those switches, win. leonida-launch.txt is gone. The menu file is written to a temporary file and moved over the old one, and only when a value leaves it. If that fails, the start runs with the command line's values and the file stays whole. Tests: 10 cases, among them the same switch typed again, an untyped default, a setting no switch makes, the restart, a start by hand, -More and a menu file that cannot be written. Co-Authored-By: Claude Opus 5.5 --- d3d12/.gitignore | 1 - d3d12/README.md | 11 ++- d3d12/scripts/play-nvidia.ps1 | 91 ++++++++++++----- docs/mod-menu.md | 7 +- scripts/play-d3d12.ps1 | 5 + tests/test_play_nvidia_menu_choice.py | 136 ++++++++++++++++---------- 6 files changed, 164 insertions(+), 87 deletions(-) diff --git a/d3d12/.gitignore b/d3d12/.gitignore index 3780e34803..621ffa2551 100644 --- a/d3d12/.gitignore +++ b/d3d12/.gitignore @@ -82,4 +82,3 @@ Thumbs.db /nvidia-sdk/ # What the F1 menu saved /leonida-settings.txt -/leonida-launch.txt diff --git a/d3d12/README.md b/d3d12/README.md index 8f749399b0..d730b36e59 100644 --- a/d3d12/README.md +++ b/d3d12/README.md @@ -331,10 +331,13 @@ still reaches. 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. The last choice wins, one - setting at a time: a setting you change on the command line after saving it - in the menu takes the command line's value, the menu file drops its own, and - the menu shows the new one; settings the command line leaves as they were - keep the menu's. Each start says which came from the menu. + 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. diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index a005f5c7e7..6b1de8e903 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -6,8 +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. The last choice wins, one setting at a time: a setting this command line changes -# since the last start wins over the menu's saved one (leonida-launch.txt keeps the last start's), the others keep it. +# 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\\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) @@ -90,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 } @@ -508,12 +513,13 @@ if ($PSBoundParameters.ContainsKey('WindowsBarMB')) { } } -# What the F1 menu saved (leonida-settings.txt, git-ignored) and the settings above: the user's last choice wins, one -# setting at a time. leonida-launch.txt (git-ignored, beside it) keeps what the last start's command line made. A -# setting this command line makes otherwise than that start's did was chosen now: it wins, and the menu file drops its -# value, so F1 shows and saves this one. A setting the command line makes as before keeps the menu's value, the newer -# choice. With no leonida-launch.txt yet (the first start with this launcher) the menu's values win, as before. An -# empty value unsets a setting. -More still wins over both. +# 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) { @@ -523,25 +529,47 @@ function Read-SettingsFile([string]$path) { } $read } -function Write-SettingsFile([string]$path, [string]$header, $values) { - # CRLF, as the menu writes the file (host/menu.rs). - $text = "# $header`r`n" + (($values.Keys | ForEach-Object { "$_=$($values[$_])`r`n" }) -join '') - [IO.File]::WriteAllText($path, $text, [Text.UTF8Encoding]::new($false)) +# 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_UPSCALE', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_FSR_UPSCALER' + NoDlss = 'LEONIDA_UPSCALE' + FrameGen = 'LEONIDA_FRAME_GEN' + NoFrameGen = 'LEONIDA_FRAME_GEN' + FsrFrameGen = 'LEONIDA_FSR_FRAMEGEN' + 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. + $said = if ($name -eq 'SeriesX') { '-SeriesS/-SeriesX' } else { "-$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' -$lastFile = Join-Path $root 'leonida-launch.txt' $smooth = -not $NoSmoothMotion # 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' } $menu = Read-SettingsFile $menuFile -$last = if (Test-Path $lastFile) { Read-SettingsFile $lastFile } else { $null } $fromMenu = @(); $replaced = @() foreach ($k in @($menu.Keys)) { - $v = $menu[$k]; $now = "$($fromLine[$k])" - if ($null -ne $last -and "$($last[$k])" -ne $now) { - $replaced += "$k $(if ($v) { $v } else { '(unset)' }) -> $(if ($now) { $now } else { '(unset)' })" + $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 } @@ -550,13 +578,22 @@ foreach ($k in @($menu.Keys)) { 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, newer than the command line): $($fromMenu -join ', ')" } -if ($replaced) { Write-Host "Command line over the F1 menu's (changed since the last start): $($replaced -join ', ')" } -if (-not $DryRun) { - if ($replaced) { Write-SettingsFile $menuFile 'Saved by the F1 menu; play.ps1 applies these after its own settings (an empty value: unset).' $menu } - $lines = [ordered]@{} - foreach ($k in $fromLine.Keys | Sort-Object) { $lines[$k] = $fromLine[$k] } - Write-SettingsFile $lastFile 'What the last start''s command line made (play-nvidia.ps1): a setting it makes otherwise next time wins over the F1 menu''s.' $lines +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 (Read-SettingsFile $menuFile).Count) { + 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 '') + $tmp = "$menuFile.tmp" + [IO.File]::WriteAllText($tmp, $text, [Text.UTF8Encoding]::new($false)) + Move-Item -LiteralPath $tmp -Destination $menuFile -Force -ErrorAction Stop + } catch { + Remove-Item -LiteralPath "$menuFile.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. if (-not $NoPrecompile) { $settings.LEONIDA_PIPELINE_BOOK = '1' } @@ -637,6 +674,10 @@ foreach ($s in 'Resolution', 'Lowest', 'Dlss', 'FrameGen', 'Aspect', 'PresentSca 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 { '' } diff --git a/docs/mod-menu.md b/docs/mod-menu.md index ab5c4b9ba8..da9f4dfbdf 100644 --- a/docs/mod-menu.md +++ b/docs/mod-menu.md @@ -119,9 +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. At the next start the launcher applies the saved settings, except one the command -line changed since the start before (`leonida-launch.txt` keeps what that start's command line made): that one takes -the command line's value and leaves the menu file, so the last choice wins either way. +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. diff --git a/scripts/play-d3d12.ps1 b/scripts/play-d3d12.ps1 index 70cb328ecf..caaa53736a 100644 --- a/scripts/play-d3d12.ps1 +++ b/scripts/play-d3d12.ps1 @@ -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 diff --git a/tests/test_play_nvidia_menu_choice.py b/tests/test_play_nvidia_menu_choice.py index 4393aa1063..b1f6fa2aee 100644 --- a/tests/test_play_nvidia_menu_choice.py +++ b/tests/test_play_nvidia_menu_choice.py @@ -1,6 +1,8 @@ """d3d12/scripts/play-nvidia.ps1: the F1 menu's saved settings and the command line, the user's last choice winning -one setting at a time (D3D12-MENU-LAST-CHOICE-WINS). The launcher's block is run alone in Windows PowerShell with -the settings a command line made, against a menu file and a last-start file in a temporary folder.""" +one setting at a time (D3D12-MENU-LAST-CHOICE-WINS): a typed switch wins over the menu's value of what it sets, the +menu file drops that value, every other setting keeps the menu's, and the menu's SAVE AND RESTART (-MenuRestart) +keeps the menu's. The launcher's block is run alone in Windows PowerShell with the settings a command line made, +against a menu file in a temporary folder.""" import json import os @@ -25,19 +27,23 @@ def setUp(self): self.tmp = tempfile.TemporaryDirectory() self.root = Path(self.tmp.name) self.menu = self.root / "leonida-settings.txt" - self.last = self.root / "leonida-launch.txt" def tearDown(self): self.tmp.cleanup() - def start(self, line: dict, console: str = "series-s", dry: bool = False) -> dict: - """One start: `line` is what the command line made; returns what the start runs with.""" - pairs = "; ".join(f"'{k}' = '{v}'" for k, v in line.items()) + def start(self, made: dict, typed=None, console="series-s", more=None, restart=False, dry=False, + direct=None) -> dict: + """One start: `made` is what the command line made, `typed` the switches typed (play-d3d12.ps1's -Typed), + `direct` the switches given when play-nvidia.ps1 is started by hand (no -Typed).""" + pairs = "; ".join(f"'{k}' = '{v}'" for k, v in made.items()) + more_pairs = "; ".join(f"'{k}' = '{v}'" for k, v in (more or {}).items()) driver = self.root / "driver.ps1" driver.write_text( + "param([string[]]$Typed, [switch]$MenuRestart, [string]$Resolution, [switch]$Fullscreen)\n" "$ErrorActionPreference = 'Stop'\n" f"$root = '{self.root}'\n" f"$settings = @{{ {pairs} }}\n" + f"$More = @{{ {more_pairs} }}\n" f"$console = '{console}'\n" "$NoSmoothMotion = $true\n" f"$DryRun = ${'true' if dry else 'false'}\n" @@ -45,8 +51,15 @@ def start(self, line: dict, console: str = "series-s", dry: bool = False) -> dic + "\n[pscustomobject]@{ settings = $settings; console = $console; smooth = $smooth } | ConvertTo-Json -Compress\n", encoding="utf-8-sig", ) + args = [] + if typed is not None: + args += ["-Typed", ",".join(typed) if typed else "''"] + if restart: + args.append("-MenuRestart") + args += direct or [] + command = f"& '{driver}' {' '.join(args)}" res = subprocess.run( - ["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", str(driver)], + ["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", command], capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=60, ) self.assertEqual(res.returncode, 0, res.stderr) @@ -55,69 +68,84 @@ def start(self, line: dict, console: str = "series-s", dry: bool = False) -> dic ran["said"] = "\n".join(out[:-1]) return ran - def saved(self, path: Path) -> dict: - lines = path.read_text(encoding="utf-8").splitlines() if path.exists() else [] + def saved(self) -> dict: + lines = self.menu.read_text(encoding="utf-8").splitlines() if self.menu.exists() else [] return dict(l.split("=", 1) for l in lines if l.startswith("LEONIDA_")) - def test_the_first_start_keeps_the_menu_values_and_notes_the_command_line(self): + def test_a_typed_switch_wins_over_the_menu_and_the_menu_file_follows(self): + self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\nLEONIDA_FPS_LINE=0\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_RENDER_SCALE": "1", "LEONIDA_OWN_UPSCALER": "1"}, typed=["Resolution"]) + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "1") + self.assertEqual(ran["settings"]["LEONIDA_FPS_LINE"], "0", "a setting no switch made keeps F1's") + self.assertEqual(self.saved(), {"LEONIDA_FPS_LINE": "0"}) + self.assertIn("LEONIDA_RENDER_SCALE 0.6 -> 1 (-Resolution)", ran["said"]) + + def test_the_same_switch_typed_again_after_a_menu_save_wins_again(self): + self.start({"LEONIDA_RENDER_SCALE": "1"}, typed=["Resolution"]) self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8") - ran = self.start({"LEONIDA_RENDER_SCALE": "1"}) - self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.6") - self.assertEqual(self.saved(self.last)["LEONIDA_RENDER_SCALE"], "1") + ran = self.start({"LEONIDA_RENDER_SCALE": "1"}, typed=["Resolution"]) + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "1") + self.assertEqual(self.saved(), {}) + + def test_a_default_nobody_typed_keeps_the_menu_value(self): + # play-d3d12.ps1's Series X default with its -Lowest 1080: nothing typed. + self.menu.write_text("LEONIDA_MENU_CONSOLE=series-s\r\nLEONIDA_RENDER_SCALE_MIN=0.6667\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_RENDER_SCALE_MIN": "0.75"}, typed=[], console="series-x") + self.assertEqual(ran["console"], "series-s") + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE_MIN"], "0.6667") self.assertIn("F1 menu settings", ran["said"]) + # -SeriesS typed (passed on as SeriesX, the console's switch) wins over a menu's Series X. + self.menu.write_text("LEONIDA_MENU_CONSOLE=series-x\r\n", encoding="utf-8") + self.assertEqual(self.start({}, typed=["SeriesX"], console="series-s")["console"], "series-s") + self.assertEqual(self.saved(), {}) - def test_a_menu_choice_after_the_same_command_line_wins(self): - self.start({"LEONIDA_RENDER_SCALE": "1"}) + def test_a_setting_no_switch_makes_is_never_taken_from_the_menu(self): + self.menu.write_text("LEONIDA_CARD_AWAKE=1\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_CARD_AWAKE": "0", "LEONIDA_RENDER_SCALE": "1"}, typed=["Resolution", "Log"]) + self.assertEqual(ran["settings"]["LEONIDA_CARD_AWAKE"], "1") + self.assertEqual(self.saved(), {"LEONIDA_CARD_AWAKE": "1"}) + self.assertNotIn("Command line over", ran["said"]) + + def test_the_menus_restart_keeps_the_values_it_saved(self): self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8") - ran = self.start({"LEONIDA_RENDER_SCALE": "1"}) + before = self.menu.read_bytes() + ran = self.start({"LEONIDA_RENDER_SCALE": "1"}, restart=True, direct=["-Resolution", "1080"]) self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.6") - self.assertEqual(self.saved(self.menu), {"LEONIDA_RENDER_SCALE": "0.6"}) + self.assertEqual(self.menu.read_bytes(), before) - def test_a_command_line_changed_after_the_menu_wins_and_the_menu_file_follows(self): - self.start({"LEONIDA_RENDER_SCALE": "1"}) - self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\nLEONIDA_FPS_LINE=0\r\n", encoding="utf-8") - ran = self.start({"LEONIDA_RENDER_SCALE": "0.5"}) - self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.5") - self.assertEqual(ran["settings"]["LEONIDA_FPS_LINE"], "0", "a setting the command line left alone keeps F1's") - self.assertEqual(self.saved(self.menu), {"LEONIDA_FPS_LINE": "0"}) - self.assertIn("LEONIDA_RENDER_SCALE 0.6 -> 0.5", ran["said"]) - # And the start after it, with the same command line, has nothing left to replace. - again = self.start({"LEONIDA_RENDER_SCALE": "0.5"}) - self.assertEqual(again["settings"]["LEONIDA_RENDER_SCALE"], "0.5") - self.assertNotIn("Command line over", again["said"]) - - def test_a_setting_the_command_line_drops_wins_over_the_menu_value(self): - self.start({"LEONIDA_RENDER_SCALE": "1", "LEONIDA_OWN_UPSCALER": "1"}) - self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8") - ran = self.start({"LEONIDA_UPSCALE": "dlss"}) - self.assertNotIn("LEONIDA_RENDER_SCALE", ran["settings"]) - self.assertIn("LEONIDA_RENDER_SCALE 0.6 -> (unset)", ran["said"]) + def test_a_start_by_hand_counts_its_own_switches(self): + self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\nLEONIDA_FULLSCREEN=\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_RENDER_SCALE": "1", "LEONIDA_FULLSCREEN": "1"}, + direct=["-Resolution", "1080", "-Fullscreen"]) + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "1") + self.assertEqual(ran["settings"]["LEONIDA_FULLSCREEN"], "1") + self.assertEqual(self.saved(), {}) - def test_the_console_follows_the_last_choice(self): - self.start({}, console="series-s") - self.menu.write_text("LEONIDA_MENU_CONSOLE=series-x\r\n", encoding="utf-8") - self.assertEqual(self.start({}, console="series-s")["console"], "series-x", "F1 chose after that command line") - ran = self.start({}, console="series-x") - self.assertEqual(ran["console"], "series-x") - ran = self.start({}, console="series-s") - self.assertEqual(ran["console"], "series-s", "-SeriesS given after F1's choice") - self.assertNotIn("LEONIDA_MENU_CONSOLE", self.saved(self.menu)) + def test_more_wins_over_the_menu_like_a_typed_switch(self): + self.menu.write_text("LEONIDA_PROMPTS=playstation\r\nLEONIDA_PANEL=1\r\n", encoding="utf-8") + ran = self.start({}, typed=["More"], more={"LEONIDA_PROMPTS": "xbox"}) + self.assertEqual(self.saved(), {"LEONIDA_PANEL": "1"}) + self.assertIn("(-More)", ran["said"]) def test_an_empty_menu_value_still_unsets(self): - self.start({"LEONIDA_PANEL": "1"}) self.menu.write_text("LEONIDA_PANEL=\r\n", encoding="utf-8") - self.assertNotIn("LEONIDA_PANEL", self.start({"LEONIDA_PANEL": "1"})["settings"]) + self.assertNotIn("LEONIDA_PANEL", self.start({"LEONIDA_PANEL": "1"}, typed=[])["settings"]) - def test_a_dry_run_writes_neither_file(self): + def test_a_dry_run_writes_nothing(self): self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8") - self.start({"LEONIDA_RENDER_SCALE": "1"}, dry=True) - self.assertFalse(self.last.exists()) - self.start({"LEONIDA_RENDER_SCALE": "1"}) before = self.menu.read_bytes() - ran = self.start({"LEONIDA_RENDER_SCALE": "0.5"}, dry=True) - self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.5") + ran = self.start({"LEONIDA_RENDER_SCALE": "1"}, typed=["Resolution"], dry=True) + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "1") + self.assertEqual(self.menu.read_bytes(), before) + + def test_a_menu_file_that_cannot_be_written_keeps_every_saved_value(self): + self.menu.write_text("LEONIDA_RENDER_SCALE_MIN=0.6667\r\nLEONIDA_PANEL=1\r\n", encoding="utf-8") + before = self.menu.read_bytes() + (self.root / "leonida-settings.txt.tmp").mkdir() # the new file cannot be written beside it + ran = self.start({"LEONIDA_RENDER_SCALE_MIN": "0.5"}, typed=["Lowest"]) + self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE_MIN"], "0.5", "the start still runs with the switch") self.assertEqual(self.menu.read_bytes(), before) - self.assertEqual(self.saved(self.last)["LEONIDA_RENDER_SCALE"], "1") + self.assertIn("was not updated", ran["said"]) if __name__ == "__main__": From 3a3f38325086968be253ec095974fe9447263b15 Mon Sep 17 00:00:00 2001 From: Alfredo Peres Date: Tue, 1 Dec 2026 13:09:20 -0300 Subject: [PATCH 3/4] d3d12: a typed frame generation replaces the menu's other one; the restart replays -NoFrameGen Review of cf15c2c6e (merzleckeier, full launcher with the final start mocked): - A saved LEONIDA_FSR_FRAMEGEN=1 undid a typed -FrameGen 2. The launcher keeps FSR 3's frame generation when both are set and drops DLSS's. The two are one choice, so -FrameGen now also sets LEONIDA_FSR_FRAMEGEN and -FsrFrameGen also sets LEONIDA_FRAME_GEN in $switchSettings. A typed one replaces the menu's other. - LEONIDA_MENU_ARGS left -NoFrameGen out, as main does, so SAVE AND RESTART turned frame generation on. It is replayed now. Tests: 12 (two new). With the launcher of cf15c2c6e, the two new ones fail. Co-Authored-By: Claude Opus 5.5 --- d3d12/scripts/play-nvidia.ps1 | 7 +++--- tests/test_play_nvidia_menu_choice.py | 34 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index 6b1de8e903..7bdce34178 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -537,9 +537,10 @@ $switchSettings = @{ Lowest = 'LEONIDA_RENDER_SCALE', 'LEONIDA_RENDER_SCALE_MIN', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_UPSCALE', 'LEONIDA_FSR_UPSCALER', 'LEONIDA_OUTPUT' Dlss = 'LEONIDA_RENDER_SCALE', 'LEONIDA_UPSCALE', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_FSR_UPSCALER' NoDlss = 'LEONIDA_UPSCALE' - FrameGen = 'LEONIDA_FRAME_GEN' + # 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' + FsrFrameGen = 'LEONIDA_FSR_FRAMEGEN', 'LEONIDA_FRAME_GEN' Fullscreen = 'LEONIDA_FULLSCREEN' Aspect = 'LEONIDA_ASPECT' PresentScale = 'LEONIDA_PRESENT_SCALE' @@ -667,7 +668,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', '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') { diff --git a/tests/test_play_nvidia_menu_choice.py b/tests/test_play_nvidia_menu_choice.py index b1f6fa2aee..f746c78e59 100644 --- a/tests/test_play_nvidia_menu_choice.py +++ b/tests/test_play_nvidia_menu_choice.py @@ -148,5 +148,39 @@ def test_a_menu_file_that_cannot_be_written_keeps_every_saved_value(self): self.assertIn("was not updated", ran["said"]) + def test_a_typed_frame_generation_replaces_the_menus_other_one(self): + # DLSS's and FSR 3's are one choice: the launcher keeps FSR 3's when both are set, so a saved FSR 3 would + # undo a typed -FrameGen. + self.menu.write_text("LEONIDA_FSR_FRAMEGEN=1\r\nLEONIDA_PANEL=1\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_FRAME_GEN": "2"}, typed=["FrameGen"]) + self.assertEqual(ran["settings"]["LEONIDA_FRAME_GEN"], "2") + self.assertNotIn("LEONIDA_FSR_FRAMEGEN", ran["settings"]) + self.assertEqual(self.saved(), {"LEONIDA_PANEL": "1"}) + self.menu.write_text("LEONIDA_FRAME_GEN=3\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_FSR_FRAMEGEN": "1"}, typed=["FsrFrameGen"]) + self.assertEqual(ran["settings"]["LEONIDA_FSR_FRAMEGEN"], "1") + self.assertNotIn("LEONIDA_FRAME_GEN", ran["settings"]) + self.assertEqual(self.saved(), {}) + + +@unittest.skipUnless(os.name == "nt", "Windows PowerShell launcher") +class MenuRestartArgsTests(unittest.TestCase): + def test_the_restart_replays_every_frame_generation_switch(self): + """The menu's SAVE AND RESTART starts the launcher again with LEONIDA_MENU_ARGS: a switch left out of it is + lost on that start (-NoFrameGen was, and the restart turned frame generation on).""" + with tempfile.TemporaryDirectory() as tmp: + exe = Path(tmp) / "title.exe" + exe.write_bytes(b"") + res = subprocess.run( + ["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", str(SCRIPT), + "-Exe", str(exe), "-SeriesX", "-Lowest", "1080", "-NoFrameGen", "-FsrFrameGen", "-DryRun"], + capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120, + ) + self.assertEqual(res.returncode, 0, res.stderr) + args = next(l for l in res.stdout.splitlines() if l.startswith("LEONIDA_MENU_ARGS=")) + for switch in ("-NoFrameGen", "-FsrFrameGen", "-SeriesX", "-Lowest '1080'", "-MenuRestart"): + self.assertIn(switch, args) + + if __name__ == "__main__": unittest.main() From 8e1d4000a8945adff36d06189749b9a3991fcf24 Mon Sep 17 00:00:00 2001 From: Alfredo Peres Date: Tue, 1 Dec 2026 13:48:08 -0300 Subject: [PATCH 4/4] d3d12: -More's values in the menu report, -Dlss replaces the lowest scale, a tidier menu file write Review of 3a3f38325 (aslan2142): - The values -More sets were not in what the menu was compared with. A replaced value printed "-> (unset)", a value equal to the menu's was reported as replaced, and an empty menu value set by -More was not reported. They are overlaid now. - -Dlss now also sets LEONIDA_RENDER_SCALE_MIN and LEONIDA_OUTPUT in $switchSettings, as -Resolution and -Lowest do, so a typed DLSS mode replaces a saved lowest scale. - play-d3d12.ps1's -SmoothMotion is named -SmoothMotion/-NoSmoothMotion in the report, as -SeriesS is. - The menu file is not read again to tell whether a value left it. After a failed write, only a temporary file this start wrote is removed; whatever already stood at that name is left alone. Tests: 14. With the launcher of 3a3f38325, 4 fail. Co-Authored-By: Claude Opus 5.5 --- d3d12/scripts/play-nvidia.ps1 | 21 ++++++++++++++++----- tests/test_play_nvidia_menu_choice.py | 23 +++++++++++++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index 7bdce34178..dfa371e08c 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -535,7 +535,7 @@ $switchSettings = @{ 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_UPSCALE', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_FSR_UPSCALER' + 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' @@ -553,7 +553,12 @@ $chosenNow = @{} if (-not $MenuRestart) { foreach ($name in $typedNames) { # -SeriesS reaches this script as the console's switch, SeriesX. - $said = if ($name -eq 'SeriesX') { '-SeriesS/-SeriesX' } else { "-$name" } + # 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' } @@ -564,7 +569,10 @@ $smooth = -not $NoSmoothMotion $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] @@ -583,16 +591,19 @@ if ($fromMenu) { Write-Host "F1 menu settings (leonida-settings.txt, for what th 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 (Read-SettingsFile $menuFile).Count) { +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 '') - $tmp = "$menuFile.tmp" [IO.File]::WriteAllText($tmp, $text, [Text.UTF8Encoding]::new($false)) + $wrote = $true Move-Item -LiteralPath $tmp -Destination $menuFile -Force -ErrorAction Stop } catch { - Remove-Item -LiteralPath "$menuFile.tmp" -ErrorAction SilentlyContinue + # 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." } } diff --git a/tests/test_play_nvidia_menu_choice.py b/tests/test_play_nvidia_menu_choice.py index f746c78e59..128608acec 100644 --- a/tests/test_play_nvidia_menu_choice.py +++ b/tests/test_play_nvidia_menu_choice.py @@ -125,7 +125,24 @@ def test_more_wins_over_the_menu_like_a_typed_switch(self): self.menu.write_text("LEONIDA_PROMPTS=playstation\r\nLEONIDA_PANEL=1\r\n", encoding="utf-8") ran = self.start({}, typed=["More"], more={"LEONIDA_PROMPTS": "xbox"}) self.assertEqual(self.saved(), {"LEONIDA_PANEL": "1"}) - self.assertIn("(-More)", ran["said"]) + self.assertIn("LEONIDA_PROMPTS playstation -> xbox (-More)", ran["said"]) + # The same value from -More replaces nothing worth reporting; an empty menu value set by -More is reported. + self.menu.write_text("LEONIDA_PANEL=1\r\nLEONIDA_FPS_LINE=\r\n", encoding="utf-8") + ran = self.start({}, typed=["More"], more={"LEONIDA_PANEL": "1", "LEONIDA_FPS_LINE": "0"}) + self.assertNotIn("LEONIDA_PANEL", ran["said"]) + self.assertIn("LEONIDA_FPS_LINE (unset) -> 0 (-More)", ran["said"]) + self.assertEqual(self.saved(), {}) + + def test_a_typed_dlss_mode_replaces_the_menus_lowest_scale(self): + self.menu.write_text("LEONIDA_RENDER_SCALE_MIN=0.5\r\n", encoding="utf-8") + ran = self.start({"LEONIDA_UPSCALE": "dlss"}, typed=["Dlss"]) + self.assertNotIn("LEONIDA_RENDER_SCALE_MIN", ran["settings"]) + self.assertEqual(self.saved(), {}) + + def test_smooth_motion_typed_in_play_d3d12_is_named_as_typed(self): + self.menu.write_text("LEONIDA_MENU_SMOOTH_MOTION=1\r\n", encoding="utf-8") + ran = self.start({}, typed=["NoSmoothMotion"]) + self.assertIn("(-SmoothMotion/-NoSmoothMotion)", ran["said"]) def test_an_empty_menu_value_still_unsets(self): self.menu.write_text("LEONIDA_PANEL=\r\n", encoding="utf-8") @@ -141,11 +158,13 @@ def test_a_dry_run_writes_nothing(self): def test_a_menu_file_that_cannot_be_written_keeps_every_saved_value(self): self.menu.write_text("LEONIDA_RENDER_SCALE_MIN=0.6667\r\nLEONIDA_PANEL=1\r\n", encoding="utf-8") before = self.menu.read_bytes() - (self.root / "leonida-settings.txt.tmp").mkdir() # the new file cannot be written beside it + blocker = self.root / "leonida-settings.txt.tmp" + blocker.mkdir() # the new file cannot be written beside it ran = self.start({"LEONIDA_RENDER_SCALE_MIN": "0.5"}, typed=["Lowest"]) self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE_MIN"], "0.5", "the start still runs with the switch") self.assertEqual(self.menu.read_bytes(), before) self.assertIn("was not updated", ran["said"]) + self.assertTrue(blocker.is_dir(), "what stood at the temporary name is not the launcher's to remove") def test_a_typed_frame_generation_replaces_the_menus_other_one(self):