GPU: pool HostList device-local UAV buffers and wire ahead::card_if_ready #884

Closed
Starchaser1024 wants to merge 0 commits from upstream-pr/884 into main
Starchaser1024 commented 2026-11-28 08:33:30 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Starchaser1024 on 2026-11-28T08:33:30Z.


Summary

Pools COMMON-state device-local scratch UAV buffers used by HostList (card_budget, indirect_scratch, batch_place, and place::between) across list resets and drops, and wires ahead::card_if_ready() into Host::uav_buffer — addressing the remaining per-list device-buffer churn noted in #57 (~13,500 buffers / 7.5 s of synchronous CreateCommittedResource + MakeResident + mapped() fence waits per 5 minutes, amplified now that VICTORY_ALLOCATOR_TRIM is on by default).

Design & Safety Invariants

  1. Preserving Shadow zero-initialization vs transient HostList scratch (crates/victory-gpu/src/host/uav_pool.rs, host.rs, ahead.rs):
    • Shadow (take, dword_runs, by_address) and ambient rely on Host::uav_buffer returning a freshly zero-initialized buffer. Host::uav_buffer therefore strictly preserves zero-initialized semantics (consulting ahead::card_if_ready() for 64 KiB pre-made zeroed buffers once CARD_WANTED is active, without spawning victory-ahead during victory warm).
    • uav_pool::take_uav(host, size) serves the four transient HostList scratch consumers (make_card_budget, indirect_scratch, batch_place, and place::between), each of which overwrites its region before reading.
  2. Exact Width power-of-two bucketing:
    • UAV_SPARE keys by exact GetDesc().Width in power-of-two multiples of 64 KiB (64 KiB minimum up to 16 MiB per item), so card_budget (64 KiB), batch_args (64 KiB), indirect_scratch, and place::between share unified buckets without altering GetDesc().Width expectations.
  3. D3D12 resource state & in-flight GPU safety:
    • HostList::between tracks buffers in Deferred::between_uavs and batch-transitions them back to D3D12_RESOURCE_STATE_COMMON in HostList::close() (between_common), matching card_budget_out, indirect_common, and batches_common.
    • On reset() or Drop for HostList (IDLE_MOST overflow and VICTORY_ALLOCATOR_TRIM), buffers pass through retire_uavs: entering UAV_SPARE immediately when no submissions are in flight, or waiting in RETIRED_UAVS until bury(finished) observes their fence completion.
  4. Caps, pressure trimming & switch:
    • Capped at 256 MiB (128 MiB on <= 32 GiB hosts), gated by VICTORY_UAV_POOL (default 1, =0 disables pooling), and hooked into Host::sweep() and trim_spare_chunks() (16 MiB warm floor under mild pressure / allocator_trim, 0 under critical commit or >= 95% VRAM).

Benchmark & Verification (RTX 5060 Ti 16 GB, Windows 11, --release)

host::uav_pool::tests::bench_host_list_uav_pool_ab (7 rounds each):

Workload VICTORY_UAV_POOL=0 VICTORY_UAV_POOL=1 Speedup
Steady-state reset() + 4x between copies across 64 HostLists (256 between buffers/round) 125.01 ms median 0.47 ms median 264.9x (-124.54 ms)
Full 64-HostList create + record (card_budget + batch_place + 2x between) + reset + drop churn 175.97 ms median (1,792 D3D12 UAVs made) 49.15 ms median (0 D3D12 UAVs made, 1,792 pool hits) 3.58x (-126.82 ms)
  • host::uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue: verified under VICTORY_D3D12_DEBUG=1 (0 ID3D12InfoQueue errors across card_budget, mid-list indirect_scratch growth, batch_place, between copy, reset(), in-flight retirement, and trim).
  • cargo test -p victory-gpu --locked: 457 passed, 0 failed.
  • cargo clippy --workspace --all-targets --all-features --locked: 0 warnings in changed files.
  • cargo xtask policy: 295 files ok.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5538346266 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/884). Originally posted by [Starchaser1024](https://github.com/Starchaser1024) on 2026-11-28T08:33:30Z. --- ## Summary Pools `COMMON`-state device-local scratch UAV buffers used by `HostList` (`card_budget`, `indirect_scratch`, `batch_place`, and `place::between`) across list resets and drops, and wires `ahead::card_if_ready()` into `Host::uav_buffer` — addressing the remaining per-list device-buffer churn noted in #57 (`~13,500` buffers / `7.5 s` of synchronous `CreateCommittedResource` + `MakeResident` + `mapped()` fence waits per 5 minutes, amplified now that `VICTORY_ALLOCATOR_TRIM` is on by default). ### Design & Safety Invariants 1. **Preserving `Shadow` zero-initialization vs transient `HostList` scratch (`crates/victory-gpu/src/host/uav_pool.rs`, `host.rs`, `ahead.rs`)**: - `Shadow` (`take`, `dword_runs`, `by_address`) and `ambient` rely on `Host::uav_buffer` returning a freshly zero-initialized buffer. `Host::uav_buffer` therefore strictly preserves zero-initialized semantics (consulting `ahead::card_if_ready()` for `64 KiB` pre-made zeroed buffers once `CARD_WANTED` is active, without spawning `victory-ahead` during `victory warm`). - `uav_pool::take_uav(host, size)` serves the four transient `HostList` scratch consumers (`make_card_budget`, `indirect_scratch`, `batch_place`, and `place::between`), each of which overwrites its region before reading. 2. **Exact `Width` power-of-two bucketing**: - `UAV_SPARE` keys by exact `GetDesc().Width` in power-of-two multiples of `64 KiB` (`64 KiB` minimum up to `16 MiB` per item), so `card_budget` (`64 KiB`), `batch_args` (`64 KiB`), `indirect_scratch`, and `place::between` share unified buckets without altering `GetDesc().Width` expectations. 3. **D3D12 resource state & in-flight GPU safety**: - `HostList::between` tracks buffers in `Deferred::between_uavs` and batch-transitions them back to `D3D12_RESOURCE_STATE_COMMON` in `HostList::close()` (`between_common`), matching `card_budget_out`, `indirect_common`, and `batches_common`. - On `reset()` or `Drop for HostList` (`IDLE_MOST` overflow and `VICTORY_ALLOCATOR_TRIM`), buffers pass through `retire_uavs`: entering `UAV_SPARE` immediately when no submissions are in flight, or waiting in `RETIRED_UAVS` until `bury(finished)` observes their fence completion. 4. **Caps, pressure trimming & switch**: - Capped at `256 MiB` (`128 MiB` on `<= 32 GiB` hosts), gated by `VICTORY_UAV_POOL` (default `1`, `=0` disables pooling), and hooked into `Host::sweep()` and `trim_spare_chunks()` (`16 MiB` warm floor under mild pressure / `allocator_trim`, `0` under critical commit or `>= 95%` VRAM). ## Benchmark & Verification (RTX 5060 Ti 16 GB, Windows 11, `--release`) `host::uav_pool::tests::bench_host_list_uav_pool_ab` (7 rounds each): | Workload | `VICTORY_UAV_POOL=0` | `VICTORY_UAV_POOL=1` | Speedup | | :--- | ---: | ---: | ---: | | Steady-state `reset()` + `4x between` copies across 64 `HostList`s (256 `between` buffers/round) | **125.01 ms** median | **0.47 ms** median | **264.9x** (`-124.54 ms`) | | Full 64-`HostList` create + record (`card_budget` + `batch_place` + `2x between`) + reset + drop churn | **175.97 ms** median (`1,792` D3D12 UAVs made) | **49.15 ms** median (`0` D3D12 UAVs made, `1,792` pool hits) | **3.58x** (`-126.82 ms`) | - `host::uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue`: verified under `VICTORY_D3D12_DEBUG=1` (`0` `ID3D12InfoQueue` errors across `card_budget`, mid-list `indirect_scratch` growth, `batch_place`, `between` copy, `reset()`, in-flight retirement, and trim). - `cargo test -p victory-gpu --locked`: 457 passed, 0 failed. - `cargo clippy --workspace --all-targets --all-features --locked`: 0 warnings in changed files. - `cargo xtask policy`: 295 files ok.
Alxspb commented 2026-11-28 14:17:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Alxspb on 2026-11-28T14:17:39Z.


Build break when this is merged on top of #1012 (found while building a play-test stack; both PRs are currently MERGEABLE against main, but not with each other).

error[E0061]: this method takes 2 arguments but 1 argument was supplied
  --> crates\victory-gpu\src\host\uav_pool.rs:96:83

#1012 gave Spare::take a predicate (host.rs: fn take(&mut self, size: u64, matches: impl Fn(&T) -> bool)) because SPARE holds two classes of chunk — upload (card_writable = false) and card-writable — and mixing them would push a GPU-writable buffer into the CPU-only path. uav_pool.rs still calls take(size).

For UAV_SPARE the predicate is genuinely a no-op, so the call site can adapt without changing what this pool does: every supplier puts in the same class of buffer (DEFAULT heap + ALLOW_UNORDERED_ACCESS, retired only after the recordings that wrote them have run, so they come back in COMMON state) — between/place_copy via ahead::card, indirect_scratch, batch_args, card_budget, drain_retired_uavs; the upload and shared chunks live in host.rs's own SPARE and never enter this one. So:

-        && let Some(buffer) = UAV_SPARE.lock().unwrap_or_else(|e| e.into_inner()).take(size)
+        && let Some(buffer) = UAV_SPARE
+            .lock()
+            .unwrap_or_else(|e| e.into_inner())
+            .take(size, |_| true)

I run exactly that in a 12-PR stack (#1002 #989 #1005 #65 #1014 #884 #941 #816 #797 #933 #934 #614 #1012) — green build here: https://github.com/Alxspb/VIctory-NVIDIA/actions/runs/46145821590 (the failing run before the fix: https://github.com/Alxspb/VIctory-NVIDIA/actions/runs/46145596521). Verified on an RTX 5060 Ti 16 GB / i5-13600KF, Series S job + DLSS Quality + 2x frame generation; the pool's own debug-layer reuse test is part of that stack, and VICTORY_UAV_POOL=0 is kept as the A/B switch.

If you would rather take the other direction (a take_where(size, pred) in host.rs so the old one-argument take stays), say so and I'll send the two-line change against your branch.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7240561784 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/884#issuecomment-7240561784). Originally posted by [Alxspb](https://github.com/Alxspb) on 2026-11-28T14:17:39Z. --- **Build break when this is merged on top of #1012** (found while building a play-test stack; both PRs are currently `MERGEABLE` against `main`, but not with each other). ``` error[E0061]: this method takes 2 arguments but 1 argument was supplied --> crates\victory-gpu\src\host\uav_pool.rs:96:83 ``` #1012 gave `Spare::take` a predicate (`host.rs`: `fn take(&mut self, size: u64, matches: impl Fn(&T) -> bool)`) because `SPARE` holds two classes of chunk — upload (`card_writable = false`) and card-writable — and mixing them would push a GPU-writable buffer into the CPU-only path. `uav_pool.rs` still calls `take(size)`. For `UAV_SPARE` the predicate is genuinely a no-op, so the call site can adapt without changing what this pool does: every supplier puts in the *same* class of buffer (DEFAULT heap + `ALLOW_UNORDERED_ACCESS`, retired only after the recordings that wrote them have run, so they come back in COMMON state) — `between`/`place_copy` via `ahead::card`, `indirect_scratch`, `batch_args`, `card_budget`, `drain_retired_uavs`; the upload and shared chunks live in `host.rs`'s own `SPARE` and never enter this one. So: ```diff - && let Some(buffer) = UAV_SPARE.lock().unwrap_or_else(|e| e.into_inner()).take(size) + && let Some(buffer) = UAV_SPARE + .lock() + .unwrap_or_else(|e| e.into_inner()) + .take(size, |_| true) ``` I run exactly that in a 12-PR stack (#1002 #989 #1005 #65 #1014 #884 #941 #816 #797 #933 #934 #614 #1012) — green build here: https://github.com/Alxspb/VIctory-NVIDIA/actions/runs/46145821590 (the failing run before the fix: https://github.com/Alxspb/VIctory-NVIDIA/actions/runs/46145596521). Verified on an RTX 5060 Ti 16 GB / i5-13600KF, Series S job + DLSS Quality + 2x frame generation; the pool's own debug-layer reuse test is part of that stack, and `VICTORY_UAV_POOL=0` is kept as the A/B switch. If you would rather take the other direction (a `take_where(size, pred)` in `host.rs` so the old one-argument `take` stays), say so and I'll send the two-line change against your branch.
Starchaser1024 commented 2026-11-28 15:12:24 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Starchaser1024 on 2026-11-28T15:12:24Z.


Thanks @Alxspb for testing #884 in your RTX 5060 Ti play-test stack and flagging the interaction with #1012!

Agreed — keeping 1-arg Spare::take(size) (delegating to take_where(size, pred) on #1012's side) is the cleanest path so both #884 and #1012 compile standalone against current main and merge cleanly in either order. And if #1012 lands on main first with the 2-arg signature, I'll rebase uav_pool.rs to .take(size, |_| true) right away.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7241285725 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/884#issuecomment-7241285725). Originally posted by [Starchaser1024](https://github.com/Starchaser1024) on 2026-11-28T15:12:24Z. --- Thanks @Alxspb for testing `#884` in your RTX 5060 Ti play-test stack and flagging the interaction with `#1012`! Agreed — keeping 1-arg `Spare::take(size)` (delegating to `take_where(size, pred)` on `#1012`'s side) is the cleanest path so both `#884` and `#1012` compile standalone against current `main` and merge cleanly in either order. And if `#1012` lands on `main` first with the 2-arg signature, I'll rebase `uav_pool.rs` to `.take(size, |_| true)` right away.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!884
No description provided.