shader: lower 6 RDNA2 integer dot-product instructions without INT64 #1694

Closed
github-bot wants to merge 1 commit from gh-pr/1694/head into gh-pr/1694/base
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 20:48 UTC · original
geiyiliyabumo:fix/shader-dot-products → main · +208 −1 · 2 files · 1 commits · closed without merging

Summary

  • Lowers all six RDNA2 VOP2/VOP3P integer dot-product instructions in crates/victory-shader/src/emit/lower.rs (Lower::dot_int):
    • VOP2 in-place accumulator: v_dot4c_i32_i8 (0x00d, reading old vdst already supplied by ir.rs).
    • VOP3P 3-operand forms: v_dot2_i32_i16 (0x014), v_dot2_u32_u16 (0x015), v_dot4_i32_i8 (0x016), v_dot4_u32_u8 (0x017), v_dot8_u32_u4 (0x019).
  • Uses pure 32-bit DXIL arithmetic so shaders set neither INT64 (0x8000) nor native 16-bit (0x40000) feature flags in SFI0.
  • Matches AMD RDNA2 ISA §§6.5, 12.7, 12.10: honors VOP3P op_sel/op_sel_hi half selection on dot2, exact signed/unsigned CLAMP saturation (including i16x2 +2^31 and u16x2 double-carry saturation), and wraparound when clamp is clear.
  • Scoped cleanly to integer dot products so this composes without conflict alongside #465 (v_dot2_f32_f16 / v_dot2c_f32_f16).

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) (v_dot4c_i32_i8_reads_old_destination_and_wraps, vop3p_integer_dots_clamp_or_wrap_the_full_sum, vop3p_integer_dot2_selects_each_source_half, asserting both INT64 and native 16-bit SFI0 flags are clear).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: pass (154 files).

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 20:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1694) `geiyiliyabumo:fix/shader-dot-products` → `main` · +208 −1 · 2 files · 1 commits · closed without merging ## Summary - Lowers all six RDNA2 VOP2/VOP3P integer dot-product instructions in `crates/victory-shader/src/emit/lower.rs` (`Lower::dot_int`): - VOP2 in-place accumulator: `v_dot4c_i32_i8` (`0x00d`, reading old `vdst` already supplied by `ir.rs`). - VOP3P 3-operand forms: `v_dot2_i32_i16` (`0x014`), `v_dot2_u32_u16` (`0x015`), `v_dot4_i32_i8` (`0x016`), `v_dot4_u32_u8` (`0x017`), `v_dot8_u32_u4` (`0x019`). - Uses pure 32-bit DXIL arithmetic so shaders set neither `INT64` (`0x8000`) nor native 16-bit (`0x40000`) feature flags in `SFI0`. - Matches AMD RDNA2 ISA §§6.5, 12.7, 12.10: honors VOP3P `op_sel`/`op_sel_hi` half selection on `dot2`, exact signed/unsigned `CLAMP` saturation (including `i16x2` `+2^31` and `u16x2` double-carry saturation), and wraparound when `clamp` is clear. - Scoped cleanly to integer dot products so this composes without conflict alongside #465 (`v_dot2_f32_f16` / `v_dot2c_f32_f16`). ## 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)** (`v_dot4c_i32_i8_reads_old_destination_and_wraps`, `vop3p_integer_dots_clamp_or_wrap_the_full_sum`, `vop3p_integer_dot2_selects_each_source_half`, asserting both `INT64` and native 16-bit `SFI0` flags are clear). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: pass (154 files). *AI-assisted; synthetic tests only, no game files.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:41:49 +00:00
github-bot closed this pull request 2026-11-26 04:41:49 +00:00
Author
Owner

@⁠adamdotpy on GitHub · 2026-11-24 21:36 UTC · original

Reviewed head da18cb8 locally (isolated worktree, fresh CARGO_TARGET_DIR, real GPU dispatch, ~90s for the dot tests).

What it does: lowers the six RDNA2 integer dot products — v_dot2_{i32_i16,u32_u16}, v_dot4c_i32_i8/v_dot4_i32_i8, v_dot4_u32_u8, v_dot8_u32_u4 — in pure 32-bit DXIL via a shared dot_int: per-lane BFE/SDWA-style extraction (select_bits, opsel picks each 16-bit half), i32 products summed with Bin::Add, accumulator read from the old destination for the 2-source VOP2 forms and from src2 for the VOP3P/c forms. Clamp: signed saturates with sign-based overflow detection, with the width-16 special case that a dot of exactly +2^31 has bit pattern 0x80000000 and must count as positive (handled by an unsigned IUGT(dot, i32::MIN) test); unsigned saturates to u32::MAX using the carry from add_sub_carry, tracked at the second 16-bit lane where a carry is possible.

Verified locally:

  • cargo test -p victory-shader --lib dot -- --nocapture — all 3 new tests pass on hardware: the 11-case x 5-ops x clamp on/off sweep against an i64 reference (including +2^31-before-add, opposite-signed products, unsigned carry, accumulator-only carry), the VOP2 dst-as-accumulator wrap test, and the opsel half-selection test. build_dot_cs also asserts SFI0 has neither INT64 nor NATIVE_16BIT_OPS, so the lowering provably needs no 64-bit ops.
  • cargo test -p victory-shader --lib --locked — 123 passed / 0 failed / 1 ignored
  • cargo clippy -p victory-shader --all-targets --all-features --locked — clean
  • cargo build --release -p victory --locked — ok
  • rustfmt vs main@⁠ffe310e: lower.rs same 3 pre-existing hunks (shifted), valu_tests.rs 0 — no new fmt hunks

Findings, ranked:

  1. Sound. I checked the edge cases by hand: the only dot sum outside i32 is the two-product +2^31 for width 16, and the unsigned-compare trick classifies 0x80000000 correctly as positive; the signed overflow select then saturates to i32::MAX as hardware would (case 4/6/7 in the sweep pin exactly this). Unsigned carry can only arise at the second 16-bit product, which is where it's tracked. Accumulator source (old dst vs src2) matches the VOP2/VOP3P split.
  2. Complements #1292 (which we reviewed earlier for the other integer dot forms) — no opcode overlap; both reduce INT64 dependence, which the SFI0 assertion in the tests proves for these six.
  3. No issues found. The 90s runtime of the sweep is just 110 hardware dispatches; fine for a GPU test.

LGTM.

**@⁠adamdotpy** on GitHub · 2026-11-24 21:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/1694#issuecomment-7145146178) Reviewed head da18cb8 locally (isolated worktree, fresh CARGO_TARGET_DIR, real GPU dispatch, ~90s for the dot tests). **What it does:** lowers the six RDNA2 integer dot products — `v_dot2_{i32_i16,u32_u16}`, `v_dot4c_i32_i8`/`v_dot4_i32_i8`, `v_dot4_u32_u8`, `v_dot8_u32_u4` — in pure 32-bit DXIL via a shared `dot_int`: per-lane BFE/SDWA-style extraction (`select_bits`, opsel picks each 16-bit half), i32 products summed with `Bin::Add`, accumulator read from the old destination for the 2-source VOP2 forms and from src2 for the VOP3P/`c` forms. Clamp: signed saturates with sign-based overflow detection, with the width-16 special case that a dot of exactly +2^31 has bit pattern 0x80000000 and must count as positive (handled by an unsigned `IUGT(dot, i32::MIN)` test); unsigned saturates to u32::MAX using the carry from `add_sub_carry`, tracked at the second 16-bit lane where a carry is possible. **Verified locally:** - `cargo test -p victory-shader --lib dot -- --nocapture` — all 3 new tests pass on hardware: the 11-case x 5-ops x clamp on/off sweep against an i64 reference (including +2^31-before-add, opposite-signed products, unsigned carry, accumulator-only carry), the VOP2 dst-as-accumulator wrap test, and the opsel half-selection test. `build_dot_cs` also asserts SFI0 has neither INT64 nor NATIVE_16BIT_OPS, so the lowering provably needs no 64-bit ops. - `cargo test -p victory-shader --lib --locked` — 123 passed / 0 failed / 1 ignored - `cargo clippy -p victory-shader --all-targets --all-features --locked` — clean - `cargo build --release -p victory --locked` — ok - rustfmt vs `main`@⁠ffe310e: `lower.rs` same 3 pre-existing hunks (shifted), `valu_tests.rs` 0 — no new fmt hunks **Findings, ranked:** 1. Sound. I checked the edge cases by hand: the only dot sum outside i32 is the two-product +2^31 for width 16, and the unsigned-compare trick classifies 0x80000000 correctly as positive; the signed overflow select then saturates to i32::MAX as hardware would (case 4/6/7 in the sweep pin exactly this). Unsigned carry can only arise at the second 16-bit product, which is where it's tracked. Accumulator source (old dst vs src2) matches the VOP2/VOP3P split. 2. Complements #1292 (which we reviewed earlier for the other integer dot forms) — no opcode overlap; both reduce INT64 dependence, which the SFI0 assertion in the tests proves for these six. 3. No issues found. The 90s runtime of the sweep is just 110 hardware dispatches; fine for a GPU test. LGTM.
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:52 UTC · original

NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, at the PR head da18cb8. v_dot4c_i32_i8_reads_old_destination_and_wraps, vop3p_integer_dots_clamp_or_wrap_the_full_sum and vop3p_integer_dot2_selects_each_source_half: 3 passed.
It is based on ffe310e and GitHub shows conflicts with main 70564ae, so this is the head as it stands, not a merge.
AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 22:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1694#issuecomment-7146752326) NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, at the PR head `da18cb8`. `v_dot4c_i32_i8_reads_old_destination_and_wraps`, `vop3p_integer_dots_clamp_or_wrap_the_full_sum` and `vop3p_integer_dot2_selects_each_source_half`: 3 passed. It is based on `ffe310e` and GitHub shows conflicts with `main` `70564ae`, so this is the head as it stands, not a merge. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠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 #1292. The six integer dot products of #1292 in one helper. Its v_dot4_i32_i8/v_dot4c_i32_i8 arms ignore op_sel, which main's (added today for the upscaler's shaders, lower.rs:5371-5428) handle; the other four are not 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:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1694#issuecomment-7149517150) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1292. The six integer dot products of #1292 in one helper. Its v_dot4_i32_i8/v_dot4c_i32_i8 arms ignore op_sel, which main's (added today for the upscaler's shaders, lower.rs:5371-5428) handle; the other four are not 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.
Author
Owner

@⁠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/lower.rs, crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1694#issuecomment-7149707698) <!-- victory-triage v1 head=da18cb8bab09320d4fc9555ffec86de4cfcda30f verdict=needs-rebase at=2026-11-25T01:34:39Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1694
No description provided.