Rig launcher: preload done by exit code, skip choice, A/B tests

Preload:
- Counted as done when victory.exe's `preload` process exits with 0
  (the watcher holds its handle to read the code); the "Shaders preloaded
  in" line is only a fallback. Stopped early, the launcher says how many
  pipelines are built (warm-done.txt) and the next start offers to go on.
- The question takes yes / no this time / skip for this version; skip is
  remembered per victory.exe and driver.
- The preload's warm workers are no longer given the fast-core preference
  with -Cores pcores, and do not count as the game's memory.

Measuring:
- rig-runs.csv records the A/B variant, commit free at the start, the
  least free while the game ran and the game's peak memory (every 5 s);
  older rows are kept under the new header.
- -Try cores|room: each start takes the variant with fewer long runs.
- -Compare: medians by settings, a verdict with three runs a side (under
  3 % is called noise), and the commit the game actually took, to check
  the 32/26 GB thresholds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gertvw23
2026-11-28 20:52:08 +01:00
parent f0fdc76eeb
commit 4e8bc2be75
2 changed files with 201 additions and 21 deletions

View File

@ -77,6 +77,19 @@ run at once, with the slow cores idle), and it is not measured on this PC yet. C
Import-Csv $env:LOCALAPPDATA\victory\rig-runs.csv | Format-Table
```
Or let the launcher alternate for you and keep the score:
```powershell
.\scripts\play-rig.ps1 -Try cores # each start takes the variant with fewer runs so far
.\scripts\play-rig.ps1 -Try room # texture room: the launcher's 80 % against the 16 GB card's 84 %
.\scripts\play-rig.ps1 -Compare # medians by settings, a verdict once each side has three runs
```
`-Compare` counts only runs with a minute or more in the game, calls a difference under 3 % of median
fps noise, and also reports how much of Windows' commit the game took (free at the start minus the least
free while it ran, sampled every 5 s). That is what the 32 GB / 26 GB thresholds above should be checked
against: they came from one crashed run.
The summary's numbers come from the layer's own once-a-second frame-time lines. Seconds drawn faster
than 125 frames a second (menus, loading screens) are left out; "under 10 fps" counts the stalls.
@ -89,7 +102,8 @@ than 125 frames a second (menus, loading screens) are left out; "under 10 fps" c
| `-Summary [-Log <file>]` | a run's summary only |
| `-Cores layer` / `pcores` | see above |
| `-Dlss`, `-Res`, `-FrameGen 0..6`, `-NoFrameGen`, `-SeriesS`, `-Fps` | override what it picked |
| `-Preload auto` / `yes` / `no` | the shader preload |
| `-Preload auto` / `yes` / `no` | the shader preload. Auto asks yes / no this time / skip for this version (remembered). It counts as done only when victory.exe's preload process exits with 0; stopped early, the next start says how many pipelines are built and offers to go on |
| `-Try cores` / `room`, `-Compare` | A/B tests and their comparison (above) |
| `-NoFullscreen` | leave the window as the layer makes it |
| `-Set VICTORY_X=1` | add or override any switch (`-Set "VICTORY_A=1,VICTORY_B=2"` from cmd) |
| `-Yes` | take the default answer to every question |

View File

@ -47,8 +47,14 @@ param(
[switch]$SeriesS,
# Frames a second at most (0: no cap, 1000 to the layer).
[ValidateRange(0, 1000)][int]$Fps = 0,
# auto: once for each victory.exe and graphics driver (asked); yes: now; no: not.
# auto: once for each victory.exe and graphics driver (asked: yes, no this time, or skip for this version);
# yes: now; no: not this time.
[ValidateSet('auto', 'yes', 'no')][string]$Preload = 'auto',
# An A/B test: this start takes whichever variant has the fewer runs of a minute or more in rig-runs.csv.
# cores: -Cores layer or pcores; room: the launcher's texture room (80 %) or the one worked out for the card.
[ValidateSet('', 'cores', 'room')][string]$Try = '',
# Only the comparison of the runs in rig-runs.csv, by settings, and what they say about the memory needed.
[switch]$Compare,
[switch]$NoFullscreen,
# Add or override a switch: -Set VICTORY_X=1,VICTORY_Y=2
[string[]]$Set = @(),
@ -545,17 +551,114 @@ function Show-RunSummary($s) {
if ($s.Stalls -gt 5) { Write-Host ' Many seconds under 10 fps: a shader preload (-Preload yes) makes those pipelines ahead.' }
}
function Add-RunRow($s, [string]$cores) {
$new = -not (Test-Path -LiteralPath $runsFile)
$row = [pscustomobject]@{
function Add-RunRow($s, [string]$cores, [hashtable]$extra) {
$gb = { param($mb) if ($null -ne $mb -and "$mb" -ne '') { [math]::Round([double]$mb / 1024, 1) } else { '' } }
$row = [ordered]@{
When = (Get-Date).ToString('yyyy-MM-dd HH:mm'); Log = $s.Log; Console = $s.Console; Res = $s.Res; Dlss = $s.Dlss
FrameGen = $s.FrameGen; Cores = $cores; Workers = $s.Workers; Room = $s.Room; GameSeconds = $s.GameSeconds
FpsMedian = if ($null -ne $s.FpsMedian) { [math]::Round($s.FpsMedian, 1) } else { '' }
FpsLow = if ($null -ne $s.FpsLow) { [math]::Round($s.FpsLow, 1) } else { '' }
Stalls = $s.Stalls; MinCommitMB = $s.MinCommitMB; OutOfMemory = $s.OutOfMemory; Ended = $s.Ended
# Added for A/B tests and the commit thresholds (rows written before have these empty).
Variant = $extra.Variant
CommitStartGB = $extra.CommitStartGB
CommitLimitGB = $extra.CommitLimitGB
MinCommitFreeGB = & $gb $extra.MinCommitFreeMB
PeakGameGB = & $gb $extra.PeakGameMB
}
$csv = $row | ConvertTo-Csv -NoTypeInformation
if ($new) { $csv | Set-Content -LiteralPath $runsFile -Encoding UTF8 } else { $csv | Select-Object -Skip 1 | Add-Content -LiteralPath $runsFile -Encoding UTF8 }
# The file is written whole, so rows from before a column was added line up under the new header.
$old = if (Test-Path -LiteralPath $runsFile) { @(Import-Csv -LiteralPath $runsFile) } else { @() }
$all = @(foreach ($r in $old) {
$o = [ordered]@{}
foreach ($c in $row.Keys) { $o[$c] = if ($r.PSObject.Properties[$c]) { $r.$c } else { '' } }
[pscustomobject]$o
}) + @([pscustomobject]$row)
$all | Export-Csv -LiteralPath $runsFile -NoTypeInformation -Encoding UTF8
}
function Get-Median([double[]]$values) {
$a = @($values | Sort-Object)
if (-not $a.Count) { return $null }
if ($a.Count % 2) { return $a[($a.Count - 1) / 2] }
return ($a[$a.Count / 2 - 1] + $a[$a.Count / 2]) / 2
}
# Runs of a minute or more in the game: shorter ones (a warm-up restart, a quick look) say little about speed.
$MinGameSeconds = 60
function Get-TryVariant([string]$kind, [string[]]$options) {
$counts = @{}; foreach ($o in $options) { $counts[$o] = 0 }
if (Test-Path -LiteralPath $runsFile) {
foreach ($r in Import-Csv -LiteralPath $runsFile) {
if ($r.PSObject.Properties['Variant'] -and "$($r.Variant)" -match "^$kind=(.+)$" -and $counts.ContainsKey($Matches[1]) -and [int]("0$($r.GameSeconds)") -ge $MinGameSeconds) { $counts[$Matches[1]]++ }
}
}
$pick = $options | Sort-Object { $counts[$_] }, { [array]::IndexOf($options, $_) } | Select-Object -First 1
[pscustomobject]@{ Pick = $pick; Counts = $counts }
}
function Show-Compare {
if (-not (Test-Path -LiteralPath $runsFile)) { Write-Host "No runs recorded yet ($runsFile): play through this launcher first."; return }
$rows = @(Import-Csv -LiteralPath $runsFile)
Write-Host ''
Write-Host "Runs in $runsFile : $($rows.Count) ($(@($rows | Where-Object { [int]("0$($_.GameSeconds)") -ge $MinGameSeconds }).Count) with a minute or more in the game)" -ForegroundColor Cyan
$key = { param($r) if ($r.PSObject.Properties['Variant'] -and $r.Variant) { $r.Variant } else { "cores=$($r.Cores) room=$(if ($r.Room) { $r.Room } else { 'layer' }) workers=$(if ($r.Workers) { $r.Workers } else { 'layer' }) fg=$($r.FrameGen)" } }
$groups = $rows | Group-Object { & $key $_ }
$table = foreach ($g in $groups) {
$long = @($g.Group | Where-Object { [int]("0$($_.GameSeconds)") -ge $MinGameSeconds -and "$($_.FpsMedian)" -ne '' })
$secs = 0; $stalls = 0
foreach ($r in $long) { $secs += [int]$r.GameSeconds; $stalls += [int]("0$($r.Stalls)") }
[pscustomobject]@{
Settings = $g.Name
Runs = $long.Count
'Fps median' = if ($long.Count) { '{0:N1}' -f (Get-Median ($long | ForEach-Object { [double]$_.FpsMedian })) } else { '-' }
'Fps low 5%' = if ($long.Count) { '{0:N1}' -f (Get-Median ($long | ForEach-Object { [double]$_.FpsLow })) } else { '-' }
'Stalls/min' = if ($secs) { '{0:N2}' -f (60.0 * $stalls / $secs) } else { '-' }
Crashes = @($g.Group | Where-Object { $_.Ended -eq 'crashed' }).Count
}
}
$table | Format-Table -AutoSize | Out-String | Write-Host
# The A/B pairs: a verdict only with three runs of each, and a difference larger than run-to-run noise.
foreach ($kind in 'cores', 'room') {
# Only rows an A/B start tagged ("cores=pcores"), not the settings key of untagged runs.
$pair = @($table | Where-Object { $_.Settings -match "^$kind=\S+$" })
if ($pair.Count -lt 2) { if ($pair.Count) { Write-Host " -Try ${kind}: only $($pair[0].Settings) so far; the next -Try $kind start takes the other." }; continue }
$few = @($pair | Where-Object { $_.Runs -lt 3 })
if ($few.Count) { Write-Host (" -Try {0}: not enough runs yet ({1}); three of a minute or more each, in the same part of the game." -f $kind, (($pair | ForEach-Object { "$($_.Settings): $($_.Runs)" }) -join ', ')); continue }
$a = $pair[0]; $b = $pair[1]
$diff = 100.0 * ([double]$b.'Fps median' - [double]$a.'Fps median') / [double]$a.'Fps median'
if ([math]::Abs($diff) -lt 3) { Write-Host (" -Try {0}: {1} vs {2}: {3:+0.0;-0.0} % median fps, inside run-to-run noise: no clear winner (compare slow 5 % and stalls too)." -f $kind, $b.Settings, $a.Settings, $diff) }
else { Write-Host (" -Try {0}: {1} vs {2}: {3:+0.0;-0.0} % median fps." -f $kind, $b.Settings, $a.Settings, $diff) }
}
# What the runs used of Windows' commit: the launcher's thresholds (want $CommitComfortGB GB free, fewer workers under
# $CommitTightGB) came from one crashed run; these replace guesswork once there are a few runs.
$mem = @($rows | Where-Object { $_.PSObject.Properties['CommitStartGB'] -and "$($_.CommitStartGB)" -ne '' -and "$($_.MinCommitFreeGB)" -ne '' })
if ($mem.Count) {
$used = @($mem | ForEach-Object { [double]$_.CommitStartGB - [double]$_.MinCommitFreeGB })
$peak = ($used | Measure-Object -Maximum).Maximum
$low = ($mem | ForEach-Object { [double]$_.MinCommitFreeGB } | Measure-Object -Minimum).Minimum
Write-Host (" Memory: the game took up to {0:N1} GB of commit in {1} run(s) (median {2:N1}); the least left free was {3:N1} GB." -f $peak, $mem.Count, (Get-Median $used), $low)
Write-Host (" The launcher wants {0} GB free; from these runs {1} GB would be enough (the most used plus 15 %)." -f $CommitComfortGB, [math]::Ceiling($peak * 1.15))
if ($mem.Count -lt 3) { Write-Host ' (Fewer than three runs: keep the current threshold until there are more.)' }
} else {
Write-Host ' Memory: no runs with commit measurements yet (they are recorded from now on).'
}
}
# What the preload has finished so far, by victory.exe's own list (one line per pipeline made).
function Get-PreloadDoneCount {
$cache = if ($env:VICTORY_CACHE_DIR) { $env:VICTORY_CACHE_DIR } else { Join-Path $vhome 'cache' }
$file = Join-Path $cache 'pipelines\warm-done.txt'
if (-not (Test-Path -LiteralPath $file)) { return 0 }
$n = 0
foreach ($l in [IO.File]::ReadLines($file)) { if ($l.Trim()) { $n++ } }
return $n
}
function Read-PreloadChoice([string]$question) {
if (-not $interactive) { return 'yes' }
$answer = [string](Read-Host "$question [Y]es / [n]o, not this time / [s]kip for this version")
switch -regex ($answer.Trim().ToLowerInvariant()) { '^n' { 'no' } '^s' { 'skip' } default { 'yes' } }
}
# ---------------------------------------------------------------------------------------------------------------
@ -565,9 +668,10 @@ if ($Summary) {
$path = if ($Log) { $Log } else { Get-ChildItem (Join-Path $vhome 'logs') -Filter 'victory-nvidia*.log' -ErrorAction SilentlyContinue | Sort-Object LastWriteTime | Select-Object -Last 1 -ExpandProperty FullName }
if (-not $path) { Write-Host "No run logs in $(Join-Path $vhome 'logs')."; return }
Show-RunSummary (Get-RunSummary $path)
if (Test-Path -LiteralPath $runsFile) { Write-Host ''; Write-Host "Earlier runs: $runsFile" }
if (Test-Path -LiteralPath $runsFile) { Write-Host ''; Write-Host "Earlier runs: $runsFile (-Compare compares them)" }
return
}
if ($Compare) { Show-Compare; return }
# ---------------------------------------------------------------------------------------------------------------
# The title and victory.exe
@ -605,19 +709,42 @@ Write-Host ''
Write-Host " Game $game"
Write-Host " Runner $runner"
Test-Rig $rig $runner
# An A/B test: the variant with the fewer long runs so far.
$variant = ''
if ($Try -eq 'cores') {
if ($rig.Hybrid) {
$t = Get-TryVariant 'cores' @('layer', 'pcores')
$Cores = $t.Pick; $variant = "cores=$Cores"
} else { Write-Line 'WARN' '-Try cores: this CPU has one kind of core; nothing to compare' }
}
$settings = Get-RigSettings $rig
if ($Try -eq 'room') {
$ours = $settings.Set['VICTORY_TEXTURE_ROOM_PERCENT']
if ($settings.Options.FrameGen -ge 2 -and $ours) {
$t = Get-TryVariant 'room' @('80', [string]$ours)
$settings.Set['VICTORY_TEXTURE_ROOM_PERCENT'] = $t.Pick; $variant = "room=$($t.Pick)"
} else { Write-Line 'WARN' '-Try room: needs frame generation on and a card with more than 12 GB; nothing to compare' }
}
if ($variant) {
$settings.Why.Add(("A/B test {0} this start (long runs so far: {1}); play the same part of the game as in the other runs" -f $variant, (($t.Counts.GetEnumerator() | Sort-Object Name | ForEach-Object { "$($_.Name) $($_.Value)" }) -join ', ')))
}
# A preload for each victory.exe (its bytes) and graphics driver: both change what the pipelines are.
$hash = (Get-FileHash -LiteralPath $runner -Algorithm SHA256).Hash.Substring(0, 16)
$preloadKey = "$hash|$($rig.Gpu.Driver)"
$done = $state.PSObject.Properties['preloaded'] -and $state.preloaded -eq $preloadKey
$doPreload = switch ($Preload) { 'yes' { $true } 'no' { $false } default { -not $done } }
$skipped = $state.PSObject.Properties['preloadSkip'] -and $state.preloadSkip -eq $preloadKey
$doPreload = switch ($Preload) { 'yes' { $true } 'no' { $false } default { -not $done -and -not $skipped } }
$builtBefore = Get-PreloadDoneCount
Write-Host ''
Write-Host 'Settings for this PC' -ForegroundColor Cyan
foreach ($w in $settings.Why) { Write-Host " - $w" }
if ($Preload -eq 'auto') {
if ($done) { Write-Host ' - shaders already preloaded for this victory.exe and driver' }
elseif ($skipped) { Write-Host ' - shader preload skipped for this victory.exe and driver, as you chose (-Preload yes runs it)' }
elseif ($builtBefore) { Write-Host (" - shader preload: partly done ({0:N0} pipelines built so far); it goes on from there" -f $builtBefore) }
else { Write-Host " - shader preload: not done yet for this victory.exe and driver $($rig.Gpu.Driver) (the last run sat at 2-3 fps while the world's pipelines were made)" }
}
if (-not $NoFullscreen) { Write-Host ' - borderless full screen at the monitor''s size once frames are being shown (15 s after the first; the layer fits a window inside the screen, scaling the picture)' }
@ -631,8 +758,12 @@ Write-Host ' (What the F1 menu saved in victory-settings.txt still goes over th
if ($Check) { Save-State $state; return }
if ($Preload -eq 'auto' -and $doPreload) {
$doPreload = Read-YesNo 'Preload shaders before the game starts? A while (more on a first time); what is done is kept.' $true
if (-not $doPreload) { $playArgs = Get-PlayArgs $game $settings $false }
$choice = Read-PreloadChoice 'Preload shaders before the game starts? A while (more on a first time); what is done is kept.'
if ($choice -ne 'yes') { $doPreload = $false; $playArgs = Get-PlayArgs $game $settings $false }
if ($choice -eq 'skip') {
Set-StateValue $state 'preloadSkip' $preloadKey
Write-Host ' Not asked again for this victory.exe and driver; -Preload yes runs it.'
}
}
if ($rig.CommitFreeGB -lt $CommitTightGB -and -not (Read-YesNo 'Commit room is short and the game may run out of memory. Start anyway?' $true)) { Save-State $state; return }
Save-State $state
@ -640,23 +771,33 @@ Save-State $state
# ---------------------------------------------------------------------------------------------------------------
# While it runs: the window, and the title's threads on the fast cores
# ---------------------------------------------------------------------------------------------------------------
$sync = [hashtable]::Synchronized(@{ Stop = $false; Notes = [System.Collections.ArrayList]::Synchronized((New-Object System.Collections.ArrayList)) })
$sync = [hashtable]::Synchronized(@{ Stop = $false; Notes = [System.Collections.ArrayList]::Synchronized((New-Object System.Collections.ArrayList))
PreloadExit = $null; MinCommitMB = $null; PeakGameMB = 0 })
$pin = if ($Cores -eq 'pcores' -and $rig.Hybrid) { $rig.FastIds } else { $null }
$watch = {
param($RunnerPath, $PinIds, $MakeBorderless, $Sync, $LogsDir, $SettleSeconds)
$seen = @{}
$tick = 0
while (-not $Sync.Stop) {
$gameMB = 0; $games = 0
foreach ($p in @(Get-Process victory -ErrorAction SilentlyContinue)) {
$path = $null
try { $path = $p.Path } catch { }
if ($path -ne $RunnerPath) { continue }
$st = $seen[$p.Id]
if (-not $st) {
$cmd = (Get-CimInstance Win32_Process -Filter "ProcessId=$($p.Id)" -ErrorAction SilentlyContinue).CommandLine
$st = @{ Preload = [string]$cmd -match '\spreload\s'; Pinned = $false; Window = [IntPtr]::Zero; WindowAt = $null; FramesAt = $null; Done = $false }
$cmd = [string](Get-CimInstance Win32_Process -Filter "ProcessId=$($p.Id)" -ErrorAction SilentlyContinue).CommandLine
# preload: `victory preload`; warm: its pipeline workers; game: `play` or `run`.
$kind = if ($cmd -match '\spreload\s') { 'preload' } elseif ($cmd -match '\swarm(\s|$)') { 'warm' } else { 'game' }
$st = @{ Kind = $kind; Proc = $null; Reported = $false; Pinned = $false; Window = [IntPtr]::Zero; WindowAt = $null; FramesAt = $null; Done = $false }
# The preload's own process is held, so that its exit code can be read once it ends: 0 when every
# step ran to the end, anything else when it stopped early (closed, killed, failed).
if ($kind -eq 'preload') { $st.Proc = $p; try { [void]$p.Handle } catch { } }
$seen[$p.Id] = $st
}
if ($st.Preload) { continue } # the shader preload: every core is welcome
if ($st.Kind -ne 'game') { continue } # the shader preload and its workers: every core is welcome
$games++
try { $gameMB += $p.PrivateMemorySize64 / 1MB } catch { }
if ($PinIds -and -not $st.Pinned) {
$r = [RigNative]::PreferCpuSets($p.Id, [uint32[]]$PinIds)
$st.Pinned = $true
@ -681,6 +822,17 @@ $watch = {
}
}
}
foreach ($st in @($seen.Values)) {
if ($st.Kind -eq 'preload' -and $st.Proc -and -not $st.Reported) {
try { if ($st.Proc.HasExited) { $st.Reported = $true; $Sync.PreloadExit = $st.Proc.ExitCode } } catch { $st.Reported = $true }
}
}
# What the game holds and what Windows can still commit, every 5 s while the game (not the preload) runs.
if ($games -and ($tick++ % 5) -eq 0) {
if ($gameMB -gt $Sync.PeakGameMB) { $Sync.PeakGameMB = [int]$gameMB }
$free = [int]((Get-CimInstance Win32_OperatingSystem).FreeVirtualMemory / 1KB)
if ($null -eq $Sync.MinCommitMB -or $free -lt $Sync.MinCommitMB) { $Sync.MinCommitMB = $free }
}
Start-Sleep -Milliseconds 1000
}
}
@ -708,17 +860,31 @@ $sync.Stop = $true
$ps.Dispose()
foreach ($n in $sync.Notes) { Write-Host " $n" }
if ($preloadOk) {
$state = Read-State
Set-StateValue $state 'preloaded' $preloadKey
Save-State $state
# The preload counts as done when its process ended with 0 (every step ran to the end); its closing line
# ("Shaders preloaded in ...") is only a fallback, for a start whose preload process the watcher did not see.
$builtAfter = Get-PreloadDoneCount
if ($doPreload) {
$complete = if ($null -ne $sync.PreloadExit) { $sync.PreloadExit -eq 0 } else { $preloadOk }
if ($complete) {
$state = Read-State
Set-StateValue $state 'preloaded' $preloadKey
Save-State $state
Write-Line 'OK' ("shader preload complete ({0:N0} pipelines built in all); not asked again for this victory.exe and driver" -f $builtAfter)
} else {
$why = if ($null -ne $sync.PreloadExit) { "ended with code $($sync.PreloadExit)" } else { 'did not report its end' }
Write-Line 'WARN' ("shader preload stopped early ({0}): {1:N0} pipelines built so far, {2:N0} of them this time. The next start offers to go on." -f $why, $builtAfter, ($builtAfter - $builtBefore))
}
}
$extra = @{ Variant = $variant; CommitStartGB = $rig.CommitFreeGB; CommitLimitGB = $rig.CommitLimitGB; MinCommitFreeMB = $sync.MinCommitMB; PeakGameMB = $(if ($sync.PeakGameMB) { $sync.PeakGameMB } else { $null }) }
if ($null -ne $sync.MinCommitMB) {
Write-Host (" memory: {0:N1} GB of commit free at the start, {1:N1} GB at the least; the game held up to {2:N1} GB" -f $rig.CommitFreeGB, ($sync.MinCommitMB / 1024), ($sync.PeakGameMB / 1024))
}
$logs = @(Get-ChildItem (Join-Path $vhome 'logs') -Filter 'victory-nvidia-play-*.log' -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -ge $began } | Sort-Object LastWriteTime)
foreach ($l in $logs) {
$s = Get-RunSummary $l.FullName
Show-RunSummary $s
Add-RunRow $s $Cores
Add-RunRow $s $Cores $extra
}
if ($logs.Count) { Write-Host ''; Write-Host "Runs so far, to compare settings: $runsFile" }
if ($logs.Count) { Write-Host ''; Write-Host "Runs so far: $runsFile (-Compare compares them by settings)" }
else { Write-Host "victory.exe ended (code $code) without a new log in $(Join-Path $vhome 'logs')." }