gpu: compact non-empty indirect draw and dispatch arguments #2201
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2201
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2201"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@UnkwnDev on GitHub · 2026-11-25 07:39 UTC · original
UnkwnDev:arc-indirect-compaction→main· +473 −49 · 3 files · 1 commits · openSplit 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 incrates/victory-gpu/src/host.rsand wired intocrates/victory-gpu/src/draw.rs:indirect::SOURCE(the single-group tiled clamp shader onmain) so lane 0 computes per-tile compacted output indices sequentially in groupshared memory whendo_compact != 0(counter.is_none()), writing surviving non-empty records (cost > 0within the list budget) into the compacted buffer and recording the final compacted count at offset0.mainwalks every tile of 64 within one compute threadgroup, compaction uses zero global atomics and strictly preserves command submission order for any record count.ExecuteIndirectreads 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.compaction_preserves_order_and_drops_empty_recordscovering multi-tile compaction (150 records) and zero-record batches.Testing
cargo test -p victory-gpu --lib indirect -- --test-threads=1(with and withoutVICTORY_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 --lockedand--all-features: clean on all modified files (indirect.rs,host.rs,draw.rs; 2 pre-existingfetch_updatedeprecation warnings inobject.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
main's tiledindirect.rsand verifying barriers and multi-tile test coverage.Closes part of #740.
@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
1d530c93intomain940d32fin 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 (mainalone 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.
@UnkwnDev on GitHub · 2026-11-25 09:21 UTC · original
@catminou4 Confirmed: command order is strictly preserved for any record count. On
main,indirect::SOURCEruns 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_recordsexplicitly asserts exact sequential order across a 150-record (3-tile) batch (verified passing on Intel Arc A770 withVICTORY_D3D12_DEBUG=1, RTX 5090 per@DenRakEiw, and RX 6950 XT per@MamaLeVrai).@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 asmainwhen compaction is off. Whendo_compactis 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.Stateindraw.rsthen passes the count buffer toExecuteIndirect. 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:checkpassing.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:
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.rsonly gains the test-onlytimestamp_frequency).Generated by Claude Code
@UnkwnDev on GitHub · 2026-11-25 16:10 UTC · original
Rebased onto
origin/main(67e8ae1) at commit60a649fto address@Marvisak's triage feedback and integrate315cea1.Changes in
60a649fHostList::arguments):CompactionScratcharena and second buffer allocation/copy. Since315cea1already copies clamped records into the per-listHostList::argumentsbuffer,indirect::boundnow writes compacted records directly intoHostList::argumentsbehind a 16-byte header (countat offset0, compacted records starting at offset16).HostList::argumentsgrows bynext_power_of_two()and reuses the cached committed shared buffer across calls and frames (including requests > 2 MiB, verified incompaction_preserves_order_and_drops_empty_records), keeping315cea1'sCOMMON -> UNORDERED_ACCESS -> INDIRECT_ARGUMENT -> COMMONbarrier discipline andcapture::read_indirectcompatibility intact.COMPACT_MIN_RECORDS = 16):1..8), compaction andExecuteIndirectcount-buffer indirection cost more than skipping empty records saves on Arc A770, soindirect::boundskips compaction below 16 records (and whenever a title count buffer is supplied).indirect::tests::bench_indirect_compaction,#[ignore]):32.0.101.9175,19.2 MHztimestamp clock, median of 15 post-warmup runs), not an in-title frame-time run.totalmeasuresbound+ExecuteIndirect+done;execmeasuresExecuteIndirectalone.total/exec(us)total/exec(us)kind=2)kind=2)kind=2)kind=2)kind=2)kind=2)kind=2)kind=2)kind=2)kind=2)kind=2)kind=0)kind=0)kind=0)kind=0)kind=0)kind=0)What the synthetic benchmark shows: empty
Dispatchrecords cost ~52 ns each inExecuteIndirecton Arc A770 (214 usfor 4096), so compacting sparse dispatches (>= 16records) cutsExecuteIndirecttime by 70-98% and end-to-end GPU time by 16-25% at 256-4096 records. EmptyDrawrecords cost ~10 ns each (51.5 usfor 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 raisingCOMPACT_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_VIEWSchecks unrelated to indirect compaction:descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::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.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.