d3d12 play-nvidia: select adapter VRAM by -Adapter and DXGI #N index (D3D12-PLAY-NVIDIA-ADAPTER-VRAM) #3396

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u  "fix/play-nvidia-adapter-vram:blud-fix/play-nvidia-adapter-vram"
git switch "blud-fix/play-nvidia-adapter-vram"
Open
leonida/mandy
blud wants to merge 2 commits from blud/mandy:fix/play-nvidia-adapter-vram into main

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/play-nvidia-adapter-vram:blud-fix/play-nvidia-adapter-vram'
git switch 'blud-fix/play-nvidia-adapter-vram'
First-time contributor

Claimed in the coordination issue as: D3D12-PLAY-NVIDIA-ADAPTER-VRAM (originally claimed in #2570, addressing the finding that play-nvidia.ps1's $vram read the largest card in the registry instead of the -Adapter card; cc @OreoFR for tools/leonida_launcher.py per DOCS-LAUNCHER-OWNER).

What and why

Previously, d3d12/scripts/play-nvidia.ps1 always set $vram to the largest HardwareInformation.qwMemorySize across every subkey in the Windows display class, ignoring -Adapter. tools/leonida_launcher.py (card_facts) mirrored that behavior so Settings matched the script. On multi-GPU PCs or hybrid-GPU laptops, selecting a smaller card via -Adapter still evaluated both the < 20 GB Series X FG+RT rule and the < 6 GB small-card buffer rule using the larger card's VRAM.

This updates both d3d12/scripts/play-nvidia.ps1 and tools/leonida_launcher.py in lockstep:

  1. Numeric DXGI index selectors (-Adapter '#0', '#1', ...): resolve against DXGI CreateDXGIFactory1 -> EnumAdapters1 -> GetDesc1 (skipping DXGI_ADAPTER_FLAG_SOFTWARE, using 32-bit/64-bit-safe LUID fields, matching d3d12/crates/leonida-gpu/src/host.rs chosen_adapter()), using that adapter's DedicatedVideoMemory. Out-of-range indices (#8) or software adapters fall back to the largest display-class adapter.
  2. Name substring selectors (-Adapter 'RTX 4060', any case): match DriverDesc case-insensitively and take the largest HardwareInformation.qwMemorySize among matching subkeys (returning 0 / unknown if a matching adapter has no qwMemorySize, without borrowing another card's memory).
  3. Unset / whitespace-only -Adapter: preserves the existing largest-adapter behavior across the display class.

Tested

  • Red on main: WinLaunchersTests.test_nvidia_vram_follows_selected_adapter fails on unmodified main across -Adapter 'RTX 4060', -Adapter 'rtx 4060', -Adapter '#1', -Adapter 'Intel' (missing memory), and -Adapter '1050 Ti' (4 GB small-card rule).
  • Green with fix (cherry-picked cleanly onto leonida/main 99e0bc1ce):
    • python -I tests/test_win_launchers.py — 13/13 passed (including #0, #1, software #2, out-of-range #8, name matching, missing-memory, and 4 GB small-card cases).
    • python -I tests/test_leonida_launcher.py — 144/144 passed.
    • python -I tests/test_text_write_line_endings.py — 3/3 passed.
    • python -I scripts/check_no_game_data.py d3d12/scripts/play-nvidia.ps1 tools/leonida_launcher.py tests/test_win_launchers.py tests/test_leonida_launcher.py — exit 0.
  • Independent reviews:
    • Separate read-only reviewer subagent (Gemini 4 Neon) — audited COM ABI (LUID 4-byte alignment on x86/x64, vtable slots, Release in finally), ASCII digit parsing, line endings, and clean-room rules.
    • Third-party verification by @merzleckeier — confirmed PowerShell VRAM fixture passes for #0, #1, software #2, and absent #8, and verified our Python DXGI enumerator under Wine against real host adapters (12,282 MiB NVIDIA #0, 512 MiB AMD #1), matching the runtime.

GPUs tested: live DXGI EnumAdapters1 verified on Windows 11 (NVIDIA GeForce RTX 5060 Laptop GPU #0 + AMD Radeon 780M #1 + Microsoft Basic Render Driver #3 skipped) and by @merzleckeier under Wine; unit tests use synthetic registry/DXGI stubs, no game files needed.

AI-assisted: yes — Gemini 4 Neon via Antigravity (implementation, tests, and a separate read-only reviewer subagent using Gemini 4 Neon).

Checklist

  • Based on current main (99e0bc1ce) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed (n/a: no translator rule changed).
Claimed in the coordination issue as: `D3D12-PLAY-NVIDIA-ADAPTER-VRAM` (originally claimed in #2570, addressing the finding that `play-nvidia.ps1`'s `$vram` read the largest card in the registry instead of the `-Adapter` card; cc @OreoFR for `tools/leonida_launcher.py` per `DOCS-LAUNCHER-OWNER`). ### What and why Previously, `d3d12/scripts/play-nvidia.ps1` always set `$vram` to the largest `HardwareInformation.qwMemorySize` across every subkey in the Windows display class, ignoring `-Adapter`. `tools/leonida_launcher.py` (`card_facts`) mirrored that behavior so Settings matched the script. On multi-GPU PCs or hybrid-GPU laptops, selecting a smaller card via `-Adapter` still evaluated both the `< 20 GB` Series X FG+RT rule and the `< 6 GB` small-card buffer rule using the larger card's VRAM. This updates both `d3d12/scripts/play-nvidia.ps1` and `tools/leonida_launcher.py` in lockstep: 1. **Numeric DXGI index selectors (`-Adapter '#0'`, `'#1'`, ...):** resolve against DXGI `CreateDXGIFactory1` -> `EnumAdapters1` -> `GetDesc1` (skipping `DXGI_ADAPTER_FLAG_SOFTWARE`, using 32-bit/64-bit-safe `LUID` fields, matching `d3d12/crates/leonida-gpu/src/host.rs` `chosen_adapter()`), using that adapter's `DedicatedVideoMemory`. Out-of-range indices (`#8`) or software adapters fall back to the largest display-class adapter. 2. **Name substring selectors (`-Adapter 'RTX 4060'`, any case):** match `DriverDesc` case-insensitively and take the largest `HardwareInformation.qwMemorySize` among matching subkeys (returning `0` / unknown if a matching adapter has no `qwMemorySize`, without borrowing another card's memory). 3. **Unset / whitespace-only `-Adapter`:** preserves the existing largest-adapter behavior across the display class. ### Tested - **Red on `main`:** `WinLaunchersTests.test_nvidia_vram_follows_selected_adapter` fails on unmodified `main` across `-Adapter 'RTX 4060'`, `-Adapter 'rtx 4060'`, `-Adapter '#1'`, `-Adapter 'Intel'` (missing memory), and `-Adapter '1050 Ti'` (4 GB small-card rule). - **Green with fix (cherry-picked cleanly onto `leonida/main` `99e0bc1ce`):** - `python -I tests/test_win_launchers.py` — `13/13` passed (including `#0`, `#1`, software `#2`, out-of-range `#8`, name matching, missing-memory, and 4 GB small-card cases). - `python -I tests/test_leonida_launcher.py` — `144/144` passed. - `python -I tests/test_text_write_line_endings.py` — `3/3` passed. - `python -I scripts/check_no_game_data.py d3d12/scripts/play-nvidia.ps1 tools/leonida_launcher.py tests/test_win_launchers.py tests/test_leonida_launcher.py` — exit `0`. - **Independent reviews:** - Separate read-only reviewer subagent (Gemini 4 Neon) — audited COM ABI (`LUID` 4-byte alignment on x86/x64, vtable slots, `Release` in `finally`), ASCII digit parsing, line endings, and clean-room rules. - Third-party verification by `@merzleckeier` — confirmed PowerShell VRAM fixture passes for `#0`, `#1`, software `#2`, and absent `#8`, and verified our Python DXGI enumerator under Wine against real host adapters (`12,282 MiB` NVIDIA `#0`, `512 MiB` AMD `#1`), matching the runtime. GPUs tested: live DXGI `EnumAdapters1` verified on Windows 11 (NVIDIA GeForce RTX 5060 Laptop GPU `#0` + AMD Radeon 780M `#1` + Microsoft Basic Render Driver `#3` skipped) and by `@merzleckeier` under Wine; unit tests use synthetic registry/DXGI stubs, no game files needed. AI-assisted: yes — Gemini 4 Neon via Antigravity (implementation, tests, and a separate read-only reviewer subagent using Gemini 4 Neon). ### Checklist - [x] Based on current `main` (`99e0bc1ce`) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed (n/a: no translator rule changed).
First-time contributor

tested: no regression, and the adapter figures agree with what the layer itself prints. Machine: Windows 11, NVIDIA GeForce RTX 5080 16 GB, driver 621.47, hardware-accelerated GPU scheduling on, page file 49,152 MB.

python -I tests/test_leonida_launcher.py -> Ran 240 tests, OK (skipped=1), against Ran 234 tests on main 78ac03cb27, so the six added cases pass. node --test tests/test_*.cjs -> 113 tests, 113 pass, 0 fail. python -I tests/test_game_gate.py, tests/test_red_green.py, tests/test_run_game_wine.py, tests/test_win_launchers.py all rc 0 (test_run_game_wine.py skips its 18 cases with no Wine). cargo test --workspace --exclude xtask --locked in d3d12/ -> 8 binaries, 845 passed / 1 failed, leonida-gpu 728 / 1 - byte for byte the same as main, as expected for a script-only change; the one failure is the known descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in, which passes with LEONIDA_VIEW_COPY=0.

The two numbers this pull request has to agree with, from the layer's own log on this box: with LEONIDA_ADAPTER naming the card, host device on the card ... index=1 memory_mb=15977; unset, the host device is the iGPU VEN_1002&DEV_13C0. The card's own budget line then reads 15,209 MB, which is what the presets' pool peaks are measured against. One observation on ordering, for whoever re-runs: test_leonida_launcher.py showed one F when it was the second file in a chain started by test_game_gate.py, and passed clean twice when run on its own - so the case looks order-dependent through the shared cache folder rather than wrong.

tested: no regression, and the adapter figures agree with what the layer itself prints. Machine: Windows 11, NVIDIA GeForce RTX 5080 16 GB, driver 621.47, hardware-accelerated GPU scheduling on, page file 49,152 MB. `python -I tests/test_leonida_launcher.py` -> `Ran 240 tests`, `OK (skipped=1)`, against `Ran 234 tests` on main `78ac03cb27`, so the six added cases pass. `node --test tests/test_*.cjs` -> 113 tests, 113 pass, 0 fail. `python -I tests/test_game_gate.py`, `tests/test_red_green.py`, `tests/test_run_game_wine.py`, `tests/test_win_launchers.py` all rc 0 (`test_run_game_wine.py` skips its 18 cases with no Wine). `cargo test --workspace --exclude xtask --locked` in `d3d12/` -> 8 binaries, 845 passed / 1 failed, `leonida-gpu` 728 / 1 - byte for byte the same as main, as expected for a script-only change; the one failure is the known `descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in`, which passes with `LEONIDA_VIEW_COPY=0`. The two numbers this pull request has to agree with, from the layer's own log on this box: with `LEONIDA_ADAPTER` naming the card, `host device on the card ... index=1 memory_mb=15977`; unset, the host device is the iGPU `VEN_1002&DEV_13C0`. The card's own budget line then reads 15,209 MB, which is what the presets' pool peaks are measured against. One observation on ordering, for whoever re-runs: `test_leonida_launcher.py` showed one `F` when it was the second file in a chain started by `test_game_gate.py`, and passed clean twice when run on its own - so the case looks order-dependent through the shared cache folder rather than wrong.
Sign in to join this conversation.
No description provided.