Recompiler: split wave64 halves skip the exchange at local votes and uniform first-lane reads #3563
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3563"
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 Royalflamejlh on 2026-12-01T06:34:35Z.
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)s_cbranch_execzthat 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.v_readfirstlaneof 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.s_movk_i32,s_cmovk_i32,s_addk_i32,s_mulk_i32ands_cmpk_*were taken to read every register, which forced an exchange on any compare before them.XCL_WAVE64_IDIOMS=0turns all three off and is part of the translated cache's identity.Kernel::exchange_sitescounts 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
x86_64-pc-windows-gnu, release. Head8a02160af(bmjask's three review points fixed;idioms mask_exchange shaders:: pso::151 passed, 0 failed, 2 ignored, 17 SKIPPED;gpu::dxil316 passed, 1 failed (directed_reference_basics, which fails onmainunder Wine), 4 ignored; the GPU tests not rerun on this head). The results below are off0e1c97f3, onmain493dbd3d.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 isround_tests::directed_reference_basics, which fails the same way onmain.gpu_split_wave64_local_votes_leave_what_the_exchange_leavesandgpu_split_wave64_uniform_first_lanes_read_what_the_exchange_readspassed (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.v_div_fmas, a carry-in whose carry-out goes nowhere,v_dot2c/v_dot4c, a 16-bit result).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.main493dbd3d, 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
RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
bench_split_wave64.docs/wave64-on-wave32.md, "What is not exact").AI use
25590d0ee).Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:11:43Z.
Review (head
edc0e4e7, diff read, not a merge-check; draft withPR descriptionred, so not built or run here):idioms.rs~207-209: the uniform-value check only looks atv_cndmask's mask, so an instruction with a hidden per-lane VCC input (e.g.v_div_fmas_f32with 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.PR descriptionfails), 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. #2343 batches the same direct-pathv_readfirstlaneexchange and conflicts incompact.rs/kernel.rs; #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, srestore (every path keeps EXEC insides), both halves entering the fallback together, and the SOPK change (x64_masks already treatss_addk/s_mulk/s_cmovkas read-modify-write). On by default withXCL_WAVE64_IDIOMS=0to 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.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T08:05:01Z.
Thanks. The
v_div_fmaspoint 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 ontomain493dbd3d, headf0e1c97f3.gpu::dxilon it, RTX 4060 Ti under Wine: 314 passed, 1 failed (directed_reference_basics, as onmain), 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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:18:34Z.
Re-review (head
f0e1c97f, diff read, not a merge-check:PR descriptionstill fails (no xcl-smoke blocks), so not built or run here). Follow-up to my review ofedc0e4e7.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 inrdna2_spec.rsand found no mask input it misses; the near-miss tests cover each case.22e2f916carries an Opus 5.5 trailer.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:17:18Z.
Triage (#1607) – head
f0e1c97No 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.
Imported from ivall/xcl. Originally posted by AAsobu on 2026-12-01T12:19:24Z.
Test report on head
f0e1c97f(onmain493dbd3d), retail title in the world, NVIDIA wave32. Not a merge-check: the test suite was not run.Setup: release builds of
main493dbd3d(A) and this head as is (B;XCL_WAVE64_IDIOMSunset, so on),xcl.exewith 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 byXCL_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.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
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:01:44Z.
Code review location:
crates/xcl/src/gpu/dxil/idioms.rs; line 37plain_sopkleaves outS_WAITCNT_VSCNT,S_WAITCNT_VMCNT/LGKMCNT/EXPCNTandS_VERSION. They lower to no-ops butuses()still treats them as reading every register (read: !0).s_waitcnt_vscnt null, 0is very common after stores, so any local vote whose skipped side contains one is taken back. Separately,lane_worklistsS_WAITCNT_VSCNTunder ENC_SOPP, where it can never match because it's SOPK.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:01:44Z.
Review: COMMENTED
Review of
f0e1c97f: 3 finding(s). 1 are inline. These are on lines outside the diff:crates/xcl/src/shaders.rs:35:XCL_WAVE64_IDIOMSisn't insemantic_pipeline_setting, and on the HLSL backendpso.rs:379also leaves the tag out of the translated identity. A run withXCL_WAVE64_IDIOMS=0keeps the samewarm_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_*ands_addk_i32write SCC when lowered (lower.rs~1278-1297), butuses()only kills SCC demand for names starting withS_CMP_, andS_CMPK_EQ_I32doesn't match. Inv_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, andvccgets exchanged even with the idioms on. AddingS_CMPK_andS_ADDK_I32to 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.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T20:47:08Z.
@bmjask thank you, all three hold; fixed at
8a02160af.XCL_WAVE64_IDIOMSis now a warm setting, tested on both backends (warm_settings_keep_the_wave64_idioms_switch_on_both_backends).s_cmpk_*ands_addk_i32now replace SCC in the demand (mask_exchange.rs:65), tested with your sequence (split_wave64_scalar_constant_compares_replace_scc).s_waitcnt_*cntands_versionare plain SOPK now, and the SOPP entry that could not match is gone; a vote overs_waitcnt_vscnt null, 0stays 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) andXCL_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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:14:03Z.
Follow-up review (head
8a02160a, sincef0e1c97, diff read, not a merge-check; checks red):f0e1c97f.PR descriptionis red); Tested has only filtered runs under Wine; AMD is still under Not tested.22e2f916, which is no longer on the branch.New: none.
Fine:
S_CMPK_*andS_ADDK_I32now kill SCC demand inmask_exchange.rs~65, which is right becauselower.rs~1278-1297 sets SCC every time for both;S_WAITCNT_*CNTandS_VERSIONare plain SOPK (idioms.rs~38) and lower to nothing; withXCL_WAVE64_IDIOMS=0every SOPK stays opaque;XCL_WAVE64_IDIOMSis 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.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T11:25:01Z.
merge-check
base:
1c8b551475head:
8a02160af1merge: clean (trial-merge commit 7976c6617b74c8f100cd232947fcba424dc5d1e8, git diff --check clean)
build: cargo build --workspace ok; cargo build --release -p xcl ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture (43 targets): 2919 passed, 1 failed, 52 ignored (+11 new runnable tests and +1 ignored census test vs main baseline 2908/1/51). All 11 new runnable tests passed with 0 skips on RTX 4060 (wave32), including both live GPU equivalence tests (gpu::dxil::idioms::tests::gpu_split_wave64_local_votes_leave_what_the_exchange_leaves and gpu_split_wave64_uniform_first_lanes_read_what_the_exchange_reads), all 7 idioms unit tests, gpu::dxil::mask_exchange::tests::split_wave64_scalar_constant_compares_replace_scc, and shaders::warm_settings_keep_the_wave64_idioms_switch_on_both_backends. The single failure is the pre-existing Issue #3441 flake in tests/gpu_two_pass_cache_e2e.rs::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (line 584, left: 1, right: 0), reproduced identically on clean base
1c8b5514and unrelated to split-wave64 idioms. 28 SKIPPED lines (host environment only: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache (Windows Developer Mode required)).review: Read the full merged diff (+825/-23 across 10 files: gpu/dxil/{idioms.rs,mask_exchange.rs,kernel.rs,compact.rs,lanes.rs,lower.rs,lower_valu.rs,mod.rs}, shaders.rs, and docs/wave64-on-wave32.md). Strictly scoped to split-wave64 compute/mesh shaders without LDS (guarded by
mask_exchange::planinkernel.rs), with opt-outXCL_WAVE64_IDIOMS=0wired into both the DXIL cache tag (compact_nest_tag) and warm pipeline settings hash (semantic_pipeline_setting), anduniform_reads.contains(&d.pc)included in thecompact.rsinstruction key. Checked soundness of all four idioms: (1) local forwards_cbranch_execzvotes reject external entries, backward/escaping branches, cross-lane/LDS/barrier/coherent-SMEM/relative ops, live scalar writes, and any vote whose skipped compares get exchanged or whose EXEC write is read whole at the join; (2)empty_afterinductively preservess[r..r+2] ⊆ E_0 ⊆ saved_exec, sos_or_b64 exec, exec, savedat the join (info[end].inputs &= !EXEC) exact-restores full EXEC (and SCC) in both halves even if a vote is retracted; (3)uniform_readsrestricts uniform VGPRs to single-block plain VALU ops excluding cross-lane/rank/relative/SDWA/DPP ops and treating MAC/DOT2C/DOT4C/16-bit-VDST ops (verified againstrdna2_spec.rs) as RMW, whileread_first_lane_uniformevaluates the identicallonepredicate in both halves so both halves enter the exchange fallback together whenever either half has zero active lanes; (4)plain_sopkmarks side-effect-free SOPK ops non-opaque and kills SCC onS_CMPK_*/S_ADDK_I32. No scope creep, deadlock risk, or UB.performance: 60 s retail smoke (title: 29640639, ON by default on RTX 4060 wave32): 1626 frames (+11.2% vs
1c8b5514baseline 1462 frames), 15191 MB peak commit (-5.3% vs 16043 MB baseline), 0 device removals, 0 crashes.verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:11:08Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T14:33:09Z.
Closing: this landed through #3655, which was stacked on it.
git cherry origin/mainshows all three of this PR's commits inmainunchanged sinced71578f8. Thanks to everyone who reviewed and merge-checked it.AI use: Claude Code (Claude Opus 5.5) checked the commits and wrote this comment.
Pull request closed