Recompiler: a vote's side may narrow EXEC through a whole-quad copy (#336) #947

Merged
emirduran707 merged 3 commits from upstream-pr/953 into main 2026-11-25 01:00:31 +00:00
emirduran707 commented 2026-11-24 09:27:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T09:27:03Z.


Stacked on #517 (itself on #341); only the top commit (38992ed) belongs here. Part of #336.

#517's classifier accepts a mask vote only if the side the wave runs starts with an instruction that narrows EXEC by the vote's mask. The console compiler's pixel-shader discard early-out narrows it one step later:

v_cmpx_gt_f32 …              ; EXEC &= alpha test
s_andn2_b64  s6, s6, exec    ; live pixels (SCC: any left)
s_cbranch_scc0 → null export ; none left: end
s_wqm_b64    s8, s6          ; ← the side starts here
s_load_dwordx4 …
s_and_b64    exec, exec, s8  ; EXEC narrowed to the live quads

So these votes were reported as vote-branch. In the retail shader pack, this shape is behind most of the 2 409 programs whose only reason was vote-branch.

The side now only has to turn EXEC off in a half whose mask is empty before its first lane instruction. #517's zero flow checks this: wqm(0) and x & 0 are zero there. Before that point only scalar ALU ops, scalar loads, s_waitcnt and s_nop are allowed. Their writes are the wave's, and #517 already follows them as stale where the sides join. s_setreg, s_sendmsg, PC writes and any lane instruction end the search. Every shape the old first-instruction check accepted passes the new one.

What is in it

  • crates/xcl/src/gpu/recomp/partition.rs: narrows_before_lane_work replaces narrows_exec_by in vote.
  • Test a_discard_early_out_that_narrows_through_a_whole_quad_copy_is_exact:
    • the compiler's form with a scalar load in between is exact (it fails without the change);
    • lane work before the narrowing, a narrowing by another mask, and s_setreg before it all stay vote-branch.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.31044.16; Ryzen 5 5600, 32 GB; Windows 11 Pro 26300; rustc 1.100.0 x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug for the suite, release for the runs.
  • cargo test --workspace -- --test-threads=4 at 38992ed: 727 passed, 0 failed, 41 ignored; no SKIPPED lines.
  • cargo test -p xcl --lib recomp::partition: 44 passed.
  • QemmHD's review module from #517: 35 of its 36 pass, the same as on #517's head. The one that fails pins p1's reason list.
  • Reference interpreter (QemmHD's cut: one 64-lane wave against its two 32-lane halves), in a local test that is not committed:
    • the new exact form shows no difference over 5 000 random cuts;
    • an export placed before the narrowing differs in 84 of 5 000 cuts and stays vote-branch.
  • Over the 13 210 wave64 VS / PS of a retail shader pack (a local test, not committed; release, one thread):
    • 7 015 Exact instead of 6 057 (PS 4 912 of 10 974, up from 3 954; VS unchanged at 2 103 of 2 236);
    • vote-branch in 5 186 programs instead of 6 375;
    • at most 171 ms for one program.

Regression run

Nothing in the runtime calls the classifier yet, so this only shows the build is unchanged in use. The gpu: line names a virtual display adapter of this machine (what #281 / #282 / #285 fix); XCL's log names backend 'real' – AMD Radeon RX 9060 XT (16188 MiB VRAM).

main:

xcl-smoke v1
commit: 077ce40c3e371cf3df8c57985b1cc6b1db39e75a
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1555 (PresentX 1555)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17182 MB

PR:

xcl-smoke v1
commit: 38992eddadc828da6857f0c7f0e63d454e7e5ef1
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1385 (PresentX 1385)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14707 MB

Not tested

  • Whether the programs this makes Exact match on a 32-lane GPU: there is no 64-lane reference on the GPU yet; the interpreter covers the idiom's shape.
  • NVIDIA (nothing here runs on the GPU).

AI use

  • Claude Code with Claude Opus 5.5: found the shape with a probe over the pack, and wrote the code, the test and this description. The runs above were made on my machine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:6578680678 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/953). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-24T09:27:03Z. --- Stacked on #517 (itself on #341); only the top commit (38992ed) belongs here. Part of #336. #517's classifier accepts a mask vote only if the side the wave runs **starts** with an instruction that narrows EXEC by the vote's mask. The console compiler's pixel-shader discard early-out narrows it one step later: ``` v_cmpx_gt_f32 … ; EXEC &= alpha test s_andn2_b64 s6, s6, exec ; live pixels (SCC: any left) s_cbranch_scc0 → null export ; none left: end s_wqm_b64 s8, s6 ; ← the side starts here s_load_dwordx4 … s_and_b64 exec, exec, s8 ; EXEC narrowed to the live quads ``` So these votes were reported as `vote-branch`. In the retail shader pack, this shape is behind most of the 2 409 programs whose only reason was `vote-branch`. The side now only has to turn EXEC off in a half whose mask is empty before its first lane instruction. #517's zero flow checks this: `wqm(0)` and `x & 0` are zero there. Before that point only scalar ALU ops, scalar loads, `s_waitcnt` and `s_nop` are allowed. Their writes are the wave's, and #517 already follows them as stale where the sides join. `s_setreg`, `s_sendmsg`, PC writes and any lane instruction end the search. Every shape the old first-instruction check accepted passes the new one. **What is in it** - `crates/xcl/src/gpu/recomp/partition.rs`: `narrows_before_lane_work` replaces `narrows_exec_by` in `vote`. - Test `a_discard_early_out_that_narrows_through_a_whole_quad_copy_is_exact`: - the compiler's form with a scalar load in between is exact (it fails without the change); - lane work before the narrowing, a narrowing by another mask, and `s_setreg` before it all stay `vote-branch`. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.31044.16; Ryzen 5 5600, 32 GB; Windows 11 Pro 26300; rustc 1.100.0 `x86_64-pc-windows-msvc`; DXC 1.9.2602.17; debug for the suite, release for the runs. - `cargo test --workspace -- --test-threads=4` at 38992ed: 727 passed, 0 failed, 41 ignored; no `SKIPPED` lines. - `cargo test -p xcl --lib recomp::partition`: 44 passed. - QemmHD's review module from #517: 35 of its 36 pass, the same as on #517's head. The one that fails pins `p1`'s reason list. - **Reference interpreter** (QemmHD's `cut`: one 64-lane wave against its two 32-lane halves), in a local test that is not committed: - the new exact form shows no difference over 5 000 random cuts; - an export placed before the narrowing differs in 84 of 5 000 cuts and stays `vote-branch`. - Over the 13 210 wave64 VS / PS of a retail shader pack (a local test, not committed; release, one thread): - **7 015 Exact instead of 6 057** (PS 4 912 of 10 974, up from 3 954; VS unchanged at 2 103 of 2 236); - `vote-branch` in 5 186 programs instead of 6 375; - at most 171 ms for one program. **Regression run** Nothing in the runtime calls the classifier yet, so this only shows the build is unchanged in use. The `gpu:` line names a virtual display adapter of this machine (what #281 / #282 / #285 fix); XCL's log names `backend 'real' – AMD Radeon RX 9060 XT (16188 MiB VRAM)`. main: ``` xcl-smoke v1 commit: 077ce40c3e371cf3df8c57985b1cc6b1db39e75a gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1555 (PresentX 1555) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17182 MB ``` PR: ``` xcl-smoke v1 commit: 38992eddadc828da6857f0c7f0e63d454e7e5ef1 gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1385 (PresentX 1385) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14707 MB ``` **Not tested** - Whether the programs this makes `Exact` match on a 32-lane GPU: there is no 64-lane reference on the GPU yet; the interpreter covers the idiom's shape. - NVIDIA (nothing here runs on the GPU). **AI use** - Claude Code with Claude Opus 5.5: found the shape with a probe over the pack, and wrote the code, the test and this description. The runs above were made on my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fromthemoonx commented 2026-11-24 10:04:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-24T09:42:34Z.


NVIDIA run, since Not tested lists NVIDIA. The classifier is CPU-side and nothing calls it yet, so this mainly covers the build and suite on a 32-lane card.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools (D3D12 debug layer) installed; rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug
  • Exact head 38992eddadc828da6857f0c7f0e63d454e7e5ef1 (with #517 / #341 under it), clean worktree: cargo build --workspace, then cargo test --workspace -- --test-threads=4: 727 passed, 0 failed, 41 ignored (lib 687 / 0 / 21), the same total as yours. The new test partition::tests::a_discard_early_out_that_narrows_through_a_whole_quad_copy_is_exact passed.
  • Fails without the change, as you say: I put this test alone into partition.rs as it is at dfc5578 (#517's head) and ran it with --exact. It fails, assertion left == right failed at the exact/vote-branch check.
  • Merged onto current main 6bac4b4 (git auto-merged recomp/mod.rs, no conflict): cargo test --workspace --no-fail-fast -- --test-threads=4 --skip a_freed_block_is_decommitted_before_its_address_is_reused, 2 runs: 769 passed, 0 failed, 41 ignored, 1 filtered out both times. The skip is #913, which fills video memory on this 12 GB card.
    • A third merged run had one failure: real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state, at its final assert_ne!(VirtualFree(..), 0). That test does not touch the recompiler. It has failed the same way now and then on plain main here too (see #913), so I don't count it against this PR.
  • recomp::partition + recomp::cfg + recomp::upper_lanes on the merged tree, 10 runs: 10 of 10 passed (60 tests each)
  • D3D12 debug layer: the e2e test title's XCL_D3D12_DEBUG=1 run (test_title_draws_with_a_root_signature_under_the_debug_layer, which runs here because Graphics Tools are installed) logs the same set of debug-layer errors and warnings on the merged tree as on main 077ce40. Nothing new.
  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
  • XCL_SAMPLE_* not set

Not tested

  • The pack survey and reference-interpreter runs (no shader pack here, and the local tests aren't committed); a retail title; release build.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests on the machine above, including the check without the change, and wrote this report from the logs.
<!-- greyfinch-sync:ivall/xcl:comment:7127780796 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/953#issuecomment-7127780796). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-11-24T09:42:34Z. --- NVIDIA run, since **Not tested** lists NVIDIA. The classifier is CPU-side and nothing calls it yet, so this mainly covers the build and suite on a 32-lane card. **Tested** - NVIDIA GeForce RTX 3060 12 GB (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools (D3D12 debug layer) installed; rustc 1.100.0 `stable-x86_64-pc-windows-msvc`; DXC 1.9.2602.17; debug - **Exact head `38992eddadc828da6857f0c7f0e63d454e7e5ef1`** (with #517 / #341 under it), clean worktree: `cargo build --workspace`, then `cargo test --workspace -- --test-threads=4`: **727 passed, 0 failed, 41 ignored** (lib 687 / 0 / 21), the same total as yours. The new test `partition::tests::a_discard_early_out_that_narrows_through_a_whole_quad_copy_is_exact` passed. - **Fails without the change, as you say:** I put this test alone into `partition.rs` as it is at `dfc5578` (#517's head) and ran it with `--exact`. It fails, `assertion left == right failed` at the exact/`vote-branch` check. - **Merged onto current `main` `6bac4b4`** (git auto-merged `recomp/mod.rs`, no conflict): `cargo test --workspace --no-fail-fast -- --test-threads=4 --skip a_freed_block_is_decommitted_before_its_address_is_reused`, 2 runs: **769 passed, 0 failed, 41 ignored, 1 filtered out** both times. The skip is #913, which fills video memory on this 12 GB card. - A third merged run had one failure: `real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state`, at its final `assert_ne!(VirtualFree(..), 0)`. That test does not touch the recompiler. It has failed the same way now and then on plain `main` here too (see #913), so I don't count it against this PR. - `recomp::partition` + `recomp::cfg` + `recomp::upper_lanes` on the merged tree, 10 runs: **10 of 10 passed** (60 tests each) - D3D12 debug layer: the e2e test title's `XCL_D3D12_DEBUG=1` run (`test_title_draws_with_a_root_signature_under_the_debug_layer`, which runs here because Graphics Tools are installed) logs the same set of debug-layer errors and warnings on the merged tree as on `main` `077ce40`. Nothing new. - SKIPPED (no wave64 on this adapter): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` - `XCL_SAMPLE_*` not set **Not tested** - The pack survey and reference-interpreter runs (no shader pack here, and the local tests aren't committed); a retail title; release build. **AI use** - Claude Code (Claude Opus 5.5) ran the builds and tests on the machine above, including the check without the change, and wrote this report from the logs.
hkgamingdk231-prog commented 2026-11-24 10:04:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by hkgamingdk231-prog on 2026-11-24T09:44:11Z.


Test report for head 38992edda.

Setup

  • Each PR's diff applied on main 077ce40 (all applied cleanly), debug build, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.
  • cargo test -p xcl --lib -- gpu::recomp --test-threads=4, once with XCL_ADAPTER=radeon and once with XCL_ADAPTER=3060.
    • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: waves 32..64, so wave64 programs run in native 64-lane waves.
    • NVIDIA RTX 3060 (Ampere), driver 32.0.16.1088: 32 only, so wave64 programs run in the split form.
  • Not run per PR: the whole workspace suite (the recompiler tests only) and a retail smoke run.

Tested: no regressions on either GPU.

  • RX 9070 XT (native wave64): 239 passed, 0 failed, 18 ignored, 0 SKIPPED.
  • RTX 3060 (split wave64): 239 passed, 0 failed, 18 ignored, 2 SKIPPED (no wave64).

This PR adds no GPU test, so these runs only show that the existing recompiler GPU tests still pass with it, including native wave64 on AMD. They do not check the programs it makes Exact against a 64-lane reference.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7127817722 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/953#issuecomment-7127817722). Originally posted by [hkgamingdk231-prog](https://github.com/hkgamingdk231-prog) on 2026-11-24T09:44:11Z. --- Test report for head `38992edda`. **Setup** - Each PR's diff applied on `main` `077ce40` (all applied cleanly), debug build, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17. - `cargo test -p xcl --lib -- gpu::recomp --test-threads=4`, once with `XCL_ADAPTER=radeon` and once with `XCL_ADAPTER=3060`. - AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: waves 32..64, so wave64 programs run in native 64-lane waves. - NVIDIA RTX 3060 (Ampere), driver 32.0.16.1088: 32 only, so wave64 programs run in the split form. - Not run per PR: the whole workspace suite (the recompiler tests only) and a retail smoke run. Tested: no regressions on either GPU. - RX 9070 XT (native wave64): 239 passed, 0 failed, 18 ignored, 0 SKIPPED. - RTX 3060 (split wave64): 239 passed, 0 failed, 18 ignored, 2 SKIPPED (no wave64). This PR adds no GPU test, so these runs only show that the existing recompiler GPU tests still pass with it, including native wave64 on AMD. They do not check the programs it makes `Exact` against a 64-lane reference. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
dcastell1 commented 2026-11-24 10:04:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by dcastell1 on 2026-11-24T09:53:52Z.


Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@077ce40 (baseline 716 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
767 passed; 0 failed; 41 ignored   (exit 0)

51 more passing tests than the baseline — the whole-console-block EXEC narrowing change ships a lot of new fixtures and every one of them runs green here.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

<!-- greyfinch-sync:ivall/xcl:comment:7128037245 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/953#issuecomment-7128037245). Originally posted by [dcastell1](https://github.com/dcastell1) on 2026-11-24T09:53:52Z. --- Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on `main@077ce40` (baseline **716 passed, 0 failed, 41 ignored** on this box): ``` patch -p1 < this PR # clean, no fuzz cargo test --workspace -- --test-threads=4 767 passed; 0 failed; 41 ignored (exit 0) ``` 51 more passing tests than the baseline — the whole-console-block EXEC narrowing change ships a lot of new fixtures and every one of them runs green here. Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
SlopTart commented 2026-11-24 11:05:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-24T10:38:08Z.


Linux / AMD RDNA3 datapoint.

Merged state: head 38992ed onto main 9aec53d, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 764 passed, 11 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows plus this rig's title-textures flake family (see #718). whole-quad-vote EXEC narrowing green on wave64.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7129042509 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/953#issuecomment-7129042509). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-24T10:38:08Z. --- Linux / AMD RDNA3 datapoint. **Merged state:** head `38992ed` onto main `9aec53d`, clean merge. **Full suite, `cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4`:** **764 passed, 11 failed, 41 ignored**; failures are the known Wine-lane set from my #42 rows plus this rig's title-textures flake family (see #718). whole-quad-vote EXEC narrowing green on wave64. **Not tested:** retail titles (none here), Windows, RDNA4. Counts only, no game data. **Machine:** RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross `x86_64-pc-windows-gnu`, `XCL_NETWORK=0`, release profile, `--test-threads=4`. My Linux rows: #42 / #718. AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
DavidM1911 commented 2026-11-24 14:06:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:51:26Z.


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

  • lib recomp: 240 passed, 18 ignored, 0 failed.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7133439211 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/953#issuecomment-7133439211). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T13:51:26Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - lib recomp: 240 passed, 18 ignored, 0 failed. Thanks!
upstream-sync closed this pull request 2026-11-25 01:08:51 +00:00
DavidM1911 commented 2026-11-26 04:07:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T03:11:30Z.


Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

<!-- greyfinch-sync:ivall/xcl:comment:7181477650 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/953#issuecomment-7181477650). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T03:11:30Z. --- Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!947
No description provided.