Recompiler: scalars written behind a vote and read after it are partition-dependent (#336) #528

Closed
github-bot wants to merge 3 commits from gh-pr/528/head into gh-pr/528/base
Owner

@⁠emirduran707 on GitHub · 2026-11-24 01:23 UTC · original
emirduran707:wave64-stale → main · +1061 −1 · 4 files · 3 commits · closed without merging

Stacked on #517 (which is stacked on #341); only the top commit (741efd7) belongs here. Part of #336.

A half whose mask is empty takes the other side of a vote (or skips its lane-masked side), so it never runs the scalar code the wave runs there. A scalar that code writes and that is read after the sides join holds something else in that half – one of the ways #517 left to follow. Classification only: nothing translates by it yet.

What is in it

  • gpu/recomp/partition.rs: classify runs its data-flow pass twice. The first finds the votes – branches on a mask, unless every half has lanes and votes as the wave does (the launch EXEC, or a mask that is all or none of its lanes) – and the scalars written in the blocks each one decides (SGPRs, VCC, M0, SCC; not EXEC, which the join restores), from cfg's control dependence with nested branches' blocks included. The second marks those scalars stale where the vote's sides join; a stale value reaching an export, a store, a branch or EXEC is the new reason stale-scalar.
  • Tests: a scalar written behind an EXEC vote and read after the join (and the same not read: exact); a scalar behind a vote every half takes as the wave.

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 741efd7: 700 passed, 0 failed, 41 ignored; no SKIPPED lines.
  • Over the 13 210 wave64 VS / PS of a retail shader pack (a local test, not committed; release, one thread): 8 767 Exact (was 9 424 with #517 alone: 6 620 of 10 974 PS, 2 147 of 2 236 VS); stale-scalar in 2 468 programs; no panic; at most 99 ms for one program (two passes; nothing calls this on a title's path yet).

Regression run

Nothing in the runtime calls the new code, 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: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1382 (PresentX 1382)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14751 MB

PR:

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

Not tested

  • Whether the flagged programs actually differ on a 32-lane GPU (no 64-lane reference yet).
  • NVIDIA (nothing here runs on the GPU).

AI use

  • Claude Code with Claude Opus 5.5: wrote the code, the tests and this description; the runs above were made on my machine.
**@⁠emirduran707** on GitHub · 2026-11-24 01:23 UTC · [original](https://github.com/xcl-dev/xcl/pull/528) `emirduran707:wave64-stale` → `main` · +1061 −1 · 4 files · 3 commits · closed without merging Stacked on #517 (which is stacked on #341); only the top commit (741efd7) belongs here. Part of #336. A half whose mask is empty takes the other side of a vote (or skips its lane-masked side), so it never runs the scalar code the wave runs there. A scalar that code writes and that is read after the sides join holds something else in that half – one of the ways #517 left to follow. Classification only: nothing translates by it yet. **What is in it** - `gpu/recomp/partition.rs`: `classify` runs its data-flow pass twice. The first finds the votes – branches on a mask, unless every half has lanes and votes as the wave does (the launch EXEC, or a mask that is all or none of its lanes) – and the scalars written in the blocks each one decides (SGPRs, VCC, M0, SCC; not EXEC, which the join restores), from `cfg`'s control dependence with nested branches' blocks included. The second marks those scalars stale where the vote's sides join; a stale value reaching an export, a store, a branch or EXEC is the new reason `stale-scalar`. - Tests: a scalar written behind an EXEC vote and read after the join (and the same not read: exact); a scalar behind a vote every half takes as the wave. **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 741efd7: 700 passed, 0 failed, 41 ignored; no `SKIPPED` lines. - Over the 13 210 wave64 VS / PS of a retail shader pack (a local test, not committed; release, one thread): 8 767 Exact (was 9 424 with #517 alone: 6 620 of 10 974 PS, 2 147 of 2 236 VS); `stale-scalar` in 2 468 programs; no panic; at most 99 ms for one program (two passes; nothing calls this on a title's path yet). **Regression run** Nothing in the runtime calls the new code, 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: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212 gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1382 (PresentX 1382) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14751 MB ``` PR: ``` xcl-smoke v1 commit: 741efd798a50b3d75e011c54e9e5790b1fd3894f gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1401 (PresentX 1401) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14736 MB ``` **Not tested** - Whether the flagged programs actually differ on a 32-lane GPU (no 64-lane reference yet). - NVIDIA (nothing here runs on the GPU). **AI use** - Claude Code with Claude Opus 5.5: wrote the code, the tests and this description; the runs above were made on my machine.
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 <[email protected]>
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 way the cut shows: wave-wide
votes are taken per half, and lane counts, ranks, first-lane indices,
masks used as numbers and other lanes' varying 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, follows values every lane has
(compares, loads at such addresses) and masks that are all or none of the
active lanes, and reports a tier (Exact / MayDiffer) and the reasons:
- a tainted value reaching an export, a store, a branch or EXEC;
- a vote (vccz/vccnz, execz/execnz, scc on a mask) unless its side taken
  with the mask empty is the join or ends the program writing nothing (a
  pixel shader's all-discarded way out), and, for a mask other than EXEC,
  the other side starts by narrowing EXEC to it – or the mask is all or
  none of the active lanes.
Scalars defined behind a vote (the next part of #336) and exact idioms
(waterfall loops) are not followed yet; unknown counts as MayDiffer.

Over the 13 210 wave64 VS / PS of a retail shader pack (local run): 9 424
Exact (7 248 of 10 974 PS, 2 176 of 2 236 VS), at most 25 ms a program.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A half whose mask is empty takes the other side of a vote (or skips its
lane-masked side) and so never runs the scalar code the wave runs there.
A scalar that code writes (SGPR, VCC, M0, SCC; not EXEC, which the join
restores) and that is read after the sides join holds something else in
that half.

partition::classify now runs its data-flow pass twice: the first finds the
votes – branches on a mask, unless every half has lanes and votes as the
wave does (the launch EXEC, or a mask that is all or none of its lanes) –
and the scalars written in the blocks each one decides (control
dependence, nested branches included); the second marks those scalars
stale where the vote's sides join. A stale value reaching an export, a
store, a branch or EXEC is the new reason `stale-scalar`.

Over the 13 210 wave64 VS / PS of a retail shader pack (local run): 8 767
Exact (was 9 424): 2 468 programs read such a scalar; at most 99 ms a
program.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:24:40 +00:00
github-bot closed this pull request 2026-11-26 04:24:40 +00:00
Author
Owner

@⁠4MDomo on GitHub · 2026-11-24 01:53 UTC · original

NVIDIA test report for 741efd7 (this PR's head, #517 and #341 included).

Tested

  • NVIDIA GeForce RTX 3070 (32-lane waves only), driver 32.0.16.1742; Intel i9-9900K, 32 GB; Windows 11 Home 10.0.26300; rustc 1.98.1 stable-x86_64-pc-windows-msvc; DXC 1.8.2502.11 (Windows SDK 10.0.26100.0); debug.
  • cargo test --workspace -- --test-threads=4 at 741efd7: 700 passed, 0 failed, 41 ignored (the same 700 as on the RX 9060 XT).
  • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware. Same as main 508a0c7.

Not tested

  • The shader-pack counts (no retail shader pack here).

AI use

  • Claude Code (Claude Opus 5.5) ran the suite and wrote this report; checked by me.
**@⁠4MDomo** on GitHub · 2026-11-24 01:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/528#issuecomment-7119553437) NVIDIA test report for 741efd7 (this PR's head, #517 and #341 included). **Tested** - NVIDIA GeForce RTX 3070 (32-lane waves only), driver 32.0.16.1742; Intel i9-9900K, 32 GB; Windows 11 Home 10.0.26300; rustc 1.98.1 `stable-x86_64-pc-windows-msvc`; DXC 1.8.2502.11 (Windows SDK 10.0.26100.0); debug. - `cargo test --workspace -- --test-threads=4` at 741efd7: 700 passed, 0 failed, 41 ignored (the same 700 as on the RX 9060 XT). - SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. Same as `main` 508a0c7. **Not tested** - The shader-pack counts (no retail shader pack here). **AI use** - Claude Code (Claude Opus 5.5) ran the suite and wrote this report; checked by me.
Author
Owner

@⁠tugasky on GitHub · 2026-11-24 02:12 UTC · original

Same harness as the #517 census, run again on this stack, so the numbers below are a
delta over the same 13 210 programs of the same retail pack, not a separate sample.

Machine: Windows 11 Pro 26300, Ryzen 7 9700X (8C/16T), Rust 1.98.0
x86_64-pc-windows-msvc, DXC 1.9.2602.17, Radeon RX 9070 XT (RDNA4, 16 GB), driver
32.0.32029.2010. Release build, 741efd7 merged into 7ebf1b8 (the stack's base is
a6f5f7a, three commits behind main; the merge touches only README and
title_textures.rs, so partition.rs is the PR's).

stage Exact with #517 Exact with #528 MayDiffer stale-scalar slowest program
PS 7 248 6 620 (60.3 %) 4 354 2 416 82.2 ms
VS 2 176 2 147 (96.0 %) 89 52 48.7 ms
total 9 424 8 767 (66.4 %) 4 443 2 468 82.2 ms

Your 8 767 / 6 620 / 2 147 and stale-scalar in 2 468 programs come out here exactly.
13 034 distinct programs still, 8 598 distinct Exact (was 9 255), so the 657 newly gated
programs are 657 distinct ones – no program is counted twice in that drop. No panic,
0 undecoded dwords, 0 no-graph.

What the 657 cost, attributed. 447 of them (68.0 %) are gated by stale-scalar alone
(442 PS + 5 VS). The other 210 carry stale-scalar+tainted-exec and nothing else
(186 PS + 24 VS), which is the rule doing what it should: the stale scalar also reaches
EXEC or a branch, so control is tainted too. That accounts for the second finding –
tainted-exec is the only other reason that moves, 2 215 → 2 612 (+397): 210 are those
newly gated programs, the remaining 187 are programs that were already MayDiffer and
whose stale scalar now also taints control. Every other reason is unchanged to the
program: cross-lane 2 473, vote-branch 1 817, unsafe-execz-branch 1 443,
mask-data 619, lane-count 432, first-lane 353, lane-id 186. So the rule is
purely additive on this corpus, and its cost is 657 programs, not 2 468 – the other
2 011 already differed for another reason.

Order of the remaining parts of #336 is now measurable the same way (programs whose
only reason is this one): unsafe-execz-branch 744, then stale-scalar 447 (the ones
this PR adds), vote-branch 206, cross-lane 150, lane-count 40, mask-data 6. The
EXECZ/EXECNZ rule is still first.

Cost: 65.2 s of classify time over the 13 210 programs, against 24.6 s and 26.8 s in
two runs of #517 alone on this machine (mean 4.9 ms, slowest program 82.2 ms; your machine
reports 99 ms). Fine for a census, and worth knowing before anything calls this on a
title's path.

Suite: cargo build --workspace --release, then
cargo test --workspace --release -- --test-threads=4 → 701 passed, 0 failed, 41
ignored
, no test skipped (your 700 plus the one test #486 adds on main). The 17
partition::tests pass on their own as well.

Not tested (same as you): whether the flagged programs actually differ on a 32-lane
GPU, and NVIDIA.

No game data in this comment – only counts printed by the tool.

AI use: written with Cline; the runs are from my machine.

**@⁠tugasky** on GitHub · 2026-11-24 02:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/528#issuecomment-7119871196) Same harness as the #517 census, run again on this stack, so the numbers below are a delta over the same 13 210 programs of the same retail pack, not a separate sample. **Machine:** Windows 11 Pro 26300, Ryzen 7 9700X (8C/16T), Rust 1.98.0 `x86_64-pc-windows-msvc`, DXC 1.9.2602.17, Radeon RX 9070 XT (RDNA4, 16 GB), driver 32.0.32029.2010. Release build, `741efd7` merged into `7ebf1b8` (the stack's base is a6f5f7a, three commits behind `main`; the merge touches only README and `title_textures.rs`, so `partition.rs` is the PR's). | stage | Exact with #517 | Exact with #528 | MayDiffer | `stale-scalar` | slowest program | |:--|--:|--:|--:|--:|--:| | PS | 7 248 | **6 620** (60.3 %) | 4 354 | 2 416 | 82.2 ms | | VS | 2 176 | **2 147** (96.0 %) | 89 | 52 | 48.7 ms | | total | 9 424 | **8 767** (66.4 %) | 4 443 | 2 468 | 82.2 ms | Your 8 767 / 6 620 / 2 147 and `stale-scalar` in 2 468 programs come out here exactly. 13 034 distinct programs still, 8 598 distinct Exact (was 9 255), so the 657 newly gated programs are 657 *distinct* ones – no program is counted twice in that drop. No panic, 0 undecoded dwords, 0 `no-graph`. **What the 657 cost, attributed.** 447 of them (68.0 %) are gated by `stale-scalar` alone (442 PS + 5 VS). The other 210 carry `stale-scalar+tainted-exec` and nothing else (186 PS + 24 VS), which is the rule doing what it should: the stale scalar also reaches EXEC or a branch, so control is tainted too. That accounts for the second finding – `tainted-exec` is the only other reason that moves, 2 215 → 2 612 (+397): 210 are those newly gated programs, the remaining 187 are programs that were already MayDiffer and whose stale scalar now also taints control. Every other reason is unchanged to the program: `cross-lane` 2 473, `vote-branch` 1 817, `unsafe-execz-branch` 1 443, `mask-data` 619, `lane-count` 432, `first-lane` 353, `lane-id` 186. So the rule is purely additive on this corpus, and its cost is 657 programs, not 2 468 – the other 2 011 already differed for another reason. **Order of the remaining parts of #336** is now measurable the same way (programs whose only reason is this one): `unsafe-execz-branch` 744, then `stale-scalar` 447 (the ones this PR adds), `vote-branch` 206, `cross-lane` 150, `lane-count` 40, `mask-data` 6. The EXECZ/EXECNZ rule is still first. **Cost:** 65.2 s of classify time over the 13 210 programs, against 24.6 s and 26.8 s in two runs of #517 alone on this machine (mean 4.9 ms, slowest program 82.2 ms; your machine reports 99 ms). Fine for a census, and worth knowing before anything calls this on a title's path. **Suite:** `cargo build --workspace --release`, then `cargo test --workspace --release -- --test-threads=4` → **701 passed, 0 failed, 41 ignored**, no test skipped (your 700 plus the one test #486 adds on `main`). The 17 `partition::tests` pass on their own as well. **Not tested (same as you):** whether the flagged programs actually differ on a 32-lane GPU, and NVIDIA. No game data in this comment – only counts printed by the tool. **AI use:** written with Cline; the runs are from my machine.
Author
Owner

@⁠emirduran707 on GitHub · 2026-11-24 02:26 UTC · original

Folded into #517 (ad4add0) after its review: leaving the stale-scalar rule to a later PR made #517 report Exact for programs that differ.

AI use: Claude Code with Claude Opus 5.5 wrote this note.

**@⁠emirduran707** on GitHub · 2026-11-24 02:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/528#issuecomment-7120137191) Folded into #517 (ad4add0) after its review: leaving the stale-scalar rule to a later PR made #517 report Exact for programs that differ. AI use: Claude Code with Claude Opus 5.5 wrote this note.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.