Shaders: lower v_swap_b32 and v_xnor_b32 #127

Closed
7ROBE wants to merge 1 commit from upstream-pr/127 into main
7ROBE commented 2026-11-24 00:43:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 7ROBE on 2026-11-24T00:43:26Z.


What is in it

  • Lowers RDNA2 v_swap_b32 (swapping two VGPRs under the active EXEC guard; ir.rs already marks both operands as read and written) in crates/victory-shader/src/emit/lower.rs.
  • Lowers RDNA2 v_xnor_b32 (~(src0 ^ src1)) in crates/victory-shader/src/emit/lower.rs.
  • Adds a synthetic compute-shader unit test v_xnor_b32_and_v_swap_b32_translate covering v_xnor_b32 and v_swap_b32 (distinct VGPRs and self-swap).

Refs #97.

Tested

  • cargo xtask policy: asset policy: 150 files ok
  • cargo test --workspace: 240 passed, 0 failed, 3 ignored (including emit::lower::tests::v_xnor_b32_and_v_swap_b32_translate)
  • cargo clippy --workspace --all-targets: passed (0 warnings)
  • rustfmt --check --edition 2024 crates/victory-shader/src/emit/lower.rs: passed

Hardware / OS

  • Windows 11 Pro (26H2), Intel Core i5-14600KF, AMD Radeon RX 9060 XT (Adrenalin 26.11.2)

AI-assisted

  • Yes (Antigravity / Gemini 3.1 Pro)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6571965726 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/127). Originally posted by [7ROBE](https://github.com/7ROBE) on 2026-11-24T00:43:26Z. --- ## What is in it - Lowers RDNA2 `v_swap_b32` (swapping two VGPRs under the active `EXEC` guard; `ir.rs` already marks both operands as read and written) in `crates/victory-shader/src/emit/lower.rs`. - Lowers RDNA2 `v_xnor_b32` (`~(src0 ^ src1)`) in `crates/victory-shader/src/emit/lower.rs`. - Adds a synthetic compute-shader unit test `v_xnor_b32_and_v_swap_b32_translate` covering `v_xnor_b32` and `v_swap_b32` (distinct VGPRs and self-swap). Refs #97. ## Tested - `cargo xtask policy`: `asset policy: 150 files ok` - `cargo test --workspace`: 240 passed, 0 failed, 3 ignored (including `emit::lower::tests::v_xnor_b32_and_v_swap_b32_translate`) - `cargo clippy --workspace --all-targets`: passed (0 warnings) - `rustfmt --check --edition 2024 crates/victory-shader/src/emit/lower.rs`: passed ## Hardware / OS - Windows 11 Pro (26H2), Intel Core i5-14600KF, AMD Radeon RX 9060 XT (Adrenalin 26.11.2) ## AI-assisted - Yes (Antigravity / Gemini 3.1 Pro)
raffclar commented 2026-11-24 06:54:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by raffclar on 2026-11-24T00:50:27Z.


This isn't needed anymore. #58 added them

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118488103 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/127#issuecomment-7118488103). Originally posted by [raffclar](https://github.com/raffclar) on 2026-11-24T00:50:27Z. --- This isn't needed anymore. #58 added them
tanishq-dubey commented 2026-11-24 06:54:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tanishq-dubey on 2026-11-24T00:53:49Z.


Related self-swap edge case on main at 9aef3d9: a synthetic compute shader that reads v1 after v_swap_b32 v1, v1 and stores it to a UAV fails translation with a value defined after its use (offset 36). The existing self-swap here is immediately followed by s_endpgm, so it may not exercise a later use.

In ir.rs, the same VGPR is recorded twice as a write; skipping the second write when v.dst.as_ref() == v.src.first() fixed the regression. An end-to-end synthetic test then returned both 0x12345678 and 0xffffffff unchanged on an RTX 5090 using Wine 11.22 and vkd3d-proton. No game assets used. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118547404 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/127#issuecomment-7118547404). Originally posted by [tanishq-dubey](https://github.com/tanishq-dubey) on 2026-11-24T00:53:49Z. --- Related self-swap edge case on `main` at `9aef3d9`: a synthetic compute shader that reads `v1` after `v_swap_b32 v1, v1` and stores it to a UAV fails translation with `a value defined after its use` (offset 36). The existing self-swap here is immediately followed by `s_endpgm`, so it may not exercise a later use. In `ir.rs`, the same VGPR is recorded twice as a write; skipping the second write when `v.dst.as_ref() == v.src.first()` fixed the regression. An end-to-end synthetic test then returned both `0x12345678` and `0xffffffff` unchanged on an RTX 5090 using Wine 11.22 and vkd3d-proton. No game assets used. AI-assisted.
DaviTostes commented 2026-11-24 06:54:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:10:06Z.


Tested 60e8adf on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 52 passed, 0 failed (2 test binaries), including the 1 test this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7118825530 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/127#issuecomment-7118825530). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:10:06Z. --- Tested `60e8adf` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **52 passed, 0 failed** (2 test binaries), including the 1 test this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425.
Lyrnc commented 2026-11-24 06:56:20 +00:00 (Migrated from github.com)

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


RDNA2 hardware check: both match.

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. 400 operand pairs (edge values and 300 random).

  • v_xnor_b32: ~(src0 ^ src1), 400/400.
  • v_swap_b32 v16, v17 with distinct registers swaps them, 400/400. v_swap_b32 v18, v18 leaves the register unchanged, 400/400 (your self-swap case).

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:7123869615 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/127#issuecomment-7123869615). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:22:39Z. --- RDNA2 hardware check: **both match.** **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. 400 operand pairs (edge values and 300 random). - `v_xnor_b32`: `~(src0 ^ src1)`, 400/400. - `v_swap_b32 v16, v17` with distinct registers swaps them, 400/400. `v_swap_b32 v18, v18` leaves the register unchanged, 400/400 (your self-swap case). 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.
Dathinel commented 2026-11-24 06:56:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-24T06:23:41Z.


I checked what remains to integrate after #58. On main@d2a4bae1, applying #127's test function without either lowering change gives 1 passed for v_xnor_b32_and_v_swap_b32_translate. Clippy also passes in that configuration.

With the full #127 change applied to the same main, cargo clippy --frozen -p victory-shader --features host --all-targets -- -D warnings reports two unreachable match arms in lower.rs, one for each opcode. The integrated file matches GitHub's test merge.

I'd drop the duplicate lowering changes. The added dst != src check is inside the unreachable swap arm. If you want to keep a distinct regression test here, the case reported on 9aef3d9 reads the register after swapping it with itself. The current test ends immediately after that instruction and checks translation. The RDNA2 measurement above supplies the expected register value for a readback test. AI tools assisted with the comparison.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123887188 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/127#issuecomment-7123887188). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-24T06:23:41Z. --- I checked what remains to integrate after #58. On `main@d2a4bae1`, applying #127's test function **without either lowering change** gives 1 passed for `v_xnor_b32_and_v_swap_b32_translate`. Clippy also passes in that configuration. With the full #127 change applied to the same main, `cargo clippy --frozen -p victory-shader --features host --all-targets -- -D warnings` reports two unreachable match arms in `lower.rs`, one for each opcode. The integrated file matches [GitHub's test merge](https://github.com/Marvisak/VIctory/blob/30207725678a77da2d5b9b5fdb6d1b1d5c981a3f/crates/victory-shader/src/emit/lower.rs). I'd drop the duplicate lowering changes. The added `dst != src` check is inside the unreachable swap arm. If you want to keep a distinct regression test here, the [case reported on `9aef3d9`](https://github.com/Marvisak/VIctory/pull/127#issuecomment-7118547404) reads the register after swapping it with itself. The current test ends immediately after that instruction and checks translation. The [RDNA2 measurement above](https://github.com/Marvisak/VIctory/pull/127#issuecomment-7123869615) supplies the expected register value for a readback test. AI tools assisted with the comparison.
upstream-sync closed this pull request 2026-11-24 09:04:59 +00:00

Pull request closed

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!127
No description provided.