victory-gpu: small device-local buffers placed together (about 1.2 GB of the card on AMD) #331

Closed
github-bot wants to merge 0 commits from github-bot/gh-331 into main AGit
Owner

@⁠Bushyon on GitHub · 2026-12-01 13:57 UTC · original
Bushyon:small-buffers-placed-together → main · +304 −6 · 5 files · 72 commits · closed without merging

Small device-local buffers placed together (about 1.2 GB of the card on AMD)

What was wrong

Every buffer Host::uav_buffer makes is a committed resource. The AMD driver gives each committed resource in local video memory 256 KiB of the card, however small it is. Several kinds of buffers foxhound makes by the thousands are far smaller:

Maker Count (2.3 min in) Size each
title buffers' card copies (shadow::card_room_for, ahead) ~7,400 64 KiB
indirect batch buffers (HostList::batch_place) ~3,000 64 KiB
indirect budgets (HostList::make_card_budget) ~1,200 256 bytes
card copies' piece hashes (card_make_before), window card copies hundreds tens of bytes / up to 256 KiB

An RMV memory trace (RX 7800 XT 16 GB, driver 32.0.32029.2010, Series X profile at 1440p, standing in the world 2.3 minutes after loading, launcher's default switches) had 8,622 allocations of 256 KiB: 2,156 MB of the card holding 463 MB of buffers (21% used). The 4 MiB blocks next to them were 90% full.

What this changes

New crates/victory-gpu/src/card_pool.rs: buffers of 256 KiB or less are placed in shared 4 MiB ALLOW_ONLY_BUFFERS heaps at 64 KiB multiples (a buffer's placement alignment) instead of being committed one by one. The six makers above ask the pool first and fall back to uav_buffer if it can't place one.

Reuse is safe without changing any owner: the pool keeps its own reference to every buffer it placed, and a slot is taken again only once that reference is the last one (host::references), i.e. no copy, host list or heap slot holds the buffer, so no recorded or in-flight work can read it. Owners drop their buffers exactly as they dropped committed ones. Reclaiming runs when the pool has no room, and at most once a second otherwise.

VICTORY_CARD_POOL=0 turns it off (every buffer committed, as before).

Measured (same switches and scene, RMV traces, 2.3 minutes in)

Before After
Separate 256 KiB allocations 8,622 (2,156 MB) 1,362 (340 MB; 1,215 of them command allocators)
Pooled buffers – 10,087 in 161 heaps, 640 of 644 MB used
Card's use outside the texture heaps 7.4 GB 6.4 GB
Video memory spilled to system memory 0.12 GB 0.02 GB

Texture heaps varied 5.5–6.3 GB between runs, so the comparison leaves them out. Every run rendered normally (38–42 FPS log lines a run), with no device removal.

Tests

  • cargo clippy --workspace-equivalent for victory-gpu, with and without --all-features, -D warnings: clean.
  • cargo test --workspace --locked: all pass, apart from watch::tests::faults_that_take_no_lock_tell_the_same. That test fails about 1 run in 3 on unmodified main too (it passes alone), so it is timing-sensitive under the parallel run, not this change.
  • New tests in card_pool: slot masks, finding runs of free slots, and a slot not being given out again while its buffer is still held.
  • cargo xtask policy --staged: 5 files ok.

#327 and #276 tune texture eviction and reserves in pool.rs / resource.rs. This PR doesn't touch those files, and its saving stacks with theirs. #290 changes the same ahead.rs line (host.uav_buffer(SIZE)); whichever merges second needs a one-line merge.

Not in this PR, but seen while measuring

  • shadow::by_address keeps its card-memory total in a function-local counter that only grows. It is never lowered when a copy goes, and is raised even when uav_buffer fails. After 4 GiB has passed through it in a session, every later copy goes to PC memory even with room on the card. Only ray-tracing runs use it.
  • Hands-off runs with these switches crashed in the title's code twice in eight starts, ~40 s in (write to address 0, victory-image-…dll+0x2215c35). This was before and after this change, so it isn't related to it.
  • With the launcher's defaults at 1440p, the process passed 30 GB of RAM within 3 minutes standing still (19 GB of it mapped file memory, 5.5 GB of that resident).

🤖 Generated with Claude Code

**@⁠Bushyon** on GitHub · 2026-12-01 13:57 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/331) `Bushyon:small-buffers-placed-together` → `main` · +304 −6 · 5 files · 72 commits · closed without merging ## Small device-local buffers placed together (about 1.2 GB of the card on AMD) ### What was wrong Every buffer `Host::uav_buffer` makes is a committed resource. The AMD driver gives each committed resource in local video memory **256 KiB of the card, however small it is**. Several kinds of buffers foxhound makes by the thousands are far smaller: | Maker | Count (2.3 min in) | Size each | |---|---|---| | title buffers' card copies (`shadow::card_room_for`, `ahead`) | ~7,400 | 64 KiB | | indirect batch buffers (`HostList::batch_place`) | ~3,000 | 64 KiB | | indirect budgets (`HostList::make_card_budget`) | ~1,200 | 256 bytes | | card copies' piece hashes (`card_make_before`), window card copies | hundreds | tens of bytes / up to 256 KiB | An RMV memory trace (RX 7800 XT 16 GB, driver 32.0.32029.2010, Series X profile at 1440p, standing in the world 2.3 minutes after loading, launcher's default switches) had **8,622 allocations of 256 KiB: 2,156 MB of the card holding 463 MB of buffers (21% used)**. The 4 MiB blocks next to them were 90% full. ### What this changes New `crates/victory-gpu/src/card_pool.rs`: buffers of 256 KiB or less are placed in shared 4 MiB `ALLOW_ONLY_BUFFERS` heaps at 64 KiB multiples (a buffer's placement alignment) instead of being committed one by one. The six makers above ask the pool first and fall back to `uav_buffer` if it can't place one. Reuse is safe without changing any owner: the pool keeps its own reference to every buffer it placed, and a slot is taken again only once that reference is the last one (`host::references`), i.e. no copy, host list or heap slot holds the buffer, so no recorded or in-flight work can read it. Owners drop their buffers exactly as they dropped committed ones. Reclaiming runs when the pool has no room, and at most once a second otherwise. `VICTORY_CARD_POOL=0` turns it off (every buffer committed, as before). ### Measured (same switches and scene, RMV traces, 2.3 minutes in) | | Before | After | |---|---|---| | Separate 256 KiB allocations | 8,622 (2,156 MB) | 1,362 (340 MB; 1,215 of them command allocators) | | Pooled buffers | – | 10,087 in 161 heaps, 640 of 644 MB used | | Card's use outside the texture heaps | 7.4 GB | 6.4 GB | | Video memory spilled to system memory | 0.12 GB | 0.02 GB | Texture heaps varied 5.5–6.3 GB between runs, so the comparison leaves them out. Every run rendered normally (38–42 FPS log lines a run), with no device removal. ### Tests - `cargo clippy --workspace`-equivalent for `victory-gpu`, with and without `--all-features`, `-D warnings`: clean. - `cargo test --workspace --locked`: all pass, apart from `watch::tests::faults_that_take_no_lock_tell_the_same`. That test fails about 1 run in 3 **on unmodified `main` too** (it passes alone), so it is timing-sensitive under the parallel run, not this change. - New tests in `card_pool`: slot masks, finding runs of free slots, and a slot not being given out again while its buffer is still held. - `cargo xtask policy --staged`: 5 files ok. ### Related open PRs #327 and #276 tune texture eviction and reserves in `pool.rs` / `resource.rs`. This PR doesn't touch those files, and its saving stacks with theirs. #290 changes the same `ahead.rs` line (`host.uav_buffer(SIZE)`); whichever merges second needs a one-line merge. ### Not in this PR, but seen while measuring - `shadow::by_address` keeps its card-memory total in a function-local counter that only grows. It is never lowered when a copy goes, and is raised even when `uav_buffer` fails. After 4 GiB has passed through it in a session, every later copy goes to PC memory even with room on the card. Only ray-tracing runs use it. - Hands-off runs with these switches crashed in the title's code twice in eight starts, ~40 s in (write to address 0, `victory-image-…dll+0x2215c35`). This was before and after this change, so it isn't related to it. - With the launcher's defaults at 1440p, the process passed 30 GB of RAM within 3 minutes standing still (19 GB of it mapped file memory, 5.5 GB of that resident). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Every buffer Host::uav_buffer makes is committed, and the AMD driver gives each
committed resource in local memory 256 KiB of the card however small it is. An
RMV trace (RX 7800 XT, Series X profile at 1440p, 2.3 minutes into the world)
had 8,622 such allocations: 2,156 MB of the card holding 463 MB of buffers,
mostly 64 KiB card copies of title buffers, indirect batch buffers, 256-byte
indirect budgets and a copy's piece hashes.

card_pool places buffers of 256 KiB or less in 4 MiB buffer heaps at 64 KiB
multiples instead. The pool keeps a reference to each buffer it placed and
takes a slot again only once that reference is the last (no copy, list or heap
slot holds the buffer), so owners drop buffers as they did committed ones.

Same run with the pool: 10,087 buffers in 161 heaps (640 of 644 MB used);
the card's use outside the texture heaps 7.4 -> 6.4 GB; video memory spilled
to system memory 0.12 -> 0.02 GB. VICTORY_CARD_POOL=0: committed, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 13:59:38 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-12-01 14:00 UTC · original

Ran the card_pool::tests group at 542e329 on an NVIDIA Blackwell desktop part with 16 GB of VRAM. The PR's measured 1.2 GB saving is on AMD, where committed small buffers cost 256 KiB each; this NVIDIA adapter runs the same synthetic tests but does not reproduce that driver behaviour.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own CARGO_TARGET_DIR, no local patches.

cargo test -q --locked -p victory-gpu --lib card_pool::tests -- --test-threads=1
3 passed; 0 failed; 0 ignored; 512 filtered out      (exit 0)

All three new tests pass here: slot masks, finding runs of free slots, and not reusing a slot while its buffer is still held. The description's full workspace run and the AMD RMV trace were not repeated.

Not tested: the full workspace suite, a retail title, VRAM-savings on this adapter, AMD adapters, Wine, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-12-01 14:00 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/331#issuecomment-7313549613) Ran the `card_pool::tests` group at `542e329` on an NVIDIA Blackwell desktop part with 16 GB of VRAM. The PR's measured 1.2 GB saving is on AMD, where committed small buffers cost 256 KiB each; this NVIDIA adapter runs the same synthetic tests but does not reproduce that driver behaviour. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own `CARGO_TARGET_DIR`, no local patches. ``` cargo test -q --locked -p victory-gpu --lib card_pool::tests -- --test-threads=1 3 passed; 0 failed; 0 ignored; 512 filtered out (exit 0) ``` All three new tests pass here: slot masks, finding runs of free slots, and not reusing a slot while its buffer is still held. The description's full workspace run and the AMD RMV trace were not repeated. Not tested: the full workspace suite, a retail title, VRAM-savings on this adapter, AMD adapters, Wine, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
github-bot closed this pull request 2026-12-02 07:54:40 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.