Direct dispatches past 65,535 groups in x run in parts #662

Open
0xkn0wh3r3 wants to merge 1 commit from upstream-pr/662 into main
0xkn0wh3r3 commented 2026-11-28 02:58:28 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T02:58:28Z.


What

A direct dispatch with more than 65,535 thread groups in x now runs in parts.

The console runs more than 65,535 groups in x in one dispatch. D3D12 refuses more than D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION (65,535), and State::dispatch passed the title's counts straight through.

Ported from Marvisak/VIctory#3086, which came from DexNom/VIctory@570a941. It's rebuilt on this tree's host words instead of #3086's own user-data plumbing. DexNom is credited with Co-authored-by.

How

  • Shader side:
    • A compute program's group x now adds USER_GROUP_BASE (RootType::Other(0x107)), a dword the host sets through the existing host_word mechanism. As bound, it is 0.
    • The counted path of the structure builder's programs (USER_DISPATCH_THREADS_X) reads group x on its own, so it adds the base too.
    • A program that doesn't read its group x gets no such dword.
  • Host side:
    • State::dispatch runs a dispatch of more than 65,535 groups in x in parts of at most 65,535 (dispatch_parts).
    • Before each part after the first, it sets the dword to that part's first group, then puts it back to 0 afterwards.
    • A program without the dword just runs once per part, which is correct, since it doesn't read group x.
    • More than 65,535 groups in y or z is still passed through, now with a one-time warning.
  • Indirect dispatches are not changed. They're still capped at 65,535 groups on NVIDIA (indirect.rs, widest). That's a separate fix.
  • Shader cache: translations of programs that read group x change. The shader cache key already holds the translator's source hash, so old entries aren't found.

Tests

  • New emit::wave64_tests::group_x_starts_at_the_dispatch_part runs on the GPU. It runs a translated program in which each lane adds 1 to counter[group x], as 2 groups with base 0 and base 3, on the hardware adapter and on WARP.
    • With base 3, counters 3 and 4 must hold 64 and every other counter 0.
    • It fails on the old code: there is no base dword, and group x would start at 0.
  • New draw::thread_tests::large_dispatches_run_in_parts checks the split for 0, 100, 65,535, 65,536, 115,200 and u32::MAX groups. Every part is at most 65,535, the parts follow each other, and together they cover every group once.
  • The existing the_lanes_past_a_count_of_threads_do_not_run (the counted path, now through the base) still passes.
  • cargo test -p victory-shader --lib: 291 passed, 0 failed.
  • cargo test -p victory-gpu --lib: 442 passed, 2 failed. Both fail the same way on main: indirect::tests::host_list_budget_starts_empty_at_each_submission and indirect::tests::warp_batch_charges_every_execution.
  • cargo clippy -p victory-gpu -p victory-shader --all-targets, with and without --all-features: no new warnings. (main has 78, the same count, two of them moved down a few lines in draw.rs.)

Performance, before and after

This is a correctness fix, and I haven't measured any performance numbers for it.

  • Dispatches of up to 65,535 groups in x, nearly all of them, still make one Dispatch call and no extra root constant. The only added work for them is looking up whether the pipeline has the base dword. I expect no change, but didn't measure it.
  • Larger dispatches:
    • Before, Dispatch was called with a count D3D12 refuses.
    • After, it runs as two or more Dispatch calls, plus one SetComputeRoot32BitConstant per part after the first and one to reset the base.

Not measured: the title's own dispatches. DexNom's fork recorded a 115,200 × 1 × 1 dispatch. I haven't checked which of this title's dispatches go over 65,535, or what they draw.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5536017795 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/662). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T02:58:28Z. --- ## What A direct dispatch with more than 65,535 thread groups in x now runs in parts. The console runs more than 65,535 groups in x in one dispatch. D3D12 refuses more than `D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION` (65,535), and `State::dispatch` passed the title's counts straight through. Ported from Marvisak/VIctory#3086, which came from DexNom/VIctory@570a941. It's rebuilt on this tree's host words instead of #3086's own user-data plumbing. DexNom is credited with `Co-authored-by`. ## How - **Shader side:** - A compute program's group x now adds `USER_GROUP_BASE` (`RootType::Other(0x107)`), a dword the host sets through the existing `host_word` mechanism. As bound, it is 0. - The counted path of the structure builder's programs (`USER_DISPATCH_THREADS_X`) reads group x on its own, so it adds the base too. - A program that doesn't read its group x gets no such dword. - **Host side:** - `State::dispatch` runs a dispatch of more than 65,535 groups in x in parts of at most 65,535 (`dispatch_parts`). - Before each part after the first, it sets the dword to that part's first group, then puts it back to 0 afterwards. - A program without the dword just runs once per part, which is correct, since it doesn't read group x. - More than 65,535 groups in y or z is still passed through, now with a one-time warning. - **Indirect dispatches are not changed.** They're still capped at 65,535 groups on NVIDIA (`indirect.rs`, `widest`). That's a separate fix. - **Shader cache:** translations of programs that read group x change. The shader cache key already holds the translator's source hash, so old entries aren't found. ## Tests - New `emit::wave64_tests::group_x_starts_at_the_dispatch_part` runs on the GPU. It runs a translated program in which each lane adds 1 to `counter[group x]`, as 2 groups with base 0 and base 3, on the hardware adapter and on WARP. - With base 3, counters 3 and 4 must hold 64 and every other counter 0. - It fails on the old code: there is no base dword, and group x would start at 0. - New `draw::thread_tests::large_dispatches_run_in_parts` checks the split for 0, 100, 65,535, 65,536, 115,200 and `u32::MAX` groups. Every part is at most 65,535, the parts follow each other, and together they cover every group once. - The existing `the_lanes_past_a_count_of_threads_do_not_run` (the counted path, now through the base) still passes. - `cargo test -p victory-shader --lib`: 291 passed, 0 failed. - `cargo test -p victory-gpu --lib`: 442 passed, 2 failed. Both fail the same way on `main`: `indirect::tests::host_list_budget_starts_empty_at_each_submission` and `indirect::tests::warp_batch_charges_every_execution`. - `cargo clippy -p victory-gpu -p victory-shader --all-targets`, with and without `--all-features`: no new warnings. (`main` has 78, the same count, two of them moved down a few lines in `draw.rs`.) ## Performance, before and after This is a correctness fix, and I haven't measured any performance numbers for it. - **Dispatches of up to 65,535 groups in x**, nearly all of them, still make one `Dispatch` call and no extra root constant. The only added work for them is looking up whether the pipeline has the base dword. I expect no change, but didn't measure it. - **Larger dispatches:** - Before, `Dispatch` was called with a count D3D12 refuses. - After, it runs as two or more `Dispatch` calls, plus one `SetComputeRoot32BitConstant` per part after the first and one to reset the base. **Not measured:** the title's own dispatches. DexNom's fork recorded a 115,200 × 1 × 1 dispatch. I haven't checked which of this title's dispatches go over 65,535, or what they draw.
Dukestar69 commented 2026-11-28 05:38:34 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T05:38:34Z.

Review: APPROVED


LGTM — verified on Windows (RTX 5090):

  • cargo test -p victory-shader --lib emit::tests:: passed (22/22)
  • cargo test -p victory-gpu --lib draw:: passed (9/9, including draw::thread_tests::large_dispatches_run_in_parts)
  • 0 new compiler warnings in touched files
  • cargo xtask policy passed (294 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6096086989 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/662#pullrequestreview-6096086989). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T05:38:34Z. **Review:** APPROVED --- LGTM — verified on Windows (RTX 5090): - `cargo test -p victory-shader --lib emit::tests::` passed (22/22) - `cargo test -p victory-gpu --lib draw::` passed (9/9, including `draw::thread_tests::large_dispatches_run_in_parts`) - 0 new compiler warnings in touched files - `cargo xtask policy` passed (`294 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/662:upstream-pr/662'
git switch 'upstream-pr/662'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/662'
git switch 'upstream-pr/662'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/662'
git switch 'upstream-pr/662'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/662'
git switch 'main'
git merge --squash 'upstream-pr/662'
git switch 'main'
git merge --ff-only 'upstream-pr/662'
git switch 'main'
git merge 'upstream-pr/662'
git push origin 'main'
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
trustno1-coder/VIctory-NVIDIA!662
No description provided.