Add opt-in NVAPI CPU-Visible VRAM (CVV) fallback and F10 menu setting #104

Manually merged
github merged 1 commit from github-bot/gh-104 into main 2026-12-05 19:01:11 +00:00 AGit
Owner

@⁠reloadggg on GitHub · 2026-12-05 18:32 UTC · original
reloadggg:nvapi-cpu-visible-vidmem → main · +393 −27 · 13 files · 1 commits · merged 2026-12-05 19:00 UTC

Summary

Adds an opt-in (off by default) NVIDIA NVAPI CPU-Visible VRAM (NvAPI_D3D12_CreateHeap2 with NV_D3D12_HEAP_FLAG_CPUVISIBLE_VIDMEM) fallback to Host::card_mapped_buffer_as when standard D3D12 GPU_UPLOAD heaps are unavailable, along with an F10 menu / settings.ini / LARP_CVV toggle.

Who this helps

  • NVIDIA GPUs where hardware/driver BAR1 is expanded (> 256 MiB, e.g. Resizable BAR / ReBAR), but D3D12 D3D12_HEAP_TYPE_GPU_UPLOAD is not exposed by the OS/driver:
    • RTX 20-series (Turing) with ReBAR / expanded BAR1
    • RTX 30/40/50-series on Windows 10 or pre-24H2 Windows 11 (WDDM < 3.2) where GPU_UPLOAD is unavailable despite ReBAR being enabled
  • Systems where standard D3D12 GPU_UPLOAD is already available are completely unaffected (GPU_UPLOAD always takes priority).
  • Systems where nvapi_cvv / LARP_CVV is left at its default (off) are completely unaffected (no nvapi64.dll load, zero behavior change).
  • Systems with a standard 256 MiB BAR1 automatically skip CVV safely (> 256 MiB total CVV guard) and fall back to system-memory upload heaps as before.

What changed

  • crates/larp-gpu/src/nvapi.rs (new):
    • Dynamically loads nvapi64.dll from System32 (LOAD_LIBRARY_SEARCH_SYSTEM32) only when opted in and GPU_UPLOAD is unavailable.
    • Queries NvAPI_D3D12_QueryCpuVisibleVidmem and requires > 256 MiB total CVV before enabling.
    • Creates placed buffers on D3D12_HEAP_TYPE_CUSTOM (WRITE_COMBINE + L0) heaps via NvAPI_D3D12_CreateHeap2 (NV_D3D12_HEAP_FLAG_CPUVISIBLE_VIDMEM = 1), supporting UAV + COMMON initial state for all four card_mapped_buffer_as call sites (descriptor staging, host scratch, title memory windows, shadow UAV windows), and keeps the backing heap alive via SetPrivateDataInterface.
    • Exposes ask(bool), status(), and note_status() for the F10 menu and settings.ini.
  • crates/larp-gpu/src/host.rs:
    • Tracks card-mapped fallback cleanly without assuming heap.Type == GPU_UPLOAD (scratch_buffer / take_chunk).
    • Logs card memory the CPU maps supported=true way="NVAPI CVV" cvv_mib=... when active.
  • crates/larp-game/src/settings.rs, crates/larp-hle/src/settings.rs, locales/*.json (all 7 catalogs), docs/environment-variables.md:
    • Adds nvapi_cvv (default / off / on, When::Start, env LARP_CVV, default off) to [picture] and the F10 menu.

Testing

Unit tests & build (Windows x86_64 MSVC, commit 5406444)

  • cargo test -p larp-gpu --lib nvapi::tests --locked — 4/4 passed
  • cargo test -p larp-core --locked — 7/7 passed (all 7 locale catalogs verified sorted/complete)
  • cargo test -p larp-game --locked — 60/60 passed
  • cargo build --release --locked -p larp — succeeded

Live game verification (Windows 11 26300, i5-13490F, NVIDIA RTX 2080 Ti with 16 GiB expanded BAR1, driver 621.1, LARP_CVV=1)

  • Confirmed nvapi64.dll detection & activation:
    • NVAPI CPU-visible vidmem total_mib=16352 free_mib=15835
    • card memory the CPU maps supported=true way="NVAPI CVV" cvv_mib=16352
  • Verified both --console series-x and --console series-s in-world at 2560×1440 with DXR 1.2 ray tracing + DLSS + DLSS FG (copies 0.1 ms, copying back 0.1 ms, 0 CVV errors).
  • Not tested on non-ReBAR GPUs (256 MiB BAR1 guard verified via unit test min_cvv_guard_requires_expanded_bar) or AMD/Intel GPUs (where nvapi64.dll is not loaded by default and returns unavailable if opted in).
**@⁠reloadggg** on GitHub · 2026-12-05 18:32 UTC · [original](https://github.com/gamingwithhomie/larp/pull/104) `reloadggg:nvapi-cpu-visible-vidmem` → `main` · +393 −27 · 13 files · 1 commits · merged 2026-12-05 19:00 UTC ## Summary Adds an **opt-in (off by default)** NVIDIA NVAPI CPU-Visible VRAM (`NvAPI_D3D12_CreateHeap2` with `NV_D3D12_HEAP_FLAG_CPUVISIBLE_VIDMEM`) fallback to `Host::card_mapped_buffer_as` when standard D3D12 `GPU_UPLOAD` heaps are unavailable, along with an `F10` menu / `settings.ini` / `LARP_CVV` toggle. ### Who this helps - NVIDIA GPUs where hardware/driver BAR1 is expanded (`> 256 MiB`, e.g. Resizable BAR / ReBAR), **but** D3D12 `D3D12_HEAP_TYPE_GPU_UPLOAD` is not exposed by the OS/driver: - **RTX 20-series (Turing)** with ReBAR / expanded BAR1 - **RTX 30/40/50-series** on **Windows 10** or pre-24H2 Windows 11 (WDDM < 3.2) where `GPU_UPLOAD` is unavailable despite ReBAR being enabled - Systems where standard D3D12 `GPU_UPLOAD` is already available are completely unaffected (`GPU_UPLOAD` always takes priority). - Systems where `nvapi_cvv` / `LARP_CVV` is left at its default (`off`) are completely unaffected (no `nvapi64.dll` load, zero behavior change). - Systems with a standard 256 MiB BAR1 automatically skip CVV safely (`> 256 MiB` total CVV guard) and fall back to system-memory upload heaps as before. ### What changed - **`crates/larp-gpu/src/nvapi.rs`** (new): - Dynamically loads `nvapi64.dll` from `System32` (`LOAD_LIBRARY_SEARCH_SYSTEM32`) only when opted in and `GPU_UPLOAD` is unavailable. - Queries `NvAPI_D3D12_QueryCpuVisibleVidmem` and requires `> 256 MiB` total CVV before enabling. - Creates placed buffers on `D3D12_HEAP_TYPE_CUSTOM` (`WRITE_COMBINE` + `L0`) heaps via `NvAPI_D3D12_CreateHeap2` (`NV_D3D12_HEAP_FLAG_CPUVISIBLE_VIDMEM = 1`), supporting UAV + `COMMON` initial state for all four `card_mapped_buffer_as` call sites (descriptor staging, host scratch, title memory windows, shadow UAV windows), and keeps the backing heap alive via `SetPrivateDataInterface`. - Exposes `ask(bool)`, `status()`, and `note_status()` for the `F10` menu and `settings.ini`. - **`crates/larp-gpu/src/host.rs`**: - Tracks card-mapped fallback cleanly without assuming `heap.Type == GPU_UPLOAD` (`scratch_buffer` / `take_chunk`). - Logs `card memory the CPU maps supported=true way="NVAPI CVV" cvv_mib=...` when active. - **`crates/larp-game/src/settings.rs`**, **`crates/larp-hle/src/settings.rs`**, **`locales/*.json`** (all 7 catalogs), **`docs/environment-variables.md`**: - Adds `nvapi_cvv` (`default` / `off` / `on`, `When::Start`, env `LARP_CVV`, default `off`) to `[picture]` and the `F10` menu. ## Testing ### Unit tests & build (Windows x86_64 MSVC, commit `5406444`) - `cargo test -p larp-gpu --lib nvapi::tests --locked` — 4/4 passed - `cargo test -p larp-core --locked` — 7/7 passed (all 7 locale catalogs verified sorted/complete) - `cargo test -p larp-game --locked` — 60/60 passed - `cargo build --release --locked -p larp` — succeeded ### Live game verification (Windows 11 26300, i5-13490F, NVIDIA RTX 2080 Ti with 16 GiB expanded BAR1, driver 621.1, `LARP_CVV=1`) - Confirmed `nvapi64.dll` detection & activation: - `NVAPI CPU-visible vidmem total_mib=16352 free_mib=15835` - `card memory the CPU maps supported=true way="NVAPI CVV" cvv_mib=16352` - Verified both `--console series-x` and `--console series-s` in-world at 2560×1440 with DXR 1.2 ray tracing + DLSS + DLSS FG (`copies 0.1 ms`, `copying back 0.1 ms`, 0 CVV errors). - Not tested on non-ReBAR GPUs (256 MiB BAR1 guard verified via unit test `min_cvv_guard_requires_expanded_bar`) or AMD/Intel GPUs (where `nvapi64.dll` is not loaded by default and returns unavailable if opted in).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 18:36:13 +00:00
github manually merged commit 465c629cb8 into main 2026-12-05 19:01:11 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.