Recompiler: each loop region of a program gets its own iteration budget #2793
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!2793
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2793"
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?
@jessenic on GitHub · 2026-11-26 13:29 UTC · original
jessenic:recompiler/loop-region-budgets→main· +213 −13 · 6 files · 1 commits · openA translated program caps its loops with one per-lane counter: 65,536 iterations, shared by the whole program. When a program's own spin-wait gives up after exactly 0x10000 tries, it spends all of them, and every later loop leaves at its first guard. Each outermost loop region now gets its own budget. The program stays capped at four budgets in all.
Part of #505.
Found on a retail FSR pass. CS
a8de35e47f36d28cpolls flags from an earlier pass, inside an outer loop, and gives up after 0x10000 tries.0should have been.1.5f29d7e51b2c6230, the one in my #505 GPU profile) spun to its own cap every frame. That took about 260 ms of GPU time a frame, two thirds of the console code's GPU time.These values were measured with a local probe that reads the buffers at bind time: the flags,
cb[0xa8] = 0, and the weight dword the flags carry.What is in it (one commit)
gpu/recomp/mod.rs:budget_regions(the outermost ranges ofloop_ranges),budget_regionandloop_guard.LOOP_BUDGETS_PER_REGION(2) budgets and countsxcl_btotaldown fromLOOP_BUDGETS_IN_ALL(4) budgets. Both forms are covered: structuredfor (;;)and thepcform'swhile.gpu/dxil/kernel.rs,compact.rs,lower.rs: the same in the direct translator's plain and compact forms. It adds two variables,VAR_BUDGET + 7and+ 24, which are free onmain. A loop head's compact class now includes its region.recomp::tests::gpu_a_loop_after_a_spin_to_the_budget_still_runs: a spin of 0x10000, of 0xFFF0, and of 0x10000 inside an outer loop, each followed by a loop. Both HLSL forms.recomp::tests::gpu_endless_loops_in_many_regions_stop_after_four_budgets.dxil::compact_tests::gpu_a_loop_after_a_spin_to_the_budget_still_runs_in_both_forms: direct plain and compact.Cost: the guard text changes in every program with two or more loop regions: 1,512 of the title's 2,682 compute programs (counted in an export with this change), and graphics programs too. My precompile after the change rebuilt 1,032 compute, 9,282 mesh, 3,133 pixel and 145 vertex programs. Those programs are translated and compiled once more, so the first run after this change rebuilds most pipelines; I needed a precompile plus two runs before the world was warm again. The worst case for a program that really runs away is four budgets instead of one.
(The commit message says 1,916; that was a brace count of
[loop]s. The exact count is 1,512.)Tested
cargo test --workspace -- --test-threads=4on this head: 1438 passed, 0 failed, 47 ignored, 37 test binaries.lower/lower_dxilcomparisons,dispatch_chain_native_wave64_builds_whole,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware), andheap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).0xc0000005ingamesave::tests::blob_enumeration_sees_one_submitted_update(#2421). The next two runs passed.main0829441+ about 40 open PRs, #929 among them), with the same change. Settings:XCL_DIRECT_DXIL=1, UMA shadow, the RT resolve programs refused, warm caches.5f29…fell out of the profile's top 15; it had been at about 260 ms a call.0x887a0006), and so did the run without the change. With warm caches, all three hung after 565–602 presents in the world, so the hang follows how far the world gets, not the change, which only gets there sooner. An older run of my tree went past 1,072 world presents with no hang. Today, that tree without this change and without the probe hung after 222. So the hang comes from something else that changed on this machine since then (my guess is the much larger driver-blob cache after two precompiles, so pipelines that used to be skipped while building now run); I have not found it.Regression run
scripts/smoke.ps1 -Game <the retail title>, 60 s, onmainand on this head (the default length does not reach the FSR passes):Tested by others
main:[65536, 0, 0, 0]).main1435 / 0 / 47), and a review of the diff.gpu::tests on both paths: only the three new tests differ frommain, all pass.Not tested
mainin the retail title's world: the game runs above were on my integration tree. The smoke runs only reach the menus.XCL_PER_LANE=1: it has no loop budget at all yet (#2769).a8de…ran its HLSL translation in every run, even withXCL_DIRECT_DXIL=1; the direct plain and compact forms are covered by the GPU tests only.HANDOFF.md(around line 1660) describes one per-laneLOOP_GUARDbudget per shader, and its "4 M iterations" was already out of date. With this change, a program with two or more loop regions has a budget per region and four in all.AI use
🤖 Generated with Claude Code
@ettehn on GitHub · 2026-11-26 13:35 UTC · original
Independent Windows GPU check of the global cap in direct DXIL on
3cde150b3c7a869e95b8eefcb5a2379859ad77d0, withb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7as the control. The only local change on each checkout was one synthetic test.The test requests three consecutive finite loops of 98,304 iterations each and records their counters and completed-region count. On the PR, both direct DXIL forms (plain and compact) returned
[98304, 98304, 65536, 2], stopping the third loop at the global 262,144-iteration limit. The main control failed at the plain-form assertion with[65536, 0, 0, 0]. The four existing loop-budget tests also passed on the PR checkout.Windows 11 build 26200, Ryzen 9 8945HX, RTX 5070 Ti Laptop GPU (12 GB, driver 621.24), Rust 1.97.1 MSVC debug, DXC 1.8.2502.11. With
XCL_ADAPTER=NVIDIA XCL_REQUIRE_GPU=wave64, I ran:PR plus local test: 5 passed, 0 failed, 0 ignored, no reported skips. The control ran only the new test. Native wave64, the full workspace suite, and a retail title were outside this check.
OpenAI Codex assisted with the synthetic test and verification. The exact model identifier was unavailable in this session.
@retrope13 on GitHub · 2026-11-26 13:45 UTC · original
Independent Ada Lovelace (RTX 4060 Laptop 8 GB) full-suite verification and diff review of
#2793(3cde150b) againstmain(b49be183): full debug suite + release recompiler/DXIL tests green, 0 failures. No title was run.Tested
32.0.16.2140, wave32), Intel Core i5-14500HX (14C/20T), 24 GB RAM, Windows 11 26H2 (build26300.9818),rustc 1.100.0(stable-x86_64-pc-windows-msvc), Windows SDK10.0.26100.0DXC1.9.2602.17,XCL_ADAPTER=NVIDIA.cargo test --locked -p xcl --lib -- gpu_a_loop_after_a_spin_to_the_budget_still_runs gpu_endless_loops_in_many_regions_stop_after_four_budgets gpu_a_loop_after_a_spin_to_the_budget_still_runs_in_both_forms --test-threads=4 --nocapture: 3 passed, 0 failed, 0 ignored (0.49 s; all three executed on GPU, none skipped).cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4:main(b49be183): 1435 passed, 0 failed, 47 ignored#2793(3cde150b): 1438 passed, 0 failed, 47 ignored (+3 new tests, 0 failures)--release):cargo test --release --locked -p xcl --lib -- gpu::recomp::tests:: gpu::dxil::compact_tests:: --test-threads=4: 183 passed, 0 failed, 17 ignored (12.44 s).Code Review Notes (
b49be183..3cde150b)lower.rs,kernel.rs,compact.rs): VerifiedVAR_BUDGET_OWNER(VAR_BUDGET + 7) andVAR_BUDGET_TOTAL(VAR_BUDGET + 24) do not collide with any existingVAR_*constant (+0..+5,VAR_IMG_WRITE+8..+23,VAR_TMP = 1024), and both are initialized inInit(0andLOOP_BUDGET * 4).kernel.rsandcompact.rs,spent(total == 0) forcesleft = 0beforecond_br(none, end, cont), so neitherleft - 1nortotal - 1can underflow incont. Incompact.rs:84,budget_regionis 1-based, sohead as u64 + region(0non-head,1unregioned head,2..per region) cleanly separates heads across regions without key collisions.phase_splitscoping (recomp/mod.rs,emit.rs): Programs with< 2regions produce emptyregionsand keep identicalLOOP_GUARDHLSL text. For multi-regionphase_splitgeometry shaders,emit::finishwraps each phase'sbodyin its own{ ... }scope, so localxcl_bown/xcl_btotaldeclarations do not collide across ES and GS phases (andxcl_bown = 0uresetsstatic xcl_budgeton the first region entered). Also confirmed every loop innested_loop_rangesmaps into an enclosing outermost range ofbudget_regions(&loops).Not Tested
#[ignore]/SKIPPEDtests.AI disclosure: Antigravity (Gemini 4 Neon, XHigh) ran the builds/tests, reviewed the diff, and drafted this report.
@DarkPanda69 on GitHub · 2026-11-26 13:51 UTC · original
AMD run (listed as untested) on an RX 9070 XT, plus an RTX 3060: the 3 new GPU tests pass on both cards, on both paths, and nothing else changes in the GPU suite.
Head
3cde150applied onmainb49be18, debug, Windows 11 Pro 26200,cargo test -p xcl --lib -- gpu:: --test-threads=4onmainand with the PR, once withXCL_DIRECT_DXIL=1and once with it unset, card chosen withXCL_ADAPTER:mainThe counts are the same on both paths. On both cards and both paths, the only result changes against
mainare the newgpu_a_loop_after_a_spin_to_the_budget_still_runs_in_both_forms,gpu_a_loop_after_a_spin_to_the_budget_still_runsandgpu_endless_loops_in_many_regions_stop_after_four_budgets, all ok, with no new skips. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same onmain.I did not check which wave width each new test runs on the RX 9070 XT, so I don't claim native wave64 coverage for them.
Not tested: a title, Intel.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@SzczepanGrela on GitHub · 2026-11-26 14:05 UTC · original
Verified native-wave64 / Wine coverage on RX 9070, including the direct global-cap case discussed above.
Tested
3cde150b3c7a869e95b8eefcb5a2379859ad77d0, against mainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.8293130ebe370b1+(local asserts-disabled build), DXC/DXIL 1.9.2602.17, Rust 1.97.1, releasex86_64-pc-windows-gnu.XCL_REQUIRE_GPU=wave64,XCL_NETWORK=0, no inheritedXCL_*test overrides, private caches, Windows libtest binaries through GE-Proton Wine with--exact --nocapture --test-threads=1.Test-only changes
All runtime translator files remain exact for each revision. In the test files, I added native-wave64 assertions and readback logging to the three new tests, plus local width/global-cap fixtures. Main receives the same new tests and
spin_then_loophelper; its total-cap expectation uses literal4instead of the absent new constant. The loop programs and expected values otherwise match. Source inventories and the reversible test edits were checked before and after testing.Native width
A separate
[WaveSize(64)]shader wroteWaveGetLaneCount()for all 64 threads: every value was 64, in 3/3 processes per revision. The loop fixtures requirerunner::wave64_supported() == trueandrunner::split_wave64() == false; HLSL fixtures check the emitted[WaveSize(64)], and direct fixtures usewave64: true, split: false.Region results
Each fixture below was repeated in three fresh processes per revision. The head returned these scalar registers in both HLSL forms and both direct forms:
[s0, s1, s2][65536, 3, 7][65520, 1000, 7][65536, 3, 7]Main stops at the first assertion in these tests: HLSL returns
[65536, 0, 7]; direct compact returns[65536, 0, 0]. The later spin cases do not execute in those failing control invocations. The head completes all six HLSL and all six direct case/form combinations on every repetition.The HLSL six-region total-budget fixture returned
[iterations, regions_reached] = [262144, 6]on the head, versus[65536, 6]on main, 3/3 each.The local direct fixture requests three finite loops of 98,304 iterations, recording their counters and completed-region count:
[65536, 0, 0, 0][98304, 98304, 65536, 2][65536, 0, 0, 0][98304, 98304, 65536, 2]Both forms are run before the fixture asserts, so the main control covers both. The head's three counters sum to 262,144. Direct fixtures invoke
translate_full_asexplicitly; the process setting isXCL_DIRECT_DXIL=0for these targeted checks.Existing controls
gpu_compact_form_spends_the_loop_budget_as_the_plain_form: 1/0/0 per revision, retaining the single-region 65,536-iteration result in both direct forms.gpu_scalar_loop_and_scc: 1/0/0 per revision withXCL_DIRECT_DXIL=0and1.Not tested
Native Windows, split Wave32,
XCL_PER_LANE=1, non-kernel stages, full workspace suite, retail/smoke workloads, visual behavior or FPS. These synthetic results do not measure the retail FSR pass or diagnose the reported TDR.AI use
OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the diff, prepared the test-only controls, ran and verified the paired GPU tests, and drafted this report. Publication authorized by the account owner.
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.