Recompiler: translate ds_permute_b32 as RDNA2 runs it #2222

Open
github-bot wants to merge 1 commit from github-bot/gh-2222 into main AGit
Owner

@⁠NWProgramming00 on GitHub · 2026-11-25 10:19 UTC · original
NWProgramming00:recomp/ds-permute → main · +134 −0 · 2 files · 1 commits · open

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 #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 #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 #925's emitted code, wrote the tests, ran the suites and the comparisons, and wrote this description.

🤖 Generated with Claude Code

**@⁠NWProgramming00** on GitHub · 2026-11-25 10:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/2222) `NWProgramming00:recomp/ds-permute` → `main` · +134 −0 · 2 files · 1 commits · open `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 #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 #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 #925's emitted code, wrote the tests, ran the suites and the comparisons, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/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 #925. The emitted
code follows #925 by @maximecmb, which was closed unmerged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:23:41 +00:00
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 10:32 UTC · original

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.

**@⁠luckyteagirl** on GitHub · 2026-11-25 10:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/2222#issuecomment-7159839861) 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.
Author
Owner

@⁠cindertheblue on GitHub · 2026-11-25 21:33 UTC · original

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.

  • For reference, the raw instruction on this RDNA3 card follows the same model as your RDNA2 measurements. In my OpenCL probe on #772, 11 ds_permute_b32 cases in native wave64 (full and partial EXEC, offsets 0, 2, 4, 128, 132, 65532) gave the half-wave result on all 64 lanes, as did the same cases on this gfx1036.

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.

**@⁠cindertheblue** on GitHub · 2026-11-25 21:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/2222#issuecomment-7175238962) 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. - For reference, the raw instruction on this RDNA3 card follows the same model as your RDNA2 measurements. In my OpenCL probe on #772, 11 `ds_permute_b32` cases in native wave64 (full and partial `EXEC`, offsets 0, 2, 4, 128, 132, 65532) gave the half-wave result on all 64 lanes, as did the same cases on this gfx1036. **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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2222/head:github-bot/gh-2222'
git switch 'github-bot/gh-2222'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2222'
git switch 'github-bot/gh-2222'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2222'
git switch 'github-bot/gh-2222'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2222'
git switch 'main'
git merge --squash 'github-bot/gh-2222'
git switch 'main'
git merge --ff-only 'github-bot/gh-2222'
git switch 'main'
git merge 'github-bot/gh-2222'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.