Shaders: scope wave64 ds_bpermute_b32 to 32-lane halves #573

Merged
banbanzhige merged 1 commit from upstream-pr/573 into main 2026-11-25 21:39:36 +00:00
banbanzhige commented 2026-11-24 05:10:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by banbanzhige on 2026-11-24T05:10:26Z.


Summary

0b35b7f added ds_bpermute_b32 lowering in victory-shader::emit::lower::Lower::ds, masking the source lane with ((addr + offset) >> 2) & (self.wave() - 1).

On RDNA 2 / GFX10 (AMD RDNA 2 ISA §10.4.4, and confirmed on gfx1036 hardware in this thread), Wave64 ds_bpermute_b32 operates on two independent 32-lane halves (0..31 and 32..63) rather than permuting across all 64 lanes.

This PR fixes that Wave64 half-wave semantics bug and adds regression coverage:

  • Masks the dword lane index to ((addr + offset) >> 2) & 31 and, when wave64 is set, preserves the calling lane's half with (self.lane_index() & !31) | within_half while reusing main's existing waveActiveBallot + Lower::lane_bit_of active-lane check.
  • Adds cross-platform offline tests in emit::lower::tests (ds_bpermute_wave64_preserves_32_lane_half and ds_bpermute_refuses_gds, backed by #[cfg(test)]-only inspection helpers on bitcode::Module / Lowered) so Wave64 half-wave emission is verified even without a Wave64 GPU.
  • Adds synthetic permute tests in emit::synthetic_tests alongside permutes_read_the_lane_named_and_zero_from_lanes_left_out (following 42363ab / ccfb029's adapter-skip convention):
    • permutes_mask_high_address_bits_and_divergent_branches (Wave32: high/sub-dword address bit masking + divergent s_cbranch_execz zeroing)
    • wave64_permutes_stay_within_each_32_lane_half (Wave64: half-wave isolation, wrap-around, and high/sub-dword bit masking)
    • wave64_permutes_check_exec_within_each_half (Wave64: per-half EXEC masking so upper-half lanes pulling inactive upper-half lanes read 0 even when the corresponding lower-half lanes are active)

Validation

Rebased onto main (ccfb029, head 8b96041):

  • rustfmt --edition 2024 --check crates/victory-shader/src/emit/bitcode.rs crates/victory-shader/src/emit/synthetic_tests.rs — 0 diffs (0 diffs in modified hunks of lower.rs)
  • cargo clippy --workspace --all-targets --locked -- -D warnings — 0 warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — 0 warnings
  • cargo test --locked -p victory-shader --lib permute — 6 passed, 0 failed:
    • 2 cross-platform offline tests passed (including DXIL validation)
    • 2 Wave32 synthetic tests executed and passed on this machine's 32-lane hardware D3D12 GPU
    • 2 Wave64 synthetic tests passed DXIL validation and skipped pipeline creation on this 32-lane GPU (the same Wave64 half-wave lowering was previously hardware-verified on AMD RX 7900 XTX RDNA3 and 7800X3D RDNA2 in this thread)
  • cargo xtask policy — 182 files ok
  • Offline shader corpus A/B (victory translate <shaders.rpf> --validate, 26,503 containers / 26,084 programs, dxil.dll 10.0.26100.0) against 42363ab:
    • VS/PS: 14,205 emitted / 14,205 validated (unchanged, 0 regressions)
    • CS: 2,621 emitted / 1,886 validated (unchanged, 0 regressions)
    • MS: 8,765 emitted / 8,694 validated (unchanged, 0 regressions)

AI-assisted implementation; semantics, tests, and asset-policy checks verified locally.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575111971 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573). Originally posted by [banbanzhige](https://github.com/banbanzhige) on 2026-11-24T05:10:26Z. --- ## Summary `0b35b7f` added `ds_bpermute_b32` lowering in `victory-shader::emit::lower::Lower::ds`, masking the source lane with `((addr + offset) >> 2) & (self.wave() - 1)`. On RDNA 2 / GFX10 (AMD RDNA 2 ISA §10.4.4, and confirmed on gfx1036 hardware in this thread), Wave64 `ds_bpermute_b32` operates on **two independent 32-lane halves** (`0..31` and `32..63`) rather than permuting across all 64 lanes. This PR fixes that Wave64 half-wave semantics bug and adds regression coverage: - Masks the dword lane index to `((addr + offset) >> 2) & 31` and, when `wave64` is set, preserves the calling lane's half with `(self.lane_index() & !31) | within_half` while reusing `main`'s existing `waveActiveBallot` + `Lower::lane_bit_of` active-lane check. - Adds cross-platform offline tests in `emit::lower::tests` (`ds_bpermute_wave64_preserves_32_lane_half` and `ds_bpermute_refuses_gds`, backed by `#[cfg(test)]`-only inspection helpers on `bitcode::Module` / `Lowered`) so Wave64 half-wave emission is verified even without a Wave64 GPU. - Adds synthetic permute tests in `emit::synthetic_tests` alongside `permutes_read_the_lane_named_and_zero_from_lanes_left_out` (following `42363ab` / `ccfb029`'s adapter-skip convention): - `permutes_mask_high_address_bits_and_divergent_branches` (Wave32: high/sub-dword address bit masking + divergent `s_cbranch_execz` zeroing) - `wave64_permutes_stay_within_each_32_lane_half` (Wave64: half-wave isolation, wrap-around, and high/sub-dword bit masking) - `wave64_permutes_check_exec_within_each_half` (Wave64: per-half `EXEC` masking so upper-half lanes pulling inactive upper-half lanes read `0` even when the corresponding lower-half lanes are active) ## Validation Rebased onto `main` (`ccfb029`, head `8b96041`): - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/bitcode.rs crates/victory-shader/src/emit/synthetic_tests.rs` — 0 diffs (0 diffs in modified hunks of `lower.rs`) - `cargo clippy --workspace --all-targets --locked -- -D warnings` — 0 warnings - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` — 0 warnings - `cargo test --locked -p victory-shader --lib permute` — 6 passed, 0 failed: - 2 cross-platform offline tests passed (including DXIL validation) - 2 Wave32 synthetic tests executed and passed on this machine's 32-lane hardware D3D12 GPU - 2 Wave64 synthetic tests passed DXIL validation and skipped pipeline creation on this 32-lane GPU (the same Wave64 half-wave lowering was previously hardware-verified on AMD RX 7900 XTX RDNA3 and 7800X3D RDNA2 in this thread) - `cargo xtask policy` — 182 files ok - Offline shader corpus A/B (`victory translate <shaders.rpf> --validate`, 26,503 containers / 26,084 programs, `dxil.dll` 10.0.26100.0) against `42363ab`: - VS/PS: `14,205` emitted / `14,205` validated (unchanged, 0 regressions) - CS: `2,621` emitted / `1,886` validated (unchanged, 0 regressions) - MS: `8,765` emitted / `8,694` validated (unchanged, 0 regressions) _AI-assisted implementation; semantics, tests, and asset-policy checks verified locally._
Raxstreams commented 2026-11-24 06:55:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Raxstreams on 2026-11-24T05:12:15Z.


I tested the related split-wave implementation on an RTX 3080 Ti. On RDNA2 the wave64 case uses two independent 32-lane groups for this instruction (AMD RDNA 2 ISA, section 10.4). That matters for the & 63 in the PR description. For example, with all lanes active and values equal to their lane IDs, a byte address of zero in destination lane 32 should select lane 32. A full-wave permutation would select lane 0.

The two 64-result fixtures in r4tedx/VIctory#2 cover the group boundary, offset wrap and masked lanes. Both passed on the 3080 Ti. A real checkerboard shadow-mask shader using that implementation also created its D3D12 pipeline and ran 460,800 GPU invocations in a captured scene. Those results are for the linked implementation. I have not run this PR head on a wave64 GPU.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122722875 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7122722875). Originally posted by [Raxstreams](https://github.com/Raxstreams) on 2026-11-24T05:12:15Z. --- I tested the related split-wave implementation on an RTX 3080 Ti. On RDNA2 the wave64 case uses two independent 32-lane groups for this instruction (AMD RDNA 2 ISA, section 10.4). That matters for the `& 63` in the PR description. For example, with all lanes active and values equal to their lane IDs, a byte address of zero in destination lane 32 should select lane 32. A full-wave permutation would select lane 0. The two 64-result fixtures in [r4tedx/VIctory#2](https://github.com/r4tedx/VIctory/pull/2) cover the group boundary, offset wrap and masked lanes. Both passed on the 3080 Ti. A real checkerboard shadow-mask shader using that implementation also created its D3D12 pipeline and ran 460,800 GPU invocations in a captured scene. Those results are for the linked implementation. I have not run this PR head on a wave64 GPU.
banbanzhige commented 2026-11-24 06:56:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by banbanzhige on 2026-11-24T05:36:54Z.


Good catch, thanks for pointing that out! You are completely right — on RDNA 2 (ISA §10.4), ds_bpermute_b32 in wave64 operates as two independent 32-lane halves rather than permuting across all 64 lanes.

I have pushed a follow-up commit to mask ((addr + offset) >> 2) to & 31 and preserve (lane & !31) in wave64 (keeping the wave32 path unchanged), updated the PR description, and added two wave64 synthetic tests in valu_tests.rs covering the 32-lane group boundary, offset wrap-around, and per-half EXEC masking (DXIL-validated on a 32-lane GPU; ready to execute all 64 lanes on a native wave64 device).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123112525 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7123112525). Originally posted by [banbanzhige](https://github.com/banbanzhige) on 2026-11-24T05:36:54Z. --- Good catch, thanks for pointing that out! You are completely right — on RDNA 2 (ISA §10.4), `ds_bpermute_b32` in wave64 operates as two independent 32-lane halves rather than permuting across all 64 lanes. I have pushed a follow-up commit to mask `((addr + offset) >> 2)` to `& 31` and preserve `(lane & !31)` in wave64 (keeping the wave32 path unchanged), updated the PR description, and added two wave64 synthetic tests in `valu_tests.rs` covering the 32-lane group boundary, offset wrap-around, and per-half `EXEC` masking (DXIL-validated on a 32-lane GPU; ready to execute all 64 lanes on a native wave64 device).
iurysf commented 2026-11-24 06:56:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T06:17:06Z.


Tested offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17:

  • Translation failures: 3,733 on main -> 3,728 with this PR (-5, all compute). "an LDS operation" (4 -> 0) and "LDS the program does not allocate" (1 -> 0) disappear; compute emitted/validated 1,693/1,670 -> 1,698/1,675, matching your numbers.
  • Vertex/pixel and mesh unchanged; no program that validated on main fails now (185 rejected on both).

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123775030 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7123775030). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-24T06:17:06Z. --- Tested offline against main `d2a4bae` with `victory translate --list --validate` over the title's `shaders.rpf` + executable (26,096 programs), dxil.dll 1.9.2602.17: - Translation failures: 3,733 on main -> 3,728 with this PR (-5, all compute). "an LDS operation" (4 -> 0) and "LDS the program does not allocate" (1 -> 0) disappear; compute emitted/validated 1,693/1,670 -> 1,698/1,675, matching your numbers. - Vertex/pixel and mesh unchanged; no program that validated on main fails now (185 rejected on both). AI-assisted.
Lyrnc commented 2026-11-24 06:56:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:26:49Z.


RDNA2 hardware check of the wave64 point raised above: ds_bpermute_b32 in wave64 works on two independent 32-lane halves, as your follow-up commit models.

Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. Lane i holds i + 1, the byte address is 4 * source. Wave32 and wave64 kernels, all lanes active.

Pattern (source lane) wave32 wave64
all lanes address 0 every lane reads lane 0 lanes 0-31 read lane 0, lanes 32-63 read lane 32
reverse (n - 1 - i) lane 31 - i lanes 0-31: 31 - i; lanes 32-63: 95 - i (reverse within the half)
(i + 33) % 64 (i + 1) & 31 (i & 32) | ((i + 1) & 31)
i + 1 (i + 1) & 31 (i & 32) | ((i + 1) & 31)

So the address selects lane (addr >> 2) & 31 within the lane's own half (i & 32), in all 4 patterns × 2 wave sizes. A full 64-lane index matches none of the wave64 patterns. That is the & 31 plus lane & !31 in your follow-up.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123941340 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7123941340). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:26:49Z. --- RDNA2 hardware check of the wave64 point raised above: **`ds_bpermute_b32` in wave64 works on two independent 32-lane halves**, as your follow-up commit models. **Setup.** AMD Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036 (RDNA2)**, AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. Lane `i` holds `i + 1`, the byte address is `4 * source`. Wave32 and wave64 kernels, all lanes active. | Pattern (source lane) | wave32 | wave64 | |---|---|---| | all lanes address 0 | every lane reads lane 0 | lanes 0-31 read lane 0, **lanes 32-63 read lane 32** | | reverse (`n - 1 - i`) | lane `31 - i` | lanes 0-31: `31 - i`; lanes 32-63: `95 - i` (reverse within the half) | | `(i + 33) % 64` | `(i + 1) & 31` | `(i & 32) \| ((i + 1) & 31)` | | `i + 1` | `(i + 1) & 31` | `(i & 32) \| ((i + 1) & 31)` | So the address selects lane `(addr >> 2) & 31` within the lane's own half (`i & 32`), in all 4 patterns × 2 wave sizes. A full 64-lane index matches none of the wave64 patterns. That is the `& 31` plus `lane & !31` in your follow-up. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
slint6614-dev commented 2026-11-24 11:04:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T10:16:57Z.


AMD hardware check attempt (RX 9070 / RDNA2 iGPU, Windows 11): at the PR head the victory-shader tests do not compile:

error[E0061]: this function takes 2 arguments but 1 argument was supplied
    --> crates\victory-shader\src\emit\lower.rs:7012:13
7012 |             lowers(&words).unwrap();
     |             ^^^^^^-------- argument #2 of type `u32` is missing

lowers gained an rsrc2 argument on main (#612 / #719), so this call needs lowers(&words, 0). The new ds_bpermute_b32_* GPU tests could not run until that is fixed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7128564295 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7128564295). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T10:16:57Z. --- AMD hardware check attempt (RX 9070 / RDNA2 iGPU, Windows 11): at the PR head the `victory-shader` tests **do not compile**: ``` error[E0061]: this function takes 2 arguments but 1 argument was supplied --> crates\victory-shader\src\emit\lower.rs:7012:13 7012 | lowers(&words).unwrap(); | ^^^^^^-------- argument #2 of type `u32` is missing ``` `lowers` gained an `rsrc2` argument on main (#612 / #719), so this call needs `lowers(&words, 0)`. The new `ds_bpermute_b32_*` GPU tests could not run until that is fixed.
slint6614-dev commented 2026-11-24 11:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T10:42:28Z.


Measured on the full retail shader pack (26,503 containers) with victory translate --validate --pipelines (pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. Merged locally with current main c7a5f49 (main: CS 1440 / 1417 / 1440).

CS 1445 / 1422 / 1445 (+5 validated): the ds_bpermute_b32 refusals are gone and those programs validate. VS/PS and MS unchanged. (The tests still need the lowers(&words, 0) fix, see above.)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129137617 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7129137617). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T10:42:28Z. --- Measured on the full retail shader pack (26,503 containers) with `victory translate --validate --pipelines` (pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. Merged locally with current main c7a5f49 (main: CS 1440 / 1417 / 1440). CS **1445 / 1422** / 1445 (+5 validated): the `ds_bpermute_b32` refusals are gone and those programs validate. VS/PS and MS unchanged. (The tests still need the `lowers(&words, 0)` fix, see above.)
banbanzhige commented 2026-11-24 11:04:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by banbanzhige on 2026-11-24T10:46:33Z.


Thanks for testing on AMD hardware! That lowers(&words) error was in our previous base commit (58fed37), which main fixed in 8e79c80.

I've rebased this branch onto main (ffe310e) — picking up 8e79c80, resolving the ONE_AT_A_TIME conflict from #566, and updating the test resource::track calls to the new 4-argument signature. Both cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings and cargo test --workspace --locked pass locally, so it's ready to test on RX 9070 / RDNA2 Wave64 now.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129228869 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7129228869). Originally posted by [banbanzhige](https://github.com/banbanzhige) on 2026-11-24T10:46:33Z. --- Thanks for testing on AMD hardware! That `lowers(&words)` error was in our previous base commit (`58fed37`), which `main` fixed in `8e79c80`. I've rebased this branch onto `main` (`ffe310e`) — picking up `8e79c80`, resolving the `ONE_AT_A_TIME` conflict from #566, and updating the test `resource::track` calls to the new 4-argument signature. Both `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` and `cargo test --workspace --locked` pass locally, so it's ready to test on RX 9070 / RDNA2 Wave64 now.
Halfect commented 2026-11-24 11:04:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Halfect on 2026-11-24T11:03:24Z.


Independent check of the rebased head 1d09f19 on Windows 11:

  • cargo test --locked -p victory-shader --lib -- --test-threads=1: 127 passed, 0 failed, 1 ignored.
  • All 7 ds_bpermute tests passed. The three Wave32 synthetic execution tests ran successfully on the default D3D12 hardware adapter. WARP was unavailable.
  • The two Wave64 tests passed DXIL validation, but fixed WaveSize(64) pipeline creation returned E_INVALIDARG on this adapter; they are not claimed as 64-lane hardware executions here.
  • cargo clippy --locked -p victory-shader --lib --tests -- -D warnings: clean.
  • cargo xtask policy: 154 files ok.

The earlier lowers(&words) / E0061 compile failure is gone at this head. No game data or title execution used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129596605 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7129596605). Originally posted by [Halfect](https://github.com/Halfect) on 2026-11-24T11:03:24Z. --- Independent check of the rebased head `1d09f19` on Windows 11: - `cargo test --locked -p victory-shader --lib -- --test-threads=1`: **127 passed, 0 failed, 1 ignored**. - All 7 `ds_bpermute` tests passed. The three Wave32 synthetic execution tests ran successfully on the default D3D12 hardware adapter. WARP was unavailable. - The two Wave64 tests passed DXIL validation, but fixed `WaveSize(64)` pipeline creation returned `E_INVALIDARG` on this adapter; they are **not** claimed as 64-lane hardware executions here. - `cargo clippy --locked -p victory-shader --lib --tests -- -D warnings`: clean. - `cargo xtask policy`: **154 files ok**. The earlier `lowers(&words)` / `E0061` compile failure is gone at this head. No game data or title execution used.
catminou4 commented 2026-11-24 13:01:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:44:21Z.

Review: APPROVED


Solid ds_bpermute_b32 lowering. The semantics match the RDNA2 ISA description in the comment: backward pull permute within the lane's own 32-lane half (((addr + offset) >> 2) & 31, with the wave64 high-half base OR'd in), zero when the source lane is inactive, and GDS correctly rejected. The refactor extracting mask_bit from the existing ballot helper avoids duplication.

Test coverage is good:

  • ds_bpermute_lowers_without_lds_in_wave32_and_wave64 and ds_bpermute_refuses_gds run on macOS (lowering-level).
  • The new run_wave_cs harness in valu_tests.rs is a proper host-execution test (hardware + WARP, DXIL validation fallback, fixed-wave-size skips) — it's #[cfg(windows)]-gated like the rest of that suite, so it will exercise the permute on the Windows CI lane.

Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 98 passed / 0 failed / 1 ignored (Windows-gated execution tests not run here, as usual).

<!-- greyfinch-sync:Marvisak/VIctory:review:6039402229 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#pullrequestreview-6039402229). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:44:21Z. **Review:** APPROVED --- Solid `ds_bpermute_b32` lowering. The semantics match the RDNA2 ISA description in the comment: backward pull permute within the lane's own 32-lane half (`((addr + offset) >> 2) & 31`, with the wave64 high-half base OR'd in), zero when the source lane is inactive, and GDS correctly rejected. The refactor extracting `mask_bit` from the existing ballot helper avoids duplication. Test coverage is good: - `ds_bpermute_lowers_without_lds_in_wave32_and_wave64` and `ds_bpermute_refuses_gds` run on macOS (lowering-level). - The new `run_wave_cs` harness in `valu_tests.rs` is a proper host-execution test (hardware + WARP, DXIL validation fallback, fixed-wave-size skips) — it's `#[cfg(windows)]`-gated like the rest of that suite, so it will exercise the permute on the Windows CI lane. Verified locally: test-merge with current main (`ffe310e`) clean; `cargo test -p victory-shader --locked` (macOS arm64, rustc 1.98.1) → **98 passed / 0 failed / 1 ignored** (Windows-gated execution tests not run here, as usual).
bvtterbroot commented 2026-11-24 18:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by bvtterbroot on 2026-11-24T17:54:39Z.


AMD check at 1d09f19 (base ffe310e), on an RDNA3 and an RDNA2 GPU:

  • Windows 11, Rust 1.98.1. Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010) and the Ryzen 7 7800X3D's iGPU (RDNA2, gfx1036, driver 32.0.21045.29003). I picked each as the hardware device of run_cases with a local adapter-selection patch that is not part of this PR. WARP runs in each pass as well.
  • cargo test -p victory-shader -p victory-gpu --locked: 177 passed, 0 failed, 2 ignored, on both GPUs. That includes its 7 new tests (ds_bpermute_b32_divergent_branch_zeroes_skipped_lanes, ds_bpermute_b32_gathers_with_offset_and_wrap, ds_bpermute_b32_wave64_exec_mask_per_half, ds_bpermute_b32_wave64_stays_within_each_32_lane_half, ds_bpermute_b32_zeroes_inactive_source_and_preserves_inactive_dst, ds_bpermute_lowers_without_lds_in_wave32_and_wave64, ...).

Synthetic tests only, no game files. Tested with AI assistance (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139881333 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7139881333). Originally posted by [bvtterbroot](https://github.com/bvtterbroot) on 2026-11-24T17:54:39Z. --- AMD check at `1d09f19` (base `ffe310e`), on an RDNA3 and an RDNA2 GPU: - Windows 11, Rust 1.98.1. Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010) and the Ryzen 7 7800X3D's iGPU (RDNA2, gfx1036, driver 32.0.21045.29003). I picked each as the hardware device of `run_cases` with a local adapter-selection patch that is not part of this PR. WARP runs in each pass as well. - `cargo test -p victory-shader -p victory-gpu --locked`: **177 passed, 0 failed**, 2 ignored, on both GPUs. That includes its 7 new tests (`ds_bpermute_b32_divergent_branch_zeroes_skipped_lanes`, `ds_bpermute_b32_gathers_with_offset_and_wrap`, `ds_bpermute_b32_wave64_exec_mask_per_half`, `ds_bpermute_b32_wave64_stays_within_each_32_lane_half`, `ds_bpermute_b32_zeroes_inactive_source_and_preserves_inactive_dst`, `ds_bpermute_lowers_without_lds_in_wave32_and_wave64`, ...). Synthetic tests only, no game files. _Tested with AI assistance (Claude Code)._
Melow-code commented 2026-11-24 23:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-24T23:02:18Z.


Thanks for this. We wrote the same lowering in our fork (fxceless/victory-gta6) and got the same result. The index is ((addr + offset) >> 2) & 31, the base is lane & !31 in wave64, and a ballot zeroes reads from inactive source lanes.

Rebase note. Main has its own ds_bpermute_b32 block in Lower::ds since 0b35b7f (24 Nov). That block masks the lane with self.wave() - 1, so in wave64 it reads across the two halves. The RDNA2 check by Lyrnc in this thread and ISA section 10.4.4 show that this is wrong. This is probably the conflict on the PR. To fix it:

  1. Keep one block.
  2. Use the index and the half base from this PR.
  3. Keep the ballot, and use the existing lane_bit_of in place of the new mask_bit. They do the same test.

Tests we can add, if they help:

  • An address with high bits (0x104 gives lane 1). This shows that the instruction uses only bits 6:2.
  • A wave32 program with 48 threads. The second wave has 16 lanes, and indices 16 to 31 must read 0.
  • A CPU model of ds_bpermute_b32 and ds_permute_b32 from ISA sections 10.4.4 and 12.13, with the ISA examples as tests.

Gap. Main does not lower ds_permute_b32 (scatter) yet. We can send the scatter model and an explicit refusal as a separate PR.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146939322 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7146939322). Originally posted by [Melow-code](https://github.com/Melow-code) on 2026-11-24T23:02:18Z. --- Thanks for this. We wrote the same lowering in our fork (fxceless/victory-gta6) and got the same result. The index is `((addr + offset) >> 2) & 31`, the base is `lane & !31` in wave64, and a ballot zeroes reads from inactive source lanes. **Rebase note.** Main has its own `ds_bpermute_b32` block in `Lower::ds` since 0b35b7f (24 Nov). That block masks the lane with `self.wave() - 1`, so in wave64 it reads across the two halves. The RDNA2 check by Lyrnc in this thread and ISA section 10.4.4 show that this is wrong. This is probably the conflict on the PR. To fix it: 1. Keep one block. 2. Use the index and the half base from this PR. 3. Keep the ballot, and use the existing `lane_bit_of` in place of the new `mask_bit`. They do the same test. **Tests we can add, if they help:** - An address with high bits (`0x104` gives lane 1). This shows that the instruction uses only bits 6:2. - A wave32 program with 48 threads. The second wave has 16 lanes, and indices 16 to 31 must read 0. - A CPU model of `ds_bpermute_b32` and `ds_permute_b32` from ISA sections 10.4.4 and 12.13, with the ISA examples as tests. **Gap.** Main does not lower `ds_permute_b32` (scatter) yet. We can send the scatter model and an explicit refusal as a separate PR.
Melow-code commented 2026-11-25 00:06:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-24T23:14:48Z.


Here are three tests for the half-wave semantics, written in the style of valu_tests.rs. They cover:

  1. High address bits — byte address 0x104 (dword index 65, low 5 bits = 1) reads lane 1 of the calling half, not lane 65.
  2. Host lane past the console — 48 threads on two host wave32s: an address naming dword 16 in the second half reads zero through the EXEC ballot.
  3. CPU reference — reproduces both ISA §12.13 examples bit-for-bit (EXEC=0xF and EXEC=0xA).

The CPU reference function:

fn bpermute(src: &[u32], addresses: &[u32], offset: u32, exec: u64, wave64: bool) -> Vec<Option<u32>> {
    let lanes = if wave64 { 64 } else { 32 };
    (0..lanes)
        .map(|l| {
            if exec >> l & 1 == 0 { return None; }
            let idx = usize::from(((addresses[l].wrapping_add(offset)) >> 2) & 31);
            let base = if wave64 { l & 32 } else { 0 };
            let s = base | idx;
            Some(if exec >> s & 1 == 0 { 0 } else { src[s] })
        })
        .collect()
}

Happy to send the full file as a PR if it helps.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7147181489 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7147181489). Originally posted by [Melow-code](https://github.com/Melow-code) on 2026-11-24T23:14:48Z. --- Here are three tests for the half-wave semantics, written in the style of `valu_tests.rs`. They cover: 1. **High address bits** — byte address `0x104` (dword index 65, low 5 bits = 1) reads lane 1 of the calling half, not lane 65. 2. **Host lane past the console** — 48 threads on two host wave32s: an address naming dword 16 in the second half reads zero through the EXEC ballot. 3. **CPU reference** — reproduces both ISA §12.13 examples bit-for-bit (EXEC=0xF and EXEC=0xA). The CPU reference function: ```rust fn bpermute(src: &[u32], addresses: &[u32], offset: u32, exec: u64, wave64: bool) -> Vec<Option<u32>> { let lanes = if wave64 { 64 } else { 32 }; (0..lanes) .map(|l| { if exec >> l & 1 == 0 { return None; } let idx = usize::from(((addresses[l].wrapping_add(offset)) >> 2) & 31); let base = if wave64 { l & 32 } else { 0 }; let s = base | idx; Some(if exec >> s & 1 == 0 { 0 } else { src[s] }) }) .collect() } ``` Happy to send the full file as a PR if it helps.
Marvisak commented 2026-11-25 01:07:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:26:49Z.


Automated triage for the maintainers.

Merge candidate.

This fixes the wave64 ds_bpermute_b32 lowering in Lower::ds (crates/victory-shader/src/emit/lower.rs). On main the source lane is ((addr + offset) >> 2) & (wave - 1), which lets wave64 read across all 64 lanes. The PR masks the index with & 31 and, in wave64, ORs in the calling lane's half (lane_index() & !31). The existing ballot / lane_bit_of check for inactive source lanes is kept. This matches the RDNA 2 ISA (section 10.4.4) and the gfx1036 hardware results posted in this thread. Wave32 is unchanged. The new synthetic tests cover the half boundary, wrap-around, high address bits and per-half EXEC. The offline test checks that the half mask is only emitted for wave64. The test-only helpers on Module and Lowered are #[cfg(test)].

CI (check) passes on this head.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148518575 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7148518575). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:26:49Z. --- <!-- victory-triage v1 head=92a23a06a7e422157d902904c41cfcb05158ba29 verdict=merge-candidate at=2026-11-25T16:48:22Z --> Automated triage for the maintainers. **Merge candidate.** This fixes the wave64 `ds_bpermute_b32` lowering in `Lower::ds` (`crates/victory-shader/src/emit/lower.rs`). On main the source lane is `((addr + offset) >> 2) & (wave - 1)`, which lets wave64 read across all 64 lanes. The PR masks the index with `& 31` and, in wave64, ORs in the calling lane's half (`lane_index() & !31`). The existing ballot / `lane_bit_of` check for inactive source lanes is kept. This matches the RDNA 2 ISA (section 10.4.4) and the gfx1036 hardware results posted in this thread. Wave32 is unchanged. The new synthetic tests cover the half boundary, wrap-around, high address bits and per-half EXEC. The offline test checks that the half mask is only emitted for wave64. The test-only helpers on `Module` and `Lowered` are `#[cfg(test)]`. CI (`check`) passes on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync changed title from [PR #573] Shaders: lower ds_bpermute_b32 to [PR #573] Shaders: scope wave64 ds_bpermute_b32 to 32-lane halves 2026-11-25 02:02:57 +00:00
banbanzhige commented 2026-11-25 02:06:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by banbanzhige on 2026-11-25T01:27:49Z.


Rebased onto main (ccfb029, head 8b96041) and resolved the conflicts from 0b35b7f:

  • Re-scoped this PR to fix the Wave64 half-wave indexing bug in 0b35b7f's ds_bpermute_b32 lowering (& (self.wave() - 1) → (self.lane_index() & !31) | (((addr + offset) >> 2) & 31) per RDNA 2 ISA §10.4.4).
  • Dropped the redundant mask_bit helper and reused main's Lower::lane_bit_of (thanks @Melow-code for the rebase note).
  • Moved the synthetic permute tests into emit::synthetic_tests alongside permutes_read_the_lane_named_and_zero_from_lanes_left_out (removing the valu_tests.rs conflict), added high-address-bit (0x100 + +3) masking and divergent s_cbranch_execz coverage, and added an offline Wave64 half-wave check in emit::lower::tests.

Verified locally: clippy (default and --all-features) clean, cargo test --locked -p victory-shader --lib permute 6/6 passed, cargo xtask policy 182 files ok, and full shaders.rpf --validate A/B shows 0 regressions. Ready for review (and a Wave64 AMD hardware re-check if helpful).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149573811 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7149573811). Originally posted by [banbanzhige](https://github.com/banbanzhige) on 2026-11-25T01:27:49Z. --- Rebased onto `main` (`ccfb029`, head `8b96041`) and resolved the conflicts from `0b35b7f`: - Re-scoped this PR to fix the Wave64 half-wave indexing bug in `0b35b7f`'s `ds_bpermute_b32` lowering (`& (self.wave() - 1)` → `(self.lane_index() & !31) | (((addr + offset) >> 2) & 31)` per RDNA 2 ISA §10.4.4). - Dropped the redundant `mask_bit` helper and reused `main`'s `Lower::lane_bit_of` (thanks @Melow-code for the rebase note). - Moved the synthetic permute tests into `emit::synthetic_tests` alongside `permutes_read_the_lane_named_and_zero_from_lanes_left_out` (removing the `valu_tests.rs` conflict), added high-address-bit (`0x100` + `+3`) masking and divergent `s_cbranch_execz` coverage, and added an offline Wave64 half-wave check in `emit::lower::tests`. Verified locally: `clippy` (default and `--all-features`) clean, `cargo test --locked -p victory-shader --lib permute` 6/6 passed, `cargo xtask policy` 182 files ok, and full `shaders.rpf --validate` A/B shows 0 regressions. Ready for review (and a Wave64 AMD hardware re-check if helpful).
Melow-code commented 2026-11-25 13:01:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-25T12:05:32Z.

Review: APPROVED


The half-wave masking is correct: idx = ((addr + offset) >> 2) & 31, source lane = (WaveGetLaneIndex() & !31) | idx, inactive lanes stay zero through the ballot guard. This matches the RDNA2 ISA §10.4.4 ds_bpermute_b32 description and the gfx1036 hardware results from the thread.

We independently implemented and verified the same lowering on a fork (commit fa92ce0): CPU reference against all 1024 permutations, ballot-based liveness, wave32 passthrough. The semantics are identical.

The rebase on ccfb029 and the added tests (high-address-bits, divergent execz, offline wave64) look clean. No regressions.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:review:6057282688 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#pullrequestreview-6057282688). Originally posted by [Melow-code](https://github.com/Melow-code) on 2026-11-25T12:05:32Z. **Review:** APPROVED --- The half-wave masking is correct: `idx = ((addr + offset) >> 2) & 31`, source lane = `(WaveGetLaneIndex() & !31) | idx`, inactive lanes stay zero through the ballot guard. This matches the RDNA2 ISA §10.4.4 `ds_bpermute_b32` description and the gfx1036 hardware results from the thread. We independently implemented and verified the same lowering on a fork (commit fa92ce0): CPU reference against all 1024 permutations, ballot-based liveness, wave32 passthrough. The semantics are identical. The rebase on ccfb029 and the added tests (high-address-bits, divergent execz, offline wave64) look clean. No regressions. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
banbanzhige commented 2026-11-25 17:05:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by banbanzhige on 2026-11-25T16:20:24Z.


Rebased cleanly onto main (67e8ae1, head 95c761e), resolving the emit/synthetic_tests.rs conflict and adding view_marks: false to Parts in the offline test. clippy (default + --all-features), permute/bitcode/synthetic_tests, and cargo xtask policy all pass locally.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167799427 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/573#issuecomment-7167799427). Originally posted by [banbanzhige](https://github.com/banbanzhige) on 2026-11-25T16:20:24Z. --- Rebased cleanly onto `main` (`67e8ae1`, head `95c761e`), resolving the `emit/synthetic_tests.rs` conflict and adding `view_marks: false` to `Parts` in the offline test. `clippy` (default + `--all-features`), `permute`/`bitcode`/`synthetic_tests`, and `cargo xtask policy` all pass locally.
upstream-sync closed this pull request 2026-11-25 22:02:40 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!573
No description provided.