Skip to content

Recompiler: translate ds_permute_b32 as RDNA2 runs it - #2222

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

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

Conversation

@NWProgramming00

Copy link
Copy Markdown

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), NVIDIA GeForce RTX 5070 Ti:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x80000003
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0 1 0
device removals: 0
crashes: 2
peak commit: 11500 MB

This PR, same card:

xcl-smoke v1
commit: 22133f3abd080bdcdc0ff67703fadfb33bf0c06b
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x80000003
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 2
peak commit: 11502 MB

On this machine the title currently exits the same way on main and on this PR, at the same point in the run with the same exit code. I checked this on both adapters (the Radeon pair matches), with a fresh XCL_DATA_ROOT and a fresh XCL_DXIL_CACHE for each run. Earlier today a build that contains this main ran the same title here for 20 minutes without that exit, so the cause is on this machine and not in this change. So these blocks show no difference between base and PR, but they cannot meet the no-crash rule. This PR stays a draft until I can replace both blocks with runs that reach their end, or someone with a working title posts a pair.

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.

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.

2 participants