Skip to content

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

Open
ESAT586 wants to merge 1 commit into
Marvisak:mainfrom
ESAT586:shader/valu-fma-k-f16-cvt-pk-lerp
Open

ESAT586 wants to merge 1 commit into
Marvisak:mainfrom
ESAT586:shader/valu-fma-k-f16-cvt-pk-lerp

Conversation

@ESAT586

@ESAT586 ESAT586 commented Nov 24, 2026

Copy link
Copy Markdown

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 DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

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.

@muhammed-aksoy

Copy link
Copy Markdown

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@ESAT586

ESAT586 commented Nov 25, 2026

Copy link
Copy Markdown
Author

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.

@ESAT586
ESAT586 force-pushed the shader/valu-fma-k-f16-cvt-pk-lerp branch from f574bf2 to 4b1a829 Compare November 25, 2026 11:17
@ESAT586
ESAT586 force-pushed the shader/valu-fma-k-f16-cvt-pk-lerp branch from 4b1a829 to 249bd88 Compare November 25, 2026 12:56
@ESAT586 ESAT586 changed the title Shaders: lower v_{fmaak,fmamk}_f16, v_cvt_pk_{i16_i32,u16_u32}, and v_lerp_u8 Shaders: lower v_{fmaak,fmamk}_f16 and v_cvt_pk_{i16_i32,u16_u32} Nov 25, 2026
@ESAT586

ESAT586 commented Nov 25, 2026

Copy link
Copy Markdown
Author

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.

notquiteog pushed a commit to notquiteog/VIctory that referenced this pull request Nov 26, 2026
The lib tests of victory-shader had stopped compiling after ports whose
tests were written against other trees:
- `lowers` takes the program's rsrc2 (0 here), three SOP1 tests did not
  pass it;
- `try_build_valu_cs` (Marvisak#1314's test) did not exist: it
  is `build_valu_cs` returning the lowering's error;
- `branches_around` also says whether the widening is wave-wide; the two
  wave64 tests compare its branches;
- the f16 sum of Marvisak#2493's test is `Shape::Active` here
  (this tree has no `Shape::Half`).

v_ldexp_f16_matches_rdna2 builds with the console's rounding
(VICTORY_F16_NEAREST): NVIDIA converts toward zero, which gives the
largest finite half for 1.0 * 2^16 where the console gives +inf.

319 passed, 4 ignored, on the RTX 5060 Ti and WARP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jennydeth pushed a commit to jennydeth/Hail-to-the-Thief that referenced this pull request Nov 27, 2026
…e), 4 KiB dirty tracking, gather segments, the black-face texture fixes, shadow and translator fixes from pull requests

Measured in in-run on/off splits on an RTX 4070 (diagnostics builds, the
same switches for every run):
- VICTORY_CARD_HASH_WIDE=1|alt: the card's hashes of copies' pieces by a group
  of 64 threads a piece, alternating per submission: card -10 ms a frame
  (86.5 vs 96.5), world frames -5 ms.
- VICTORY_GATHER_SEGMENTS=1|alt (after flipflop877 c69bff19): one clamp pass
  per segment once a list stops gathering: ~30 records a pass, neutral to
  slightly faster at equal draws.
- VICTORY_DIRTY_4K=1|alt: refreshes copy only the written 4 KiB pages of a
  stale write-watched page: -45 % of those bytes; faster in loading, no world
  gain.
Fixes:
- Textures under a DirectStorage write or a landed plain read are made due
  again (VICTORY_PAGE_WRITES default 1|2|8): textures uploaded before their
  data landed kept zeros (black faces); VICTORY_HEAP_RECHECK_EVERY=<frames>
  keeps looking at uploaded textures after the schedule (after RyanCase94).
- Pull requests Marvisak#646 (builder dispatches count threads), Marvisak#1002 (alpha-tested
  geometry casts cascade shadows), Marvisak#1314, Marvisak#1324, Marvisak#589, Marvisak#702, Marvisak#1112 (mesh
  triangle corners masked 9 bits, cube-map levels, two-sampler branches,
  split 64-lane masks); upstream Marvisak#3198 (textures without card room retried).
- VICTORY_WAVE_WIDE_ONLY=<hashes>: listed refused programs may take the
  wave-wide form (after Marvisak#823's a416e39; the water's colour, with dark patches
  still under investigation).
- VICTORY_MERGE_RUNS_ALT, VICTORY_CLAMP_LEAN, VICTORY_CLAMP_WINDOW,
  VICTORY_OCCLUSION: measured, no gain; off.
The shader translator changed: delete both shader caches before the first run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants