shader: lower remaining packed dot products and clamped integer forms #2202

Open
github-bot wants to merge 2 commits from github-bot/gh-2202 into main AGit
Owner

@⁠UnkwnDev on GitHub · 2026-11-25 07:44 UTC · original
UnkwnDev:arc-packed-dot-products → main · +655 −56 · 3 files · 2 commits · open

Split out from #740 per triage feedback against current main (940d32f).

main already lowers v_dot4_i32_i8 (with opsel/opsel_hi) and unclamped v_dot4c_i32_i8 to DXIL dot4AddPacked.i32. This PR adds the remaining dot-product lowering and saturation forms:

  • v_dot4_u32_u8: lowers through the same opsel/opsel_hi half-selection helper to dot4AddPacked.i32 (DXIL opcode 164, Dot4AddU8Packed), with overflow-safe select(sum < acc, u32::MAX, sum) when v.clamp is set.
  • v.clamp saturation on v_dot4_i32_i8 and v_dot4c_i32_i8: emits dot4AddPacked.i32(0, a, b) (bounded within [-65024, +65536]) and saturates dot + acc in 64-bit arithmetic before truncating to i32.
  • v_dot2_f32_f16 and v_dot2c_f32_f16: converts operands via legacyF16ToF32 (handling both VOP3P opsel/opsel_hi + neg_hi and VOP2 [15:0]/[31:16] slicing) and chains fmad (tertiary.f32) matching RDNA2 rounding, using write_f for v.clamp / v.omod.
  • v_dot2_i32_i16 and v_dot2_u32_u16: extracts halves via packed_src with 64-bit clamping when v.clamp is set.
  • v_dot8_u32_u4: unpacks and accumulates 8 nibble products with wrapping saturation when v.clamp is set.
  • Adds end-to-end execution test emit::valu_tests::packed_dot_products_and_clamps_execute_cleanly in crates/victory-shader/src/emit/valu_tests.rs.

Testing

  • Hardware: Intel Arc A770 + WARP (Windows 11, DXC 1.9.2602.17)
  • cargo test -p victory-shader --locked packed_dot_products_and_clamps_execute_cleanly -- --test-threads=1: 1 passed, 0 failed.
  • cargo test -p victory-shader --locked -- --test-threads=1: 244 passed, 4 failed, 3 ignored. All 4 failures are pre-existing baseline failures on this adapter (stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware, valu_tests::fspx_programs_run_with_the_hardwares_dot_products which also fails identically on main 940d32f, and valu_tests::image_atomics_of_64_bits).
  • cargo clippy -p victory-shader --all-targets --locked and --all-features: clean on all modified code (1 pre-existing needless_range_loop warning at lower.rs:1009).
  • cargo test -p xtask --locked: 6 passed, 0 failed (repository_passes_policy).

AI use

  • Antigravity (Gemini 4 Hydrogen) assisted in porting the missing dot-product lowering and saturation forms onto main and verifying hardware/WARP execution tests.

Closes part of #740.

**@⁠UnkwnDev** on GitHub · 2026-11-25 07:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2202) `UnkwnDev:arc-packed-dot-products` → `main` · +655 −56 · 3 files · 2 commits · open Split out from #740 per triage feedback against current `main` (`940d32f`). `main` already lowers `v_dot4_i32_i8` (with `opsel`/`opsel_hi`) and unclamped `v_dot4c_i32_i8` to DXIL `dot4AddPacked.i32`. This PR adds the remaining dot-product lowering and saturation forms: - `v_dot4_u32_u8`: lowers through the same `opsel`/`opsel_hi` half-selection helper to `dot4AddPacked.i32` (DXIL opcode 164, `Dot4AddU8Packed`), with overflow-safe `select(sum < acc, u32::MAX, sum)` when `v.clamp` is set. - `v.clamp` saturation on `v_dot4_i32_i8` and `v_dot4c_i32_i8`: emits `dot4AddPacked.i32(0, a, b)` (bounded within `[-65024, +65536]`) and saturates `dot + acc` in 64-bit arithmetic before truncating to `i32`. - `v_dot2_f32_f16` and `v_dot2c_f32_f16`: converts operands via `legacyF16ToF32` (handling both VOP3P `opsel`/`opsel_hi` + `neg_hi` and VOP2 `[15:0]`/`[31:16]` slicing) and chains `fmad` (`tertiary.f32`) matching RDNA2 rounding, using `write_f` for `v.clamp` / `v.omod`. - `v_dot2_i32_i16` and `v_dot2_u32_u16`: extracts halves via `packed_src` with 64-bit clamping when `v.clamp` is set. - `v_dot8_u32_u4`: unpacks and accumulates 8 nibble products with wrapping saturation when `v.clamp` is set. - Adds end-to-end execution test `emit::valu_tests::packed_dot_products_and_clamps_execute_cleanly` in `crates/victory-shader/src/emit/valu_tests.rs`. ### Testing - Hardware: Intel Arc A770 + WARP (Windows 11, DXC 1.9.2602.17) - `cargo test -p victory-shader --locked packed_dot_products_and_clamps_execute_cleanly -- --test-threads=1`: 1 passed, 0 failed. - `cargo test -p victory-shader --locked -- --test-threads=1`: 244 passed, 4 failed, 3 ignored. All 4 failures are pre-existing baseline failures on this adapter (`stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `synthetic_tests::gathers_at_a_level_match_the_hardware`, `valu_tests::fspx_programs_run_with_the_hardwares_dot_products` which also fails identically on `main` `940d32f`, and `valu_tests::image_atomics_of_64_bits`). - `cargo clippy -p victory-shader --all-targets --locked` and `--all-features`: clean on all modified code (1 pre-existing `needless_range_loop` warning at `lower.rs:1009`). - `cargo test -p xtask --locked`: 6 passed, 0 failed (`repository_passes_policy`). ### AI use - Antigravity (Gemini 4 Hydrogen) assisted in porting the missing dot-product lowering and saturation forms onto `main` and verifying hardware/WARP execution tests. Closes part of #740.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:19 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 07:57 UTC · original

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head cecd8e77 into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 702 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 07:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2202#issuecomment-7156451511) Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head `cecd8e77` into `main` `940d32f` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean; the same with `--all-features`: clean. `cargo test --workspace --locked`: 702 passed, 0 failed, 10 ignored, two runs (`main` alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Author
Owner

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

Offline measurement on a retail dump

Result: no count change against main.

I merged head cecd8e77 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 10:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2202#issuecomment-7160397630) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head cecd8e77 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:28 UTC · original · edited 2026-11-25 22:20 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/bitcode.rs and emit/valu_tests.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: a source or a distinguishing test for fused rounding in v_dot2_f32_f16, splitting the Intel Arc workaround into its own PR with a repro, and a green CI.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2202#issuecomment-7163833426) · edited 2026-11-25 22:20 UTC <!-- victory-triage v1 head=cf43fda230c8b980f9b0b521a5bf2215c00430d2 verdict=needs-rebase at=2026-11-25T22:26:40Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/bitcode.rs` and `emit/valu_tests.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: a source or a distinguishing test for fused rounding in `v_dot2_f32_f16`, splitting the Intel Arc workaround into its own PR with a repro, and a green CI. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

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

Updated in cf43fda230c8 to address the review points and add edge-case assertions:

  1. RDNA2 ISA semantics and comments:

    • V_DOT2_F32_F16 / V_DOT2C_F32_F16: per the AMD RDNA2 Instruction Set Architecture manual (VOP3P / VOP2 dot-product definitions), each packed f16 input pair (including denormals) is converted to f32 without precision loss, then accumulated with two chained f32 fused multiply-adds (fma(a0, b0, c) followed by fma(a1, b1, inner)). In DXIL, legacyF16ToF32 decodes f16 including subnormals (whereas SM 6.4 f16 arithmetic may flush), fmad supplies the fused rounding, and write_f applies v.clamp (saturate to [0.0, 1.0]) and v.omod.
    • neg / neg_hi handling: VOP2 encoding (0x02) has no neg/abs modifiers; VOP3 v_dot2c_f32_f16 carries operand-wide v.neg applied to both halves of src0 or src1 (if !is_vop3p); VOP3P v_dot2_f32_f16 splits low/high halves across v.neg/v.neg_hi. Also fixed a double-negation bug on v_dot2_f32_f16 where fsrc already applied v.neg[2] before an unconditional extra negation in dot_product cancelled it out; explicit v.neg >> 2 negation is now restricted to v_dot2c_f32_f16.
    • Integer clamp saturation: RDNA2 clamp=1 saturates signed results to [i32::MIN, i32::MAX] via 64-bit bounds clamping (sat_64 / sat_i32_add) and unsigned results to u32::MAX (sat_u32_add, since max unsigned 4x8 / 8x4 dot products stay below 260,101 and overflow iff sum < acc).
  2. Constant dot4 expansion for Intel Arc IGC:

    • 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 arithmetic instead of emitting dx.op.dot4AddPacked with a constant operand, avoiding Intel Arc IGC's 16-bit constant broadcast miscompilation.
  3. Expanded packed_dot_products_and_clamps_execute_cleanly assertions:

    • Asserts i32::MIN / i32::MAX saturation on v_dot2_i32_i16, u32::MAX saturation on v_dot2_u32_u16 and v_dot8_u32_u4, negated accumulator and low-half operands on v_dot2_f32_f16 (2.0 and -4.0), f16 denormals (0x0001, 0x03FF), and constant dot4 multiplicands across v_dot4_i32_i8, v_dot4_u32_u8, and v_dot4c_i32_i8.

Verified after the final edit:

  • cargo test -p victory-shader --locked packed_dot_products_and_clamps_execute_cleanly -- --nocapture --test-threads=1: passed (Arc A770 hardware + WARP).
  • cargo test -p victory-shader --locked fspx_programs_run_with_the_hardwares_dot_products -- --nocapture --test-threads=1: passed (Arc A770 hardware + WARP).
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (exit 0).
  • cargo test -p xtask --locked: 6 passed, 0 failed.
**@⁠UnkwnDev** on GitHub · 2026-11-25 15:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2202#issuecomment-7167088043) · edited 2026-11-25 15:47 UTC Updated in `cf43fda230c8` to address the review points and add edge-case assertions: 1. **RDNA2 ISA semantics and comments**: - `V_DOT2_F32_F16` / `V_DOT2C_F32_F16`: per the AMD RDNA2 Instruction Set Architecture manual (VOP3P / VOP2 dot-product definitions), each packed f16 input pair (including denormals) is converted to f32 without precision loss, then accumulated with two chained f32 fused multiply-adds (`fma(a0, b0, c)` followed by `fma(a1, b1, inner)`). In DXIL, `legacyF16ToF32` decodes f16 including subnormals (whereas SM 6.4 `f16` arithmetic may flush), `fmad` supplies the fused rounding, and `write_f` applies `v.clamp` (saturate to `[0.0, 1.0]`) and `v.omod`. - `neg` / `neg_hi` handling: VOP2 encoding (`0x02`) has no `neg`/`abs` modifiers; VOP3 `v_dot2c_f32_f16` carries operand-wide `v.neg` applied to both halves of `src0` or `src1` (`if !is_vop3p`); VOP3P `v_dot2_f32_f16` splits low/high halves across `v.neg`/`v.neg_hi`. Also fixed a double-negation bug on `v_dot2_f32_f16` where `fsrc` already applied `v.neg[2]` before an unconditional extra negation in `dot_product` cancelled it out; explicit `v.neg >> 2` negation is now restricted to `v_dot2c_f32_f16`. - Integer clamp saturation: RDNA2 `clamp=1` saturates signed results to `[i32::MIN, i32::MAX]` via 64-bit bounds clamping (`sat_64` / `sat_i32_add`) and unsigned results to `u32::MAX` (`sat_u32_add`, since max unsigned 4x8 / 8x4 dot products stay below 260,101 and overflow iff `sum < acc`). 2. **Constant dot4 expansion for Intel Arc IGC**: - 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 arithmetic instead of emitting `dx.op.dot4AddPacked` with a constant operand, avoiding Intel Arc IGC's 16-bit constant broadcast miscompilation. 3. **Expanded `packed_dot_products_and_clamps_execute_cleanly` assertions**: - Asserts `i32::MIN` / `i32::MAX` saturation on `v_dot2_i32_i16`, `u32::MAX` saturation on `v_dot2_u32_u16` and `v_dot8_u32_u4`, negated accumulator and low-half operands on `v_dot2_f32_f16` (`2.0` and `-4.0`), f16 denormals (`0x0001`, `0x03FF`), and constant dot4 multiplicands across `v_dot4_i32_i8`, `v_dot4_u32_u8`, and `v_dot4c_i32_i8`. Verified after the final edit: - `cargo test -p victory-shader --locked packed_dot_products_and_clamps_execute_cleanly -- --nocapture --test-threads=1`: passed (Arc A770 hardware + WARP). - `cargo test -p victory-shader --locked fspx_programs_run_with_the_hardwares_dot_products -- --nocapture --test-threads=1`: passed (Arc A770 hardware + WARP). - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed (exit 0). - `cargo test -p xtask --locked`: 6 passed, 0 failed.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/bitcode.rs
  • 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/2202/head:github-bot/gh-2202'
git switch 'github-bot/gh-2202'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2202'
git switch 'github-bot/gh-2202'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2202'
git switch 'github-bot/gh-2202'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2202'
git switch 'main'
git merge --squash 'github-bot/gh-2202'
git switch 'main'
git merge --ff-only 'github-bot/gh-2202'
git switch 'main'
git merge 'github-bot/gh-2202'
git push origin 'main'
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!2202
No description provided.