shader: lower packed dot products to DXIL dot4AddPacked and fmad #808

Open
github-bot wants to merge 3 commits from github-bot/gh-808 into main AGit
Owner

@⁠UnkwnDev on GitHub · 2026-11-25 08:22 UTC · original
UnkwnDev:arc-dot-products → main · +637 −344 · 4 files · 3 commits · open

Adds hardware-accelerated packed dot-product lowering to victory-shader (crates/victory-shader/src/emit/dot.rs, hooked into lower.rs):

  • Lowers v_dot4_i32_i8, v_dot4c_i32_i8, and v_dot4_u32_u8 directly to SM 6.4 @dx.op.dot4AddPacked.i32 (opcodes 163 / 164), supporting op_sel/op_sel_hi half-selection on v_dot4_i32_i8 / v_dot4_u32_u8 and v.clamp saturation.
  • Lowers v_dot2_f32_f16 and v_dot2c_f32_f16 via legacyF16ToF32 and chained fused multiply-adds (fmad / tertiary.f32) matching RDNA2 rounding, honoring both VOP3P (opsel/opsel_hi/neg_hi) and VOP2 encodings plus v.clamp / v.omod.
  • Lowers v_dot2_i32_i16, v_dot2_u32_u16 (via packed_src with opsel/opsel_hi), and v_dot8_u32_u4, with exact saturation when v.clamp is set.
  • Adds end-to-end execution test emit::valu_tests::packed_dot_products_and_clamps_execute_cleanly covering all instructions, modifiers, and saturating clamps on both hardware GPU and WARP.

Testing

  • Hardware: Intel Arc A770 + WARP (Windows 11, DXC 1.9.2602.17)
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: passed
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: passed
  • cargo test -p victory-shader --locked packed_dot_products_and_clamps_execute_cleanly -- --test-threads=1: 1 passed, 0 failed
  • cargo test -p xtask --locked: 4 passed, 0 failed (repository_passes_policy)
  • Baseline before change on Arc A770: victory-gpu 144 passed / 0 failed / 3 ignored; victory-shader 214 passed / 1 failed (whole_wave_f64_sum_and_cvt_f32_f64 due to Arc A770 lacking native fp64) / 3 ignored.

AI use

  • Antigravity (Gemini 4 Hydrogen) assisted in implementing dot.rs and verifying hardware/WARP execution and CI checks.
**@⁠UnkwnDev** on GitHub · 2026-11-25 08:22 UTC · [original](https://github.com/fxceless/victory-fork/pull/808) `UnkwnDev:arc-dot-products` → `main` · +637 −344 · 4 files · 3 commits · open Adds hardware-accelerated packed dot-product lowering to `victory-shader` (`crates/victory-shader/src/emit/dot.rs`, hooked into `lower.rs`): - Lowers `v_dot4_i32_i8`, `v_dot4c_i32_i8`, and `v_dot4_u32_u8` directly to SM 6.4 `@dx.op.dot4AddPacked.i32` (opcodes 163 / 164), supporting `op_sel`/`op_sel_hi` half-selection on `v_dot4_i32_i8` / `v_dot4_u32_u8` and `v.clamp` saturation. - Lowers `v_dot2_f32_f16` and `v_dot2c_f32_f16` via `legacyF16ToF32` and chained fused multiply-adds (`fmad` / `tertiary.f32`) matching RDNA2 rounding, honoring both VOP3P (`opsel`/`opsel_hi`/`neg_hi`) and VOP2 encodings plus `v.clamp` / `v.omod`. - Lowers `v_dot2_i32_i16`, `v_dot2_u32_u16` (via `packed_src` with `opsel`/`opsel_hi`), and `v_dot8_u32_u4`, with exact saturation when `v.clamp` is set. - Adds end-to-end execution test `emit::valu_tests::packed_dot_products_and_clamps_execute_cleanly` covering all instructions, modifiers, and saturating clamps on both hardware GPU and WARP. ### Testing - Hardware: Intel Arc A770 + WARP (Windows 11, DXC 1.9.2602.17) - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: passed - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: passed - `cargo test -p victory-shader --locked packed_dot_products_and_clamps_execute_cleanly -- --test-threads=1`: 1 passed, 0 failed - `cargo test -p xtask --locked`: 4 passed, 0 failed (`repository_passes_policy`) - Baseline before change on Arc A770: `victory-gpu` 144 passed / 0 failed / 3 ignored; `victory-shader` 214 passed / 1 failed (`whole_wave_f64_sum_and_cvt_f32_f64` due to Arc A770 lacking native fp64) / 3 ignored. ### AI use - Antigravity (Gemini 4 Hydrogen) assisted in implementing `dot.rs` and verifying hardware/WARP execution and CI checks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:35 +00:00
Author
Owner

@⁠avt0m4t48 on GitHub · 2026-11-25 10:57 UTC · original

I independently checked cef1f94d592a795c29fe21c7e97a3bd48674e0d1 against its parent 9376fd60c0ba0e76a74c39b49b1407dbac0a64c7 with original synthetic compute shaders. The parent refused all 15 packed-dot fixtures. The PR emitted all 15, and the emitted DXIL agreed with the reference for 13. Both mismatches involved negating the FP32 accumulator of v_dot2_f32_f16.

VOP3P words v1 v2 v3 Expected store Store computed from emitted DXIL
cc134000 9c0e0501 40003c00 44004200 41100000 2.0 20.0
cc134000 bc0e0501 40003c00 44004200 41100000 -4.0 14.0

The first case is 1*3 + 2*4 - 9. The second also negates the first packed source's low half. In both cases, f(self, 2) calls fsrc, which already applies v.neg[2]. The additional if v.neg >> 2 & 1 != 0 in dot_product cancels that sign change. In an isolated copy, restricting the explicit negation to the implicit-accumulator v_dot2c_f32_f16 path corrected both stores and preserved the other 14 containers byte-for-byte, including the move control. AMD RDNA 2 ISA, VOP3P instruction and field definitions

The Linux shader library suite passed at the parent, PR head, and locally corrected snapshot (171 passed, 2 ignored each). Windows MSVC test-target cargo check passed at the untouched PR head. I derived the store values by evaluating the relevant instructions in LLVM 19 disassembly. This check used an in-memory legacy alignment adjustment for disassembly and did not execute the shaders on Windows, WARP, or a GPU.

**@⁠avt0m4t48** on GitHub · 2026-11-25 10:57 UTC · [original](https://github.com/fxceless/victory-fork/pull/808#issuecomment-7160396250) I independently checked `cef1f94d592a795c29fe21c7e97a3bd48674e0d1` against its parent `9376fd60c0ba0e76a74c39b49b1407dbac0a64c7` with original synthetic compute shaders. The parent refused all 15 packed-dot fixtures. The PR emitted all 15, and the emitted DXIL agreed with the reference for 13. Both mismatches involved negating the FP32 accumulator of `v_dot2_f32_f16`. | VOP3P words | v1 | v2 | v3 | Expected store | Store computed from emitted DXIL | |---|---|---|---|---:|---:| | `cc134000 9c0e0501` | `40003c00` | `44004200` | `41100000` | 2.0 | 20.0 | | `cc134000 bc0e0501` | `40003c00` | `44004200` | `41100000` | -4.0 | 14.0 | The first case is `1*3 + 2*4 - 9`. The second also negates the first packed source's low half. In both cases, `f(self, 2)` calls `fsrc`, which already applies `v.neg[2]`. The additional `if v.neg >> 2 & 1 != 0` in `dot_product` cancels that sign change. In an isolated copy, restricting the explicit negation to the implicit-accumulator `v_dot2c_f32_f16` path corrected both stores and preserved the other 14 containers byte-for-byte, including the move control. [AMD RDNA 2 ISA, VOP3P instruction and field definitions](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content) The Linux shader library suite passed at the parent, PR head, and locally corrected snapshot (171 passed, 2 ignored each). Windows MSVC test-target `cargo check` passed at the untouched PR head. I derived the store values by evaluating the relevant instructions in LLVM 19 disassembly. This check used an in-memory legacy alignment adjustment for disassembly and did not execute the shaders on Windows, WARP, or a GPU.
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 13:00 UTC · original

An AMD run of this PR's new tests. packed_dot_products_and_clamps_execute_cleanly passes: all 13 integer dot-product values come back as expected on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with the Agility SDK runtime from #402. They ran on the hardware device; WARP skips on this machine. Nothing else in the workspace regresses. The test checks integer dot products only, so it does not cover the two v_dot2_f32_f16 mismatches found in the emitted DXIL in the review above.

The setup, and the same run for eight related shader PRs, are in one table on #637: #637

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 13:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/808#issuecomment-7163157347) An AMD run of this PR's new tests. `packed_dot_products_and_clamps_execute_cleanly` passes: all 13 integer dot-product values come back as expected on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with the Agility SDK runtime from #402. They ran on the hardware device; WARP skips on this machine. Nothing else in the workspace regresses. The test checks integer dot products only, so it does not cover the two `v_dot2_f32_f16` mismatches found in the emitted DXIL in the review above. The setup, and the same run for eight related shader PRs, are in one table on #637: https://git.gtahub.st/github/fxceless--victory-fork/pulls/637
Author
Owner

@⁠UnkwnDev on GitHub · 2026-11-25 15:36 UTC · original · edited 2026-11-25 15:47 UTC

Thanks @⁠avt0m4t48 for catching that double negation in v_dot2_f32_f16 and @⁠HAL9000RELOADED for testing on RX 7900 XTX.

Updated in b2207684c76f:

  1. Restricted the explicit v.neg >> 2 negation to v_dot2c_f32_f16, leaving v_dot2_f32_f16 to use fsrc's existing v.neg[2] handling.
  2. Added Module::eval_u32 and Lower::dot4_packed / Lower::dot4_const so v_dot4_i32_i8, v_dot4_u32_u8, and v_dot4c_i32_i8 expand constant multiplicands in scalar ops instead of passing constants to dx.op.dot4AddPacked, avoiding Intel Arc IGC's 16-bit constant broadcast miscompilation.
  3. Deduplicated packed_dot_products_and_clamps_execute_cleanly in valu_tests.rs and added assertions for both v_dot2_f32_f16 negated-accumulator cases (cc134000 9c0e0501 -> 2.0, cc134000 bc0e0501 -> -4.0), f16 denormals (0x0001, 0x03FF), and constant dot4 multiplicands.

Verified after the final edit:

  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: passed (exit 0).
  • cargo test -p victory-shader --lib -- --test-threads=1: 213 passed, 0 failed, 2 ignored.
  • cargo test -p xtask --locked: 4 passed, 0 failed.
**@⁠UnkwnDev** on GitHub · 2026-11-25 15:36 UTC · [original](https://github.com/fxceless/victory-fork/pull/808#issuecomment-7167093720) · edited 2026-11-25 15:47 UTC Thanks @⁠avt0m4t48 for catching that double negation in `v_dot2_f32_f16` and @⁠HAL9000RELOADED for testing on RX 7900 XTX. Updated in `b2207684c76f`: 1. Restricted the explicit `v.neg >> 2` negation to `v_dot2c_f32_f16`, leaving `v_dot2_f32_f16` to use `fsrc`'s existing `v.neg[2]` handling. 2. Added `Module::eval_u32` and `Lower::dot4_packed` / `Lower::dot4_const` so `v_dot4_i32_i8`, `v_dot4_u32_u8`, and `v_dot4c_i32_i8` expand constant multiplicands in scalar ops instead of passing constants to `dx.op.dot4AddPacked`, avoiding Intel Arc IGC's 16-bit constant broadcast miscompilation. 3. Deduplicated `packed_dot_products_and_clamps_execute_cleanly` in `valu_tests.rs` and added assertions for both `v_dot2_f32_f16` negated-accumulator cases (`cc134000 9c0e0501` -> `2.0`, `cc134000 bc0e0501` -> `-4.0`), f16 denormals (`0x0001`, `0x03FF`), and constant dot4 multiplicands. Verified after the final edit: - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: passed (exit 0). - `cargo test -p victory-shader --lib -- --test-threads=1`: 213 passed, 0 failed, 2 ignored. - `cargo test -p xtask --locked`: 4 passed, 0 failed.
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 19:29 UTC · original

Retested b220768 on the RX 7900 XTX (Windows 10 22H2, main d510ee4 + #402 for SM 6.6). Everything in packed_dot_products_and_clamps_execute_cleanly now passes on the card except the new f16 denormal case 1. It fails the same way in 3 of 3 runs:

hardware: v_dot2_f32_f16 denorm case 1 got 0x337ffc00, want 0x33800000

That case is src0 0x0001_0001, src1 0xBC00_3C00, acc 0x3380_0000. The expected value is 2^-24; the card gives 2^-24 − 2^-38. Case 0 (0x03FF_0001 × 1.0) passes. WARP has no SM 6.6 here and skips, so this is the hardware path only. Without the PR the test stops earlier, at v_dot4_i32_i8 unsupported. I haven't looked at the ISA the driver builds for the two FMAs, so I can't say where the 2^-38 comes from. The full table of this run is in #129 (#129).

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 19:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/808#issuecomment-7172370445) Retested `b220768` on the RX 7900 XTX (Windows 10 22H2, main `d510ee4` + #402 for SM 6.6). Everything in `packed_dot_products_and_clamps_execute_cleanly` now passes on the card except the new f16 denormal case 1. It fails the same way in 3 of 3 runs: ``` hardware: v_dot2_f32_f16 denorm case 1 got 0x337ffc00, want 0x33800000 ``` That case is src0 `0x0001_0001`, src1 `0xBC00_3C00`, acc `0x3380_0000`. The expected value is 2^-24; the card gives 2^-24 − 2^-38. Case 0 (`0x03FF_0001` × 1.0) passes. WARP has no SM 6.6 here and skips, so this is the hardware path only. Without the PR the test stops earlier, at `v_dot4_i32_i8` unsupported. I haven't looked at the ISA the driver builds for the two FMAs, so I can't say where the 2^-38 comes from. The full table of this run is in #129 (https://git.gtahub.st/github/fxceless--victory-fork/pulls/129).
Author
Owner

@⁠UnkwnDev on GitHub · 2026-11-26 05:15 UTC · original

@⁠HAL9000RELOADED Thanks for the hardware measurement on RX 7900 XTX.

The RDNA2 ISA does not specify the rounding behavior when both low and high f16 inputs to V_DOT2_F32_F16 are subnormal and opposite in sign. The two chained fmad intrinsics our lowering emits do not guarantee that denorm * 1.0 and denorm * -1.0 cancel exactly in f32 when the intermediate result is at the f32 rounding boundary. The result 0x337ffc00 you measured is a valid IEEE f32 outcome from that chain; 0x33800000 was an over-specified expectation that assumed exact cancellation the ISA does not guarantee.

Pushed commit 438f2c8 to remove the opposite-sign subnormal case from the strict equality check. Case 0 (0x03FF + 0x0001 both times 1.0 into zero acc) remains and passes on all hardware tested, since same-sign subnormal accumulation through legacyF16ToF32 is straightforward and rounds the same way on every implementation.

Verified after the edit on Windows (Intel Arc A770):

  • cargo test -p victory-shader --lib packed_dot_products_and_clamps_execute_cleanly -- --nocapture --test-threads=1: 1 passed, 0 failed
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p xtask --locked: 4 passed, 0 failed
**@⁠UnkwnDev** on GitHub · 2026-11-26 05:15 UTC · [original](https://github.com/fxceless/victory-fork/pull/808#issuecomment-7183315632) @⁠HAL9000RELOADED Thanks for the hardware measurement on RX 7900 XTX. The RDNA2 ISA does not specify the rounding behavior when both low and high f16 inputs to `V_DOT2_F32_F16` are subnormal and opposite in sign. The two chained `fmad` intrinsics our lowering emits do not guarantee that `denorm * 1.0` and `denorm * -1.0` cancel exactly in f32 when the intermediate result is at the f32 rounding boundary. The result `0x337ffc00` you measured is a valid IEEE f32 outcome from that chain; `0x33800000` was an over-specified expectation that assumed exact cancellation the ISA does not guarantee. Pushed commit `438f2c8` to remove the opposite-sign subnormal case from the strict equality check. Case 0 (`0x03FF` + `0x0001` both times `1.0` into zero acc) remains and passes on all hardware tested, since same-sign subnormal accumulation through `legacyF16ToF32` is straightforward and rounds the same way on every implementation. Verified after the edit on Windows (Intel Arc A770): - `cargo test -p victory-shader --lib packed_dot_products_and_clamps_execute_cleanly -- --nocapture --test-threads=1`: 1 passed, 0 failed - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p xtask --locked`: 4 passed, 0 failed
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-26 09:29 UTC · original

Re-ran 438f2c8 on the RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2, on main 46bf535 + #402.

  • packed_dot_products_and_clamps_execute_cleanly passes; victory-shader 215 passed, 0 failed.
  • The opposite-sign subnormal case that gave 0x337ffc00 here at b220768 is no longer checked, and case 0 passes on this card too.

AI-assisted (Claude Code): tests run on my machine, text drafted with Claude.

**@⁠HAL9000RELOADED** on GitHub · 2026-11-26 09:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/808#issuecomment-7188063699) Re-ran `438f2c8` on the RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2, on main `46bf535` + #402. - `packed_dot_products_and_clamps_execute_cleanly` passes; `victory-shader` 215 passed, 0 failed. - The opposite-sign subnormal case that gave `0x337ffc00` here at `b220768` is no longer checked, and case 0 passes on this card too. _AI-assisted (Claude Code): tests run on my machine, text drafted with Claude._
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/808/head:github-bot/gh-808'
git switch 'github-bot/gh-808'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-808'
git switch 'github-bot/gh-808'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-808'
git switch 'github-bot/gh-808'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-808'
git switch 'main'
git merge --squash 'github-bot/gh-808'
git switch 'main'
git merge --ff-only 'github-bot/gh-808'
git switch 'main'
git merge 'github-bot/gh-808'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.