perf(gpu): batch scattered indirect clamps and coalesce ready queue parts #43

Open
github-bot wants to merge 1 commit from github-bot/gh-43 into beta AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 21:05 UTC · original
Vladimir-Human:perf/indirect-gather-join → beta · +5464 −1539 · 5 files · 1 commits · open

AI-assisted clean-room contribution (victory-gpu, D3D12 unit/WARP/hardware tests + synthetic indirect & ready-queue benchmarks only — no title files used).

Summary

Combines scattered indirect argument clamping (VICTORY_INDIRECT_GATHER, on by default, off via =0) and ready-queue adjacent part coalescing (VICTORY_JOIN_PARTS, on by default, off via =0) across crates/victory-gpu/src/{draw.rs, host.rs, indirect.rs, list.rs, queue.rs} while integrating klbf-lab's existing BufferStates (ae89047) and compute group diagnostics (015af28):

  1. Scattered indirect gather-clamp + hoisted mode-7 clamping (indirect.rs, draw.rs, list.rs, host.rs):
    • Batches non-contiguous indirect draw/dispatch argument records into two-pass gather dispatches (GATHER_PASS1_CS -> GATHER_PASS2_CS) with batched mid-pass UAV barriers across costs_res, budget_res, and distinct destination chunks.
    • Emits budget UAV barriers on mid-list flushes and scalar fallbacks, retains referenced SRV/UAV resources when record_pending_scalar falls back under allocation failure, caps raw ByteAddressBuffer element counts at (1 << 30) - 1 (4 GiB - 4 B), and calls sources_read(clamps, ...) for BufferStates.
  2. Ready-queue part coalescing (queue.rs, host.rs):
    • Coalesces adjacent safe Part submissions under VICTORY_JOIN_PARTS, blocking coalescing on backs/texture_backs/back_wanted, overlapping GpuWrite/writes vs blocked_by/Refresh/cross-shadow aliasing, WAR hazards (Refresh/Texture vs Copy/Step::Run), and Held::Value wait-range writes (lists_write_range).
  • Sibling PR compatibility: git merge-tree clean against beta (e328c88), #15, #41, #42, and our pending lazy-copyback/VRAM branches.

Verification (beta e328c88, RTX 4070 SUPER / i5-13400F)

  • cargo clippy -p victory-gpu --all-targets (default & --features diagnostics): 0 warnings in added/modified code.
  • cargo test -p victory-gpu -- --test-threads=1: 161 passed, 0 failed (5 ignored).
  • VICTORY_D3D12_DEBUG=1 VICTORY_REQUIRE_HW_GPU=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1: 169 passed, 0 failed (6/6 live hw_gather_ / hw_coalesce_ tests including multi-frame HostList::reset reuse with 0 D3D12 debug errors/warnings), and kill switches (VICTORY_INDIRECT_GATHER=0, VICTORY_JOIN_PARTS=0, VICTORY_HOIST_CLAMPS=0) all pass.
  • Hardware benchmarks (under parallel build load; uncontested run planned): gather-clamp 62.92x–98.38x GPU speedup across 1–256 buffers (86.56x at 256 buffers); join_parts 7.47x–12.89x (16 -> 1 submissions).
**@⁠Vladimir-Human** on GitHub · 2026-11-25 21:05 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/43) `Vladimir-Human:perf/indirect-gather-join` → `beta` · +5464 −1539 · 5 files · 1 commits · open AI-assisted clean-room contribution (`victory-gpu`, D3D12 unit/WARP/hardware tests + synthetic indirect & ready-queue benchmarks only — no title files used). ### Summary Combines scattered indirect argument clamping (`VICTORY_INDIRECT_GATHER`, on by default, off via `=0`) and ready-queue adjacent part coalescing (`VICTORY_JOIN_PARTS`, on by default, off via `=0`) across `crates/victory-gpu/src/{draw.rs, host.rs, indirect.rs, list.rs, queue.rs}` while integrating `klbf-lab`'s existing `BufferStates` (`ae89047`) and compute group diagnostics (`015af28`): 1. **Scattered indirect gather-clamp + hoisted mode-7 clamping (`indirect.rs`, `draw.rs`, `list.rs`, `host.rs`)**: - Batches non-contiguous indirect draw/dispatch argument records into two-pass gather dispatches (`GATHER_PASS1_CS -> GATHER_PASS2_CS`) with batched mid-pass UAV barriers across `costs_res`, `budget_res`, and distinct destination chunks. - Emits budget UAV barriers on mid-list flushes and scalar fallbacks, retains referenced SRV/UAV resources when `record_pending_scalar` falls back under allocation failure, caps raw `ByteAddressBuffer` element counts at `(1 << 30) - 1` (`4 GiB - 4 B`), and calls `sources_read(clamps, ...)` for `BufferStates`. 2. **Ready-queue part coalescing (`queue.rs`, `host.rs`)**: - Coalesces adjacent safe `Part` submissions under `VICTORY_JOIN_PARTS`, blocking coalescing on `backs`/`texture_backs`/`back_wanted`, overlapping `GpuWrite`/`writes` vs `blocked_by`/`Refresh`/cross-shadow aliasing, WAR hazards (`Refresh`/`Texture` vs `Copy`/`Step::Run`), and `Held::Value` wait-range writes (`lists_write_range`). - **Sibling PR compatibility**: `git merge-tree` clean against `beta` (`e328c88`), `#15`, `#41`, `#42`, and our pending lazy-copyback/VRAM branches. ### Verification (`beta` `e328c88`, RTX 4070 SUPER / i5-13400F) - `cargo clippy -p victory-gpu --all-targets` (`default` & `--features diagnostics`): **0 warnings** in added/modified code. - `cargo test -p victory-gpu -- --test-threads=1`: **161 passed, 0 failed** (5 ignored). - `VICTORY_D3D12_DEBUG=1 VICTORY_REQUIRE_HW_GPU=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1`: **169 passed, 0 failed** (`6/6` live `hw_gather_` / `hw_coalesce_` tests including multi-frame `HostList::reset` reuse with **0 D3D12 debug errors/warnings**), and kill switches (`VICTORY_INDIRECT_GATHER=0`, `VICTORY_JOIN_PARTS=0`, `VICTORY_HOIST_CLAMPS=0`) all pass. - Hardware benchmarks (under parallel build load; uncontested run planned): gather-clamp **62.92x–98.38x** GPU speedup across 1–256 buffers (`86.56x` at 256 buffers); `join_parts` **7.47x–12.89x** (`16 -> 1` submissions).
- Port hoisted indirect argument clamps (VICTORY_HOIST_CLAMPS, mode 7 default)
  and GPU gather-clamp batching (VICTORY_INDIRECT_GATHER, on by default):
  - Single-pass [numthreads(64,1,1)] prefix-sum shader for <= 8 uniform groups
    and 2-pass parallel gather + exact original-order budget pass for scattered
    multi-buffer batches, preserving compute and mesh budget diagnostics.
  - Preserves BufferStates source/count read tracking (sources_read), gates
    hoist reuse on dispatches, buffer-writing draws, copies, readbacks, and
    bottom-of-pipe writes, and skips hoisting when cut-waits is disabled.
  - Enforces all F1-F5 audit invariants: mid-pass UAV barriers over costs,
    budget, and all destination chunks; budget UAV barriers across flushes and
    scalar fallbacks; allocation-failure scalar fallback retaining SRV/UAV
    lifetimes; 2^30 - 1 raw SRV/UAV element cap.
- Port ready-queue part coalescing (VICTORY_JOIN_PARTS, on by default):
  - Coalesces consecutive ready Held::Run parts across satisfied Wait/Value
    gates while stopping at Held::Signal, unsatisfied waits, or CPU/GPU hazards.
  - Preserves F3/F4 WAR refresh/copy/Run checks, texture copy-back checks, and
    lists_write_range guard preventing stale CPU wait bypasses.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:53:25 +00:00
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 21:08 UTC · original

Thanks a lot @⁠Vladimir-Human! The indirect clamps are one of the costs we are looking at right now, so this one goes first in our queue. We test one change at a time on the RX 9070 XT (same save, same 7-minute run, fps and picture compared with our reference build, with and without VICTORY_INDIRECT_GATHER / VICTORY_JOIN_PARTS). Results will be posted here.

**@⁠PastiiJay** on GitHub · 2026-11-25 21:08 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/43#issuecomment-7174655807) Thanks a lot @⁠Vladimir-Human! The indirect clamps are one of the costs we are looking at right now, so this one goes first in our queue. We test one change at a time on the RX 9070 XT (same save, same 7-minute run, fps and picture compared with our reference build, with and without `VICTORY_INDIRECT_GATHER` / `VICTORY_JOIN_PARTS`). Results will be posted here.
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-25 21:20 UTC · original

I ran both switches independently on Microsoft WARP at 4f71557, using the PR source unchanged. With VICTORY_JOIN_PARTS=0, the queue fixture observed four submissions. At =1, it observed one, with the same four written values. The unsatisfied-wait and intervening-fence checks passed in both runs. With VICTORY_INDIRECT_GATHER=0 and =1, the end-to-end test read back the expected indirect arguments, including the clamped record. Each setting ran in a fresh process and required a D3D12 device. All four runs passed. Windows test log

That gives the RX 9070 XT comparison a correctness baseline for the two switches. The software-adapter tests did not measure in-game timing.

**@⁠HandshakeHackin** on GitHub · 2026-11-25 21:20 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/43#issuecomment-7174941288) I ran both switches independently on Microsoft WARP at `4f71557`, using the PR source unchanged. With `VICTORY_JOIN_PARTS=0`, the queue fixture observed four submissions. At `=1`, it observed one, with the same four written values. The unsatisfied-wait and intervening-fence checks passed in both runs. With `VICTORY_INDIRECT_GATHER=0` and `=1`, the end-to-end test read back the expected indirect arguments, including the clamped record. Each setting ran in a fresh process and required a D3D12 device. All four runs passed. [Windows test log](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45702812697/job/139517020229) That gives the RX 9070 XT comparison a correctness baseline for the two switches. The software-adapter tests did not measure in-game timing.
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 21:21 UTC · original

Thanks @⁠HandshakeHackin, that's exactly the baseline we wanted before the hardware runs. What we keep: on WARP, with each switch tested on its own in a fresh process, VICTORY_JOIN_PARTS=1 folds four submissions into one with the same written values and the wait/fence checks still passing, and VICTORY_INDIRECT_GATHER reads back the expected indirect arguments either way, clamped record included.

So when we run #43 on the RX 9070 XT, any difference we see in fps or picture comes from the GPU path, not from correctness. We'll post the on/off results for both switches here.

**@⁠PastiiJay** on GitHub · 2026-11-25 21:21 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/43#issuecomment-7174962034) Thanks @⁠HandshakeHackin, that's exactly the baseline we wanted before the hardware runs. What we keep: on WARP, with each switch tested on its own in a fresh process, `VICTORY_JOIN_PARTS=1` folds four submissions into one with the same written values and the wait/fence checks still passing, and `VICTORY_INDIRECT_GATHER` reads back the expected indirect arguments either way, clamped record included. So when we run #43 on the RX 9070 XT, any difference we see in fps or picture comes from the GPU path, not from correctness. We'll post the on/off results for both switches here.
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/43/head:github-bot/gh-43'
git switch 'github-bot/gh-43'

Merge

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