Recompiler: enforce LOOP_BUDGET at loop headers in per-lane lowering #2769

Open
github-bot wants to merge 1 commit from github-bot/gh-2769 into amd-dev AGit
Owner

@⁠Saksukella on GitHub · 2026-11-26 11:33 UTC · original
Saksukella:fix/per-lane-loop-budget → amd-dev · +90 −10 · 3 files · 1 commits · open

What is in it

  • crates/xcl/src/gpu/recomp/ssa.rs:
    • Add Var::Budget to track remaining loop-header iterations (LOOP_BUDGET = 1 << 16) per lane in the per-lane SSA lowering backend.
  • crates/xcl/src/gpu/recomp/lower_dxil.rs:
    • Map Var::Budget to i32 in DxilIr::ty() and add the Var::Budget arm in DxilIr::escape().
  • crates/xcl/src/gpu/recomp/lower.rs:
    • Detect loop headers from reverse-postorder (rpo_pos[b] >= rpo_pos[s]), split each loop header into a budget-check entry block and continuation block (budget_cont), initialize Var::Budget to crate::gpu::dxil::lower::LOOP_BUDGET at block 0, and branch to exit when the counter reaches 0 (otherwise decrement and continue).
    • Brings XCL_PER_LANE=1 into parity with the HLSL backend (recomp/emit.rs xcl_budget = 1u << 16) and the per-instruction Direct DXIL backend (gpu/dxil/kernel.rs VAR_BUDGET), preventing runaway compute shaders (e.g. zero-stride or wrapping loop bounds) from hanging the GPU until Windows TDR (0x887a0006).
    • Add CPU unit test infinite_loop_exits_at_loop_budget verifying an unconditional back-edge loop exits cleanly after exactly LOOP_BUDGET iterations.
  • Target branch: amd-dev.

Tested

  • Hardware: AMD Radeon RX 9070 XT (driver 32.0.32029.2010), 24-thread x86_64 CPU, 32 GB RAM, Windows; rustc 1.100.0 (0ef1bc386 2026-11-09); debug (tests) and release (xcl.exe).
  • cargo test -p xcl --lib gpu::recomp::lower::tests: 37 passed, 0 failed (0.43s), including infinite_loop_exits_at_loop_budget.

Regression run

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19700 MB
xcl-smoke v1
commit: 4dcc796b9d82220a3655494250bbdd4e00fcc560
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1609 (PresentX 1609)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15113 MB

Not tested

  • NVIDIA and Intel GPU adapters (tested on AMD Radeon RX 9070 XT only).

AI use

  • Antigravity (Google Gemini): assisted with XCL_GPU_CULPRIT / DRED TDR diagnosis, DXBC disassembly comparison across backends, writing the Var::Budget per-lane lowering patch and unit test, and running local tests and smoke verification. All diffs and measurements were verified locally on hardware.
**@⁠Saksukella** on GitHub · 2026-11-26 11:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/2769) `Saksukella:fix/per-lane-loop-budget` → `amd-dev` · +90 −10 · 3 files · 1 commits · open **What is in it** - `crates/xcl/src/gpu/recomp/ssa.rs`: - Add `Var::Budget` to track remaining loop-header iterations (`LOOP_BUDGET = 1 << 16`) per lane in the per-lane SSA lowering backend. - `crates/xcl/src/gpu/recomp/lower_dxil.rs`: - Map `Var::Budget` to `i32` in `DxilIr::ty()` and add the `Var::Budget` arm in `DxilIr::escape()`. - `crates/xcl/src/gpu/recomp/lower.rs`: - Detect loop headers from reverse-postorder (`rpo_pos[b] >= rpo_pos[s]`), split each loop header into a budget-check entry block and continuation block (`budget_cont`), initialize `Var::Budget` to `crate::gpu::dxil::lower::LOOP_BUDGET` at block 0, and branch to `exit` when the counter reaches 0 (otherwise decrement and continue). - Brings `XCL_PER_LANE=1` into parity with the HLSL backend (`recomp/emit.rs` `xcl_budget = 1u << 16`) and the per-instruction Direct DXIL backend (`gpu/dxil/kernel.rs` `VAR_BUDGET`), preventing runaway compute shaders (e.g. zero-stride or wrapping loop bounds) from hanging the GPU until Windows TDR (`0x887a0006`). - Add CPU unit test `infinite_loop_exits_at_loop_budget` verifying an unconditional back-edge loop exits cleanly after exactly `LOOP_BUDGET` iterations. - Target branch: `amd-dev`. **Tested** - Hardware: AMD Radeon RX 9070 XT (driver `32.0.32029.2010`), 24-thread x86_64 CPU, 32 GB RAM, Windows; `rustc 1.100.0 (0ef1bc386 2026-11-09)`; debug (tests) and release (`xcl.exe`). - `cargo test -p xcl --lib gpu::recomp::lower::tests`: 37 passed, 0 failed (`0.43s`), including `infinite_loop_exits_at_loop_budget`. **Regression run** ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: AMD Radeon RX 9070 XT title: b8db18c2 seconds: 60 exit: 0x0 frames shown: 1624 (PresentX 1624) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19700 MB ``` ``` xcl-smoke v1 commit: 4dcc796b9d82220a3655494250bbdd4e00fcc560 gpu: AMD Radeon RX 9070 XT title: b8db18c2 seconds: 60 exit: 0x0 frames shown: 1609 (PresentX 1609) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15113 MB ``` **Not tested** - NVIDIA and Intel GPU adapters (tested on AMD Radeon RX 9070 XT only). **AI use** - Antigravity (Google Gemini): assisted with `XCL_GPU_CULPRIT` / DRED TDR diagnosis, DXBC disassembly comparison across backends, writing the `Var::Budget` per-lane lowering patch and unit test, and running local tests and smoke verification. All diffs and measurements were verified locally on hardware.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:34:51 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 11:47 UTC · original

Independent amd-win test report (claim: #1607)

Tested: head 4dcc796b9d82220a3655494250bbdd4e00fcc560 (unchanged since claim; no other reports) vs. base b5c0275f (merge-base on amd-dev).
Hardware: RX 7800 XT, Ryzen 7 5700X3D, Windows 11 Pro 10.0.26200, debug build, stable-x86_64-pc-windows-msvc. Not release, not a retail title.

Commands (CARGO_TARGET_DIR separate, -j 4):

  • cargo test -p xcl --lib -j 4 -- --test-threads=4 --skip placed_title_textures_share_vram_and_preserve_pixels
  • each failing test again alone with --test-threads=1, on head and on base
  • cargo test -p xcl --lib -j 4 -- --test-threads=1 recomp::

Results

  • Head, full lib: 1533 passed, 11 failed, 27 ignored, 1 filtered (the skipped test).
  • New test gpu::recomp::lower::tests::infinite_loop_exits_at_loop_budget: passes.
  • Head recomp:: alone: 416 passed, 2 failed, 20 ignored (failures: f32_programs_on_the_gpu, a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier).
  • placed_title_textures_share_vram_and_preserve_pixels alone on head: passes.
  • Base, full lib: the parallel run aborted with STATUS_STACK_BUFFER_OVERRUN (known amd-dev behaviour, here in a different test than on head), so I have no clean full-run count for base. Instead I ran each of the 11 head failures alone on both commits.

Attribution (alone, --test-threads=1): the same 10 tests fail on base and on head: fuzz_validate_and_gpu_1 (#2115), dispatch_chain_native_wave64_builds_whole, a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, f32_programs_on_the_gpu, a_dispatch_with_a_pipeline_still_building_waits_at_the_submit, a_put_off_dispatch_runs_at_the_submit_when_its_build_outlasts_the_wait_budget, bitset_runs_emit_exact_contiguous_page_ranges, giant_driver_compiles_have_their_own_lane, title_bytes_are_used_in_place_when_all_are_readable, physical_home_without_sparse_windows_uses_coherent_window. The 11th, two_pass_binds_set_the_shared_view_heap, fails only in the parallel run and passes alone on both. So no failure I found is caused by this PR. I did not investigate the root causes of the pre-existing ones.

SKIPPED: 4 lines, all f16_programs_on_the_gpu (f16 arithmetic and packed, wave32/wave64, per-lane form refused: V_MUL_F16 / V_PK_MUL_F16, #1426). These are not coverage.

Diff review: read the 3-file diff; no concrete defect found. The LOOP_BUDGET cap is exercised only by the CPU-interpreter test, so the GPU (DXIL) path of the new loop-header block is covered only by the existing per-lane GPU tests, which do not include a loop that hits the budget. I did not run a retail title or scripts/smoke.ps1.

AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Results are from real runs on the hardware above.

**@⁠oni-swr** on GitHub · 2026-11-26 11:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/2769#issuecomment-7191174859) Independent amd-win test report (claim: https://git.gtahub.st/github/xcl-dev--xcl/issues/1607) **Tested:** head `4dcc796b9d82220a3655494250bbdd4e00fcc560` (unchanged since claim; no other reports) vs. base `b5c0275f` (merge-base on `amd-dev`). **Hardware:** RX 7800 XT, Ryzen 7 5700X3D, Windows 11 Pro 10.0.26200, debug build, stable-x86_64-pc-windows-msvc. Not release, not a retail title. **Commands** (`CARGO_TARGET_DIR` separate, `-j 4`): - `cargo test -p xcl --lib -j 4 -- --test-threads=4 --skip placed_title_textures_share_vram_and_preserve_pixels` - each failing test again alone with `--test-threads=1`, on head and on base - `cargo test -p xcl --lib -j 4 -- --test-threads=1 recomp::` **Results** - Head, full lib: 1533 passed, 11 failed, 27 ignored, 1 filtered (the skipped test). - New test `gpu::recomp::lower::tests::infinite_loop_exits_at_loop_budget`: passes. - Head `recomp::` alone: 416 passed, 2 failed, 20 ignored (failures: `f32_programs_on_the_gpu`, `a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier`). - `placed_title_textures_share_vram_and_preserve_pixels` alone on head: passes. - Base, full lib: the parallel run aborted with STATUS_STACK_BUFFER_OVERRUN (known amd-dev behaviour, here in a different test than on head), so I have **no clean full-run count for base**. Instead I ran each of the 11 head failures alone on both commits. **Attribution (alone, `--test-threads=1`):** the same 10 tests fail on base and on head: `fuzz_validate_and_gpu_1` (#2115), `dispatch_chain_native_wave64_builds_whole`, `a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier`, `f32_programs_on_the_gpu`, `a_dispatch_with_a_pipeline_still_building_waits_at_the_submit`, `a_put_off_dispatch_runs_at_the_submit_when_its_build_outlasts_the_wait_budget`, `bitset_runs_emit_exact_contiguous_page_ranges`, `giant_driver_compiles_have_their_own_lane`, `title_bytes_are_used_in_place_when_all_are_readable`, `physical_home_without_sparse_windows_uses_coherent_window`. The 11th, `two_pass_binds_set_the_shared_view_heap`, fails only in the parallel run and passes alone on both. So no failure I found is caused by this PR. I did not investigate the root causes of the pre-existing ones. **SKIPPED:** 4 lines, all `f16_programs_on_the_gpu` (f16 arithmetic and packed, wave32/wave64, per-lane form refused: V_MUL_F16 / V_PK_MUL_F16, #1426). These are not coverage. **Diff review:** read the 3-file diff; no concrete defect found. The `LOOP_BUDGET` cap is exercised only by the CPU-interpreter test, so the GPU (DXIL) path of the new loop-header block is covered only by the existing per-lane GPU tests, which do not include a loop that hits the budget. I did not run a retail title or `scripts/smoke.ps1`. **AI use:** Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Results are from real runs on the hardware above.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2769/head:github-bot/gh-2769'
git switch 'github-bot/gh-2769'

Merge

Merge the changes and update on Forgejo.
git switch 'amd-dev'
git merge --no-ff 'github-bot/gh-2769'
git switch 'github-bot/gh-2769'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --ff-only 'github-bot/gh-2769'
git switch 'github-bot/gh-2769'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --no-ff 'github-bot/gh-2769'
git switch 'amd-dev'
git merge --squash 'github-bot/gh-2769'
git switch 'amd-dev'
git merge --ff-only 'github-bot/gh-2769'
git switch 'amd-dev'
git merge 'github-bot/gh-2769'
git push origin 'amd-dev'
This discussion has been locked. Commenting is limited to contributors.
No description provided.