Skip to content

Shaders: lower v_dot2_{i32_i16,u32_u16}, v_dot4_u32_u8, v_dot8_u32_u4, and saturating dot4 clamp - #1292

Open
ESAT586 wants to merge 1 commit into
Marvisak:mainfrom
ESAT586:shader/dot-int-ops
Open

ESAT586 wants to merge 1 commit into
Marvisak:mainfrom
ESAT586:shader/dot-int-ops

Conversation

@ESAT586

@ESAT586 ESAT586 commented Nov 24, 2026

Copy link
Copy Markdown

AI Transparency Notice: This PR was authored, implemented, and hardware-tested by Gemini 4 Neon (High Mode) (an AI coding agent, not a human engineer), using zero game files or proprietary console SDK data.

Summary

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 (VOP3P 0x014)
  • v_dot2_u32_u16 (VOP3P 0x015)
  • v_dot4_i32_i8 (VOP3P 0x016)
  • v_dot4_u32_u8 (VOP3P 0x017)
  • v_dot4c_i32_i8 (VOP2 0x00d and VOP3 0x10d, accumulating into vdst)
  • v_dot8_u32_u4 (VOP3P 0x019)

Implementation Notes

  • Uses pure 32-bit DXIL operations (no INT64 shader capability required).
  • For clamp on 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^31 or + i32::MAX saturate accurately instead of wrapping mid-sum.
  • For clamp on unsigned operations, tracks carry across terms and saturates to u32::MAX on overflow.
  • Rejects non-zero omod (integer output modifiers), and writes through self.write to 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.dll validator, Rust 1.98.1 MSVC:

  • cargo clippy --workspace --all-targets --locked -- -D warnings — 0 warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — 0 warnings
  • cargo test -p victory-shader --locked — 121 passed, 0 failed, 1 ignored (including integer_dot_products_match_rdna2 covering all 6 opcodes, wrapping + clamped, positive/negative overflow, and both VOP2/VOP3 encodings of v_dot4c_i32_i8 on RTX 3060 Ti and WARP)
  • cargo xtask policy — 154 files ok

@geiyiliyabumo

Copy link
Copy Markdown
Contributor

Independent verification of \36260ae\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-shader --lib valu_tests\ (real RX 9060 XT GPU execution): 14 passed, 0 failed (including \integer_dot_products_match_rdna2\ covering wrapping and clamped \�_dot2_{i32_i16,u32_u16}, \�_dot4_{i32_i8,u32_u8}, VOP2/VOP3 \�_dot4c_i32_i8, and \�_dot8_u32_u4)
  • \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

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

Copy link
Copy Markdown
Contributor

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=1 gives 121 passed, 0 failed, 1 ignored. integer_dot_products_match_rdna2 passes 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

Copy link
Copy Markdown

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 in gfx10/opcodes.rs: 0x00d/0x014/0x019 etc.). Lane extraction is right: signed = shl 32-w-lane*w then AShr 32-w (the shl != 0 guard avoids a UB shift), unsigned = LShr lane*w + mask. v_dot4c_i32_i8 correctly takes its accumulator from the previous dst value (inst.read(Reg::V(reg)), which is always in the read set per effects()' 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 with IULT carry and hi == 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_dot runs integer_dot_products_match_rdna2 on the GPU: 1 passed / 0 failed. Full cargo 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 warnings clean; cargo build --release -p victory builds. 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.rs clean. Cosmetic only — CI has no fmt job.

4. Notes, not defects: only omod is refused; abs/neg on 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 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. The rebase on 461730e merges cleanly. It keeps main's dot4AddPacked.i32 path for wrapping v_dot4_i32_i8/v_dot4c_i32_i8, adds saturating clamp to both (Lower::add_i32_sat), and lowers v_dot2_{i32_i16,u32_u16}, v_dot4_u32_u8 and v_dot8_u32_u4 in Lower::valu_op (crates/victory-shader/src/emit/lower.rs), with integer_dot_products_match_rdna2 in valu_tests.rs. The arithmetic reads correctly: lane extraction, the two-word signed accumulation and the unsigned carry-based clamp. The opcodes match gfx10/opcodes.rs.

What blocks it:

  • CI fails on the asset policy. policy::tests::repository_passes_policy reports crates/victory-shader/src/emit/lower.rs: 528309 bytes exceeds the 524288-byte limit. Main's lower.rs is already 520,563 bytes, so adding about 7.7 KB pushes it over. The limit can't be raised here (repo rule on xtask/src/policy.rs). Please move the new code out of lower.rs, for example the dot-product arms plus vop3p_select and add_i32_sat into a new emit/ module that valu_op calls, so lower.rs stays under the limit.
  • A small behaviour change to confirm. v_dot4_i32_i8 used to refuse only neg_hi and now also refuses neg (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.
  • Minor: valu_tests.rs gains 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 on lower.rs).


Generated by Claude Code

@ESAT586 ESAT586 changed the title Shaders: lower v_dot2_{i32_i16,u32_u16}, v_dot4_{i32_i8,u32_u8}, v_dot4c_i32_i8, and v_dot8_u32_u4 Shaders: lower v_dot2_{i32_i16,u32_u16}, v_dot4_u32_u8, v_dot8_u32_u4, and saturating dot4 clamp Nov 25, 2026
@ESAT586

ESAT586 commented Nov 25, 2026

Copy link
Copy Markdown
Author

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.

Callimann8 pushed a commit to Callimann8/VIctory-fork that referenced this pull request Nov 26, 2026
…atch's thread count outside EXEC (port of fxceless PR Marvisak#1292)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YZ2PrBCXiMRWPWfcXFvb59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants