VRAM: tighten D3D12MA/heaps granularity and Pool::Copies/Bind caps on <=8 GiB budgets #393

Open
github-bot wants to merge 2 commits from github-bot/gh-393 into main AGit
Owner

@⁠Lakanya on GitHub · 2026-12-06 00:04 UTC · original
Lakanya:pr/vram-8gb-pools-and-heaps → main · +73 −23 · 6 files · 2 commits · open

On 8 GB VRAM cards running Xbox Series X mode (--card-budget 7200), three allocation defaults cause severe VRAM fragmentation and WDDM shared-RAM spill (~1.0 GB spilled):

  1. Pool::Copies (CARD_MOST = 1024 MiB, WINDOW_MAPPED_MOST = 4096 MiB, cardmem::may_place up to 80% of budget) greedily fills VRAM during world load, and shadow::let_go_idle() uses ram_idle_ms (10 s on 32 GB RAM) while ignoring VRAM pressure.
  2. Pool::Bind keeps up to SPARE_MOST = 128 MiB of idle GPU_UPLOAD scratch chunks in SPARE.
  3. texheap uses 64 MiB D3D12MA pools (even for 4 KiB small textures) and heaps.rs uses 128 MiB Kind::Card heaps that mix transient buffers with persistent sparse.rs tiles while always retaining an empty 128 MiB spare heap.

What is in it

  • crates/larp-gpu/src/cardmem.rs: add tight_vram() (budget <= 8 GiB) and tighten may_place() headroom from 80% to 60% on <= 8 GiB budgets.
  • crates/larp-gpu/src/shadow.rs: on tight_vram(), cap CARD_MOST to 256 MiB (CARD_LEAST = 4 MiB) and WINDOW_MAPPED_MOST to 192 MiB (cold windows fall back to existing shared_buffer), and lower let_go_idle() timeout for mapped VRAM windows to 1_000 ms when used > target.
  • crates/larp-gpu/src/host.rs: cap Pool::Bind SPARE_MOST to 32 MiB on tight_vram().
  • crates/larp-gpu/src/texheap.rs & crates/larp-gpu/d3d12ma/shim.cpp: use 16 MiB D3D12MA pool blocks (8 MiB for the 4 KiB small-texture pool) on tight_vram() (concept from Darner PR #345).
  • crates/larp-gpu/src/heaps.rs: use 64 MiB Kind::Card heaps on tight_vram(), split persistent sparse tiles into Kind::CardTiles, and release empty card spare heaps under tight VRAM / over target.

No visual, mip, or RT shortcuts; cards with > 8 GiB budget keep the existing defaults.

Tested

  • Hardware: Windows 11 x64, RTX 5070 Mobile (8 GB VRAM), 32 GB RAM, Series X profile @ 2560x1440 DLSS Performance (FG off).
  • cargo test --lib -p larp-gpu -p larp-hle -- --test-threads=4: larp-gpu 24 passed / 0 failed / 6 ignored; larp-hle 76 passed / 0 failed / 4 ignored.
  • Live A/B (opening 3D gameplay scene, 0 dropped draws): local VRAM -197 MB (6,289 -> 6,092 MB), free_heap 256 -> 163-178 MB (D3D12MA free 100 -> 21 MB), p99 270.4 -> 91.2 ms.
  • Not tested on Linux/Wine or >8 GB GPUs.

AI-assisted by Antigravity (Gemini 4 Neon Medium).

**@⁠Lakanya** on GitHub · 2026-12-06 00:04 UTC · [original](https://github.com/gamingwithhomie/larp/pull/393) `Lakanya:pr/vram-8gb-pools-and-heaps` → `main` · +73 −23 · 6 files · 2 commits · open On 8 GB VRAM cards running Xbox Series X mode (`--card-budget 7200`), three allocation defaults cause severe VRAM fragmentation and WDDM shared-RAM spill (~1.0 GB spilled): 1. `Pool::Copies` (`CARD_MOST = 1024 MiB`, `WINDOW_MAPPED_MOST = 4096 MiB`, `cardmem::may_place` up to 80% of budget) greedily fills VRAM during world load, and `shadow::let_go_idle()` uses `ram_idle_ms` (10 s on 32 GB RAM) while ignoring VRAM pressure. 2. `Pool::Bind` keeps up to `SPARE_MOST = 128 MiB` of idle `GPU_UPLOAD` scratch chunks in `SPARE`. 3. `texheap` uses 64 MiB D3D12MA pools (even for 4 KiB small textures) and `heaps.rs` uses 128 MiB `Kind::Card` heaps that mix transient buffers with persistent `sparse.rs` tiles while always retaining an empty 128 MiB spare heap. ### What is in it - `crates/larp-gpu/src/cardmem.rs`: add `tight_vram()` (`budget <= 8 GiB`) and tighten `may_place()` headroom from 80% to 60% on `<= 8 GiB` budgets. - `crates/larp-gpu/src/shadow.rs`: on `tight_vram()`, cap `CARD_MOST` to 256 MiB (`CARD_LEAST = 4 MiB`) and `WINDOW_MAPPED_MOST` to 192 MiB (cold windows fall back to existing `shared_buffer`), and lower `let_go_idle()` timeout for mapped VRAM windows to `1_000 ms` when `used > target`. - `crates/larp-gpu/src/host.rs`: cap `Pool::Bind` `SPARE_MOST` to 32 MiB on `tight_vram()`. - `crates/larp-gpu/src/texheap.rs` & `crates/larp-gpu/d3d12ma/shim.cpp`: use 16 MiB D3D12MA pool blocks (8 MiB for the 4 KiB small-texture pool) on `tight_vram()` (concept from Darner PR #345). - `crates/larp-gpu/src/heaps.rs`: use 64 MiB `Kind::Card` heaps on `tight_vram()`, split persistent `sparse` tiles into `Kind::CardTiles`, and release empty card spare heaps under tight VRAM / over target. No visual, mip, or RT shortcuts; cards with `> 8 GiB` budget keep the existing defaults. ### Tested - Hardware: Windows 11 x64, RTX 5070 Mobile (8 GB VRAM), 32 GB RAM, Series X profile @ 2560x1440 DLSS Performance (FG off). - `cargo test --lib -p larp-gpu -p larp-hle -- --test-threads=4`: `larp-gpu` 24 passed / 0 failed / 6 ignored; `larp-hle` 76 passed / 0 failed / 4 ignored. - Live A/B (opening 3D gameplay scene, 0 dropped draws): local VRAM `-197 MB` (`6,289 -> 6,092 MB`), `free_heap` `256 -> 163-178 MB` (D3D12MA free `100 -> 21 MB`), p99 `270.4 -> 91.2 ms`. - Not tested on Linux/Wine or >8 GB GPUs. AI-assisted by Antigravity (Gemini 4 Neon Medium).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 00:07:02 +00:00
Author
Owner

@⁠vanya890 on GitHub · 2026-12-06 01:27 UTC · original

The allocation changes are narrowly gated and the 8-GiB A/B data is useful. Please add focused boundary tests for the policy selector and placement threshold: exactly 8 GiB versus just above 8 GiB, plus the ASKED fallback when figures() is unavailable. tight_vram() now controls heap sizing, pool caps, mapped-window limits, and idle release, while may_place() changes the headroom from 80% to 60%; a small regression test around those boundaries would make it safer to maintain this policy across adapters and explicit --card-budget values.

**@⁠vanya890** on GitHub · 2026-12-06 01:27 UTC · [original](https://github.com/gamingwithhomie/larp/pull/393#issuecomment-7449188924) The allocation changes are narrowly gated and the 8-GiB A/B data is useful. Please add focused boundary tests for the policy selector and placement threshold: exactly 8 GiB versus just above 8 GiB, plus the `ASKED` fallback when `figures()` is unavailable. `tight_vram()` now controls heap sizing, pool caps, mapped-window limits, and idle release, while `may_place()` changes the headroom from 80% to 60%; a small regression test around those boundaries would make it safer to maintain this policy across adapters and explicit `--card-budget` values.
Author
Owner

@⁠TrinityForever15 on GitHub · 2026-12-06 03:17 UTC · original

Tested on RX 6650 XT 8 GB (RDNA 2), Series S profile, 1080p FSR Quality + FG 2x, together with #388 (LARP_HEAP_MB=64), #464, #435 and #392 on top of amd-test v1.1.7. Free heap space went from 1.1 GB to 662 MB, shared memory from 1.0 to 0.8 GB, and VRAM stayed steady at 7.4 GB. Combined with the others: 1% low 112 ms, 0.1% low 388 ms, longest frame 434 ms (up to 6,519 ms before). I haven't isolated this PR's share on its own. No regressions seen. I also recommended it to larp-amd for RX 6000 users: https://github.com/iceboerg00/larp-amd/issues/64

**@⁠TrinityForever15** on GitHub · 2026-12-06 03:17 UTC · [original](https://github.com/gamingwithhomie/larp/pull/393#issuecomment-7450571962) Tested on RX 6650 XT 8 GB (RDNA 2), Series S profile, 1080p FSR Quality + FG 2x, together with #388 (`LARP_HEAP_MB=64`), #464, #435 and #392 on top of `amd-test` v1.1.7. Free heap space went from 1.1 GB to 662 MB, shared memory from 1.0 to 0.8 GB, and VRAM stayed steady at 7.4 GB. Combined with the others: 1% low 112 ms, 0.1% low 388 ms, longest frame 434 ms (up to 6,519 ms before). I haven't isolated this PR's share on its own. No regressions seen. I also recommended it to larp-amd for RX 6000 users: https://github.com/iceboerg00/larp-amd/issues/64
This pull request can be merged automatically.
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 origin '+refs/pull/393/head:github-bot/gh-393'
git switch 'github-bot/gh-393'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-393'
git switch 'github-bot/gh-393'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-393'
git switch 'github-bot/gh-393'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-393'
git switch 'main'
git merge --squash 'github-bot/gh-393'
git switch 'main'
git merge --ff-only 'github-bot/gh-393'
git switch 'main'
git merge 'github-bot/gh-393'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.