Recompiler: each loop region of a program gets its own iteration budget #2793

Open
github-bot wants to merge 1 commit from github-bot/gh-2793 into main AGit
Owner

@⁠jessenic on GitHub · 2026-11-26 13:29 UTC · original
jessenic:recompiler/loop-region-budgets → main · +213 −13 · 6 files · 1 commits · open

A 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 a8de35e47f36d28c polls flags from an earlier pass, inside an outer loop, and gives up after 0x10000 tries.

  • When that spin ran out, its main loop never ran. A spilled SGPR then held a weight from an earlier load where the constant buffer's 0 should have been.
  • So every flag the pass publishes read that weight with bit 0 set, instead of 1.
  • The pass waiting on those flags (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 of loop_ranges), budget_region and loop_guard.
    • In a program with two or more regions, a loop head's guard starts a new region with LOOP_BUDGETS_PER_REGION (2) budgets and counts xcl_btotal down from LOOP_BUDGETS_IN_ALL (4) budgets. Both forms are covered: structured for (;;) and the pc form's while.
    • Why two per region: a 0x10000 spin inside an outer loop must fit, because the outer loop's head spends from the same count.
    • Control only moves forward between regions; a jump back would make them one range.
    • Programs with fewer than two regions keep their exact HLSL text.
  • 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 + 7 and + 24, which are free on main. A loop head's compact class now includes its region.
  • Tests, each failing without the change:
    • 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

  • RTX 5070 Ti 16 GB (driver 610.88), 32 GB RAM, Windows 11 26300, Rust stable msvc, debug (tests) and release (the game). Series S profile.
  • cargo test --workspace -- --test-threads=4 on this head: 1438 passed, 0 failed, 47 ignored, 37 test binaries.
    • SKIPPED (15): 14 for "no wave64" (the per-lane lower / lower_dxil comparisons, dispatch_chain_native_wave64_builds_whole, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
    • One earlier run of the lib tests stopped with 0xc0000005 in gamesave::tests::blob_enumeration_sees_one_submitted_update (#2421). The next two runs passed.
  • The retail title, in a local integration tree (main 0829441 + 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.
    • The producer's flags read 1,013 ones and no other value.
    • 5f29… fell out of the profile's top 15; it had been at about 260 ms a call.
    • World frame rate, same settings throughout, measured over the same spans after the world's first frame:
      run +60..+160 s +60..+275 s
      with the change 1.69 1.97
      with the change 1.79 1.99
      without it 1.43 1.55
  • Those runs ended in a TDR (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, on main and on this head (the default length does not reach the FSR passes):
xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 5070 Ti
title: 7cc04381
seconds: 60
exit: 0x0
frames shown: 1057 (PresentX 1057)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 20900 MB
xcl-smoke v1
commit: 3cde150b3c7a869e95b8eefcb5a2379859ad77d0
gpu: NVIDIA GeForce RTX 5070 Ti
title: 7cc04381
seconds: 60
exit: 0x0
frames shown: 1126 (PresentX 1126)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 20893 MB

Tested by others

  • @⁠ettehn: RTX 5070 Ti Laptop, a test of three 98,304-iteration loops in direct DXIL: both forms stop the third at the 262,144 total (main: [65536, 0, 0, 0]).
  • @⁠retrope13: RTX 4060 Laptop, whole suite 1438 / 0 / 47 (main 1435 / 0 / 47), and a review of the diff.
  • @⁠DarkPanda69: RX 9070 XT and RTX 3060, gpu:: tests on both paths: only the three new tests differ from main, all pass.
  • @⁠SzczepanGrela: RX 9070 with native wave64 (RADV under Wine), including the direct total cap.

Not tested

  • AMD and native wave64 in a title (only the GPU tests above).
  • The change on plain main in the retail title's world: the game runs above were on my integration tree. The smoke runs only reach the menus.
  • Geometry-phase programs (the region guard in an ES + GS body); vertex, pixel and mesh programs in the game beyond what the runs above reach.
  • XCL_PER_LANE=1: it has no loop budget at all yet (#2769).
  • The title's a8de… ran its HLSL translation in every run, even with XCL_DIRECT_DXIL=1; the direct plain and compact forms are covered by the GPU tests only.

HANDOFF.md (around line 1660) describes one per-lane LOOP_GUARD budget 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

  • Claude Code (Claude Opus 5.5). It found the cause with a local probe and the program's disassembly, wrote the change and the tests, ran the tests and the game runs, and wrote this description. A review agent (same model) checked the change, and its findings led to the second budget per region and the nested-spin test.

🤖 Generated with Claude Code

**@⁠jessenic** on GitHub · 2026-11-26 13:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/2793) `jessenic:recompiler/loop-region-budgets` → `main` · +213 −13 · 6 files · 1 commits · open A 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 `a8de35e47f36d28c` polls flags from an earlier pass, inside an outer loop, and gives up after 0x10000 tries. - When that spin ran out, its main loop never ran. A spilled SGPR then held a weight from an earlier load where the constant buffer's `0` should have been. - So every flag the pass publishes read that weight with bit 0 set, instead of `1`. - The pass waiting on those flags (`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 of `loop_ranges`), `budget_region` and `loop_guard`. - In a program with two or more regions, a loop head's guard starts a new region with `LOOP_BUDGETS_PER_REGION` (2) budgets and counts `xcl_btotal` down from `LOOP_BUDGETS_IN_ALL` (4) budgets. Both forms are covered: structured `for (;;)` and the `pc` form's `while`. - Why two per region: a 0x10000 spin inside an outer loop must fit, because the outer loop's head spends from the same count. - Control only moves forward between regions; a jump back would make them one range. - Programs with fewer than two regions keep their exact HLSL text. - `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 + 7` and `+ 24`, which are free on `main`. A loop head's compact class now includes its region. - Tests, each failing without the change: - `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** - RTX 5070 Ti 16 GB (driver 610.88), 32 GB RAM, Windows 11 26300, Rust stable msvc, debug (tests) and release (the game). Series S profile. - `cargo test --workspace -- --test-threads=4` on this head: 1438 passed, 0 failed, 47 ignored, 37 test binaries. - SKIPPED (15): 14 for "no wave64" (the per-lane `lower` / `lower_dxil` comparisons, `dispatch_chain_native_wave64_builds_whole`, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`), and `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - One earlier run of the lib tests stopped with `0xc0000005` in `gamesave::tests::blob_enumeration_sees_one_submitted_update` (#2421). The next two runs passed. - The retail title, in a local integration tree (`main` `0829441` + 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. - The producer's flags read 1,013 ones and no other value. - `5f29…` fell out of the profile's top 15; it had been at about 260 ms a call. - World frame rate, same settings throughout, measured over the same spans after the world's first frame: | run | +60..+160 s | +60..+275 s | |---|---|---| | with the change | 1.69 | 1.97 | | with the change | 1.79 | 1.99 | | without it | 1.43 | 1.55 | - Those runs ended in a TDR (`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, on `main` and on this head (the default length does not reach the FSR passes): ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 5070 Ti title: 7cc04381 seconds: 60 exit: 0x0 frames shown: 1057 (PresentX 1057) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 20900 MB ``` ``` xcl-smoke v1 commit: 3cde150b3c7a869e95b8eefcb5a2379859ad77d0 gpu: NVIDIA GeForce RTX 5070 Ti title: 7cc04381 seconds: 60 exit: 0x0 frames shown: 1126 (PresentX 1126) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 20893 MB ``` **Tested by others** - @⁠ettehn: RTX 5070 Ti Laptop, a test of three 98,304-iteration loops in direct DXIL: both forms stop the third at the 262,144 total (`main`: `[65536, 0, 0, 0]`). - @⁠retrope13: RTX 4060 Laptop, whole suite 1438 / 0 / 47 (`main` 1435 / 0 / 47), and a review of the diff. - @⁠DarkPanda69: RX 9070 XT and RTX 3060, `gpu::` tests on both paths: only the three new tests differ from `main`, all pass. - @⁠SzczepanGrela: RX 9070 with native wave64 (RADV under Wine), including the direct total cap. **Not tested** - AMD and native wave64 in a title (only the GPU tests above). - The change on plain `main` in the retail title's world: the game runs above were on my integration tree. The smoke runs only reach the menus. - Geometry-phase programs (the region guard in an ES + GS body); vertex, pixel and mesh programs in the game beyond what the runs above reach. - `XCL_PER_LANE=1`: it has no loop budget at all yet (#2769). - The title's `a8de…` ran its HLSL translation in every run, even with `XCL_DIRECT_DXIL=1`; the direct plain and compact forms are covered by the GPU tests only. `HANDOFF.md` (around line 1660) describes one per-lane `LOOP_GUARD` budget 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** - Claude Code (Claude Opus 5.5). It found the cause with a local probe and the program's disassembly, wrote the change and the tests, ran the tests and the game runs, and wrote this description. A review agent (same model) checked the change, and its findings led to the second budget per region and the nested-spin test. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A translated program caps its loops with one per-lane counter, 65,536
iterations shared by the whole program. A program whose own spin-wait gives
up after 0x10000 tries uses all of it, and every loop after that spin then
leaves at its first guard.

A retail FSR pass (CS a8de35e47f36d28c) polls flags written by an earlier
pass with a cap of exactly 0x10000 tries, inside an outer loop. When the
spin ran out, its main loop never ran. A spilled SGPR then held a weight
from an earlier load where the constant buffer's 0 should have been, and
the flags it publishes read that weight with bit 0 set instead of 1. The pass
waiting on those flags (5f29d7e51b2c6230) spun to its own cap every frame:
about 260 ms of GPU time a frame on an RTX 5070 Ti. Measured with a local
probe: the flags, cb[0xa8] = 0, and the weight dword the flags carry.

The outermost ranges of loop_ranges are the program's loop regions. Control
only moves forward between them: a jump back would make them one range. In
a program with two or more regions, each region starts with two budgets.
Two, so that a 0x10000 spin inside an outer loop fits, because the outer
loop's head spends from the same count. All regions together have at most
four budgets (xcl_btotal / VAR_BUDGET_TOTAL), so a program that really runs
away stops within four budgets. Before, it stopped within one.

This is done in all three emitters: the HLSL structured and pc forms
(loop_guard), the direct DXIL plain form (kernel.rs) and the compact form.
In the compact form, a loop head's class now includes its region.

Programs with fewer than two regions keep their exact HLSL text and cached
translations. Of the title's 2,682 compute programs, 1,916 have two or more
regions, so those are translated and compiled again once.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:31:35 +00:00
Author
Owner

@⁠ettehn on GitHub · 2026-11-26 13:35 UTC · original

Independent Windows GPU check of the global cap in direct DXIL on 3cde150b3c7a869e95b8eefcb5a2379859ad77d0, with b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 as 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:

cargo test --locked --offline -p xcl --lib -j 2 -- gpu_direct_dxil_regions_share_the_total_loop_budget gpu_a_loop_after_a_spin_to_the_budget_still_runs gpu_endless_loops_in_many_regions_stop_after_four_budgets gpu_compact_form_spends_the_loop_budget_as_the_plain_form --test-threads=1 --nocapture

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.

**@⁠ettehn** on GitHub · 2026-11-26 13:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/2793#issuecomment-7193566312) Independent Windows GPU check of the global cap in direct DXIL on `3cde150b3c7a869e95b8eefcb5a2379859ad77d0`, with `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7` as 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: ```text cargo test --locked --offline -p xcl --lib -j 2 -- gpu_direct_dxil_regions_share_the_total_loop_budget gpu_a_loop_after_a_spin_to_the_budget_still_runs gpu_endless_loops_in_many_regions_stop_after_four_budgets gpu_compact_form_spends_the_loop_budget_as_the_plain_form --test-threads=1 --nocapture ``` 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.
Author
Owner

@⁠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) against main (b49be183): full debug suite + release recompiler/DXIL tests green, 0 failures. No title was run.

Tested

  • Hardware / Env: NVIDIA GeForce RTX 4060 Laptop GPU (8 GB, Ada Lovelace, driver 32.0.16.2140, wave32), Intel Core i5-14500HX (14C/20T), 24 GB RAM, Windows 11 26H2 (build 26300.9818), rustc 1.100.0 (stable-x86_64-pc-windows-msvc), Windows SDK 10.0.26100.0 DXC 1.9.2602.17, XCL_ADAPTER=NVIDIA.
  • New targeted tests (debug):
    • 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).
  • Full workspace (debug): cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4:
    • Clean main (b49be183): 1435 passed, 0 failed, 47 ignored
    • PR #2793 (3cde150b): 1438 passed, 0 failed, 47 ignored (+3 new tests, 0 failures)
  • Targeted recompiler + DXIL compact suite (--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)

  • Direct DXIL variable slots & initialization (lower.rs, kernel.rs, compact.rs): Verified VAR_BUDGET_OWNER (VAR_BUDGET + 7) and VAR_BUDGET_TOTAL (VAR_BUDGET + 24) do not collide with any existing VAR_* constant (+0..+5, VAR_IMG_WRITE +8..+23, VAR_TMP = 1024), and both are initialized in Init (0 and LOOP_BUDGET * 4).
  • Underflow & compact class key safety: In both kernel.rs and compact.rs, spent (total == 0) forces left = 0 before cond_br(none, end, cont), so neither left - 1 nor total - 1 can underflow in cont. In compact.rs:84, budget_region is 1-based, so head as u64 + region (0 non-head, 1 unregioned head, 2.. per region) cleanly separates heads across regions without key collisions.
  • HLSL single-region preservation & ES+GS phase_split scoping (recomp/mod.rs, emit.rs): Programs with < 2 regions produce empty regions and keep identical LOOP_GUARD HLSL text. For multi-region phase_split geometry shaders, emit::finish wraps each phase's body in its own { ... } scope, so local xcl_bown / xcl_btotal declarations do not collide across ES and GS phases (and xcl_bown = 0u resets static xcl_budget on the first region entered). Also confirmed every loop in nested_loop_ranges maps into an enclosing outermost range of budget_regions(&loops).

Not Tested

  • Live retail title runs, AMD / Intel GPUs, native wave64 hardware, Linux, and the 47 #[ignore] / SKIPPED tests.

AI disclosure: Antigravity (Gemini 4 Neon, XHigh) ran the builds/tests, reviewed the diff, and drafted this report.

**@⁠retrope13** on GitHub · 2026-11-26 13:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/2793#issuecomment-7193797401) **Independent Ada Lovelace (RTX 4060 Laptop 8 GB) full-suite verification and diff review of `#2793` (`3cde150b`) against `main` (`b49be183`): full debug suite + release recompiler/DXIL tests green, 0 failures.** No title was run. ### Tested - **Hardware / Env:** NVIDIA GeForce RTX 4060 Laptop GPU (8 GB, Ada Lovelace, driver `32.0.16.2140`, wave32), Intel Core i5-14500HX (14C/20T), 24 GB RAM, Windows 11 26H2 (build `26300.9818`), `rustc 1.100.0` (`stable-x86_64-pc-windows-msvc`), Windows SDK `10.0.26100.0` DXC `1.9.2602.17`, `XCL_ADAPTER=NVIDIA`. - **New targeted tests (debug):** - `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). - **Full workspace (debug):** `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4`: - Clean `main` (`b49be183`): **1435 passed, 0 failed, 47 ignored** - PR `#2793` (`3cde150b`): **1438 passed, 0 failed, 47 ignored** (+3 new tests, 0 failures) - **Targeted recompiler + DXIL compact suite (`--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`) - **Direct DXIL variable slots & initialization (`lower.rs`, `kernel.rs`, `compact.rs`):** Verified `VAR_BUDGET_OWNER` (`VAR_BUDGET + 7`) and `VAR_BUDGET_TOTAL` (`VAR_BUDGET + 24`) do not collide with any existing `VAR_*` constant (`+0..+5`, `VAR_IMG_WRITE` `+8..+23`, `VAR_TMP = 1024`), and both are initialized in `Init` (`0` and `LOOP_BUDGET * 4`). - **Underflow & compact class key safety:** In both `kernel.rs` and `compact.rs`, `spent` (`total == 0`) forces `left = 0` before `cond_br(none, end, cont)`, so neither `left - 1` nor `total - 1` can underflow in `cont`. In `compact.rs:84`, `budget_region` is 1-based, so `head as u64 + region` (`0` non-head, `1` unregioned head, `2..` per region) cleanly separates heads across regions without key collisions. - **HLSL single-region preservation & ES+GS `phase_split` scoping (`recomp/mod.rs`, `emit.rs`):** Programs with `< 2` regions produce empty `regions` and keep identical `LOOP_GUARD` HLSL text. For multi-region `phase_split` geometry shaders, `emit::finish` wraps each phase's `body` in its own `{ ... }` scope, so local `xcl_bown` / `xcl_btotal` declarations do not collide across ES and GS phases (and `xcl_bown = 0u` resets `static xcl_budget` on the first region entered). Also confirmed every loop in `nested_loop_ranges` maps into an enclosing outermost range of `budget_regions(&loops)`. ### Not Tested - Live retail title runs, AMD / Intel GPUs, native wave64 hardware, Linux, and the 47 `#[ignore]` / `SKIPPED` tests. *AI disclosure: Antigravity (Gemini 4 Neon, XHigh) ran the builds/tests, reviewed the diff, and drafted this report.*
Author
Owner

@⁠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 3cde150 applied on main b49be18, debug, Windows 11 Pro 26200, cargo test -p xcl --lib -- gpu:: --test-threads=4 on main and with the PR, once with XCL_DIRECT_DXIL=1 and once with it unset, card chosen with XCL_ADAPTER:

main this PR
RX 9070 XT (RDNA4, 32.0.32029.2010) 708 passed, 2 failed, 6 SKIPPED 711 passed, 2 failed, 6 SKIPPED
RTX 3060 (32.0.16.1088) 710 passed, 0 failed, 24 SKIPPED 713 passed, 0 failed, 24 SKIPPED

The counts are the same on both paths. On both cards and both paths, the only result changes against main are the new gpu_a_loop_after_a_spin_to_the_budget_still_runs_in_both_forms, gpu_a_loop_after_a_spin_to_the_budget_still_runs and gpu_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 on main.

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.

**@⁠DarkPanda69** on GitHub · 2026-11-26 13:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/2793#issuecomment-7193932453) 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 `3cde150` applied on `main` `b49be18`, debug, Windows 11 Pro 26200, `cargo test -p xcl --lib -- gpu:: --test-threads=4` on `main` and with the PR, once with `XCL_DIRECT_DXIL=1` and once with it unset, card chosen with `XCL_ADAPTER`: | | `main` | this PR | |---|---|---| | RX 9070 XT (RDNA4, 32.0.32029.2010) | 708 passed, 2 failed, 6 SKIPPED | 711 passed, 2 failed, 6 SKIPPED | | RTX 3060 (32.0.16.1088) | 710 passed, 0 failed, 24 SKIPPED | 713 passed, 0 failed, 24 SKIPPED | The counts are the same on both paths. On both cards and both paths, the only result changes against `main` are the new `gpu_a_loop_after_a_spin_to_the_budget_still_runs_in_both_forms`, `gpu_a_loop_after_a_spin_to_the_budget_still_runs` and `gpu_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 on `main`. 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.
Author
Owner

@⁠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

  • Head 3cde150b3c7a869e95b8eefcb5a2379859ad77d0, against main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.
  • RX 9070 16 GB (RADV GFX1201), Ryzen 7 7700, CachyOS kernel 7.3.0-5-cachyos, Mesa 26.3.1-arch3.5, GE-Proton11-12 Wine 11.0 Staging, vkd3d-proton 8293130ebe370b1+ (local asserts-disabled build), DXC/DXIL 1.9.2602.17, Rust 1.97.1, release x86_64-pc-windows-gnu.
  • Explicit RX 9070 selection, XCL_REQUIRE_GPU=wave64, XCL_NETWORK=0, no inherited XCL_* 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_loop helper; its total-cap expectation uses literal 4 instead 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 wrote WaveGetLaneCount() for all 64 threads: every value was 64, in 3/3 processes per revision. The loop fixtures require runner::wave64_supported() == true and runner::split_wave64() == false; HLSL fixtures check the emitted [WaveSize(64)], and direct fixtures use wave64: 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:

Spin Following loop Nested spin Head [s0, s1, s2]
65536 3 false [65536, 3, 7]
65520 1000 false [65520, 1000, 7]
65536 3 true [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:

Direct form Main, 3/3 Head, 3/3
Plain [65536, 0, 0, 0] [98304, 98304, 65536, 2]
Compact [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_as explicitly; the process setting is XCL_DIRECT_DXIL=0 for 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 with XCL_DIRECT_DXIL=0 and 1.
  • All 36 raw process summaries were checked: 24 pass, 12 expected main-control failures. No ignored tests or runtime skip markers. Per-case readbacks, source inventories, test-only exceptions and executable hashes were independently checked.

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.

**@⁠SzczepanGrela** on GitHub · 2026-11-26 14:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/2793#issuecomment-7194253689) Verified native-wave64 / Wine coverage on RX 9070, including the direct global-cap case discussed above. **Tested** - Head `3cde150b3c7a869e95b8eefcb5a2379859ad77d0`, against main `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7`. - RX 9070 16 GB (RADV GFX1201), Ryzen 7 7700, CachyOS kernel 7.3.0-5-cachyos, Mesa 26.3.1-arch3.5, GE-Proton11-12 Wine 11.0 Staging, vkd3d-proton `8293130ebe370b1+` (local asserts-disabled build), DXC/DXIL 1.9.2602.17, Rust 1.97.1, release `x86_64-pc-windows-gnu`. - Explicit RX 9070 selection, `XCL_REQUIRE_GPU=wave64`, `XCL_NETWORK=0`, no inherited `XCL_*` 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_loop` helper; its total-cap expectation uses literal `4` instead 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 wrote `WaveGetLaneCount()` for all 64 threads: every value was 64, in 3/3 processes per revision. The loop fixtures require `runner::wave64_supported() == true` and `runner::split_wave64() == false`; HLSL fixtures check the emitted `[WaveSize(64)]`, and direct fixtures use `wave64: 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: | Spin | Following loop | Nested spin | Head `[s0, s1, s2]` | | --- | ---: | --- | --- | | 65536 | 3 | false | `[65536, 3, 7]` | | 65520 | 1000 | false | `[65520, 1000, 7]` | | 65536 | 3 | true | `[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: | Direct form | Main, 3/3 | Head, 3/3 | | --- | --- | --- | | Plain | `[65536, 0, 0, 0]` | `[98304, 98304, 65536, 2]` | | Compact | `[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_as` explicitly; the process setting is `XCL_DIRECT_DXIL=0` for 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 with `XCL_DIRECT_DXIL=0` and `1`. - All 36 raw process summaries were checked: 24 pass, 12 expected main-control failures. No ignored tests or runtime skip markers. Per-case readbacks, source inventories, test-only exceptions and executable hashes were independently checked. **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.
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/2793/head:github-bot/gh-2793'
git switch 'github-bot/gh-2793'

Merge

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