Skip to content

Recompiler: XCL_LOOP_BUDGET sets the loop iteration budget of a lane - #1284

Open
upipibi wants to merge 2 commits into
xcl-dev:mainfrom
upipibi:feat/loop-budget-env
Open

upipibi wants to merge 2 commits into
xcl-dev:mainfrom
upipibi:feat/loop-budget-env

Conversation

@upipibi

@upipibi upipibi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

LOOP_GUARD caps every lane at 65 536 loop iterations. In the stops of #505, the GPU runs translated compute loops at 100 % for tens of seconds. The current reading there is that the loops run on data a skipped dispatch never wrote:

If that reading holds, the budget is what finally ends those loops. There was no way to try a lower one without editing the prelude, so this adds a switch for it. It is a diagnostic, not a fix: the default does not change.

Part of #505.

What is in it

  • gpu/recomp/mod.rs: loop_budget() reads XCL_LOOP_BUDGET. A whole number from 1 sets the budget; anything else keeps 65 536. Documented at LOOP_GUARD.
  • gpu/recomp/emit.rs: with the variable set to anything but 65 536, the prelude's static uint xcl_budget = 1u << 16; becomes static uint xcl_budget = <n>u;. Unset, the HLSL is byte for byte as on main, so DXIL cache keys and driver blobs stay valid (an earlier head wrote a #define into every prelude; changed after @not-rex's point on Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505).
  • gpu/recomp/pso.rs: XCL_LOOP_BUDGET joins the switches whose translations are not cached in memory or on disk (cache_allowed, and its test). DXC's cache is keyed by the HLSL, so it stays correct. The first run with a new value recompiles every shader it meets.
  • gpu/recomp/tests.rs:
    • loop_budget_reads_a_whole_number_from_one checks the parser.
    • gpu_loop_budget_caps_a_loop runs a loop whose exit never comes (s_cmp_lg against 0 after the first increment). It checks that the unset translation keeps main's prelude line, then that the loop stops after 4 096 iterations with the budget at 4096, and 61 440 iterations later at 65 536.

Tested

  • NVIDIA GeForce RTX 3070, driver 616.56; Windows 11 Pro 26100; Rust 1.100.0 MSVC; debug.
  • cargo build --workspace + cargo test --workspace --no-fail-fast -- --test-threads=4:
    • this PR (3980a81): 753 passed, 0 failed, 41 ignored;
    • main 930e8b4: 751 passed, 0 failed, 41 ignored, same machine.
    • Both skip the same two tests (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware.
  • XCL_LOOP_BUDGET=4096 cargo test -p xcl --lib loop_budget: 2 passed. The budget follows the variable.
  • On cost: in my timing on Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505, a 64-thread split-wave64 loop with one exchange per iteration takes 15 ms per Dispatch(4,1,1) to reach 65 536 iterations. At 4 096 it is 16 times shorter.

Regression run

Rebased onto main cbc296a (a conflict with the new pixel-shader prelude in emit.rs), so the head is now 81745f8 and the pair below, for 0b28a6b, no longer counts for the check. Could someone with a retail title post the xcl-smoke blocks for main and 81745f8? Without XCL_LOOP_BUDGET the HLSL is byte for byte main's, so the two runs should match.

Previous pair, from Kalmarv's run (thanks):

From Kalmarv's run on an RTX 5070 Ti (NVIDIA 610.74), main 20cf130 and this head 0b28a6b, 60 s each (#1284 (comment)), thanks:

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1279 (PresentX 1279)
presents per 2 s (last 3): 4 40 42
device removals: 0
crashes: 0
peak commit: 26967 MB
xcl-smoke v1
commit: 0b28a6bc618d5580c99ada0bc182929536f06abe
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1289 (PresentX 1289)
presents per 2 s (last 3): 11 41 36
device removals: 0
crashes: 0
peak commit: 27396 MB

Not tested

  • A title, with or without the variable. Whether a working program of the title needs more than a few thousand iterations of one loop per lane, so that a low budget breaks it, is not known.
  • AMD, Wine.

AI use

  • Claude Code (Claude Opus 5.5) wrote the change and the tests, ran the suites, and wrote this description.

🤖 Generated with Claude Code

@futurepro62

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head e1573e3 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: loop_budget_reads_a_whole_number_from_one, gpu_loop_budget_define_caps_a_loop.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Regression pair for 3980a81 against main 930e8b4 (this PR's base), on a retail title, for the Regression run section. Both runs pass: no device removal, no crash, 101 % of main's frames, 105 % of its peak commit.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74), AMD Ryzen 9 9950X, Windows 11 Pro 26200.
  • scripts/smoke.ps1, the same retail title for 60 s each: main at 930e8b4 (this PR's base) first, then this PR's head, one after the other on the same machine. XCL_LOOP_BUDGET was unset, so the PR's run used the default budget.

main 930e8b4:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1302 (PresentX 1302)
presents per 2 s (last 3): 12 17 21
device removals: 0
crashes: 0
peak commit: 25725 MB

this PR, 3980a81:

xcl-smoke v1
commit: 3980a81864ea3eb2a181472e857a54b69ae39349
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1318 (PresentX 1318)
presents per 2 s (last 3): 39 40 37
device removals: 0
crashes: 0
peak commit: 26939 MB

For #505 (earlier runs, not this pair). On this machine the 100 % phase before the removal is one dispatch: the BVH builder's refit program (cs b6043104de672057), whose threads climb parent links, and a local build of main that skipped it had no device removal. A lower XCL_LOOP_BUDGET caps exactly that climb.

Not tested

AI use: Claude Code (Claude Opus 5.5)

@not-rex

not-rex commented Nov 24, 2026

Copy link
Copy Markdown

RTX 3080 (10 GB, driver 610.88, Windows 11), retail 1.0.2.1 into the world: with XCL_LOOP_BUDGET=4096 the GPU no longer hangs; it works in bounded bursts and the title keeps presenting for about 110 s longer, until a different fault in the title.

Tested

without (main tree) this PR, XCL_LOOP_BUDGET=4096
first ListX #101 90.3 s 88.6 s
presents after #101 12 (last at 124.1 s) 35 (last at 238.2 s)
GPU queue.Wait … did not complete within 5000 ms 18 (first 125.1 s) 93 (first 129.1 s)
"would close a GPU cycle" 5 32
GPU after presents slow down 100 % from ~122 s until the hang 100 % bursts of 6-12 s with idle gaps, ~128-238 s; idle after
end 0x887A0006 (hung) at 168.5 s 0xC0000005 at +0x4e8b4be (read at -1, about ten threads at once) at 241.3 s
peak commit / local video memory 31.9 GB / 14.5 GB 32.7 GB / 15.0 GB

With the budget, the title limps on at about 1 present and 40-60 submissions per 2 s for ~110 s after the point where the tree without it hangs, and the GPU keeps coming back between bursts. That fits the reading on #505 that the stop is loops running long on data a skipped dispatch never wrote. The title then faults at +0x4e8b4be, which I haven't seen in any other run on this machine; it may be what a capped loop leaves behind.

Not tested: other budgets (4096 only); more than one run; without XCL_PSO_WAIT_MS; AMD.

AI use: Claude Code (Claude Opus 5.5) ran the runs on my machine through a scripted runner and wrote this report.

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
wondercrash added a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
Port of upstream PR xcl-dev#1284 (head 3980a81, open). LOOP_GUARD caps every lane
at 65 536 loop iterations; the variable sets another budget (a whole number
from 1). Unset, the HLSL is byte for byte as before, so DXIL cache keys and
driver blobs stay valid. With it set, translations bypass the in-memory and
disk caches (cache_allowed), next to XCL_CS_COHERENT from integ.

Conflict resolved in pso.rs (cache_allowed and its test now list both
XCL_CS_COHERENT and XCL_LOOP_BUDGET). One mis-indented test line of the PR
re-indented.

For the retail cutscene stop (run 22b: the GPU at 100 % SM, 230 W, 1-3 %
memory use for 60 s while no title op is marked running): a loop running
to the budget on data a skipped producer never wrote ends 16x sooner with
XCL_LOOP_BUDGET=4096.

Tests: loop_budget (2, incl. the GPU test, unset and with
XCL_LOOP_BUDGET=4096), shader_cache_bypasses_debug_overrides (1).

Assisted-by: omp (Claude Opus 5.5)
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 20cf130 (now 0b28a6b). One conflict in recomp/mod.rs: #1307's STRUCTURED_BYTES_PER_CODE_BYTE landed next to loop_budget; both are kept, unchanged. RTX 3070, driver 616.56: tests matching loop_budget / loop, 23 passed, 0 failed, with and without XCL_DIRECT_DXIL=1.

@upipibi
upipibi force-pushed the feat/loop-budget-env branch from 3980a81 to 0b28a6b Compare November 24, 2026 23:32
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

The rebase onto 20cf130 moved the head to 0b28a6b, so the PR description check now wants the Regression-run pair made on that head. The pair in the description (Kalmarv's, thanks) is for 3980a81. The rebase changed only the conflict lines in recomp/mod.rs; loop_budget is untouched and the suite passes. I can't make a smoke run here (no title). If someone with one has a minute, a scripts/smoke.ps1 pair of main 20cf130 and 0b28a6b would clear it, and I'll paste it in with credit.

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@upipibi on it: a scripts/smoke.ps1 pair of main 20cf130 and 0b28a6b on an RTX 5070 Ti is queued behind a run that's using the GPU now. I'll post both blocks here within the hour.

AI use: Claude Code (Claude Opus 5.5) wrote this.

@Kalmarv

Kalmarv commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@upipibi here is the pair. scripts/smoke.ps1, the same retail title for 60 s each, one after the other, release builds from clean trees. RTX 5070 Ti (NVIDIA 610.74), Ryzen 9 9950X, Windows 11 26200. A separate NVIDIA driver build was running in another process during both runs.

main 20cf130:

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1279 (PresentX 1279)
presents per 2 s (last 3): 4 40 42
device removals: 0
crashes: 0
peak commit: 26967 MB

#1284 0b28a6b:

xcl-smoke v1
commit: 0b28a6bc618d5580c99ada0bc182929536f06abe
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1289 (PresentX 1289)
presents per 2 s (last 3): 11 41 36
device removals: 0
crashes: 0
peak commit: 27396 MB

1289 / 1279 frames (101 %), peak commit 27396 / 26967 MB (102 %), no device removal or crash on either run. No out-of-memory or exception lines in either log.

AI use: Claude Code (Claude Opus 5.5) ran the pair and wrote this.

upipibi and others added 2 commits November 24, 2026 20:40
`LOOP_GUARD` caps a lane at 65 536 loop iterations (`xcl_budget` in the
prelude). In the stops of xcl-dev#505 the GPU runs translated compute loops for tens
of seconds, apparently on data a skipped dispatch never wrote, and the budget
is what ends them; there was no way to try a lower one without editing the
prelude.

The prelude now takes the budget from `#define XCL_LOOP_BUDGET`, which the
emitter writes from the variable of that name (a whole number from 1; anything
else keeps 65 536). A translation with it set is not cached in memory or on
disk (`cache_allowed`), as for the other translation switches; DXC's own cache
is keyed by the HLSL, so it stays correct.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The budget came in through a `#define` written before every prelude, which
changed every program's HLSL and so every DXIL cache key, even with the
variable unset: one full recompile for everyone after the update. The
prelude keeps its `1u << 16` now, and only a budget other than the default
replaces that line. (Point raised by not-rex on xcl-dev#505.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@upipibi
upipibi force-pushed the feat/loop-budget-env branch from 0b28a6b to 81745f8 Compare November 25, 2026 02:41
@JJAutoCompare

Copy link
Copy Markdown

XCL PR #1284 — Intel Arc A770 loop budget compatibility

Tested

  • Exact clean head 81745f8. GitHub showed the PR open at that head before and after the run. I checked the seven existing comments and found no Arc report for this head. PR #1284
  • Intel Arc A770, driver 32.0.101.9175, AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation 25H2 build 26200.9974. Rust 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc), Cargo 1.100.0 (3acc79c0c), unoptimized test profile. The GPU log reports dxcompiler 1.9.2609.5 (01b62ad4) and dxil 1.9.2609.5 from the configured DXC directory. dxc.exe in that directory also reports file version 1.9.2609.5.
  • The parser fixture passed in 0.40 s. Counts were 1 passed, 0 failed, 0 ignored, 0 skipped.
  • The bounded HLSL/DXC GPU fixture passed in 3.82 s under the Arc lock. Counts were 1 passed, 0 failed, 0 ignored, 0 skipped. With XCL_LOOP_BUDGET unset, it verified the default prelude line and dispatched the checked-in wave32 cases for 4,096 and 65,536. Its assertions verified that the smaller case returned 4,096 or 4,097 and that the default-budget case returned exactly 61,440 more. The fixture reports the combined time and only prints exact counter values on an assertion failure.
  • Each exact harness invocation filtered out 1,125 other tests. Cargo prebuild and both test processes exited 0. The GPU log records acquisition and release of the Arc lock.

Commands

Process environment for both commands (XCL_LOOP_BUDGET unset).

CARGO_TARGET_DIR=L:/XclTooling/pr1844-71f2ceb-t3-737e5ee5/target
CARGO_BUILD_JOBS=2
CARGO_INCREMENTAL=0
CARGO_PROFILE_DEV_DEBUG=0
CARGO_PROFILE_TEST_DEBUG=0
TEMP=L:/XclTooling/pr1284/81745f8-20261125-035452420/temp
TMP=L:/XclTooling/pr1284/81745f8-20261125-035452420/temp
XCL_ADAPTER=A770
XCL_DXC_DIR=C:/Users/ljensen/AppData/Local/XclTooling/dxc-1.9.2609/bin/x64

Prebuilt the library test executable outside the Arc lock (Cargo reported 1m 02s).

& 'C:/Users/ljensen/.cargo/bin/cargo.exe' +stable-x86_64-pc-windows-msvc test -p xcl --lib --no-run --locked --message-format=json

Exact test arguments for the Cargo-reported executable.

$bin = 'L:/XclTooling/pr1844-71f2ceb-t3-737e5ee5/target/debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe'
& $bin gpu::recomp::tests::loop_budget_reads_a_whole_number_from_one --exact --nocapture --test-threads=1
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { & $bin gpu::recomp::tests::gpu_loop_budget_caps_a_loop --exact --nocapture --test-threads=1 }

The GPU command ran in a child Windows PowerShell with -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -EncodedCommand, with the test executable path passed through XCL_PR1284_LIBTEST_EXE. RemoteSigned applied to that process only. The machine policy was unchanged.

Logs beside this report include prebuild.log, prebuild.jsonl, parser.stdout.log, parser.stderr.log, gpu.stdout.log, gpu.stderr.log, and run-status.log.

Not tested

  • Retail titles or the paired main/PR smoke run, the workspace suite, release builds, other adapters, the direct DXIL backend, or stress cases. The GPU fixture exercised only its checked-in 4,096 and 65,536 budgets.

AI use

  • T3 Code / Codex (gpt-6.2-sol) ran the two checked-in fixtures, verified the head and existing conversation, and wrote this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants