shader: lower v_mad_u64_u32 and v_mad_i64_i32 without INT64 #1654

Closed
github-bot wants to merge 2 commits from gh-pr/1654/head into gh-pr/1654/base
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 20:30 UTC · original
geiyiliyabumo:fix/shader-mad-64-32 → main · +285 −29 · 2 files · 2 commits · closed without merging

Summary

  • Lowers RDNA2 VOP3B 64-bit multiply-add instructions v_mad_u64_u32 (0x176) and v_mad_i64_i32 (0x177) in crates/victory-shader/src/emit/lower.rs (Lower::mad64 + Lower::mad64_addend).
  • Uses DXIL 32-bit UMul/IMul (dx.op.binaryWithTwoOuts.i32) and 32-bit carry propagation (add_sub_carry) so neither instruction sets the INT64 DXIL capability flag (SFI0 & 0x8000 == 0).
  • Matches AMD RDNA2 ISA §§6.5, 12.12 (and RDNA4 ISA §16.12) across all edge cases:
    • Writes both destination VGPRs vdst[0:1] under the active EXEC guard.
    • Writes sdst via write_mask (v.carry.or(v.dst)): unsigned carry-out (bit 64) for v_mad_u64_u32, and bit 64 (sign of the exact 65-bit sum: mul_sign ^ add_sign ^ carry_hi) for v_mad_i64_i32.
    • Supports CLAMP saturation (u64::MAX for unsigned; i64::MIN/i64::MAX on 64-bit signed overflow).
    • Expands 64-bit VGPR/SGPR pairs, signed/unsigned inline constants, and 32-bit literals for src2.

Verification

  • cargo test -p victory-shader --lib: 124 passed, 0 failed, 1 ignored on both AMD Radeon RX 9060 XT (D3D12 hardware) and Microsoft Basic Render Driver (WARP), including 4 new regression tests (v_mad_u64_u32_writes_both_dwords_and_carry, v_mad_i64_i32_writes_both_dwords_and_bit_64, v_mad_64_respects_exec, v_mad_64_reads_scalar_pairs_and_expands_immediates — 41 synthetic GPU dispatches verifying low/high dwords, sdst mask readback, CLAMP, EXEC masking, and SFI0 & 0x8000 == 0).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: pass (154 files).

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 20:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1654) `geiyiliyabumo:fix/shader-mad-64-32` → `main` · +285 −29 · 2 files · 2 commits · closed without merging ## Summary - Lowers RDNA2 VOP3B 64-bit multiply-add instructions `v_mad_u64_u32` (`0x176`) and `v_mad_i64_i32` (`0x177`) in `crates/victory-shader/src/emit/lower.rs` (`Lower::mad64` + `Lower::mad64_addend`). - Uses DXIL 32-bit `UMul`/`IMul` (`dx.op.binaryWithTwoOuts.i32`) and 32-bit carry propagation (`add_sub_carry`) so neither instruction sets the `INT64` DXIL capability flag (`SFI0 & 0x8000 == 0`). - Matches AMD RDNA2 ISA §§6.5, 12.12 (and RDNA4 ISA §16.12) across all edge cases: - Writes both destination VGPRs `vdst[0:1]` under the active `EXEC` guard. - Writes `sdst` via `write_mask` (`v.carry.or(v.dst)`): unsigned carry-out (bit 64) for `v_mad_u64_u32`, and bit 64 (sign of the exact 65-bit sum: `mul_sign ^ add_sign ^ carry_hi`) for `v_mad_i64_i32`. - Supports `CLAMP` saturation (`u64::MAX` for unsigned; `i64::MIN`/`i64::MAX` on 64-bit signed overflow). - Expands 64-bit VGPR/SGPR pairs, signed/unsigned inline constants, and 32-bit literals for `src2`. ## Verification - `cargo test -p victory-shader --lib`: **124 passed, 0 failed, 1 ignored** on both **AMD Radeon RX 9060 XT (D3D12 hardware)** and **Microsoft Basic Render Driver (WARP)**, including 4 new regression tests (`v_mad_u64_u32_writes_both_dwords_and_carry`, `v_mad_i64_i32_writes_both_dwords_and_bit_64`, `v_mad_64_respects_exec`, `v_mad_64_reads_scalar_pairs_and_expands_immediates` — 41 synthetic GPU dispatches verifying low/high dwords, `sdst` mask readback, `CLAMP`, `EXEC` masking, and `SFI0 & 0x8000 == 0`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: pass (154 files). *AI-assisted; synthetic tests only, no game files.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:40:02 +00:00
github-bot closed this pull request 2026-11-26 04:40:02 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 21:06 UTC · original

Updated in 3a08221: replaced dx.op.binaryWithTwoOuts.i32 (IMul/UMul) with pure 32-bit LLVM 16-bit partial-product wide multiplication (still zero INT64 flags in SFI0) so strict dxil.dll validation accepts the emitted DXIL. Re-verified with VICTORY_DXIL active on both AMD Radeon RX 9060 XT and WARP (17/17 valu_tests PASS, clippy clean, cargo xtask policy 154 files ok).

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 21:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1654#issuecomment-7144494767) Updated in `3a08221`: replaced `dx.op.binaryWithTwoOuts.i32` (`IMul`/`UMul`) with pure 32-bit LLVM 16-bit partial-product wide multiplication (still zero `INT64` flags in `SFI0`) so strict `dxil.dll` validation accepts the emitted DXIL. Re-verified with `VICTORY_DXIL` active on both **AMD Radeon RX 9060 XT** and **WARP** (17/17 `valu_tests` PASS, clippy clean, `cargo xtask policy` 154 files ok). *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:23 UTC · original

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

v_mad_u64_u32/v_mad_i64_i32 without 64-bit integers. Main lowers both (lower.rs:5214-5244) with i64, which the translator uses in many other places, so avoiding the INT64 flag here buys nothing.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 01:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1654#issuecomment-7149497927) Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. v_mad_u64_u32/v_mad_i64_i32 without 64-bit integers. Main lowers both (lower.rs:5214-5244) with i64, which the translator uses in many other places, so avoiding the INT64 flag here buys nothing. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:33 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1654#issuecomment-7149685830) <!-- victory-triage v1 head=3a08221a6246821ca9e441bbb5faf81cc9a03979 verdict=needs-rebase at=2026-11-25T01:33:33Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1654
No description provided.