perf: an indirect execution's argument buffer stays readable until the next clamp #445

Closed
github-bot wants to merge 1 commit from github-bot/gh-445 into main AGit
Owner

@⁠KainanP on GitHub · 2026-11-26 18:53 UTC · original
KainanP:perf/indirect-args → main · +351 −63 · 5 files · 1 commits · closed without merging

Reopened: main reverted #409 (#452), so this is the Neptune-base version again, rebased onto 15024d5; the numbers below were measured on main 8e32daa (Neptune base, a few VIctory commits before today's main). On the combined base this change is already there (see my closing comment of earlier today), so if #409 returns this PR goes away.

Port of Marvisak/VIctory#3307 (mine) to this tree's indirect path, which has the same per-call clamp plus windows, dispatches in parts and records clamped ahead.

The problem

Every clamped ExecuteIndirect recorded three barrier calls on the list's argument buffer: common → unordered access and → indirect argument around the clamp, then indirect::done's → common right after the execution. On top of that, per call: host_signature took a global mutex and AddRef/Release'd one shared COM object; the title's pipeline, bound again after the clamp's own, was kept again (used_pipeline's string set, two QueryInterface + AddRef + push); budget() asked the driver for the budget word's GPU address.

The change

  • One barrier call fewer per execution. The argument buffer stays in the indirect-argument state after the execution; the next clamp's existing barrier moves it from there to unordered access (waiting for the earlier execution's reads, as the move to common did). HostList::close moves it back to common, and so does a bigger buffer replacing it mid-list (the old one is moved before it is kept). Between lists it is common as before, so its states are known whatever order lists run in. A clamp marks the buffer readable only once its barriers are recorded. indirect::done is gone (the WARP tests keep their own done_on).
  • Command signatures made once and kept for good (&'static), each thread remembering the last one it asked for.
  • HostList::holds_pipeline: the pipeline bound again after the clamp is not kept again.
  • The budget word's GPU address is kept.

The GPU sees the same commands, minus one barrier per execution.

Measured

List bench of #441 with VICTORY_LIST_BENCH_INDIRECT=1: each thread records one indirect call at a time into its own list, the list's close timed with the calls. Median of 9 interleaved runs [min–max]. RTX 4060 Laptop GPU, Core i7-14650HX, Windows 11, release profile. Foreign CPU load: about 20–30 % from other applications (an editor, Steam, a browser) throughout; the builds were interleaved run by run so they share it, which is also why the absolute numbers sit above an idle machine's.

ns a call main this PR main + #443 + #444 + this PR
dispatch, 1 thread 4629 [4440–5252] 4074 [3903–4764] 4052
dispatch, 5 threads 7362 [7002–7880] 6804 [6212–8318] 5709
indexed draw, 1 thread 4478 4411 2574
indexed draw, 5 threads 9107 9000 4976

About −0.55 µs per clamped indirect dispatch (−8 to −12 %). Indirect draws in this bench go through this tree's other routes (records clamped ahead, windows), which this PR doesn't change, so they stay within their spread; what they gain comes from #443 and #444.

Tests

New:

  • indirect/args_state_tests.rs each_execution_reads_its_own_clamped_records: four indirect dispatches in one list through the list's one argument buffer, including 6,000 records that make the list replace its 64 KiB buffer while it is readable; the list runs twice (the second run starts from what the first left). A counting compute shader checks each execution ran its own records' groups (6, 4, 5, 7), and every transition is replayed from the buffers' states by the debug layer's rule (host::barrier_log, test-only; the D3D12 debug layer isn't installed here), all common at the close. It fails with the clamp's barrier changed back to "from common" (barrier 2 starts from common while the buffer is readable) or without the close's move (not common at the close).
  • the_argument_buffer_is_common_until_a_clamp_and_after_the_close, and draw::indirect_signature_tests (signatures made once across threads; holds_pipeline until the reset).
  • Existing indirect tests are updated for done's removal and still check the same values.

cargo test -p victory-gpu --release --lib, one thread, same failures as main (8e32daa) on each adapter: RTX 4060 Laptop, Intel UHD (a78b, through a local adapter-selection hook not in this PR), WARP (--features diagnostics, VICTORY_D3D12_WARP=1). Main fails descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots and warp_card_patch_writes_the_masked_bytes_and_no_others here on all three; draw::heap_texture_tests::duplicate_texture_views_share_uploads_within_each_pass is timing-bound and fails now and then on main too. Clippy (--all-targets, with and without diagnostics): no warning main doesn't have. cargo xtask policy ok, ruff clean. The four PRs merged together (octopus, on 91c15f2): same suite results on RTX.

What this does not show

No in-game numbers: I don't run the title. The bench records only indirect calls, the best case for the per-call saving. GPU time should not change (same commands, one barrier fewer), but I didn't time it. Please A/B it in game.

Overlaps

No textual conflict with the open PRs that touch third_party/victory (checked with git merge-tree), except those already conflicting with main. No conflict with #441, #443 or #444. If #409 (combined base) lands first, I'll port this again onto it.

The kept GPU address of the budget word follows the per-list VA caches of wbkepler's Marvisak/VIctory#1356 (idea only, no code taken).

AI use: Claude Code (Claude Opus 5.5) ported the change, wrote the tests, ran the measurements and drafted this description.

🤖 Generated with Claude Code

**@⁠KainanP** on GitHub · 2026-11-26 18:53 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/445) `KainanP:perf/indirect-args` → `main` · +351 −63 · 5 files · 1 commits · closed without merging > **Reopened: main reverted #409 (#452)**, so this is the Neptune-base version again, rebased onto 15024d5; the numbers below were measured on main 8e32daa (Neptune base, a few VIctory commits before today's main). On the combined base this change is already there (see my closing comment of earlier today), so if #409 returns this PR goes away. Port of Marvisak/VIctory#3307 (mine) to this tree's indirect path, which has the same per-call clamp plus windows, dispatches in parts and records clamped ahead. ## The problem Every clamped `ExecuteIndirect` recorded three barrier calls on the list's argument buffer: common → unordered access and → indirect argument around the clamp, then `indirect::done`'s → common right after the execution. On top of that, per call: `host_signature` took a global mutex and AddRef/Release'd one shared COM object; the title's pipeline, bound again after the clamp's own, was kept again (`used_pipeline`'s string set, two QueryInterface + AddRef + push); `budget()` asked the driver for the budget word's GPU address. ## The change - **One barrier call fewer per execution.** The argument buffer stays in the indirect-argument state after the execution; the next clamp's existing barrier moves it from there to unordered access (waiting for the earlier execution's reads, as the move to common did). `HostList::close` moves it back to common, and so does a bigger buffer replacing it mid-list (the old one is moved before it is kept). Between lists it is common as before, so its states are known whatever order lists run in. A clamp marks the buffer readable only once its barriers are recorded. `indirect::done` is gone (the WARP tests keep their own `done_on`). - **Command signatures** made once and kept for good (`&'static`), each thread remembering the last one it asked for. - **`HostList::holds_pipeline`**: the pipeline bound again after the clamp is not kept again. - **The budget word's GPU address** is kept. The GPU sees the same commands, minus one barrier per execution. ## Measured List bench of #441 with `VICTORY_LIST_BENCH_INDIRECT=1`: each thread records one indirect call at a time into its own list, the list's close timed with the calls. Median of 9 interleaved runs [min–max]. RTX 4060 Laptop GPU, Core i7-14650HX, Windows 11, release profile. Foreign CPU load: about 20–30 % from other applications (an editor, Steam, a browser) throughout; the builds were interleaved run by run so they share it, which is also why the absolute numbers sit above an idle machine's. | ns a call | main | this PR | main + #443 + #444 + this PR | |---|---:|---:|---:| | dispatch, 1 thread | 4629 [4440–5252] | **4074** [3903–4764] | 4052 | | dispatch, 5 threads | 7362 [7002–7880] | **6804** [6212–8318] | 5709 | | indexed draw, 1 thread | 4478 | 4411 | 2574 | | indexed draw, 5 threads | 9107 | 9000 | 4976 | About −0.55 µs per clamped indirect dispatch (−8 to −12 %). Indirect draws in this bench go through this tree's other routes (records clamped ahead, windows), which this PR doesn't change, so they stay within their spread; what they gain comes from #443 and #444. ## Tests New: - `indirect/args_state_tests.rs` `each_execution_reads_its_own_clamped_records`: four indirect dispatches in one list through the list's one argument buffer, including 6,000 records that make the list replace its 64 KiB buffer while it is readable; the list runs twice (the second run starts from what the first left). A counting compute shader checks each execution ran its own records' groups (6, 4, 5, 7), and every transition is replayed from the buffers' states by the debug layer's rule (`host::barrier_log`, test-only; the D3D12 debug layer isn't installed here), all common at the close. It fails with the clamp's barrier changed back to "from common" (barrier 2 starts from common while the buffer is readable) or without the close's move (not common at the close). - `the_argument_buffer_is_common_until_a_clamp_and_after_the_close`, and `draw::indirect_signature_tests` (signatures made once across threads; `holds_pipeline` until the reset). - Existing indirect tests are updated for `done`'s removal and still check the same values. `cargo test -p victory-gpu --release --lib`, one thread, same failures as main (8e32daa) on each adapter: RTX 4060 Laptop, Intel UHD (a78b, through a local adapter-selection hook not in this PR), WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`). Main fails `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots` and `warp_card_patch_writes_the_masked_bytes_and_no_others` here on all three; `draw::heap_texture_tests::duplicate_texture_views_share_uploads_within_each_pass` is timing-bound and fails now and then on main too. Clippy (`--all-targets`, with and without `diagnostics`): no warning main doesn't have. `cargo xtask policy` ok, ruff clean. The four PRs merged together (octopus, on 91c15f2): same suite results on RTX. ## What this does not show No in-game numbers: I don't run the title. The bench records only indirect calls, the best case for the per-call saving. GPU time should not change (same commands, one barrier fewer), but I didn't time it. **Please A/B it in game.** ## Overlaps No textual conflict with the open PRs that touch `third_party/victory` (checked with `git merge-tree`), except those already conflicting with main. No conflict with #441, #443 or #444. If #409 (combined base) lands first, I'll port this again onto it. The kept GPU address of the budget word follows the per-list VA caches of wbkepler's Marvisak/VIctory#1356 (idea only, no code taken). _AI use: Claude Code (Claude Opus 5.5) ported the change, wrote the tests, ran the measurements and drafted this description._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Each clamped indirect execution recorded three barrier calls on the
list's argument buffer: common -> unordered access and -> indirect
argument around the clamp, then indirect::done's -> common right after
the execution. Now the buffer stays in the indirect-argument state
after the execution; the next clamp's existing barrier moves it from
there to unordered access (waiting for the earlier execution's reads, as
the move to common did), HostList::close moves it back to common, and so
does a bigger buffer replacing it mid-list (the old one is moved before
it is kept). Between lists it is common as before, so its states are
known whatever order lists run in. indirect::done is gone (the tests
keep their own done_on).

Also, per call:
- host_signature: made once and kept for good (&'static), each thread
  remembers the last one it asked for: no global mutex and no
  AddRef/Release of one shared COM object per call on every thread;
- the title's pipeline bound again after the clamp's is not kept again
  (used_pipeline's string set, two QueryInterface + AddRef + push):
  HostList::holds_pipeline remembers the last pipeline kept since the
  list's reset;
- the budget word's GPU address is kept, not asked of the driver.

The GPU commands are the same but one barrier fewer per execution.

Tests: indirect/args_state_tests.rs runs four indirect dispatches in one
list, twice, through the list's one argument buffer, including one that
makes the list replace its 64 KiB buffer while readable; a counting
shader checks each execution ran its own records' groups, and every
transition is replayed from the buffers' states (the debug layer's rule,
host::barrier_log, test-only), all common at the close. It fails with
the clamp's barrier changed back to "from common" or without the
close's move. Also: the reported states, signatures made once,
holds_pipeline.

List bench (VICTORY_LIST_BENCH_INDIRECT=1), RTX 4060 Laptop, release,
median of 9 interleaved runs, one indirect dispatch with its list's
close: 4629 -> 4074 ns on 1 thread, 7362 -> 6804 ns on 5 threads.

Source: Marvisak/VIctory#3307 (ported by hand: this tree's clamp also
has windows, parts and ahead records)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:56:46 +00:00
github-bot closed this pull request 2026-11-26 20:24:53 +00:00
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 20:21 UTC · original

Closing: after #409 this is already in the base, and what isn't doesn't measure.

The combined base has the two parts of this PR that mattered, written independently:

  • One barrier per list instead of one per execution: HostList::indirect_readable / indirect_state / indirect_common (host.rs). The clamp moves the scratch buffer from wherever the last clamp left it, it stays in INDIRECT_ARGUMENT for the executions that read it, and it goes back to common at the close or when a bigger buffer replaces it. That was this PR's barrier change, most of the ~0.55 µs per indirect dispatch it saved on the old base.
  • No re-keep of the pipeline bound again after a clamp: HostList::bind_pipeline keeps a pipeline and notes its name only the first time per list.
  • Also, single-record executions are now clamped in batches (VICTORY_INDIRECT_BATCH, on by default), so most executions no longer have a clamp of their own.

What was left is the per-thread command-signature cache and the cached GPU address of the budget word. I ported both onto 37d4686 and measured them with the list bench of #441. Median of 9 interleaved runs [min–max], ns a call with the list's close, RTX 4060 Laptop, release; foreign load from other applications throughout, builds interleaved so they share it:

ns main + signature/budget caches
1 dispatch, 1 thread 2626 [2461–2812] 2544 [2505–2675]
1 dispatch, 5 threads 3430 [3188–3574] 3333 [3129–3610]
1 indexed draw, 1 thread 3120 [2904–3244] 3178 [2878–3242]
1 indexed draw, 5 threads 4518 [4418–4876] 4712 [4536–4892]
tuned set: 1 dispatch, 1 / 5 threads 822 / 1841 854 / 1842

Every difference is inside the other build's spread, in both directions. It's not worth a PR. The indirect rows still gain from #443 and #444 (for example 1 indexed draw on 5 threads: 4518 → 4057), and those PRs carry that.

AI use: Claude Code (Claude Opus 5.5) compared the code, ran the benchmark and drafted this comment.

**@⁠KainanP** on GitHub · 2026-11-26 20:21 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/445#issuecomment-7202588710) Closing: after #409 this is already in the base, and what isn't doesn't measure. The combined base has the two parts of this PR that mattered, written independently: - **One barrier per list instead of one per execution**: `HostList::indirect_readable` / `indirect_state` / `indirect_common` (`host.rs`). The clamp moves the scratch buffer from wherever the last clamp left it, it stays in `INDIRECT_ARGUMENT` for the executions that read it, and it goes back to common at the close or when a bigger buffer replaces it. That was this PR's barrier change, most of the ~0.55 µs per indirect dispatch it saved on the old base. - **No re-keep of the pipeline bound again after a clamp**: `HostList::bind_pipeline` keeps a pipeline and notes its name only the first time per list. - Also, single-record executions are now clamped in batches (`VICTORY_INDIRECT_BATCH`, on by default), so most executions no longer have a clamp of their own. What was left is the per-thread command-signature cache and the cached GPU address of the budget word. I ported both onto 37d4686 and measured them with the list bench of #441. Median of 9 interleaved runs [min–max], ns a call with the list's close, RTX 4060 Laptop, release; foreign load from other applications throughout, builds interleaved so they share it: | ns | main | + signature/budget caches | |---|---:|---:| | 1 dispatch, 1 thread | 2626 [2461–2812] | 2544 [2505–2675] | | 1 dispatch, 5 threads | 3430 [3188–3574] | 3333 [3129–3610] | | 1 indexed draw, 1 thread | 3120 [2904–3244] | 3178 [2878–3242] | | 1 indexed draw, 5 threads | 4518 [4418–4876] | 4712 [4536–4892] | | tuned set: 1 dispatch, 1 / 5 threads | 822 / 1841 | 854 / 1842 | Every difference is inside the other build's spread, in both directions. It's not worth a PR. The indirect rows still gain from #443 and #444 (for example 1 indexed draw on 5 threads: 4518 → 4057), and those PRs carry that. _AI use: Claude Code (Claude Opus 5.5) compared the code, ran the benchmark and drafted this comment._
github-bot reopened this pull request 2026-11-26 20:45:27 +00:00
github-bot force-pushed github-bot/gh-445 from c02352396a to 836325ffde 2026-11-26 20:51:02 +00:00 Compare
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 20:46 UTC · original

Reopened: main reverted #409 (#452), so this is back to the Neptune-base version measured in the original body, rebased onto 15024d5 (RTX: its tests pass, and the suite gives the same results as before). On the combined base this change is already in the tree (my closing comment above), so this PR only applies while main is on the Neptune base.

AI use: Claude Code (Claude Opus 5.5).

**@⁠KainanP** on GitHub · 2026-11-26 20:46 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/445#issuecomment-7203054996) Reopened: main reverted #409 (#452), so this is back to the Neptune-base version measured in the original body, rebased onto 15024d5 (RTX: its tests pass, and the suite gives the same results as before). On the combined base this change is already in the tree (my closing comment above), so this PR only applies while main is on the Neptune base. _AI use: Claude Code (Claude Opus 5.5)._
github-bot closed this pull request 2026-11-27 00:37:53 +00:00
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 23:48 UTC · original

Closing: the Vice-Tay base (#454) already does what this PR was for. Its indirect::bound leaves the list's argument buffer in the indirect-argument state until the next clamp (HostList::indirect_readable / indirect_state), and moves it back to common only before the list closes or a bigger buffer replaces it (indirect_common): the barrier this PR removed is already gone. HostList::bind_pipeline also keeps a pipeline bound again only once per recording, which covers holds_pipeline.

What was left, a per-thread command signature (no global mutex and no AddRef/Release per call) and the budget words' GPU address kept per list, I ported and measured with the list bench of #441 (VICTORY_LIST_BENCH_INDIRECT=1, main b6d86cf8, RTX 4060 Laptop, quiet machine, median of 9 interleaved runs [min–max], ns a call with the list's close):

main + the rest of this PR
dispatch, 1 thread 2445 [2194–2607] 2417 [2189–2679]
dispatch, 5 threads 3183 [2752–3434] 2996 [2833–3340]
indexed draw, 1 thread 2957 [2740–3241] 2848 [2685–3089]
indexed draw, 5 threads 4089 [3931–4668] 4155 [3888–4681]

All within main's spread, so not worth a PR. The code is on perf/indirect-args-vicetay-remainder for reference, and the Neptune version on perf/indirect-args-neptune.

AI use: Claude Code (Claude Opus 5.5).

**@⁠KainanP** on GitHub · 2026-11-26 23:48 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/445#issuecomment-7205880603) Closing: the Vice-Tay base (#454) already does what this PR was for. Its `indirect::bound` leaves the list's argument buffer in the indirect-argument state until the next clamp (`HostList::indirect_readable` / `indirect_state`), and moves it back to common only before the list closes or a bigger buffer replaces it (`indirect_common`): the barrier this PR removed is already gone. `HostList::bind_pipeline` also keeps a pipeline bound again only once per recording, which covers `holds_pipeline`. What was left, a per-thread command signature (no global mutex and no AddRef/Release per call) and the budget words' GPU address kept per list, I ported and measured with the list bench of #441 (`VICTORY_LIST_BENCH_INDIRECT=1`, main b6d86cf8, RTX 4060 Laptop, quiet machine, median of 9 interleaved runs [min–max], ns a call with the list's close): | | main | + the rest of this PR | |---|---:|---:| | dispatch, 1 thread | 2445 [2194–2607] | 2417 [2189–2679] | | dispatch, 5 threads | 3183 [2752–3434] | 2996 [2833–3340] | | indexed draw, 1 thread | 2957 [2740–3241] | 2848 [2685–3089] | | indexed draw, 5 threads | 4089 [3931–4668] | 4155 [3888–4681] | All within main's spread, so not worth a PR. The code is on [`perf/indirect-args-vicetay-remainder`](https://github.com/KainanP/AnyXboxX/tree/perf/indirect-args-vicetay-remainder) for reference, and the Neptune version on [`perf/indirect-args-neptune`](https://github.com/KainanP/AnyXboxX/tree/perf/indirect-args-neptune). _AI use: Claude Code (Claude Opus 5.5)._

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.