Shaders: lower v_mad_u64_u32 and v_mad_i64_i32 #171

Open
github-bot wants to merge 1 commit from github-bot/gh-171 into main AGit
Owner

@⁠n-romanovich on GitHub · 2026-11-24 01:05 UTC · original
n-romanovich:feat/valu-mad64 → main · +162 −8 · 2 files · 1 commits · open

Summary

emit::lower previously lowered v_mad_u64_u32 and v_mad_i64_i32 in crates/victory-shader/src/emit/lower.rs, but only emitted the carry-out lane mask (SDST) for the unsigned form, causing shaders that read v_mad_i64_i32's SDST to be refused.

This PR adds signed carry-out for v_mad_i64_i32 as bit 64 of the exact 65-bit result, refuses clamp on both instructions, and adds a GPU execution test.

Changes

  • crates/victory-shader/src/emit/lower.rs (v_mad_u64_u32 | v_mad_i64_i32):
    • Refuse v.clamp with Err("a clamped integer operation").
    • Compute sum = prod + acc and unsigned carry ucarry = sum < prod (equivalent to sum < acc).
    • For v_mad_i64_i32 (signed == true), derive the signed carry-out (bit 64 of the exact 65-bit signed result) as ucarry ^ (prod < 0) ^ (acc < 0) and write carry to self.lane_bits for v.carry on both signed and unsigned forms.
  • crates/victory-shader/src/emit/mod.rs (emit::tests::valu_mad64_executes_on_gpu):
    • Add a GPU execution test covering v_mad_u64_u32 and v_mad_i64_i32 carry-out across -3 * 5 + 0, -3 * 5 + 25, and -15 + i64::MIN, as well as v.clamp refusal.

Verification

  • Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti.
  • cargo test -p victory-shader --locked -- mad64: 1 passed; 0 failed (emit::tests::valu_mad64_executes_on_gpu ... ok).
  • No game data used.
  • AI-assisted (authored and verified with Antigravity).
**@⁠n-romanovich** on GitHub · 2026-11-24 01:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/171) `n-romanovich:feat/valu-mad64` → `main` · +162 −8 · 2 files · 1 commits · open ### Summary `emit::lower` previously lowered `v_mad_u64_u32` and `v_mad_i64_i32` in `crates/victory-shader/src/emit/lower.rs`, but only emitted the carry-out lane mask (`SDST`) for the unsigned form, causing shaders that read `v_mad_i64_i32`'s `SDST` to be refused. This PR adds signed carry-out for `v_mad_i64_i32` as bit 64 of the exact 65-bit result, refuses `clamp` on both instructions, and adds a GPU execution test. ### Changes - `crates/victory-shader/src/emit/lower.rs` (`v_mad_u64_u32` | `v_mad_i64_i32`): - Refuse `v.clamp` with `Err("a clamped integer operation")`. - Compute `sum = prod + acc` and unsigned carry `ucarry = sum < prod` (equivalent to `sum < acc`). - For `v_mad_i64_i32` (`signed == true`), derive the signed carry-out (bit 64 of the exact 65-bit signed result) as `ucarry ^ (prod < 0) ^ (acc < 0)` and write `carry` to `self.lane_bits` for `v.carry` on both signed and unsigned forms. - `crates/victory-shader/src/emit/mod.rs` (`emit::tests::valu_mad64_executes_on_gpu`): - Add a GPU execution test covering `v_mad_u64_u32` and `v_mad_i64_i32` carry-out across `-3 * 5 + 0`, `-3 * 5 + 25`, and `-15 + i64::MIN`, as well as `v.clamp` refusal. ### Verification - Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti. - `cargo test -p victory-shader --locked -- mad64`: `1 passed; 0 failed` (`emit::tests::valu_mad64_executes_on_gpu ... ok`). - No game data used. - AI-assisted (authored and verified with Antigravity).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:53:13 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:19 UTC · original

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

  • cargo test -p victory-shader: 57 passed, 0 failed (2 test binaries), including the 1 test this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7118988306) Tested `60b63b4` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **57 passed, 0 failed** (2 test binaries), including the 1 test this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used.
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-24 01:29 UTC · original

The unsigned form looks right. For v_mad_i64_i32, though, the SDST bit isn't signed overflow. AMD's machine-readable ISA spec defines it as { D1.i1, D0.i64 } = 65'I(S0.i32) * 65'I(S1.i32) + 65'I(S2.i64), so D1 is bit 64 of the exact 65-bit sum, i.e. unsigned_carry ^ sign(prod) ^ sign(acc). The overflow check at crates/victory-shader/src/emit/lower.rs:3540 gives a different result whenever the true sum is negative and doesn't overflow: for example, -3 * 5 + 0 should set the bit, but here it's 0. The test cases (10 and i64::MIN - 15) agree under both definitions, so they don't catch it.

#163 lowers the same two opcodes (wide_mad, lower.rs:5043 there) with the 65-bit form, and it also refuses clamp, which this version ignores.

Static review, not built or run.

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 01:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7119151595) The unsigned form looks right. For `v_mad_i64_i32`, though, the SDST bit isn't signed overflow. AMD's machine-readable ISA spec defines it as `{ D1.i1, D0.i64 } = 65'I(S0.i32) * 65'I(S1.i32) + 65'I(S2.i64)`, so D1 is bit 64 of the exact 65-bit sum, i.e. `unsigned_carry ^ sign(prod) ^ sign(acc)`. The overflow check at `crates/victory-shader/src/emit/lower.rs:3540` gives a different result whenever the true sum is negative and doesn't overflow: for example, `-3 * 5 + 0` should set the bit, but here it's 0. The test cases (`10` and `i64::MIN - 15`) agree under both definitions, so they don't catch it. #163 lowers the same two opcodes (`wide_mad`, `lower.rs:5043` there) with the 65-bit form, and it also refuses `clamp`, which this version ignores. Static review, not built or run.
Author
Owner

@⁠n-romanovich on GitHub · 2026-11-24 01:42 UTC · original

Thanks for the review, @⁠Sunkiller-qc!

Addressed in a5af45f:

  • Updated v_mad_i64_i32 carry-out to compute bit 64 of the 65-bit sum (unsigned_carry ^ sign(prod) ^ sign(acc)).
  • Refused v.clamp on both v_mad_u64_u32 and v_mad_i64_i32.
  • Added the -3 * 5 + 0 (SDST = 1) case to valu_mad64_executes_on_gpu and re-verified cargo test -p victory-shader (70 passed) on D3D12 (RTX 5060 Ti).
**@⁠n-romanovich** on GitHub · 2026-11-24 01:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7119366401) Thanks for the review, @⁠Sunkiller-qc! Addressed in `a5af45f`: - Updated `v_mad_i64_i32` carry-out to compute bit 64 of the 65-bit sum (`unsigned_carry ^ sign(prod) ^ sign(acc)`). - Refused `v.clamp` on both `v_mad_u64_u32` and `v_mad_i64_i32`. - Added the `-3 * 5 + 0` (`SDST = 1`) case to `valu_mad64_executes_on_gpu` and re-verified `cargo test -p victory-shader` (70 passed) on D3D12 (RTX 5060 Ti).
Author
Owner

@⁠r4tedx on GitHub · 2026-11-24 01:42 UTC · original

A note from comparing this with #163, which lowers the same two instructions: the 64-bit results agree, but the carry-out of v_mad_i64_i32 differs. This PR writes signed overflow of the 64-bit add; AMD's references define the flag as the top bit of the 65-bit result:

  • RDNA 3 ISA (Feb 2023), V_MAD_I64_I32: { D1.i1, D0.i64 } = 65'B(65'I(S0.i) * 65'I(S1.i) + 65'I(S2.i64))
  • RDNA 2 ISA, opcode 375: {vcc_out,D.i64} = S0.i32 * S1.i32 + S2.i64

With the operands sign-extended to 65 bits, bit 64 is the unsigned carry out of bit 63 xor the signs of the product and the addend. The two differ when both addends are negative and the add does not overflow, e.g. (-1) * 1 + (-1) = -2: bit 64 is 1, signed overflow is 0. The unsigned form here (sum < prod) matches the reference.

I have not run this on hardware; the above is from the documents only. No game data used.

**@⁠r4tedx** on GitHub · 2026-11-24 01:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7119371764) A note from comparing this with #163, which lowers the same two instructions: the 64-bit results agree, but the carry-out of `v_mad_i64_i32` differs. This PR writes signed overflow of the 64-bit add; AMD's references define the flag as the top bit of the 65-bit result: - RDNA 3 ISA (Feb 2023), `V_MAD_I64_I32`: `{ D1.i1, D0.i64 } = 65'B(65'I(S0.i) * 65'I(S1.i) + 65'I(S2.i64))` - RDNA 2 ISA, opcode 375: `{vcc_out,D.i64} = S0.i32 * S1.i32 + S2.i64` With the operands sign-extended to 65 bits, bit 64 is the unsigned carry out of bit 63 xor the signs of the product and the addend. The two differ when both addends are negative and the add does not overflow, e.g. `(-1) * 1 + (-1) = -2`: bit 64 is 1, signed overflow is 0. The unsigned form here (`sum < prod`) matches the reference. I have not run this on hardware; the above is from the documents only. No game data used.
Author
Owner

@⁠n-romanovich on GitHub · 2026-11-24 01:44 UTC · original

Thanks, @⁠r4tedx! This was updated in a5af45f to compute bit 64 of the 65-bit sum (unsigned_carry ^ sign(prod) ^ sign(acc)), so cases like -3 * 5 + 0 and (-1) * 1 + (-1) set SDST = 1 per the RDNA2/RDNA3 ISA spec.

**@⁠n-romanovich** on GitHub · 2026-11-24 01:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7119398414) Thanks, @⁠r4tedx! This was updated in `a5af45f` to compute bit 64 of the 65-bit sum (`unsigned_carry ^ sign(prod) ^ sign(acc)`), so cases like `-3 * 5 + 0` and `(-1) * 1 + (-1)` set `SDST = 1` per the RDNA2/RDNA3 ISA spec.
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-24 06:26 UTC · original

RDNA2 hardware measurement of both instructions, including the carry-out discussed above: the current head (a5af45f) has the hardware's rule.

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. 748 operand sets: all combinations of 0, 1, 3, 5, 0x7fffffff, 0x80000000, 0xffffffff, 0xfffffffd for the two 32-bit sources and 0, 1, 0xffffffff, 2^64-1, 2^63, 2^63-1, 0xffffffff00000000 for the 64-bit addend, plus 300 random sets. The carry SGPR was read with v_cndmask_b32.

match
v_mad_u64_u32: 64-bit result, carry = bit 64 of a*b + c 748/748
v_mad_i64_i32: 64-bit result 748/748
v_mad_i64_i32: carry = bit 64 of the 65-bit signed result 748/748
v_mad_i64_i32: carry = signed overflow of the 64-bit add (the earlier rule) 385/748

Both of your examples set the flag on the hardware: -3 * 5 + 0 → 1 and (-1) * 1 + (-1) → 1.

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.

**@⁠Lyrnc** on GitHub · 2026-11-24 06:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7123938726) RDNA2 hardware measurement of both instructions, including the carry-out discussed above: **the current head (`a5af45f`) has the hardware's rule.** **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. 748 operand sets: all combinations of `0, 1, 3, 5, 0x7fffffff, 0x80000000, 0xffffffff, 0xfffffffd` for the two 32-bit sources and `0, 1, 0xffffffff, 2^64-1, 2^63, 2^63-1, 0xffffffff00000000` for the 64-bit addend, plus 300 random sets. The carry SGPR was read with `v_cndmask_b32`. | | match | |---|---| | `v_mad_u64_u32`: 64-bit result, carry = bit 64 of `a*b + c` | 748/748 | | `v_mad_i64_i32`: 64-bit result | 748/748 | | `v_mad_i64_i32`: carry = **bit 64 of the 65-bit signed result** | **748/748** | | `v_mad_i64_i32`: carry = signed overflow of the 64-bit add (the earlier rule) | 385/748 | Both of your examples set the flag on the hardware: `-3 * 5 + 0` → 1 and `(-1) * 1 + (-1)` → 1. 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.
Author
Owner

@⁠DeerSilver on GitHub · 2026-11-24 10:51 UTC · original

Tested head f4a24e1 merged onto main ffe310e on NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1. No game files: the test suite only.

Merged onto current main, the test build fails. 6638098 ("per-lane descriptors chosen by control flow", merged with #566 at 09:53) added a fourth argument to resource::track:

error[E0061]: this function takes 4 arguments but 3 arguments were supplied
  --> crates/victory-shader/src/emit/mod.rs (in the new test)
   |     resource::track(&p, &native.layout, native.stage)
   |     argument #4 of type `Option<&structure::Structured>` is missing

There's no text conflict, so GitHub still shows the PR as mergeable, but merging it as it is would break cargo test on main. The call this PR adds needs the fourth argument. main's own tests pass Some(&st); None keeps the old three-argument behaviour.

With , None added locally to that one call, everything passes:

  • The PR's GPU test ran on the RTX 5060 (DXGI adapter 0 on this laptop; no "no SM 6.6 device" skip) and passed:
    • valu_mad64_executes_on_gpu
  • cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored, against 342 passed / 6 ignored on main.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.

AI-assisted (Claude Code).

**@⁠DeerSilver** on GitHub · 2026-11-24 10:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7129328486) Tested head `f4a24e1` merged onto `main` `ffe310e` on **NVIDIA GeForce RTX 5060 Laptop GPU** (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1. No game files: the test suite only. **Merged onto current `main`, the test build fails.** `6638098` ("per-lane descriptors chosen by control flow", merged with #566 at 09:53) added a fourth argument to `resource::track`: ``` error[E0061]: this function takes 4 arguments but 3 arguments were supplied --> crates/victory-shader/src/emit/mod.rs (in the new test) | resource::track(&p, &native.layout, native.stage) | argument #4 of type `Option<&structure::Structured>` is missing ``` There's no text conflict, so GitHub still shows the PR as mergeable, but merging it as it is would break `cargo test` on `main`. The call this PR adds needs the fourth argument. `main`'s own tests pass `Some(&st)`; `None` keeps the old three-argument behaviour. **With `, None` added locally to that one call**, everything passes: - The PR's GPU test ran on the RTX 5060 (DXGI adapter 0 on this laptop; no "no SM 6.6 device" skip) and passed: - `valu_mad64_executes_on_gpu` - `cargo test --workspace --locked`: **343 passed, 0 failed, 6 ignored**, against 342 passed / 6 ignored on `main`. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. AI-assisted (Claude Code).
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:23 UTC · original

Merged onto main @ ffe310eb, this PR (f4a24e1e) no longer compiles its tests. crates/victory-shader/src/emit/mod.rs:835 calls resource::track with 3 arguments. Since 6638098c it takes a 4th, lanes: Option<&Structured>; main's tests pass Some(&st) with let st = structure::structure(&p).unwrap();.

Checked with CI's steps (both clippy runs with -D warnings, cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87

**@⁠alexdeliu** on GitHub · 2026-11-24 17:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7139117063) Merged onto `main` @ `ffe310eb`, this PR (`f4a24e1e`) no longer compiles its tests. `crates/victory-shader/src/emit/mod.rs:835` calls `resource::track` with 3 arguments. Since 6638098c it takes a 4th, `lanes: Option<&Structured>`; main's tests pass `Some(&st)` with `let st = structure::structure(&p).unwrap();`. <sub>Checked with CI's steps (both clippy runs with `-D warnings`, `cargo test --workspace`) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87</sub>
Author
Owner

@⁠n-romanovich on GitHub · 2026-11-24 17:53 UTC · original

Thanks for testing and pointing this out, @⁠alexdeliu!

Merged latest main and updated resource::track in the test to pass Some(&st) per 6638098c. Verified with cargo clippy --all-targets --locked -- -D warnings and re-ran the GPU test — both compile cleanly and pass with 0 warnings.

**@⁠n-romanovich** on GitHub · 2026-11-24 17:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7139865546) Thanks for testing and pointing this out, @⁠alexdeliu! Merged latest main and updated resource::track in the test to pass Some(&st) per 6638098c. Verified with cargo clippy --all-targets --locked -- -D warnings and re-ran the GPU test — both compile cleanly and pass with 0 warnings.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:56 UTC · original

@⁠n-romanovich rechecked 9dc6a7e3 merged onto main @ ffe310eb on the RX 9070: both CI clippy runs are clean and cargo test --workspace passes (343 tests).

**@⁠alexdeliu** on GitHub · 2026-11-24 17:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7139915473) @⁠n-romanovich rechecked `9dc6a7e3` merged onto `main` @ `ffe310eb` on the RX 9070: both CI clippy runs are clean and `cargo test --workspace` passes (343 tests).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:20 UTC · original · edited 2026-11-25 02:30 UTC

Automated triage for the maintainers.

Recommended for a maintainer's look. The verdict hasn't changed. The new head is a rebase onto current main (940d32f). In crates/victory-shader/src/emit/lower.rs (v_mad_u64_u32 | v_mad_i64_i32), the signed carry-out is bit 64 of the exact 65-bit result (unsigned carry ^ sign(prod) ^ sign(acc)), and clamp is refused. This matches the ISA pseudocode and Lyrnc's RDNA2 measurement (748/748). I rechecked the test's expected values by hand.

A small optional addition: the two signed cases in valu_mad64_executes_on_gpu (-3*5+25 and -3*5 + i64::MIN) give the same carry under the old signed-overflow rule. The -3*5+0 case from the earlier thread, with carry 1, isn't in this head. Adding it back would make the test catch a regression to the old rule.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7148407282) · edited 2026-11-25 02:30 UTC <!-- victory-triage v1 head=d1d21f9c707667483ee08350106f3f70a4c40334 verdict=merge-candidate at=2026-11-25T02:20:29Z --> Automated triage for the maintainers. **Recommended for a maintainer's look.** The verdict hasn't changed. The new head is a rebase onto current `main` (940d32f). In `crates/victory-shader/src/emit/lower.rs` (`v_mad_u64_u32 | v_mad_i64_i32`), the signed carry-out is bit 64 of the exact 65-bit result (`unsigned carry ^ sign(prod) ^ sign(acc)`), and `clamp` is refused. This matches the ISA pseudocode and Lyrnc's RDNA2 measurement (748/748). I rechecked the test's expected values by hand. A small optional addition: the two signed cases in `valu_mad64_executes_on_gpu` (`-3*5+25` and `-3*5 + i64::MIN`) give the same carry under the old signed-overflow rule. The `-3*5+0` case from the earlier thread, with carry 1, isn't in this head. Adding it back would make the test catch a regression to the old rule. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠n-romanovich on GitHub · 2026-11-25 00:35 UTC · original

@⁠Marvisak, thanks for the review.

In 6b5e0b4, I removed the redundant flags::INT64 assignment (as src64 already sets it) and updated the PR description to reflect the 65-bit carry rule.
Re-ran cargo test -p victory-shader --locked -- mad64 on Windows 11 (NVIDIA GeForce RTX 5060 Ti): 1 passed, 0 failed.

**@⁠n-romanovich** on GitHub · 2026-11-25 00:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7148679129) @⁠Marvisak, thanks for the review. In 6b5e0b4, I removed the redundant flags::INT64 assignment (as src64 already sets it) and updated the PR description to reflect the 65-bit carry rule. Re-ran cargo test -p victory-shader --locked -- mad64 on Windows 11 (NVIDIA GeForce RTX 5060 Ti): 1 passed, 0 failed.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 02:35 UTC · original

Verification on Windows 10 19045 (RX 7800 XT), your head d1d21f9 plus the "skip the GPU suites a device cannot run" patch from #1991 (this host reports SM 6.5, so the probe suites would otherwise fail for an unrelated reason):

cargo test -p victory-shader --lib — 248 passed, 0 failed, 3 ignored. valu_mad64_executes_on_gpu skips here (no SM 6.6 device); CI runs it.

On the carry, I checked the formula rather than only the test: for the signed form ucarry ^ sign(prod) ^ sign(acc) is bit 64 of the exact (65-bit) sum, which is what AMD's SDST holds for v_mad_i64_i32 — e.g. max + 1 gives 0, -2^63 + -2^63 gives 1, 1 + -1 gives 0, -2^63 + max gives 1. The unsigned form stays sum < prod. Refusing v.clamp on both is right; it has no 64-bit DXIL equivalent here.

One thing worth a line in the PR body, if you agree: the previous code only wrote the carry for the unsigned form, so this changes v_mad_i64_i32 output for shaders that read SDST — it is the fix, but it is a behaviour change, not just new instructions.

**@⁠Calvix2k** on GitHub · 2026-11-25 02:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7150912652) Verification on Windows 10 19045 (RX 7800 XT), your head `d1d21f9` plus the "skip the GPU suites a device cannot run" patch from #1991 (this host reports SM 6.5, so the probe suites would otherwise fail for an unrelated reason): `cargo test -p victory-shader --lib` — **248 passed, 0 failed, 3 ignored**. `valu_mad64_executes_on_gpu` skips here (no SM 6.6 device); CI runs it. On the carry, I checked the formula rather than only the test: for the signed form `ucarry ^ sign(prod) ^ sign(acc)` is bit 64 of the exact (65-bit) sum, which is what AMD's SDST holds for `v_mad_i64_i32` — e.g. `max + 1` gives 0, `-2^63 + -2^63` gives 1, `1 + -1` gives 0, `-2^63 + max` gives 1. The unsigned form stays `sum < prod`. Refusing `v.clamp` on both is right; it has no 64-bit DXIL equivalent here. One thing worth a line in the PR body, if you agree: the previous code only wrote the carry for the unsigned form, so this changes `v_mad_i64_i32` output for shaders that read SDST — it is the fix, but it is a behaviour change, not just new instructions.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:11 UTC · original

Code review and RTX 5090 + WARP + DXIL verification at head d1d21f9c7076 merged cleanly onto main (63bcca43c6a0; emit/lower.rs = 521,055 B, 3,233 B under the 512 KiB cap):

  • Semantics audit (crates/victory-shader/src/emit/lower.rs:5422-5451):
    • Rejects v.clamp cleanly ("a clamped integer operation").
    • v_mad_u64_u32: ZExt 32->64 multiply-add with unsigned carry IULT(sum, prod).
    • v_mad_i64_i32: SExt 32->64 multiply-add where ucarry ^ (prod < 0) ^ (acc < 0) is exact for bit 64 of (i65)S0 * (i65)S1 + (i65)S2 across all (i32, i32, i64) inputs, recorded into lane_bits (sdst/VCC) while writing the 64-bit result under guard.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy (default + --features diagnostics): 0 warnings
    • emit::tests (18/18, including valu_mad64_executes_on_gpu) and emit::semantics_tests (34/34, 1 ignored): passed on both RTX 5090 and WARP.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7179522402) Code review and RTX 5090 + WARP + DXIL verification at head `d1d21f9c7076` merged cleanly onto `main` (`63bcca43c6a0`; `emit/lower.rs` = `521,055` B, `3,233` B under the 512 KiB cap): - **Semantics audit (`crates/victory-shader/src/emit/lower.rs:5422-5451`)**: - Rejects `v.clamp` cleanly (`"a clamped integer operation"`). - `v_mad_u64_u32`: `ZExt` 32->64 multiply-add with unsigned carry `IULT(sum, prod)`. - `v_mad_i64_i32`: `SExt` 32->64 multiply-add where `ucarry ^ (prod < 0) ^ (acc < 0)` is exact for bit 64 of `(i65)S0 * (i65)S1 + (i65)S2` across all `(i32, i32, i64)` inputs, recorded into `lane_bits` (`sdst`/`VCC`) while writing the 64-bit result under `guard`. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy` (default + `--features diagnostics`): 0 warnings - `emit::tests` (18/18, including `valu_mad64_executes_on_gpu`) and `emit::semantics_tests` (34/34, 1 ignored): passed on both RTX 5090 and WARP. LGTM.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 02:58 UTC · original

@⁠n-romanovich Your signed carry implementation resolves a concrete conflict with the newer lane-mask PR #2967. I merged your original d1d21f9 into that PR and compared 65,536 signed multiply-add readbacks per adapter against an i128 reference. With your code, the RTX 5080 and built-in Microsoft WARP both went from 32,759 incorrect SDST bits to zero. The low 64 bits and the unsigned control matched throughout. The integration keeps your commit and includes a small regression for the two PRs' different behavior. Results and fast-forward instructions on #2967.

**@⁠steven-seagull27** on GitHub · 2026-11-26 02:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7181287430) @⁠n-romanovich Your signed carry implementation resolves a concrete conflict with the newer lane-mask PR #2967. I merged your original `d1d21f9` into that PR and compared 65,536 signed multiply-add readbacks per adapter against an `i128` reference. With your code, the RTX 5080 and built-in Microsoft WARP both went from 32,759 incorrect SDST bits to zero. The low 64 bits and the unsigned control matched throughout. The integration keeps your commit and includes a small regression for the two PRs' different behavior. [Results and fast-forward instructions on #2967](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2967).
Author
Owner

@⁠pawrenity on GitHub · 2026-11-26 04:33 UTC · original

A small gap, read on main 63bcca4 (not run). The v_mad_u64_u32 / v_mad_i64_i32 arm in emit/lower.rs (around 6011-6041) writes both halves with self.write(...) and does not go through write_i (around 2846-2851). write_i refuses clamp and omod as "integer output modifiers". This PR adds the v.clamp refusal, but v.omod (VOP3B bits 59-60, decoded for these opcodes in gfx10/fields.rs) is still ignored silently. Refusing it next to the clamp check would make the arm match every other integer write.

AI-assisted (Claude Code).

**@⁠pawrenity** on GitHub · 2026-11-26 04:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7182700201) A small gap, read on `main` `63bcca4` (not run). The `v_mad_u64_u32` / `v_mad_i64_i32` arm in `emit/lower.rs` (around 6011-6041) writes both halves with `self.write(...)` and does not go through `write_i` (around 2846-2851). `write_i` refuses `clamp` **and** `omod` as "integer output modifiers". This PR adds the `v.clamp` refusal, but `v.omod` (VOP3B bits 59-60, decoded for these opcodes in `gfx10/fields.rs`) is still ignored silently. Refusing it next to the clamp check would make the arm match every other integer write. AI-assisted (Claude Code).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/171/head:github-bot/gh-171'
git switch 'github-bot/gh-171'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-171'
git switch 'github-bot/gh-171'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-171'
git switch 'github-bot/gh-171'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-171'
git switch 'main'
git merge --squash 'github-bot/gh-171'
git switch 'main'
git merge --ff-only 'github-bot/gh-171'
git switch 'main'
git merge 'github-bot/gh-171'
git push origin 'main'
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!171
No description provided.