Shaders: lower v_mad_u64_u32 and v_mad_i64_i32 #171

Open
n-romanovich wants to merge 1 commit from upstream-pr/171 into main
n-romanovich commented 2026-11-24 01:05:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-24T01:05:31Z.


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).
<!-- greyfinch-sync:Marvisak/VIctory:issue:5464098574 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-24T01:05:31Z. --- ### 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).
DaviTostes commented 2026-11-24 06:54:54 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118988306 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7118988306). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:19:34Z. --- 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.
Sunkiller-qc commented 2026-11-24 06:54:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T01:29:32Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119151595 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7119151595). Originally posted by [Sunkiller-qc](https://github.com/Sunkiller-qc) on 2026-11-24T01:29:32Z. --- 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.
n-romanovich commented 2026-11-24 06:55:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-24T01:42:23Z.


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).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7119366401 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7119366401). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-24T01:42:23Z. --- 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).
r4tedx commented 2026-11-24 06:55:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T01:42:42Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119371764 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7119371764). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-24T01:42:42Z. --- 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.
n-romanovich commented 2026-11-24 06:55:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-24T01:44:20Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119398414 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7119398414). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-24T01:44:20Z. --- 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.
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:40Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123938726 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7123938726). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:26:40Z. --- 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.
catminou4 commented 2026-11-24 09:13:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T09:13:25Z.

Review: APPROVED


Merges cleanly with current main (8e79c80); cargo test -p victory-shader --locked on macOS arm64 / rustc 1.98.1 → 71 passed / 0 failed (1 ignored, Windows execution).

The lowering looks right: both v_mad_u64_u32 and v_mad_i64_i32 sign/zero-extend the 32-bit operands to i64 (can't overflow on the multiply), detect carry-out as sum < prod unsigned, and for the signed form XOR in the sign disagreement of prod/acc — the standard mad carry. Clamped forms are refused, the carry goes to lane_bits, and other writes are marked as lane-mask reads. The new valu_mad64_executes_on_gpu test is Windows-gated (validator + host execution), so CI covers it; I can't run it here.

One note: the victory-gpu/src/host.rs hunk (mod tests → mod batch) is already on main — it merges as a no-op, so the PR's real content is just the shader lowering + test.

<!-- greyfinch-sync:Marvisak/VIctory:review:6036481265 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#pullrequestreview-6036481265). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T09:13:25Z. **Review:** APPROVED --- Merges cleanly with current main (`8e79c80`); `cargo test -p victory-shader --locked` on macOS arm64 / rustc 1.98.1 → **71 passed / 0 failed** (1 ignored, Windows execution). The lowering looks right: both `v_mad_u64_u32` and `v_mad_i64_i32` sign/zero-extend the 32-bit operands to i64 (can't overflow on the multiply), detect carry-out as `sum < prod` unsigned, and for the signed form XOR in the sign disagreement of prod/acc — the standard mad carry. Clamped forms are refused, the carry goes to `lane_bits`, and other writes are marked as lane-mask reads. The new `valu_mad64_executes_on_gpu` test is Windows-gated (validator + host execution), so CI covers it; I can't run it here. One note: the `victory-gpu/src/host.rs` hunk (`mod tests` → `mod batch`) is already on main — it merges as a no-op, so the PR's real content is just the shader lowering + test.
DeerSilver commented 2026-11-24 11:04:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DeerSilver on 2026-11-24T10:51:04Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129328486 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7129328486). Originally posted by [DeerSilver](https://github.com/DeerSilver) on 2026-11-24T10:51:04Z. --- 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).
alexdeliu commented 2026-11-24 18:05:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:23:16Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139117063 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7139117063). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T17:23:16Z. --- 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>
n-romanovich commented 2026-11-24 18:06:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-24T17:53:59Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139865546 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7139865546). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-24T17:53:59Z. --- 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.
alexdeliu commented 2026-11-24 18:06:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:56:06Z.


@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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139915473 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7139915473). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T17:56:06Z. --- @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).
Marvisak commented 2026-11-25 01:07:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00: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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148407282 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7148407282). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:20:29Z. --- <!-- 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)_
n-romanovich commented 2026-11-25 01:08:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-25T00:35:56Z.


@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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148679129 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7148679129). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-25T00:35:56Z. --- @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.
Calvix2k commented 2026-11-25 03:03:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T02:35:07Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150912652 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7150912652). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T02:35:07Z. --- 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.
fuzeofficlal commented 2026-11-26 02:06:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:11:23Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179522402 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7179522402). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:11:23Z. --- 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.
steven-seagull27 commented 2026-11-26 03:05:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T02:58:48Z.


@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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181287430 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7181287430). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T02:58:48Z. --- @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://github.com/Marvisak/VIctory/pull/2967#issuecomment-7181283517).
pawrenity commented 2026-11-26 05:04:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pawrenity on 2026-11-26T04:33:34Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182700201 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#issuecomment-7182700201). Originally posted by [pawrenity](https://github.com/pawrenity) on 2026-11-26T04:33:34Z. --- 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).
Dukestar69 commented 2026-11-27 01:09:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T01:09:07Z.

Review: APPROVED


LGTM — verified on Windows (RTX 5090 + WARP):

  • cargo test -p victory-shader --lib valu_mad64_executes_on_gpu passed on RTX 5090 and under VICTORY_WARP=1
  • Guarding v.clamp and emitting the signed carry-out (ucarry ^ (prod < 0) ^ (acc < 0)) into lane_bits is clean and accurate
  • cargo clippy -p victory-shader --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6082176134 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/171#pullrequestreview-6082176134). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-27T01:09:07Z. **Review:** APPROVED --- LGTM — verified on Windows (RTX 5090 + WARP): - `cargo test -p victory-shader --lib valu_mad64_executes_on_gpu` passed on RTX 5090 and under `VICTORY_WARP=1` - Guarding `v.clamp` and emitting the signed carry-out (`ucarry ^ (prod < 0) ^ (acc < 0)`) into `lane_bits` is clean and accurate - `cargo clippy -p victory-shader --all-targets -- -D warnings` passed with 0 warnings - `cargo xtask policy` passed (`191 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/171:upstream-pr/171'
git switch 'upstream-pr/171'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/171'
git switch 'upstream-pr/171'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/171'
git switch 'upstream-pr/171'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/171'
git switch 'main'
git merge --squash 'upstream-pr/171'
git switch 'main'
git merge --ff-only 'upstream-pr/171'
git switch 'main'
git merge 'upstream-pr/171'
git push origin 'main'
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!171
No description provided.