gpu: compact non-empty indirect draw and dispatch arguments #2201

Open
github-bot wants to merge 1 commit from github-bot/gh-2201 into main AGit
Owner

@⁠UnkwnDev on GitHub · 2026-11-25 07:39 UTC · original
UnkwnDev:arc-indirect-compaction → main · +473 −49 · 3 files · 1 commits · open

Split out from #740 per triage feedback, rebased and re-designed onto current main (940d32f).

Adds an indirect draw/dispatch argument stream compaction pass inside crates/victory-gpu/src/indirect.rs, backed by per-list shared compaction scratch arenas in crates/victory-gpu/src/host.rs and wired into crates/victory-gpu/src/draw.rs:

  • Extends indirect::SOURCE (the single-group tiled clamp shader on main) so lane 0 computes per-tile compacted output indices sequentially in groupshared memory when do_compact != 0 (counter.is_none()), writing surviving non-empty records (cost > 0 within the list budget) into the compacted buffer and recording the final compacted count at offset 0.
  • Because main walks every tile of 64 within one compute threadgroup, compaction uses zero global atomics and strictly preserves command submission order for any record count.
  • ExecuteIndirect reads from the compacted argument stream and count buffer when compaction is active, skipping empty/zero-vertex/zero-group records on the GPU without stalling command execution.
  • Adds compaction_preserves_order_and_drops_empty_records covering multi-tile compaction (150 records) and zero-record batches.

Testing

  • Hardware: Intel Arc A770 (Windows 11, DXC 1.9.2602.17)
  • cargo test -p victory-gpu --lib indirect -- --test-threads=1 (with and without VICTORY_D3D12_DEBUG=1): 6 passed, 0 failed (compaction_preserves_order_and_drops_empty_records, argument_clamp_builds, rejected_records_do_not_wrap_the_budget, the_budget_goes_to_the_first_records, a_record_that_does_not_fit_ends_the_budget, a_spent_budget_stays_spent).
  • cargo clippy -p victory-gpu --all-targets --locked and --all-features: clean on all modified files (indirect.rs, host.rs, draw.rs; 2 pre-existing fetch_update deprecation warnings in object.rs).
  • cargo test -p xtask --locked: 6 passed, 0 failed (repository_passes_policy).
  • cargo test -p victory-gpu --lib -- --test-threads=1: 141 passed, 3 failed, 2 ignored (the 3 failures are unrelated baseline failures on this adapter: descriptor::host::tests::dynamic_slots_are_held_until_released, draw::tests::a_depth_texture_written_through_unordered_views_reads_as_depth, memory::tests::lists_share_a_table_and_copies_keep_their_views).

AI use

  • Antigravity (Gemini 4 Hydrogen) assisted in porting the compaction pass onto main's tiled indirect.rs and verifying barriers and multi-tile test coverage.

Closes part of #740.

**@⁠UnkwnDev** on GitHub · 2026-11-25 07:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2201) `UnkwnDev:arc-indirect-compaction` → `main` · +473 −49 · 3 files · 1 commits · open Split out from #740 per triage feedback, rebased and re-designed onto current `main` (`940d32f`). Adds an indirect draw/dispatch argument stream compaction pass inside `crates/victory-gpu/src/indirect.rs`, backed by per-list shared compaction scratch arenas in `crates/victory-gpu/src/host.rs` and wired into `crates/victory-gpu/src/draw.rs`: - Extends `indirect::SOURCE` (the single-group tiled clamp shader on `main`) so lane 0 computes per-tile compacted output indices sequentially in groupshared memory when `do_compact != 0` (`counter.is_none()`), writing surviving non-empty records (`cost > 0` within the list budget) into the compacted buffer and recording the final compacted count at offset `0`. - Because `main` walks every tile of 64 within one compute threadgroup, compaction uses zero global atomics and strictly preserves command submission order for any record count. - `ExecuteIndirect` reads from the compacted argument stream and count buffer when compaction is active, skipping empty/zero-vertex/zero-group records on the GPU without stalling command execution. - Adds `compaction_preserves_order_and_drops_empty_records` covering multi-tile compaction (150 records) and zero-record batches. ### Testing - Hardware: Intel Arc A770 (Windows 11, DXC 1.9.2602.17) - `cargo test -p victory-gpu --lib indirect -- --test-threads=1` (with and without `VICTORY_D3D12_DEBUG=1`): 6 passed, 0 failed (`compaction_preserves_order_and_drops_empty_records`, `argument_clamp_builds`, `rejected_records_do_not_wrap_the_budget`, `the_budget_goes_to_the_first_records`, `a_record_that_does_not_fit_ends_the_budget`, `a_spent_budget_stays_spent`). - `cargo clippy -p victory-gpu --all-targets --locked` and `--all-features`: clean on all modified files (`indirect.rs`, `host.rs`, `draw.rs`; 2 pre-existing `fetch_update` deprecation warnings in `object.rs`). - `cargo test -p xtask --locked`: 6 passed, 0 failed (`repository_passes_policy`). - `cargo test -p victory-gpu --lib -- --test-threads=1`: 141 passed, 3 failed, 2 ignored (the 3 failures are unrelated baseline failures on this adapter: `descriptor::host::tests::dynamic_slots_are_held_until_released`, `draw::tests::a_depth_texture_written_through_unordered_views_reads_as_depth`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`). ### AI use - Antigravity (Gemini 4 Hydrogen) assisted in porting the compaction pass onto `main`'s tiled `indirect.rs` and verifying barriers and multi-tile test coverage. Closes part of #740.
Rebased onto origin/main (67e8ae1), integrating the per-list HostList::arguments buffer and explicit resource state tracking from 315cea1.

When no title count buffer is present and records >= 16, indirect::bound compacts surviving non-empty records behind a 16-byte header holding the compacted command count at offset 0 in the reused per-list argument buffer (including > 2 MiB allocations). Below 16 records, compaction is skipped based on Arc A770 timestamp measurements.

Adds indirect::tests::bench_indirect_compaction (#[ignore]) for hardware GPU timing.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:17 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 07:58 UTC · original

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head 1d530c93 into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 702 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 07:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2201#issuecomment-7156452265) Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head `1d530c93` into `main` `940d32f` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean; the same with `--all-features`: clean. `cargo test --workspace --locked`: 702 passed, 0 failed, 10 ignored, two runs (`main` alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Author
Owner

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

@⁠catminou4 Confirmed: command order is strictly preserved for any record count. On main, indirect::SOURCE runs as a single threadgroup (l.Dispatch(records.min(1), 1, 1)) walking tiles of 64 sequentially, and lane 0 assigns compacted offsets (total + tile_out) in index order within each tile before copying surviving records. compaction_preserves_order_and_drops_empty_records explicitly asserts exact sequential order across a 150-record (3-tile) batch (verified passing on Intel Arc A770 with VICTORY_D3D12_DEBUG=1, RTX 5090 per @DenRakEiw, and RX 6950 XT per @MamaLeVrai).

**@⁠UnkwnDev** on GitHub · 2026-11-25 09:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2201#issuecomment-7158220214) @⁠catminou4 Confirmed: command order is strictly preserved for any record count. On `main`, `indirect::SOURCE` runs as a single threadgroup (`l.Dispatch(records.min(1), 1, 1)`) walking tiles of 64 sequentially, and lane 0 assigns compacted offsets (`total + tile_out`) in index order within each tile before copying surviving records. `compaction_preserves_order_and_drops_empty_records` explicitly asserts exact sequential order across a 150-record (3-tile) batch (verified passing on Intel Arc A770 with `VICTORY_D3D12_DEBUG=1`, RTX 5090 per `@DenRakEiw`, and RX 6950 XT per `@MamaLeVrai`).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:29 UTC · original · edited 2026-11-25 16:18 UTC

Automated triage for the maintainers.

Reviewed after the rebase. The clamp shader in crates/victory-gpu/src/indirect.rs (load_clamped/store_record) produces the same records as main when compaction is off. When do_compact is set (16 or more records and no title count buffer), lane 0 assigns ordered slots to surviving records with nonzero cost and writes the count at offset 0. State in draw.rs then passes the count buffer to ExecuteIndirect. By my reading it is correct: order is preserved, records past the budget are dropped instead of zeroed, and the header is always written when compaction is on. CI: check passing.

It still needs work. Its only effect is on performance, and the evidence is one synthetic benchmark on one adapter. That benchmark shows a regression for dense batches: 4096 records at 100% active cost 815 µs against 709 µs for dispatches and 646 µs against 536 µs for draws. For draws it barely helps even when sparse (the 5% rows are about even). What would change the verdict:

  • Restrict compaction to dispatches (as offered), or
  • Show from title runs that sparse indirect batches are common enough to pay for the dense-case cost (counts only, no game data), ideally on a second vendor.

Please also update the PR description. It still describes "per-list shared compaction scratch arenas in host.rs", which this head no longer has (host.rs only gains the test-only timestamp_frequency).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2201#issuecomment-7163845249) · edited 2026-11-25 16:18 UTC <!-- victory-triage v1 head=60a649f89d3f70e38d319c8319be5db7d7360ace verdict=needs-work at=2026-11-25T16:27:00Z --> Automated triage for the maintainers. Reviewed after the rebase. The clamp shader in `crates/victory-gpu/src/indirect.rs` (`load_clamped`/`store_record`) produces the same records as `main` when compaction is off. When `do_compact` is set (16 or more records and no title count buffer), lane 0 assigns ordered slots to surviving records with nonzero cost and writes the count at offset 0. `State` in `draw.rs` then passes the count buffer to `ExecuteIndirect`. By my reading it is correct: order is preserved, records past the budget are dropped instead of zeroed, and the header is always written when compaction is on. CI: `check` passing. It still needs work. Its only effect is on performance, and the evidence is one synthetic benchmark on one adapter. That benchmark shows a regression for dense batches: 4096 records at 100% active cost 815 µs against 709 µs for dispatches and 646 µs against 536 µs for draws. For draws it barely helps even when sparse (the 5% rows are about even). What would change the verdict: - Restrict compaction to dispatches (as offered), or - Show from title runs that sparse indirect batches are common enough to pay for the dense-case cost (counts only, no game data), ideally on a second vendor. Please also update the PR description. It still describes "per-list shared compaction scratch arenas in `host.rs`", which this head no longer has (`host.rs` only gains the test-only `timestamp_frequency`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠UnkwnDev on GitHub · 2026-11-25 16:10 UTC · original

Rebased onto origin/main (67e8ae1) at commit 60a649f to address @Marvisak's triage feedback and integrate 315cea1.

Changes in 60a649f

  1. Per-list arena reuse (HostList::arguments):
    • Removed the separate CompactionScratch arena and second buffer allocation/copy. Since 315cea1 already copies clamped records into the per-list HostList::arguments buffer, indirect::bound now writes compacted records directly into HostList::arguments behind a 16-byte header (count at offset 0, compacted records starting at offset 16).
    • HostList::arguments grows by next_power_of_two() and reuses the cached committed shared buffer across calls and frames (including requests > 2 MiB, verified in compaction_preserves_order_and_drops_empty_records), keeping 315cea1's COMMON -> UNORDERED_ACCESS -> INDIRECT_ARGUMENT -> COMMON barrier discipline and capture::read_indirect compatibility intact.
  2. Threshold gating (COMPACT_MIN_RECORDS = 16):
    • Below 16 records (1..8), compaction and ExecuteIndirect count-buffer indirection cost more than skipping empty records saves on Arc A770, so indirect::bound skips compaction below 16 records (and whenever a title count buffer is supplied).
  3. Synthetic Arc A770 GPU benchmark (indirect::tests::bench_indirect_compaction, #[ignore]):
    • Note: this is a synthetic D3D12 timestamp microbenchmark on Intel Arc A770 (driver 32.0.101.9175, 19.2 MHz timestamp clock, median of 15 post-warmup runs), not an in-title frame-time run.
    • total measures bound + ExecuteIndirect + done; exec measures ExecuteIndirect alone.
Kind Records Active Uncompacted total / exec (us) Compacted total / exec (us)
Dispatch (kind=2) 4 5% 12.45 / 1.51 12.92 / 1.46
Dispatch (kind=2) 8 5% 13.33 / 2.08 13.85 / 1.88
Dispatch (kind=2) 16 0% 17.50 / 5.52 15.83 / 3.80
Dispatch (kind=2) 16 5% 17.60 / 5.52 17.40 / 4.64
Dispatch (kind=2) 64 0% 24.53 / 7.86 20.89 / 3.85
Dispatch (kind=2) 64 5% 24.58 / 7.97 22.76 / 4.69
Dispatch (kind=2) 256 5% 58.70 / 17.97 49.01 / 5.16
Dispatch (kind=2) 1024 5% 187.86 / 57.14 148.91 / 7.76
Dispatch (kind=2) 4096 0% 705.31 / 213.75 525.42 / 4.32
Dispatch (kind=2) 4096 5% 709.27 / 214.17 547.24 / 15.47
Dispatch (kind=2) 4096 100% 708.75 / 214.17 814.79 / 213.91
Draw (kind=0) 64 0% 25.94 / 11.09 25.10 / 9.64
Draw (kind=0) 256 5% 51.25 / 13.18 51.51 / 10.31
Draw (kind=0) 1024 5% 147.97 / 20.73 148.91 / 11.04
Draw (kind=0) 4096 0% 536.15 / 51.51 525.26 / 10.21
Draw (kind=0) 4096 5% 537.34 / 52.14 538.39 / 12.45
Draw (kind=0) 4096 100% 536.46 / 51.61 646.04 / 51.04

What the synthetic benchmark shows: empty Dispatch records cost ~52 ns each in ExecuteIndirect on Arc A770 (214 us for 4096), so compacting sparse dispatches (>= 16 records) cuts ExecuteIndirect time by 70-98% and end-to-end GPU time by 16-25% at 256-4096 records. Empty Draw records cost ~10 ns each (51.5 us for 4096), so compacting draws only wins net total time when nearly all records are empty, breaks even around 5% active, and adds serial prefix-scan overhead when 100% active. If maintainers prefer restricting compaction to dispatches only or raising COMPACT_MIN_RECORDS, that is a one-line change.

Verification (after final edit, Intel Arc A770, Rust 1.98.1)

  • VICTORY_D3D12_DEBUG=1 cargo +1.98.1 test -p victory-gpu --features diagnostics --lib indirect -- --test-threads=1: 7 passed, 0 failed, 1 ignored (0 D3D12 debug layer errors).
  • VICTORY_D3D12_DEBUG=1 cargo +1.98.1 test -p victory-gpu --features diagnostics --lib indirect::tests::bench_indirect_compaction -- --ignored --nocapture: 1 passed.
  • cargo +1.98.1 test -p victory-gpu --lib -- --test-threads=1: 194 passed, 2 failed, 2 ignored (both failures are pre-existing Arc A770 descriptor heap cap < HEAP_VIEWS checks unrelated to indirect compaction: descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views).
  • cargo +1.98.1 clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warnings/errors.
  • cargo +1.98.1 test -p xtask --locked: 6 passed, 0 failed; cargo +1.98.1 run -p xtask -- policy: asset policy: 184 files ok.
**@⁠UnkwnDev** on GitHub · 2026-11-25 16:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2201#issuecomment-7167663773) Rebased onto `origin/main` (`67e8ae1`) at commit `60a649f` to address `@Marvisak`'s triage feedback and integrate `315cea1`. ### Changes in `60a649f` 1. **Per-list arena reuse (`HostList::arguments`)**: - Removed the separate `CompactionScratch` arena and second buffer allocation/copy. Since `315cea1` already copies clamped records into the per-list `HostList::arguments` buffer, `indirect::bound` now writes compacted records directly into `HostList::arguments` behind a 16-byte header (`count` at offset `0`, compacted records starting at offset `16`). - `HostList::arguments` grows by `next_power_of_two()` and reuses the cached committed shared buffer across calls and frames (including requests > 2 MiB, verified in `compaction_preserves_order_and_drops_empty_records`), keeping `315cea1`'s `COMMON -> UNORDERED_ACCESS -> INDIRECT_ARGUMENT -> COMMON` barrier discipline and `capture::read_indirect` compatibility intact. 2. **Threshold gating (`COMPACT_MIN_RECORDS = 16`)**: - Below 16 records (`1..8`), compaction and `ExecuteIndirect` count-buffer indirection cost more than skipping empty records saves on Arc A770, so `indirect::bound` skips compaction below 16 records (and whenever a title count buffer is supplied). 3. **Synthetic Arc A770 GPU benchmark (`indirect::tests::bench_indirect_compaction`, `#[ignore]`)**: - Note: this is a synthetic D3D12 timestamp microbenchmark on Intel Arc A770 (driver `32.0.101.9175`, `19.2 MHz` timestamp clock, median of 15 post-warmup runs), not an in-title frame-time run. - `total` measures `bound` + `ExecuteIndirect` + `done`; `exec` measures `ExecuteIndirect` alone. | Kind | Records | Active | Uncompacted `total` / `exec` (us) | Compacted `total` / `exec` (us) | | --- | ---: | ---: | ---: | ---: | | Dispatch (`kind=2`) | 4 | 5% | 12.45 / 1.51 | 12.92 / 1.46 | | Dispatch (`kind=2`) | 8 | 5% | 13.33 / 2.08 | 13.85 / 1.88 | | Dispatch (`kind=2`) | 16 | 0% | 17.50 / 5.52 | 15.83 / 3.80 | | Dispatch (`kind=2`) | 16 | 5% | 17.60 / 5.52 | 17.40 / 4.64 | | Dispatch (`kind=2`) | 64 | 0% | 24.53 / 7.86 | 20.89 / 3.85 | | Dispatch (`kind=2`) | 64 | 5% | 24.58 / 7.97 | 22.76 / 4.69 | | Dispatch (`kind=2`) | 256 | 5% | 58.70 / 17.97 | 49.01 / 5.16 | | Dispatch (`kind=2`) | 1024 | 5% | 187.86 / 57.14 | 148.91 / 7.76 | | Dispatch (`kind=2`) | 4096 | 0% | 705.31 / 213.75 | 525.42 / 4.32 | | Dispatch (`kind=2`) | 4096 | 5% | 709.27 / 214.17 | 547.24 / 15.47 | | Dispatch (`kind=2`) | 4096 | 100% | 708.75 / 214.17 | 814.79 / 213.91 | | Draw (`kind=0`) | 64 | 0% | 25.94 / 11.09 | 25.10 / 9.64 | | Draw (`kind=0`) | 256 | 5% | 51.25 / 13.18 | 51.51 / 10.31 | | Draw (`kind=0`) | 1024 | 5% | 147.97 / 20.73 | 148.91 / 11.04 | | Draw (`kind=0`) | 4096 | 0% | 536.15 / 51.51 | 525.26 / 10.21 | | Draw (`kind=0`) | 4096 | 5% | 537.34 / 52.14 | 538.39 / 12.45 | | Draw (`kind=0`) | 4096 | 100% | 536.46 / 51.61 | 646.04 / 51.04 | What the synthetic benchmark shows: empty `Dispatch` records cost ~52 ns each in `ExecuteIndirect` on Arc A770 (`214 us` for 4096), so compacting sparse dispatches (`>= 16` records) cuts `ExecuteIndirect` time by 70-98% and end-to-end GPU time by 16-25% at 256-4096 records. Empty `Draw` records cost ~10 ns each (`51.5 us` for 4096), so compacting draws only wins net total time when nearly all records are empty, breaks even around 5% active, and adds serial prefix-scan overhead when 100% active. If maintainers prefer restricting compaction to dispatches only or raising `COMPACT_MIN_RECORDS`, that is a one-line change. ### Verification (after final edit, Intel Arc A770, Rust 1.98.1) - `VICTORY_D3D12_DEBUG=1 cargo +1.98.1 test -p victory-gpu --features diagnostics --lib indirect -- --test-threads=1`: 7 passed, 0 failed, 1 ignored (0 D3D12 debug layer errors). - `VICTORY_D3D12_DEBUG=1 cargo +1.98.1 test -p victory-gpu --features diagnostics --lib indirect::tests::bench_indirect_compaction -- --ignored --nocapture`: 1 passed. - `cargo +1.98.1 test -p victory-gpu --lib -- --test-threads=1`: 194 passed, 2 failed, 2 ignored (both failures are pre-existing Arc A770 descriptor heap cap `< HEAP_VIEWS` checks unrelated to indirect compaction: `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`). - `cargo +1.98.1 clippy --workspace --all-targets --all-features --locked -- -D warnings`: 0 warnings/errors. - `cargo +1.98.1 test -p xtask --locked`: 6 passed, 0 failed; `cargo +1.98.1 run -p xtask -- policy`: `asset policy: 184 files ok`.
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/2201/head:github-bot/gh-2201'
git switch 'github-bot/gh-2201'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2201'
git switch 'github-bot/gh-2201'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2201'
git switch 'github-bot/gh-2201'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2201'
git switch 'main'
git merge --squash 'github-bot/gh-2201'
git switch 'main'
git merge --ff-only 'github-bot/gh-2201'
git switch 'main'
git merge 'github-bot/gh-2201'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2201
No description provided.