Skip to content

Recompiler: translate ds_permute_b32 as RDNA2 runs it - #2222

Open
NWProgramming00 wants to merge 1 commit into
xcl-dev:mainfrom
NWProgramming00:recomp/ds-permute
Open

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

Conversation

@NWProgramming00

@NWProgramming00 NWProgramming00 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

ds_permute_b32 (the forward lane permute) was refused by the translator. This translates it in the HLSL path the way RDNA2 hardware runs it, after the measurements on #925 (closed unmerged by its author) and new measurements on an RDNA2 GPU.

Behaviour, measured: each active lane sends DATA0 to lane ((ADDR + offset) >> 2) & 31 of its own 32-lane half, in wave64 too, so it never crosses the halves. Of several senders to one lane the highest wins. An active lane that nobody sends to gets 0. Inactive lanes neither send nor receive. No LDS memory is used.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: ds_permute_b32 in ds(). Each receiver looks at the 32 senders of its half in lane order through rla_half_fn (as ds_swizzle_b32), so the split wave64 form needs no exchange. A wave64 VS / PS that may run in 32-lane waves still refuses it, because upper_lanes does not model its writes to lanes 32..63. The emitted code follows Recompiler: translate ds_permute_b32 #925 by @maximecmb.
  • crates/xcl/src/gpu/recomp/tests.rs, three tests:
    • ds_permute_reference_matches_rdna2_values: the reference model on values read from the hardware.
    • gpu_ds_permute_b32: wave32, native wave64 and split wave64. It covers a reversal, two senders per lane, high address bits, offsets 8 and 128, and ADDR = 4*lane + 2 with offset 2. That last case catches an implementation that shifts the address and the offset apart. The case was suggested on Recompiler: translate ds_permute_b32 #925 by @akimfomin.
    • ds_permute_b32_refused_where_upper_lanes_do_not_exist.
  • The direct DXIL backend is not changed. It still refuses the instruction.

Tested

  • Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB (wave32; wave64 as two halves) and an AMD Radeon RDNA2 iGPU (gfx1036, native wave64, XCL_ADAPTER=radeon). Rust 1.100 MSVC, release.
  • Hardware measurement: 26 cases ran on the gfx1036 through HIP (ds_permute_b32 v10, v4, v5 offset:N, with v10 preset to mark inactive lanes), in native wave64 and wave32. They cover identity, reversal, rotation, collisions (all lanes to lane 5), high address bits, cross-half addresses, offsets 8 / 128 / 2, and four random address + random EXEC cases. All 26 match the half-wave model above.
  • xcl against the hardware: the same 26 RDNA2 code blocks ran through xcl's kernel path on each adapter and were compared bit for bit with the gfx1036 results. They give 26/26 equal on the RTX 5070 Ti and 26/26 equal on the Radeon.
  • The new tests: 3 passed on each adapter. With the half bit dropped (_h = 0), gpu_ds_permute_b32 fails on both adapters. With the offset dropped, it also fails on both.
  • The whole suite: cargo build --release --workspace, then cargo test --release --workspace --no-fail-fast -- --test-threads=4, with and without XCL_DIRECT_DXIL=all, against base 568e7db on the same machine:
Adapter Mode base 568e7db this PR
RTX 5070 Ti default 1150 passed, 4 failed, 46 ignored 1153 passed, 4 failed, 46 ignored
RTX 5070 Ti XCL_DIRECT_DXIL=all 1148 passed, 6 failed 1151 passed, 6 failed
Radeon gfx1036 default 1153 passed, 1 failed 1156 passed, 1 failed
Radeon gfx1036 XCL_DIRECT_DXIL=all 1151 passed, 3 failed 1154 passed, 3 failed

The +3 are the new tests. The failing tests are the same on base and PR, and all are tracked: fuzz_validate_and_gpu_0..3 on NVIDIA (#1905), fuzz_validate_and_gpu_1 seed 540 on RDNA2 (#2115, #2170), gpu_image_get_resinfo_1d_array with direct DXIL (#2046), and offline_compute_pipeline_is_reused_by_a_second_process with direct DXIL (#1674). The SKIPPED lines are the same set as on base: no wave64 on NVIDIA, the debug layer, and Developer Mode.

Regression run
Base (main 06c9f55), NVIDIA GeForce RTX 5070 Ti:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 819 (PresentX 820)
presents per 2 s (last 3): 13 28 28
device removals: 0
crashes: 0
peak commit: 16053 MB

This PR (22133f3), same card:

xcl-smoke v1
commit: 22133f3abd080bdcdc0ff67703fadfb33bf0c06b
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 793 (PresentX 794)
presents per 2 s (last 3): 27 27 29
device removals: 0
crashes: 0
peak commit: 15746 MB

Earlier runs here ended at about 44 s on main and on this PR alike. The cause was #695: this PC had no active playback device. With one active, both runs reach their end.

Not tested

  • The direct DXIL backend: it still refuses ds_permute_b32.
  • A wave64 VS / PS without the refusal.
  • RDNA3 / RDNA4 and Intel.
  • Whether a retail title's code uses ds_permute_b32.

AI use

  • Claude Code (Claude Opus 5.5) did the work: it measured the instruction on the hardware, adapted Recompiler: translate ds_permute_b32 #925's emitted code, wrote the tests, ran the suites and the comparisons, and wrote this description.

🤖 Generated with Claude Code

Each active lane sends DATA0 to lane ((ADDR + offset) >> 2) & 31 of its own
32-lane half, in wave64 too; of several senders the highest lane wins, an
active lane nobody sends to gets 0, inactive lanes take no part. Each
receiver looks at the 32 senders of its half (rla_half_fn, as ds_swizzle),
so the split wave64 form needs no exchange. A wave64 VS / PS that may run in
32-lane waves still refuses it: upper_lanes does not model its writes to
lanes 32..63.

The model was measured on an RDNA2 gfx1036 in native wave64 and wave32
(26 cases: collisions, partial EXEC, high address bits, cross-half
addresses), and matches the measurements reported on xcl-dev#925. The emitted
code follows xcl-dev#925 by @maximecmb, which was closed unmerged.

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

Copy link
Copy Markdown
Contributor

Independent RX 6800M verification on exact PR head 22133f3abd080bdcdc0ff67703fadfb33bf0c06b (base 568e7db7729c8fa6c8f0f4b32d798faaf11462bb). Both worktrees were clean, built with separate Cargo targets.

Environment: Windows 11 build 26200, Ryzen 9 5980HX, Radeon RX 6800M (RDNA2), driver 30.0.13002.13003, Rust 1.99 MSVC, DXC/DXIL 1.9.2609.5. XCL_ADAPTER=6800M.

Focused tests: cargo test --locked -p xcl --lib -j 2 ds_permute -- --test-threads=1 --show-output on the PR head, with XCL_REQUIRE_GPU=wave64 and XCL_DIRECT_DXIL=0: 3 passed, 0 failed, 0 ignored. This includes gpu_ds_permute_b32; there were no SKIPPED lines. The reference-model and graphics refusal tests also passed. cargo build --release --locked -p xcl -j 2 passed for both base and PR head.

Paired guarded retail smoke: Same locally owned title (title: 2ef5fd64), default HLSL path, separate fresh XCL_DATA_ROOT and XCL_DXIL_CACHE per run, XCL_ADAPTER=6800M, networking disabled. Each run was scheduled for 12 seconds and ended normally:

Revision Exit Frames shown / PresentX Last three 2-second present counts Device removals Crashes Peak commit
Base 568e7db 0x0 190 / 190 60, 61, 60 0 0 8,245 MB
PR 22133f3 0x0 115 / 115 0, 54, 60 0 0 8,193 MB

The different startup time makes the frame totals unsuitable as a performance comparison. The title logs show no dispatches in this window, so the smoke run does not exercise ds_permute_b32; the focused GPU test does.

I also attempted a 60-second base run. An external safety monitor stopped it after about 24 seconds when available commit fell to 952 MB (physical free 988 MB); it produced no xcl-smoke completion block. At 18 seconds, the log had reached 54 presents in the prior 2 seconds and reported 9,245 MB process commit. I did not attempt a 60-second PR run under the same memory pressure. Thus this report does not satisfy the PR's required clean 60-second regression pair or remove its draft blocker.

AI assistance: OpenAI Codex (GPT-6; exact variant not exposed) prepared the isolated runs, checked the logs and revisions, and drafted this report. No game data or shaders are attached.

@cindertheblue

Copy link
Copy Markdown
Contributor

Tested the head 22133f3 on RDNA3 (listed as untested), in native wave64, plus a second gfx1036 driver. The three tests pass on both GPUs, and the two changes you used as controls (half bit dropped, offset dropped) make gpu_ds_permute_b32 fail on both.

Tested

  • AMD Radeon RX 7600 XT 16 GB (RDNA3, Navi 33, native wave64), driver 32.0.31041.1004, and the Ryzen 5 9600X iGPU (RDNA2, gfx1036), driver 32.0.21045.5002, on the same machine. Windows 11 Home 26200.9974, rustc 1.99.1, DXC 1.8.2502.11 (SDK 10.0.26100), debug, its own Cargo target, cargo build --workspace first, no local changes.
  • cargo test -p xcl --lib ds_permute -- --test-threads=1 --nocapture (the three new tests):
RX 7600 XT iGPU gfx1036
head, 3 runs 3 passed ×3 3 passed ×3
head, XCL_REQUIRE_GPU=wave64 3 passed –
head, XCL_DIRECT_DXIL=1 3 passed –
{t}_h = 0u (half bit dropped) gpu_ds_permute_b32 fails: wave64 split=false lane 32: v10 same
{t}_a = {a}; (offset dropped) gpu_ds_permute_b32 fails: wave64 split=false lane 1: v12 same
emit.rs from 568e7db 2 fail: {"ds_permute_b32: DS": 5} and {"ds_permute_b32: LDS outside compute": 1} same
head merged onto main 6d12f58 (clean merge) 3 passed 3 passed

No SKIPPED lines in any of these. The native wave64 form runs here: the half-bit failure is in wave64 split=false.

  • cargo test --workspace --no-fail-fast -- --test-threads=4, once each, against 568e7db on the same machine:
568e7db this PR
RX 7600 XT 1153 passed, 1 failed, 46 ignored 1156 passed, 1 failed, 46 ignored
RX 7600 XT, XCL_DIRECT_DXIL=all 1151 passed, 3 failed, 46 ignored 1154 passed, 3 failed, 46 ignored
iGPU 1153 passed, 1 failed, 46 ignored 1156 passed, 1 failed, 46 ignored

The 3 extra passes are the new tests. The failures are the same on both trees: fuzz_validate_and_gpu_1 (#2115: seed 722 on the RX 7600 XT, 540 on the iGPU), and with XCL_DIRECT_DXIL=all also gpu_image_get_resinfo_1d_array (#2046) and offline_compute_pipeline_is_reused_by_a_second_process (#1674). The same 8 SKIPPED lines in all six runs.

Not tested: a release build, a title or smoke run, RDNA4, a wave64 VS / PS using ds_permute_b32.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this comment from their output.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…upstream xcl-dev#2222)

LATER shared semantics: the backend-independent ds_permute_reference
model (no 32-lane-half crossing, highest sender wins, inactive lanes
neither send nor receive) + the hardware-pinned value test land
verbatim in recomp/tests.rs. The HLSL/DXIL emit halves stay out for
the future SPIR-V path.
NWProgramming00 added a commit to NWProgramming00/xcl that referenced this pull request Nov 26, 2026
The direct translator refused ds_permute_b32. It now lowers it as the
HLSL path (xcl-dev#2222) and RDNA2 hardware do: each active lane sends DATA0 to
lane ((ADDR + offset) >> 2) & 31 of its own 32-lane half; of several
senders the highest wins, an active lane nobody sends to gets 0. Each
receiver reads the 32 senders of its half in lane order (unrolled)
through read_lane_half, so the split form needs no exchange. A wave64
VS / PS that may run in 32-lane waves still refuses it.

gpu_ds_permute_b32 runs its cases through the direct translator too
(gpu_ds_permute_b32_direct), whatever XCL_DIRECT_DXIL says.

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

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Tested head 22133f3abd080bdcdc0ff67703fadfb33bf0c06b, merge-base 568e7db7729c8fa6c8f0f4b32d798faaf11462bb, RTX 3070 (Ampere) driver 616.56, Windows 11, rustc 1.100.0

  • cargo test -p xcl --lib -- ds_permute_reference_matches_rdna2_values gpu_ds_permute_b32 ds_permute_b32_refused_where_upper_lanes_do_not_exist --test-threads=1 --nocapture, 3 runs on head: 3 passed, 0 failed (each run), 0 skips.
  • Negative control: the PR's tests.rs hunk applied alone to the merge-base (compiles): 1 passed, 2 failed. gpu_ds_permute_b32 and ds_permute_b32_refused_where_upper_lanes_do_not_exist fail there; the reference-model test passes (it does not call the translator).
  • cargo test -p xcl --lib -- --test-threads=4: head 1101 passed, 0 failed, 26 ignored; merge-base (unmodified) 1098 passed, 0 failed, 26 ignored.
  • SKIPPED lines (24, same set on both): 20 "no wave64" (32-lane waves only), 3 refused f16/conversion fixtures (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426), 1 driver-cache test needing Windows Developer Mode.

Not tested: retail title; direct DXIL; AMD wave64 hardware.

AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #2222 at head 22133f3abd080bdcdc0ff67703fadfb33bf0c06b (1 commit; exact parent & merge-base: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, Wave32-only Ada), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (22133f3a)

Command Result
cargo test --release -p xcl --lib ds_permute_reference_matches_rdna2_values -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1126 filtered out × 3 (0.00s × 3, 0 skipped)
cargo test --release -p xcl --lib gpu_ds_permute_b32 -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1126 filtered out × 3 (0.24s, 0.23s, 0.24s, 0 skipped; live RTX 4060 execution)
cargo test --release -p xcl --lib ds_permute_b32_refused_where_upper_lanes_do_not_exist -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1126 filtered out × 3 (0.00s × 3, 0 skipped)
cargo test --release -p xcl --lib gpu::recomp::tests:: -- --test-threads=4 (3 consecutive runs) 150 passed; 0 failed; 17 ignored; 960 filtered out × 3 (5.24s, 5.27s, 5.51s; 2 tests self-skipped: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware — no wave64 on Wave32-only Ada; 148 executed)
cargo build --release -p xcl Clean build (1m 02s, exit 0, 0 new warnings)

Paired quiet 60 s retail smoke (title: 29640639)

Exact parent & merge-base (568e7db7729c8fa6c8f0f4b32d798faaf11462bb, same machine):

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1587 (PresentX 1587)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14527 MB

PR #2222 (22133f3abd080bdcdc0ff67703fadfb33bf0c06b):

xcl-smoke v1
commit: 22133f3abd080bdcdc0ff67703fadfb33bf0c06b
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1574 (PresentX 1574)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14497 MB

Limits of coverage

  • ds_permute_b32 HLSL lowering (collisions, partial EXEC, high address bits, cross-half addresses, and refusal for wave64 VS/PS in 32-lane waves) was directly verified on desktop RTX 4060 via all 3 new tests (3/3 each, 0 skipped) and gpu::recomp::tests:: (148 executed, 0 failed, 2 Wave64-only tests self-skipped on Wave32-only Ada).
  • Native Wave64 hardware execution was not exercised on Wave32-only Ada; the 60 s retail smoke confirms zero runtime regression on title: 29640639 (single-run frame/commit delta vs. parent reflects normal startup variance, not this PR).

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

@SzczepanGrela

Copy link
Copy Markdown

RX 9070 / RADV / Wine verification of exact head 22133f3abd080bdcdc0ff67703fadfb33bf0c06b, current main c2ee10e4e905eb736e56953c52b749e18bcc7ede and the PR automatically applied to that main. This adds RDNA4 HLSL kernel coverage, including native wave64 and split wave64.

Tested

  • RX 9070 16 GB, RADV GFX1201 / Mesa 26.3.1-arch3.5, Ryzen 7 7700, CachyOS 7.3.0-5-cachyos. Windows GNU release executables, Rust 1.97.1, GE-Proton11-12 / Wine 11.0 Staging, native DXGI/D3D12 through vkd3d-proton 8293130ebe370b1+ (local asserts-disabled build), DXC/DXIL 1.9.2602.17.
  • Separate source copies; conflict-free integration of the two-file delta from actual parent 568e7db7729c8fa6c8f0f4b32d798faaf11462bb. Test-only translation/container/readback captures and owned fixtures; production code and original assertions preserved. Main gets the identical three new tests and reference helper.
  • Build each: cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run --message-format=json-render-diagnostics.
  • Original filter through Wine: <unit.exe> ds_permute --nocapture --test-threads=1, then --test-threads=4.
Source Threads 1 Threads 4
Main + identical tests 1 passed, 2 failed 1 passed, 2 failed
Exact head 3 passed, 0 failed 3 passed, 0 failed
Current-main integration 3 passed, 0 failed 3 passed, 0 failed

Main passes the reference-model test; the GPU and graphics-refusal tests fail their translation assertions before any feature GPU dispatch. The first GPU fixture's translation records five unsupported ds_permute_b32 instructions. Head/integration execute the original GPU fixture in native wave32, native wave64 and split wave64; all five outputs match the independently recomputed reference.

Additional owned filter <unit.exe> workflow_forward_lane_matrix --nocapture --test-threads=1, three fresh processes per source. Head/integration: 1 passed, 0 failed in each of six runs, with 288 matrix dispatches per run. Each of the three modes runs 96 cases, using 38 immediate offsets: every multiple of 4 from 0 through 124, plus 1, 2, 3, 128, 65532 and 65535.

  • All 32 × 32 selected-sender/receiver routes per half, with other senders colliding at the neighboring destination. The upper half uses a different selected sender and distinct data tags.
  • Every possible highest active collision winner in each half, with different lower/upper prefix masks. Addresses 0xfffffffe and 0xfffffffd exercise addition before shifting and unsigned address wrap.
  • 32 further address/EXEC configurations, including no active lanes, full activity, one active half, sparse lane-edge masks and deterministic mixed addresses/masks.

The independent verifier scatters active senders in ascending order, then applies receiver activity. Every readback matches: no cross-half transfer, highest active sender wins, an uncovered active receiver gets zero, and inactive receivers keep their distinct input sentinels. This checks 3,502,080 matrix result slots, including inactive receivers. Head and current-main integration readbacks match byte-for-byte and repeat identically.

Main's additional filter passes only explicit CPU translation-refusal controls: 0 matrix GPU dispatches. The unchanged direct DXIL backend also refuses the same program in all three modes on every source; no fallback is counted as direct GPU coverage.

Across the original and owned groups: 1,752 captured GPU dispatches. There are 580 in each requested mode, plus 12 separate physical-width probes; 586 dispatches use physical native wave64, including its six probes. Independently verified 6,346,176 words, including input/result registers, 16 SGPR and 16 VGPR guards, unchanged SCC and complete flat-memory readbacks. Original and owned programs were independently re-encoded from the public ISA tables; shader metadata and physical widths agree. 0 ignored, 0 skipped, no device-removal markers.

Inherited XCL_* cleared; XCL_NETWORK=0, RX 9070 selected, XCL_REQUIRE_GPU=wave64, XCL_DIRECT_DXIL=0, XCL_DXC_THREADS=1; private enabled caches per process. The owned matrix explicitly selects each wave mode.

Not tested

Raw RDNA4 ISA measurements, direct DXIL GPU execution, graphics-stage GPU execution, guest Compute ABI integration, full suite, native Windows, other GPUs, retail workload, scripts/smoke.ps1, timing or FPS. The reference is the stated RDNA2 behavior, checked against XCL-generated kernels on RX 9070.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the diff, wrote the owned test-only matrix and captures, ran comparisons, independently verified routing, collision winners, masks, offsets, guards, wave widths and source/executable provenance, and drafted this report. Publication authorized by the account owner.

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.

6 participants