Spread dispatches: VICTORY_SPREAD_LEAN runs the records within 65,535 groups through the plain signature (off by default; #1338) #1352

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

@⁠grosterr on GitHub · 2026-11-26 17:43 UTC · original
grosterr:pr/spread-lean → main · +510 −37 · 3 files · 1 commits · open

What

Since 06702fe an indirect dispatch of a program that takes the spread words goes through a command signature that sets two root constants (row, asked x) and then dispatches, 20 bytes a record. That holds for every such dispatch, whatever it asks for.

With VICTORY_SPREAD_LEAN=1 (or alt: twenty seconds each way, each change logged), the clamp writes a batch of up to 64 dispatch records twice:

  • plain [x, y, z] records from byte 0, with the records past 65,535 groups in x left empty;
  • at (records * 12 + 7) & ~7, a predicate word: 1 when any record that runs is spread;
  • 8 bytes on, [row, asked x, x, y, z] records, with only the spread records filled.

The dispatch is then recorded as ExecuteIndirect with the plain DISPATCH signature, SetPredication(EQUAL_ZERO) on the word, ExecuteIndirect with the spread signature, and predication off again.

  • Nothing is clamped to 65,535 groups. On our RTX 3060, VICTORY_DISPATCH_SPREAD=0 lost the device while loading in 2 of 4 runs.
  • Larger batches (more than one clamp group) take the spread signature as before. The predicate is written by the group's first thread after a group barrier, so one group is a hard limit here.
  • The bound program's spread words are 0 for the plain records. Its bind sets them that way for an indirect dispatch, as it did before.

The clamp also counts, in the budget buffer's words 3-5, the spread-eligible records over 65,535 groups and within it, and the groups past 65,535. The frame line says them:

dispatches spread across z ... per frame: 0.00 direct, 989.25 indirect (989.25 lean), records: 0.75 over 65,535 (+21231 extra groups), 1097.50 at or under 65,535

Measured (RTX 3060 12 GB, Ryzen 7 5700X, Series X profile, prison prologue)

The run was on our branch, which has this change on 06702fe + ceb9e1f and the #770 stack. Standing still at one spot, =alt, 9 pairs, warm pipeline library, world frames only:

lean ON lean off
frame 208 ms 225 ms
on the GPU 91 ms 108 ms
preparing 78 ms 74 ms
copying back 45 ms 45 ms

The card's time was lower in every pair: −22, −19, −9, −19, −16, −7, −1, −13, −8 ms (median −12.8). Preparing pays about 4 ms for two executions and the predication instead of one.

Of the ~890-990 spread-signature executions a frame, 0.4-1.2 a frame pass 65,535 groups.

A micro-benchmark of 1,000 single-record executions of an empty dispatch on the same card, card time:

signature card time
spread signature 1.88 ms
plain signature 0.06 ms
spread signature behind a predicate that is 0 0.53 ms

In a real frame the difference is much larger, so the driver probably serialises around executions that set root constants.

This branch is the change alone, rebased on e4245f3 (the clamp's new group charge and gather segments). It was built and tested, but not run in game on this exact base.

Tests

  • warp_spread_lean_routes_small_and_large_records_and_counts_them: a mixed batch (100, 100,000 and 65,535 groups), and an all-small batch. It checks the plain and spread arrays, the predicate word, and the counters.
  • warp_spread_lean_executes_same_group_ids_as_spread_for_100k_groups: 100,000 groups and 100 groups through the two executions under predication. It checks that the same group ids run, and that the predicate is set and clear respectively.
  • Under VICTORY_D3D12_DEBUG=1: indirect 19 passed. Whole victory-gpu --lib (--test-threads=1): 224 passed. Clippy on the workspace is clean, and --features diagnostics builds.

Not tried on AMD, hence off by default. With it unset, nothing changes apart from the three counters.

🤖 Generated with Claude Code

**@⁠grosterr** on GitHub · 2026-11-26 17:43 UTC · [original](https://github.com/fxceless/victory-fork/pull/1352) `grosterr:pr/spread-lean` → `main` · +510 −37 · 3 files · 1 commits · open ## What Since `06702fe` an indirect dispatch of a program that takes the spread words goes through a command signature that sets two root constants (row, asked x) and then dispatches, 20 bytes a record. That holds for every such dispatch, whatever it asks for. With `VICTORY_SPREAD_LEAN=1` (or `alt`: twenty seconds each way, each change logged), the clamp writes a batch of up to 64 dispatch records twice: - plain `[x, y, z]` records from byte 0, with the records past 65,535 groups in x left empty; - at `(records * 12 + 7) & ~7`, a predicate word: 1 when any record that runs is spread; - 8 bytes on, `[row, asked x, x, y, z]` records, with only the spread records filled. The dispatch is then recorded as `ExecuteIndirect` with the plain `DISPATCH` signature, `SetPredication(EQUAL_ZERO)` on the word, `ExecuteIndirect` with the spread signature, and predication off again. - **Nothing is clamped to 65,535 groups.** On our RTX 3060, `VICTORY_DISPATCH_SPREAD=0` lost the device while loading in 2 of 4 runs. - **Larger batches** (more than one clamp group) take the spread signature as before. The predicate is written by the group's first thread after a group barrier, so one group is a hard limit here. - **The bound program's spread words are 0 for the plain records.** Its bind sets them that way for an indirect dispatch, as it did before. The clamp also counts, in the budget buffer's words 3-5, the spread-eligible records over 65,535 groups and within it, and the groups past 65,535. The frame line says them: > dispatches spread across z ... per frame: 0.00 direct, 989.25 indirect (989.25 lean), records: 0.75 over 65,535 (+21231 extra groups), 1097.50 at or under 65,535 ## Measured (RTX 3060 12 GB, Ryzen 7 5700X, Series X profile, prison prologue) The run was on our branch, which has this change on `06702fe` + `ceb9e1f` and the #770 stack. Standing still at one spot, `=alt`, 9 pairs, warm pipeline library, world frames only: | | lean ON | lean off | |---|---|---| | frame | 208 ms | 225 ms | | on the GPU | **91 ms** | **108 ms** | | preparing | 78 ms | 74 ms | | copying back | 45 ms | 45 ms | The card's time was lower in every pair: −22, −19, −9, −19, −16, −7, −1, −13, −8 ms (median −12.8). Preparing pays about 4 ms for two executions and the predication instead of one. Of the ~890-990 spread-signature executions a frame, 0.4-1.2 a frame pass 65,535 groups. A micro-benchmark of 1,000 single-record executions of an empty dispatch on the same card, card time: | signature | card time | |---|---| | spread signature | 1.88 ms | | plain signature | 0.06 ms | | spread signature behind a predicate that is 0 | 0.53 ms | In a real frame the difference is much larger, so the driver probably serialises around executions that set root constants. This branch is the change alone, rebased on `e4245f3` (the clamp's new group charge and gather segments). It was built and tested, but not run in game on this exact base. ## Tests - `warp_spread_lean_routes_small_and_large_records_and_counts_them`: a mixed batch (100, 100,000 and 65,535 groups), and an all-small batch. It checks the plain and spread arrays, the predicate word, and the counters. - `warp_spread_lean_executes_same_group_ids_as_spread_for_100k_groups`: 100,000 groups and 100 groups through the two executions under predication. It checks that the same group ids run, and that the predicate is set and clear respectively. - Under `VICTORY_D3D12_DEBUG=1`: `indirect` 19 passed. Whole `victory-gpu --lib` (`--test-threads=1`): 224 passed. Clippy on the workspace is clean, and `--features diagnostics` builds. Not tried on AMD, hence off by default. With it unset, nothing changes apart from the three counters. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
An indirect dispatch of a program that takes the spread words goes through
a command signature that sets two root constants and then dispatches. On an
RTX 3060 that costs about 13 ms of the card's time a frame, for ~1,000 such
executions, of which ~1 a frame asks for more than 65,535 groups in x.

With VICTORY_SPREAD_LEAN=1 (or alt, twenty seconds each way) a batch of up
to 64 records is clamped into two arrays: plain [x, y, z] records for the
plain dispatch signature, with the records past 65,535 left empty, and
[row, asked x, x, y, z] records for the spread signature, with only those
filled. A predicate word between them is 1 when a record that runs is
spread. The dispatch is recorded as the plain execution, then the spread
one under SetPredication(EQUAL_ZERO). Nothing is clamped to 65,535 groups
either way. Larger batches take the spread signature as before.

The clamp also counts, in the budget buffer's next words, the
spread-eligible records over 65,535 groups and within it, and the groups
past 65,535; the frame line says them.

Measured on an RTX 3060 12 GB, standing still with =alt, 9 pairs: the
card's time 91 against 108 ms (lower in every pair, median -12.8 ms),
frame 208 against 225 ms, preparing +4 ms. WARP tests: the routing and
counts of a mixed batch, and equal group ids at 100,000 groups through the
two executions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:48:37 +00:00
Author
Owner

@⁠BitWuehler on GitHub · 2026-11-26 18:35 UTC · original

Tested on Linux/Proton (GE-Proton11-14 + vkd3d-proton, RTX 5080 16 GB, Series X profile, diag build with frame capture enabled, warm shader cache, merged on e4245f3 alongside #1350 and our Linux DXC/copy-plain test stack):

  • Unit tests under Proton: indirect:: with VICTORY_SPREAD_LEAN=1 — 19 passed, 0 failed, 2 ignored (both new warp_spread_lean_* tests passed).
  • Control (without #1352, VICTORY_DISPATCH_SPREAD default on): 1.7–2.0 fps (505–600 ms/frame, copying back 247–360 ms), 1,066 indirect dispatches/frame through the spread signature.
  • With #1352 (VICTORY_SPREAD_LEAN=1): 3.7–4.3 fps (234–272 ms/frame, copying back 80–100 ms) — >2x faster while keeping full lighting/volumetrics intact (visually verified across captured world frames).
  • Lean routing breakdown: 826–1,050 indirect dispatches/frame routed lean; only 0.40–1.25 records/frame exceeded 65,535 groups (1,062–1,155 at or under 65,535).

(AI-assisted testing and summary.)

**@⁠BitWuehler** on GitHub · 2026-11-26 18:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/1352#issuecomment-7200630373) Tested on Linux/Proton (GE-Proton11-14 + vkd3d-proton, RTX 5080 16 GB, Series X profile, `diag` build with frame capture enabled, warm shader cache, merged on `e4245f3` alongside #1350 and our Linux DXC/copy-plain test stack): - **Unit tests under Proton:** `indirect::` with `VICTORY_SPREAD_LEAN=1` — **19 passed, 0 failed, 2 ignored** (both new `warp_spread_lean_*` tests passed). - **Control (without `#1352`, `VICTORY_DISPATCH_SPREAD` default on):** `1.7–2.0 fps` (`505–600 ms/frame`, `copying back 247–360 ms`), `1,066` indirect dispatches/frame through the spread signature. - **With `#1352` (`VICTORY_SPREAD_LEAN=1`):** **`3.7–4.3 fps` (`234–272 ms/frame`, `copying back 80–100 ms`)** — >2x faster while keeping full lighting/volumetrics intact (visually verified across captured world frames). - **Lean routing breakdown:** `826–1,050` indirect dispatches/frame routed lean; only `0.40–1.25` records/frame exceeded 65,535 groups (`1,062–1,155` at or under 65,535). *(AI-assisted testing and summary.)*
Author
Owner

@⁠grosterr on GitHub · 2026-11-26 18:49 UTC · original

Thanks for running it under Proton. Your counters match ours: ~1,000 executions a frame through the spread signature, about one record a frame past 65,535. So the cost is the signature itself, and it is clearly worse under vkd3d (copy-back alone 247–360 → 80–100 ms there) than on Windows.

With two independent results, on Windows/NVIDIA (card −12.8 ms) and on Linux/vkd3d (frame more than halved), the switch could be on by default, at least on NVIDIA and under vkd3d. A run of VICTORY_SPREAD_LEAN=alt on an AMD card would settle whether it can be on everywhere. Happy to change the default in this PR if that is preferred.

**@⁠grosterr** on GitHub · 2026-11-26 18:49 UTC · [original](https://github.com/fxceless/victory-fork/pull/1352#issuecomment-7200893004) Thanks for running it under Proton. Your counters match ours: ~1,000 executions a frame through the spread signature, about one record a frame past 65,535. So the cost is the signature itself, and it is clearly worse under vkd3d (copy-back alone 247–360 → 80–100 ms there) than on Windows. With two independent results, on Windows/NVIDIA (card −12.8 ms) and on Linux/vkd3d (frame more than halved), the switch could be on by default, at least on NVIDIA and under vkd3d. A run of `VICTORY_SPREAD_LEAN=alt` on an AMD card would settle whether it can be on everywhere. Happy to change the default in this PR if that is preferred.
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/1352/head:github-bot/gh-1352'
git switch 'github-bot/gh-1352'

Merge

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