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

Open
UnkwnDev wants to merge 2 commits from upstream-pr/2202 into main
UnkwnDev commented 2026-11-25 07:44:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by UnkwnDev on 2026-11-25T07:44:43Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6599710728 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2202). Originally posted by [UnkwnDev](https://github.com/UnkwnDev) on 2026-11-25T07:44:43Z. --- 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.
MamaLeVrai commented 2026-11-25 08:06:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-25T07:57:58Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156451511 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2202#issuecomment-7156451511). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T07:57:58Z. --- 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.
catminou4 commented 2026-11-25 09:05:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:10:11Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. Remaining packed dot products and clamped integers lowered — packed-op lowering completeness.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053923477 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2202#pullrequestreview-6053923477). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:10:11Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed / 2 ignored. Remaining packed dot products and clamped integers lowered — packed-op lowering completeness.
DenRakEiw commented 2026-11-25 10:07:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T09:23:40Z.

Review: APPROVED


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

  • cargo test -p victory-shader --lib packed_dot_products_and_clamps_execute_cleanly — passed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean lowering of remaining packed dot products and clamped integer forms, verified end-to-end on hardware and WARP. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054874067 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2202#pullrequestreview-6054874067). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T09:23:40Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with `dxil.dll` validator): - `cargo test -p victory-shader --lib packed_dot_products_and_clamps_execute_cleanly` — passed on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean lowering of remaining packed dot products and clamped integer forms, verified end-to-end on hardware and WARP. Looks good. AI-assisted (Gemini 4 Neon).
sinan-cmyk commented 2026-11-25 11:05:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T10:57:28Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160397630 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2202#issuecomment-7160397630). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T10:57:28Z. --- ### 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).
Marvisak commented 2026-11-25 14:07:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:28:39Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163833426 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2202#issuecomment-7163833426). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:28:39Z. --- <!-- 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)_
UnkwnDev commented 2026-11-25 16:09:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by UnkwnDev on 2026-11-25T15:35:52Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7167088043 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2202#issuecomment-7167088043). Originally posted by [UnkwnDev](https://github.com/UnkwnDev) on 2026-11-25T15:35:52Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2202:upstream-pr/2202'
git switch 'upstream-pr/2202'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2202'
git switch 'upstream-pr/2202'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2202'
git switch 'upstream-pr/2202'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2202'
git switch 'main'
git merge --squash 'upstream-pr/2202'
git switch 'main'
git merge --ff-only 'upstream-pr/2202'
git switch 'main'
git merge 'upstream-pr/2202'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2200
No description provided.