Skip to content

GPU, Shaders: direct dispatches past 65,535 groups in x run in parts - #3086

Open
0xkn0wh3r3 wants to merge 3 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/dispatch-x-past-65535-in-parts
Open

0xkn0wh3r3 wants to merge 3 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/dispatch-x-past-65535-in-parts

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What

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

A direct Dispatch with more than 65,535 groups in x now runs in parts of at most 65,535, with y and z as asked.

  • Shader side: a compute program's group x adds a user-data dword that the host fills itself, RootType::Other(GROUP_BASE), placed past the console's user data. It holds the first group of the part being run, and is 0 as bound.
  • Host side: State::dispatch sets that dword to each part's first group (dispatch_parts), then back to 0 afterwards.
  • A program that doesn't read its group x gets no such dword. It runs alike in every part, so splitting it needs nothing more.
  • Groups past 65,535 in y or z are still passed through, now with a warning.
  • Translations of programs that read their group x change. The shader cache key already hashes the translator's sources (victory_shader::SOURCE_HASH), so old entries aren't found and the cache magic stays VSH1.

Relation to #2312 and #2841

Where it came from

From DexNom's fork, DexNom/VIctory@570a941: USER_GROUP_BASE added to the group id, and the direct dispatch run in parts. Here it's on this tree's user-data model. DexNom applied it only to programs that read neither group y nor group z. Adding the base to group x is right whatever else the program reads, so this PR applies it to every compute program that reads group x. Credited with Co-authored-by: DexNom.

Tested

  • emit::semantics_tests::group_x_starts_at_the_dispatch_part: a translated program run with base 1, on the hardware adapter and on WARP, reads its input and writes its output as group 1. Group 0's output stays untouched. It fails without the change (no base dword).
  • draw::tests::large_dispatches_run_in_parts: 0, 100, 65,535, 65,536, 115,200 and u32::MAX groups each split into parts of at most 65,535 that cover every group once.
  • cargo test -p victory-gpu --lib: 231 passed. The 2 failures are the ones GPU: page view heaps a host caps below the slots shaders index #2121 fixes; they fail the same on main.
  • cargo test -p victory-shader --lib (skipping heap_direct_texture_reads_mark_their_heap_index, which crashes on main): 297 passed and 5 failed. All 5 fail the same on main: the 2 stride_tests, gathers_at_a_level_match_the_hardware, rectangles_get_their_fourth_corner and elements_sharing_a_row_keep_their_order.
  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings, and victory-gpu with --features diagnostics: clean.

Not tested

  • Not run with the title. DexNom's fork shows a 115,200 × 1 × 1 dispatch; I haven't seen one with z > 1 in a title.

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

A compute program's group x now adds a user-data dword the host fills
itself (RootType::Other(GROUP_BASE), placed past the console's user
data): the first group of the part of the dispatch the host runs, 0 as
bound. State::dispatch runs a dispatch of more than 65,535 groups in x
in parts of at most 65,535 (dispatch_parts), setting the dword to each
part's first group, with y and z as asked, and sets it back to 0 after.
A program that does not read its group x has no such dword and runs
alike in every part. Groups in y or z past 65,535 are still passed
through, with a warning. Translations change for programs that read
their group x, so the shader cache's entries are VSH2.

Tests: group_x_starts_at_the_dispatch_part (a translated program run
with base 1 on the hardware adapter and WARP reads and writes as group
1), large_dispatches_run_in_parts (each group once, in parts of at most
65,535).

From DexNom/VIctory@570a941
(USER_GROUP_BASE added to the group id, and the direct dispatch run in
parts), on this tree's user data.

Co-authored-by: DexNom <29156494+DexNom@users.noreply.github.com>

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + dxil.dll):

  • cargo test -p victory-shader group_x_starts_at_the_dispatch_part -- --test-threads=1 (RTX 5090 & WARP): 1 passed, 0 failed on both.
  • cargo test -p victory-gpu draw::tests -- --test-threads=1 (RTX 5090): 21 passed, 0 failed (including large_dispatches_run_in_parts).
  • cargo test -p victory-gpu shader_cache::tests: 4 passed, 0 failed.
  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
With Marvisak#2948's root UAVs the cache entry is VSH3, and the new test passes native16 (Marvisak#2825).
@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown

Independent WARP verification of this PR at exact head 44375c1 (parent 63bcca4, main). Claim: #1633 (comment)

Setup. Windows 11, WARP only; the physical GPU was never used. VICTORY_WARP=1 (this is what makes the shader test host's Host::new(false) pick WARP too) and VICTORY_D3D12_WARP=1 (read by victory-gpu only with --features diagnostics, which I built with). The test device was confirmed from its LUID: Microsoft Basic Render Driver, DXGI_ADAPTER_FLAG_SOFTWARE set, vendor 0x1414, 0 dedicated VRAM. Shaders were validated with the Windows SDK dxil.dll (10.0.26100.0). cargo -j 4.

Boundary / group-ID check (local harness, not part of the PR: it lowers the same synthetic program as group_x_starts_at_the_dispatch_part, with unique input dwords, and runs it the way State::dispatch does: dispatch_parts split, GROUP_BASE = each part's first group). Per part it checks that the groups of that part hold exactly their own input, and that every other group is untouched.

x × y × z PR head exact parent (same harness, no GROUP_BASE dword)
1, 64, 65,534, 65,535 × 1 × 1 0 wrong lanes 0 wrong lanes (identical)
65,536 / 65,537 × 1 × 1 0 wrong 64 / 128 wrong lanes (part 2 re-runs group 0 onward)
131,070 / 131,071 × 1 × 1 0 wrong 4,194,240 / 4,194,304 wrong lanes
3×4×2, 65,536×2×3, 1×65,535×1, 1×1×65,535 0 wrong same as above for the x split; 0 wrong where x ≤ 65,535

PR head: 0 mismatches in all 12 cases (parts of at most 65,535 covering every x group once). The parent is the control: the same split without a base word gives the wrong group ids for every part after the first, so the check does tell the two apart. Dispatches of 65,535 in y or z and x=65,536 with y=2, z=3 ran and matched (the shader keys on group x only, so the y/z groups write the same values; this covers that y/z are passed through with the parts, not that y/z are numbered).

Focused suites on the PR head (all WARP):

  • cargo test -p victory-gpu --lib --features diagnostics -- draw::tests::large_dispatches_run_in_parts shader_cache: 5 passed (includes the VSH2 cache entries).
  • cargo test -p victory-shader --lib -- emit::semantics_tests --test-threads=1: 35 passed, 1 ignored (existing defect_ ignore), includes group_x_starts_at_the_dispatch_part. Both of its adapter iterations ran on WARP here.
  • emit::flow_tests, memory_tests, crosslane_tests, waterfall_tests, valu_tests: 51 passed.

Limitations. Synthetic inputs only; no game files, shader names, hashes, dumps or retail artifacts. WARP only, so nothing here speaks for GPU drivers. Not tested: y or z over 65,535 (D3D12 refuses it, and I did not send it to the device), indirect dispatches, the real State::dispatch command-list path (I replicated its split and base writes in the harness; dispatch_parts itself is covered by the PR's unit test), and the SetComputeRoot32BitConstant reset back to 0 for a following dispatch. The full victory-gpu and victory-shader suites were not run, so the PR's stated pre-existing failures were neither confirmed nor refuted.

The harness stayed local and the PR was not touched.

AI use: Claude Code (Claude Sonnet 5.5), coordinated by Codex (gpt-6.2-sol).

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on Windows 11 x64 (rustc 1.98.1, NVIDIA GeForce RTX 5090 + WARP + SDK dxil.dll):

  • cargo clippy -p victory-shader -p victory-gpu --all-targets --locked -- -D warnings (default and --all-features): clean.
  • cargo test -p victory-shader --lib --locked -- emit::semantics_tests --test-threads=1: 35 passed, 0 failed, 1 ignored (group_x_starts_at_the_dispatch_part verified on both RTX 5090 and WARP).
  • cargo test -p victory-gpu --lib --locked -- draw::tests --test-threads=1: 21 passed, 0 failed on both RTX 5090 and WARP (--features diagnostics, VICTORY_D3D12_WARP=1).
  • cargo test -p victory-gpu --lib --locked -- shader_cache::tests --test-threads=1: 4 passed, 0 failed on both RTX 5090 and WARP.
  • cargo xtask policy: 191 files ok.

The lowering and split logic look solid: lower.rs does not emit SV_DispatchThreadID (threadId.i32), so offsetting Input::GroupId(0) shifts derived global IDs consistently; index = max(p.user_data + p.sgprs) avoids collisions with ROOT_SRV_VIEW/ROOT_UAV_VIEW/ROOT_VIEW_OFFSET; and dispatch_parts handles 0..=u32::MAX without overflow.

One small diagnostics bug to fix in crates/victory-gpu/src/draw.rs (op_text, under #[cfg(feature = "diagnostics")]):

  • State::bind special-cases RootType::Other(victory_shader::emit::GROUP_BASE) => 0, but op_text iterates t.host.user_data.iter().filter(|u| !is_root_view(u)) and calls self.user_value(compute, u.slot, u.root, u.dword). For any compute shader reading GroupId(0), that hits user_value's fallback _ => arm, logging a spurious "a shader reads a root argument the title did not set" warning (slot = 0, root = Other(260)) and printing a bogus [heap 0: ...] lookup in op_text. Filtering out u.root == RootType::Other(victory_shader::emit::GROUP_BASE) alongside !is_root_view(u) avoids this.

Minor non-blocking note:

  • Bumping MAGIC from VSH1 to VSH2 in crates/victory-gpu/src/shader_cache.rs is not strictly needed: the binary encoding didn't change (root_code/root_type already round-trip RootType::Other(0x104)), and shader_cache::build() already hashes victory_shader::SOURCE_HASH into both the cache subdirectory and key. Keeping VSH1 would avoid an unnecessary merge conflict with other PRs touching shader_cache.rs (such as #2948).

… keeps VSH1

op_text skipped root views but not GROUP_BASE, so a compute program that reads its group x logged a spurious unset root argument and a heap lookup for it. The cache key already hashes the translator's sources, so its magic needs no bump.
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Thanks, both taken in e4fa1a1. op_text now skips the GROUP_BASE root alongside root views, so a compute program that reads its group x no longer logs a spurious unset root argument or a heap lookup for it. The cache magic is back to VSH1: build() already hashes victory_shader::SOURCE_HASH (and the encoding file's own text) into the key, so old entries aren't found anyway. That also removes the VSH2 overlap with #2948. draw::tests and shader_cache pass with and without --features diagnostics, and clippy is clean both ways.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work (small). The approach looks right. State::dispatch splits a direct dispatch with more than 65,535 groups in x into parts (dispatch_parts). Each part's first group goes into a host-filled root constant (RootType::Other(GROUP_BASE)), which is bound as 0 in the user-data loop and reset to 0 after the parts. In emit/lower.rs, group_x adds that constant to group x for CS programs only. The unit test and the semantics test cover the split and the base.

Needed before merge:

  • In emit/lower.rs, group_x was inserted between compute_id and its doc comment. group_x's doc now begins with "A component of a compute thread or group id, read in the entry block." and compute_id has no doc. Please move that line back above fn compute_id.
  • This overlaps GPU, Shaders: spread compute dispatches past 65,535 groups in x across z (fixes #2256) #2312 (spreading x across z, which also covers indirect dispatches and claims the same first user-data dword past the console's). Needs the maintainer's decision on which approach lands. The other one then needs a rebase.

CI: passing (check).


Generated by Claude Code

group_x was inserted between compute_id and its doc; the line is back above compute_id.
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Fixed in 2fd63f0: the doc line is back above fn compute_id, and group_x keeps only its own doc. On #2312: agreed, that's your call. Both claim the first user-data dword past the console's, so whichever lands second moves its word by one, and I'll rebase this onto #2312 if you take that one. The difference is that this PR covers direct dispatches with any y and z (including z > 1, which #2312 leaves out), while #2312 also covers indirect dispatches.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both points from the earlier review are cleanly addressed in e4fa1a1b (and the doc comment placement cleanup in 2fd63f00 looks good):

  • op_text in crates/victory-gpu/src/draw.rs now filters out RootType::Other(victory_shader::emit::GROUP_BASE), avoiding spurious missing-root-argument warnings and bogus heap lookups in diagnostics logs.
  • crates/victory-gpu/src/shader_cache.rs is left untouched on VSH1, relying on victory_shader::SOURCE_HASH for cache invalidation without colliding with other cache format work.

Verified locally on Windows 11 (RTX 5090 + WARP):

  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings (default and --all-features): clean
  • victory-shader emit::semantics_tests::group_x_starts_at_the_dispatch_part: passed (both hardware and WARP paths)
  • victory-gpu draw::tests (21/21 on RTX 5090, 21/21 on WARP with --features diagnostics) and shader_cache::tests (4/4): all passed
  • cargo xtask policy: 191 files ok

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants