Recompiler: ds_bpermute_b32 in wave64 stays in each 32-lane half (#772) #1022
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1022
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1022"
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?
@upipibi on GitHub · 2026-11-24 10:26 UTC · original
upipibi:fix/bpermute-wave64→main· +128 −124 · 7 files · 4 commits · openBranch
fix/bpermute-wave64, commit212fb96onmain6efdabc. Not pushed.Fixes #772.
What the hardware does
In native wave64 on RDNA2,
ds_bpermute_b32lets lanelread lane(l & 32) | (((addr + offset) >> 2) & 31). If that lane is inactive, the result is 0. Two people measured it:lane,63 - laneand(lane + 1) & 63. The half-wave model matched 64/64 lanes in each case.XCL used
& 63and read across the halves. That follows the opcode table's "mod 64". The ACO lowering and both measurements disagree with it.The change
emit.rs,"ds_bpermute_b32"(lane_id & 32u) | (((addr + offset) >> 2) & 31u). Wave32 is unchanged.rla_half_fn, asds_swizzledoes.xcl_x_rla_anyand its 32-word exchange slot are removed.upper_lanesconstant case (select(and(xcl_hw32, l >= 32), c, …)) is therefore removed.upper_lanes.rsds_bpermuteis no longer counted as a read of lanes ≥ 32.ds_permutekeeps its hazard; #925 covers that instruction.docs/wave64-on-wave32.mdds_bpermutewith the reads that stay inside their half.The emitter's lines for wave64 in the split form:
Test
The new test is
gpu_ds_bpermute_wave64_stays_in_its_half. It uses source data1000 + lane, so a 0 from an inactive lane can't be mistaken for lane 0. It runs seven cases and compares each with the measured model. It also checks these lanes from luckyteagirl's report directly:63 - lane: lane 0 reads 31, lane 32 reads 63, lane 63 reads 32(lane + 1) & 63: lane 31 reads 0, lane 63 reads 32Before (
main6efdabcwith the new test): 226 wrong lanes. The counts per case match the "full-wave" column of certified-retart's table.4 * lane(identity)4 * (63 - lane)4 * ((lane + 1) & 63)4 * lane,offset:44 * lane,offset:1284 * (63 - lane),offset:44 * (lane ^ 32), EXEC0xAAAAAAAA_55555555After: all seven cases match.
Three existing assertions encoded the cross-half reading and now expect the half-wave lanes. These are the same three that @NathanTheophile listed on the issue:
gpu_format_stores_atomics_global_lds63 - ll ^ 31gpu_split_wave64_cross_half_operations63 - ll ^ 31gpu_split_wave64_waves_divergel ^ 33l ^ 1outside_whole_wave_code_the_upper_lanes_stay_unwrittennow expects one read where it used to expect two.ds_bpermuteis no longer a read of lanes ≥ 32, even after whole-wave code has written them.Tested
7e1b659(rebased ontomain6e1e2be), RTX 3070 (616.56), split wave64: the direct DXIL path now also keepsds_bpermute_b32in each half (c673925: lane(lane & 32) | (((addr + offset) >> 2) & 31), as the HLSL path does;read_lane_anyand its 32-word exchange slot removed), found by cindertheblue. Targeted tests (the five from the review plussplit_wave64_reduction_tail_rulesandgpu_ds_swizzle_and_bpermute_zero_inactive_lanes): before 6/7 withXCL_DIRECT_DXIL=0and 2/7 with=1(226 wrong lanes), after 7/7 on both.split_wave64_reduction_tail_rules(added tomainsince) now counts 1 + 2 meets (7dc382b). Fullgpu_suite: 135 passed with0; with1, 134 passed and 1 failed:gpu_image_get_resinfo_1d_array, which fails onmaintoo (#2046).7e1b659updatesdocs/wave64-on-wave32.md(split exchanges spin by default since #798).RTX 3070, driver 616.56, Windows 11, DXC 1.8.2502.11. The command was
cargo test --workspace --no-fail-fast -- --test-threads=4, in its own target dir.main6efdabc212fb96On both, the usual two tests were skipped (no wave64):
gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware.This GPU has 32-lane waves only, so every wave64 case above ran in the split form. The native wave64 path is not run here.
WaveReadLaneAt, so the explicit(lane_id & 32)index is what keeps it half-wave there.Notes
ds_bpermute_b32in the 22 532 wave64 programs of the retail cache. This is a correctness fix for the instruction, not for any retail shader seen so far.Regression run
Pair for the current head
7e1b659againstmainafc5ee8, run by Kalmarv (comment, thanks): RTX 5070 Ti,scripts/smoke.ps1 -Seconds 60, release builds from clean trees. Pasted as printed. Their note: this head sits on a much oldermainthanafc5ee8, so the frame (1239 / 1126) and commit (26949 / 23683 MB) differences can't be put down to this change alone; neither run had a device removal or a crash.Earlier pair (for
212fb96, before the rebase):Smoke pair by Kalmarv (RTX 5070 Ti, driver 610.74),
main6efdabc(this PR's base) against212fb96: 1184 / 1248 frames, no crash, no device removal on either side (comment).main:
PR:
Not tested
ds_bpermute_b32in the 22 532 wave64 programs counted on #772, so a smoke run is a regression check only).AI use
🤖 Generated with Claude Code
@KENAJBBY on GitHub · 2026-11-24 10:33 UTC · original
Native wave64 run on RDNA2, the form Not tested lists: pass, and the test's seven cases measured on the hardware with the same inputs.
Tested: head
212fb96(basemain6efdabc), debug. Windows 11 Pro 26200; AMD Radeon iGPU of the Ryzen 7 9800X3D (gfx1036, RDNA2, native 64-lane waves; driver 32.0.21030.2001); NVIDIA RTX 5070 Ti (driver 621.24, 32-lane waves); Rust 1.100.0 MSVC; DXC 1.9.2602.17. One test process at a time.gfx1036,XCL_ADAPTER=radeon XCL_REQUIRE_GPU=wave64(native wave64)XCL_ADAPTER=nvidia(split wave64)gpu_ds_bpermute_wave64_stays_in_its_halfbpermute,ds_swizzle,ds_permute,split_wave64,upper_lanesandgpu_format_stores_atomics_global_ldstests (20)main's translation (emit.rsof6efdabc)226 wrong, e.g.lane 0 4 * (63 - lane): 1063, want 1031cargo test --workspace --no-fail-fast -- --test-threads=4SKIPPEDSKIPPED(no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardwareSo the native wave64 path gives the half-wave result, and the native form tells the old and new translations apart by the same 226 lanes as your split run.
The test's expected values against the hardware. I ran each of the test's seven cases as raw
ds_bpermute_b32on the samegfx1036with inline RDNA2 assembly through AMD's OpenCL driver (-cl-std=CL2.0 -Wf,-mwavefrontsize64;v_mbcntgives lanes 0..63 ands_bcnt1_i32_b64 exec= 64 in the same wave; EXEC set withs_mov_b64around the instruction; 3 runs each, identical). Each one matches the half-wave model in 64 of 64 lanes, which is the model the test checks:& 63)4 * lane4 * (63 - lane)4 * ((lane + 1) & 63)4 * lane,offset:44 * lane,offset:1284 * (63 - lane),offset:44 * (lane ^ 32), EXEC0xAAAAAAAA_55555555(inactive lanes keep VDST)The last two were only measured by @certified-retart so far; this is a second
gfx1036, with the same result.Not tested: the console itself (
gfx1036is a desktop RDNA2 APU of the same generation), RDNA1, a wave64 VS / PS in 32-lane waves (the removedupper_lanesconstant case), pixel shaders, a release build,xcl-smokeor any title.AI use: Claude Code (Claude Opus 5.5) ran the hardware probe and the tests on my PC and wrote this comment.
@DavidM1911 on GitHub · 2026-11-24 11:05 UTC · original
Independent verification, merged onto current
main384f7f7locally (clean merge).Machine: Windows 11, Ryzen 9 7900X Radeon iGPU (gfx1036, RDNA2, native wave64 — the hardware class this fix targets), RTX 3060 Ti also present; Rust stable MSVC, debug.
XCL_ADAPTER=radeon cargo test -p xcl --lib bpermute: 2 passed —gpu_ds_bpermute_wave64_stays_in_its_halfandgpu_ds_swizzle_and_bpermute_zero_inactive_lanesboth run on the Radeon (backend 'real' – AMD Radeon(TM) Graphics confirmed in output).XCL_ADAPTER=radeon cargo test -p xcl --lib recomp -- --test-threads=4: 189 passed, 0 failed, 18 ignored (ignored =XCL_SAMPLE_*retail-survey tests; all GPU wave64 tests ran).AI use: test runs by Devin (Cognition, SWE-2); no code changes.
@DavidM1911 on GitHub · 2026-11-24 11:33 UTC · original
Independent verification, merged onto current
main384f7f7locally (clean merge).Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
cargo test -p xcl --lib bpermute: 2 passed, 0 failed — including the new GPU testgpu_ds_bpermute_wave64_stays_in_its_half, which runs on this adapter (wave64 emitted as two wave32 halves with per-half lane fixup).gpu_ds_swizzle_and_bpermute_zero_inactive_lanesalso passes.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
@SlopTart on GitHub · 2026-11-24 11:55 UTC · original
Linux / AMD RDNA3 verification, following up on my #772 correction row.
Merged state: head onto current main (
54f2c17lane merge), clean merge. Full suite: 727 passed / 11 failed / 41 ignored - exactly the known Wine-lane set from my #42 rows plus this rig's flake family; no new failures.For the wave64/bpermute thread specifically, I ran the bpermute tests three ways on this merge:
ds_bpermutesemantics per my #772 measurement): passXCL_SPLIT_WAVE64=1: passSo the "stays in each 32-lane half" lowering is green end-to-end on RDNA3 native wave64, and composes correctly with the forced split path. That matches what the community measured in hardware terms in #772: GFX10-GFX11.5 already restrict bpermute to the 32-lane half, and this PR makes the recompiler stop assuming otherwise.
One honest side observation from this batch, flagged not blamed: the
gpu_split_wave64_*suite on current main underXCL_SPLIT_WAVE64=1is failing far more on this rig than when I posted my split numbers in #772 (four of the five tests 0/6 in solo reps today, vs 12/12 + 9/12 earlier). Same rig stack, same binaries, and the era-era pin1ec4c98shows the same mixed-or-red pattern today, so I am not reading it as a regression from this PR; full numbers and ruled-out causes are in my new comment on #772.Counts only, no game data.
Not tested: retail titles (none here), Windows, RDNA4.
Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross
x86_64-pc-windows-gnu,XCL_NETWORK=0, release profile,--test-threads=4. My Linux rows: #42 / #718.AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@Kalmarv on GitHub · 2026-11-24 16:12 UTC · original
Regression pair for
212fb96againstmain6efdabc(this PR's base), for the Regression run section. Both runs pass: no device removal, no crash, 95 % ofmain's frames, 92 % of its peak commit.Tested
scripts/smoke.ps1, the same retail title for 60 s each:mainat6efdabc(this PR's base, 29 commits behind today'smain) first, then this PR's head, one after the other on the same machine.main6efdabc:this PR,
212fb96:Presents per 2 s over the whole run (from the
activity (2 s)lines):main: 0 31 59 51 29 57 60 60 60 60 60 60 60 60 59 46 51 60 60 60 45 53 29 5 2 2 9 15 32 13The 64-frame gap is a few single dips in the first 20 s of the PR's run, and a slow phase from about 46 s that both runs have (93 frames in the last 16 s against 107). Both runs built about the same compute pipelines (175 and 160 lines, 17 and 13 from the driver's blob of an earlier run). As the PR says, no wave64 program counted in the retail cache uses
ds_bpermute_b32, so this run is a regression check only, and one pair can't separate 5 % from run-to-run spread.Not tested
ds_bpermute_b32: not counted.AI use: Claude Code (Claude Opus 5.5)
@upipibi on GitHub · 2026-11-24 20:47 UTC · original
This PR still needs a smoke pair for the
PR descriptioncheck: it changesemit.rs, and we have no title. Could someone with the title post thexcl-smokeblocks formainand212fb96? @eizispark and @Kalmarv have made these for our earlier PRs. Per the count on #772, no retail wave64 program usesds_bpermute_b32, so this is only a regression check.@Kalmarv on GitHub · 2026-11-24 20:52 UTC · original
@upipibi, the pair for this head is already in an earlier comment: #1022. That's
main6efdabc(this PR's merge-base) against212fb96, 1184 / 1248 frames (95 %), no crash and no device removal on either side. If you paste those twoxcl-smokeblocks under Regression run in the description, the check should pass; the head hasn't moved since.AI use: Claude Code (Claude Opus 5.5)
@upipibi on GitHub · 2026-11-24 21:07 UTC · original
Thanks, I missed it. Your pair is now under Regression run in the description, credited.
@upipibi on GitHub · 2026-11-25 06:27 UTC · original
Thanks cindertheblue, both points confirmed and fixed; rebased onto
main6e1e2be.ds_bpermute_b32indxil/lower_mem.rsnow reads lane(lane & 32) | (((addr + offset) >> 2) & 31)throughread_lane_half, likeds_swizzleand the HLSL path (c673925).read_lane_anyis gone, and so is the 32-word exchange slot it needed indxil/kernel.rs.split_wave64_reduction_tail_rulesnow expects 1 + 2 meets, as you worked out (7dc382b).In a separate commit (
7e1b659),docs/wave64-on-wave32.mdnow says the split exchange spins by default since #798 (XCL_WAVE64_SPIN=0brings the barrier back), and that the direct DXIL backend still uses the barrier for one console wave.RTX 3070 (driver 616.56), split wave64, debug: your five tests plus
split_wave64_reduction_tail_rulesandgpu_ds_swizzle_and_bpermute_zero_inactive_laneswent from 6/7 to 7/7 withXCL_DIRECT_DXIL=0, and from 2/7 to 7/7 withXCL_DIRECT_DXIL=1(before the fix: the same 226 wrong lanes). Fullgpu_suite: 135 passed withXCL_DIRECT_DXIL=0; with1, 134 passed and the 1 failure isgpu_image_get_resinfo_1d_array, which fails onmaintoo. Not tested: native wave64 with the direct path.AI-assisted (Claude Code).
@cindertheblue on GitHub · 2026-11-25 02:14 UTC · original · edited 2026-11-25 06:55 UTC
Update: retested the new head
7e1b659(onmain6e1e2be) on the same RDNA3 card in native wave64. Both points are fixed, also withXCL_DIRECT_DXIL=1, which was the case not tested yet. My first report is kept below.Tested
gfx1102, native wave64 and wave32), driver 32.0.31041.1004 (AMD Software 26.8.1), Ryzen 5 9600X, Windows 11 Home 26200.9974, rustc 1.99.1, DXC 1.8.2502.11 (SDK 10.0.26100), debug. The head and its base built withcargo build --workspace, each in its own folder, no local changes.split_wave64_reduction_tail_rulesandgpu_ds_swizzle_and_bpermute_zero_inactive_lanes,cargo test -p xcl --lib -- <the seven names>, 3 runs per row on the head:7e1b659XCL_SPLIT_WAVE64=1XCL_DIRECT_DXIL=1212fb96)XCL_DIRECT_DXIL=1 XCL_SPLIT_WAVE64=1212fb96)On
main6e1e2bethe six of these that exist there also pass in all four rows (once each);gpu_ds_bpermute_wave64_stays_in_its_halfis new in this PR.cargo test --workspace --no-fail-fast -- --test-threads=4, once each:main6e1e2be7e1b659)XCL_DIRECT_DXIL=1The same tests fail on both trees, none from this PR:
fuzz_validate_and_gpu_1(seed 722, #2115); withXCL_DIRECT_DXIL=1alsogpu_image_get_resinfo_1d_array(#2046) andoffline_compute_pipeline_is_reused_by_a_second_process(#1674). The same 8SKIPPEDlines on all four runs (f16 per-lane forms, no heap windows, Developer Mode off).Not tested: a release build, the RDNA2 iGPU on this machine, NVIDIA, titles.
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this update from the real output.
First report, on
212fb96merged ontomain025c786Tested
212fb96merged ontomain025c786(git merges it cleanly) on an RDNA3 card running native wave64, on Windows. The native form passes. Two things on currentmainneed the PR updated:XCL_DIRECT_DXILhas its ownds_bpermute_b32that still reads across halves, and a test added after this PR's base fails with it.Tested
gfx1102, native wave64 and wave32), driver 32.0.31041.1004 (AMD Software 26.8.1), Ryzen 5 9600X, Windows 11 Home 26200.9974, rustc 1.99.1, DXC 1.8.2502.11 (SDK 10.0.26100), debug. Each tree built withcargo build --workspacein its own folder.gpu_ds_bpermute_wave64_stays_in_its_half,gpu_format_stores_atomics_global_lds,gpu_split_wave64_cross_half_operations,gpu_split_wave64_waves_diverge,outside_whole_wave_code_the_upper_lanes_stay_unwritten),cargo test -p xcl --lib -- <the five names>, 3 runs per row:XCL_SPLIT_WAVE64=1(split form forced on wave64 hardware)XCL_DIRECT_DXIL=1XCL_DIRECT_DXIL=1 XCL_SPLIT_WAVE64=1cargo test --workspace --no-fail-fast -- --test-threads=4, once each:main025c786XCL_DIRECT_DXIL=1Failing on both trees, not from this PR:
fuzz_validate_and_gpu_1(the AMD seed 722 mismatch from #1679); withXCL_DIRECT_DXIL=1alsogpu_image_get_resinfo_1d_arrayandoffline_compute_pipeline_is_reused_by_a_second_process(#1674).1. The direct DXIL backend still reads across the halves. #1426 (merged after this PR's base) translates
ds_bpermute_b32itself incrates/xcl/src/gpu/dxil/lower_mem.rs("ds_bpermute_b32", line 2022 on025c786):let m = if self.wave64 { 63 } else { 31 };thenread_lane_any. WithXCL_DIRECT_DXIL=1:gpu_ds_bpermute_wave64_stays_in_its_halfreports 226 wrong lanes in every run, the same count as your "before" onmain(e.g.lane 0 4 * (63 - lane): 1063, want 1031).lane 0: ds_bpermute of index 63 from lane 31,lane 0 ds_bpermute (index 63 - l, within its half),[256, 1, 1], group 0 thread 0: ds_bpermute). OnmainwithXCL_DIRECT_DXIL=1the old cross-half expectations of those three pass.So the direct form probably needs the same index,
(lane & 32) | (((addr + offset) >> 2) & 31), in wave64.2.
split_wave64_reduction_tail_rulesfails with no variable set. It was added in9e2c7a5, after this PR's base, and countsxcl_x_meet() ?in the HLSL:This PR removes
xcl_x_rla_any, whose body has onexcl_x_meet() ?(uint o = xcl_x_meet() ? xcl_x_get(l & 31u) : 0u;), so the prelude now has 2. After a rebase the expectation would be1 + 2. It passes onmain.Not tested
212fb96on its own base6efdabc: everything above is the merge onto025c786.AI use
@cindertheblue on GitHub · 2026-11-25 06:56 UTC · original
Retested
7e1b659on the RX 7600 XT in native wave64, includingXCL_DIRECT_DXIL=1: all seven tests pass and the full suite has no new failures. Details in my edited comment above.@JJAutoCompare on GitHub · 2026-11-25 07:01 UTC · original
Tested
PR #1022 passed the requested fixture on STOR-WINLAB at clean, detached commit
7e1b659cfcd95c37d8710c85adb3753847455575. 1 passed, 0 failed, 0 ignored, 0 skipped. The PR was open at that SHA before and after the run. Its discussion had same-head NVIDIA and AMD results, with no equivalent Arc A770 result.The stock HLSL → DXIL split-wave64 fixture checked all 64 lanes in seven cases, including immediate offsets and preservation of inactive destination lanes under partial EXEC. This adds independent Arc compatibility coverage for issue #772.
Intel Arc A770 driver
32.0.101.9175, Ryzen 7 3800X, Windows 11 25H2 build26200.9974, Rust/Cargo1.100.0MSVC, DXC and DXIL1.9.2609.5. WithXCL_ADAPTER=A770andXCL_DXC_DIRpointing to the installed 1.9.2609 directory, the prebuild ran outside the Arc mutex with two jobs, incremental compilation disabled, and dev/test debug info disabled.The executable SHA-256 matched before the mutex wait and after acquisition. Native and wrapper exits were 0, with 1,124 filtered out and a 0.32 s fixture time.
Not tested
Native AMD ISA or native wave64, direct DXIL, inactive-source zeroing, the workspace suite, and retail smoke.
AI use
T3 Code / Codex (
gpt-6.2-sol) ran the verification and wrote this report.@upipibi on GitHub · 2026-11-25 13:51 UTC · original
Could someone with a retail title post an
xcl-smokepair formainand this head7e1b659? Kalmarv's pair in the description is for212fb96, before the rebase, so the PR description check stays red. I'll paste it with credit. cindertheblue's RX 7600 XT re-run and JJAutoCompare's run already cover the synthetic tests at7e1b659.AI-assisted (Claude Code).
@Kalmarv on GitHub · 2026-11-25 14:01 UTC · original
@upipibi here is the pair you asked for.
scripts/smoke.ps1 -Seconds 60ran from each tree, at default settings with noXCL_DIRECT_DXIL, the same title, one after the other. Both builds were release, from clean trees. This head7e1b659was built as it is, not merged ontomain.mainafc5ee8:this PR,
7e1b659:PR vs
main: 1239 / 1126 frames (110 %), peak commit 26949 / 23683 MB (114 %). Neither run had a device removal or a crash.This head sits on a much older
mainthanafc5ee8, so the pair compares across that gap as well as this change. The frame and commit differences can't be put down tods_bpermute_b32alone. As your Not tested says, it's a regression check only.Hardware: RTX 5070 Ti 16 GB (NVIDIA 610.74), Ryzen 9 9950X, Windows 11 build 26200.
AI use: Claude Code (Claude Opus 5.5) built both trees, ran the pair and wrote this; both blocks are pasted as printed.
@DavidM1911 on GitHub · 2026-11-26 03:32 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
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.