shader: lower v_add_nc_i16, v_sub_nc_i16, v_mad_i16, and v_mad_u16 with clamp #1699
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1699
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1699/head"
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?
@geiyiliyabumo on GitHub · 2026-11-24 20:52 UTC · original
geiyiliyabumo:fix/shader-16bit-int-vop3→main· +126 −3 · 2 files · 1 commits · closed without mergingSummary
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.
@adamdotpy on GitHub · 2026-11-24 21:09 UTC · original
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.
@upipibi on GitHub · 2026-11-24 22:46 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 01:24 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 01:34 UTC · original
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