play-nvidia: an eight-byte qwMemorySize is decoded, not cast (D3D12-VRAM-BYTES)

$vram, the largest HardwareInformation.qwMemorySize of the display class,
cast the value straight to [uint64]. Some drivers write it as eight
little-endian bytes (REG_BINARY); the cast then threw inside the walk's one
try, so the walk stopped there. With the Series X 20 GB rule for frame
generation with ray tracing, an 8 GB card written as bytes kept 2x, and an
integer 8 GB followed by a 24 GB card in bytes left it off, while the
launcher's card_facts (which decodes the bytes) said the opposite
(merzleckeier's review on #3272).

The value is now decoded with [BitConverter]::ToUInt64 when it is a byte
array of eight or more bytes, and each adapter has its own try, so an odd
value skips that adapter only.

Tests: test_nvidia_frame_generation_with_ray_tracing's registry stub takes
several adapters, each an integer or a byte array; four new cases (8 GB and
24 GB as bytes, integer 8 GB + 24 GB bytes, and the reverse order). All 11
tests of tests/test_win_launchers.py pass in Windows PowerShell 5.1; on the
unpatched script the new cases fail exactly as reported (8 GB bytes keeps 2x,
8 GB int + 24 GB bytes leaves it off).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
OreoFR
2026-12-03 03:08:05 +01:00
parent d15e048a74
commit beb1494023
2 changed files with 29 additions and 7 deletions

View File

@ -389,7 +389,12 @@ try {
Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}' -ErrorAction Stop |
ForEach-Object {
$q = (Get-ItemProperty $_.PSPath -Name 'HardwareInformation.qwMemorySize' -ErrorAction SilentlyContinue).'HardwareInformation.qwMemorySize'
if ($q -and [uint64]$q -gt $vram) { $vram = [uint64]$q }
# Some drivers write it as eight little-endian bytes (REG_BINARY), not a number: decoded as the launcher's
# card_facts reads it. One adapter's odd value skips that adapter, not the walk.
try {
if ($q -is [byte[]]) { $q = if ($q.Length -ge 8) { [BitConverter]::ToUInt64($q, 0) } else { $null } }
if ($q -and [uint64]$q -gt $vram) { $vram = [uint64]$q }
} catch { }
}
} catch { }
# Under 6 GB of it (a 4 GB card) the limits above, measured on large cards, are more than the card has: 1536 MiB of

View File

@ -195,7 +195,8 @@ if ($again -contains "LEONIDA_TEST_QUOTED=$quoted") { 'again quoted value kept'
def test_nvidia_frame_generation_with_ray_tracing(self) -> None:
"""Frame generation with hardware ray tracing: kept (and LEONIDA_FG_WITH_RT=1 set for the runtime's guard)
except on the Series X profile under 20 GB of video memory; -More LEONIDA_FG_WITH_RT=1 keeps it there too,
and LEONIDA_FG_WITH_RT=0 leaves it off anywhere. The card's memory is a stubbed registry value."""
and LEONIDA_FG_WITH_RT=0 leaves it off anywhere. The card's memory is a stubbed registry value: an integer or
the eight little-endian bytes some drivers write, and with several adapters the largest one counts."""
with tempfile.TemporaryDirectory() as td:
root = Path(td)
scripts = root / "scripts"
@ -216,17 +217,23 @@ function Get-CimInstance {
if ($ClassName -ne 'Win32_OperatingSystem') { throw "Unexpected CIM query: $ClassName" }
[pscustomobject]@{ BuildNumber = '26100' }
}
# The display class key: one adapter whose memory is $global:vram.
# The display class key: one adapter per value of $global:vram, each an integer or a byte array.
function Get-ChildItem {
param([Parameter(Position = 0)]$Path, [Parameter(ValueFromRemainingArguments = $true)]$Rest)
if ("$Path" -like 'HKLM:*{4d36e968*') { return [pscustomobject]@{ PSPath = 'stub' } }
if ("$Path" -like 'HKLM:*{4d36e968*') {
return @(for ($i = 0; $i -lt @($global:vram).Count; $i++) { [pscustomobject]@{ PSPath = "stub$i" } })
}
Microsoft.PowerShell.Management\Get-ChildItem -Path $Path @Rest
}
function Get-ItemProperty {
param([Parameter(Position = 0)]$Path, [string]$Name, [Parameter(ValueFromRemainingArguments = $true)]$Rest)
if ("$Path" -eq 'stub') { return [pscustomobject]@{ 'HardwareInformation.qwMemorySize' = [uint64]$global:vram } }
if ("$Path" -like 'stub*') {
$value = @($global:vram)[[int]("$Path".Substring(4))]
return [pscustomobject]@{ 'HardwareInformation.qwMemorySize' = $value }
}
Microsoft.PowerShell.Management\Get-ItemProperty -Path $Path -Name $Name @Rest
}
function Bytes([uint64]$memory) { ,[BitConverter]::GetBytes($memory) }
$options = @{
Exe = $env:TEST_NVIDIA_EXE
DryRun = $true
@ -236,8 +243,9 @@ $options = @{
FrameGen = 2
StreamlineDir = $env:TEST_STREAMLINE
}
function Show-Case([string]$name, [uint64]$memory, [hashtable]$extra) {
$global:vram = $memory
function Show-Case([string]$name, $memory, [hashtable]$extra) {
# A byte array is one adapter's value: kept whole, not one adapter per byte.
if ($memory -is [byte[]]) { $global:vram = @(,$memory) } else { $global:vram = $memory }
$lines = & $env:TEST_NVIDIA_LAUNCHER @options @extra
$fg = ($lines | Where-Object { $_ -like 'LEONIDA_FRAME_GEN=*' }) -replace '^LEONIDA_FRAME_GEN=', ''
$rt = ($lines | Where-Object { $_ -like 'LEONIDA_FG_WITH_RT=*' }) -replace '^LEONIDA_FG_WITH_RT=', ''
@ -250,6 +258,11 @@ Show-Case 'X-24' 24GB @{ SeriesX = $true }
Show-Case 'X-8-unlocked' 8GB @{ SeriesX = $true; More = @{ LEONIDA_FG_WITH_RT = '1' } }
Show-Case 'S-8-off' 8GB @{ More = @{ LEONIDA_FG_WITH_RT = '0' } }
Show-Case 'X-unknown' 0 @{ SeriesX = $true }
# The value as eight bytes (REG_BINARY), alone and after an integer one.
Show-Case 'X-8-bytes' (Bytes 8GB) @{ SeriesX = $true }
Show-Case 'X-24-bytes' (Bytes 24GB) @{ SeriesX = $true }
Show-Case 'X-8-int-24-bytes' @([uint64]8GB, (Bytes 24GB)) @{ SeriesX = $true }
Show-Case 'X-24-bytes-8-int' @((Bytes 24GB), [uint64]8GB) @{ SeriesX = $true }
# No -FrameGen: the automatic 2x of RTX 40/50 (with -Lowest) never comes with ray tracing, and does without it.
$options.Remove('FrameGen')
Show-Case 'S-auto-hwrt' 8GB @{ Lowest = '1080' }
@ -274,6 +287,10 @@ Show-Case 'S-auto-none' 8GB @{ Lowest = '1080' }
"X-8-unlocked": "fg=2 with_rt=1", # -More LEONIDA_FG_WITH_RT=1 keeps it under 20 GB
"S-8-off": "fg= with_rt=0", # LEONIDA_FG_WITH_RT=0 leaves it off
"X-unknown": "fg=2 with_rt=1", # memory unknown (0): not held back
"X-8-bytes": "fg= with_rt=", # eight bytes are read as the size: 8 GB, left off
"X-24-bytes": "fg=2 with_rt=1", # 24 GB as bytes: kept
"X-8-int-24-bytes": "fg=2 with_rt=1", # the largest adapter counts, whatever its value's type
"X-24-bytes-8-int": "fg=2 with_rt=1",
"S-auto-hwrt": "fg= with_rt=", # ray tracing on: no automatic frame generation
"S-auto-rt": "fg= with_rt=", # the same with software ray tracing
"S-auto-none": "fg=2 with_rt=", # without ray tracing the automatic 2x stays