Skip to content

[upstream #1022] Recompiler: ds_bpermute_b32 in wave64 stays in each 32-lane half (#772) - #115

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1022
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1022

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Branch fix/bpermute-wave64, commit 212fb96 on main 6efdabc. Not pushed.

Fixes xcl-dev#772.

What the hardware does

In native wave64 on RDNA2, ds_bpermute_b32 lets lane l read lane (l & 32) | (((addr + offset) >> 2) & 31). If that lane is inactive, the result is 0. Two people measured it:

XCL used & 63 and read across the halves. That follows the opcode table's "mod 64". The ACO lowering and both measurements disagree with it.

The change

emit.rs, "ds_bpermute_b32"

  • In wave64, the index is (lane_id & 32u) | (((addr + offset) >> 2) & 31u). Wave32 is unchanged.
  • The read goes through rla_half_fn, as ds_swizzle does.
  • Split wave64 needs no exchange any more, so xcl_x_rla_any and its 32-word exchange slot are removed.
  • In a 32-lane wave of a wave64 VS / PS, the permute can no longer reach lanes 32..63. The upper_lanes constant case (select(and(xcl_hw32, l >= 32), c, …)) is therefore removed.

upper_lanes.rs

docs/wave64-on-wave32.md

  • The exchange table, the memory slot, the cost paragraph and the VS / PS section now list ds_bpermute with the reads that stay inside their half.

The emitter's lines for wave64 in the split form:

before: uint {t}_l = (({addr} + {offset}u) >> 2) & 63u;                   uint {t} = xcl_x_rla_any({data}, {t}_l);
after:  uint {t}_l = (lane_id & 32u) | ((({addr} + {offset}u) >> 2) & 31u); uint {t} = xcl_x_rla_half({data}, {t}_l);

Test

The new test is gpu_ds_bpermute_wave64_stays_in_its_half. It uses source data 1000 + lane, so a 0 from an inactive lane can't be mistaken for lane 0. It runs seven cases and compares each with the measured model. It also checks these lanes from luckyteagirl's report directly:

  • 63 - lane: lane 0 reads 31, lane 32 reads 63, lane 63 reads 32
  • (lane + 1) & 63: lane 31 reads 0, lane 63 reads 32

Before (main 6efdabc with the new test): 226 wrong lanes. The counts per case match the "full-wave" column of certified-retart's table.

case wrong lanes
4 * lane (identity) 0
4 * (63 - lane) 64
4 * ((lane + 1) & 63) 2
4 * lane, offset:4 2
4 * lane, offset:128 64
4 * (63 - lane), offset:4 62
4 * (lane ^ 32), EXEC 0xAAAAAAAA_55555555 32

After: all seven cases match.

Three existing assertions encoded the cross-half reading and now expect the half-wave lanes. These are the same three that @NathanTheophile listed on the issue:

test old expectation new expectation
gpu_format_stores_atomics_global_lds 63 - l l ^ 31
gpu_split_wave64_cross_half_operations 63 - l l ^ 31
gpu_split_wave64_waves_diverge l ^ 33 l ^ 1

outside_whole_wave_code_the_upper_lanes_stay_unwritten now expects one read where it used to expect two. ds_bpermute is no longer a read of lanes ≥ 32, even after whole-wave code has written them.

Tested

RTX 3070, driver 616.56, Windows 11, DXC 1.8.2502.11. The command was cargo test --workspace --no-fail-fast -- --test-threads=4, in its own target dir.

passed failed ignored
main 6efdabc 727 0 41
212fb96 728 0 41

On both, the usual two tests were skipped (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware.

This GPU has 32-lane waves only, so every wave64 case above ran in the split form. The native wave64 path is not run here.

  • @NathanTheophile (RTX 4060 Laptop) and @SlopTart (RX 7900 XT, which also covers split wave64 forced on wave64 hardware) offered to run it.
  • On RADV the native wave64 form goes through ACO's own full-wave emulation of WaveReadLaneAt, so the explicit (lane_id & 32) index is what keeps it half-wave there.

Notes

Regression run
We have no retail title; this changes crates/xcl/src/gpu/recomp/emit.rs, so it needs one. Could someone with a title post the xcl-smoke blocks for main and this head?

main:

PR:

Not tested

AI use

  • AI-assisted (Claude Code): checked the hardware reports against the code, wrote the fix, the test and this description, and ran the tests above.

🤖 Generated with Claude Code


Mirror of xcl-dev#1022 (auto-synced, do not edit).

…-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>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1022 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1022 branch November 25, 2026 00:10
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.

Recompiler: ds_bpermute_b32 in wave64 may stay within each 32-lane half on RDNA2 (needs a hardware run)

2 participants