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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ Thumbs.db

# A TypeScript sample shipped with the systematic-debugging skill; .ts is not on the policy allowlist.
/.claude/skills/systematic-debugging/condition-based-waiting-example.ts

# Your own changes to the GPU profiles (gpu-profiles.json).
gpu-profiles.local.json
26 changes: 26 additions & 0 deletions docs/fork-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,32 @@ What each part does today and what it still needs:
| Textures | Console tiled layouts and detiling for the modes the title uses | Render-target metadata planes |
| Series S mode | Runs through the menus to the loading screen | The world, as above |

## Run scripts: switches by graphics card (2026-11-26)

`run-gta6.ps1`, `measure-gta6.ps1` and `shot-run.ps1` no longer set the
frame-rate switches themselves. `scripts/leonida-settings.ps1` reads the
card with the most memory from the display adapters' registry keys,
clears every `LEONIDA_*` switch an earlier run left in the PowerShell
window (the paths, `LEONIDA_PROFILE` and `LEONIDA_LOG` stay;
`LEONIDA_KEEP_WINDOW=1` keeps them all), and applies the profiles of
`gpu-profiles.json` that match the card. Each profile says where its
numbers come from.

- `base`, every card: the switches the scripts set before.
- `card-windows`, opt-in (`LEONIDA_PROFILE=card-windows`): windows of
title memory in the card's memory. RTX 3080 12 GB, Ryzen 7 7800X3D,
first rooms: usual frame 169-173 -> 149-158 ms, card time 103 -> 88 ms.
But the windows take about 3.7 GB of the card, and host copies of
textures picked by index fell from about 12,100 to 6,500.
- `LEONIDA_PROFILE=<name>[,<name>...]` applies `base` and those whatever
the card; `LEONIDA_PROFILE=none` applies none. Local changes go in
`gpu-profiles.local.json`, which git ignores.

On the same RTX 3080 textures stayed black while the card windows were on
and the AMD fork's `play.ps1` had left `LEONIDA_TEXTURE_NO_WAIT=1` and
`LEONIDA_RELAY=2` in the window; they came back once both were gone.
Which of the two did it was not separated.

## Debugging

A release build has no debugging aids. Build them in with
Expand Down
40 changes: 40 additions & 0 deletions gpu-profiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"about": [
"LEONIDA_* switches the run scripts set, by graphics card (scripts/leonida-settings.ps1).",
"Every profile whose match fits the PC's card is applied, in this order; a later one overrides an earlier one.",
"match: vendor (nvidia, amd, intel), min_vram_mb, max_vram_mb, name (a wildcard on the card's name); empty matches every card.",
"opt_in: true: never applied by its match, only when LEONIDA_PROFILE names it.",
"A value of null unsets the switch. LEONIDA_* switches left in the PowerShell window by earlier runs are cleared first (LEONIDA_KEEP_WINDOW=1 keeps them; paths, LEONIDA_PROFILE and LEONIDA_LOG always stay).",
"Add a profile only with a measurement: the card, the CPU, the scene and the frame times before and after.",
"Your own changes go in gpu-profiles.local.json (same form, applied after this file; git ignores it).",
"LEONIDA_PROFILE=<name>[,<name>...] applies base and those profiles whatever the card; LEONIDA_PROFILE=none applies none."
],
"profiles": [
{
"name": "base",
"match": {},
"measured": "victory-gta6 on an RTX 4070 (docs/fork-notes.md); kept on an RTX 3080 12 GB with a Ryzen 7 7800X3D, 2026-11-26",
"env": {
"LEONIDA_ASYNC_SUBMIT": "1",
"LEONIDA_QUEUE2": "1",
"LEONIDA_INDIRECT_WINDOW": "1",
"LEONIDA_COPY_PLAIN": "1",
"LEONIDA_JOIN_PARTS": "1",
"LEONIDA_BACK_OWN_VIEW": "1",
"LEONIDA_INDIRECT_GATHER": "1",
"LEONIDA_CARD_REHASH_RUNS": "1"
}
},
{
"name": "card-windows",
"opt_in": true,
"match": {},
"measured": "RTX 3080 12 GB, Ryzen 7 7800X3D, first rooms, 2026-11-26: usual frame 169-173 -> 149-158 ms, card time 103 -> 88 ms; but the windows take about 3.7 GB of the card and textures picked by index wait for room (host copies of textures 12,142 -> about 6,500): textures stay black. Opt-in until that is solved.",
"env": {
"LEONIDA_CARD_WINDOWS_MB": "3072",
"LEONIDA_WINDOW_UPLOAD": "1",
"LEONIDA_TEXTURE_ROOM_PERCENT": "70"
}
}
]
}
11 changes: 3 additions & 8 deletions measure-gta6.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,9 @@ try {
}
$env:LEONIDA_GAME_DIR = $dir

$env:LEONIDA_ASYNC_SUBMIT = '1'
$env:LEONIDA_QUEUE2 = '1'
$env:LEONIDA_INDIRECT_WINDOW = '1'
$env:LEONIDA_COPY_PLAIN = '1'
$env:LEONIDA_JOIN_PARTS = '1'
$env:LEONIDA_BACK_OWN_VIEW = '1'
$env:LEONIDA_INDIRECT_GATHER = '1'
$env:LEONIDA_CARD_REHASH_RUNS = '1'
# The frame-rate switches for this PC's graphics card (gpu-profiles.json).
. (Join-Path $PSScriptRoot 'scripts\leonida-settings.ps1')
Set-LeonidaProfiles $PSScriptRoot

$env:LEONIDA_FRAME_LOG = '1'
$env:LEONIDA_CARD_METER = '1'
Expand Down
13 changes: 4 additions & 9 deletions run-gta6.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builds Leonida Legacy and starts the game with the frame-rate switches measured to help
# (all off by default). Remove LEONIDA_INDIRECT_WINDOW if the device gets lost.
# for this PC's graphics card (gpu-profiles.json; all off by default in the code).
#
# The first time, it asks for the folder of your copy of the game (the one with
# MicrosoftGame.config in it) and offers to remember it in leonida.toml, which git ignores.
Expand Down Expand Up @@ -58,14 +58,9 @@ try {
}
$env:LEONIDA_GAME_DIR = $dir

$env:LEONIDA_ASYNC_SUBMIT = '1'
$env:LEONIDA_QUEUE2 = '1'
$env:LEONIDA_INDIRECT_WINDOW = '1'
$env:LEONIDA_COPY_PLAIN = '1'
$env:LEONIDA_JOIN_PARTS = '1'
$env:LEONIDA_BACK_OWN_VIEW = '1'
$env:LEONIDA_INDIRECT_GATHER = '1'
$env:LEONIDA_CARD_REHASH_RUNS = '1'
# The frame-rate switches for this PC's graphics card (gpu-profiles.json).
. (Join-Path $PSScriptRoot 'scripts\leonida-settings.ps1')
Set-LeonidaProfiles $PSScriptRoot

# Shaders not in the cache are translated the first time the game uses them, mid-play.
if ($WarmUp -eq 'ask') {
Expand Down
81 changes: 81 additions & 0 deletions scripts/leonida-settings.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# The LEONIDA_* switches for this PC's graphics card, from gpu-profiles.json (and
# gpu-profiles.local.json, if there is one). Dot-sourced by the run scripts:
#
# . (Join-Path $PSScriptRoot 'scripts\leonida-settings.ps1')
# Set-LeonidaProfiles $PSScriptRoot

# The card with the most memory of its own: name, vendor and memory in MB, from the
# display adapters' registry keys (Win32_VideoController stops counting at 4 GB).
function Get-LeonidaGpu {
$class = 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}'
$best = $null
foreach ($key in @(Get-ChildItem -LiteralPath $class -ErrorAction SilentlyContinue)) {
if ($key.PSChildName -notmatch '^\d{4}$') { continue }
$p = Get-ItemProperty -LiteralPath $key.PSPath -ErrorAction SilentlyContinue
if (-not $p -or -not $p.DriverDesc) { continue }
$bytes = [double]0
$q = $p.'HardwareInformation.qwMemorySize'
$d = $p.'HardwareInformation.MemorySize'
if ($q) { $bytes = [double]$q }
elseif ($d -is [byte[]] -and $d.Length -ge 4) { $bytes = [double][BitConverter]::ToUInt32($d, 0) }
elseif ($d) { $bytes = [double]$d }
$vendor = switch -Regex ([string]$p.MatchingDeviceId) {
'ven_10de' { 'nvidia'; break }
'ven_1002' { 'amd'; break }
'ven_8086' { 'intel'; break }
default { 'other' }
}
$gpu = [pscustomobject]@{ Name = [string]$p.DriverDesc; Vendor = $vendor; VramMB = [int]($bytes / 1MB) }
if (-not $best -or $gpu.VramMB -gt $best.VramMB) { $best = $gpu }
}
if (-not $best) { $best = [pscustomobject]@{ Name = 'unknown'; Vendor = 'other'; VramMB = 0 } }
$best
}

function Test-LeonidaMatch($match, $gpu) {
if (-not $match) { return $true }
if ($match.vendor -and $match.vendor -ne $gpu.Vendor) { return $false }
if ($match.min_vram_mb -and $gpu.VramMB -lt [int]$match.min_vram_mb) { return $false }
if ($match.max_vram_mb -and $gpu.VramMB -gt [int]$match.max_vram_mb) { return $false }
if ($match.name -and $gpu.Name -notlike $match.name) { return $false }
$true
}

# Sets the switches of the profiles that fit (or those LEONIDA_PROFILE names) and says
# which they were. -Gpu stands in for the card, for trying a profile out.
function Set-LeonidaProfiles([string]$Root, $Gpu = $null) {
if (-not $Gpu) { $Gpu = Get-LeonidaGpu }
$forced = @()
if ($env:LEONIDA_PROFILE) { $forced = @($env:LEONIDA_PROFILE -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ }) }
$set = [ordered]@{}
$applied = @()
# Switches an earlier run left in this window (this script, play.ps1, by hand) go, so the
# profiles decide; LEONIDA_KEEP_WINDOW=1 keeps them. Paths, LEONIDA_PROFILE and LEONIDA_LOG stay.
$stay = 'LEONIDA_CONFIG', 'LEONIDA_GAME_DIR', 'LEONIDA_CACHE_DIR', 'LEONIDA_DATA_DIR', 'LEONIDA_PROFILE', 'LEONIDA_LOG', 'LEONIDA_KEEP_WINDOW'
if ($env:LEONIDA_KEEP_WINDOW -ne '1') {
Get-ChildItem Env:LEONIDA_* | Where-Object { $_.Name -notin $stay } | ForEach-Object { Remove-Item -LiteralPath "Env:$($_.Name)" }
}
$files = @(Join-Path $Root 'gpu-profiles.json')
$local = Join-Path $Root 'gpu-profiles.local.json'
if (Test-Path -LiteralPath $local) { $files += $local }
foreach ($file in $files) {
$data = Get-Content -LiteralPath $file -Raw | ConvertFrom-Json
foreach ($p in @($data.profiles)) {
$wanted = if ($forced -contains 'none') { $false }
elseif ($forced.Count -gt 0) { $p.name -eq 'base' -or $forced -contains $p.name }
elseif ($p.opt_in) { $false }
else { Test-LeonidaMatch $p.match $Gpu }
if (-not $wanted) { continue }
foreach ($s in @($p.env.PSObject.Properties)) { $set[$s.Name] = $s.Value }
$applied += $p.name
}
}
$kept = @()
foreach ($name in $set.Keys) {
if (Test-Path -LiteralPath "Env:$name") { $kept += $name; continue }
if ($null -ne $set[$name]) { Set-Item -LiteralPath "Env:$name" ([string]$set[$name]) }
}
if ($applied.Count -eq 0) { $applied = @('none') }
Write-Host ("graphics card: {0} ({1}, {2} MB); profiles: {3}" -f $Gpu.Name, $Gpu.Vendor, $Gpu.VramMB, ($applied -join ', '))
if ($kept.Count -gt 0) { Write-Host ("already set in this window, left as they are: {0}" -f ($kept -join ', ')) }
}
11 changes: 3 additions & 8 deletions shot-run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,13 @@ try {
New-Item -ItemType Directory -Force $run | Out-Null
$wanted = @($ShotAt -split ',' | Where-Object { $_.Trim() -ne '' }).Count

# The frame-rate switches for this PC's graphics card (gpu-profiles.json).
. (Join-Path $PSScriptRoot 'scripts\leonida-settings.ps1')
Set-LeonidaProfiles $PSScriptRoot
$env:LEONIDA_SHOT = $run
$env:LEONIDA_SHOT_AT = $ShotAt
if ($Keys -ne '') { $env:LEONIDA_KEYS = $Keys }
$env:LEONIDA_LOG = 'warn'
$env:LEONIDA_ASYNC_SUBMIT = '1'
$env:LEONIDA_QUEUE2 = '1'
$env:LEONIDA_INDIRECT_WINDOW = '1'
$env:LEONIDA_COPY_PLAIN = '1'
$env:LEONIDA_JOIN_PARTS = '1'
$env:LEONIDA_BACK_OWN_VIEW = '1'
$env:LEONIDA_INDIRECT_GATHER = '1'
$env:LEONIDA_CARD_REHASH_RUNS = '1'

Write-Host "shots go to $run; the game is closed after $Seconds s or when $wanted shot(s) are written"
$log = Join-Path $run 'run.log'
Expand Down
Loading