Files
mandy/scripts/play-d3d12.ps1
OreoFR f1e9718e95 launcher, play scripts: review fixes of #3272 (card mask kept out of the F1 file, -Adapter for auto FG, Linux cache and binds, clear-cache race, unreadable binds kept)
merzleckeier's reviews at 02:35, 02:47 and 02:58 and DeadlyChirp's 02:46 note:
1. The AMD/Intel card filter named NoDlss, NoFrameGen and SmoothMotion in
   -Chosen, so a real PLAY rewrote leonida-settings.txt without the F1
   menu's DLSS, DLSS frame generation and Smooth Motion. The launcher now
   passes -CardMask (card_mask) instead; play-d3d12.ps1 hands it over and
   play-nvidia.ps1 leaves those settings out of this start only, keeping
   them in the menu file (and says so); the menu's FSR stays.
2. play-nvidia.ps1's automatic DLSS frame generation looked at every card:
   with -Adapter it now judges the cards whose name holds it (all when none
   does), so an AMD card chosen beside an RTX 4070 gets none; the card
   mask's NoFrameGen also keeps it off.
3. Clear shader cache on Linux looked under the Windows data folder: it now
   uses play-linux.sh's LEONIDA_CACHE_DIR or ${XDG_DATA_HOME:-~/.local/share}
   /leonida/cache.
4. After the confirmation, clear_cache asks game_running() again, not only
   its own process.
5. Linux PLAY passes the extra variables (the Controls page's binds, the
   advanced options, Advanced winning) in play-linux.sh's environment
   (`env NAME=value sh play-linux.sh ...`); none were passed before.
6. The Controls page keeps entries it cannot read beside its rows
   (split_kbm_binds) and writes them back after them: adding a row no longer
   drops a saved list with an unknown entry. Its note called t() with a
   `text=` value, which crashed the page as soon as it showed one: the
   placeholder is {entries} now, in de/es/fr/pt too.

Tests: test_card_mask_leaves_the_menus_nvidia_values_out_and_in_the_file
(dry runs, a real start with Start-Process stubbed keeping the menu file,
AMD + RTX 4070 with -Adapter each way and with the mask); card_mask and
-CardMask in play_command; LinuxPlayTests; SplitBindsTests with a guard
that no t() call passes text=. Launcher suite OK (1 skip), win launchers
12 OK, docs links, line endings, check_no_game_data. Counter-tests: the
mask ignored, the adapter filter off, the Linux env/cache, split and
card_mask reverted each fail their tests; the guard regex matches the old
source. Real window (isolated APPDATA): the game started during the
confirmation leaves the cache and says close the game first; adding H to
`both:G=Square;vehicle:N=FutureAction` saves G, H and the unknown entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 04:15:54 +01:00

147 lines
9.6 KiB
PowerShell

# Starts the title on Leonida's D3D12 runtime (d3d12/, from trustno1-coder/VIctory-NVIDIA) on Windows.
# The Vulkan renderer stays scripts\play.ps1; Linux uses scripts\play-linux.sh (docs/linux.md).
#
# powershell -ExecutionPolicy Bypass -File scripts\play-d3d12.ps1 -Game <folder with game_scarlett_master.exe>
#
# By default the game runs as on an Xbox Series X with a 2560x1440 output and its own dynamic resolution and temporal
# upscaler: it renders between 1080 and 1440 lines by how long its frames take (-Lowest 1080); -SeriesS runs the
# lighter Series S profile instead, where the game renders its own 720p picture and DLSS takes it to 1080p.
# -Resolution holds one rendered height instead (Series X: 1080 or 1440), -Lowest sets the lowest one. DLSS and DLSS
# frame generation need a few of NVIDIA's own files that no repository may carry: d3d12\Get-NVIDIA-DLSS.cmd fetches
# them from NVIDIA's GitHub once (about 70 MB). Without them the picture is stretched to the screen instead.
# In the game: F1 = settings (frame generation, frame-rate cap, DLSS preset ...), F3 = the numbers panel.
#
# -SmoothMotion starts leonida_sm.exe, the copy NVIDIA's Smooth Motion profile is set for (scripts\smooth-motion.ps1
# -State on sets it): the driver shows twice the frames the game renders (RTX 40 and 50). Not the
# default: the one start made that way on 2026-11-27 ended 2.4 s in with the title's own breakpoint
# (0x80000003 in its main loop), and the next start without it ran. Not looked into yet.
# -NoDlss the picture is stretched instead of going through DLSS
# -Dlss DLSS makes the output, on Series X too: quality (rendered at 1440 lines of the 2160), balanced
# (1296), performance (1080) or ultra (720). Leave -Resolution out with it.
# -FrameGen DLSS frame generation: 2 shows twice the frames rendered (up to 6 where the card does more). On
# Series X it needs the DLSS upscale and turns -Dlss quality on unless a mode is given. Without it, on
# RTX 40 and 50 cards with NVIDIA's files there, d3d12\scripts\play-nvidia.ps1 turns 2x on by itself
# on the title's own upscaler, held to 28 shown frames a second.
# -NoFrameGen no DLSS frame generation at all, the frames the game renders only
# -MotionBlur the game's own motion blur (left out by default: at this frame rate it smears in blocks on turns)
# -FsrFrameGen AMD's FSR 3 frame generation instead (2x), for cards without DLSS frame generation (RTX 20 and 30):
# needs AMD's two signed FidelityFX DLLs in d3d12\amd-sdk\FidelityFX\bin
# -Fullscreen the game's window borderless over its whole monitor (Alt+Enter switches while it runs)
# -Aspect the window's shape: 21:9, 32:9, 16:9, W:H or auto (the screen's). The game still draws 16:9, shown
# centred with black bars (-PresentScale fit, the default with -Aspect) or stretched (stretch).
# -Resolution the older path: the game renders at this height and the title's own upscaler does the rest
# -Lowest the lowest height of the title's own dynamic resolution (1080 by default on Series X): it renders
# between this and 1440 lines. Same save, RTX 4060 Ti (2026-11-29): 57.0 and 59.6 ms a frame (median,
# two series) against 66.0 and 67.9 at -Resolution 1440; the frames sat at 1080 there.
# -RayTracing the title's real ray tracing (slower; shaders build for minutes the first time)
# -HardwareRT a trial: the title's rays on the card's ray-tracing cores (DXR 1.1), in place of -RayTracing
# -Capture F9 in the game saves that frame and the pictures it drew
# -NoPrecompile skip shader translation and pipeline warming before starting
# -PrecompileUsed translate all shaders and warm only the pipelines earlier runs drew with
# -PrecompileAll translate all shaders and warm every pipeline recorded in earlier runs (the default).
# The first full warm-up can take an hour or more and use gigabytes of driver cache.
# -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
# caps (docs/prompt_glyphs.md; both prompt movies are built before the start when missing)
#
# Builds d3d12/ when it is missing (d3d12\scripts\build-nvidia.ps1: the diag profile, with DLSS when NVIDIA's files
# are there), keeps the caches and saves under -Data, and hands everything else to d3d12\scripts\play-nvidia.ps1:
# -SeriesX, -Quality, -Adapter and -More pass through. Nothing goes online.
param(
[Parameter(Mandatory = $true)][string]$Game,
[string]$Data = (Join-Path $env:LOCALAPPDATA "Leonida\d3d12"),
[switch]$SeriesX,
[switch]$SeriesS,
[switch]$Quality,
[ValidateSet('', '2160', '1440', '1080', '720', '540', '480')][string]$Resolution = '',
[ValidateSet('', '1440', '1080', '720', '540', '480')][string]$Lowest = '',
[ValidateSet('', 'quality', 'balanced', 'performance', 'ultra')][string]$Dlss = '',
[ValidateSet(0, 2, 3, 4, 5, 6)][int]$FrameGen = 0,
[switch]$NoFrameGen,
[switch]$MotionBlur,
[switch]$FsrFrameGen,
[switch]$Fullscreen,
[string]$Aspect = '',
[ValidateSet('', 'fit', 'stretch')][string]$PresentScale = '',
[string]$Adapter = '',
[hashtable]$More = @{},
[switch]$Rebuild,
[switch]$SmoothMotion,
[switch]$NoSmoothMotion,
[switch]$NoDlss,
[switch]$RayTracing,
[switch]$HardwareRT,
[switch]$Capture,
[switch]$NoPrecompile,
[switch]$PrecompileAll,
[switch]$Log,
[switch]$DryRun,
[string]$PcGlyphs = '',
# Launcher.bat: the switches of this start whose value changed since its last PLAY, comma-separated (`none`).
# Only those count as typed for the F1 menu: the launcher passes every option at every start.
[string]$Chosen,
# Launcher.bat: the switches this card cannot run (an AMD or Intel card: NoDlss, NoFrameGen, SmoothMotion),
# comma-separated. play-nvidia.ps1 leaves the F1 menu's values for them out of this start only and keeps them in
# its file, for a later start on an NVIDIA card.
[string]$CardMask,
[switch]$PrecompileUsed
)
$ErrorActionPreference = "Stop"
$repo = Split-Path -Parent $PSScriptRoot
$runtime = Join-Path $repo "d3d12"
$exe = Join-Path $runtime "target\diag\leonida.exe"
$title = Join-Path $Game "game_scarlett_master.exe"
if (-not (Test-Path $title)) { throw "missing: $title" }
if (-not $DryRun -and ($Rebuild -or -not (Test-Path $exe))) {
& (Join-Path $runtime "scripts\build-nvidia.ps1")
if ($LASTEXITCODE -ne 0) { throw "cargo build failed ($LASTEXITCODE)" }
}
# A shader cache of its own: one filled before the renderer changed (cache\) does not fit its pipelines.
New-Item -ItemType Directory -Force (Join-Path $Data "cache-2"), (Join-Path $Data "data") | Out-Null
$env:LEONIDA_GAME_DIR = (Resolve-Path $Game).Path
$env:LEONIDA_CACHE_DIR = Join-Path $Data "cache-2"
$env:LEONIDA_DATA_DIR = Join-Path $Data "data"
# Leonida: Smooth Motion only with -SmoothMotion (it was the default for one start, which the title did not
# survive; -NoSmoothMotion is kept and means the same as leaving -SmoothMotion out).
$launch = @{ Exe = $title; Build = 'diag'; NoSmoothMotion = (-not $SmoothMotion); More = $More }
# Leonida: the Series X profile is the default (the user's call: 1080p-1440p as on the bigger consoles).
if (-not $SeriesS) {
$launch.SeriesX = $true
# 1080 to 1440 lines by the title's own dynamic resolution and its own upscaler, unless a height is held
# (-Resolution) or DLSS (which -FrameGen brings with it) makes the output.
if (-not $Resolution -and -not $Lowest -and -not $Dlss -and -not $FrameGen) { $Lowest = '1080' }
}
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', 'HardwareRT', 'Capture', 'NoPrecompile', 'PrecompileUsed', 'Log', 'DryRun', 'FsrFrameGen', 'Fullscreen') {
if ($PSBoundParameters[$switch]) { $launch[$switch] = $true }
}
if ($PSBoundParameters.ContainsKey('PrecompileAll')) { $launch.PrecompileAll = $PrecompileAll }
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.
# Launcher.bat names those it changed (-Chosen); a start by hand counts the switches typed.
$typedHere = if ($PSBoundParameters.ContainsKey('Chosen')) {
@($Chosen -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ -and $_ -ne 'none' })
} else { @($PSBoundParameters.Keys) }
$launch.Typed = @($typedHere | ForEach-Object {
switch ($_) { 'SeriesS' { 'SeriesX' } 'SmoothMotion' { 'NoSmoothMotion' } default { $_ } }
})
if ($CardMask) {
$launch.CardMask = @($CardMask -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ } | ForEach-Object {
switch ($_) { 'SmoothMotion' { 'NoSmoothMotion' } default { $_ } }
})
}
# A called script sets the global exit status. Start fresh for checks that return before launch.
$global:LASTEXITCODE = 0
& (Join-Path $runtime "scripts\play-nvidia.ps1") @launch
exit $global:LASTEXITCODE