D3D12.X: cap a small compute dispatch's loop entries at 4096 passes #3667
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3667"
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?
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-12-02T05:54:15Z.
Requested by Prime
A compute dispatch of only a few groups got the largest loop budget there is:
recomp::dispatch_loop_budgetshares 2^28 passes among a dispatch's threads, so one group of 64 threads got 65 536 passes a loop entry. That share model fits a dispatch that fills the GPU. A small dispatch runs its groups side by side, so a loop that never ends costs the full 65 536 passes of latency whatever the thread count. On an RTX 3060 Ti, in a game title, a split wave64 compute program took 50.4 ms for one 1x1x1 group, twice a frame, every frame. This change caps each lane's loop entry at 4096 passes (four timesDISPATCH_LOOP_PASSES_MIN) for compute dispatches with known group counts. Large dispatches already get less than that and are unchanged. No translated code changes, so the shader cache stays valid.Related: #3652 (open) lowers the split-wave64 exchange and barrier waits of the direct DXIL translator from 2^20 polls (an exit bit for a departed half, then 2^12 and 2^16 polls). That is the other bounded wait that can hold a small dispatch this long. The two do not touch the same code.
What is in it
crates/xcl/src/hle/d3d12x/bind.rs:loop_passes_max()readsXCL_LOOP_PASSES_MAX.capped_loop_budget()computes theIO_LOOP_BUDGETvalue, min(share, max x threads per group), with a saturating product so extreme values fall back to the share.loop_budget_for()applies it to a compute pipeline and logs the first 64 programs whose loops get fewer passes. The direct bind path writes it for compute dispatches with known group counts. Unit testsmall_dispatches_get_at_most_the_max_loop_passes.crates/xcl/src/hle/d3d12x/console_list.rs: translated console command lists take the same capped budget.Tested
1c8b5514):cargo check -p xcl --lib --tests --target x86_64-pc-windows-gnupasses. The test suite was not run on this exact branch.Regression run
Not tested
scripts/smoke.ps1on this branch; AMD.XCL_LOOP_PASSES_MAX=0restores the old budget if one shows up.Switches
XCL_LOOP_PASSES_MAX=<n>: default 4096, the most passes one loop entry of a lane gets in a compute dispatch with known group counts.=0keeps the dispatch's share alone, as before (up to 65 536). Indirect dispatches are not affected.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:13:14Z.
Review (head
a9670ad4, diff read, not a merge-check; checks red):capped_loop_budget(hle/d3d12x/bind.rs~5128) lowers the per-entry passes whenever 2^28 / (groups x threads) > 4096. That is every compute dispatch under 65 536 threads, and those dispatches drop from up to 65 536 passes to 4 096. Small dispatches are where one lane does serial work: single-group reductions and scans, or a 1x1x1 loop over a list. For example, 64 threads striding a 512K-element buffer need 8 192 passes per entry. When the cap is hit, the direct DXIL path ends the lane's program (gpu/dxil/kernel.rs~520-523) and HLSL breaks out of the loop, so the output is silently wrong. The description itself says it was not shown that the 50 ms is a runaway loop rather than real work. Making this the default needs that evidence first, or the cap should be opt-in.gpu/dxil/kernel.rs~492,plan.is_none()). Split-wave64 compute programs with atomics, and large programs, get the compact form automatically (gpu/dxil/compact.rs~261-263). There they keep the lane's 65 536 passes, and this change does nothing. If the 50 ms is the split halves' exchange/barrier spin (2^20 polls), it is the subject of #3652 / #3668, not this PR. The PR has no before/after number.small_dispatches_get_at_most_the_max_loop_passes(bind.rs ~7191) checks only the arithmetic of the new helper. Neither call site that writesIO_LOOP_BUDGET(bind.rs ~5380,console_list.rs~1059) is tested. No GPU test shows a small dispatch's loop ending at 4 096 passes, or a long legitimate loop surviving.loop_budget_for(bind.rs ~5143-5160) runs for every compute dispatch with known group counts. For every dispatch under 65 536 threads it locksPSO_SHADERSandSEEN, and keeps doing so after 64 programs have been named. Programs without a loop also use up the 64 names, although they never readIO_LOOP_BUDGET. As a result, the log does not identify the programs whose loops were actually cut.IO_LOOP_BUDGET. With both PRs merged, a small dispatch's lane goes from 65 536 passes in all to 16 384, and that includes the compact form. Neither description mentions this.README.md~395-401 still says 1024 to 65 536 passes per thread, and the new default-onXCL_LOOP_PASSES_MAXis not documented there.PR checksis red because this runtime change has noxcl-smokeblocks (main and head) under Regression run. Tested has only acargo checkwith the gnu target and no suite counts, and AI use does not name the model.Fine: indirect dispatches (no group counts) and
XCL_LOOP_PASSES_MAX=0keep main's share. The thread count used is the console'snumthreads(pso_threads_exact), which is what both translators divide by. The saturating products handle extreme values. No translated code changes.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:37:06Z.
Test report (not a merge-check:
PR descriptionred)base:
1c8b551475head:
a9670ad427merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3667#issuecomment-7340558366 and its findings stand. Most serious: a default 4096-pass cap on every dispatch under 65,536 threads can silently cut legitimate loops.
performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (a9670ad4): 1652 -> 1687 frames shown (102 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 17407 MB, 0 device removals, 0 crashes.assessment: merges, builds and passes the whole suite on current main, and the smoke run is clean; the blocking point is in the review: a default 4096-pass cap on every dispatch under 65,536 threads can silently cut legitimate loops
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T15:22:05Z.
On the open question in the description (a bounded wait or real work): on our RTX 5070 Ti the 1x1x1 split program is
CS_DefragHeap_ProcessFreeRequests, and it is neither. Its outer loop count iss_ff1_i32_b32of a constant-buffer dword, so a 0 there gives 0xFFFFFFFF passes, and the loop runs until XCL's pass budget ends it (45 ms per dispatch here).The 0 comes from the title's GPU heaps being outside the coherent window: with the Series S window at 512 MB, its three heaps (1162 + 1277 + 258 MB) do not fit, become plain memory, and translated shaders read zeros from them (throny's follow-up on #3568). With
XCL_COHERENT_MB=3408the heaps fit and the program drops out of theXCL_GPU_TIMEStop 60 (under 2.45 ms per frame). Numbers are in my comment on #3568.So the cap here shortens that case, and the program needs only a few passes once its data is reachable. With real data its block walk is a data-dependent loop, so it may be worth checking that 4096 passes still cover it.
AI use: Claude Code (Claude Opus 5.5, with a Claude Fable 5.2 analysis of the shader and logs).
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:36:24Z.
Code review location:
crates/xcl/src/hle/d3d12x/bind.rs; line 5093High: The new default of 4096 silently cuts short real loops in every small direct compute dispatch, which used to get up to 65 536 passes per loop entry, while the same program keeps 65 536 when dispatched indirectly. A 1x1x1 dispatch of a [64,1,1] or [1,1,1] program with a legitimate serial loop (a single-group scan or compaction over more than 4096 items, a long list walk, a spin on a flag another group sets) now leaves the loop after 4096 passes and runs to the end with partial results: wrong or corrupt output with only one info line per program. The PR says the 50 ms may instead come from the exchange waits #3652 bounds, so the cap may not even fix the motivating case. Keeping the default at the old budget and limiting the cap to the split-wave64 form (or to the identified program) would avoid changing correct programs.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:36:24Z.
Review: COMMENTED
Review of
a9670ad4: 1 finding(s) (1 high), most severe first.crates/xcl/src/hle/d3d12x/bind.rs:5093: The new default of 4096 silently cuts short real loops in every small direct compute dispatch, which used to get up to 65 536 passes per loop entry, while the same program keeps 65 536 when dispatched indirectly. (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by lucsoft on 2026-12-03T14:11:28Z.
merge-check
base:
a815de932chead:
a9670ad427merge: clean
build: ok (cargo build --release -p xcl, cargo test --workspace --release --no-run)
tests: lib 2836 passed, 17 failed, 36 ignored, 2 died (base: 2835 passed, 17 failed, 18 ignored, 2 died; +1 is the new small_dispatches_get_at_most_the_max_loop_passes); integration 151 passed, 5 failed, 20 ignored (base the same); the same 19 lib and 5 integration failures on base and merge, none new; run under Wine with 2 threads, one module per process
review: whole diff read (bind.rs, console_list.rs); agrees with Foniass's review above. (1) A loop entry of a small compute dispatch now gets at most 4096 passes instead of up to 65 536; a loop that legitimately needs more (one group walking a long list) is now cut and gives a wrong result, not a stall. Large dispatches already got less (~1165), so long legit loops look rare, and the log names the first 64 programs whose loops are cut (this run: 64 named, so the list was full). (2) loop_budget_for takes a global Mutex on every dispatch whose budget is cut, also after the 64 names are logged; minor, not measurable here. (3) The unit test covers the arithmetic only, not the dispatch path. No visual comparison was done.
performance: no change measurable at this resolution: in the world 0.63 presents/s (merge) vs 0.72 (base), within the run-to-run spread of this scene; no translated code changes (shader caches stay warm)
title run: retail title, RX 7800 XT (RADV, Wine), main
a815de93+ this PR: 386 s in the world, no crash, no device removal, 0 page faults, 0.63 presents/s (basea815de93: 412 s, no crash, no device removal, 0.72 presents/s)note: the same three caps (#3667, #3668, #3669) were in all of our runs on a zip-based tree all day (Prime1997's portable build); after almost every run a wave stayed busy on the GPU after the title exited (100 % busy, no process; cleared by a reset), with them on. This PR does not fix that, and nothing here says it causes it.
verdict: not yet: confirms Foniass's two high findings (the 4096 default cap can cut loops that legitimately need more passes, with a wrong result instead of a stall; no test of the dispatch paths that write IO_LOOP_BUDGET, bind.rs ~5380 and console_list.rs ~1059); on the AMD side the merge is otherwise clean: suites with no new failures and a 386 s title run with no crash or device removal
hardware / tool and model: RX 7800 XT (RADV, Mesa 26.3.1, vkd3d-proton 3.1, Wine 11.21 Staging, Linux 7.3) / Claude Code (Claude Opus 5.5)
xcl-smoke blocks for the description (CONTRIBUTING: head + main, same title and time):
main
a815de93:PR head
a9670ad4(bare head, on its old base main1c8b5514):The device removal is ~12 s into the world (138 s after start): a TCP page fault, then a gfx ring timeout. The head's base
1c8b5514predates #3553, which fixed TCP faults at world entry here; the trial merge intoa815de93(with #3553) ran 600 s clean. A rebase onto current main would give a head block on a good base (and reset claims/checks ona9670ad4).Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T14:18:52Z.
merge-check
base:
16c2fd082ahead:
a9670ad427merge: clean
build: ok
tests: 3013 passed, 0 failed, 56 ignored; 28 skipped, the same as on main
review: 2 high, 5 medium (below)
performance: 60 s smoke run: 1683 → 1655 frames (98 % of main), peak commit 18505 → 19048 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 242 s there, 0 device removals, 0 crashes, 2.8 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: not yet: 2 blocking findings (critical or high, below); also
PR descriptionis redhardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: By default this caps each loop entry of a compute dispatch with known group counts at 4096 passes; small dispatches used to get up to 65 536. The head has not changed since my earlier review, so all of its findings are still open. A later comment on the PR shows the 50 ms program was a loop with a count of 0xFFFFFFFF, because it read zeros from heaps outside the coherent window (#3568). What blocks it: the default cap can silently cut real loops.
High
Medium
Checked and fine
How this was tested
16c2fd08, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main16c2fd08and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Gevroska on 2026-12-03T15:48:34Z.
I tested the 4,096-pass boundary on my RTX 3080 at
a9670ad4. I used one group of 64 lanes running a finite loop and checked both the iteration count and the final value from each lane.With the proposed default, a loop that needed 4,097 passes stopped at 4,096. All 64 lanes returned the wrong final value in all three trials. The parent (
1c8b5514), the opt-out, and an explicit cap of 4,097 all completed the same loop correctly. The default also gave the correct values for loops that needed exactly 4,095 or 4,096 passes.The fixture passed the budget calculated by each revision directly to the shader guard. This gives a concrete correctness case to weigh when choosing the default. Whether the original slow dispatch needs to complete that work is still a separate question.
AI disclosure: OpenAI Codex GPT-6.2 Sol ran the comparison. An independent Codex reviewer checked the readbacks. GPT-6.2 Astra drafted this comment.
I reviewed and approved this comment before posting.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.