perf(gpu): opt-in LARP_HEAP_MB for smaller placed-buffer heaps on 8 GB cards #388

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

@⁠gaut33680-sudo on GitHub · 2026-12-06 00:03 UTC · original
gaut33680-sudo:heap-size-option → main · +183 −43 · 2 files · 2 commits · open

What

Adds an opt-in environment variable, LARP_HEAP_MB (32, 64 or 128), for the size of the heaps of placed buffers in crate::heaps (upload, read-back, scratch, ray-tracing structure and geometry tiles).

  • Unset, the size stays 128 MiB and nothing changes.
  • The size is never below MOST (32 MiB), so every piece still fits.
  • The streamed textures' heaps (crate::texheap) are not touched.
  • Documented in docs/environment-variables.md.

Why

A heap goes back to the card only once every piece in it is free, so a few live pieces can keep whole 128 MiB heaps taken. On an 8 GB card whose memory is full, the F9 panel showed about 1.0 GB in "free in the heaps" while about 1.0 GB had spilled into shared (system) memory. Smaller heaps empty and go back sooner, at the cost of a few more CreateHeap calls.

Testing

  • RTX 2070 Super 8 GB (no Resizable BAR), Ryzen 5 3600XT, 16 GB RAM, Windows; series-s, 1920x1080 output, FSR balanced, FSR frame generation 2x.
  • Built from v1.1.3 with LARP_HEAP_MB=64 (alongside an unrelated local change), two sessions of about 10 minutes of driving: no errors or crashes; the log line confirms mb=64.
  • F9 "free in the heaps": about 1.0 GB in an earlier session at 128 MiB; with 64 MiB, 1.3 GB in the first session and 416 MB in the second (VRAM 6.5 / 6.6 / 7.1 GB, shared 0.9 GB).
  • That row also counts the streamed textures' heaps and the routes differed, so the gain from this change alone is not isolated yet. An A/B on one route (LARP_HEAP_MB unset vs 64) would settle it, which is why it is opt-in.
  • cargo check -p larp-gpu --target x86_64-pc-windows-msvc on current main.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QHHCB138ncHJF4i3kpiP16

**@⁠gaut33680-sudo** on GitHub · 2026-12-06 00:03 UTC · [original](https://github.com/gamingwithhomie/larp/pull/388) `gaut33680-sudo:heap-size-option` → `main` · +183 −43 · 2 files · 2 commits · open ## What Adds an opt-in environment variable, `LARP_HEAP_MB` (`32`, `64` or `128`), for the size of the heaps of placed buffers in `crate::heaps` (upload, read-back, scratch, ray-tracing structure and geometry tiles). - Unset, the size stays 128 MiB and nothing changes. - The size is never below `MOST` (32 MiB), so every piece still fits. - The streamed textures' heaps (`crate::texheap`) are not touched. - Documented in `docs/environment-variables.md`. ## Why A heap goes back to the card only once every piece in it is free, so a few live pieces can keep whole 128 MiB heaps taken. On an 8 GB card whose memory is full, the F9 panel showed about 1.0 GB in "free in the heaps" while about 1.0 GB had spilled into shared (system) memory. Smaller heaps empty and go back sooner, at the cost of a few more `CreateHeap` calls. ## Testing - RTX 2070 Super 8 GB (no Resizable BAR), Ryzen 5 3600XT, 16 GB RAM, Windows; `series-s`, 1920x1080 output, FSR balanced, FSR frame generation 2x. - Built from v1.1.3 with `LARP_HEAP_MB=64` (alongside an unrelated local change), two sessions of about 10 minutes of driving: no errors or crashes; the log line confirms `mb=64`. - F9 "free in the heaps": about 1.0 GB in an earlier session at 128 MiB; with 64 MiB, 1.3 GB in the first session and 416 MB in the second (VRAM 6.5 / 6.6 / 7.1 GB, shared 0.9 GB). - That row also counts the streamed textures' heaps and the routes differed, so the gain from this change alone is not isolated yet. An A/B on one route (`LARP_HEAP_MB` unset vs `64`) would settle it, which is why it is opt-in. - `cargo check -p larp-gpu --target x86_64-pc-windows-msvc` on current `main`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QHHCB138ncHJF4i3kpiP16
The heaps of placed buffers (`crate::heaps`) are 128 MiB each, and a heap
goes back to the card only once every piece in it is free. On an 8 GB card
whose memory is full (RTX 2070 Super, series-s, 1080p FSR balanced: VRAM
6.9 GB against a 6.6 GB target, 1.0 GB spilled to shared memory), the F9
panel's "free in the heaps" row reads 1.0-1.3 GB: a few live pieces keep
whole 128 MiB heaps taken.

`LARP_HEAP_MB` (32, 64 or 128; unset: 128, unchanged) sets the heap size for
the run. Smaller heaps empty and go back sooner, for a few more heap
creations. The largest piece (32 MiB) still fits: the size is never below it.
Off by default; the streamed textures' heaps (`crate::texheap`) are not
touched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QHHCB138ncHJF4i3kpiP16
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 00:06:54 +00:00
Author
Owner

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

The implementation consistently replaces the former fixed 128 MiB constant, including the empty-heap check and host-memory accounting, and keeping this opt-in is the right choice until a controlled A/B isolates the benefit. The main missing regression coverage is the boundary behavior: 32 MiB is exactly MOST, while requests larger than MOST are committed instead of placed. Could you add a small pure test for the accepted values (32/64/128) and fallback for unset/invalid input, plus a check that a 32 MiB heap is considered empty after its final piece is returned? Current runtime evidence only covers 64 MiB.

**@⁠vanya890** on GitHub · 2026-12-06 01:19 UTC · [original](https://github.com/gamingwithhomie/larp/pull/388#issuecomment-7449085768) The implementation consistently replaces the former fixed 128 MiB constant, including the empty-heap check and host-memory accounting, and keeping this opt-in is the right choice until a controlled A/B isolates the benefit. The main missing regression coverage is the boundary behavior: 32 MiB is exactly `MOST`, while requests larger than `MOST` are committed instead of placed. Could you add a small pure test for the accepted values (32/64/128) and fallback for unset/invalid input, plus a check that a 32 MiB heap is considered empty after its final piece is returned? Current runtime evidence only covers 64 MiB.
Author
Owner

@⁠gaut33680-sudo on GitHub · 2026-12-06 01:32 UTC · original

Thanks for the review! Added in 6f154f6:

  • heap_size_of, the pure part of heap_size: 32/64/128 accepted; unset or invalid values (empty, non-numeric, 64MB, negative, 0, 16, 256) fall back to 128 MiB.
  • piece_len: the placed/committed boundary (MOST is placed, MOST + 1 is committed).
  • Free: the free-piece bookkeeping, moved out of Heap unchanged so it can be tested without a device. One test checks that a 32 MiB heap filled by a single MOST piece is empty once that piece is returned. Another checks that a 32 MiB heap split into several pieces is empty only after the last one is returned (joined on both sides).

Checked with cargo check --tests for x86_64-pc-windows-msvc, and the pure parts pass under cargo test. Runtime evidence still only covers 64 MiB.

**@⁠gaut33680-sudo** on GitHub · 2026-12-06 01:32 UTC · [original](https://github.com/gamingwithhomie/larp/pull/388#issuecomment-7449263633) Thanks for the review! Added in 6f154f6: - `heap_size_of`, the pure part of `heap_size`: 32/64/128 accepted; unset or invalid values (empty, non-numeric, `64MB`, negative, 0, 16, 256) fall back to 128 MiB. - `piece_len`: the placed/committed boundary (`MOST` is placed, `MOST + 1` is committed). - `Free`: the free-piece bookkeeping, moved out of `Heap` unchanged so it can be tested without a device. One test checks that a 32 MiB heap filled by a single `MOST` piece is empty once that piece is returned. Another checks that a 32 MiB heap split into several pieces is empty only after the last one is returned (joined on both sides). Checked with `cargo check --tests` for x86_64-pc-windows-msvc, and the pure parts pass under `cargo test`. Runtime evidence still only covers 64 MiB.
- heap_size_of: the pure part of heap_size (32/64/128 accepted, unset or
  invalid values fall back to 128 MiB, never under MOST).
- piece_len: the placed/committed boundary of buffer() (MOST is placed,
  MOST + 1 is committed).
- Free: a heap's free-piece bookkeeping (first piece, fit, take,
  give_back with joining, empty), moved out of Heap unchanged so it can be
  tested without a device. Heap, take and put_back use it.
- Tests: accepted values and fallbacks, the MOST boundary, a 32 MiB heap
  whose single MOST piece fills it and is empty once that piece is back,
  and one emptied only by its last piece (joined on both sides).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QHHCB138ncHJF4i3kpiP16
Author
Owner

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

Thanks, this closes the test gap from my review: the accepted/fallback values, the exact MOST placement boundary, and both single-piece and multi-piece free-list coalescing are now covered without a D3D12 device. The remaining limitation is still that runtime A/B evidence only covers 64 MiB, so keeping the setting opt-in is the right scope for this PR. No further concern from my earlier review.

**@⁠vanya890** on GitHub · 2026-12-06 01:36 UTC · [original](https://github.com/gamingwithhomie/larp/pull/388#issuecomment-7449312323) Thanks, this closes the test gap from my review: the accepted/fallback values, the exact `MOST` placement boundary, and both single-piece and multi-piece free-list coalescing are now covered without a D3D12 device. The remaining limitation is still that runtime A/B evidence only covers 64 MiB, so keeping the setting opt-in is the right scope for this PR. No further concern from my earlier review.
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/388/head:github-bot/gh-388'
git switch 'github-bot/gh-388'

Merge

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