Shaders: support saturating clamp on packed 16-bit integer ops (v_pk_{add,sub,mad}_{u16,i16}) #1142
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!1142
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1142"
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?
@ESAT586 on GitHub · 2026-11-24 16:10 UTC · original
ESAT586:shader/pk-int16-clamp→main· +149 −2 · 2 files · 1 commits · openWhat's wrong
In
crates/victory-shader/src/emit/lower.rs(packed16, line 4788), any packed 16-bit integer instruction withv.clamp == truefails lowering withUnsupported { what: "modifiers on a packed integer operation" }.Under the AMD RDNA2 ISA (VOP3P),
clamp = 1is the saturating integer modifier forv_pk_add_u16,v_pk_sub_u16,v_pk_mad_u16,v_pk_add_i16,v_pk_sub_i16, andv_pk_mad_i16, clamping each 16-bit lane to[0, 65535](unsigned) or[-32768, 32767](signed).Fix
v.clampinLower::packed16specifically for the 6 saturating packed integer ops (add_u16,sub_u16,mad_u16,add_i16,sub_i16,mad_i16); non-saturating packed integer ops (mul_lo_u16, shifts,min/max) continue to rejectv.clamp.& 0xFFFFmask:add_u16/mad_u16:u16::MAX * u16::MAX + u16::MAX = 4,294,901,760 <= u32::MAX(never wrapsu32), sor >u 0xFFFF ? 0xFFFF : ris exact.sub_u16: operands are in[0, 65535], soris in[-65535, 65535]andr <s 0 ? 0 : rcatches underflow exactly.add_i16/sub_i16/mad_i16: operands are sign-extended toi32(|r| <= 32768 * 32768 + 32768 < 2^31, never wrapsi32), so signed clamp to[-32768, 32767]is exact.emit::valu_tests::v_pk_int16_clamp_saturates_as_rdna2incrates/victory-shader/src/emit/valu_tests.rstesting all 6 instructions withclamp = 1across overflow, underflow, max-product, and in-range lanes.Verification (Real GPU + WARP + CI Gates)
Tested on Windows 11, NVIDIA GeForce RTX 3060 Ti (driver
32.0.16.1656), Rust1.98.1:cargo test -p victory-shader --lib v_pk_int16_clamp_saturates_as_rdna2: ok (dxil.dllvalidator + RTX 3060 Ti hardware + Microsoft WARP)cargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignoredcargo clippy --workspace --all-targets --locked -- -D warnings: pass (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass (0 warnings)cargo xtask policy:asset policy: 154 files okScope & Non-Overlap
v_pk_{add,sub,mad}_{u16,i16}saturatingclamp.AI-generated & verified with Gemini 4 Neon (High Mode) — not written by a human engineer. `packed16` in `lower.rs` previously rejected `v.clamp` on all packed 16-bit integer instructions with `Err("modifiers on a packed integer operation")`. Under the AMD RDNA2 ISA (VOP3P), `clamp` on `v_pk_add_u16`, `v_pk_sub_u16`, `v_pk_mad_u16`, `v_pk_add_i16`, `v_pk_sub_i16`, and `v_pk_mad_i16` saturates each 16-bit lane to `[0, 65535]` (unsigned) or `[-32768, 32767]` (signed). Because `packed16` computes each lane in 32 bits (`u16*u16+u16 <= u32::MAX`, `i16*i16+i16` fits in `i32`), saturation is exact in 32-bit integer compares before masking to 16 bits. Non-saturating packed integer ops keep rejecting `clamp`. Verified with synthetic GPU + WARP + dxil.dll tests in `valu_tests.rs` on NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used. Co-Authored-By: Gemini 4 Neon (High Mode) <[email protected]>f76cf2bbcetode111550b7@ghost on GitHub · 2026-11-24 16:35 UTC · original
Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head
bf873ffon mainffe310e. Your report lists NVIDIA and WARP, so this adds AMD hardware.v_pk_int16_clamp_saturates_as_rdna2passes: v_pk_{add,sub,mad}_{u16,i16} with clamp, per half, including the 65535*65535+65535 case.stub_pipeline_is_created, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR).Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the new test fails without the fix on this host.
AI-assisted (Claude Code, Claude Opus 5.5); no game data.
@Zipettte on GitHub · 2026-11-24 18:01 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
bf873ff:cargo test -p victory-shaderpasses, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@Marvisak on GitHub · 2026-11-25 00:37 UTC · original · edited 2026-11-26 05:24 UTC
Automated triage for the maintainers.
Merge candidate (recommending a look, not approving). Thanks for the rebase: the branch now merges cleanly onto
main. Incrates/victory-shader/src/emit/lower.rsLower::packed16, theclampbit is now accepted only forv_pk_{add,sub,mad}_{u16,i16}and saturates each half before the 16-bit mask; the other packed integer ops still refuse it. I checked the range arguments (unsigned mad peaks at 4,294,901,760, belowu32::MAX; signed results stay insidei32) and the VOP3P encoding and opcodes in the newvalu_tests.rstest against the RDNA2 ISA. Saturation viaclampon these ops matches the ISA document the PR cites. CIcheckpasses onde11155.Generated by Claude Code
@ESAT586 on GitHub · 2026-11-25 13:01 UTC · original
Rebased onto \main\ (\
940d32f) at $sha. Verified on RTX 3060 Ti + WARP: \_pk_int16_clamp_saturates_as_rdna2\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.@fuzeofficlal on GitHub · 2026-11-26 16:02 UTC · original · approved these changes
The saturation ranges and signedness checks look right for all six packed integer ops (
v_pk_{add,sub,mad}_{u16,i16}):mad_u16peaks at0xffff_0000(fitting inu32soIUGTcatches overflow without wrap),sub_u16spans[-65535, 65535](soSLTagainst0catches underflow), and all three signed ops stay strictly withini32before clamping to[i16::MIN, i16::MAX]. SourceOPSEL/OPSEL_HIselection and wrapping whenclampis clear remain intact, andmul_lo_u16/min/max/shifts still rejectclamp.As optional follow-up coverage, a non-default
OPSEL/OPSEL_HItest and aCLAMP=0wrap-around case would pin those paths as well.Local verification at
de111550(and merged cleanly ontoorigin/main63bcca43,emit/lower.rs=522,255B,2,033B under the 512 KiB cap):xtask policy(191 files ok),cargo clippy -p victory-shader --all-targets(default and--all-features),emit::valu_testson both RTX 5090 and WARP (36/36), andv_pk_int16_clamp_saturates_as_rdna2on RTX 5090 and WARP all passed.@Dukestar69 on GitHub · 2026-11-26 19:50 UTC · original · approved these changes
LGTM — verified on RTX 5090 and
VICTORY_WARP=1(Windows / D3D12) againstorigin/main(63bcca4).CLAMPon packed 16-bit integer ops (v_pk_{add,sub,mad}_{u16,i16}) matches RDNA2 semantics cleanly on both discrete NVIDIA hardware and WARP.cargo test -p victory-shader --lib emit::valu_tests::v_pk_int16_clamp_saturates_as_rdna2 -- --test-threads=1: passed on RTX 5090 andVICTORY_WARP=1.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.