VICTORY_DISPATCH_SPREAD costs ~20 ms of card time a frame on an RTX 3060; with =0, 2 of 4 loads hang (DEVICE_HUNG) #1338

Open
opened 2026-11-26 17:09:58 +00:00 by github-bot · 2 comments
Owner

@⁠grosterr on GitHub · 2026-11-26 17:06 UTC · original

RTX 3060 12 GB (driver as of 2026-11), Ryzen 7 5700X, 32 GB RAM, Windows 11, Series X profile, prison prologue, the same save every run. Release build of our branch: the #770 stack with main 06702fe + ceb9e1f merged in, plus VICTORY_LEVELS_ON_DEMAND EARLY_TEXTURES_MS=40 TEXTURE_NO_WAIT WIDE_TEXTURES ASYNC_SUBMIT QUEUE2 INDIRECT_WINDOW COPY_PLAIN JOIN_PARTS BACK_OWN_VIEW INDIRECT_GATHER CARD_HASH_WIDE LOOKUP_CACHE. World frames only (> 4,000 draws, 0 being made), medians of the last 4 minutes of each run, warm pipeline library.

run spread frame on the GPU preparing copying back draws
control: our build before 06702fe (none yet) 194 ms 76 ms 79 ms 58 ms 6,105
after 06702fe + ceb9e1f on (default) 210 ms 94 ms 73 ms 52 ms 5,275
same binary, next run VICTORY_DISPATCH_SPREAD=0 177 ms 72 ms 72 ms 50 ms 5,416

The card's time goes up by 18-22 ms with the spread at fewer draws, and the cold run of the same build showed the same (99 ms). Preparing and copy-back do not move.

But =0 is not an option here: 2 of the 4 runs with VICTORY_DISPATCH_SPREAD=0 lost the device while loading, 1 min 42 s and 2.5 min in. Both had DXGI_ERROR_DEVICE_HUNG (0x887A0006), the submitting thread preparing a submission (~0.5 s, nothing of ours on the card), and no breadcrumbs. 0 of 4 runs with the spread on were lost. We read it as: a dispatch clamped to 65,535 groups leaves data the next passes rely on (indirect arguments among them) half made.

Where the cost may come from. In the same warm run the frame line says 550-1,030 indirect dispatches a frame go through the spread signature (CONSTANT ×2 + DISPATCH, stride 20). The clamp's own line says the largest group count asked for is ~84,000 (max 115,200), with 260-290 thousand groups asked a frame in all. So only a few dispatches seem to need the spread, while hundreds take the signature that sets root constants. On NVIDIA an ExecuteIndirect whose signature changes root arguments is known to cost more than a plain dispatch signature. Our guess is that this, not the extra groups, is most of the 20 ms. We have not proven it yet. We are working on a variant that keeps the plain signature for records within 65,535 and will post the A/B here.

Has anyone measured =alt on another NVIDIA card? A count, in the clamp, of records whose x really passes 65,535 would settle which of the two it is.

**@⁠grosterr** on GitHub · 2026-11-26 17:06 UTC · [original](https://github.com/fxceless/victory-fork/issues/1338) RTX 3060 12 GB (driver as of 2026-11), Ryzen 7 5700X, 32 GB RAM, Windows 11, Series X profile, prison prologue, the same save every run. Release build of our branch: the #770 stack with main `06702fe` + `ceb9e1f` merged in, plus `VICTORY_LEVELS_ON_DEMAND EARLY_TEXTURES_MS=40 TEXTURE_NO_WAIT WIDE_TEXTURES ASYNC_SUBMIT QUEUE2 INDIRECT_WINDOW COPY_PLAIN JOIN_PARTS BACK_OWN_VIEW INDIRECT_GATHER CARD_HASH_WIDE LOOKUP_CACHE`. World frames only (> 4,000 draws, `0 being made`), medians of the last 4 minutes of each run, warm pipeline library. | run | spread | frame | on the GPU | preparing | copying back | draws | |---|---|---|---|---|---|---| | control: our build before `06702fe` | (none yet) | 194 ms | 76 ms | 79 ms | 58 ms | 6,105 | | after `06702fe` + `ceb9e1f` | on (default) | 210 ms | **94 ms** | 73 ms | 52 ms | 5,275 | | same binary, next run | `VICTORY_DISPATCH_SPREAD=0` | 177 ms | **72 ms** | 72 ms | 50 ms | 5,416 | The card's time goes up by 18-22 ms with the spread at fewer draws, and the cold run of the same build showed the same (99 ms). Preparing and copy-back do not move. **But `=0` is not an option here:** 2 of the 4 runs with `VICTORY_DISPATCH_SPREAD=0` lost the device while loading, 1 min 42 s and 2.5 min in. Both had `DXGI_ERROR_DEVICE_HUNG` (0x887A0006), the submitting thread preparing a submission (~0.5 s, nothing of ours on the card), and no breadcrumbs. 0 of 4 runs with the spread on were lost. We read it as: a dispatch clamped to 65,535 groups leaves data the next passes rely on (indirect arguments among them) half made. **Where the cost may come from.** In the same warm run the frame line says 550-1,030 indirect dispatches a frame go through the spread signature (`CONSTANT` ×2 + `DISPATCH`, stride 20). The clamp's own line says the largest group count asked for is ~84,000 (max 115,200), with 260-290 thousand groups asked a frame in all. So only a few dispatches seem to need the spread, while hundreds take the signature that sets root constants. On NVIDIA an `ExecuteIndirect` whose signature changes root arguments is known to cost more than a plain dispatch signature. Our guess is that this, not the extra groups, is most of the 20 ms. We have not proven it yet. We are working on a variant that keeps the plain signature for records within 65,535 and will post the A/B here. Has anyone measured `=alt` on another NVIDIA card? A count, in the clamp, of records whose x really passes 65,535 would settle which of the two it is.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:09:58 +00:00
Author
Owner

@⁠grosterr on GitHub · 2026-11-26 17:33 UTC · original

Follow-up: most of it is the signature, and it can be had back without clamping.

Counters. We added two counters to the clamp: records that really ask for more than 65,535 groups in x, and the rest. Of the ~890-990 indirect dispatches a frame that go through the spread signature, only 0.4-1.2 a frame pass 65,535 (15-38 thousand extra groups). The other ~900-1,450 records are within the limit.

A cheaper path, VICTORY_SPREAD_LEAN=1|alt (off by default, no translator change):

  • The clamp writes each batch twice into its scratch buffer: plain [x, y, z] records, where those over 65,535 are zeroed, and the spread [row, asked x, x, y, z] records, where those within it are zeroed.
  • Between the two arrays it writes one predicate word: 1 if any active record passes 65,535.
  • Recorded as ExecuteIndirect with the plain DISPATCH signature, then SetPredication(EQUAL_ZERO) on that word, then ExecuteIndirect with the spread signature, then predication off.
  • Nothing is clamped, so the loads that hang with =0 do not apply.

A micro-benchmark on the 3060 (1,000 single-record ExecuteIndirects of empty dispatches): the spread signature takes 1.88 ms of card time against 0.06 ms for the plain one; behind a predicate that is 0 it takes 0.53 ms.

In game (RTX 3060, same setup as above, standing still at one spot, =alt 20 s / 20 s, 9 pairs, warm library):

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 came out lower in all 9 pairs: −22, −19, −9, −19, −16, −7, −1, −13, −8 ms (median −12.8). Preparing pays about +4 ms for recording two calls and the predication instead of one. So in a real frame the signature that sets root constants costs far more than in the empty benchmark, about 13 ms a frame on this card, probably because the driver serialises around it. The rest of the spread's 18-22 ms is either the extra groups or the prologue.

We can open a pull request with this if it is of use (crates/victory-gpu: indirect.rs, draw.rs, host.rs; WARP tests for the routing and for equal group ids at 100,000 groups).

**@⁠grosterr** on GitHub · 2026-11-26 17:33 UTC · [original](https://github.com/fxceless/victory-fork/issues/1338#issuecomment-7199210251) Follow-up: most of it is the signature, and it can be had back without clamping. **Counters.** We added two counters to the clamp: records that really ask for more than 65,535 groups in x, and the rest. Of the ~890-990 indirect dispatches a frame that go through the spread signature, only **0.4-1.2 a frame** pass 65,535 (15-38 thousand extra groups). The other ~900-1,450 records are within the limit. **A cheaper path, `VICTORY_SPREAD_LEAN=1|alt`** (off by default, no translator change): - The clamp writes each batch twice into its scratch buffer: plain `[x, y, z]` records, where those over 65,535 are zeroed, and the spread `[row, asked x, x, y, z]` records, where those within it are zeroed. - Between the two arrays it writes one predicate word: 1 if any active record passes 65,535. - Recorded as `ExecuteIndirect` with the plain `DISPATCH` signature, then `SetPredication(EQUAL_ZERO)` on that word, then `ExecuteIndirect` with the spread signature, then predication off. - Nothing is clamped, so the loads that hang with `=0` do not apply. A micro-benchmark on the 3060 (1,000 single-record `ExecuteIndirect`s of empty dispatches): the spread signature takes 1.88 ms of card time against 0.06 ms for the plain one; behind a predicate that is 0 it takes 0.53 ms. **In game** (RTX 3060, same setup as above, standing still at one spot, `=alt` 20 s / 20 s, 9 pairs, warm library): | | 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 came out lower in all 9 pairs: −22, −19, −9, −19, −16, −7, −1, −13, −8 ms (median −12.8). Preparing pays about +4 ms for recording two calls and the predication instead of one. So in a real frame the signature that sets root constants costs far more than in the empty benchmark, about 13 ms a frame on this card, probably because the driver serialises around it. The rest of the spread's 18-22 ms is either the extra groups or the prologue. We can open a pull request with this if it is of use (`crates/victory-gpu`: `indirect.rs`, `draw.rs`, `host.rs`; WARP tests for the routing and for equal group ids at 100,000 groups).
Author
Owner

@⁠grosterr on GitHub · 2026-11-26 17:43 UTC · original

Opened as #1352 (rebased on e4245f3, off by default).

**@⁠grosterr** on GitHub · 2026-11-26 17:43 UTC · [original](https://github.com/fxceless/victory-fork/issues/1338#issuecomment-7199542328) Opened as #1352 (rebased on `e4245f3`, off by default).
This discussion has been locked. Commenting is limited to contributors.
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/fxceless--victory-fork#1338
No description provided.