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

Closed
Vladimir-Human wants to merge 121 commits from upstream-pr/43 into main
Vladimir-Human commented 2026-11-25 21:05:50 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T21:05:50Z.


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).
<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5499169820 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/43). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T21:05:50Z. --- 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).
PastiiJay commented 2026-11-25 21:08:01 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:08:01Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7174655807 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/43#issuecomment-7174655807). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T21:08:01Z. --- 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.
HandshakeHackin commented 2026-11-25 21:20:18 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-25T21:20:18Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7174941288 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/43#issuecomment-7174941288). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-25T21:20:18Z. --- 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.
PastiiJay commented 2026-11-25 21:21:12 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:21:12Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7174962034 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/43#issuecomment-7174962034). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T21:21:12Z. --- 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.
Vladimir-Human commented 2026-11-28 18:35:42 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:35:42Z.


Superseded by https://github.com/PastiiJay/klbf-lab/pull/188 cleanly ported onto origin/stable-amd (75022ba).

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7243909838 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/43#issuecomment-7243909838). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-28T18:35:42Z. --- Superseded by https://github.com/PastiiJay/klbf-lab/pull/188 cleanly ported onto `origin/stable-amd` (`75022ba`).

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
PastiiJay/klbf-lab!43
No description provided.