Windows launcher picks the wrong memory budgets when display VRAM is stored as REG_BINARY #2600

Closed
opened 2026-11-29 01:35:32 +00:00 by ecox982745 · 3 comments
ecox982745 commented 2026-11-29 01:35:32 +00:00 (Migrated from github.com)
Contributor

Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-29T01:35:32Z.


On Windows, the launcher misclassifies a 4 GiB card when its driver stores HardwareInformation.qwMemorySize as eight binary bytes. On main 35159222a46c03dfd8965ddaec8d83d3fcd19376, a dry run with that value and 32 GiB of system RAM sets LEONIDA_CARD_BUFFERS_MB=1536 and LEONIDA_WINDOWS_BAR_MB=3072. The equivalent integer value correctly leaves both settings unset. A malformed or unreadable entry can also prevent subsequent adapters from being considered. Original review on #2583

The attached patch reads the eight-byte value as a little-endian byte count and continues past individual bad keys. The existing 6 GiB threshold still applies. Selecting the appropriate card when several adapters report valid sizes is a separate open question. Multi-adapter dry run

Reproduction and verification

The included test runs the actual launcher with -DryRun, a placeholder executable and simulated display-registry values. Run python -I tests/test_play_nvidia_vram.py on Windows. I tested Windows PowerShell 5.1.26100.10068 and PowerShell 7.6.9.

Registry input Result with patch
4 GiB as an integer or as eight binary bytes Both budgets omitted
Exactly 6 GiB as binary 1,536 MiB card buffers and 3,072 MiB windows
4 GiB plus a larger adapter, with mixed registry formats Larger reading retained with the same adapters enumerated in either order
Short value between valid entries, or unreadable key before a valid entry Later valid adapter still counted
Only missing or malformed entries Existing unknown-size defaults

Both shells failed the binary 4 GiB case on the unmodified revision. With the patch all eleven dry runs passed in each shell. The two existing Windows launcher tests and the changed-file game-data check also passed. An unmocked dry run on the RTX 4090 host printed the same budgets before and after the change in both shells. This is host-side verification. No game or GPU workload ran.

The updated patch applies to main b6bf3aa0be76d3b90eef9a12e1698f5c1b3b7816 and reconstructs tested tree 900aaf038650c69238043973262bad47181d9241. Coordination claim. AI-assisted with OpenAI Codex (GPT-6).

Localization follow-up. The test now sets UTF-8 in the PowerShell subprocess and decodes its output explicitly. With the untouched launcher and a simulated CP936 parent locale, both PowerShell versions now report the expected budget mismatch and preserve the non-ASCII diagnostic. The earlier test raised decoding errors in this check. With the patch, all eleven dry runs in each shell, the existing Windows launcher suite and the changed-file game-data check passed. Independent Windows verification

Updated two-file patch for git am

Copy the following block to launcher-vram.patch and run git am launcher-vram.patch.

From 616887a7c2b3036e6ff966847a264558ebc89229 Mon Sep 17 00:00:00 2001
From: OpenAI Codex <[email protected]>
Date: Sun, 29 Nov 2026 13:59:51 +1000
Subject: [PATCH] launcher: handle binary display memory readings

Read eight-byte registry values as unsigned VRAM byte counts. Skip unreadable display keys without losing later adapters. Verify the dry run on both PowerShell versions and preserve failure diagnostics across Windows code pages.

Fixes #2600. AI-assisted with OpenAI Codex (GPT-6 and GPT-6.2 Sol).
---
 d3d12/scripts/play-nvidia.ps1  | 14 ++++--
 tests/test_play_nvidia_vram.py | 80 ++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 3 deletions(-)
 create mode 100644 tests/test_play_nvidia_vram.py

diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1
index 8d9d81748..032ce3a3c 100644
--- a/d3d12/scripts/play-nvidia.ps1
+++ b/d3d12/scripts/play-nvidia.ps1
@@ -252,10 +252,18 @@ $settings = @{
 # AdapterRAM stops at 4 GB), the largest adapter's; 0 when unknown.
 $vram = 0
 try {
-    Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}' -ErrorAction Stop |
+    Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}' -ErrorAction SilentlyContinue |
         ForEach-Object {
-            $q = (Get-ItemProperty $_.PSPath -Name 'HardwareInformation.qwMemorySize' -ErrorAction SilentlyContinue).'HardwareInformation.qwMemorySize'
-            if ($q -and [uint64]$q -gt $vram) { $vram = [uint64]$q }
+            try {
+                $q = (Get-ItemProperty $_.PSPath -Name 'HardwareInformation.qwMemorySize' -ErrorAction Stop).'HardwareInformation.qwMemorySize'
+                if ($q -is [byte[]]) {
+                    # Some drivers store the byte count as an eight-byte REG_BINARY value.
+                    if ($q.Length -ne 8) { return }
+                    $q = [BitConverter]::ToUInt64($q, 0)
+                }
+                $bytes = [uint64]$q
+                if ($bytes -gt $vram) { $vram = $bytes }
+            } catch { return }
         }
 } 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
diff --git a/tests/test_play_nvidia_vram.py b/tests/test_play_nvidia_vram.py
new file mode 100644
index 000000000..cee120ce3
--- /dev/null
+++ b/tests/test_play_nvidia_vram.py
@@ -0,0 +1,80 @@
+"""Exercise the launcher VRAM budgets without a game or a registry write."""
+import os
+from pathlib import Path
+import shutil
+import subprocess
+import tempfile
+import unittest
+
+
+LAUNCHER = Path(__file__).resolve().parents[1] / "d3d12" / "scripts" / "play-nvidia.ps1"
+DRY_RUN = r"""
+[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
+$ErrorActionPreference = 'Stop'
+function Get-ChildItem {
+    [CmdletBinding()] param([string]$Path)
+    foreach ($entry in $entries) {
+        if ($entry -eq 'bad-key') { Write-Error 'Cannot enumerate this subkey'; continue }
+        [pscustomobject]@{ PSPath = $entry }
+    }
+}
+function Get-ItemProperty {
+    [CmdletBinding()] param([string]$Path, [string]$Name)
+    switch ($Path) {
+        'qword4' { $value = [int64]4GB }
+        'qword8' { $value = [int64]8GB }
+        'binary4' { $value = [BitConverter]::GetBytes([int64]4GB) }
+        'binary6' { $value = [BitConverter]::GetBytes([int64]6GB) }
+        'short' { $value = [byte[]](1, 2) }
+        'missing' { return }
+        'denied' { throw 'Unreadable display subkey' }
+    }
+    [pscustomobject]@{ $Name = $value }
+}
+function Get-CimInstance {
+    [CmdletBinding()] param([string]$ClassName)
+    [pscustomobject]@{ BuildNumber = '26300'; TotalPhysicalMemory = 32GB; Name = 'Test GPU' }
+}
+function Check([string[]]$entries, [bool]$small) {
+    $lines = & $env:TEST_LAUNCHER -Exe $env:TEST_EXE -NoDlss -NoSmoothMotion -DryRun 6>$null
+    if (-not ($lines -match '^LEONIDA_MENU_PLAY=')) { throw 'Dry run did not finish' }
+    $budgets = @($lines -match '^LEONIDA_(CARD_BUFFERS_MB|WINDOWS_BAR_MB)=' | Sort-Object)
+    $want = if ($small) { '' } else { 'LEONIDA_CARD_BUFFERS_MB=1536 LEONIDA_WINDOWS_BAR_MB=3072' }
+    if (($budgets -join ' ') -ne $want) { throw "Registry entries $entries gave budgets [$budgets], expected [$want]" }
+}
+Check @('qword4') $true
+Check @('binary4') $true
+Check @('binary6') $false
+Check @('qword4', 'binary6') $false
+Check @('binary6', 'qword4') $false
+Check @('binary4', 'qword8') $false
+Check @('qword8', 'binary4') $false
+Check @('qword4', 'short', 'qword8') $false
+Check @('denied', 'binary4') $true
+Check @('bad-key', 'binary4') $true
+Check @('missing', 'short') $false
+"""
+
+
[email protected](os.name == "nt", "Windows launcher")
+class PlayNvidiaVramTest(unittest.TestCase):
+    def test_registry_values_in_launcher_dry_run(self):
+        shells = [path for name in ("powershell.exe", "pwsh.exe") if (path := shutil.which(name))]
+        if not shells:
+            self.skipTest("PowerShell is unavailable")
+        with tempfile.TemporaryDirectory() as temp:
+            exe = Path(temp) / "placeholder.exe"
+            exe.touch()
+            env = {k: v for k, v in os.environ.items() if not k.upper().startswith("LEONIDA_")}
+            env.update(LOCALAPPDATA=temp, TEST_EXE=str(exe), TEST_LAUNCHER=str(LAUNCHER))
+            for shell in shells:
+                with self.subTest(shell=shell):
+                    run = subprocess.run(
+                        [shell, "-NoProfile", "-NonInteractive", "-Command", DRY_RUN],
+                        env=env, capture_output=True, encoding="utf-8", errors="backslashreplace", timeout=60,
+                    )
+                    self.assertEqual(run.returncode, 0, run.stdout + run.stderr)
+
+
+if __name__ == "__main__":
+    unittest.main()
-- 
2.53.0.windows.3
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:6673492881 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/issues/2600). Originally posted by [ecox982745](https://github.com/ecox982745) on 2026-11-29T01:35:32Z. --- On Windows, the launcher misclassifies a 4 GiB card when its driver stores `HardwareInformation.qwMemorySize` as eight binary bytes. On main `35159222a46c03dfd8965ddaec8d83d3fcd19376`, a dry run with that value and 32 GiB of system RAM sets `LEONIDA_CARD_BUFFERS_MB=1536` and `LEONIDA_WINDOWS_BAR_MB=3072`. The equivalent integer value correctly leaves both settings unset. A malformed or unreadable entry can also prevent subsequent adapters from being considered. [Original review on #2583](https://github.com/ProjectLeonida/mandy/pull/2583#pullrequestreview-6099900893) The attached patch reads the eight-byte value as a little-endian byte count and continues past individual bad keys. The existing 6 GiB threshold still applies. Selecting the appropriate card when several adapters report valid sizes is a separate open question. [Multi-adapter dry run](https://github.com/ProjectLeonida/mandy/pull/2583#issuecomment-7244628320) ### Reproduction and verification The included test runs the actual launcher with `-DryRun`, a placeholder executable and simulated display-registry values. Run `python -I tests/test_play_nvidia_vram.py` on Windows. I tested Windows PowerShell 5.1.26100.10068 and PowerShell 7.6.9. | Registry input | Result with patch | | --- | --- | | 4 GiB as an integer or as eight binary bytes | Both budgets omitted | | Exactly 6 GiB as binary | 1,536 MiB card buffers and 3,072 MiB windows | | 4 GiB plus a larger adapter, with mixed registry formats | Larger reading retained with the same adapters enumerated in either order | | Short value between valid entries, or unreadable key before a valid entry | Later valid adapter still counted | | Only missing or malformed entries | Existing unknown-size defaults | Both shells failed the binary 4 GiB case on the unmodified revision. With the patch all eleven dry runs passed in each shell. The two existing Windows launcher tests and the changed-file game-data check also passed. An unmocked dry run on the RTX 4090 host printed the same budgets before and after the change in both shells. This is host-side verification. No game or GPU workload ran. The updated patch applies to main `b6bf3aa0be76d3b90eef9a12e1698f5c1b3b7816` and reconstructs tested tree `900aaf038650c69238043973262bad47181d9241`. [Coordination claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7248830889). AI-assisted with OpenAI Codex (GPT-6). **Localization follow-up.** The test now sets UTF-8 in the PowerShell subprocess and decodes its output explicitly. With the untouched launcher and a simulated CP936 parent locale, both PowerShell versions now report the expected budget mismatch and preserve the non-ASCII diagnostic. The earlier test raised decoding errors in this check. With the patch, all eleven dry runs in each shell, the existing Windows launcher suite and the changed-file game-data check passed. [Independent Windows verification](https://github.com/ProjectLeonida/mandy/issues/2600#issuecomment-7249971924) <details> <summary>Updated two-file patch for git am</summary> Copy the following block to `launcher-vram.patch` and run `git am launcher-vram.patch`. ~~~~patch From 616887a7c2b3036e6ff966847a264558ebc89229 Mon Sep 17 00:00:00 2001 From: OpenAI Codex <[email protected]> Date: Sun, 29 Nov 2026 13:59:51 +1000 Subject: [PATCH] launcher: handle binary display memory readings Read eight-byte registry values as unsigned VRAM byte counts. Skip unreadable display keys without losing later adapters. Verify the dry run on both PowerShell versions and preserve failure diagnostics across Windows code pages. Fixes #2600. AI-assisted with OpenAI Codex (GPT-6 and GPT-6.2 Sol). --- d3d12/scripts/play-nvidia.ps1 | 14 ++++-- tests/test_play_nvidia_vram.py | 80 ++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 tests/test_play_nvidia_vram.py diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index 8d9d81748..032ce3a3c 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -252,10 +252,18 @@ $settings = @{ # AdapterRAM stops at 4 GB), the largest adapter's; 0 when unknown. $vram = 0 try { - Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}' -ErrorAction Stop | + Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}' -ErrorAction SilentlyContinue | ForEach-Object { - $q = (Get-ItemProperty $_.PSPath -Name 'HardwareInformation.qwMemorySize' -ErrorAction SilentlyContinue).'HardwareInformation.qwMemorySize' - if ($q -and [uint64]$q -gt $vram) { $vram = [uint64]$q } + try { + $q = (Get-ItemProperty $_.PSPath -Name 'HardwareInformation.qwMemorySize' -ErrorAction Stop).'HardwareInformation.qwMemorySize' + if ($q -is [byte[]]) { + # Some drivers store the byte count as an eight-byte REG_BINARY value. + if ($q.Length -ne 8) { return } + $q = [BitConverter]::ToUInt64($q, 0) + } + $bytes = [uint64]$q + if ($bytes -gt $vram) { $vram = $bytes } + } catch { return } } } 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 diff --git a/tests/test_play_nvidia_vram.py b/tests/test_play_nvidia_vram.py new file mode 100644 index 000000000..cee120ce3 --- /dev/null +++ b/tests/test_play_nvidia_vram.py @@ -0,0 +1,80 @@ +"""Exercise the launcher VRAM budgets without a game or a registry write.""" +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +LAUNCHER = Path(__file__).resolve().parents[1] / "d3d12" / "scripts" / "play-nvidia.ps1" +DRY_RUN = r""" +[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false) +$ErrorActionPreference = 'Stop' +function Get-ChildItem { + [CmdletBinding()] param([string]$Path) + foreach ($entry in $entries) { + if ($entry -eq 'bad-key') { Write-Error 'Cannot enumerate this subkey'; continue } + [pscustomobject]@{ PSPath = $entry } + } +} +function Get-ItemProperty { + [CmdletBinding()] param([string]$Path, [string]$Name) + switch ($Path) { + 'qword4' { $value = [int64]4GB } + 'qword8' { $value = [int64]8GB } + 'binary4' { $value = [BitConverter]::GetBytes([int64]4GB) } + 'binary6' { $value = [BitConverter]::GetBytes([int64]6GB) } + 'short' { $value = [byte[]](1, 2) } + 'missing' { return } + 'denied' { throw 'Unreadable display subkey' } + } + [pscustomobject]@{ $Name = $value } +} +function Get-CimInstance { + [CmdletBinding()] param([string]$ClassName) + [pscustomobject]@{ BuildNumber = '26300'; TotalPhysicalMemory = 32GB; Name = 'Test GPU' } +} +function Check([string[]]$entries, [bool]$small) { + $lines = & $env:TEST_LAUNCHER -Exe $env:TEST_EXE -NoDlss -NoSmoothMotion -DryRun 6>$null + if (-not ($lines -match '^LEONIDA_MENU_PLAY=')) { throw 'Dry run did not finish' } + $budgets = @($lines -match '^LEONIDA_(CARD_BUFFERS_MB|WINDOWS_BAR_MB)=' | Sort-Object) + $want = if ($small) { '' } else { 'LEONIDA_CARD_BUFFERS_MB=1536 LEONIDA_WINDOWS_BAR_MB=3072' } + if (($budgets -join ' ') -ne $want) { throw "Registry entries $entries gave budgets [$budgets], expected [$want]" } +} +Check @('qword4') $true +Check @('binary4') $true +Check @('binary6') $false +Check @('qword4', 'binary6') $false +Check @('binary6', 'qword4') $false +Check @('binary4', 'qword8') $false +Check @('qword8', 'binary4') $false +Check @('qword4', 'short', 'qword8') $false +Check @('denied', 'binary4') $true +Check @('bad-key', 'binary4') $true +Check @('missing', 'short') $false +""" + + +@unittest.skipUnless(os.name == "nt", "Windows launcher") +class PlayNvidiaVramTest(unittest.TestCase): + def test_registry_values_in_launcher_dry_run(self): + shells = [path for name in ("powershell.exe", "pwsh.exe") if (path := shutil.which(name))] + if not shells: + self.skipTest("PowerShell is unavailable") + with tempfile.TemporaryDirectory() as temp: + exe = Path(temp) / "placeholder.exe" + exe.touch() + env = {k: v for k, v in os.environ.items() if not k.upper().startswith("LEONIDA_")} + env.update(LOCALAPPDATA=temp, TEST_EXE=str(exe), TEST_LAUNCHER=str(LAUNCHER)) + for shell in shells: + with self.subTest(shell=shell): + run = subprocess.run( + [shell, "-NoProfile", "-NonInteractive", "-Command", DRY_RUN], + env=env, capture_output=True, encoding="utf-8", errors="backslashreplace", timeout=60, + ) + self.assertEqual(run.returncode, 0, run.stdout + run.stderr) + + +if __name__ == "__main__": + unittest.main() -- 2.53.0.windows.3 ~~~~ </details>
kirigayakazima commented 2026-11-29 03:18:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-29T03:18:50Z.


Independent Windows verification on c8bf0e7b6 using the attached fixture and patch. The stock launcher gave the large-card budgets for the synthetic binary 4 GiB value under Windows PowerShell. On this Chinese Windows locale the baseline pwsh subtest also hit a subprocess decoding error while reporting the failure. With the patch all eleven dry runs passed in each of Windows PowerShell and pwsh 7.6.9. No game launch, registry writes or GPU workload. AI-assisted with OpenAI Codex (GPT-6).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249971924 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/issues/2600#issuecomment-7249971924). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-29T03:18:50Z. --- Independent Windows verification on c8bf0e7b6 using the attached fixture and patch. The stock launcher gave the large-card budgets for the synthetic binary 4 GiB value under Windows PowerShell. On this Chinese Windows locale the baseline pwsh subtest also hit a subprocess decoding error while reporting the failure. With the patch all eleven dry runs passed in each of Windows PowerShell and pwsh 7.6.9. No game launch, registry writes or GPU workload. AI-assisted with OpenAI Codex (GPT-6).
merzleckeier commented 2026-12-03 01:42:06 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-03T01:42:06Z.


Rechecked the attached two-file patch on current main d15e048a. It applies to the current Git blobs without changing the patch. In Linux PowerShell 7.4.21, the unmodified launcher still gave the large-card budgets for the binary 4 GiB fixture. All eleven of your cases passed with the patch. For this run I selected Linux pwsh in the test fixture.

The same patch also fixes the two frame-generation mismatches in the #3272 follow-up. On the combined #3272 tree (a0a3189f, based on d15e048a), an 8 GiB binary value disables FG on Series X with RT. An integer 8 GiB value followed by a binary 24 GiB value keeps explicit 2×. The five integer/F1/Advanced controls still agree. These tests run the actual launcher with simulated registry entries and no game files. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7364636684 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/issues/2600#issuecomment-7364636684). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-03T01:42:06Z. --- Rechecked the attached two-file patch on current main `d15e048a`. It applies to the current Git blobs without changing the patch. In Linux PowerShell 7.4.21, the unmodified launcher still gave the large-card budgets for the binary 4 GiB fixture. All eleven of your cases passed with the patch. For this run I selected Linux pwsh in the test fixture. The same patch also fixes the two frame-generation mismatches in [the #3272 follow-up](https://github.com/ProjectLeonida/mandy/pull/3272#issuecomment-7364512577). On the combined #3272 tree (`a0a3189f`, based on `d15e048a`), an 8 GiB binary value disables FG on Series X with RT. An integer 8 GiB value followed by a binary 24 GiB value keeps explicit 2×. The five integer/F1/Advanced controls still agree. These tests run the actual launcher with simulated registry entries and no game files. AI-assisted with OpenAI Codex.
ecox982745 commented 2026-12-03 03:04:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-12-03T03:04:54Z.


Fixed by #3279. I reran all eleven original launcher budget cases against merge commit 2791b7756. Windows PowerShell 5.1 and PowerShell 7 both passed 11/11, including the two registry-error cases. The tests used simulated registry entries and ran without game files or a GPU workload. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7366178937 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/issues/2600#issuecomment-7366178937). Originally posted by [ecox982745](https://github.com/ecox982745) on 2026-12-03T03:04:54Z. --- Fixed by #3279. I reran all eleven original launcher budget cases against merge commit 2791b7756. Windows PowerShell 5.1 and PowerShell 7 both passed 11/11, including the two registry-error cases. The tests used simulated registry entries and ran without game files or a GPU workload. AI-assisted with OpenAI Codex.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy#2600
No description provided.