Recompiler: fix per-lane cross-lane mask lowering bugs #2118
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2128"
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 Decodere on 2026-11-25T05:27:32Z.
What is in it
Fixes four per-lane cross-lane wave lowering bugs in
crates/xcl/src/gpu/recomp/lower/wave.rs:V_MBCNT_HI_U32_B32half-wave ballot and mask addend (wave_valu):hi_halfwas unconditionallytrueforV_MBCNT_HI_U32_B32, callingballot_halfeven whenSRC0was the lower dword of a wave64 mask (e.g.vcc_loorexec_lo), which left lanes32..63reading their own half's ballot instead of lanes0..31's bits.hi_halfis now only set whenSRC0is the upper dword of a wave64 mask pair (matches!(self.mask_reg(b, s0), Some((_, true)))).SRC1is also now read viaself.word(b, d, s1)?instead ofself.src(...), so a mask SGPR can be used as the addend.words,wave_salu): In wave32, masks are single 32-bit SGPRs, so a 64-bit operands[r:r+1](rin0..=106, includingvcc_lo/vcc_hi) can hold a mask inrwith an independent scalar number inr+1, or a number inrwith a mask inr+1. Previouslywords()zeroed the upper dword wheneverrheld a mask, andwave_salu()skipped instructions where onlyr+1held a mask (causing the fallback path to fail with"a mask read as a number").words()now lowers wave320..=106pairs dword-by-dword viaword(), andwave_salu()checkss0 + 1in wave32_B64mask counts while keepingEXEC(126) mapped to[ballot(exec), 0].V_READFIRSTLANE_B32andV_READLANE_B32maskSRC0(wave_valu): Both instructions readSRC0viaself.src(b, d, s0)?, rejecting mask SGPRs (such asvcc_lo), unlikeV_WRITELANE_B32which already usedself.word(b, d, s0)?. Both now useself.word(b, d, s0)?.MaskOp::Bcntstale-SCC tracking (wave_salu):S_BCNT{0,1}_I32_B{32,64}wroteSCCvia rawself.ssa.write(b, Var::Scc, c)instead ofself.write_scc(b, c), bypassingown()so a staleSCCwritten inside a partial block and read after a lane join was not detected or refused. It now callsself.write_scc(b, c).Adds five regression tests in
gpu::recomp::lower::wave::tests: four deterministic CPU tests covering all four bugs plus a WARP-guarded GPU parity test (gpu_wave_fixes_agree_with_hlsl) comparing per-lane direct DXIL against HLSL on both split-wave64 and wave32.Part of #1269
Tested
Hardware/toolchain: Windows 11 (26200), NVIDIA GeForce RTX 4060 (32-lane waves, driver 621.14), DXC
1.9.2609.5 (01b62ad4), Rust1.100.0.s106: a mask read as a number,unsupported S_BCNT1_I32_B64 (s5: a mask read as a number), wrong upper-half counts / zeroed high SGPR, and unrefused staleSCC).cargo test --release -p xcl --lib gpu::recomp::lower::wave::tests:: -- --nocapture --test-threads=1on RTX 4060: 5 passed, 0 failed, 0 ignored (0 skipped;gpu_wave_fixes_agree_with_hlslran on GPU for split-wave64mbcnt_hi_low_maskand wave32wave32_b64_mixed_mask/readlane_of_mask).XCL_ADAPTER="Microsoft Basic Render Driver"andXCL_ADAPTER=warp) ongpu::recomp::lower::wave::tests::: 5 passed, 0 failed, 0 ignored (4 CPU tests passed;gpu_wave_fixes_agree_with_hlslcleanly reportedSKIPPED ...: no GPU with 32-lane waves).cargo build --release --workspace: exit 0.cargo test --release --workspace -- --test-threads=4: 1159 passed, 0 failed, 46 ignored across 21 test suites, with 25 pre-existing runtimeSKIPPEDlines (23 native wave64 / unsupported per-lane lowering skips on 32-lane RTX 4060, 1 Windows driver-cache skip, 1 heap-window skip; 0 new skips).Regression run
Paired 60-second
scripts/smoke.ps1runs on the same retail title build (29640639) from cleanorigin/main(6020a33) and this branch (9e08a5a):Base (
origin/main):PR (
fix-1269-perlane-wave-bugs):Not tested
V_MBCNT_HI_U32_B32was verified on both the CPU interpreter and the RTX 4060 GPU against HLSL).AI use
Drafted with Google Antigravity (Gemini 4 Neon) and verified locally by reproducing failures before the fix, checking CPU and RTX 4060 GPU parity against HLSL, checking WARP adapter skips, running the full release workspace test suite, and completing the paired 60-second smoke run above.
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T05:51:05Z.
Tested:
gpu_wave_fixes_agree_with_hlslpasses on an AMD D3D12 driver and on an RTX 3060.gpu::filter: 589 passed, 2 failed, 22 ignored. The 2 failures are the AMD fuzz seeds 722 and 1599 tracked in #2115, which fail the same way onmain.Head
9e08a5aapplied onmain6e1e2be,cargo test -p xcl --lib -- gpu:: --test-threads=4withXCL_ADAPTERset to each card.The test's wave64 cases use the split form (
kernel_split,split_wave64: true), so even on the 9070 XT they do not run in native 64-lane waves. This is an AMD driver result, not the native wave64 check the PR lists as untested.Not tested: native wave64 per-lane, retail runs.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-25T06:12:09Z.
A run with vkd3d-proton as the host D3D12. The DXIL goes through dxil-spirv and then the NVIDIA Vulkan driver, not the native-Windows path: this PR's 5 new tests pass, none skipped.
Tested
x86_64-pc-windows-gnu.9e08a5aas it is (merge base withmain6020a33), no uncommitted changes. The lib test binary runs under Wine, one test per process.bcnt_scc_written_in_partial_block_is_detected_as_stale: okgpu_wave_fixes_agree_with_hlsl: okmbcnt_hi_of_low_mask_and_mask_addend_on_cpu: okreadfirstlane_and_readlane_accept_mask_sgpr_on_cpu: okwave32_b64_mask_counts_preserve_independent_high_sgpr_on_cpu: okNot tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T06:32:33Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T07:12:05Z.
Tested
9e08a5a82b408f3272f7e340f56795946ba249acon Windows 11 Enterprise Evaluation 25H2 (26200.9974), Ryzen 7 3800X, Intel Arc A770 driver32.0.101.9175. Rust/Cargo1.100.0(x86_64-pc-windows-msvc), DXC/DXIL1.9.2609.5. Debug/test profile with debuginfo and incremental compilation disabled.cargo test --locked -p xcl --lib --no-run --jobs 2 --message-format=json-render-diagnostics. Under the Arc mutex withXCL_ADAPTER=A770, ran the pinned Cargo artifact asxcl-97fdf2b9ff8e1482.exe gpu::recomp::lower::wave::tests::gpu_wave_fixes_agree_with_hlsl --exact --nocapture --test-threads=1. The binary digest matched before and after lock acquisition and after exit.V_MBCNT_HI_U32_B32across all 64 logical lanes. Wave32 covered mixed mask/scalar B64 counts and find-first-bit, plusV_READFIRSTLANE_B32andV_READLANE_B32with a mask source. The fixture reports equality without printing passing readback values.Not tested
Native wave64, CPU tests including stale-SCC refusal, overflow or invalid inputs, the workspace suite, retail smoke, and other adapters.
AI use
T3 Code / Codex (gpt-6.2-sol) built and ran the existing fixture and wrote this report.
upstream-sync referenced this pull request2026-11-25 21:03:39 +00:00
upstream-sync referenced this pull request2026-11-25 21:05:11 +00:00
upstream-sync referenced this pull request2026-11-25 21:05:11 +00:00
upstream-sync referenced this pull request2026-11-25 21:05:11 +00:00
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T20:18:54Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T00:33:54Z.
merge-check
base:
fa204595a4head:
9e08a5a82bmerge: clean (trial merge a5984b5fe9a8d558272c23ee00fa3548f83c1375, local, not pushed;
git diff --checkclean)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 (XCL_DXC_DIR = DXC 1.9.2609) -> 2613 passed, 0 failed, 49 ignored; SKIPPED: 26 (21 no wave64 on this 32-lane GPU, 3 per-lane f16/f32 forms refused (#1426 semantics), 2 no heap windows); failing: none. All 5 new
gpu::recomp::lower::wave::testsran and passed. That includesgpu_wave_fixes_agree_with_hlsl, which ran on the GPU (not skipped): direct DXIL against HLSL, split wave64 formbcnt_hi_low_maskand wave32 for the other two.review: none blocking; whole diff read (
lower/wave.rsonly).V_MBCNT_HI_U32_B32takesballot_halfonly when SRC0 is the upper dword of a wave64 mask. A low-dword mask (vcc_lo) now gets the full ballot's low word on every lane. That is what lanes 32..63 need, because the instruction counts SRC0's bits as a number. In wave32,ltis 0 on every lane, so the result is still SRC1, as on hardware.words()fors0..s106pairs reads each dword withword(), so a mask in one half and a number in the other both survive. EXEC (126) keeps[ballot(exec), 0].wave_salualso takes_B64counts whose mask is ins0 + 1.V_READFIRSTLANE_B32/V_READLANE_B32read SRC0 throughword(), asV_WRITELANE_B32already does.S_BCNT*writes SCC throughwrite_scc, so a stale SCC after a lane join is refused.Note, not blocking:
v_mbcnt_hi_u32_b32 v, exec_lo, ...now asks for the full ballot (half = false). In a partial block of a split wave64 it is refused, where before it compiled with the wrong half-ballot. The usual idiom (mbcnt_lo exec_lothenmbcnt_hi exec_hi) is unchanged, becauseexec_hiis the upper dword.performance: none expected. The same ops are emitted, except for one extra
word()per wave32_B64operand ins0..s106. Not measured. No title run: Recompiler / Tier 1.verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74, wave32 only), AMD Ryzen 9 9950X, Windows 11 build 26200; rustc 1.99.0, debug test profile, DXC 1.9.2609 via XCL_DXC_DIR. Claude Code, Claude Opus 5.5: merge, build, suite and full-diff review; this report.
Imported from ivall/xcl. Originally posted by throny on 2026-11-29T00:47:28Z.
merge-check claim
head:
9e08a5a82bImported from ivall/xcl. Originally posted by throny on 2026-11-29T01:02:07Z.
merge-check
base:
fa204595head:
9e08a5a82bmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2613 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at
fa204595: 2608 passed, 0 failed, 49 ignored.review: no blocking finding; all hunks read (one file, the per-lane wave lowering). The half ballot is now taken only for the upper dword of a mask, a low dword gets the full ballot; in wave32 the two words of a 64-bit read are read separately, so a mask next to a plain number survives; the bit count's condition flag goes through the common write, so a stale one is caught, and that test fails without the fix. To know: one form in a partial block of a split wave64 is now refused and falls back to HLSL, where before it compiled with a wrong result. No overlap with #2117 (other files); the two point the same way. This agrees with the other check on this head in the thread.
performance: none measurable. Per-lane source only: only per-lane cache entries are re-translated.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).