Skip to content

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

Closed
geiyiliyabumo wants to merge 1 commit into
Marvisak:mainfrom
geiyiliyabumo:fix/shader-dot-products
Closed

geiyiliyabumo wants to merge 1 commit into
Marvisak:mainfrom
geiyiliyabumo:fix/shader-dot-products

Conversation

@geiyiliyabumo

@geiyiliyabumo geiyiliyabumo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 Shaders: lower v_dot2_f32_f16 and v_dot2c_f32_f16 #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.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib dot — all 5 new dot-product tests (v_dot2c_f32_f16_reads_old_destination, v_dot4c_i32_i8_reads_old_destination_and_wraps, v_dot2_f32_f16_applies_packed_modifiers_and_clamp, vop3p_integer_dots_clamp_or_wrap_the_full_sum, vop3p_integer_dot2_selects_each_source_half) passed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean 32-bit-only lowering of RDNA2 VOP2/VOP3P dot-product instructions without INT64, thoroughly verified on hardware and WARP. Looks good.

AI-assisted (Gemini 4 Neon).

@geiyiliyabumo
geiyiliyabumo force-pushed the fix/shader-dot-products branch from 26551e9 to da18cb8 Compare November 24, 2026 20:58
@geiyiliyabumo geiyiliyabumo changed the title shader: lower RDNA2 VOP2/VOP3P dot-product instructions without INT64 shader: lower 6 RDNA2 integer dot-product instructions without INT64 Nov 24, 2026
@adamdotpy

Copy link
Copy Markdown

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 Shaders: lower v_dot2_{i32_i16,u32_u16}, v_dot4_u32_u8, v_dot8_u32_u4, and saturating dot4 clamp #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.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.

Six RDNA2 integer dot-product instructions lowered without INT64 (vop2_dot/vop3p_dot const encoders, dot_int helper); tests pin old-destination reads and wraparound per backend.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown

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.

@Marvisak

Copy link
Copy Markdown
Owner

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 Marvisak closed this Nov 25, 2026

Copy link
Copy Markdown
Owner

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

Airamek added a commit to Airamek/VIctory that referenced this pull request Nov 25, 2026
Upstream model preferred throughout; our additive diagnostics kept: Marvisak#1750 250ms wait slices + stall reporting, copy/timing stats, texture-flow made/freed, stencil-view log, costs wiring, FrameWindow meter, lazy host-copy semantics via upstream made_copy, Marvisak#1267/Marvisak#1824/Marvisak#1694/Marvisak#1699 kept (Parts, opcode key, dot_int, 16-bit).

Port adaptations where our async model differs: withholding wired at completion (note_submission + expansion + memory_withheld), per-range settle in copy_page_mappings instead of drain-everything, sync-model drain() in async-sensitive GPU tests.

Dropped as superseded: manual settle around texture refresh (upstream per-thread Scratch + kept-alive per-submission uploads), Touches.staging, per-list timing grouping (upstream cuts).
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.

6 participants