DispatchX: dispatches by thread count run that many threads (the ray-tracing builder ran 64 times too many) #1289

Closed
KyleS98 wants to merge 1 commit from upstream-pr/1292 into main
KyleS98 commented 2026-11-26 11:24:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-26T11:24:36Z.


What was wrong

DispatchX(x, y, z, flags) passed its flags over ("which the host has no use for"). They are the console card's own dispatch bits, and bit 5 (0x20, "use thread dimensions") changes what x, y, z mean: counts of threads, not of thread groups. The card runs the groups that hold them and, in the last group, only the threads below the count.

The ray-tracing structure builder dispatches its in-place stages this way:

program flags
28918b7150a7aad5 0x20
caa78b8ca62bc3d6 0x20
4ddd6f9702fab2a7 0x8020
5062bc7a48e842f8 0x8020

(0x8000 is the card's 32-lane-waves bit; those two programs are wave32.) Every other builder program comes through plain Dispatch.

Taken as groups, a stage of 64 threads a group ran 64 times the threads it was asked for and made its nodes from whatever lay behind the level's records, megabytes past the structure's end. This is what stores bounding boxes over the title's own objects within a second of the first build.

How I know the counts are threads

I traced every builder dispatch with its root arguments. For one structure, 25 DispatchX calls in a row, alternating the two tree stages; each asks for x and the next stage's records begin exactly x times the node size further on:

28918b71 x=5348 offset 0x15fc80   next +0xa7200 = 5348 x 128 bytes
caa78b8c x=17   offset 0x206e80   next +0x440   =   17 x  64 bytes
28918b71 x=1761 offset 0x2072c0   next +0x37080 = 1761 x 128 bytes
caa78b8c x=12   offset 0x23e340   next +0x300   =   12 x  64 bytes
28918b71 x=727  offset 0x23e640   next +0x16b80 =  727 x 128 bytes
...
28918b71 x=1    offset 0x2683c0   next +0x80    =    1 x 128 bytes

The stages' code agrees: 28918b71 reads one header dword per lane at offset + group * 8192 + lane * 4 and stores one 128-byte node per lane at offset + group * 8192 + lane * 128, so a group of 64 threads is 64 nodes, and it counts its wave's lanes with s_bcnt1_i32_b64 exec to find where the child lists begin.

Switching those two programs off (VICTORY_SKIP_PIPELINES) took the stray write-backs away and the crash with them; switching others off did not.

The change

  • DispatchX with bit 5 set: the counts become group counts by the program's group size (rounded up), and the host notes the thread count along x for that dispatch.
  • The translated program is told the count in a host word (USER_THREAD_LIMIT; u32::MAX for a dispatch by groups).
  • Compute programs with a spilled user-data table (the builder's) start with EXEC as each lane's own bit, not "every lane": a lane past the count is in the wave and outside EXEC. A count of EXEC's lanes leaves it out, its stores do not happen, and a program that widens EXEC to every lane runs it, as on the console. All 52 builder programs I have still translate, for 32-lane and 64-lane hosts.
  • VICTORY_DISPATCH_THREADS=0 and VICTORY_THREAD_LIMIT=0 give the old behaviour.

Not done: counts along y and z are only rounded up to groups (every dispatch I saw has 1 there).

Tested

RTX 3090 Ti (32-lane waves), on main 06702fe plus this commit.

  • Unit test on the card (lanes_past_a_dispatchs_thread_count_start_outside_exec): one console wave of 64 run as two host waves, every lane stores the number of lanes in EXEC at its own dword. For 64, 63, 33, 32, 31, 6 and 1 threads the lanes below the count store the count and the others store nothing.
  • Builder on (VICTORY_BVH_BUILDER=1 VICTORY_FIRSTLANE_OWN=1, Series X, 300 s): the builder started at 11:15:12 and was still running when the run ended at 11:18:07. No exception in the title, no device loss. Before, the title died within seconds of the first builder submission on every run of mine.
  • Builder off (the default; Series X, 300 s into the prologue cell): unchanged picture, no crash.
  • cargo clippy on both crates: clean.

What this does not do

The builder is still not usable on main with this alone. In that run a frame took 4 to 7 seconds, the log has no number left for another copy; its pages read zeros COPIES=1023 and several hundred pages touched without a copy, and I did not check the picture.

On my integration branch, with two more changes I will send separately (root views of the builder's programs reached by address, since a bound view ends at its 4 MiB window and structures cross them; and root views that lie in the builder library's own memory, above the directory's 128 GiB), the prologue cell comes out lit through its window with the figure's shadow on the wall. That is one frame at about 4 s a frame, and the title still died later in that run, so I am not claiming more than that here.

AI-assisted (Claude Code, Claude Fable 5.2).

<!-- greyfinch-sync:fxceless/victory-fork:issue:6625612310 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1292). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-26T11:24:36Z. --- ## What was wrong `DispatchX(x, y, z, flags)` passed its flags over ("which the host has no use for"). They are the console card's own dispatch bits, and bit 5 (`0x20`, "use thread dimensions") changes what `x`, `y`, `z` mean: counts of **threads**, not of thread groups. The card runs the groups that hold them and, in the last group, only the threads below the count. The ray-tracing structure builder dispatches its in-place stages this way: | program | flags | |---|---| | `28918b7150a7aad5` | `0x20` | | `caa78b8ca62bc3d6` | `0x20` | | `4ddd6f9702fab2a7` | `0x8020` | | `5062bc7a48e842f8` | `0x8020` | (`0x8000` is the card's 32-lane-waves bit; those two programs are wave32.) Every other builder program comes through plain `Dispatch`. Taken as groups, a stage of 64 threads a group ran 64 times the threads it was asked for and made its nodes from whatever lay behind the level's records, megabytes past the structure's end. This is what stores bounding boxes over the title's own objects within a second of the first build. ## How I know the counts are threads I traced every builder dispatch with its root arguments. For one structure, 25 `DispatchX` calls in a row, alternating the two tree stages; each asks for `x` and the next stage's records begin exactly `x` times the node size further on: ``` 28918b71 x=5348 offset 0x15fc80 next +0xa7200 = 5348 x 128 bytes caa78b8c x=17 offset 0x206e80 next +0x440 = 17 x 64 bytes 28918b71 x=1761 offset 0x2072c0 next +0x37080 = 1761 x 128 bytes caa78b8c x=12 offset 0x23e340 next +0x300 = 12 x 64 bytes 28918b71 x=727 offset 0x23e640 next +0x16b80 = 727 x 128 bytes ... 28918b71 x=1 offset 0x2683c0 next +0x80 = 1 x 128 bytes ``` The stages' code agrees: `28918b71` reads one header dword per lane at `offset + group * 8192 + lane * 4` and stores one 128-byte node per lane at `offset + group * 8192 + lane * 128`, so a group of 64 threads is 64 nodes, and it counts its wave's lanes with `s_bcnt1_i32_b64 exec` to find where the child lists begin. Switching those two programs off (`VICTORY_SKIP_PIPELINES`) took the stray write-backs away and the crash with them; switching others off did not. ## The change - `DispatchX` with bit 5 set: the counts become group counts by the program's group size (rounded up), and the host notes the thread count along x for that dispatch. - The translated program is told the count in a host word (`USER_THREAD_LIMIT`; `u32::MAX` for a dispatch by groups). - Compute programs with a spilled user-data table (the builder's) start with EXEC as each lane's own bit, not "every lane": a lane past the count is in the wave and outside EXEC. A count of EXEC's lanes leaves it out, its stores do not happen, and a program that widens EXEC to every lane runs it, as on the console. All 52 builder programs I have still translate, for 32-lane and 64-lane hosts. - `VICTORY_DISPATCH_THREADS=0` and `VICTORY_THREAD_LIMIT=0` give the old behaviour. Not done: counts along y and z are only rounded up to groups (every dispatch I saw has 1 there). ## Tested RTX 3090 Ti (32-lane waves), on `main` `06702fe` plus this commit. - **Unit test on the card** (`lanes_past_a_dispatchs_thread_count_start_outside_exec`): one console wave of 64 run as two host waves, every lane stores the number of lanes in EXEC at its own dword. For 64, 63, 33, 32, 31, 6 and 1 threads the lanes below the count store the count and the others store nothing. - **Builder on** (`VICTORY_BVH_BUILDER=1 VICTORY_FIRSTLANE_OWN=1`, Series X, 300 s): the builder started at 11:15:12 and was still running when the run ended at 11:18:07. No exception in the title, no device loss. Before, the title died within seconds of the first builder submission on every run of mine. - **Builder off** (the default; Series X, 300 s into the prologue cell): unchanged picture, no crash. - `cargo clippy` on both crates: clean. ## What this does not do The builder is still not usable on `main` with this alone. In that run a frame took 4 to 7 seconds, the log has `no number left for another copy; its pages read zeros COPIES=1023` and several hundred pages touched without a copy, and I did not check the picture. On my integration branch, with two more changes I will send separately (root views of the builder's programs reached by address, since a bound view ends at its 4 MiB window and structures cross them; and root views that lie in the builder library's own memory, above the directory's 128 GiB), the prologue cell comes out lit through its window with the figure's shadow on the wall. That is one frame at about 4 s a frame, and the title still died later in that run, so I am not claiming more than that here. AI-assisted (Claude Code, Claude Fable 5.2).
HLVM04 commented 2026-11-26 12:07:19 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HLVM04 on 2026-11-26T11:27:37Z.


For overlap: fork PR #994 (stacked on #854 and #993) already handles the same USE_THREAD_DIMENSIONS bit (0x20 / 0x8020) in DispatchX, with a thread-limited translated form and a USER_THREAD_LIMIT word. It also covers the upload-memory addresses that the builder's header stage reads. That sounds close to the two follow-ups you plan to send.

Our data with it, RTX 5070 Ti (32-lane), Windows, Series S profile, on our own integration stack plus #993/#994 (c9ca6b2 + 55f0043 + 51700c6), not on 06702fe:

  • VICTORY_BVH_BUILDER=1 ran steady at 70-77 ms a frame in the first window scene. There was no crash in 2 runs of 380 s, and interiors were much better lit.
  • Caveat: with the builder on, the main character's skin draw was missing from the G-buffer in both builder-on runs. Free RAM fell to 0.5-0.8 GB of 31 GB.
  • Before #994, a local fix of ours for only the 0x20 counts still crashed about 70 s in.

These are few runs on a different tree, and we did not run this PR's code. Details are in the #994 thread.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7190755904 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1292#issuecomment-7190755904). Originally posted by [HLVM04](https://github.com/HLVM04) on 2026-11-26T11:27:37Z. --- For overlap: fork PR #994 (stacked on #854 and #993) already handles the same `USE_THREAD_DIMENSIONS` bit (0x20 / 0x8020) in `DispatchX`, with a thread-limited translated form and a `USER_THREAD_LIMIT` word. It also covers the upload-memory addresses that the builder's header stage reads. That sounds close to the two follow-ups you plan to send. Our data with it, RTX 5070 Ti (32-lane), Windows, Series S profile, on our own integration stack plus #993/#994 (c9ca6b2 + 55f0043 + 51700c6), not on 06702fe: - `VICTORY_BVH_BUILDER=1` ran steady at 70-77 ms a frame in the first window scene. There was no crash in 2 runs of 380 s, and interiors were much better lit. - Caveat: with the builder on, the main character's skin draw was missing from the G-buffer in both builder-on runs. Free RAM fell to 0.5-0.8 GB of 31 GB. - Before #994, a local fix of ours for only the 0x20 counts still crashed about 70 s in. These are few runs on a different tree, and we did not run this PR's code. Details are in the #994 thread.
upstream-sync closed this pull request 2026-11-26 13:05:49 +00:00
KyleS98 commented 2026-11-26 13:05:53 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-26T13:02:56Z.


@HLVM04 thanks, you are right, and it goes further than #994: this is a duplicate. I did not search before opening it.

  • #646 (mynzjerko) has the same fix and was opened about 31 hours before this one: DispatchX with USE_THREAD_DIMENSIONS takes the counts as threads, and the lanes past the count are masked. It also handles y and z, which this PR does not, and it has been run on four cards.
  • #840 (Yorivel) was the same finding again, closed by its author in favour of #646.
  • #994 (PiloteCode) carries it with the rest of what the builder needs, including the two follow-ups I said I would send (root views by address, memory past the directory). I will not send those.

The analysis in #16 had the cause before any of us. I reached it separately from my own traces, which is a confirmation and nothing more.

Closing in favour of #646. I will post what is useful from here on #646: the RTX 3090 Ti results and a note on why it no longer merges onto main.

AI-assisted (Claude Code, Claude Fable 5.2).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7192803488 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1292#issuecomment-7192803488). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-26T13:02:56Z. --- @HLVM04 thanks, you are right, and it goes further than #994: this is a duplicate. I did not search before opening it. - #646 (mynzjerko) has the same fix and was opened about 31 hours before this one: `DispatchX` with `USE_THREAD_DIMENSIONS` takes the counts as threads, and the lanes past the count are masked. It also handles y and z, which this PR does not, and it has been run on four cards. - #840 (Yorivel) was the same finding again, closed by its author in favour of #646. - #994 (PiloteCode) carries it with the rest of what the builder needs, including the two follow-ups I said I would send (root views by address, memory past the directory). I will not send those. The analysis in #16 had the cause before any of us. I reached it separately from my own traces, which is a confirmation and nothing more. Closing in favour of #646. I will post what is useful from here on #646: the RTX 3090 Ti results and a note on why it no longer merges onto `main`. AI-assisted (Claude Code, Claude Fable 5.2).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!1289
No description provided.