Recompiler: close nested loop ranges with prefix maxima #1642

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

@⁠pmilewsskiedu-gif on GitHub · 2026-11-24 18:34 UTC · original
pmilewsskiedu-gif:perf/nested-loop-1269 → main · +96 −7 · 1 files · 1 commits · open

Part of #1269. The structured shader translator's nested_loop_ranges previously searched every pair of backward-jump intervals repeatedly until all strict overlaps were closed. Crossing chains can make this superquadratic. Close later-starting ranges first and query a Fenwick prefix maximum to compute the same fixed point in O(L log L), keeping the original strict endpoint and equal-start semantics.

What is in it

  • crates/xcl/src/gpu/recomp/mod.rs: replace repeated pair scans for nested loop closure with a descending-start prefix-max pass, including zero/one-range fast paths.
  • Two reference-oracle tests preserve the old algorithm in test code; cover all 32,768 subsets of 15 small intervals, touching endpoints, equal starts, long crossing chains, and 1,000 seeded randomized collections.

Tested

  • Windows 11 Pro build 26200; AMD Ryzen 7 7700; NVIDIA RTX 4060 Ti (8GB), driver 32.0.16.1088; Rust 1.100.0 MSVC; DXC 1.9.2602.17.
  • cargo build --workspace and cargo test --workspace -- --test-threads=4: 778 passed, 0 failed, 41 ignored. GPU SKIPPED messages: two tests on unavailable native wave64; one heap-window test on unavailable heap windows.
  • cargo build --release -p xcl: passed.
  • On a local retail 26,698-program shader pack (xcl shaders <pack> --recomp --top 0), both builds translated 26,698 programs with zero errors and emitted an aggregate 9,665.7 MB HLSL. The report lines matched except timing. Matched HLSL-dump pair: main 9e3831e 110.3 s, this branch 15e7f71 109.2 s (CLI-reported translation scan time). This small ~1% difference is within run noise, not a claim about DXC or GPU driver compilation.
  • XCL_DUMP_EVERY=100 XCL_DUMP_HLSL=<separate local folders>: 253/253 sampled generated HLSL files, 85.1 MiB, identical SHA-256 on main and this branch, no missing/extra files. No game data or dumps are committed.
  • A temporary debug-build scaling test (removed from the final source) compared the exact old algorithm with this one on 160 chained overlapping intervals: 318,074 µs → 50 µs, same interval output. This is synthetic worst-case behavior, not a retail shader FPS estimate.

Regression run
Both binaries were copied sequentially to the exact same temporary xcl.exe path and working directory on this computer, with SHA-256 verification after each swap. The title and run settings are identical. This controls for executable-path-dependent driver caches. All runs used scripts/smoke.ps1 -Seconds 60; no crash/device removal.

Pair 1, shared executable path:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 4060 Ti
title: local Xbox title (folder name redacted)
seconds: 60
exit: 0x0
frames shown: 1210 (PresentX 1210)
presents per 2 s (last 3): 5 9 2
device removals: 0
crashes: 0
peak commit: 25169 MB
xcl-smoke v1
commit: 15e7f71bb755ed35c1a79f8a3564f028cf5746bd
gpu: NVIDIA GeForce RTX 4060 Ti
title: local Xbox title (folder name redacted)
seconds: 60
exit: 0x0
frames shown: 1256 (PresentX 1257)
presents per 2 s (last 3): 10 23 40
device removals: 0
crashes: 0
peak commit: 25714 MB

Pair 2, same path and same build order:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 4060 Ti
title: local Xbox title (folder name redacted)
seconds: 60
exit: 0x0
frames shown: 1259 (PresentX 1259)
presents per 2 s (last 3): 2 6 38
device removals: 0
crashes: 0
peak commit: 25743 MB
xcl-smoke v1
commit: 15e7f71bb755ed35c1a79f8a3564f028cf5746bd
gpu: NVIDIA GeForce RTX 4060 Ti
title: local Xbox title (folder name redacted)
seconds: 60
exit: 0x0
frames shown: 1658 (PresentX 1658)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14771 MB

Caveat: Earlier tests from different release-executable paths yielded consistently lower frames/higher memory on the patch path (~1.25k frames/25 GB) than on the main path (~1.65k/14.8 GB). Moving the unmodified main binary to a third shared path reproduced the high-memory/low-frame state, establishing executable path or cache state as a confounder. The same-path tests above do not show a consistent regression, but these 60-second runs are too variable to claim FPS or memory benefits.

Not tested
AMD/Intel GPU hardware; long-duration gameplay; full-byte HLSL comparison for every shader (sampled 253); cold cache and fixed driver-state PSO compile timings.

AI use
ChatGPT GPT-6 with Chat On Steroids Core wrote the source and tests, ran the Windows tests, synthetic/retail benchmarks and RTX 4060 Ti smoke checks, and prepared this PR. An independent Chat On Steroids worker reviewed the algorithm and every diff line; it made no edits.

**@⁠pmilewsskiedu-gif** on GitHub · 2026-11-24 18:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1642) `pmilewsskiedu-gif:perf/nested-loop-1269` → `main` · +96 −7 · 1 files · 1 commits · open Part of #1269. The structured shader translator's `nested_loop_ranges` previously searched every pair of backward-jump intervals repeatedly until all strict overlaps were closed. Crossing chains can make this superquadratic. Close later-starting ranges first and query a Fenwick prefix maximum to compute the same fixed point in O(L log L), keeping the original strict endpoint and equal-start semantics. **What is in it** - `crates/xcl/src/gpu/recomp/mod.rs`: replace repeated pair scans for nested loop closure with a descending-start prefix-max pass, including zero/one-range fast paths. - Two reference-oracle tests preserve the old algorithm in test code; cover all 32,768 subsets of 15 small intervals, touching endpoints, equal starts, long crossing chains, and 1,000 seeded randomized collections. **Tested** - Windows 11 Pro build 26200; AMD Ryzen 7 7700; NVIDIA RTX 4060 Ti (8GB), driver 32.0.16.1088; Rust 1.100.0 MSVC; DXC 1.9.2602.17. - `cargo build --workspace` and `cargo test --workspace -- --test-threads=4`: **778 passed, 0 failed, 41 ignored**. GPU SKIPPED messages: two tests on unavailable native wave64; one heap-window test on unavailable heap windows. - `cargo build --release -p xcl`: passed. - On a local retail 26,698-program shader pack (`xcl shaders <pack> --recomp --top 0`), both builds translated 26,698 programs with **zero errors** and emitted an aggregate 9,665.7 MB HLSL. The report lines matched except timing. Matched HLSL-dump pair: main `9e3831e` **110.3 s**, this branch `15e7f71` **109.2 s** (CLI-reported translation scan time). This small ~1% difference is within run noise, not a claim about DXC or GPU driver compilation. - `XCL_DUMP_EVERY=100 XCL_DUMP_HLSL=<separate local folders>`: **253/253 sampled generated HLSL files, 85.1 MiB, identical SHA-256** on main and this branch, no missing/extra files. No game data or dumps are committed. - A temporary debug-build scaling test (removed from the final source) compared the exact old algorithm with this one on 160 chained overlapping intervals: **318,074 µs → 50 µs**, same interval output. This is synthetic worst-case behavior, not a retail shader FPS estimate. **Regression run** Both binaries were copied sequentially to the exact **same temporary xcl.exe path and working directory** on this computer, with SHA-256 verification after each swap. The title and run settings are identical. This controls for executable-path-dependent driver caches. All runs used `scripts/smoke.ps1 -Seconds 60`; no crash/device removal. Pair 1, shared executable path: ```text xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: NVIDIA GeForce RTX 4060 Ti title: local Xbox title (folder name redacted) seconds: 60 exit: 0x0 frames shown: 1210 (PresentX 1210) presents per 2 s (last 3): 5 9 2 device removals: 0 crashes: 0 peak commit: 25169 MB ``` ```text xcl-smoke v1 commit: 15e7f71bb755ed35c1a79f8a3564f028cf5746bd gpu: NVIDIA GeForce RTX 4060 Ti title: local Xbox title (folder name redacted) seconds: 60 exit: 0x0 frames shown: 1256 (PresentX 1257) presents per 2 s (last 3): 10 23 40 device removals: 0 crashes: 0 peak commit: 25714 MB ``` Pair 2, same path and same build order: ```text xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: NVIDIA GeForce RTX 4060 Ti title: local Xbox title (folder name redacted) seconds: 60 exit: 0x0 frames shown: 1259 (PresentX 1259) presents per 2 s (last 3): 2 6 38 device removals: 0 crashes: 0 peak commit: 25743 MB ``` ```text xcl-smoke v1 commit: 15e7f71bb755ed35c1a79f8a3564f028cf5746bd gpu: NVIDIA GeForce RTX 4060 Ti title: local Xbox title (folder name redacted) seconds: 60 exit: 0x0 frames shown: 1658 (PresentX 1658) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14771 MB ``` **Caveat:** Earlier tests from different release-executable paths yielded consistently lower frames/higher memory on the patch path (~1.25k frames/25 GB) than on the main path (~1.65k/14.8 GB). Moving the *unmodified main* binary to a third shared path reproduced the high-memory/low-frame state, establishing executable path or cache state as a confounder. The same-path tests above do not show a consistent regression, but these 60-second runs are too variable to claim FPS or memory benefits. **Not tested** AMD/Intel GPU hardware; long-duration gameplay; full-byte HLSL comparison for every shader (sampled 253); cold cache and fixed driver-state PSO compile timings. **AI use** ChatGPT GPT-6 with Chat On Steroids Core wrote the source and tests, ran the Windows tests, synthetic/retail benchmarks and RTX 4060 Ti smoke checks, and prepared this PR. An independent Chat On Steroids worker reviewed the algorithm and every diff line; it made no edits.
The structured shader path repeatedly searched all pairs of backward-branch ranges and restarted whenever an end grew. Close later-starting ranges first and use a Fenwick prefix maximum to compute the same strict-overlap fixed point in O(L log L), with zero/one-range fast paths.

Exhaustive and random old/new parity tests, 253 sampled HLSL files byte-identical to main, and a 160-interval chained-crossing synthetic case reduced from ~318 ms to ~50 us (debug build).

Assisted-by: Chat On Steroids Core (GPT-6)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:00:19 +00:00
Author
Owner

@⁠nnonno91 on GitHub · 2026-11-24 19:19 UTC · original

Independent AMD run and synthetic loop-closure scaling at 15e7f71bb755ed35c1a79f8a3564f028cf5746bd (base c160d86ef2efe3a07e4dfb473e4fa72eafb413c0).

Tested

  • AMD Ryzen 7 9800X3D, integrated AMD Radeon(TM) Graphics (32.0.21042.62), Windows 11 25H2 26200.9974, Rust 1.100.0 MSVC, SDK DXC 1.8.2502.11. XCL_ADAPTER='AMD Radeon'. Workspace builds used the unoptimized profile with debug info disabled.
  • cargo build --workspace --locked passed. cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output reported 778 passed, 0 failed, 41 ignored. The bundled title passed. One GPU skip is included in the pass count (heap_window_out_of_memory_falls_back_to_the_switch_form, heap windows off).
  • With XCL_REQUIRE_GPU=wave64,mesh, cargo test --locked -p xcl --lib -- interval_closure gpu_scalar_loop_and_scc jumps_to_outer_loop_heads_are_structured --test-threads=1 --nocapture gave 4 passed, 0 failed, 0 ignored, 0 skips. The structured-control-flow test reported 120 of 120 programs structured and 120 run both ways, including 70 jumps into a loop.
  • A temporary standalone Rust probe used the PR's pair-scan reference and its new close_nested_loop_ranges verbatim (rustc --edition=2021 -C opt-level=3 pr1642-loop-closure-probe.rs -o pr1642-loop-closure-probe.exe, then ran the exe). The outputs matched for 512 seeded input sets and each set's shuffled order (1,024 comparisons). Inputs included duplicate and touching ranges and addresses near u64::MAX. The chain cases below also matched the independently constructed expected ranges.
Synthetic crossing chain Old pair scan, median PR prefix maximum, median
32 ranges 69.3 µs 0.467 µs
64 ranges 1,129.1 µs 1.056 µs
128 ranges 21,154.9 µs 2.432 µs
256 ranges 352,662.3 µs 5.628 µs

Each chain was (i, i+2) in ascending order. Medians use nine alternating-order samples, one call per old sample and 512 calls averaged per new sample. Input copies were prepared before timing.

Not tested

Retail packs or titles, full translator timing, DXC or driver compile timing, and other GPUs. The timing table covers only the CPU interval-closure step on these synthetic inputs.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) wrote the temporary comparison harness, ran the tests, and drafted the report.

**@⁠nnonno91** on GitHub · 2026-11-24 19:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/1642#issuecomment-7141928239) Independent AMD run and synthetic loop-closure scaling at `15e7f71bb755ed35c1a79f8a3564f028cf5746bd` (base `c160d86ef2efe3a07e4dfb473e4fa72eafb413c0`). **Tested** - AMD Ryzen 7 9800X3D, integrated AMD Radeon(TM) Graphics (32.0.21042.62), Windows 11 25H2 26200.9974, Rust 1.100.0 MSVC, SDK DXC 1.8.2502.11. `XCL_ADAPTER='AMD Radeon'`. Workspace builds used the unoptimized profile with debug info disabled. - `cargo build --workspace --locked` passed. `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output` reported **778 passed, 0 failed, 41 ignored**. The bundled title passed. One GPU skip is included in the pass count (`heap_window_out_of_memory_falls_back_to_the_switch_form`, heap windows off). - With `XCL_REQUIRE_GPU=wave64,mesh`, `cargo test --locked -p xcl --lib -- interval_closure gpu_scalar_loop_and_scc jumps_to_outer_loop_heads_are_structured --test-threads=1 --nocapture` gave **4 passed, 0 failed, 0 ignored, 0 skips**. The structured-control-flow test reported **120 of 120 programs structured and 120 run both ways**, including 70 jumps into a loop. - A temporary standalone Rust probe used the PR's pair-scan reference and its new `close_nested_loop_ranges` verbatim (`rustc --edition=2021 -C opt-level=3 pr1642-loop-closure-probe.rs -o pr1642-loop-closure-probe.exe`, then ran the exe). The outputs matched for 512 seeded input sets and each set's shuffled order (1,024 comparisons). Inputs included duplicate and touching ranges and addresses near `u64::MAX`. The chain cases below also matched the independently constructed expected ranges. | Synthetic crossing chain | Old pair scan, median | PR prefix maximum, median | | --- | ---: | ---: | | 32 ranges | 69.3 µs | 0.467 µs | | 64 ranges | 1,129.1 µs | 1.056 µs | | 128 ranges | 21,154.9 µs | 2.432 µs | | 256 ranges | 352,662.3 µs | 5.628 µs | Each chain was `(i, i+2)` in ascending order. Medians use nine alternating-order samples, one call per old sample and 512 calls averaged per new sample. Input copies were prepared before timing. **Not tested** Retail packs or titles, full translator timing, DXC or driver compile timing, and other GPUs. The timing table covers only the CPU interval-closure step on these synthetic inputs. **AI use** OpenAI Codex (GPT-6 family, exact variant unavailable) wrote the temporary comparison harness, ran the tests, and drafted the report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 21:06 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 21:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/1642#issuecomment-7144493031) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠throny on GitHub · 2026-11-25 10:28 UTC · original

Test report for exact head 15e7f71.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, title runs in release.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on 15e7f71 as it is (its own base): 778 passed, 0 failed, 41 ignored. SKIPPED: 3 lines (no wave64 on this adapter, and the like).
  • scripts/smoke.ps1, the retail title, 60 s, release builds, main 568e7db first, then this head. Both runs started without the preload list newer builds leave behind (used-pipelines.txt in the DXIL cache), which makes builds on an older base run out of memory at start:

main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1607 (PresentX 1607)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14549 MB

PR:

xcl-smoke v1
commit: 15e7f71bb755ed35c1a79f8a3564f028cf5746bd
gpu: NVIDIA GeForce RTX 4080
title: retail-title
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: 14763 MB

Not tested: AMD, the head merged onto current main, a world load.

AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.

**@⁠throny** on GitHub · 2026-11-25 10:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1642#issuecomment-7159747371) Test report for exact head `15e7f71`. **Tested** - Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, title runs in release. - `cargo build --workspace && cargo test --workspace -- --test-threads=4` on `15e7f71` as it is (its own base): **778 passed, 0 failed, 41 ignored**. `SKIPPED`: 3 lines (no wave64 on this adapter, and the like). - `scripts/smoke.ps1`, the retail title, 60 s, release builds, `main` `568e7db` first, then this head. Both runs started without the preload list newer builds leave behind (`used-pipelines.txt` in the DXIL cache), which makes builds on an older base run out of memory at start: main: ``` xcl-smoke v1 commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb gpu: NVIDIA GeForce RTX 4080 title: 21222967 seconds: 60 exit: 0x0 frames shown: 1607 (PresentX 1607) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14549 MB ``` PR: ``` xcl-smoke v1 commit: 15e7f71bb755ed35c1a79f8a3564f028cf5746bd gpu: NVIDIA GeForce RTX 4080 title: retail-title 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: 14763 MB ``` **Not tested:** AMD, the head merged onto current `main`, a world load. AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/1642/head:github-bot/gh-1642'
git switch 'github-bot/gh-1642'

Merge

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