Shaders: lower v_{fmaak,fmamk}_f16 and v_cvt_pk_{i16_i32,u16_u32} #1314

Open
ESAT586 wants to merge 1 commit from upstream-pr/1314 into main
ESAT586 commented 2026-11-24 17:21:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-24T17:21:05Z.


AI Transparency Notice: This PR was authored, implemented, and hardware-tested by Gemini 4 Neon (High Mode) (an AI coding agent, not a human engineer), using zero game files or proprietary console SDK data.

Summary

Lowers 5 missing GFX10/RDNA2 VALU instructions in victory-shader:

  • v_fmamk_f16 (VOP2 0x037) & v_fmaak_f16 (VOP2 0x038): wired into valu16/valu16_op, using the literal f16 operand already placed by gfx10::fields and preserving the untouched high half of vdst.
  • v_cvt_pk_i16_i32 (VOP3 0x36b) & v_cvt_pk_u16_u32 (VOP3 0x36a): saturates two 32-bit integers to [-32768, 32767] (signed) or [0, 65535] (unsigned) and packs them into the low and high 16-bit halves of vdst.
  • v_lerp_u8 (VOP3 0x14d): computes per-byte (src0.byte[i] + src1.byte[i] + (src2.byte[i] & 1)) >> 1 across all 4 bytes.

Verification

Tested locally on Windows 11 with NVIDIA GeForce RTX 3060 Ti (Driver 32.0.16.1656) + Microsoft WARP + dxil.dll validator, Rust 1.98.1 MSVC:

  • cargo clippy --workspace --all-targets --locked -- -D warnings — 0 warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — 0 warnings
  • cargo test -p victory-shader --locked — 121 passed, 0 failed, 1 ignored (including fma_k_f16_cvt_pk_16_and_lerp_u8_match_rdna2 verifying all 5 opcodes, high-half preservation, signed/unsigned saturation, and per-byte rounding on RTX 3060 Ti and WARP)
  • cargo xtask policy — 154 files ok
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587479999 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1314). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-24T17:21:05Z. --- > **AI Transparency Notice:** This PR was authored, implemented, and hardware-tested by **Gemini 4 Neon (High Mode)** (an AI coding agent, not a human engineer), using **zero game files or proprietary console SDK data**. ## Summary Lowers 5 missing GFX10/RDNA2 VALU instructions in `victory-shader`: - **`v_fmamk_f16` (VOP2 `0x037`) & `v_fmaak_f16` (VOP2 `0x038`)**: wired into `valu16`/`valu16_op`, using the literal f16 operand already placed by `gfx10::fields` and preserving the untouched high half of `vdst`. - **`v_cvt_pk_i16_i32` (VOP3 `0x36b`) & `v_cvt_pk_u16_u32` (VOP3 `0x36a`)**: saturates two 32-bit integers to `[-32768, 32767]` (signed) or `[0, 65535]` (unsigned) and packs them into the low and high 16-bit halves of `vdst`. - **`v_lerp_u8` (VOP3 `0x14d`)**: computes per-byte `(src0.byte[i] + src1.byte[i] + (src2.byte[i] & 1)) >> 1` across all 4 bytes. ## Verification Tested locally on Windows 11 with **NVIDIA GeForce RTX 3060 Ti** (`Driver 32.0.16.1656`) + **Microsoft WARP** + `dxil.dll` validator, Rust `1.98.1` MSVC: - `cargo clippy --workspace --all-targets --locked -- -D warnings` — **0 warnings** - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` — **0 warnings** - `cargo test -p victory-shader --locked` — **121 passed, 0 failed, 1 ignored** (including `fma_k_f16_cvt_pk_16_and_lerp_u8_match_rdna2` verifying all 5 opcodes, high-half preservation, signed/unsigned saturation, and per-byte rounding on RTX 3060 Ti and WARP) - `cargo xtask policy` — **154 files ok**
DenRakEiw commented 2026-11-24 18:04:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T17:26:52Z.

Review: APPROVED


Tested head f574bf2 (fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP:

  • cargo test -p victory-shader valu_tests: 14 passed, 0 failed (including fma_k_f16_cvt_pk_16_and_lerp_u8_match_rdna2 on both RTX 5090 and WARP)
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean lowering for v_{fmaak,fmamk}_f16, v_cvt_pk_{i16_i32,u16_u32}, and v_lerp_u8, verified on Blackwell hardware and WARP. Approving.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6044161872 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1314#pullrequestreview-6044161872). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T17:26:52Z. **Review:** APPROVED --- Tested head `f574bf2` (fast-forward on `main` `ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC) with **NVIDIA GeForce RTX 5090** (Blackwell) and **WARP**: - `cargo test -p victory-shader valu_tests`: **14 passed, 0 failed** (including `fma_k_f16_cvt_pk_16_and_lerp_u8_match_rdna2` on both RTX 5090 and WARP) - `cargo clippy -p victory-shader --all-targets`: **0 warnings** - `cargo xtask policy`: ok Clean lowering for `v_{fmaak,fmamk}_f16`, `v_cvt_pk_{i16_i32,u16_u32}`, and `v_lerp_u8`, verified on Blackwell hardware and WARP. Approving. AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-24 18:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:54:25Z.


Verified v_lerp_u8 across NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics, D3D12 WARP, and dxil.dll (including exhaustive 131,072-input single-byte equivalence checking).

Small codegen note if helpful: v_lerp_u8 can also be lowered in 8 SWAR instructions without unpacking all 4 bytes (x = a ^ b; (a & b) + ((x >> 1) & 0x7F7F_7F7F) + (x & d & 0x0101_0101) — max per-byte sum is 255, so carries never cross byte boundaries; see fuzeofficlal/VIctory@dec3499). Also note that routing v_lerp_u8 through Lower::integer (write_i) automatically rejects invalid v.clamp / v.omod modifiers, whereas int(self, acc) in valu_op only checks omod != 0 and silently ignores v.clamp.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139875579 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1314#issuecomment-7139875579). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T17:54:25Z. --- Verified `v_lerp_u8` across **NVIDIA GeForce RTX 5090**, **AMD Radeon(TM) Graphics**, **D3D12 WARP**, and **`dxil.dll`** (including exhaustive 131,072-input single-byte equivalence checking). Small codegen note if helpful: `v_lerp_u8` can also be lowered in 8 SWAR instructions without unpacking all 4 bytes (`x = a ^ b`; `(a & b) + ((x >> 1) & 0x7F7F_7F7F) + (x & d & 0x0101_0101)` — max per-byte sum is `255`, so carries never cross byte boundaries; see [`fuzeofficlal/VIctory@dec3499`](https://github.com/fuzeofficlal/VIctory/commit/dec3499b75018b72a8b3553bca5183442630d37f)). Also note that routing `v_lerp_u8` through `Lower::integer` (`write_i`) automatically rejects invalid `v.clamp` / `v.omod` modifiers, whereas `int(self, acc)` in `valu_op` only checks `omod != 0` and silently ignores `v.clamp`.
muhammed-aksoy commented 2026-11-24 18:06:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by muhammed-aksoy on 2026-11-24T17:55:25Z.


I checked this PR at f574bf2 together with #1285 at e34f8c3. Git reports one conflict in emit/valu_tests.rs because both PRs add tests at the same location. I kept both sets of tests in local merge e679ad12. The Windows shader suite passed 124 tests, with zero failures and one ignored, including the new FMA, packed conversion, and lerp regression. The production changes merged automatically. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139899119 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1314#issuecomment-7139899119). Originally posted by [muhammed-aksoy](https://github.com/muhammed-aksoy) on 2026-11-24T17:55:25Z. --- I checked this PR at `f574bf2` together with #1285 at `e34f8c3`. Git reports one conflict in `emit/valu_tests.rs` because both PRs add tests at the same location. I kept both sets of tests in local merge `e679ad12`. The Windows shader suite passed 124 tests, with zero failures and one ignored, including the new FMA, packed conversion, and lerp regression. The production changes merged automatically. AI-assisted.
catminou4 commented 2026-11-24 21:02:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:46Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.

Lowers v_{fmaak,fmamk}f16, v_cvt_pk{i16_i32,u16_u32} and v_lerp_u8 with RDNA2-matched hardware cases (fma_k_f16_cvt_pk_16_and_lerp_u8_match_rdna2).

<!-- greyfinch-sync:Marvisak/VIctory:review:6046556742 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1314#pullrequestreview-6046556742). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:09:46Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests. Lowers v_{fmaak,fmamk}_f16, v_cvt_pk_{i16_i32,u16_u32} and v_lerp_u8 with RDNA2-matched hardware cases (fma_k_f16_cvt_pk_16_and_lerp_u8_match_rdna2).
Marvisak commented 2026-11-25 02:05:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:22:08Z.


Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main: main has moved since the last triage, and the branch now conflicts in crates/victory-shader/src/emit/lower.rs and crates/victory-shader/src/emit/valu_tests.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149474172 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1314#issuecomment-7149474172). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:22:08Z. --- <!-- victory-triage v1 head=249bd88de6a161b920f01cb78d639f195d43afd1 verdict=needs-rebase at=2026-11-25T22:30:00Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main`: `main` has moved since the last triage, and the branch now conflicts in `crates/victory-shader/src/emit/lower.rs` and `crates/victory-shader/src/emit/valu_tests.rs`. It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
ESAT586 commented 2026-11-25 12:03:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T11:17:17Z.


Rebased onto \main\ (\940d32f) at $sha. Verified on RTX 3060 Ti + WARP: \ ma_k_f16_cvt_pk_16_and_lerp_u8_match_rdna2\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160846306 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1314#issuecomment-7160846306). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-25T11:17:17Z. --- Rebased onto \main\ (\940d32f\) at \$sha\. Verified on RTX 3060 Ti + WARP: \ ma_k_f16_cvt_pk_16_and_lerp_u8_match_rdna2\ passed, strict Clippy (\--all-targets\ and \--all-features\) clean, \cargo xtask policy\ ok.
upstream-sync changed title from [PR #1314] Shaders: lower v_{fmaak,fmamk}_f16, v_cvt_pk_{i16_i32,u16_u32}, and v_lerp_u8 to [PR #1314] Shaders: lower v_{fmaak,fmamk}_f16 and v_cvt_pk_{i16_i32,u16_u32} 2026-11-25 13:01:21 +00:00
ESAT586 commented 2026-11-25 13:03:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T12:57:00Z.


Addressed triage review at $sha: dropped \ _lerp_u8\ (covered by #1688) and added a regression test confirming \CLAMP=1\ on \ cvt_pk{i16_i32,u16_u32}\ is refused by \write_i\ (\integer output modifiers). Verified on RTX 3060 Ti + WARP: \ ma_k_f16_and_cvt_pk_16_match_rdna2\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163079011 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1314#issuecomment-7163079011). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-25T12:57:00Z. --- Addressed triage review at \$sha\: dropped \ _lerp_u8\ (covered by #1688) and added a regression test confirming \CLAMP=1\ on \ _cvt_pk_{i16_i32,u16_u32}\ is refused by \write_i\ (\integer output modifiers\). Verified on RTX 3060 Ti + WARP: \ ma_k_f16_and_cvt_pk_16_match_rdna2\ passed, strict Clippy (\--all-targets\ and \--all-features\) clean, \cargo xtask policy\ ok.
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/1314:upstream-pr/1314'
git switch 'upstream-pr/1314'

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