Recompiler: close nested loop ranges with prefix maxima #1632
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1642"
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?
Imported from ivall/xcl. Originally posted by pmilewsskiedu-gif on 2026-11-24T18:34:24Z.
Part of #1269. The structured shader translator's
nested_loop_rangespreviously 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.Tested
cargo build --workspaceandcargo 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.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: main9e3831e110.3 s, this branch15e7f71109.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.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:
Pair 2, same path and same build order:
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.
Imported from ivall/xcl. Originally posted by Flyander on 2026-11-24T19:08:19Z.
Review: APPROVED
I reviewed head
15e7f71and rancargo test -p xcl nested_loop_tests -- --nocaptureon Windows/MSVC: 2 passed. The descending-start Fenwick pass preserves the strict overlap predicate and defers updates for equal starts; the exhaustive and seeded oracle cases agree with the previous pair-scan algorithm. No findings.AI use: OpenAI Codex (GPT-6; exact variant unavailable).
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-24T19:19:28Z.
Independent AMD run and synthetic loop-closure scaling at
15e7f71bb755ed35c1a79f8a3564f028cf5746bd(basec160d86ef2efe3a07e4dfb473e4fa72eafb413c0).Tested
XCL_ADAPTER='AMD Radeon'. Workspace builds used the unoptimized profile with debug info disabled.cargo build --workspace --lockedpassed.cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-outputreported 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).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 --nocapturegave 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.close_nested_loop_rangesverbatim (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 nearu64::MAX. The chain cases below also matched the independently constructed expected ranges.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.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T21:06:50Z.
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 unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by throny on 2026-11-25T10:28:37Z.
Test report for exact head
15e7f71.Tested
cargo build --workspace && cargo test --workspace -- --test-threads=4on15e7f71as 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,main568e7dbfirst, then this head. Both runs started without the preload list newer builds leave behind (used-pipelines.txtin the DXIL cache), which makes builds on an older base run out of memory at start:main:
PR:
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.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T14:25:57Z.
Independent desktop NVIDIA verification of PR #1642 at head
15e7f71bb755ed35c1a79f8a3564f028cf5746bd(1commit; exact parent & merge-base:9e3831e1f570d3646e53ab753b19ec07eb8f1485, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted tests & build (
15e7f71b)cargo test --release -p xcl --lib -- --nocapture gpu::recomp::nested_loop_tests::(3 consecutive runs)2 passed; 0 failed; 0 ignored; 748 filtered out× 3 (0.02s,0.02s,0.02s,0skipped; exhaustive2^15small-set parity +1000random duplicate/crossing cases vs. pair-scan reference)cargo test --release -p xcl --lib -- --nocapture gpu::recomp::(3 consecutive parallel runs)16.31s):185 passed; 9 failed; 18 ignored; 538 filtered out(pre-existing parallel-GPU failure ingpu_sparse_vram_descriptors_buffers_and_xmemattests.rs:3527:13,left: 0, right: 1077, accompanied by D3D120x887A0005DXGI_ERROR_DEVICE_REMOVEDcascading to 8 concurrent GPU tests; bothnested_loop_tests::andjumps_to_outer_loop_heads_are_structuredpassed on Run 1); Runs 2–3 (5.84s,6.08s):194 passed; 0 failed; 18 ignored; 538 filtered out(191executed +3runtime skips: 2×no wave64, 1×XCL_SAMPLE_RPF not set)cargo build --release -p xcl1m 14s, exit0,0new warnings ingpu/recomp/mod.rs)Paired quiet 60 s retail smoke (
title: 29640639)(Note:
scripts/smoke.ps1at9e3831e1predates9683e7a6and printed the local folder basename ontitle:; replaced below with the standard9683e7a6title hash29640639, with all measured fields verbatim.)Exact parent & merge-base (
9e3831e1f570d3646e53ab753b19ec07eb8f1485, cached baseline on the same machine):PR #1642 (
15e7f71bb755ed35c1a79f8a3564f028cf5746bd):Limits of coverage
gpu::recomp::nested_loop_tests::(2/2,0skipped) andjumps_to_outer_loop_heads_are_structured(120 of 120 programs structured (76 jumps into a loop)) passed3/3, directly verifying Fenwick prefix-maximumclose_nested_loop_rangesparity against the prior pair-scan fixed point.gpu::recomp::sweep, Run 1 hit an unrelated parallel D3D12 device removal (0x887A0005alongsidegpu_sparse_vram_descriptors_buffers_and_xmem), while Runs 2 and 3 passed cleanly (194/0/18:191executed +3Wave32/env self-skips); on the Wave32-only RTX 4060 host the two Wave64-only tests self-skip.0device removals,0crashes, steady 60 Hz); single-run frame/commit delta vs. the cached parent (1477vs.1549frames) reflects normal startup variance rather than steady-state frame pacing.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T05:42:56Z.
merge-check claim
head:
15e7f71bb7Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T05:56:51Z.
merge-check
base:
d52ff48caahead:
15e7f71bb7merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2877 passed, 2 failed, 51 ignored; 29 SKIPPED lines
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review.
performance: not assessed beyond the suite.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017
correction: this check first reported the PR as "not yet" because of a test failure that is not the PR's. The base-comparison step failed to run (test names contain a double colon, not a legal Windows filename), so an empty read was mistaken for "passes on base".
gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16fails on based52ff48cby itself (verified separately with the same command: "assertion failed: 2D D16 resinfo clobbered v2/v3"). Verdict corrected. Apologies for the noise.Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T09:39:45Z.
merge-check claim
head:
15e7f71bb7Imported from ivall/xcl. Originally posted by Elytes on 2026-11-30T09:42:08Z.
merge-check
base:
9dfbe3ea66head:
15e7f71bb7merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2887 passed, 1 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer, 1 driver cache needs Developer Mode); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, also failing on the base alone (base lib 2737 passed / 1 failed, merge 2739 / 1; the +2 are this PR's oracle tests, passing).
review: no blocking finding after reading the whole diff and the comments; the two oracle tests pass and the closure matches the old pair scan by construction (equal starts deferred, strict overlap kept). Scope today: nested_loop_ranges serves only the HLSL translator (recomp::translate: per-stage fallback from direct DXIL,
xcl shaders), not the default direct DXIL path, so the gain applies there.performance: translation time on the HLSL path only; output unchanged by construction (reasoned, not measured here).
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.1742, wave32), Intel Core i9-14900KS, 192 GB, Windows 11 build 26300.10075, rustc 1.100.1, debug / Claude Code (Claude Opus 5.5) ran the merge, build, suite and base run, and reviewed the diff and comments.
Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T09:45:56Z.
merge-check
base:
9dfbe3ea66head:
15e7f71bb7merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2887 passed, 1 failed, 51 ignored; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails on the base alone too (base: 2885 passed, 1 failed, 51 ignored, 28 SKIPPED lines). 28 SKIPPED lines, as on the base. Both new tests passed (
interval_closure_matches_pair_scan_for_all_small_sets,interval_closure_matches_pair_scan_with_duplicates_and_crossing_chains).review: no blocking finding; one file, every hunk read.
loop_rangeskeeps its inputs and hands the closure of crossing ranges to a newclose_nested_loop_ranges(ranges sorted by start, later starts closed first, a Fenwick prefix maximum over starts strictly inside the range). The old pair-scan loop is kept in the test module as the reference: the new function is compared with it on every subset of the 15 intervals over 0..6 (32,768 sets) and on 1,000 random sets plus hand-picked chains, equal starts and duplicates included. Output order changes fromsorttosort_unstableon(u64, u64)pairs, which is the same order. I did not find another PR making this change (searched open and merged for loop_ranges / nested loop closure).performance: CPU time of shader translation only, lower for programs with many crossing backward jumps (the PR's claim; not measured here). No effect on frame time or memory; the generated code is the same when the closure is the same, which is what the tests check.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:22:22Z.
Triage (#1607) – head
15e7f71No open or merged PR makes the same change. Main still runs the repeated pair scan in
nested_loop_ranges.No problems found in the diff. The descending-start Fenwick prefix max computes the same closure, because later starts are closed first, the query is strict (
start < end), and writes for equal starts wait until the group is done. The test against the old algorithm on every subset of 15 intervals, plus 1000 random sets, covers equal starts and touching endpoints.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.