Skip to content

Recompiler: split wave64 halves skip the exchange at local votes and uniform first-lane reads - #3563

Open
Royalflamejlh wants to merge 3 commits into
xcl-dev:mainfrom
Royalflamejlh:recompiler/wave64-idioms
Open

Royalflamejlh wants to merge 3 commits into
xcl-dev:mainfrom
Royalflamejlh:recompiler/wave64-idioms

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

A split wave64 compute or mesh program on a GPU with 32-lane waves only meets its other half at every mask read whole and every v_readfirstlane. Three recognised cases now need no meeting. Over the wave64 compute and mesh programs of one retail pack without LDS (9,074 programs), the places where the halves meet went from 217,578 to 112,237. That is a static count of sites, not GPU time, and it was taken on a tree that carries this change beside other unmerged pull requests, not on this branch. #3114 measures the exchange at 2.6x a program's GPU time.

The three commits can be three pull requests (the first stands alone, the other two need it) if that is easier to review.

What is in it (crates/xcl/src/gpu/dxil/idioms.rs, new, 677 lines with tests; direct translator only)

  • Local vote. A forward s_cbranch_execz that only skips per-lane work reads each half's own word of EXEC, so the compare behind it stays in its half. It holds when the skipped side has only per-lane work under EXEC, scalar arithmetic, non-coherent scalar loads or mesh exports; no lane read or write, LDS, barrier or message; no exchanged mask; forward branches that stay inside; EXEC within the EXEC at the branch; and no SGPR written there that is read after it.
  • Uniform first lane. v_readfirstlane of a value made, in the same block and after the last EXEC write, by plain VALU on scalars: each half reads its own first running lane when both halves have one; otherwise the exchange runs as before.
  • Scalar constants. s_movk_i32, s_cmovk_i32, s_addk_i32, s_mulk_i32 and s_cmpk_* were taken to read every register, which forced an exchange on any compare before them.
  • XCL_WAVE64_IDIOMS=0 turns all three off and is part of the translated cache's identity. Kernel::exchange_sites counts the sites.

848 changed lines (825 added) in three commits of 528, 242 and 57 added lines, each a form of its own that the others do not need; about a third of each is tests.

Tested

  • RTX 4060 Ti 16 GB, NVIDIA 615.71.09, AMD Ryzen 9 9950X3D, Linux, Wine 11.21 Staging, vkd3d-proton master with local patches, x86_64-pc-windows-gnu, release. Head 8a02160af (bmjask's three review points fixed; idioms mask_exchange shaders:: pso:: 151 passed, 0 failed, 2 ignored, 17 SKIPPED; gpu::dxil 316 passed, 1 failed (directed_reference_basics, which fails on main under Wine), 4 ignored; the GPU tests not rerun on this head). The results below are of f0e1c97f3, on main 493dbd3d.
  • cargo test -p xcl --release --lib gpu::dxil -- --test-threads=2: 314 passed, 1 failed, 4 ignored. SKIPPED: dispatch_chain_native_wave64_builds_whole (no wave64). The failure is round_tests::directed_reference_basics, which fails the same way on main.
  • On the GPU: gpu_split_wave64_local_votes_leave_what_the_exchange_leaves and gpu_split_wave64_uniform_first_lanes_read_what_the_exchange_reads passed (groups of 32, 48, 64, 96 and 128 threads; idioms on against off, and against the console's values). Both are compute programs: the votes also apply to mesh programs, which no GPU test here covers.
  • Site counts on the test programs: 4 to 1, and 12 to 6. Each recogniser has a test with near-misses it refuses, among them a value that depends on a per-lane mask it does not name (v_div_fmas, a carry-in whose carry-out goes nowhere, v_dot2c / v_dot4c, a 16-bit result).
  • A retail title, on another tree that carries these commits beside other unmerged pull requests: 1 run, 855 s, no crash, no device removal. That run had XCL_GPU_PROFILE=1, which makes a queue run its draws and dispatches one after the other; on a later head of that tree the title lost its device at the world start without the switch (2 of 2 runs, with folding on and with it off) and ran 600 s with it (1 of 1), so the run says nothing about this change with the GPU's work overlapping.
  • Native Windows, by AAsobu (report below; RTX 3090 24 GB, driver 621.24, this head against main 493dbd3d, a retail title in its world, 2 measured runs of 420 s each): no device removal, and no change in presents, draws or dispatches per 2 s outside the spread of two runs of one build. The suite was not run there.

Regression run

  • None yet: no Windows machine was reachable. The two xcl-smoke blocks are still owed.

Not tested

  • Native Windows, AMD, any other NVIDIA card, the whole suite, a title from this branch, bench_split_wave64.
  • A removed exchange was also a point that ordered one half's global-memory writes before the other's later reads; the existing lane-by-lane masks have the same property (docs/wave64-on-wave32.md, "What is not exact").
  • The uniform read under a dispatch's thread limits.
  • Recompiler: skip split-wave64 v_readfirstlane_b32 exchanges for wave-uniform VGPRs #1193 does the uniform first-lane read on the HLSL path; it shares no file with this.

AI use

  • Claude Code. Claude Fable 5.2 wrote the code, the tests and this description. Claude Opus 5.5 wrote the stricter uniform-source check and its tests (squashed into 25590d0ee).

@github-actions github-actions Bot added area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head edc0e4e, diff read, not a merge-check; draft with PR description red, so not built or run here):

  • idioms.rs ~207-209: the uniform-value check only looks at v_cndmask's mask, so an instruction with a hidden per-lane VCC input (e.g. v_div_fmas_f32 with scalar operands under a VCC that differs per lane) is taken as uniform, and the halves could then read a different first lane than the console. Rare in compiler output, but worth refusing implicit-VCC instructions.
  • Local votes also apply to mesh programs (exports allowed on the skipped side, ~77), but the GPU tests cover compute only.
  • 805 lines; splitting along the three commits as offered would help (the SOPK commit stands alone).
  • Still owed: both xcl-smoke blocks (why PR description fails), the whole suite on native Windows, and AMD. The exchange counts are static site counts from a tree with other PRs in it, not GPU time. dxil: batch consecutive v_readfirstlane/v_readlane exchanges in split-wave64 #2343 batches the same direct-path v_readfirstlane exchange and conflicts in compact.rs / kernel.rs; Recompiler: skip split-wave64 v_readfirstlane_b32 exchanges for wave-uniform VGPRs #1193 does the uniform first-lane read on the HLSL path.

Fine: the fixed-point retraction of non-local votes, the EXEC-within-branch tracking, the s_or_b64 exec, exec, s restore (every path keeps EXEC inside s), both halves entering the fallback together, and the SOPK change (x64_masks already treats s_addk / s_mulk / s_cmovk as read-modify-write). On by default with XCL_WAVE64_IDIOMS=0 to turn it off; merges cleanly with main and #3504.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

Thanks. The v_div_fmas point is right, and it was not the only one: a carry-in whose carry-out goes to null, v_dot2c / v_dot4c (they add to their destination) and 16-bit results (they keep the other half of theirs) also passed as uniform. The check now takes every mask input from the operand table and counts those destinations as operands, and each case has a near-miss test. It is squashed into the second commit; the branch is rebased onto main 493dbd3d, head f0e1c97f3.

gpu::dxil on it, RTX 4060 Ti under Wine: 314 passed, 1 failed (directed_reference_basics, as on main), 4 ignored; both GPU tests of the idioms passed.

Still true: the votes apply to mesh programs and the GPU tests are compute only (now said under Tested). I can open the three commits as three pull requests if that is wanted.

AI use: Claude Code. Claude Opus 5.5 checked the point and wrote the change; Claude Fable 5.2 ran the tests on the card and wrote this reply.

@Royalflamejlh
Royalflamejlh marked this pull request as ready for review December 1, 2026 08:05
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Re-review (head f0e1c97, diff read, not a merge-check: PR description still fails (no xcl-smoke blocks), so not built or run here). Follow-up to my review of edc0e4e.

  • Uniform-value check: fixed. idioms.rs ~203 / ~207 now require every lane-mask input (v_cndmask, carry-in, v_div_fmas's VCC) to cover all of EXEC's lanes and count accumulator (*MAC*, v_dot2c / v_dot4c) and 16-bit destinations as inputs. I checked this against every VALU encoding in rdna2_spec.rs and found no mask input it misses; the near-miss tests cover each case.
  • Still open: the smoke pair (main and this head), a Windows run of the whole suite, AMD coverage, and a GPU test of local votes on mesh programs. The description still says the blocks are owed "before this leaves draft", but the PR is no longer a draft.
  • 812 lines, just over the ~800 rule, and the description says it could be three PRs.
  • AI use names only Claude Fable 5.2, while 22e2f91 carries an Opus 5.5 trailer.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head f0e1c97

No open or merged PR makes the same change on the direct DXIL path. #1193 skips uniform v_readfirstlane exchanges on the HLSL path (recomp/x64_uniform.rs), and #2343 batches consecutive v_readfirstlane/v_readlane exchanges in dxil/lower_valu.rs instead of skipping them; both are different changes, though #2343 touches the same lowering and may conflict.
No concrete problem found in idioms.rs / mask_exchange.rs: uniform_reads excludes loads, MBCNT, cross-lane ops and SDWA/DPP forms, the fallback exchange in read_first_lane_uniform is entered by both halves on the same condition, and the compact-form key includes uniform_reads.
The PR description check fails because the two xcl-smoke blocks are missing, and at ~790 lines the three commits would be easier to review as the three PRs the description offers.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@AAsobu

AAsobu commented Dec 1, 2026

Copy link
Copy Markdown

Test report on head f0e1c97f (on main 493dbd3d), retail title in the world, NVIDIA wave32. Not a merge-check: the test suite was not run.

Setup: release builds of main 493dbd3d (A) and this head as is (B; XCL_WAVE64_IDIOMS unset, so on), xcl.exe with the #2590 profile at 2048 MB. Env: XCL_PREPARE=0 XCL_DIRECT_DXIL=1 XCL_DXC_THREADS=4 XCL_NETWORK=0 XCL_DRED=1 XCL_ACTIVITY=1 XCL_PSO_WAIT_MS=1000 XCL_TEXTURE_LEVEL_PAGES=1 XCL_HUGE_PSO_CONCURRENCY=4 XCL_HUGE_PSO_WANTED_CONCURRENCY=4, start prompt by XCL_PRESS_A_AT, no input. Runs of 420 s in the order B, A, B, A, B; the first B run only warmed this head's translated and driver caches (its source hash gives it a cache of its own) and is left out. Measured from world entry (first two-pass mesh dispatch) + 30 s to the end.

A1 B1 A2 B2
world entry 150 s 147 s 119 s 155 s
presents per 2 s 1.07 1.09 1.10 1.03
draws per 2 s 4482 4616 4832 4433
dispatches per 2 s 5434 5528 5928 5490
2 s windows with no present 10 % 12 % 7 % 14 %
process CPU (cores busy) 8.0 8.6 5.3 7.8
peak process commit, MB 43,326 41,187 43,751 42,351
peak VRAM, MB 17,057 16,680 17,528 17,101
skipped draws (whole run) 0 73 0 0
device removals 0 0 0 0
  • No frame-rate change on this title and card: 1.09 / 1.03 presents per 2 s against 1.07 / 1.10, within the spread of two runs of one build. Draws and dispatches per 2 s, CPU and memory are within that spread too.
  • B1 still finished a few pipelines (73 draws skipped while they were built); B2 skipped none.
  • Nothing changed on screen, as expected for this change, and no device removal in any of the five runs.
  • What I cannot tell from these logs: how many of the exchange sites this head removes are in the programs this title spends its GPU time on in this part of the world (the idioms apply only to programs without LDS), or the GPU time of those programs.

hardware / tool and model: NVIDIA GeForce RTX 3090 24 GB (driver 621.24, wave32 only), Intel Core i5-10600K, 32 GB, Windows 11 Home build 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5), numbers from the logs checked by me

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of f0e1c97f: 3 finding(s). 1 are inline. These are on lines outside the diff:

crates/xcl/src/shaders.rs:35: XCL_WAVE64_IDIOMS isn't in semantic_pipeline_setting, and on the HLSL backend pso.rs:379 also leaves the tag out of the translated identity. A run with XCL_WAVE64_IDIOMS=0 keeps the same warm_settings_key() / translation_cache_identity(), so a warm pipeline library built with the idioms on is reused for a run that turns them off.

crates/xcl/src/gpu/dxil/mask_exchange.rs:65: s_cmpk_* and s_addk_i32 write SCC when lowered (lower.rs ~1278-1297), but uses() only kills SCC demand for names starting with S_CMP_, and S_CMPK_EQ_I32 doesn't match. In v_cmp vcc; s_and_saveexec_b64 s4, vcc; ...; s_cmpk_eq_i32 s5, 7; s_cbranch_scc1, the branch's SCC demand passes the S_CMPK, reaches the saveexec, and vcc gets exchanged even with the idioms on. Adding S_CMPK_ and S_ADDK_I32 to the SCC-kill list fixes it.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

}

/// SOPK instructions that read and write what their operands say, no more.
pub(super) fn plain_sopk(name: &str) -> bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plain_sopk leaves out S_WAITCNT_VSCNT, S_WAITCNT_VMCNT/LGKMCNT/EXPCNT and S_VERSION. They lower to no-ops but uses() still treats them as reading every register (read: !0). s_waitcnt_vscnt null, 0 is very common after stores, so any local vote whose skipped side contains one is taken back. Separately, lane_work lists S_WAITCNT_VSCNT under ENC_SOPP, where it can never match because it's SOPK.

Royalflamejlh and others added 3 commits December 1, 2026 13:20
A forward s_cbranch_execz over per-lane work reads each half's own word of
EXEC, so the compare behind it is not exchanged (gpu/dxil/idioms.rs, the
conditions in docs/wave64-on-wave32.md, "Idioms"); s_or_b64 exec, exec, s
at its target gives the saved EXEC without asking for EXEC whole.
XCL_WAVE64_IDIOMS=0 turns it off and tags the translated cache and the warm
pipeline library's settings.
Kernel::exchange_sites counts where the halves meet in a translation.

On a retail pack's 9 442 distinct wave64 compute and mesh programs
(retail_wave64_compute_exchange_census): 157 393 exchanged compares
before, 114 214 with the votes.

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

v_readfirstlane of a value every lane of EXEC holds (scalar arithmetic the
compiler does in a VGPR) is the same in each half's first running lane of
EXEC: the halves exchange it only when one of them has no such lane
(idioms::uniform_reads, Lw::read_first_lane_uniform; the rule in
docs/wave64-on-wave32.md). Kernel::exchange_sites leaves that exchange out.
A lane mask an instruction reads (v_cndmask_b32's, a carry in, v_div_fmas'
VCC) has to have one bit for all of EXEC's lanes, and the destination an
accumulator or a 16-bit result keeps part of counts as an operand.

In the same pack's programs 38 702 of 57 884 v_readfirstlane are such reads.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
s_movk_i32, s_cmovk_i32, s_addk_i32, s_mulk_i32 and s_cmpk_* read and write
the registers they name, s_waitcnt_*cnt and s_version none; s_cmpk_* and
s_addk_i32 replace SCC. The split form's mask demand took every SOPK
instruction for one that may read any register, so a compare before any of
them was exchanged: 114 214 exchanged compares in the pack's wave64 compute
and mesh programs, 90 743 without that. Under XCL_WAVE64_IDIOMS as the
other idioms.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh force-pushed the recompiler/wave64-idioms branch from f0e1c97 to 8a02160 Compare December 1, 2026 20:46
@github-actions github-actions Bot added the area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation label Dec 1, 2026
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@bmjask thank you, all three hold; fixed at 8a02160af.

  1. Partly: the direct backend's identity and the entries the HLSL backend sends to the direct translator already carried the tag; the warm pipeline library's settings key did not. XCL_WAVE64_IDIOMS is now a warm setting, tested on both backends (warm_settings_keep_the_wave64_idioms_switch_on_both_backends).
  2. Yes: s_cmpk_* and s_addk_i32 now replace SCC in the demand (mask_exchange.rs:65), tested with your sequence (split_wave64_scalar_constant_compares_replace_scc).
  3. Yes: the four s_waitcnt_*cnt and s_version are plain SOPK now, and the SOPP entry that could not match is gone; a vote over s_waitcnt_vscnt null, 0 stays local (a_vote_over_a_wait_stays_in_each_half). Exchanged compares in the pack: 90,754 to 90,743.

The same check found XCL_WAVE64_FOLD (#3562) and XCL_WAVE64_LANE_LOOP (#3561) missing from the warm settings too; both fixed there.

AI use: Claude Code (Claude Opus 5.5) checked each point, wrote the fixes and tests, and drafted this reply.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up review (head 8a02160, since f0e1c97, diff read, not a merge-check; checks red):

  • Uniform-value check: fixed, unchanged since f0e1c97f.
  • Smoke pair, whole suite on native Windows, AMD: still open. Regression run says "None yet" (the reason PR description is red); Tested has only filtered runs under Wine; AMD is still under Not tested.
  • GPU test of local votes on mesh programs: still open. Votes still apply to mesh programs and both GPU tests are compute only.
  • Size: still open. Now 848 changed lines, over ~800, and the description says it could be three PRs rather than why it cannot; its "786 added lines in three commits (519, 235 and 32)" is out of date (now 528, 242, 57).
  • Draft wording and AI use: fixed. AI use names both models, though it still points at 22e2f916, which is no longer on the branch.

New: none.

Fine: S_CMPK_* and S_ADDK_I32 now kill SCC demand in mask_exchange.rs ~65, which is right because lower.rs ~1278-1297 sets SCC every time for both; S_WAITCNT_*CNT and S_VERSION are plain SOPK (idioms.rs ~38) and lower to nothing; with XCL_WAVE64_IDIOMS=0 every SOPK stays opaque; XCL_WAVE64_IDIOMS is now a warm setting, tested on both backends; each fix has a test.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

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

Labels

area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants