Skip to content

Recompiler: translate ds_permute_b32 - #925

Closed
maximecmb wants to merge 1 commit into
xcl-dev:mainfrom
maximecmb:recomp-ds-permute
Closed

maximecmb wants to merge 1 commit into
xcl-dev:mainfrom
maximecmb:recomp-ds-permute

Conversation

@maximecmb

@maximecmb maximecmb commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

ds_permute_b32 was untranslated (the isa_coverage census lists it as missing; no open PR or issue covers it). It is the forward form of ds_bpermute_b32. Each active lane sends DATA0 to lane ((ADDR + offset) >> 2) & 31 of 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 matches ds_bpermute_b32 in #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 through rla_half_fn, as ds_swizzle does, 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, and upper_lanes doesn't model this instruction's writes to them.
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_ds_permute_b32 compares 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_exist checks 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

  • head c3e3442, rebased onto main 6bac4b4
  • NVIDIA GeForce RTX 5080 (driver 617.42, 32-lane waves), AMD Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug, DXC 1.9.2602.17
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 721 passed, 0 failed, 41 ignored
  • SKIPPED on this adapter (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware; no XCL_SAMPLE_* set
  • The native wave64 form of the first version was run on RDNA4 and RDNA2 by @4usphs and @eizispark (comments below). It hasn't been rerun on native wave64 for this head.

Regression run
main:

xcl-smoke v1
commit: 9aec53df7004bd9018ef3df67532f85d66ee261c
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1674 (PresentX 1674)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15195 MB

This PR:

xcl-smoke v1
commit: c3e34429cbb8a216c6f88015f772367614e371be
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1671 (PresentX 1671)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14709 MB

Not tested

  • the native wave64 form of this head (no 64-lane GPU here)
  • a wave32 program in 64-lane hardware waves, and pixel shaders (helper lanes)
  • whether the VS / PS refusal is still needed now that no lane reads the other half
  • a title that uses the instruction: the regression run won't show whether one does

AI use

  • Claude Code, Claude Opus 5.5: wrote the code, the tests and this description, and ran the tests above. The hardware model comes from the measurements in the comments.

🤖 Generated with Claude Code

@dcastell1

Copy link
Copy Markdown

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):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
715 passed; 0 failed; 41 ignored   (exit 0)

Two more passing tests than main: ds_permute_b32 translates 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.

@maximecmb
maximecmb marked this pull request as ready for review November 24, 2026 08:46
@4usphs

4usphs commented Nov 24, 2026 •

Copy link
Copy Markdown

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 (base 09940bb; main 077ce40 is 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, 0 SKIPPED. The 3 are the Memory: a sparse alloc/free loop makes a new 64 MiB pool each cycle; lib tests fill a 12 GB card (#348's test) #913 trio (placed_title_textures_share_vram_and_preserve_pixels, then transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory on the poisoned lock), the same as in the description. main 077ce40 fails 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_b32 runs all three forms on this adapter (native wave64, wave32, split wave64): 10 of 10 passed. ds_permute_b32_refused_where_upper_lanes_do_not_exist passes.
  • Negative controls, each failing in the native wave64 case (wave64 split=false):
    • index masked to 31 in the non-split loop (no crossing between the halves): lane 2: v12, left: 4128, right: 0 (lane 32's value arrives at lane 2).
    • inactive lanes allowed to send: 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_b32 does the same in XCL (& 63, emit.rs:3961). In #772, plain ds_bpermute_b32 was 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 of ds_permute_b32 itself. 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: c3e3442 merged onto main 47efa2e (local merge, no conflicts), debug. Two GPUs on the same PC, picked with XCL_ADAPTER: the Ryzen 7 9800X3D's Radeon iGPU (gfx1036, RDNA2, native wave64, driver 32.0.21045.29003) and the RX 9070 XT (RDNA4).

RDNA2 iGPU RX 9070 XT
gpu_ds_permute_b32 (XCL_REQUIRE_GPU=wave64: native wave64, wave32, split wave64) 3 / 3 passed 3 / 3 passed
cargo test --workspace --no-fail-fast -- --test-threads=4 743 passed, 0 failed, 41 ignored, 0 SKIPPED 743 passed, 0 failed, 41 ignored, 0 SKIPPED

AI use: as above, Claude Code (Claude Opus 5.5) ran the tests and the control on my PC and wrote this update.

@eizispark

eizispark commented Nov 24, 2026 •

Copy link
Copy Markdown

Hardware check of c3e34429cbb8a216c6f88015f772367614e371be (verified clean merge with main 6efdabc): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo 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: all ok

Regression run
main (6bac4b4):

xcl-smoke v1
commit: 6bac4b4419886acc940d479dcf8815d0b1804435
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1669 (PresentX 1669)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14860 MB

PR (c3e3442):

xcl-smoke v1
commit: c3e34429cbb8a216c6f88015f772367614e371be
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1666 (PresentX 1667)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14861 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); pixel shader helper-lane behavior; gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.

@KENAJBBY

KENAJBBY commented Nov 24, 2026 •

Copy link
Copy Markdown

ds_permute_b32 measured on RDNA2 in native wave64: it stays within each 32-lane half, like ds_bpermute_b32 in #772. This answers the wave64 question above: on RDNA2 the reversal case in gpu_ds_permute_b32 asserts 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/hi give lanes 0..63, s_bcnt1_i32_b64 exec = 64). The instruction runs between s_mov_b64 exec, <mask> and a restore, followed by s_waitcnt lgkmcnt(0); DATA0 = 0x1000 + lane, VDST preset to 0xCAFEBABE. 28 cases, each run 3 times with identical output. Two models, compared lane by lane:

  • full (this PR): target = ((addr + offset) >> 2) & 63
  • half: target = (lane & 32) | (((addr + offset) >> 2) & 31)
Instruction, ADDR / 4 EXEC offset half full Distinguishing output
ds_bpermute, lane (control) all 0 64/64 64/64 –
ds_bpermute, 63 - lane (control) all 0 64/64 0/64 lane 0 read 31, lane 32 read 63, lane 63 read 32 (as the RX 6800M)
ds_bpermute, (lane + 1) & 63 (control) all 0 64/64 62/64 lane 31 read 0, lane 63 read 32
ds_permute, lane all 0 64/64 64/64 –
ds_permute, 63 - lane all 0 64/64 0/64 lane 0 got 31's, lane 32 got 63's
ds_permute, (lane + 1) & 63 all 0 64/64 62/64 lane 0 got 31's, lane 32 got 63's
ds_permute, lane >> 1 (two senders per target) all 0 64/64 32/64 lane k < 16 got 2k+1's; lanes 16..47 got 0; lane 48+k got (33+2k)'s
ds_permute, lane & 31 all 0 64/64 0/64 identity (full: lane l < 32 would get l+32's)
ds_permute, 0 (all to one lane) all 0 64/64 62/64 lane 0 got 31's, lane 32 got 63's, the rest 0
ds_permute, 40 (all to one lane) all 0 64/64 63/64 lane 8 got 31's, lane 40 got 63's
ds_permute, (62 - lane) & 63 0x5555…5555 0 64/64 32/64 lane 0 got 30's, lane 32 got 62's
ds_permute, 63 - lane 0x0000_0000_FFFF_FFFF 0 64/64 32/64 lane 0 got 31's (full: 0)
ds_permute, 63 - lane 0xFFFF_FFFF_0000_0000 0 64/64 32/64 lane 32 got 63's (full: 0)
ds_permute, lane all 4 64/64 62/64 lane 0 got 31's, lane 32 got 63's
ds_permute, lane all 128 64/64 0/64 identity: the offset is added before the 5-bit lane mask
ds_permute, 63 - lane, + 0x10000 + (lane & 3) bytes all 0 64/64 0/64 address bits 0–1 and 8+ are ignored
ds_permute, the PR's ADDR in v1 / v2 / v3 0xF0F0_FF0F_7777_FFFE 0 / 0 / 8 64/64 each 20 / 51 / 61 the PR's three cases with its EXEC and DATA0

Agreeing with the PR's reference model in every case: of several senders the highest lane wins (a lowest-wins model fails on lane >> 1 and 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…5555 with identity, 63 - lane and +1) give the same result in both models and match it. For ds_bpermute_b32, the two cases still open in #772 also follow the half model: EXEC 0x5555…5555 (a read of an inactive lane gives 0) and offset:4 / offset:128.

Effect on this PR (874a9fd).

  • gpu_ds_permute_b32 passes 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: 4126 on the Radeon (lane 62's value arrives; the hardware delivers lane 30's), and the same at wave64 split=true on the RTX.
  • With the half reference, the test's three cases equal the measured values lane for lane (last row above).

A possible change in emit.rs (tried locally, not pushed). Each receiver looks only at the 32 senders of its own half, through rla_half_fn like ds_swizzle, so the split form needs no exchange:

let rla = self.rla_half_fn();
self.line(&format!("uint {t}_a = {a} + {off16}u;"));
self.line(&format!("uint {t} = 0u, {t}_h = lane_id & 0x20u;"));
self.line(&format!("[loop] for (uint {t}_k = 0u; {t}_k < 32u; {t}_k++) {{"));
self.line(&format!("    uint {t}_s = {t}_h | {t}_k, {t}_sa = {rla}({t}_a, {t}_s), {t}_sd = {rla}({v}, {t}_s);"));
self.line(&format!("    if (lanebit_at({el}, {eh}, {t}_s) && (({t}_sa >> 2) & 31u) == (lane_id & 31u)) {t} = {t}_sd;"));
self.line("}");

The same tests before (PR head) and after (with this change and the half reference):

Test GPU Before After
ds_permute, ds_bpermute, ds_swizzle, split_wave64 (11 tests) Radeon, XCL_REQUIRE_GPU=wave64 11 passed 11 passed
same RTX 5070 Ti 11 passed 11 passed
gpu_ds_permute_b32 with the half reference Radeon / RTX fails (lane 1 gets lane 62's value) passes (wave32, native wave64, split wave64 / wave32, split wave64)
cargo test --workspace --no-fail-fast -- --test-threads=4 Radeon 715 passed, 3 failed, 41 ignored 715 passed, 3 failed, 41 ignored
same RTX 5070 Ti 715 passed, 3 failed, 41 ignored 718 passed, 0 failed, 41 ignored

The 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_b32 seems simplest. Per the census in #772 this title has no wave64 ds_permute_b32, so the effect is on other programs.

Tested

  • PR head 874a9fd (base 09940bb), debug. Windows 11 Pro 26200; AMD Radeon iGPU of the Ryzen 7 9800X3D (gfx1036, RDNA2, native wave64; driver 32.0.21030.2001, OpenCL 3652.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.
  • The 3 are the Memory: a sparse alloc/free loop makes a new 64 MiB pool each cycle; lib tests fill a 12 GB card (#348's test) #913 trio (placed_title_textures_share_vram_and_preserve_pixels, then transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory on the poisoned lock). main 077ce40 on 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

One of the 28 kernels (two senders per target)
__kernel void k(__global uint* o) {
  uint l = get_local_id(0), lo, L, cnt, r = 0xCAFEBABEu;
  __asm__ volatile("v_mbcnt_lo_u32_b32 %0, -1, 0" : "=v"(lo));
  __asm__ volatile("v_mbcnt_hi_u32_b32 %0, -1, %1" : "=v"(L) : "v"(lo));   // hardware lane 0..63
  __asm__ volatile("s_bcnt1_i32_b64 %0, exec" : "=s"(cnt));                // 64 = native wave64
  uint addr = 4u*(L>>1), data = 0x1000u + L;
  ulong m = 0xffffffffffffffffUL, saved;
  __asm__ volatile(
    "s_mov_b64 %1, exec\n"
    "s_mov_b64 exec, %4\n"
    "ds_permute_b32 %0, %2, %3\n"
    "s_waitcnt lgkmcnt(0)\n"
    "s_mov_b64 exec, %1\n"
    : "+v"(r), "=&s"(saved) : "v"(addr), "v"(data), "s"(m) : "memory");
  o[l*4+0] = L; o[l*4+1] = cnt; o[l*4+2] = r; o[l*4+3] = addr;
}

The other cases change only addr, the EXEC mask m, the opcode and offset: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 onto main 6bac4b4), 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 of gpu_ds_permute_b32 with the test's exact inputs on the gfx1036 probe: its EXEC 0xF0F0_FF0F_7777_FFFE, its ADDR, DATA0 and 0xCAFEBABE preset, offsets 0 / 0 / 8 / 128. The test's expected values equal the hardware's in 64 of 64 lanes in each. The new offset:128 case with that EXEC is the identity on the hardware too (full-wave model: 17/64).
  • Radeon gfx1036, XCL_ADAPTER=radeon XCL_REQUIRE_GPU=wave64:
    • gpu_ds_permute_b32 passes in wave32, native wave64 and split wave64, and the 11 ds_permute / ds_bpermute / ds_swizzle / split_wave64 tests pass.
    • Negative control: with 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, 0 SKIPPED (the two wave64-only tests run and pass).
  • RTX 5070 Ti, 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.
  • Not tested: as above (the console itself, RDNA1, pixel shaders, a wave32 program in 64-lane waves, split VS / PS without the refusal, release, any title).

AI use: Claude Code (Claude Opus 5.5) compared the commit, ran the probe and the tests on my PC and drafted this update.

@certified-retart

Copy link
Copy Markdown
Contributor

Measured ds_permute_b32 directly in native wave64 on RDNA2 (gfx1036, Ryzen 7 9800X3D iGPU, Windows 10 Pro build 19045, driver 32.0.21030.2001, AMD OpenCL 2.1 AMD-APP (3652.0) with -cl-std=CL2.0 -Wf,-mwavefrontsize64, verified raw 0xDAC8xxxx instruction in CL_PROGRAM_BINARIES and s_bcnt1_i32_b64(exec) == 64 / v_readlane_b32(lane, 63) == 63). Full table is in #772; the key ds_permute_b32 findings for this PR:

  • Stays strictly within each 32-lane half on RDNA2 in native wave64: dst = (sender & 32) | (((addr + offset) >> 2) & 31) matched 64/64 across all 17 cases tested (full EXEC, partial EXEC, collisions, and nonzero immediate offsets 2, 4, 128, 132, 65532).
  • Reversal (addr = 4 * (63 - lane), data = 1000 + lane): half=64/64, full=0/64 (l0=1031, l31=1000, l32=1063, l63=1032).
  • All 64 lanes sending to addr = 0: l0=1031, l32=1063, all other lanes 0 — each 32-lane half resolves its own highest active sender independently; lane 63 does not overwrite lane 0.
  • offset:128 (+32 lanes) with addr = 4 * lane: l0=1000..l31=1031, l32=1032..l63=1063 — does not cross halves.
  • offset:2 with addr = 4 * lane + 2: l0=1031, l31=1030, l32=1063, l63=1062 (vs identity for offset:0) — confirms byte addition (addr + offset) before >> 2.

So @4usphs's suspicion is confirmed on RDNA2 hardware: ds_permute_b32 has the exact same within-32-lane-half restriction as ds_bpermute_b32 in 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.

It was untranslated (the isa_coverage census listed it as missing). Each
active lane sends DATA0 to lane ((ADDR + offset) >> 2) & 31 of its own
32-lane half: in wave64 too, as measured on RDNA2 in native wave64 (#925,
like ds_bpermute_b32 in #772). Of several senders the highest lane wins,
a lane nobody sends to gets 0, inactive lanes neither send nor receive,
and no LDS memory is used.

Each lane looks at the 32 senders of its half in lane order, through the
half-local lane read ds_swizzle uses, so the split wave64 form needs no
exchange. In a wave64 VS / PS that may run in 32-lane waves the
instruction is refused: the console wave's lanes 32..63 do not exist
there.

Tests: a GPU test against the measured model (reversal within halves,
colliding senders, high address bits, offsets 8 and 128, inactive lanes)
in wave32, wave64 and split wave64, and the refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DarkPanda69

DarkPanda69 commented Nov 24, 2026 •

Copy link
Copy Markdown

Test report for head c3e34429c (updated; first run was on 874a9fdcd).

Setup

  • This PR's diff applied on main 9aec53d (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 with XCL_ADAPTER=radeon and once with XCL_ADAPTER=3060.
    • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: waves 32..64, so wave64 programs run in native 64-lane waves.
    • NVIDIA RTX 3060 (Ampere), driver 32.0.16.1088: 32 only, so wave64 programs run in the split form.
  • Not run: the whole workspace suite (the recompiler tests only) and a retail smoke run.

Tested: gpu_ds_permute_b32 passes on both GPUs with c3e3442.

  • RX 9070 XT (native wave64): 190 passed, 0 failed, 18 ignored, 0 SKIPPED.
  • RTX 3060 (split wave64): 190 passed, 0 failed, 18 ignored, 2 SKIPPED (no wave64).

Correction to my first report: 874a9fd also 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.

@maximecmb
maximecmb marked this pull request as draft November 24, 2026 09:42
@maximecmb

Copy link
Copy Markdown
Contributor Author

@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_b32 sends 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, through rla_half_fn as ds_swizzle does. 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_lanes doesn'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).
  • The new test against the old translation (874a9fd's emit.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 onto main 6bac4b4): 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.

@maximecmb
maximecmb marked this pull request as ready for review November 24, 2026 09:51
@akimfomin

Copy link
Copy Markdown

I checked the ds_permute_reference from c3e3442 against four of the native RDNA2 controls and got the reported values. The 4*lane + 2 address with OFFSET0 = 2 looks like a useful addition to gpu_ds_permute_b32: it exposes an implementation that shifts the address and offset separately before adding. The current +8 and +128 cases leave those low bits at zero.

With all lanes active and DATA0 = 0x1000 + lane, lanes 0 / 31 / 32 / 63 read 0x101F / 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 v4 with 4*lane + 2 and adding DS_PERMUTE_B32 with ADDR=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.

@maximecmb

Copy link
Copy Markdown
Contributor Author

@akimfomin Yes, that case is worth having. I get the same values from the model: ADDR = 4*lane + 2 with OFFSET0 = 2 sends each lane to (lane + 1) & 31 of 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 +8 nor the +128 case 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 new xcl-smoke runs 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 now c3e3442, 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.

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head c3e3442 onto main 9aec53d, 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

Copy link
Copy Markdown
Member

Code/CI review only (not independently runtime-tested by me): clean merge with both checks green (Build and test + PR description). Self-contained ds_permute_b32 translation with unit test coverage. Recommend merging, @ivall.

@akimfomin

Copy link
Copy Markdown

Thanks for checking the byte-carry values. The stacked test-only PR is open on your recomp-ds-permute branch, 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.

CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
…-dev#772)

Measured on RDNA2 in native wave64, the index for lane l is
(l & 32) | (((addr + offset) >> 2) & 31):

- RX 6800M (gfx1031), luckyteagirl:
  xcl-dev#772 (comment)
- gfx1036 with partial EXEC and immediate offsets, certified-retart:
  xcl-dev#772 (comment)

XCL masked the index with 63 and read across the halves.

- emit.rs: wave64 uses the half-wave index and reads it through
  rla_half_fn, as ds_swizzle does. As a result:
  - The split form needs no exchange, so xcl_x_rla_any and its 32-word
    slot are gone.
  - In a 32-lane wave of a wave64 VS / PS, the permute can no longer
    reach lanes 32..63, so the upper_lanes constant case is gone.
- upper_lanes.rs: ds_bpermute is no longer a read of lanes >= 32.
  ds_permute is unchanged (xcl-dev#925).
- docs/wave64-on-wave32.md: ds_bpermute is now listed with the reads
  that stay inside their half.

New test gpu_ds_bpermute_wave64_stays_in_its_half: the three full-EXEC
indices, offsets 4 and 128, and EXEC 0xAAAAAAAA_55555555, expected
values from the measured model. On main 6efdabc it gives 226 wrong
lanes. Three existing assertions that encoded the cross-half reading
now expect the half-wave lanes:

- gpu_format_stores_atomics_global_lds: l ^ 31
- gpu_split_wave64_cross_half_operations: l ^ 31
- gpu_split_wave64_waves_diverge: l ^ 1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants