Recompiler: bound a direct DXIL compute lane's loops by its dispatch's share #3669
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3669"
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:24Z.
Requested by Prime
In the direct DXIL translator, a compute lane's loops were bounded per loop entry by the dispatch's share (1024 to 65 536 passes a thread), but the lane's total was still 65 536 passes. Nested loops (each entry of an inner loop starts a fresh count), loops one after another, and every loop of the compact form (programs of 20 000 instructions and more, which count no entry) could spend all of them. On an RTX 3060 Ti 8 GB a retail loop in a 262 144-thread dispatch took 0.47 ms a pass, so 65 536 passes would be about 31 s, far past the 2 s Windows waits before it removes the device. A compute lane's whole loop budget now starts at four entries of its dispatch's share, at most 65 536: large dispatches get 4096 passes (about 1.9 s at that rate in the worst case), small and indirect dispatches keep 65 536 as before. The lane then goes to the program's end, as it already did at 0. A second commit fixes invalid DXIL in the compact form's compute epilogue: on main it shows in a multi-wave group of a compact compute program with
S_BARRIER, whose safe barrier exit reads a register after the entry gate's path joins. We found it with the new GPU test in our builds, where the epilogue reads one more register.Related: #2793 gives each loop region its own budget in the HLSL path and in the direct translator's plain and compact forms; it touches the same budget code in
gpu/dxil/kernel.rs,compact.rsandlower.rs, so whichever lands second needs a rebase and a look at how the two caps combine. #1976 addsXCL_SHADER_LOOP_LIMIT, which also makes the direct translator's loop limit configurable, likeXCL_DXIL_LOOP_GUARDhere.What is in it (two commits)
crates/xcl/src/gpu/dxil/lower.rs:LOOP_SHARE_ENTRIES(4),loop_guard()(XCL_DXIL_LOOP_GUARD),loop_share_wanted()(XCL_DXIL_LOOP_SHARE), andInit::budget, the lane budget's first value when it is not the constant; a unit test of the guard's parsing.crates/xcl/src/gpu/dxil/kernel.rs:dispatch_loop_cap(the dispatch's share, split out ofloop_passes) andshare_budget(four shares, at most the guard), made once in the entry block for both forms;loop_guard_tagfor the cache identity, with a unit test. The compact form's epilogue now goes into an end block that no SSA edge enters and loads the registers there, so a read in it no longer becomes a phi of a load the entry gate's path never passes ("Instruction does not dominate all uses").crates/xcl/src/gpu/dxil/compact.rs: loop heads count down the budget only when the guard is on; comments on where reads load.crates/xcl/src/gpu/recomp/pso.rs,crates/xcl/src/shaders.rs: non-default switch values get their own translated-cache identity.crates/xcl/src/gpu/dxil/core_tests.rs:direct_compute_lane_budget_follows_the_dispatch_share(the budget in the disassembly, both forms) andgpu_direct_compute_lane_budget_follows_the_dispatch(passes run on the GPU with and without a share).README.md: the loop budget paragraph.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.Switches
XCL_DXIL_LOOP_SHARE(default on):=0leaves a compute lane the guard's passes in all, as before.XCL_DXIL_LOOP_GUARD(default 65 536): the passes a lane may run in all, also the most one loop entry gets;=0emits no loop guard at all.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:12:56Z.
Review (head
e13653d7, diff read, not a merge-check; checks red):gpu/dxil/kernel.rs ~46). For any dispatch of 262 144 threads or more, such as a full-screen 1920x1080 pass, the share is floored at 1024, soshare_budget(gpu/dxil/kernel.rs ~1321) gives the lane 4 x 1024 = 4096 loop-head passes for all of its loops together. On main that lane had 1024 passes per loop entry and 65 536 in all.DISPATCH_LOOP_PASSES_MIN(gpu/recomp/mod.rs ~896) exists so that "a working program's loop is not cut short because many threads run it". With this PR, an outer loop of 64 around an inner loop of 64 (4160 passes), or five loops of 1000 one after another, ends early. The lane jumps to the program's end and skips its remaining stores, and nothing is logged. The only basis for the value 4 is the PR's own test. No retail title was measured.DISPATCH_LOOP_PASSES), each pass of that dispatch takes about 8x as long, so it is still far past the 2 s Windows allows. The PR shortens what working programs can run without holding large dispatches under the limit.gpu/dxil/kernel.rs ~630) fixes invalid DXIL for compact compute programs that haveS_BARRIERin a multi-wave group. None of the new tests containsS_BARRIER, and no existing test validates that case. The commit message also says the failure was found "in our builds", not on this branch. This fix belongs in its own PR, with a test that validates such a program, for example 64 threads on wave32.IO_LOOP_BUDGETat 4096 passes per lane for small dispatches. With both PRs merged, small dispatches get 4096 passes per entry and at most 16 384 in all. That contradicts this PR's "small and indirect dispatches keep 65 536 as before". Both PRs change the default cap for the same TDR problem, so they should be measured together, or folded into one change. There are also textual conflicts with #3668 (gpu/recomp/pso.rs: both add an identity tag at the same lines), #3664 (shaders.rs) and #3655.xcl-smokeblock from main or from heade13653d7. Tested only listscargo checkfor the gnu target; the suite was not run. Both new GPU tests skip on the no-GPU CI, so neither the new budget nor the DXIL fix has run on a GPU.XCL_DXIL_LOOP_GUARDalso changes direct vertex and pixel shaders.Init::first(gpu/dxil/lower.rs ~167) and theguard != 0head check (gpu/dxil/kernel.rs ~549) apply to every stage, so=0removes the loop guard from graphics too. The README puts the switch in the compute paragraph, and the commit says graphics stages keep their budgets.Fine: by reading, both new tests would fail without the first commit (4091 vs 10 000; no share-budget select in the disassembly). The
guard / 4compare prevents the multiply from overflowing. Non-default switches get their own cache identity, andgpu/dxilsources are hashed into the direct identity, so old cached programs are not reused.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-02T11:39:18Z.
Test report (not a merge-check:
PR descriptionred)base:
1c8b551475head:
e13653d721merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2913 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/3669#issuecomment-7340551173 and its findings stand. Most serious: on by default, lanes of large dispatches get 4096 loop passes in all (main: 65,536), so working loops are silently cut.
performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (e13653d7): 1652 -> 1442 frames shown (87 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 15620 MB, 0 device removals, 0 crashes. This run is lower than most today: the PC was in use at the time (a browser and Discord running), and main's own runs on this machine today ranged from 1370 to 1652 frames, so the difference isn't clearly from this PR.assessment: merges, builds and passes the whole suite on current main, and the smoke run is clean; the blocking point is in the review: on by default, lanes of large dispatches get 4096 loop passes in all (main: 65,536), so working loops are silently cut
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 bmjask on 2026-12-02T20:47:03Z.
Code review location:
crates/xcl/src/gpu/dxil/lower.rs; line 54High: LOOP_SHARE_ENTRIES = 4 caps a lane's total loop-head passes across all loops, nested ones included, at 4 x share, so in large dispatches working nested loops are silently cut off and the lane jumps to the program's end, skipping its later stores. A 1920x1080 compute pass with 8x8 groups (32 400 groups) gets share = 2^28/32400/64, clamped to 1024, so budget = 4096. A legitimate shader with an outer loop over 32 lights and an inner 128-step march spends 32*129 = 4128 head passes, exceeds 4096, leaves to
endpartway through the last light, and never writes its output. The PR notes the guard doesn't report when it fires, so this shows up only as corrupted output. Counting per loop entry (as the HLSL path'sxcl_capdoes), or applying the share only to loops without a per-entry count, would leave working programs alone.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:47:03Z.
Code review location:
crates/xcl/src/gpu/dxil/lower.rs; line 58Medium: Four shares were picked to fit under the TDR limit, but at the PR's own measured rate (4096 x 0.47 ms = 1.93 s) the margin under Windows' 2 s timeout is about 3%, so a slightly heavier loop body or other queued GPU work still removes the device. A runaway compact-form loop (which has no per-entry count) in a 262 144-thread dispatch whose body costs 0.5 ms a pass instead of 0.47 ms runs for 2.05 s, past the timeout, which is the failure the PR sets out to prevent. A larger margin (two shares, or a bound derived from a time target) would make the fix hold.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:47:03Z.
Review: COMMENTED
Review of
e13653d7: 2 finding(s) (1 high, 1 medium), most severe first.crates/xcl/src/gpu/dxil/lower.rs:54: LOOP_SHARE_ENTRIES = 4 caps a lane's total loop-head passes across all loops, nested ones included, at 4 x share, so in large dispatches working nested loops are silently cut off and the lane jumps to the program's end, skipping its late.... (inline)crates/xcl/src/gpu/dxil/lower.rs:58: Four shares were picked to fit under the TDR limit, but at the PR's own measured rate (4096 x 0.47 ms = 1.93 s) the margin under Windows' 2 s timeout is about 3%, so a slightly heavier loop body or other queued GPU work still removes the.... (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.
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.