Repository navigation
GPU, Shaders: direct dispatches past 65,535 groups in x run in parts - #3086
0xkn0wh3r3 wants to merge 3 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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 (includinglarge_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).
With Marvisak#2948's root UAVs the cache entry is VSH3, and the new test passes native16 (Marvisak#2825).
|
Independent WARP verification of this PR at exact head 44375c1 (parent 63bcca4, Setup. Windows 11, WARP only; the physical GPU was never used. Boundary / group-ID check (local harness, not part of the PR: it lowers the same synthetic program as
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):
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 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
left a comment
There was a problem hiding this comment.
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_partverified 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::bindspecial-casesRootType::Other(victory_shader::emit::GROUP_BASE) => 0, butop_textiteratest.host.user_data.iter().filter(|u| !is_root_view(u))and callsself.user_value(compute, u.slot, u.root, u.dword). For any compute shader readingGroupId(0), that hitsuser_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 inop_text. Filtering outu.root == RootType::Other(victory_shader::emit::GROUP_BASE)alongside!is_root_view(u)avoids this.
Minor non-blocking note:
- Bumping
MAGICfromVSH1toVSH2incrates/victory-gpu/src/shader_cache.rsis not strictly needed: the binary encoding didn't change (root_code/root_typealready round-tripRootType::Other(0x104)), andshader_cache::build()already hashesvictory_shader::SOURCE_HASHinto both the cache subdirectory and key. KeepingVSH1would avoid an unnecessary merge conflict with other PRs touchingshader_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.
|
Thanks, both taken in e4fa1a1. |
|
Automated triage for the maintainers. Needs work (small). The approach looks right. Needed before merge:
CI: passing (check). Generated by Claude Code |
group_x was inserted between compute_id and its doc; the line is back above compute_id.
|
Fixed in 2fd63f0: the doc line is back above |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Both points from the earlier review are cleanly addressed in e4fa1a1b (and the doc comment placement cleanup in 2fd63f00 looks good):
op_textincrates/victory-gpu/src/draw.rsnow filters outRootType::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.rsis left untouched onVSH1, relying onvictory_shader::SOURCE_HASHfor 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): cleanvictory-shaderemit::semantics_tests::group_x_starts_at_the_dispatch_part: passed (both hardware and WARP paths)victory-gpudraw::tests(21/21 on RTX 5090, 21/21 on WARP with--features diagnostics) andshader_cache::tests(4/4): all passedcargo xtask policy: 191 files ok
LGTM.
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, andState::dispatchpassed the title's counts straight through.A direct
Dispatchwith more than 65,535 groups in x now runs in parts of at most 65,535, with y and z as asked.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.State::dispatchsets that dword to each part's first group (dispatch_parts), then back to 0 afterwards.victory_shader::SOURCE_HASH), so old entries aren't found and the cache magic staysVSH1.Relation to #2312 and #2841
Where it came from
From DexNom's fork, DexNom/VIctory@570a941:
USER_GROUP_BASEadded 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 withCo-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 andu32::MAXgroups 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(skippingheap_direct_texture_reads_mark_their_heap_index, which crashes on main): 297 passed and 5 failed. All 5 fail the same on main: the 2stride_tests,gathers_at_a_level_match_the_hardware,rectangles_get_their_fourth_cornerandelements_sharing_a_row_keep_their_order.cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings, andvictory-gpuwith--features diagnostics: clean.Not tested