Recompiler: translate ds_permute_b32 #925
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!925
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/925/head"
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?
@maximecmb on GitHub · 2026-11-24 08:27 UTC · original
recomp-ds-permute→main· +111 −0 · 2 files · 1 commits · closed without mergingds_permute_b32was untranslated (theisa_coveragecensus lists it as missing; no open PR or issue covers it). It is the forward form ofds_bpermute_b32. Each active lane sends DATA0 to lane((ADDR + offset) >> 2) & 31of its own 32-lane half, in wave64 too. That was measured on RDNA2 in native wave64 in the comments below (by @KENAJBBY and @certified-retart), and it matchesds_bpermute_b32in #772. Of several senders to one lane the highest-numbered one wins, a lane no active lane sends to gets 0, inactive lanes neither send nor receive, and no LDS memory is used.The first version of this PR (
874a9fd) took the target mod 64 and could send across the halves. It was wrong on the hardware, and its test agreed with it only because the reference model had the same mistake.What is in it
crates/xcl/src/gpu/recomp/emit.rs: each lane looks at the 32 senders of its half in lane order throughrla_half_fn, asds_swizzledoes, so the highest active sender wins. The split wave64 form needs no exchange. In a wave64 VS / PS that may run in 32-lane waves the instruction is refused: lanes 32..63 of the console wave don't exist there, andupper_lanesdoesn't model this instruction's writes to them.crates/xcl/src/gpu/recomp/tests.rs:gpu_ds_permute_b32compares against the measured model in wave32, wave64 and split wave64. The cases are a reversal (within each half), two senders per lane with high address bits set, offset 8 (wrapping in its half), offset 128 (the identity), and inactive senders and receivers.ds_permute_b32_refused_where_upper_lanes_do_not_existchecks the refusal, and that compute and non-split pixel modes translate. Against the first version's translation the GPU test fails:wave64 split=true lane 1: v10,left: 4158,right: 4126(lane 62's value where the hardware gives lane 30's).Tested
c3e3442, rebased ontomain6bac4b4stable-x86_64-pc-windows-msvc, debug, DXC 1.9.2602.17cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 721 passed, 0 failed, 41 ignoredgpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware; noXCL_SAMPLE_*setRegression run
main:This PR:
Not tested
AI use
🤖 Generated with Claude Code
@dcastell1 on GitHub · 2026-11-24 08:40 UTC · original
Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on clean
main@beaa245(713 passed, 0 failed, 41 ignored on this box):Two more passing tests than main:
ds_permute_b32translates and its fixture runs green here; nothing else changes verdict.Tree restored afterwards (md5 and a full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
@certified-retart on GitHub · 2026-11-24 09:24 UTC · original
Measured
ds_permute_b32directly in native wave64 on RDNA2 (gfx1036, Ryzen 7 9800X3D iGPU, Windows 10 Pro build 19045, driver32.0.21030.2001, AMD OpenCL2.1 AMD-APP (3652.0)with-cl-std=CL2.0 -Wf,-mwavefrontsize64, verified raw0xDAC8xxxxinstruction inCL_PROGRAM_BINARIESands_bcnt1_i32_b64(exec) == 64/v_readlane_b32(lane, 63) == 63). Full table is in #772; the keyds_permute_b32findings for this PR:dst = (sender & 32) | (((addr + offset) >> 2) & 31)matched 64/64 across all 17 cases tested (fullEXEC, partialEXEC, collisions, and nonzero immediate offsets2, 4, 128, 132, 65532).addr = 4 * (63 - lane),data = 1000 + lane):half=64/64,full=0/64(l0=1031,l31=1000,l32=1063,l63=1032).addr = 0:l0=1031,l32=1063, all other lanes0— each 32-lane half resolves its own highest active sender independently; lane 63 does not overwrite lane 0.offset:128(+32 lanes) withaddr = 4 * lane:l0=1000..l31=1031,l32=1032..l63=1063— does not cross halves.offset:2withaddr = 4 * lane + 2:l0=1031,l31=1030,l32=1063,l63=1062(vs identity foroffset:0) — confirms byte addition(addr + offset)before>> 2.So @4usphs's suspicion is confirmed on RDNA2 hardware:
ds_permute_b32has the exact same within-32-lane-half restriction asds_bpermute_b32in wave64, which also means split-wave64 does not need a cross-half exchange for it.Not tested: XCL's PR branch itself, other GPU generations, or retail titles.
AI use: Antigravity (
gemini-4-neon) wrote and ran the OpenCL probe, checked the compiled ELF opcodes, and drafted this comment.@maximecmb on GitHub · 2026-11-24 09:42 UTC · original
@4usphs: no, I didn't consider it. I took the target lane mod 64 from the ISA pseudocode and from XCL's own
ds_bpermute_b32, without measuring the hardware. The test passed only because the translation and its reference model had the same mistake.@KENAJBBY and @certified-retart's measurements settle it. On RDNA2 in native wave64,
ds_permute_b32sends to(sender & 32) | (((addr + offset) >> 2) & 31)and never crosses the 32-lane halves. Their runs also confirm the rest of the PR's model: the highest sender wins, an active lane nobody sends to gets 0, and inactive lanes take no part. Thank you, all three.Pushed
c3e3442(squashed into the PR's one commit):emit.rs: each lane looks at the 32 senders of its own half, throughrla_half_fnasds_swizzledoes. This is @KENAJBBY's change, so the split wave64 form needs no exchange any more. I kept the refusal in a wave64 VS / PS that may run in 32-lane waves:upper_lanesdoesn't model this instruction's writes to lanes 32..63, and I haven't tested without the refusal.tests.rs: the reference model is the measured half-wave one, and there's one more case,offset:128, which is the identity (it doesn't move a lane to the other half).874a9fd'semit.rs) fails as @KENAJBBY saw:wave64 split=true lane 1: v10,left: 4158,right: 4126. Lane 1 gets lane 62's value, where the hardware gives lane 30's.Tested on
c3e3442(rebased ontomain6bac4b4): RTX 5080 (driver 617.42, 32-lane waves: wave32 and split wave64), Ryzen 7 9800X3D, Windows 11 26300, Rust 1.100.0 MSVC, debug, DXC 1.9.2602.17.cargo test -p xcl --lib ds_permute: 2 passed.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 721 passed, 0 failed, 41 ignored; SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.ds_bpermute_b32(#772) is left as it is: it's a separate change, and this PR now matches whatever fix lands there. The regression run will be redone on the new head.AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and wrote this reply.
@KENAJBBY on GitHub · 2026-11-24 09:23 UTC · original · edited 2026-11-24 09:57 UTC
ds_permute_b32measured on RDNA2 in native wave64: it stays within each 32-lane half, likeds_bpermute_b32in #772. This answers the wave64 question above: on RDNA2 the reversal case ingpu_ds_permute_b32asserts the opposite of the hardware.Method. Inline RDNA2 assembly in OpenCL C through AMD's OpenCL driver (the #518 / #772 method), one group of 64 work-items built with
-cl-std=CL2.0 -Wf,-mwavefrontsize64. Every kernel checks native wave64 in the same wave (v_mbcnt_lo/higive lanes 0..63,s_bcnt1_i32_b64 exec= 64). The instruction runs betweens_mov_b64 exec, <mask>and a restore, followed bys_waitcnt lgkmcnt(0); DATA0 =0x1000 + lane, VDST preset to0xCAFEBABE. 28 cases, each run 3 times with identical output. Two models, compared lane by lane:((addr + offset) >> 2) & 63(lane & 32) | (((addr + offset) >> 2) & 31)ds_bpermute,lane(control)ds_bpermute,63 - lane(control)ds_bpermute,(lane + 1) & 63(control)ds_permute,laneds_permute,63 - laneds_permute,(lane + 1) & 63ds_permute,lane >> 1(two senders per target)ds_permute,lane & 31ds_permute,0(all to one lane)ds_permute,40(all to one lane)ds_permute,(62 - lane) & 630x5555…5555ds_permute,63 - lane0x0000_0000_FFFF_FFFFds_permute,63 - lane0xFFFF_FFFF_0000_0000ds_permute,laneds_permute,laneds_permute,63 - lane,+ 0x10000 + (lane & 3)bytesds_permute, the PR's ADDR in v1 / v2 / v30xF0F0_FF0F_7777_FFFEAgreeing with the PR's reference model in every case: of several senders the highest lane wins (a lowest-wins model fails on
lane >> 1and the all-to-one-lane cases), an active lane no one sends to gets 0, inactive lanes neither send nor change VDST. Three more partial-EXEC cases (0x5555…5555with identity,63 - laneand+1) give the same result in both models and match it. Fords_bpermute_b32, the two cases still open in #772 also follow the half model: EXEC0x5555…5555(a read of an inactive lane gives 0) andoffset:4/offset:128.Effect on this PR (
874a9fd).gpu_ds_permute_b32passes because the translation and the reference model are both full-wave. With only the reference changed to the half model (tmp[(i & 32) | ((addr[i].wrapping_add(offset) >> 2) as usize & 31)]), it fails:wave64 split=false lane 1: v10,left: 4158,right: 4126on the Radeon (lane 62's value arrives; the hardware delivers lane 30's), and the same atwave64 split=trueon the RTX.A possible change in
emit.rs(tried locally, not pushed). Each receiver looks only at the 32 senders of its own half, throughrla_half_fnlikeds_swizzle, so the split form needs no exchange:The same tests before (PR head) and after (with this change and the half reference):
ds_permute,ds_bpermute,ds_swizzle,split_wave64(11 tests)XCL_REQUIRE_GPU=wave64gpu_ds_permute_b32with the half referencecargo test --workspace --no-fail-fast -- --test-threads=4The failures are always the #913 trio, which comes and goes between runs (it passed in the last RTX run). Since no lane would read the other half any more, the VS / PS refusal may not be needed; I did not test that. Keeping this in step with the #772 fix for
ds_bpermute_b32seems simplest. Per the census in #772 this title has no wave64ds_permute_b32, so the effect is on other programs.Tested
874a9fd(base09940bb), debug. Windows 11 Pro 26200; AMD Radeon iGPU of the Ryzen 7 9800X3D (gfx1036, RDNA2, native wave64; driver 32.0.21030.2001, OpenCL3652.0 (PAL,LC)); NVIDIA RTX 5070 Ti (driver 621.24); Rust 1.100.0 MSVC; DXC 1.9.2602.17.XCL_ADAPTER=radeon XCL_REQUIRE_GPU=wave64 cargo test --workspace --no-fail-fast -- --test-threads=4: 715 passed, 3 failed, 41 ignored, 0 SKIPPED.XCL_ADAPTER=nvidia cargo test --workspace --no-fail-fast -- --test-threads=4: 715 passed, 3 failed, 41 ignored; SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.placed_title_textures_share_vram_and_preserve_pixels, thentransitions_apply_when_their_list_is_submittedandd32s8_targets_take_their_own_size_of_video_memoryon the poisoned lock).main077ce40on the Radeon (cargo test -p xcl --lib -- --test-threads=4): 672 passed, the same 3 failed. All three pass on their own (--test-threads=1) at the PR head on both GPUs.cargo test -p xcl --lib ds_permute -- --test-threads=1: 2 passed on each GPU.Not tested
gfx1036is a desktop RDNA2 APU, the same generation; the RX 6800M in #772 agrees fords_bpermute_b32. RDNA1 not tested.One of the 28 kernels (two senders per target)
The other cases change only
addr, the EXEC maskm, the opcode andoffset:N.AI use: Claude Code (Claude Opus 5.5) wrote the probe kernels and the host, ran them and the tests on my PC, tried the change above and drafted this comment.
Update for
c3e3442(rebased ontomain6bac4b4), run on the native wave64 form the new head had not been tested on.emit.rs: the code lines are the ones I tried above (only the comment differs); the VS / PS refusal stays.tests.rs: the reference model is the measured half-wave one. I measured all four cases ofgpu_ds_permute_b32with the test's exact inputs on thegfx1036probe: its EXEC0xF0F0_FF0F_7777_FFFE, its ADDR, DATA0 and0xCAFEBABEpreset, offsets 0 / 0 / 8 / 128. The test's expected values equal the hardware's in 64 of 64 lanes in each. The newoffset:128case with that EXEC is the identity on the hardware too (full-wave model: 17/64).gfx1036,XCL_ADAPTER=radeon XCL_REQUIRE_GPU=wave64:gpu_ds_permute_b32passes in wave32, native wave64 and split wave64, and the 11ds_permute/ds_bpermute/ds_swizzle/split_wave64tests pass.874a9fd's translation, the new test fails in the native form:wave64 split=false lane 1: v10,left: 4158,right: 4126.cargo test --workspace --no-fail-fast -- --test-threads=4: 721 passed, 0 failed, 41 ignored, 0SKIPPED(the two wave64-only tests run and pass).XCL_ADAPTER=nvidia: the same 11 tests pass;cargo test --workspace --no-fail-fast -- --test-threads=4: 721 passed, 0 failed, 41 ignored;SKIPPED(no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.AI use: Claude Code (Claude Opus 5.5) compared the commit, ran the probe and the tests on my PC and drafted this update.
@akimfomin on GitHub · 2026-11-24 10:10 UTC · original
I checked the
ds_permute_referencefromc3e3442against four of the native RDNA2 controls and got the reported values. The4*lane + 2address withOFFSET0 = 2looks like a useful addition togpu_ds_permute_b32: it exposes an implementation that shifts the address and offset separately before adding. The current+8and+128cases leave those low bits at zero.With all lanes active and
DATA0 = 0x1000 + lane, lanes 0 / 31 / 32 / 63 read0x101F / 0x101E / 0x103F / 0x103E. I added a CPU check for all 64 lanes. It passes on the exact reference function and fails when the shift is moved before the addition. I have a test-only change for the GPU fixture that applies cleanly to this head. The GPU run for that change is still pending.Would you be open to adding the case? It can reuse the existing masked fixtures by seeding
v4with4*lane + 2and addingDS_PERMUTE_B32withADDR=4,OFFSET0=2,VDST=14.I used PortBridge to follow the related Wave64 work in VIctory #439 and keep the separate gather question in #772 linked. AI-assisted with Codex.
@eizispark on GitHub · 2026-11-24 09:08 UTC · original · edited 2026-11-24 10:21 UTC
Hardware check of
c3e34429cbb8a216c6f88015f772367614e371be(verified clean merge withmain6efdabc): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace -- --test-threads=4:721 passed, 0 failed, 41 ignored(GPU tests skipped on this adapter:none)gpu::recomp::tests::gpu_ds_permute_b32(native wave64, wave32, and split-wave64 half-wave model),ds_permute_b32_refused_where_upper_lanes_do_not_exist,gpu_wave32_program_in_wave64_hardware,gpu_geometry_wave32_prefix_count_over_a_mask: allokRegression run
main(6bac4b4):PR (
c3e3442):Not tested
AI use
scripts/smoke.ps1harness on this machine and formatted this report.@maximecmb on GitHub · 2026-11-24 10:23 UTC · original
@akimfomin Yes, that case is worth having. I get the same values from the model:
ADDR = 4*lane + 2withOFFSET0 = 2sends each lane to(lane + 1) & 31of its half, so lanes 0 / 31 / 32 / 63 read lane 31's / 30's / 63's / 62's data,0x101F / 0x101E / 0x103F / 0x103E. An implementation that shifts address and offset separately gives the identity there instead, which neither the+8nor the+128case can tell apart.Could you open it as its own test-only PR, stacked on this one? It only touches
tests.rs, so it needs no regression run. Putting it into this PR would mean newxcl-smokeruns for the head. The credit for the case stays with you too. I'll run it on the RTX 5080 (wave32 and split wave64) and post the result there.@hkgamingdk231-prog thank you for the native wave64 runs. Note that they were on
874a9fd, the first version, which crossed the 32-lane halves. The head is nowc3e3442, which follows the measured RDNA2 behaviour (see above). A native wave64 run of it would still be welcome.AI use: Claude Code (Claude Opus 5.5) checked the values against the reference model and wrote this reply.
@DarkPanda69 on GitHub · 2026-11-24 09:42 UTC · original · edited 2026-11-24 10:24 UTC
Test report for head
c3e34429c(updated; first run was on874a9fdcd).Setup
main9aec53d(applied cleanly), debug build, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.cargo test -p xcl --lib -- gpu::recomp --test-threads=4, once withXCL_ADAPTER=radeonand once withXCL_ADAPTER=3060.Tested:
gpu_ds_permute_b32passes on both GPUs withc3e3442.Correction to my first report:
874a9fdalso passed here, so these runs check that the translated HLSL matches the test's reference model, in 64-lane and in 32-lane waves. They cannot show that the model matches the hardware, which is what the RDNA2 measurements above settled.Not tested: pixel shaders with helper lanes; a title that uses the instruction.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@SlopTart on GitHub · 2026-11-24 10:37 UTC · original
Linux / AMD RDNA3 datapoint.
Merged state: head
c3e3442onto main9aec53d, clean merge.Full suite,
cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 719 passed, 7 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows. ds_permute_b32 translation green on wave64 - permute crossing halves lands correctly on RDNA3, consistent with the #772 hardware data.Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.
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.
@raylitebull on GitHub · 2026-11-24 10:40 UTC · original
Code/CI review only (not independently runtime-tested by me): clean merge with both checks green (
Build and test+PR description). Self-containedds_permute_b32translation with unit test coverage. Recommend merging, @ivall.@akimfomin on GitHub · 2026-11-24 10:40 UTC · original
Thanks for checking the byte-carry values. The stacked test-only PR is open on your
recomp-ds-permutebranch, with one changed file. It passed the focused tests on RTX 4070 Ti SUPER in wave32 and split wave64. The new check failed with a deliberate shift-before-add mutation while the previous fixture passed. I left the additional GPU run open in the PR. PortBridge connected this case to the published RDNA2 measurements. AI-assisted with Codex.@4usphs on GitHub · 2026-11-24 08:57 UTC · original · edited 2026-11-24 11:25 UTC
Test run on AMD RDNA4 with native 64-lane waves, the form Not tested lists, and one question about the wave64 semantics.
Tested: the PR head
874a9fd(base09940bb;main077ce40is one README commit ahead). RX 9070 XT (RDNA4, native wave64), driver 32.0.32029.2010, Ryzen 7 9800X3D, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug.cargo test --workspace --no-fail-fast -- --test-threads=4: 715 passed, 3 failed, 41 ignored, 0SKIPPED. The 3 are the #913 trio (placed_title_textures_share_vram_and_preserve_pixels, thentransitions_apply_when_their_list_is_submittedandd32s8_targets_take_their_own_size_of_video_memoryon the poisoned lock), the same as in the description.main077ce40fails the same three here (cargo test -p xcl --lib -- --test-threads=4: 672 passed, 3 failed), so they are not from this change.gpu_ds_permute_b32runs all three forms on this adapter (native wave64, wave32, split wave64): 10 of 10 passed.ds_permute_b32_refused_where_upper_lanes_do_not_existpasses.wave64 split=false):lane 2: v12,left: 4128,right: 0(lane 32's value arrives at lane 2).lane 2: v12,left: 4096,right: 0(inactive lane 0's value arrives).So the native wave64 path, including sending across the halves, is checked on real 64-lane hardware.
A question on the wave64 semantics. The translation takes the target lane mod 64, so a lane can send to the other half, and the reversal case asserts that.
ds_bpermute_b32does the same in XCL (& 63,emit.rs:3961). In #772, plainds_bpermute_b32was measured on an RDNA2 GPU (RX 6800M) in native wave64, and it stayed within each 32-lane half. A Mesa ACO comment quoted there says ds_bpermute is restricted to 32 lanes on GFX10–GFX11.7. I did not find a measurement ofds_permute_b32itself. If it behaves like its backward form on the console, the reversal case would assert the opposite of the hardware, and both instructions would need the same change. Was that considered? Keeping the two in step with whatever the fix for #772 does may be the simplest. The first control above shows that a within-half index makes this test fail, so the test would need to change with it.Not tested: smoke or a retail title, a release build, a wave32 program in 64-lane hardware waves, pixel shaders (helper lanes), the console's own behaviour for
ds_permute_b32.AI use: Claude Code (Claude Opus 5.5) read the diff, ran the tests and the controls on my PC and wrote this comment. I have not reviewed the code.
Update: the new head
c3e3442(within-half model), now also on RDNA2 itself. Thanks for the quick change.Tested:
c3e3442merged ontomain47efa2e(local merge, no conflicts), debug. Two GPUs on the same PC, picked withXCL_ADAPTER: the Ryzen 7 9800X3D's Radeon iGPU (gfx1036, RDNA2, native wave64, driver 32.0.21045.29003) and the RX 9070 XT (RDNA4).gpu_ds_permute_b32(XCL_REQUIRE_GPU=wave64: native wave64, wave32, split wave64)cargo test --workspace --no-fail-fast -- --test-threads=4SKIPPEDSKIPPED{t}_h = 0u), the test fails atwave64 split=false lane 32: v10,left: 0,right: 4159.main(#923).AI use: as above, Claude Code (Claude Opus 5.5) ran the tests and the control on my PC and wrote this update.
Pull request closed