Shaders: lower v_mad_{u16,i16} and saturating clamp on 16-bit integer ops #1211

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

@⁠ESAT586 on GitHub · 2026-11-24 16:26 UTC · original
ESAT586:shader/valu16-mad-clamp → main · +162 −2 · 2 files · 1 commits · open

AI Disclosure — Generated & Verified by Gemini 4 Neon (High Mode) (Not Written by a Human Engineer)
This diagnosis, RDNA2 ISA implementation, and synthetic GPU/WARP test suite were authored and verified end-to-end by Gemini 4 Neon (High Mode), submitted transparently on behalf of @ESAT586. All builds, clippy checks, DXIL validation, and GPU/WARP tests below were executed locally on real hardware (NVIDIA GeForce RTX 3060 Ti, Windows 11, Rust 1.98.1). No game data was used.

What's wrong

In crates/victory-shader/src/emit/lower.rs (valu16 / valu16_op):

  1. v_mad_u16 (VOP3 0x340) and v_mad_i16 (VOP3 0x35e) are decoded in gfx10/opcodes.rs but not lowered, causing shaders using 16-bit integer multiply-add to fail lowering.
  2. valu16_op rejects v.clamp on all 16-bit integer ops with Err("modifiers on a 16-bit integer operation"), even though under the AMD RDNA2 ISA clamp = 1 selects saturating 16-bit arithmetic on v_add_nc_u16, v_sub_nc_u16, v_subrev_nc_u16, v_mad_u16, and v_mad_i16.

Fix

  • Add v_mad_u16 and v_mad_i16 to valu16's INT list and compute a * b + d in 32 bits (half_src zero-extended for _u16, sign-extended for _i16), preserving the untouched destination half via write_half.
  • Allow v.clamp specifically on v_add_nc_u16, v_sub_nc_u16, v_subrev_nc_u16, v_mad_u16, and v_mad_i16:
    • v_add_nc_u16 / v_mad_u16: clamp to 0xFFFF via IUGT (u16::MAX * u16::MAX + u16::MAX <= u32::MAX, never wraps u32).
    • v_sub_nc_u16 / v_subrev_nc_u16: clamp to 0 via SLT (result is in [-65535, 65535]).
    • v_mad_i16: clamp to [-32768, 32767] via SLT/SGT (|r| <= 32768 * 32768 + 32768 < 2^31, never wraps i32).
    • Non-saturating 16-bit integer ops keep rejecting v.clamp.
  • Add emit::valu_tests::v_mad_16_and_int16_clamp_match_rdna2 in crates/victory-shader/src/emit/valu_tests.rs testing wrapping & saturating v_mad_u16, v_mad_i16, v_add_nc_u16 clamp, v_sub_nc_u16 clamp, and upper-half preservation.

Verification (Real GPU + WARP + CI Gates)

Tested on Windows 11, NVIDIA GeForce RTX 3060 Ti (driver 32.0.16.1656), Rust 1.98.1:

  • cargo test -p victory-shader --lib v_mad_16_and_int16_clamp_match_rdna2: ok (dxil.dll validator + RTX 3060 Ti hardware + Microsoft WARP)
  • cargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignored
  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass (0 warnings)
  • cargo xtask policy: asset policy: 154 files ok

Scope & Non-Overlap

  • Independent complement to #1142 (which covers packed VOP3P v_pk_*); this PR covers single-lane valu16 (v_mad_u16, v_mad_i16, and 16-bit integer clamp). Checked open PRs and issues — no overlap.
  • Not tested: against retail title shader packages (synthetic fixtures only, no game data).
**@⁠ESAT586** on GitHub · 2026-11-24 16:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211) `ESAT586:shader/valu16-mad-clamp` → `main` · +162 −2 · 2 files · 1 commits · open > **AI Disclosure — Generated & Verified by Gemini 4 Neon (High Mode) (Not Written by a Human Engineer)** > This diagnosis, RDNA2 ISA implementation, and synthetic GPU/WARP test suite were authored and verified end-to-end by **Gemini 4 Neon (High Mode)**, submitted transparently on behalf of `@ESAT586`. All builds, clippy checks, DXIL validation, and GPU/WARP tests below were executed locally on real hardware (`NVIDIA GeForce RTX 3060 Ti`, Windows 11, Rust `1.98.1`). **No game data was used.** ## What's wrong In `crates/victory-shader/src/emit/lower.rs` (`valu16` / `valu16_op`): 1. `v_mad_u16` (`VOP3 0x340`) and `v_mad_i16` (`VOP3 0x35e`) are decoded in `gfx10/opcodes.rs` but not lowered, causing shaders using 16-bit integer multiply-add to fail lowering. 2. `valu16_op` rejects `v.clamp` on all 16-bit integer ops with `Err("modifiers on a 16-bit integer operation")`, even though under the AMD RDNA2 ISA `clamp = 1` selects saturating 16-bit arithmetic on `v_add_nc_u16`, `v_sub_nc_u16`, `v_subrev_nc_u16`, `v_mad_u16`, and `v_mad_i16`. ## Fix - Add `v_mad_u16` and `v_mad_i16` to `valu16`'s `INT` list and compute `a * b + d` in 32 bits (`half_src` zero-extended for `_u16`, sign-extended for `_i16`), preserving the untouched destination half via `write_half`. - Allow `v.clamp` specifically on `v_add_nc_u16`, `v_sub_nc_u16`, `v_subrev_nc_u16`, `v_mad_u16`, and `v_mad_i16`: - `v_add_nc_u16` / `v_mad_u16`: clamp to `0xFFFF` via `IUGT` (`u16::MAX * u16::MAX + u16::MAX <= u32::MAX`, never wraps `u32`). - `v_sub_nc_u16` / `v_subrev_nc_u16`: clamp to `0` via `SLT` (result is in `[-65535, 65535]`). - `v_mad_i16`: clamp to `[-32768, 32767]` via `SLT`/`SGT` (`|r| <= 32768 * 32768 + 32768 < 2^31`, never wraps `i32`). - Non-saturating 16-bit integer ops keep rejecting `v.clamp`. - Add `emit::valu_tests::v_mad_16_and_int16_clamp_match_rdna2` in `crates/victory-shader/src/emit/valu_tests.rs` testing wrapping & saturating `v_mad_u16`, `v_mad_i16`, `v_add_nc_u16 clamp`, `v_sub_nc_u16 clamp`, and upper-half preservation. ## Verification (Real GPU + WARP + CI Gates) Tested on Windows 11, **NVIDIA GeForce RTX 3060 Ti** (driver `32.0.16.1656`), Rust `1.98.1`: - `cargo test -p victory-shader --lib v_mad_16_and_int16_clamp_match_rdna2`: **ok** (`dxil.dll` validator + RTX 3060 Ti hardware + Microsoft WARP) - `cargo test -p victory-shader --locked`: **121 passed, 0 failed, 1 ignored** - `cargo clippy --workspace --all-targets --locked -- -D warnings`: **pass (0 warnings)** - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: **pass (0 warnings)** - `cargo xtask policy`: **`asset policy: 154 files ok`** ## Scope & Non-Overlap - Independent complement to `#1142` (which covers packed VOP3P `v_pk_*`); this PR covers single-lane `valu16` (`v_mad_u16`, `v_mad_i16`, and 16-bit integer `clamp`). Checked open PRs and issues — no overlap. - **Not tested:** against retail title shader packages (synthetic fixtures only, no game data).
AI-generated & verified with Gemini 4 Neon (High Mode) — not written by a human engineer.

- Add `v_mad_u16` (VOP3 0x340) and `v_mad_i16` (VOP3 0x35e) to `valu16` / `valu16_op`
  in `crates/victory-shader/src/emit/lower.rs`, preserving the untouched half
  of the destination VGPR via `write_half`.
- Allow saturating `v.clamp` on `v_add_nc_u16`, `v_sub_nc_u16`, `v_subrev_nc_u16`,
  `v_mad_u16`, and `v_mad_i16` (clamping to `[0, 65535]` for unsigned and
  `[-32768, 32767]` for signed in 32-bit intermediate precision). Non-saturating
  16-bit integer ops continue to reject `v.clamp`.

Verified with synthetic GPU + WARP + dxil.dll tests in `valu_tests.rs` on
NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used.

Co-Authored-By: Gemini 4 Neon (High Mode) <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:54 +00:00
github-bot force-pushed github-bot/gh-1211 from ed4b40ffc8 to 5780573f47 2026-11-26 06:30:10 +00:00 Compare
Author
Owner

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

This PR has no CI run yet, so I ran the CI's checks at head 7dffb2a (on main ffe310e) on AMD, to add a second vendor to the RTX 3060 Ti run: Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2).

  • cargo test --workspace --locked -- --test-threads=1: 343 passed, 0 failed, including v_mad_16_and_int16_clamp_match_rdna2 on the AMD device and WARP.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean.
  • cargo xtask policy: ok.
**@⁠shortselow-byte** on GitHub · 2026-11-24 17:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#issuecomment-7139127002) This PR has no CI run yet, so I ran the CI's checks at head `7dffb2a` (on `main` `ffe310e`) on AMD, to add a second vendor to the RTX 3060 Ti run: Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2). - `cargo test --workspace --locked -- --test-threads=1`: 343 passed, 0 failed, including `v_mad_16_and_int16_clamp_match_rdna2` on the AMD device and WARP. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, and with `--all-features`: clean. - `cargo xtask policy`: ok.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:00 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 7dffb2a: cargo test -p victory-shader passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#issuecomment-7140010484) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 7dffb2a: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:18 UTC · original · edited 2026-11-26 05:31 UTC

Automated triage for the maintainers.

Merge candidate. Rebased onto current main. The change is the same as the head that was a merge candidate before. In lower.rs (the 16-bit integer path of the VALU lowering), v_mad_u16 and v_mad_i16 now wrap, with sign extension for the i16 form. v_add_nc_u16, v_sub_nc_u16 and v_subrev_nc_u16 saturate when CLAMP is set. On the eight ops where the cited RDNA2 measurement found the clamp bit has no effect, CLAMP is accepted and does nothing. CLAMP on v_mad_* is still refused, since nobody has measured it. I checked the opcode numbers in the test against gfx10/opcodes.rs and the saturation compares (unsigned for add, signed below zero for the zero-extended sub).

CI: passing. Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#issuecomment-7149419358) · edited 2026-11-26 05:31 UTC <!-- victory-triage v1 head=5780573f4755676da8d2271cba0ae91dda016882 verdict=merge-candidate at=2026-11-26T05:31:40Z --> Automated triage for the maintainers. **Merge candidate.** Rebased onto current `main`. The change is the same as the head that was a merge candidate before. In `lower.rs` (the 16-bit integer path of the VALU lowering), `v_mad_u16` and `v_mad_i16` now wrap, with sign extension for the i16 form. `v_add_nc_u16`, `v_sub_nc_u16` and `v_subrev_nc_u16` saturate when CLAMP is set. On the eight ops where the cited RDNA2 measurement found the clamp bit has no effect, CLAMP is accepted and does nothing. CLAMP on `v_mad_*` is still refused, since nobody has measured it. I checked the opcode numbers in the test against `gfx10/opcodes.rs` and the saturation compares (unsigned for add, signed below zero for the zero-extended sub). CI: passing. Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 03:39 UTC · original

A hardware data point for the ops this PR still refuses with CLAMP=1, from reading, not a run here. boykopovar/AnyPS5 measured VOP3 16-bit integer ops with and without the clamp bit on gfx1036 (RDNA2), through their hardware oracle (the §9 entry and #22615):

  • v_add_nc_u16 with clamp saturates. That matches this PR's add / sub arms.
  • The clamp bit has no effect on v_mul_lo_u16, v_lshlrev_b16 / v_lshrrev_b16 / v_ashrrev_i16 and v_min / v_max_{u16,i16}. The result is the wrapped low 16 bits either way.

So those eight could take v.clamp as a no-op instead of returning Err("modifiers on a 16-bit integer operation"). It should not saturate there: xcl-dev/xcl#202 made v_mul_lo_u16 saturate and the same measurement contradicts it. v_mad_u16 / v_mad_i16 with clamp weren't part of that measurement.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 03:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#issuecomment-7152118988) A hardware data point for the ops this PR still refuses with CLAMP=1, from reading, not a run here. boykopovar/AnyPS5 measured VOP3 16-bit integer ops with and without the clamp bit on gfx1036 (RDNA2), through their hardware oracle (the §9 entry and #22615): - `v_add_nc_u16` with clamp saturates. That matches this PR's add / sub arms. - The clamp bit has **no effect** on `v_mul_lo_u16`, `v_lshlrev_b16` / `v_lshrrev_b16` / `v_ashrrev_i16` and `v_min` / `v_max_{u16,i16}`. The result is the wrapped low 16 bits either way. So those eight could take `v.clamp` as a no-op instead of returning `Err("modifiers on a 16-bit integer operation")`. It should not saturate there: xcl-dev/xcl#202 made `v_mul_lo_u16` saturate and the same measurement contradicts it. `v_mad_u16` / `v_mad_i16` with clamp weren't part of that measurement. AI-assisted (Claude Code).
Author
Owner

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

Rebased onto \main\ (\940d32f) at $sha. Thanks @⁠upipibi for the RDNA2 (\gfx1036) hardware data point! Updated \lower.rs\ to accept \CLAMP=1\ as a no-op (wrapped low 16 bits, no saturation) on \ _mul_lo_u16, \ _lshlrev_b16, \ _lshrrev_b16, \ _ashrrev_i16, and \ {min,max}{u16,i16}, and added GPU regression tests for all 8 ops. Verified on RTX 3060 Ti + WARP: \ _mad_16_and_int16_clamp_match_rdna2\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.

**@⁠ESAT586** on GitHub · 2026-11-25 11:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#issuecomment-7160979179) Rebased onto \main\ (\940d32f\) at \$sha\. Thanks @⁠upipibi for the RDNA2 (\gfx1036\) hardware data point! Updated \lower.rs\ to accept \CLAMP=1\ as a no-op (wrapped low 16 bits, no saturation) on \ _mul_lo_u16\, \ _lshlrev_b16\, \ _lshrrev_b16\, \ _ashrrev_i16\, and \ _{min,max}_{u16,i16}\, and added GPU regression tests for all 8 ops. Verified on RTX 3060 Ti + WARP: \ _mad_16_and_int16_clamp_match_rdna2\ passed, strict Clippy (\--all-targets\ and \--all-features\) clean, \cargo xtask policy\ ok.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 11:48 UTC · original

@⁠ESAT586 I read 21e43af against the gfx1036 measurement. The eight ops take CLAMP=1 as a no-op and keep the wrapped low 16 bits (clamp_noop in lower.rs, and the no-op cases in the new test), which is what was measured. v_add_nc_u16 and v_sub_nc_u16 saturate, which also matches. v_mad_i16 sign-extends all three sources, and u16::MAX * u16::MAX + u16::MAX fits in 32 bits, so the > 0xFFFF compare is exact.

One open point: v_mad_u16 / v_mad_i16 with clamp. The saturating results that v_mad_16_and_int16_clamp_match_rdna2 checks come from the lowering's model, because the measurement didn't include either op with clamp. v_mul_lo_u16 is a reason to be careful here: the same measurement showed its clamp bit does nothing, even though one could expect it to saturate. Until someone measures the two mad ops with clamp on RDNA2, I'd name or comment the test so it says which half was measured, or keep v_mad_* with clamp refused.

AI-assisted (Claude Code). Read only, nothing run for this.

**@⁠upipibi** on GitHub · 2026-11-25 11:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#issuecomment-7161536182) @⁠ESAT586 I read `21e43af` against the gfx1036 measurement. The eight ops take `CLAMP=1` as a no-op and keep the wrapped low 16 bits (`clamp_noop` in `lower.rs`, and the no-op cases in the new test), which is what was measured. `v_add_nc_u16` and `v_sub_nc_u16` saturate, which also matches. `v_mad_i16` sign-extends all three sources, and `u16::MAX * u16::MAX + u16::MAX` fits in 32 bits, so the `> 0xFFFF` compare is exact. One open point: `v_mad_u16` / `v_mad_i16` **with** clamp. The saturating results that `v_mad_16_and_int16_clamp_match_rdna2` checks come from the lowering's model, because the measurement didn't include either op with clamp. `v_mul_lo_u16` is a reason to be careful here: the same measurement showed its clamp bit does nothing, even though one could expect it to saturate. Until someone measures the two `mad` ops with clamp on RDNA2, I'd name or comment the test so it says which half was measured, or keep `v_mad_*` with clamp refused. AI-assisted (Claude Code). Read only, nothing run for this.
Author
Owner

@⁠ESAT586 on GitHub · 2026-11-25 12:59 UTC · original

Updated at $sha\ per triage and @⁠upipibi's note: kept \CLAMP=1\ refused on \ _mad_u16\ / \ _mad_i16\ (added refusal regression check) until hardware-measured on RDNA2, while keeping wrapping \ mad{u16,i16}, saturating \ _{add,sub,subrev}_nc_u16, and the 8 hardware-measured \clamp_noop\ ops. Verified on RTX 3060 Ti + WARP: \ _mad_16_and_int16_clamp_match_rdna2\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.

**@⁠ESAT586** on GitHub · 2026-11-25 12:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#issuecomment-7163135490) Updated at \$sha\ per triage and @⁠upipibi's note: kept \CLAMP=1\ refused on \ _mad_u16\ / \ _mad_i16\ (added refusal regression check) until hardware-measured on RDNA2, while keeping wrapping \ _mad_{u16,i16}\, saturating \ _{add,sub,subrev}_nc_u16\, and the 8 hardware-measured \clamp_noop\ ops. Verified on RTX 3060 Ti + WARP: \ _mad_16_and_int16_clamp_match_rdna2\ passed, strict Clippy (\--all-targets\ and \--all-features\) clean, \cargo xtask policy\ ok.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 13:53 UTC · original

@⁠ESAT586 Thanks for keeping the clamp refused there. ed4b40f (as-is, on main 940d32f), RTX 3070 (616.56) plus WARP, Windows 11, debug, cargo test -p victory-shader --locked:

  • v_mad_16_and_int16_clamp_match_rdna2 passes, including the new refusal check for v_mad_u16 / v_mad_i16 with CLAMP=1. It's slow on this machine, though: it ran for more than 60 s, most of the suite's 82 s.
  • The suite gives 245 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures that main has too (a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, a_heap_buffer_read_by_element_takes_the_views_stride, gathers_at_a_level_match_the_hardware).

One run only.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-25 13:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#issuecomment-7164429977) @⁠ESAT586 Thanks for keeping the clamp refused there. `ed4b40f` (as-is, on `main` `940d32f`), RTX 3070 (616.56) plus WARP, Windows 11, debug, `cargo test -p victory-shader --locked`: - `v_mad_16_and_int16_clamp_match_rdna2` passes, including the new refusal check for `v_mad_u16` / `v_mad_i16` with `CLAMP=1`. It's slow on this machine, though: it ran for more than 60 s, most of the suite's 82 s. - The suite gives 245 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures that `main` has too (`a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `a_heap_buffer_read_by_element_takes_the_views_stride`, `gathers_at_a_level_match_the_hardware`). One run only. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 13:54 UTC · original · approved these changes

Reviewed and verified 5780573f4755 merged locally onto origin/main (63bcca43) on Windows 11 x64 (RTX 5090 and VICTORY_WARP=1, Rust 1.98.1 MSVC, Windows SDK 10.0.26100.0 dxil.dll).

  • The unclamped v_mad_u16 / v_mad_i16 paths (emit/lower.rs:6937-6955, 7144-7166) have exact 32-bit intermediate precision without overflow (65535^2 + 65535 <= u32::MAX, signed range within i32), v_add_nc_u16 / v_sub_nc_u16 saturate overflow/underflow cleanly, clamped MAD stays explicitly refused, and the 8 clamp_noop ops align with the gfx1036 hardware data point cited above.
  • emit/lower.rs after merging onto origin/main is 522,266 B (+1,703 B, 2,022 B under the 512 KiB cap).
  • Minor non-blocking cleanup notes: v_subrev_nc_u16 (lower.rs:6940, 7107, 7158) currently has no entry in gfx10/opcodes.rs:714-735; rustfmt --edition 2024 --check flags 3 new lines in valu_tests.rs:2332, 2357, 2368; and a mixed non-zero OPSEL MAD test writing the upper destination half while checking a low-half sentinel would cover the remaining half-selection path.

Local verification: git merge-tree onto 63bcca43 clean, cargo run --locked -p xtask -- policy (191 files ok), cargo clippy -p victory-shader --all-targets (default and --all-features, 0 warnings), emit::lower::tests (33 passed), and emit::valu_tests (36 passed, 0 failed) with dxil.dll validation all pass on both RTX 5090 and VICTORY_WARP=1. Looks good to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 13:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#pullrequestreview-6075325630) · **approved these changes** Reviewed and verified `5780573f4755` merged locally onto `origin/main` (`63bcca43`) on Windows 11 x64 (RTX 5090 and `VICTORY_WARP=1`, Rust `1.98.1` MSVC, Windows SDK `10.0.26100.0` `dxil.dll`). - The unclamped `v_mad_u16` / `v_mad_i16` paths (`emit/lower.rs:6937-6955, 7144-7166`) have exact 32-bit intermediate precision without overflow (`65535^2 + 65535 <= u32::MAX`, signed range within `i32`), `v_add_nc_u16` / `v_sub_nc_u16` saturate overflow/underflow cleanly, clamped MAD stays explicitly refused, and the 8 `clamp_noop` ops align with the `gfx1036` hardware data point cited above. - `emit/lower.rs` after merging onto `origin/main` is **`522,266 B`** (+1,703 B, **2,022 B** under the 512 KiB cap). - Minor non-blocking cleanup notes: `v_subrev_nc_u16` (`lower.rs:6940, 7107, 7158`) currently has no entry in `gfx10/opcodes.rs:714-735`; `rustfmt --edition 2024 --check` flags 3 new lines in `valu_tests.rs:2332, 2357, 2368`; and a mixed non-zero `OPSEL` MAD test writing the upper destination half while checking a low-half sentinel would cover the remaining half-selection path. Local verification: `git merge-tree` onto `63bcca43` clean, `cargo run --locked -p xtask -- policy` (191 files ok), `cargo clippy -p victory-shader --all-targets` (`default` and `--all-features`, 0 warnings), `emit::lower::tests` (33 passed), and `emit::valu_tests` (36 passed, 0 failed) with `dxil.dll` validation all pass on both RTX 5090 and `VICTORY_WARP=1`. Looks good to merge.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 19:32 UTC · original · approved these changes

LGTM — verified on RTX 5090 and VICTORY_WARP=1 (Windows / D3D12) against origin/main (63bcca4).

  • Lowering v_mad_u16 / v_mad_i16, handling unsigned 16-bit saturating clamp on v_add_nc_u16 / v_sub_nc_u16 / v_subrev_nc_u16, and treating no-op CLAMP on the remaining 8 16-bit integer ops (while safely rejecting unhandled v_mad_{u16,i16} clamp) is clean and matches RDNA2 semantics.
  • cargo test -p victory-shader --lib emit::valu_tests::v_mad_16_and_int16_clamp_match_rdna2 -- --test-threads=1: passed on RTX 5090 and VICTORY_WARP=1.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 19:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1211#pullrequestreview-6079577077) · **approved these changes** LGTM — verified on RTX 5090 and `VICTORY_WARP=1` (Windows / D3D12) against `origin/main` (`63bcca4`). - Lowering `v_mad_u16` / `v_mad_i16`, handling unsigned 16-bit saturating clamp on `v_add_nc_u16` / `v_sub_nc_u16` / `v_subrev_nc_u16`, and treating no-op `CLAMP` on the remaining 8 16-bit integer ops (while safely rejecting unhandled `v_mad_{u16,i16}` clamp) is clean and matches RDNA2 semantics. - `cargo test -p victory-shader --lib emit::valu_tests::v_mad_16_and_int16_clamp_match_rdna2 -- --test-threads=1`: passed on RTX 5090 and `VICTORY_WARP=1`. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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/1211/head:github-bot/gh-1211'
git switch 'github-bot/gh-1211'

Merge

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