shader: lower v_add_nc_i16, v_sub_nc_i16, v_mad_i16, and v_mad_u16 with clamp #1698
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1699"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T20:52:11Z.
Summary
crates/victory-shader/src/emit/lower.rs(valu16_op), honoringop_sel[0..3]and preserving the untouched VGPR half viawrite_halfwith pure 32-bit DXIL arithmetic:v_add_nc_i16(0x30d),v_sub_nc_i16(0x30e),v_mad_i16(0x35e), andv_mad_u16(0x340), with both wraparound andCLAMPsaturation ([-32768, 32767]signed /[0, 65535]unsigned).v_{min3,max3,med3}_{i16,u16}), #1688 (v_mad_{u32_u16,i32_i16}), and #1668 (half_srcinline float handling).Verification
cargo test -p victory-shader --lib valu_tests: PASS on both AMD Radeon RX 9060 XT (D3D12 hardware) and Microsoft Basic Render Driver (WARP), includingvop3_16bit_int_add_sub_mad_and_triads_match_rdna2testing all 4 instructions across wrap vsCLAMPsaturation,op_selhigh/low half selection, and untouched VGPR half preservation.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: pass (154 files).AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T20:56:54Z.
Review: APPROVED
Verified locally merged onto
origin/main(Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, withdxil.dllvalidator):cargo test -p victory-shader --lib vop3_16bit_int_add_sub_mad_and_triads_match_rdna2— passed on RTX 5090 hardware and underVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— okClean lowering of the 10 RDNA2 16-bit integer VOP3 ops (add/sub/mad/min3/max3/med3) with end-to-end GPU+WARP verification. Looks good.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by adamdotpy on 2026-11-24T21:09:43Z.
Reviewed head
6fd640alocally (isolated worktree, fresh CARGO_TARGET_DIR, real GPU dispatch).What it does: lowers
v_add_nc_i16,v_sub_nc_i16,v_mad_i16,v_mad_u16in the shared 16-bit VOP3 arm. Signed forms sext all three sources to i32, compute in 32-bit, and when the clamp bit is set saturate to [i16::MIN, i16::MAX] (SLT/SGT + select);v_mad_u16saturates to u16::MAX with an unsigned compare. Clamp is now accepted for exactly these four names and still refused for the other 16-bit ops (v_add_nc_u16etc.), keeping the conservative refusal where hardware behavior wasn't pinned.Verified locally:
cargo test -p victory-shader --lib vop3_16bit_int_add_sub_mad_and_triads_match_rdna2 -- --nocapture— passes on hardware (2.2s, no skip): 4 ops x clamp on/off x 4 cases, checking wrap vs clamp, exact i32/u32 reference, and high-half preservation through op_sel writescargo test -p victory-shader --lib --locked— 121 passed / 0 failed / 1 ignoredcargo clippy -p victory-shader --all-targets --all-features --locked— cleancargo build --release -p victory --locked— okmain@ffe310e:lower.rshas the same 3 pre-existing hunks (7099/7118/7137 -> 7142/7161/7180, shifted by the added lines), no new ones;valu_tests.rshas 2 new cosmetic hunks (940, 980, long lines in the new test)Findings, ranked:
half_src(f16-packed inline constants), but 16-bit integer ops read inline floats as raw f32 bits — so when #1668 lands,let mut d = self.half_src(inst, 2)?must becomehalf_int_src(inst, 2), and the shared(a, b)pair flips tohalf_int_srctoo (textual conflict at the same lines, same behavior). Worth a one-line note here so the second merger adjusts the mad operand as well.LGTM, with the #1668 note above.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:40:04Z.
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. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.v_add_nc_i16/v_sub_nc_i16/v_mad_i16/v_mad_u16 lowered with clamp support (computed on selected 16-bit halves, low 16 bits kept); clamp_ok gate rejects clamp/omod/abs/neg for the rest. Hardware tests on RDNA2/WARP.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T22:46:09Z.
Measurement-backed extensions to the clamp list, from reading the diff (not run). AnyPS5 measured the VOP3 clamp bit on 16-bit integer ops on RDNA2 hardware: gfx1036, wave32 and wave64; boykopovar/AnyPS5's
docs/dev/debt/shader.md"VOP3 16-bit integer binary clamp" and boykopovar/AnyPS5#22615.v_mul_lo_u16,v_lshlrev_b16,v_lshrrev_b16,v_ashrrev_i16,v_min/max_u16andv_min/max_i16, the clamp bit changed none of the results.v_mul_lo_u16keeps the low 16 bits of an overflowing product. Those eight could acceptclampas a no-op instead of refusing it. The one to keep wrapping isv_mul_lo_u16; XCL's #202 currently saturates it.v_add_nc_u16with clamp saturates on the same part. It is still refused byclamp_okhere and would be the unsigned counterpart of yourv_add_nc_i16path.v_sub_nc_u16is presumably the same, but wasn't in that measurement.AI-assisted (Claude Code). No game files.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:24:50Z.
Automated triage for the maintainers. Closing because another open pull request covers the same change.
See #1211. v_mad_u16/v_mad_i16 with clamp (the same code as #1211) plus v_add_nc_i16/v_sub_nc_i16 (also in #92). None is used by the title.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:34:45Z.
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
Pull request closed