Shaders: support saturating clamp on packed 16-bit integer ops (port of upstream VIctory #1142) #1040
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1042"
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 fxceless/victory-fork. Originally posted by Moon0755 on 2026-11-25T17:13:39Z.
Port of upstream
Marvisak/VIctory#1142(originally authored by@ESAT586).Summary
Adds saturating
clampsupport for RDNA2 packed 16-bit integer VOP3P operations:v_pk_add_u16,v_pk_sub_u16,v_pk_mad_u16,v_pk_add_i16,v_pk_sub_i16, andv_pk_mad_i16.Previously,
Lower::packed16rejectedv.clampon all packed integer operations (Err("modifiers on a packed integer operation")), preventing shaders using saturating 16-bit packed integer arithmetic from lowering.Changes
crates/victory-shader/src/emit/lower.rs:v.clampinLower::packed16specifically for"add_u16" | "sub_u16" | "mad_u16" | "add_i16" | "sub_i16" | "mad_i16"(while continuing to rejectomod,neg/neg_hi, andclampon non-saturating packed integer ops).add_u16/mad_u16: clamp unsigned values> 0xFFFFto0xFFFF(since65535 * 65535 + 65535 <= u32::MAX, the 32-bit intermediate never wraps).sub_u16: clamp signed< 0underflow to0.add_i16/sub_i16/mad_i16: clamp sign-extended 32-bit intermediates to[i16::MIN, i16::MAX](|r| <= 32768 * 32768 + 32768 < 2^31, soi32never wraps).crates/victory-shader/src/emit/valu_tests.rs: addedvop3pencoding helper and D3D12 WARP regression testv_pk_int16_clamp_saturates_as_rdna2testing overflow, underflow, and in-range lanes across all 6 instructions (includingu16::MAX * u16::MAX + u16::MAXandi16::MIN * i16::MIN + i16::MAX).Verification
Verified on
windows-latestvia GitHub Actions (run 45661896173):cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings— passedcargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings— passedcargo test -p victory-shader -p xtask --locked -- --nocapture—216 passed; 0 failed; 3 ignored(includingv_pk_int16_clamp_saturates_as_rdna2executed on D3D12 WARP, plusxtask4 passed,repository_passes_policypassed)— Neon
Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T17:20:26Z.
Independent synthetic shader check on base
ca8829fand the GitHub test mergeaca45c3for heade0e993d(head and merge have identical source trees).--all-targets --locked, including compilation of the WARP test.The CPU evaluation covered the emitted integer dataflow. I did not independently run WARP, physical GPU readback, or the Microsoft DXIL validator.
Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T18:01:01Z.
A hardware run of this PR's new test:
v_pk_int16_clamp_saturates_as_rdna2passes on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with #402's Agility SDK runtime. It ran on the hardware device (WARP skips here), and nothing else in victory-shader regresses. The setup, and the same run for eight related ports, are in one table on #1030: https://github.com/fxceless/victory-fork/pull/1030#issuecomment-7170315986Pull request closed