D3D12.X: dispatches of more than 65 535 groups in X are folded into Y #1428
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1428
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1428"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@lukastaro on GitHub · 2026-11-24 15:51 UTC · original
lukastaro:d3d12x-fold-large-dispatches→main· +540 −32 · 10 files · 3 commits · openPart of #505 (the world load): the GPU hang (
0x887a0006) about 100 s into the world load on an RTX 5060 Ti.The console runs up to 2^32 − 1 thread groups a dimension; D3D12 takes 65 535, and past that a dispatch is undefined. On an NVIDIA RTX 5060 Ti a retail game's world loading hung the GPU (
DXGI_ERROR_DEVICE_HUNG, 0x887A0006) about 100 s in, every run. The dispatch markers of #1323 showed one unfinished dispatch each time: anExecuteIndirectof one loop-free compute program, whose arguments (written by an earlier dispatch) were 72 512 × 1 × 1 and 75 072 × 1 × 1 groups. Clamping them to 65 535 removed the hang but left the last groups' work undone (the game crashed later, reading what they should have written); folding runs all of them.A dispatch of more than 65 535 groups in X with 1 in Y now runs as 65 535 × ⌈n / 65 535⌉ groups. The console's count goes into a new io word,
IO_GROUP_LIMIT(in the trap-temp range likeIO_UMA_BASE_HI; 0 when not folded), and every translated compute program – the HLSL path and both direct translators (gpu::dxiland its per-lane form inrecomp::lower) – takesgid.x + gid.y · 65 535as its group in X when the word is set, 0 as its Y, and returns at once in the groups at or past the count. A dispatch that cannot be folded (two dimensions past the limit) is clamped and logged.What is in it
Dispatchand console-recorded dispatches, whose counts the CPU knows:bind::fold(bind.rs, also used inconsole_list.rs).ExecuteIndirectof one dispatch, whose counts only the GPU knows: a one-thread pass (clamp.rs) reads them, writes the counts to dispatch into a slot of XCL's buffer and the console's count into the dispatch's io; the dispatch then reads its arguments from the slot.bind_abinow returns what it bound (Bound), sorebindsets it again after the pass.recomp/emit.rs; the direct translator's compute entry (gpu/dxil/kernel.rs,compute_init, with a gate before the program for the groups past the count) and its per-lane form's (recomp/lower.rs, the groups past the count take its skip block);IO_GROUP_LIMIT/FOLD_Xinrecomp/mod.rs.recomp/tests.rs: the HLSL path, the direct translator in wave32, wave64 and split wave64, and the per-lane form; fails without the change from group 65 535 on), the indirect pass folds / clamps / leaves counts as they are (GPU,clamp.rs), the folding rule (unit,bind.rs).runner::device()gives tests the runner's device: a test that made its own device first left the Agility SDK unappliable for the process (0x887E0003), and the GPU tests after it skipped.The translated compute HLSL and the direct translators' compute DXIL change (a few lines in the prelude / entry), so cached translations and DXIL of compute programs are made again once.
Tested
cargo build --workspace, thencargo test --workspace -- --test-threads=4oncf6cc59: 754 passed, 0 failed, 41 ignored (SKIPPED GPU tests:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware– no wave64 on this GPU). One run before that hadvram::tests::d32s8_targets_take_their_own_size_of_video_memoryfail withE_FAILcreating a resource; it passed 3 of 3 times alone, on this head and onmain.72512 groups folded into 65535 x 2, group 65535).cf6cc59(after @nnonno91's and @gut0to's reports): the indirect pass computes the row count without the addition that wrapped near 2^32 and folds only when it stays within 65 535, asbind::folddoes. Its test covers 65 535², 65 535² + 1 andu32::MAXagainstbind::foldand fails on the previous shader.main9e3831e(conflict inbind_abiwith the descriptor-heap binding offe7d70b; both kept), heade29892e:cargo test --workspace -- --test-threads=4779 passed, 0 failed, 41 ignored.main1d027e5(conflict inexecute_indirectwith #1791'sfresh_indirect_arguments; both kept: the fold pass first, then the ExecuteIndirect between #1791's transitions), head280164a:cargo test --workspace --no-fail-fast -- --test-threads=4962 passed, 0 failed, 43 ignored. In a first runvram::tests::d32s8_targets_take_their_own_size_of_video_memoryfailed once while the precompile held most of the video memory; it passed 3 of 3 times alone.7dbd80c(after @ivall's report that only the HLSL path undid the fold): the direct translators unfold too.main1a0bbe3merged in (no conflicts), head7dbd80c, driver 621.40, DXC 1.9.2609.5:cargo test --workspace --no-fail-fast -- --test-threads=41248 passed, 5 failed, 46 ignored (SKIPPED GPU tests: the wave64 ones – no wave64 on this GPU – and two f16 per-lane cases the per-lane form refuses). The failures arefuzz_validate_and_gpu_0–_3(0x8007000E creating the pipeline, the same seeds without this change) andvram::tests::d32s8_targets_take_their_own_size_of_video_memory(passed 3 of 3 times alone). WithXCL_DIRECT_DXIL=all,cargo test -p xcl --lib gpu::: 628 passed, the same 4 fuzz tests failed, 22 ignored. The extended GPU test fails on the direct path without7dbd80c.Regression run
main:
PR:
The 60 s stay in the game's menus and loading screen, before the folded dispatches. The PR's first run after the build had 1136 frames and a peak commit of 26285 MB (its shader caches were made new for the changed translator sources); the block above is the run right after it, with no change in between.
Not tested
kernel.rsandbind.rs, and itsdispatch_chainwould need to fold too; whichever lands second takes care of it.max > 1): they are left as they were.AI use
🤖 Generated with Claude Code
@nnonno91 on GitHub · 2026-11-24 16:05 UTC · original
Indirect dispatch fold disagrees with the CPU at the upper boundary
On
a902d3e3e02e497d8d30b37cdccd89ba9585feb1, the existing fold tests pass on my RTX 5090, including the 72,512-group case. I extendedindirect_group_counts_are_folded_or_clamped_on_the_gputo compare the GPU setup pass’s readback withbind::foldfor three additional X counts, with Y and Z both set to 1. The test reads the generated counts without submitting them as a dispatch.(X, Y, Z)(X, Y, Z)(65535, 65535, 1)(65535, 65535, 1)(65535, 1, 1)(65535, 65536, 1)u32::MAX)(65535, 1, 1)(65535, 0, 1)The shader in
clamp.rscan produce a row count above the D3D12 limit, and the addition in its ceiling division wraps foru32::MAX. In a temporary local test I computed the ceiling using division and remainder, and kept the existing clamp path when the row count exceeded 65,535. The extended test then passed, including agreement on the stored fold limit.Tested
cargo test --locked -p xcl --lib indirect_group_counts_are_folded_or_clamped_on_the_gpu -- --nocapture --test-threads=1on the temporary fixture. The PR shader failed the two out-of-range comparisons. The local correction passed all six cases.Not tested
AI use
@oz-stanislav-zhukov on GitHub · 2026-11-24 16:12 UTC · original · edited 2026-11-24 16:47 UTC
Test report from the retail game, GTA VI 1.0.2.1. With this PR applied, the world-loading GPU hang did not show up in one run; before it, the hang happened in both runs I had on the same machine. Correction (edited): the PR's per-dispatch report lines never appeared in that run, so I can't attribute the missing hang to it. See below.
Tested at
a902d3e, cherry-picked ontomainb7aa9f3together with other open PRs (local branch, commit5ab018c): #751, #688, #1123, #488, #789 (ported by hand onto the currentsparse.rs), #1195, #1323, and two localxgCopyFromSubresource fixes. The only conflict was with #1323 inbind.rs/mod.rs, where I kept both: fold first, then the culprit markers around the dispatch.Hardware: NVIDIA GeForce RTX 5060 Ti 16 GB, driver 621.24, Agility SDK 1.620.2. CPU i7-14700KF, 64 GB RAM, Windows 10 22H2 (19045). Rust 1.88.0, release build with line tables. Game runs used
XCL_DRED=1 XCL_PSO_WAIT_MS=50 XCL_ACTIVITY=1; the run with this PR also hadXCL_GPU_CULPRIT=1.Before (
main930e8b4+ parts of the same stack, without #1195/#1428/#1323; two runs):DXGI_ERROR_DEVICE_HUNG(0x887A0006) at 112 s and 183 s.q4 end=signalin the first run,q2 end=signalin the second).ExecuteIndirectbetween dispatches and barriers. All other lists had 0 operations done. The page fault was at VA 0x0.With this PR (one run):
indirect dispatches past 65535 groups a dimension are folded or clamped on the GPUlogged at 96 s. That line only says the pass was set up.… indirect dispatches folded so farnor… had group counts clamped so farwas ever logged. As far asclamp::reportsaw, no dispatch was folded or clamped in this run.GPU wait chainline for the whole run.0x80000003atgame_scarlett_master.exe+0x4da6315(called from+0x9dff91) at 132 s;0xc0000005reading0xffffffffffffffffat+0x50705fcat 147 s.Update, a second run with this PR (same build, no DRED;
XCL_GPU_CULPRIT=1 XCL_PSO_WAIT_MS=50):1 indirect dispatches folded so far (the latest of 72604 groups in X)at 142 s. That is the same size as the counts in the description (72 512 / 75 072).GPU wait chainline afterwards.0x80000003at+0x4da6315.0x50000000/0x60000000bases) through the resource's map. The pointer it got was0xae99cec5ab88357b, which is garbage, so the resource's contents were not what the game expected.Unit tests:
cargo test --release -p xcl --lib -- sparse late_release bind culprit clamp --test-threads=4: 41 passed, 0 failed, 1 ignored. Three GPU tests printed SKIPPED with "no GPU" / "no GPU or DXC" in this run, includingclamp::tests::indirect_group_counts_are_folded_or_clamped_on_the_gpu, so that test was not covered here.Not tested:
scripts/smoke.ps1;The before and after runs differ in more than this PR:
mainmoved from930e8b4tob7aa9f3, and #1195/#1323 were added. #1195's skip message never appeared either.AI use: run, log analysis and this report by Claude Code (Claude Opus 5.5); posted at the request of the person running the tests.
@lukastaro on GitHub · 2026-11-24 16:54 UTC · original
Thanks @nnonno91 and @gut0to, fixed in
cf6cc59(folded into the one commit): the GPU pass now computes the row count without the addition that wrapped, and folds only when it stays within 65 535, asbind::folddoes on the CPU; otherwise it clamps. The test covers 65 535², 65 535² + 1 andu32::MAXand checks each case againstbind::fold; it fails on the previous shader.Thanks also @Aniseto and @DarkPanda69 for the NVIDIA / AMD test runs, and @oz-stanislav-zhukov for the run on the title. Smoke run and the whole suite are redone on the new head (numbers in the description).
AI use: Claude Code (Claude Opus 5.5) wrote this.
@DavidM1911 on GitHub · 2026-11-24 17:21 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.Thanks!
@lukastaro on GitHub · 2026-11-24 22:00 UTC · original
Added "Part of #505" to the description, since this PR is about a stop at the world load (#1833) and has no
goal:world-loadlabel yet. On #675, @qcdaark found that the hang there is a different one (the fold path runs on that card, the hang stays), so this PR does not name #675 as fixed.AI use: Claude Code (Claude Opus 5.5) wrote this.
@ivall on GitHub · 2026-11-25 11:35 UTC · original
A gap I found while merging this for a test on AMD RDNA4: the fold is only undone on the HLSL path.
IO_GROUP_LIMITis read ingpu/recomp/emit.rsand nowhere undergpu/dxil(head280164a); the direct translator takes the group id as the hardware gives it (gpu/dxil/kernel.rs,group_id).bind.rsandclamp.rsfold for every translated compute pipeline, so withXCL_DIRECT_DXIL=1(and for the programs #2120 sends to the direct translator by default) a folded dispatch would run with the group ids of the folded grid instead of the console's. Before this change such a dispatch was clamped: groups were missing, but the ones that ran had the right ids.What is needed: the same unfolding in the direct translator's group and thread ids, with a GPU test like
gpu_compute_folded_dispatchon that path, or no fold for a pipeline built by it. This is from reading the code; I did not run a folded dispatch on the direct path.It also conflicts in
bind.rswith #2080 (two hunks, both easy).Tested:
9633138+ #2245's test fix + #2180 + #2029 + #1782 + this, AMD RDNA4, Windows, DXC 1.8.2502.11, debug,cargo test --workspace --no-fail-fast -- --test-threads=4: 1250 passed, 3 failed, 46 ignored, 7 SKIPPED. The 3 failures are onmainthere too (fuzz_validate_and_gpu_1and_3, #2115;gpu_image_get_resinfo_past_last_level). WithXCL_DIRECT_DXIL=all,cargo test -p xcl --lib gpu::: 629 passed, the same 3 failed, 22 ignored.AI use: Claude Code (Claude Opus 5.5) read the code, ran the tests and wrote this on the maintainer's behalf.
@lukastaro on GitHub · 2026-11-25 12:54 UTC · original · edited 2026-11-25 12:55 UTC
@ivall Thanks, you were right: the fold was only undone on the HLSL path.
7dbd80cadds the same unfolding to both direct translators:gpu::dxil(compute_init) and the per-lane form inrecomp::lower. The groups past the console's count leave at once in both. The folded-dispatch GPU test now covers HLSL, direct (wave32, wave64, split wave64) and per-lane, and fails on the direct path without the fix. Currentmainis merged in. The #2080 overlap and the test numbers are in the description.AI use: Claude Code (Claude Opus 5.5) wrote the change and this comment.
@ivall on GitHub · 2026-11-25 13:05 UTC · original
The direct path's unfold is written and tested; it goes in with this PR. On
main1a0bbe3merged with280164a, plus a commit that adds the unfold to the direct translator (both the compact form and the per-lane form,kernel.rsunfold_groups/start):gpu_compute_folded_dispatch_runs_each_console_group_oncenow runs the HLSL and the direct program, 65 536 and 72 512 groups, wave32 and wave64: pass on AMD RDNA4.main), 46 ignored.Not merged yet: it changes the DXIL of every compute program, and I want a title run of the tree first.
AI use: Claude Code (Claude Opus 5.5) wrote the commit, ran the tests and wrote this on the maintainer's behalf.
@DarkPanda69 on GitHub · 2026-11-24 16:02 UTC · original · edited 2026-11-25 13:27 UTC
Update for head
7dbd80c: same result. Applied onmain1a0bbe3,gpu_compute_folded_dispatch_runs_each_console_group_oncepasses on the RX 9070 XT (native wave64) and the RTX 3060. Wholegpu::filter: RX 9070 XT 630 passed, 2 failed (the #2115 fuzz seeds, same onmain); RTX 3060 632 passed, 0 failed.AMD run, which this PR lists as not tested. Updated for head
280164a(earlier runs ona902d3e,cf6cc59ande29892e, same result).Tested: pass, head
280164aapplied onmain689f2db, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.cargo test -p xcl --lib -- gpu::recomp --test-threads=4:gpu_compute_folded_dispatch_runs_each_console_group_onceok. The 6 SKIPPED lines (per-lane form refused for some f16/f32 programs) are the same onmain.main.On
a902d3e,cargo test -p xcl --lib -- d3d12x --test-threads=4also passed on both (145 passed, 0 failed, 1 ignored); not rerun since.Not tested: RDNA2; the upper-boundary case from the review above beyond the PR's own tests; the whole workspace suite; a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@Aniseto on GitHub · 2026-11-24 16:00 UTC · original · edited 2026-11-25 14:11 UTC
Ran the two new tests at
e29892e(re-run after the head moved again; earlier runs werea902d3eandcf6cc59): Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.XCL_ADAPTER=nvidia cargo test -p xcl --lib gpu_compute_folded_dispatch 1 passed; 0 failed; 0 ignored (exit 0) XCL_ADAPTER=nvidia cargo test -p xcl --lib indirect_group_counts_are_folded 1 passed; 0 failed; 0 ignored (exit 0)Both still pass on the new head:gpu_compute_folded_dispatch_runs_each_console_group_onceruns a real folded dispatch on the GPU here and each console group runs exactly once, andindirect_group_counts_are_folded_or_clamped_on_the_gpupasses too. Not tested: a title that actually issues more than 65 535 groups in X (no unpacked title here), RDNA2/RDNA4 and Intel GPUs, Wine, release profile, native wave64. AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - built the PR's head commit from a clean tree and ran the tests on this machine; no local changes were made.Update (25/11, after the head moved to
7dbd80c): re-ran the same two tests at the new head, which also unfolds a folded dispatch in the direct translators.Environment unchanged: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 MSVC 14.44.35207, DXC 1.9.2609.5, debug build.
Both still pass on
7dbd80c. The PR is currently in conflict againstmain1a0bbe3; this run is on the exact head commit in a detached worktree, not on a rebased tree.Not tested (same gaps as above): a title that actually issues more than 65 535 groups in X, RDNA2/RDNA4 and Intel GPUs, Wine, release profile, native wave64.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the new head in a detached worktree, rebuilt, ran the tests, and updated this report; the worktree was not modified; no game data was used.
@upipibi on GitHub · 2026-11-25 15:02 UTC · original
For comparison, two other designs of this fix, in case cases are worth borrowing:
DispatchandExecuteIndirect. That covers x > 65,535 with y > 1, which this PR clamps (bind.rs, "any other count past 65 535 is clamped (logged once)"). The shader returns before its body wheneff_x >= asked_x, so padding groups do nothing even in side-effect-only programs. Its indirect test checks records such as 115,200 × 1 × 1 → [57600, 115200, 57600, 1, 2].Cases that might be worth a test here: x > 65,535 with y > 1 (clamped now), the same pipeline used by a direct and then an indirect dispatch, and a side-effect-only program whose padding groups must not write. Read from the PR texts and this diff only.
AI-assisted (Claude Code).
@lucsoft on GitHub · 2026-11-25 19:27 UTC · original
Test report: Linux / RADV, RX 7800 XT (RDNA3). Head
7dbd80c, in a stack, not alone. Folding is required on this card for the title to get past world loading.main50a9fdeplus about 20 other PRs. The full list is in #505. #2205's culprit markers sit around the folded dispatch.568e7db: without this PR every run hung at about 131 000 dispatches. With it, runs went to 262 000–301 000 dispatches before an unrelated hang. With the current stack, runs pass 2 000 000 dispatches and reach gameplay, with no GPU-wait timeouts.AI use: Claude Code (Claude Opus 5.5) ran the analysis and drafted this. The runs were real, on the hardware above.
@DavidM1911 on GitHub · 2026-11-26 05:13 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.@gut0to on GitHub · 2026-11-24 16:22 UTC · original · reviewed
At g.x == UINT_MAX, g.x + 65534u wraps to 65533, so the quotient becomes 0 and the folded indirect dispatch runs no groups in Y. Please use overflow-safe ceiling division and add a UINT_MAX case to the GPU clamp test. AI-assisted review; I checked the arithmetic against the limit documented in this PR.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.