Shaders: lower v_dot2_{i32_i16,u32_u16}, v_dot4_u32_u8, v_dot8_u32_u4, and saturating dot4 clamp #1292
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!1292
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1292"
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 17:10 UTC · original
ESAT586:shader/dot-int-ops→main· +393 −38 · 2 files · 1 commits · openSummary
Lowers all 6 GFX10/RDNA2 integer packed dot-product instructions in
victory-shader, with exact wrapping and saturating (clamp) 32-bit accumulation:v_dot2_i32_i16(VOP3P0x014)v_dot2_u32_u16(VOP3P0x015)v_dot4_i32_i8(VOP3P0x016)v_dot4_u32_u8(VOP3P0x017)v_dot4c_i32_i8(VOP20x00dand VOP30x10d, accumulating intovdst)v_dot8_u32_u4(VOP3P0x019)Implementation Notes
INT64shader capability required).clampon signed operations, accumulates in exact 64-bit(lo, hi)two-word form before saturating to[i32::MIN, i32::MAX]so edge cases like(-32768 * -32768) * 2 + 0 = +2^31or+ i32::MAXsaturate accurately instead of wrapping mid-sum.clampon unsigned operations, tracks carry across terms and saturates tou32::MAXon overflow.omod(integer output modifiers), and writes throughself.writeto preserve EXEC lane guards and SDWA placement.Verification
Tested locally on Windows 11 with NVIDIA GeForce RTX 3060 Ti (
Driver 32.0.16.1656) + Microsoft WARP +dxil.dllvalidator, Rust1.98.1MSVC:cargo clippy --workspace --all-targets --locked -- -D warnings— 0 warningscargo clippy --workspace --all-targets --all-features --locked -- -D warnings— 0 warningscargo test -p victory-shader --locked— 121 passed, 0 failed, 1 ignored (includinginteger_dot_products_match_rdna2covering all 6 opcodes, wrapping + clamped, positive/negative overflow, and both VOP2/VOP3 encodings ofv_dot4c_i32_i8on RTX 3060 Ti and WARP)cargo xtask policy— 154 files ok06a1725cbato461730ed7a@geiyiliyabumo on GitHub · 2026-11-24 17:24 UTC · original
Independent verification of \36260ae\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:
Code audit: the two-word 64-bit signed accumulation (\lo/\hi\ without requiring \INT64\ capability) is exact—each \i16 * i16\ product fits in \i32, \4 * i8 * i8\ stays in [-65024, 65536], and \hi == (lo >> 31)\ accurately detects 32-bit signed saturation.
AI-assisted; synthetic tests only, no game files.
@marquezinii on GitHub · 2026-11-24 18:10 UTC · original
NVIDIA data point to go with the RDNA4 run above: RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1, head
36260ae.cargo test -p victory-shader --lib -- --test-threads=1gives 121 passed, 0 failed, 1 ignored.integer_dot_products_match_rdna2passes on the hardware adapter and WARP. The lowering uses only 32-bit integer ops, so it should not depend on the host. This run confirms that on a second vendor.@adamdotpy on GitHub · 2026-11-24 18:25 UTC · original
Reviewed at head
36260ae(worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:1. Semantics verified exhaustively against exact arithmetic. The new arm lowers
v_dot2_{i32_i16,u32_u16},v_dot4_{i32_i8,u32_u8},v_dot4c_i32_i8,v_dot8_u32_u4(opcodes confirmed ingfx10/opcodes.rs: 0x00d/0x014/0x019 etc.). Lane extraction is right: signed = shl32-w-lane*wthen AShr32-w(theshl != 0guard avoids a UB shift), unsigned = LShrlane*w+ mask.v_dot4c_i32_i8correctly takes its accumulator from the previous dst value (inst.read(Reg::V(reg)), which is always in the read set pereffects()' tail; an unwritten dst refuses, consistent with the undef policy). I modeled the emitted ops — including the two's-complement 64-bit (lo,hi) accumulator for signed clamp withIULTcarry andhi == AShr(lo,31)range test, and the carry-OR for unsigned clamp — against an exact-integer reference with saturation, over 210,000 combinations (all edge values × edge × edge plus 20k random per config, all five shapes, clamp on and off): 0 mismatches. The lane-count reduction (4/8 products pre-summed into one i32 term, exact since 4×i8·i8 ∈ [-65024, 65536] and 8×u4·u4 ≤ 1800) is sound.2. Hardware evidence on this machine.
cargo test -p victory-shader --lib integer_dotrunsinteger_dot_products_match_rdna2on the GPU: 1 passed / 0 failed. Fullcargo test -p victory-shader --lib: 121 passed / 0 failed / 1 ignored (22 s).3. Checks:
cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warningsclean;cargo build --release -p victorybuilds.rustfmt --edition 2024 --check: one new hunk in the PR's own code (lower.rs:4009, the(imin, imax)tuple), the other three are main's pre-existing hunks shifted by the +118 lines;valu_tests.rsclean. Cosmetic only — CI has no fmt job.4. Notes, not defects: only
omodis refused;abs/negon these integer ops are ignored rather than refused (hardware ignores them for integer ops, so emitting without them matches). The non-clamped path wraps in 32 bits, which is the ISA behavior. These opcodes previously fell through to a refusal, so this strictly widens translation.Nothing found that would block this.
@Marvisak on GitHub · 2026-11-25 01:21 UTC · original · edited 2026-11-26 05:39 UTC
Automated triage for the maintainers.
Needs work. The rebase on
461730emerges cleanly. It keeps main'sdot4AddPacked.i32path for wrappingv_dot4_i32_i8/v_dot4c_i32_i8, adds saturatingclampto both (Lower::add_i32_sat), and lowersv_dot2_{i32_i16,u32_u16},v_dot4_u32_u8andv_dot8_u32_u4inLower::valu_op(crates/victory-shader/src/emit/lower.rs), withinteger_dot_products_match_rdna2invalu_tests.rs. The arithmetic reads correctly: lane extraction, the two-word signed accumulation and the unsigned carry-based clamp. The opcodes matchgfx10/opcodes.rs.What blocks it:
policy::tests::repository_passes_policyreportscrates/victory-shader/src/emit/lower.rs: 528309 bytes exceeds the 524288-byte limit. Main'slower.rsis already 520,563 bytes, so adding about 7.7 KB pushes it over. The limit can't be raised here (repo rule onxtask/src/policy.rs). Please move the new code out oflower.rs, for example the dot-product arms plusvop3p_selectandadd_i32_satinto a newemit/module thatvalu_opcalls, solower.rsstays under the limit.v_dot4_i32_i8used to refuse onlyneg_hiand now also refusesneg(neg_lo). Programs that translated on main with neg_lo bits set would now be refused. Please either keep main's behaviour or say why neg_lo must be refused.valu_tests.rsgains a doubled blank line before the new test.With the file-size fix and CI green, this would be a merge candidate again. The earlier hardware runs and the exhaustive model check in the comments support the semantics.
CI: failing (
check: asset-policy file-size limit onlower.rs).Generated by Claude Code
@ESAT586 on GitHub · 2026-11-25 11:28 UTC · original
Rebased onto \main\ (\
940d32f) at $sha. Kept \main's hardware \dot4AddPacked.i32\ path for wrapping \_dot4_i32_i8\ / \_dot4c_i32_i8\ and extended both with saturating \clamp\ (32-bit saturating add, no INT64); lowered the remaining \dot2{i32_i16,u32_u16}, \_dot4_u32_u8, and \_dot8_u32_u4\ with VOP3P \opsel/\opsel_hi\ support and \clamp. Verified on RTX 3060 Ti + WARP: \integer_dot_products_match_rdna2, \spx_programs_run_with_the_hardwares_dot_products, and \yte_dot_products_match_the_hardware\ all passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.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.