Skip to content

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

Merged
raylitebull merged 3 commits into
xcl-dev:mainfrom
emirduran707:wave64-idioms
Nov 25, 2026
Merged

raylitebull merged 3 commits into
xcl-dev:mainfrom
emirduran707:wave64-idioms

Conversation

@emirduran707

Copy link
Copy Markdown
Contributor

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 Recompiler: classify wave64 VS / PS by whether a 32-lane cut changes them (#336) #517: 35 of its 36 pass, the same as on Recompiler: classify wave64 VS / PS by whether a 32-lane cut changes them (#336) #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

emirduran707 and others added 3 commits November 24, 2026 03:21
…ll#336)

Preparation for classifying wave64 VS / PS by whether their result depends
on how a 32-lane GPU cuts their waves: that needs to know which blocks run
because of a wave-wide vote. No behaviour change: nothing calls it yet.

cfg::Cfg builds a program's basic blocks from upper_lanes::successors (now
shared), and gives each block's immediate post-dominator (Cooper, Harvey
and Kennedy's iteration on the reversed graph, with one exit after every
block that ends the program) and the branches it is control-dependent on
(Ferrante, Ottenstein and Warren). A program with an indirect jump has no
graph; a block from which no path ends the program has no post-dominator.

Measured over all 26 698 programs of a retail shader pack (release, one
thread): no panic, 195 with an indirect jump, at most 15 995 blocks in one
program, at most 15 ms for one program's graph, post-dominators and
control dependence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…them

Part of xcl-dev#336. A GPU that runs a console wave64 VS / PS in 32-lane waves runs
each half of the console wave on its own. upper_lanes follows what lanes >= 32
hold when they are read; this follows the other ways the cut shows: wave-wide
votes are taken per half, and lane counts, ranks, first-lane indices, masks
used as numbers and other lanes' values differ in a half. Classification
only: nothing translates by it yet.

partition::classify runs a forward data-flow pass over the program's blocks
(cfg) with taint bits per register and reports Exact / MayDiffer with the
reasons:
- a tainted value reaching an export, a store (LDS / GDS ones included), a
  branch or EXEC; one word of EXEC or a number written to EXEC;
- a vote (vccz/vccnz, execz/execnz, scc on a mask) unless the side taken
  with the mask empty is the join or ends the program writing nothing, and
  the other side starts by narrowing EXEC to the mask (for a mask other
  than EXEC) and does not widen it again before the join (a restore of a
  mask saved inside, an if/else flip, a restore right before the join are
  fine) – or the mask is all or none of the active lanes;
- a scalar written in the blocks a vote decides and read after the join
  (a half that took the other side never wrote it).
Values every lane has are followed (written under the launch EXEC by plain
VALU ops of such values, through all-or-none selectors, or loaded at such
addresses), so reading one from the first lane is exact. Register uses
come from x64_masks::uses (read-modify-write destinations, SDWA scalar
sources, SMEM offsets, src_vccz / src_execz) plus src_scc, NSA addresses
and image loads by their DMASK (upper_lanes::vgpr_writes, now shared).

Tests include the review's counter-examples (values written under a
narrowed EXEC or selected per lane, a vote read as a number, mask words
moved, read-modify-write taint, a side that widens EXEC again, an SCC vote
whose mask is rewritten, EXEC's high word, image DMASK, DS writes) and one
for every reason.

Over the 13 210 wave64 VS / PS of a retail shader pack (local run): 7 208
Exact (5 118 of 10 974 PS, 2 090 of 2 236 VS), at most 159 ms a program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cl-dev#336)

The partition classifier accepted 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: `s_wqm_b64 s, live; s_and_b64 exec, exec, s`, often with scalar
loads in between. Such votes were reported as `vote-branch`.

The side now only has to turn EXEC off, in a half whose mask is empty,
before its first lane instruction. The zero flow of the vote's side checks
it: wqm(0) and x & 0 are zero there. Before that only scalar ALU ops, scalar
loads, s_waitcnt and s_nop are allowed; their writes are the wave's and are
followed 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.

Over the 13 210 wave64 VS / PS of a retail shader pack: 7 015 Exact
instead of 6 057 (PS 4 912 of 10 974, from 3 954), `vote-branch` 5 186
programs instead of 6 375. A reference interpreter of a 64-lane wave and
its two 32-lane halves (from the review of xcl-dev#517) shows no difference for
the new exact form over 5 000 random cuts, and differs for an export
placed before the narrowing, which stays `vote-branch`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fromthemoonx

Copy link
Copy Markdown

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 Recompiler: classify wave64 VS / PS by whether a 32-lane cut changes them (#336) #517 / Recompiler: basic blocks, post-dominators and control dependence (#336) #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 (Recompiler: classify wave64 VS / PS by whether a 32-lane cut changes them (#336) #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 Memory: a sparse alloc/free loop makes a new 64 MiB pool each cycle; lib tests fill a 12 GB card (#348's test) #913, which fills video memory on this 12 GB card.
  • 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.

@DarkPanda69

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

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

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants