Recompiler: v_swaprel_b32 indexes the destination with M0[25:16] #797
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/803"
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 upipibi on 2026-11-24T05:37:20Z.
v_swaprel_b32exchanged the fixedVDSTwithVGPR[SRC0 + M0]and switched on all of M0. The RDNA 2 ISA gives each side its own index (VOP1 opcode 104):addr_src = SRC0 + M0.u[9:0],addr_dst = DST + M0.u[25:16], thentmp = VGPR[addr_dst]; VGPR[addr_dst] = VGPR[addr_src]; VGPR[addr_src] = tmp, with the examplem0 = (20 << 16) | 10,v_swaprel_b32 v5, v7swapping v25 and v17. Section 6.6 (table 25) also uses separate fields for source and destination; it prints the low field as M0[7:0], and this PR follows the opcode table's M0[9:0], asv_movrelsd_2_b32already does. LLVM defines the instruction (VOP1Instructions.td,Uses = [M0]) but no compiler I know of emits it.On
main, withm0 = (2 << 16) | 3, no case ofswitch (m0)matched. XCL wrote 0 to v5 and left v7 and v13 alone, where the ISA swaps v7 and v13 and leaves v5 untouched. The existing test only used m0 = 3 and m0 = 1, where both readings agree.What is in it
crates/xcl/src/gpu/recomp/emit.rs:swaprelreads and writes both sides through the bounded switches thatmovreluses forv_movrelsd_2_b32(m0 & 0x3FF,(m0 >> 16) & 0x3FF). Both old values are still read before either write, so an overlapping pair is a no-op, and the writes stay EXEC-gated as for any VOP1 write.crates/xcl/src/gpu/dxil/lower_wide.rs(added 2026-12-03, after the merge-check reviews): the direct-DXIL loweringLw::swaprelhad the same old reading (fixedVDST, switch on all of M0), and the direct backend is now the default for kernels, sogpu_v_swaprel_b32failed there. It now mirrorsemit.rs: destinationVDST + M0[25:16], sourceSRC0 + M0[9:0], both& 0x3FF, both old values read before either write, writes EXEC-gated.crates/xcl/src/gpu/recomp/tests.rs:gpu_v_swaprel_b32getsm0 = (2 << 16) | 3,v_swaprel_b32 v5, v10(swaps v7 and v13, v5 untouched), andm0 = 0xFC01FC02,v_swaprel_b32 v16, v20(bits outside the two fields ignored: swaps v17 and v22).v_swaprel_b32_uses_the_m0_relative_switchchecks the two index expressions in the HLSL.Tested
At the current head
94bcb7c(rebased ontomaine99b0bdon 2026-12-03): NVIDIA GeForce RTX 3070, driver 621.40, Windows 11 Pro, rustc 1.100.0, debug.cargo test -p xcl --lib -- --test-threads=4(direct backend, the default): 2863 passed, 0 failed, 37 ignored. The 24 SKIPPED lines are the usual ones for this card: 22 need wave64, 1 needs heap windows, and 1 needs the driver cache off.swapreltests (gpu_v_swaprel_b32,v_swaprel_b32_uses_the_m0_relative_switch,upper_lanes::tests::swaprel_writes_any_register), 3 runs each withXCL_DIRECT_DXIL=0and=1: 3 passed, 0 failed every run.lower_wide.rschange failsgpu_v_swaprel_b32withXCL_DIRECT_DXIL=1(lane 0: v5 = 0, expected 2000), as the reviews found; it passes onXCL_DIRECT_DXIL=0.Earlier, at
4db1a2a(driver 616.56):cargo test --workspace --no-fail-fast -- --test-threads=4on4db1a2a: 704 passed, 0 failed, 41 ignoredgpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu_wave32_program_in_wave64_hardware(no wave64)main(d5442d2) without theemit.rschange.gpu_v_swaprel_b32fails at lane 0 withv5 = 0, expected 2000 (untouched), andv_swaprel_b32_uses_the_m0_relative_switchfails on the oldswitch (m0). Both pass with the change.upper_lanes::tests::swaprel_writes_any_registerpasses before and after.Regression run
From eizispark's run (https://github.com/ivall/xcl/pull/803#issuecomment-7123874976), thanks. It is for the previous head
4db1a2a, before the rebase and the direct-DXIL change, so a pair on94bcb7cis still needed:main:
PR:
Not tested
v_swaprel_b32with a non-zero M0[25:16]. Low impact: neither LLVM nor ACO emits the instruction.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T05:46:09Z.
Test run of
4db1a2a4a3d03b3f5eb559670c1f584fbbdd055con AMD RDNA4. I merged it onto currentmaine50836blocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 704 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 663 passed, 0 failed, 21 ignoredSKIPPED;gpu_v_swaprel_b32,v_swaprel_b32_uses_the_m0_relative_switchandswaprel_writes_any_registerpass.Review: Separate indices for the two sides (
SRC0 + M0[9:0],DST + M0[25:16]) are what the RDNA2 ISA's pseudo-code for VOP1 opcode 104 gives, including itsm0 = (20 << 16) | 10example. I found nothing to change.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Imported from ivall/xcl. Originally posted by ethandepstein-del on 2026-11-24T05:57:38Z.
Independent native Windows NVIDIA RTX 5080 (wave32) + D3D12 debug layer build/test run and code review at head
4db1a2a4a3d03b3f5eb559670c1f584fbbdd055c.Code Review
v_swaprel_b32(VDST + M0[25:16]<->SRC0 + M0[9:0]), capturing both old values before either EXEC-gated write and masking both indices to 10 bits (0x3FFu). Both CPU HLSL and GPU tests cover the destination index and ignored upper M0 bits. No issues found.Tested
617.42/32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll),rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC from Windows SDK10.0.26100.0, debug build.cargo build --workspace && cargo test --workspace -- --test-threads=4hle::d3d12x::cpu_writes::tests::writes_land_after_the_queueatcpu_writes.rs:184, while both PR tests passed in both Run 1 and Run 2.)ok, executed on RTX 5080, not skipped):gpu::recomp::tests::v_swaprel_b32_uses_the_m0_relative_switchgpu::recomp::tests::gpu_v_swaprel_b32gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64)gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64)Not tested
AI use: Antigravity (Gemini 4 Neon reviewed the diff; Gemini 4 Hydrogen ran the RTX 5080 workspace tests) drafted this report.
Imported from ivall/xcl. Originally posted by eizispark on 2026-11-24T06:22:58Z.
Hardware check of
4db1a2a4a3d03b3f5eb559670c1f584fbbdd055c(verified clean merge withmainbeaa245): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace -- --test-threads=4:704 passed, 0 failed, 41 ignored(GPU tests skipped on this adapter:none)gpu_v_swaprel_b32,v_swaprel_b32_uses_the_m0_relative_switch,swaprel_writes_any_register:3 passed, 0 failedRegression run
main(beaa245):PR (
4db1a2a):Not tested
AI use
scripts/smoke.ps1harness on this machine and formatted this report.Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-24T06:41:28Z.
2|
3|AMD/wave64 + release-build datapoint - the axes your row lists as not tested. Plus one flake sighting to log.
4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross
x86_64-pc-windows-gnu, release profile,XCL_NETWORK=0, native wave64. Same rig as my Linux rows in #42 / #718.6|
7|Merged state: head
4db1a2aonto mainbeaa245, clean merge.8|
9|Full suite,
cargo test --workspace --release --no-fail-fast -- --test-threads=4: 702 passed, 11 failed, 41 ignored (17 suites). The 11 = this rig's 7 stable Wine-lane failures (my #42 row) + the #718 flaky trio + one hit ofgpu_geometry_wave32_prefix_count_over_a_mask- that one is AMD-only (skipped on your wave32 boxes); 2 hits in 12 full-suite runs and 5 of 20 isolated runs atbeaa245(load-sensitive - see #847). Nothing failed because of your change. Your tests pass on RDNA3 native wave64:gpu_v_swaprel_b32ok,v_swaprel_b32_uses_the_m0_relative_switchok,upper_lanes::tests::swaprel_writes_any_registerok - and your two skipped GPU tests actually execute here, including the geometry one above.10|
11|Not tested: retail titles (none here), Windows, RDNA4.
12|Counts only, no game data.
13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T10:58:31Z.
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 github-actions[bot] on 2026-11-29T20:41:25Z.
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 saintwolf on 2026-11-30T17:14:54Z.
merge-check claim
head:
4db1a2a4a3Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T17:22:03Z.
merge-check
base:
9dfbe3ea66head:
4db1a2a4a3merge: clean (trial merge 67cf3ece007da0bd66cf245fb88a6d2e88ffbd03; git diff --check clean; +50/-26 in crates/xcl/src/gpu/recomp/emit.rs and tests.rs)
build: cargo build --workspace -> ok (pre-existing warnings only, none from the PR's lines)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2884 passed, 2 failed, 51 ignored (same test count as base: the PR reworks two existing tests rather than adding new ones); SKIPPED: 27, the standard set for this card (22 "no wave64" — wave32-only GPU, 2 "no heap windows", 1 "cannot disable the driver cache (Developer Mode)", 2 "no xgameruntime.dll"). Failing: (1) gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 — pre-existing on this machine, identical on base
9dfbe3ea; (2) gpu_v_swaprel_b32 in the default environment: kernel tests run on the direct-DXIL backend when XCL_DIRECT_DXIL is unset, and that backend's own swaprel (dxil/lower_wide.rs:350) still implements the old fixed-VDST / unmasked-full-M0 behavior — this PR changes only the HLSL recompiler, so the direct-path counterpart is a separate follow-up, the same shape as #1296's. I reproduced the identical failure on a clean base worktree with only the PR's tests.rs applied (lane 0: v5 = 0 vs 2000), so this is not a regression. On the HLSL path the PR actually changes (XCL_DIRECT_DXIL=0) I confirmed first-hand: both swaprel tests fail on base and pass with the change, every lane bit-exact on this card.review: read the whole diff and the surrounding code. The fix matches the RDNA2 ISA: v_swaprel_b32 (VOP1 opcode 104) exchanges the VGPR at VDST + M0[25:16] with the VGPR at SRC0 + M0[9:0], while the old code treated the destination as the fixed VDST and compared the unmasked full M0 against the source index — so any instruction with M0[25:16] != 0 or out-of-field bits swapped the wrong registers (the source read stays 0u when the full M0 matches no case, zeroing the destination). The new code mirrors the v_movrelsd_2_b32 path in the same file (emit.rs:3440): the same masked two indices, the same bounded switches, both old values captured before either write, both writes EXEC-gated, an overlapping pair degenerating to a no-op. I verified every GPU-test vector by hand (m0 = 3 ordinary swap; the EXEC-gated even-lane swap via 0x55555555; m0 = 1 giving v7 <-> v7; m0 = (2 << 16) | 3, the case that discriminates old from new — destination 5 + 2 = v7, source 10 + 3 = v13, v5 untouched; m0 = 0xFC01_FC02, whose out-of-field bits are ignored, giving indices 1 and 2). The reworked unit test pins the generated HLSL of both indexed switches and the DXC compile. Thread: full-suite passes on an RX 9060 XT (RDNA4 wave64, 704/0/41), an RX 9070 XT (704/0/41) with an xcl-smoke main-vs-head regression pair, and an RTX 5080 (wave32, 704/0/41); RTX 3060 Ti lib clean; SlopTart's RADV wave64 release run shows only that rig's known failures with this PR's tests passing. No duplicates (#1616 is the SALU sibling S_MOVRELSD_2_B32 in upper_lanes, a different concern). Only emit.rs and tests.rs, no unsafe, no new dependencies, no stop-criteria files.
performance: none; the generated switches are the same shape as v_movrelsd_2_b32's.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B
Imported from ivall/xcl. Originally posted by coolpersonnn on 2026-11-30T17:27:21Z.
merge-check claim
head:
4db1a2a4a3Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T17:28:50Z.
merge-check claim
head:
4db1a2a4a3Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T17:31:05Z.
merge-check claim
head:
4db1a2a4a3Withdrawn: the checking tool was stopped mid-run before it could post a check, so this claim is released. The head is unchanged and nobody has lost work - anyone may take it.
Imported from ivall/xcl. Originally posted by coolpersonnn on 2026-11-30T17:54:09Z.
merge-check
base:
9dfbe3ea66head:
4db1a2a4a3merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2884 passed, 2 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 (also fails on base
9dfbe3eaalone with identical assertion left: (0, 0), right: (3735928559, 3405691582)), gpu::recomp::tests::gpu_v_swaprel_b32 (passes on base9dfbe3eaalone; fails on merged tree at lane 0: left: 0, right: 2000 because runner::direct_dxil() defaults to true and dxil/lower_wide.rs:350 still uses fixed VDST and unmasked M0; with XCL_DIRECT_DXIL=0, v_swaprel_b32_uses_the_m0_relative_switch, gpu_v_swaprel_b32, and swaprel_writes_any_register pass: 3 passed, 0 failed)review: PR #803 updates only the HLSL recompiler (emit.rs:3480-3516) and not Direct DXIL (crates/xcl/src/gpu/dxil/lower_wide.rs:350-380), while Direct DXIL is now enabled by default on main (dxil/kernel.rs:46-61), causing cargo test --workspace to fail gpu_v_swaprel_b32 on GPU machines once merged. The HLSL fix itself matches RDNA2 ISA VOP1 opcode 104 (VDST + M0[25:16] <-> SRC0 + M0[9:0], matching v_movrelsd_2_b32 at emit.rs:3440, capturing both old values before either EXEC-gated write), and the updated tests cover M0[25:16] vs M0[9:0] and ignored high/mid bits. Clean scope (emit.rs and tests.rs only, no unsafe, no new dependencies, no duplicates in #1607 or open/merged PRs).
performance: none in runtime cost (two bounded switches matching v_movrelsd_2_b32). Extra 60 s retail smoke (scripts/smoke.ps1, release): base
9dfbe3ea-> 1702 frames shown (PresentX 1702), 60 60 61 presents/2s, 0 device removals, 0 crashes, 16028 MB peak commit; merged b705d643 -> 1700 frames shown (PresentX 1700), 60 60 60 presents/2s, 0 device removals, 0 crashes, 16340 MB peak commit (title a93b40d7).verdict: not yet: gpu::recomp::tests::gpu_v_swaprel_b32 passes on base
9dfbe3eaand fails on the merged tree under the default Direct DXIL backend (dxil/lower_wide.rs:350 still uses fixed VDST and unmasked M0); merging as-is breaks cargo test --workspace on GPU hardware until either Direct DXIL swaprel is updated to match or the test selects the HLSL path.hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.2101), AMD Ryzen 9 9950X3D, Windows 11 Pro 26H2 build 26300, rustc 1.100.0 / T3 Code (Antigravity), Gemini 4 Hydrogen
Imported from ivall/xcl. Originally posted by Chrysana on 2026-12-01T00:14:08Z.
merge-check
base:
d0832e614fhead:
4db1a2a4a3merge: clean (git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2881 passed, 10 failed, 51 ignored (base: 2882 passed, 9 failed, 51 ignored); SKIPPED: 6, the same as on base (2 no heap windows, 1 cannot disable the driver cache without Developer Mode, 3 no D3D12 debug layer). failing: the same 8 tests as on base (fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_3, gpu_smem_flat_descriptor_windows_and_limits, f32_programs_on_the_gpu, gpu_f32_compares_with_nan, gpu_float_compares_random, gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs, counted twice), plus gpu_v_swaprel_b32, which passes on base and fails on the merge: "lane 0 ordinary swap; v5 untouched by the second", left 0, right 2000. Run alone with XCL_DIRECT_DXIL=0 it passes. v_swaprel_b32_uses_the_m0_relative_switch passes.
review: I read the whole diff. The HLSL swaprel now indexes VDST with M0[25:16] and SRC0 with M0[9:0], as v_movrelsd_2_b32 does. Both old values are captured before either write, and the writes are EXEC-gated. On AMD that passes the updated test. The default direct-DXIL swaprel (gpu/dxil/lower_wide.rs:350) still swaps with the fixed VDST and compares all of M0 against the source offset. So I see the same failure as coolpersonnn on NVIDIA, now on AMD too: it isn't vendor-specific.
performance: on the HLSL path one more bounded switch per v_swaprel_b32; the default path is unchanged. Not measured (Tier 1, no title run).
verdict: not yet: gpu_v_swaprel_b32 passes on base and fails on the merge under the default direct-DXIL path (AMD RDNA 4, as on NVIDIA); gpu/dxil/lower_wide.rs swaprel needs the same two M0 fields
hardware / tool and model: AMD Radeon RX 9070 XT 16 GB (RDNA 4, driver 32.0.32015.2008), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.1 / Claude Code (Claude Opus 5.5)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:09:47Z.
Triage (#1607) – head
4db1a2aNo open or merged PR changes
v_swaprel_b32to the two M0 fields. #1975 and #1976 only add M0 bound analysis that mentions swaprel.Main's
emit.rs::swaprelstill switches on all of M0.Main has also gained a direct-DXIL
Lw::swaprel(gpu/dxil/lower_wide.rs) since this PR's base, and it has the same old reading (m0 == k, fixed VDST). On a rebase it needs the same fix, or the two backends will disagree.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 upipibi on 2026-12-03T17:08:15Z.
Test report for the new head
94bcb7c(rebased ontomaine99b0bd). The new commit ports the fix to the direct-DXIL lowering (Lw::swaprelindxil/lower_wide.rs), wheregpu_v_swaprel_b32failed on the default path, as the merge-checks above found.NVIDIA GeForce RTX 3070, driver 621.40, Windows 11 Pro, rustc 1.100.0, debug:
cargo test -p xcl --lib -- --test-threads=4(default, direct backend): 2863 passed, 0 failed, 37 ignoredgpu_v_swaprel_b32,v_swaprel_b32_uses_the_m0_relative_switch,upper_lanes::tests::swaprel_writes_any_register, 3 runs each:XCL_DIRECT_DXIL=1: 3 passed, 0 failed (each run)XCL_DIRECT_DXIL=0: 3 passed, 0 failed (each run)lower_wide.rschange,XCL_DIRECT_DXIL=1: 2 passed, 1 failed (gpu_v_swaprel_b32, lane 0: v5 = 0, expected 2000)The smoke pair in the description is for the old head
4db1a2a, so a new pair on94bcb7cis needed.Tested with the help of Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T17:08:33Z.
Follow-up review of
94bcb7ce, since4db1a2a(code reading only, not a merge-check;PR descriptionred) · 2 medium, 1 nitIn short: Rebased, with a second commit that fixes the direct-DXIL
Lw::swaprel(dxil/lower_wide.rs) the same way as the HLSL path. That answers the earlier triage point that the two backends would disagree. The destination is nowVDST + M0[25:16]and the sourceSRC0 + M0[9:0]. Both old values are read before either write, and the writes are EXEC-gated, matchingemit.rs. Two process points remain: the first commit alone fails the default backend's test, and the whole workspace was not run on this head.Medium
gpu_v_swaprel_b32on the default backend.1042ba13changes the test to the new reading but fixes onlyemit.rs. The direct backend, the default for kernels, still has the old reading until94bcb7ce. Tested confirms this (lane 0:v5 = 0, expected 2000). CONTRIBUTING.md asks that every commit build and pass the tests, sogit bisectworks. Squash the two into one commit: it is one logical change, the same instruction in both backends.cargo test -p xcl --libon94bcb7ce(2863 passed, 0 failed, 37 ignored). The workspace run (with the integration tests) is from4db1a2a, before the rebase and the new commit. CONTRIBUTING.md asks forcargo test --workspace -- --test-threads=4on the head under review.Nit
Direct DXIL:is not one of the commit areas. CONTRIBUTING.md listsRecompilerfor this code, as the first commit uses. Squashing (point 1) settles it.Checked and fine
Lw::swaprelno longer compares all of M0 and no longer writes a fixed VDST.emit.rs::swaprelstep by step:0x3FF;M0[9:0]and the destination indexM0[25:16];first..=top(0 past the program's VGPRs, like the HLSLdefault);VGPR[dst] = old srcandVGPR[src] = old dst, each gated byact() && idx == k.top = top_vgpr().max(vdst).max(base)matches the HLSL path'smax_vgprbound.swapreltests three times each withXCL_DIRECT_DXIL=0and=1, and shows the direct path failing without the new commit.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.