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

Open
UnkwnDev wants to merge 2 commits from upstream-pr/75 into main
UnkwnDev commented 2026-11-25 09:08:55 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by UnkwnDev on 2026-11-25T08:25:12Z.


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. Improves SM 6.4 hardware DP4a utilization on NVIDIA RTX and Intel Arc GPUs.
  • 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)

AI use

  • Antigravity (Gemini 4 Hydrogen) assisted in implementing dot.rs and verifying hardware/WARP execution and CI checks.
<!-- greyfinch-sync:Zettrox/ztrx:issue:6600310904 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/75). Originally posted by [UnkwnDev](https://github.com/UnkwnDev) on 2026-11-25T08:25:12Z. --- 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. Improves SM 6.4 hardware DP4a utilization on NVIDIA RTX and Intel Arc GPUs. - 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`) ### AI use - Antigravity (Gemini 4 Hydrogen) assisted in implementing `dot.rs` and verifying hardware/WARP execution and CI checks.
IIKurumiII commented 2026-11-25 09:08:58 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by IIKurumiII on 2026-11-25T09:04:01Z.


Tested commit 2c6ba52 on an NVIDIA RTX 3060, driver 621.24, Windows 11 Home build 26300.9711. packed_dot_products_and_clamps_execute_cleanly passed on both the GPU and WARP, with no device skips. This was a shader correctness test only. I didn’t measure in-game performance.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7157828810 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/75#issuecomment-7157828810). Originally posted by [IIKurumiII](https://github.com/IIKurumiII) on 2026-11-25T09:04:01Z. --- Tested commit `2c6ba52` on an NVIDIA RTX 3060, driver `621.24`, Windows 11 Home build `26300.9711`. `packed_dot_products_and_clamps_execute_cleanly` passed on both the GPU and WARP, with no device skips. This was a shader correctness test only. I didn’t measure in-game performance.
Aniseto commented 2026-11-25 16:13:08 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Aniseto on 2026-11-25T15:29:02Z.


Ran the packed dot-product test at 2c6ba52 (clean PR head on main 90b529f):

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB), driver 32.0.16.2124
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXIL validator 1.9.2609.5 (VICTORY_DXIL), debug build

Results

  • cargo test --locked -p victory-shader --lib packed_dot_products_and_clamps_execute_cleanly -- --nocapture: 1 passed, 0 failed, 0 ignored, 212 filtered out (exit 0), with no device skip under --nocapture
  • cargo test --locked -p victory-shader --lib -- --test-threads=1: 211 passed, 0 failed, 2 ignored (exit 0)

What this adds
The existing report in the thread is an RTX 3060 (Ampere). This adds a Blackwell wave32 part on driver 32.0.16.2124 with DXIL validator 1.9.2609.5; the packed-dot test, which executes on the host GPU and WARP, passes here.

Not tested
The title's shader pack, live pipeline creation, retail runs, a separate Intel Arc control lane, the console compiler's DXC, release profile, AMD GPUs.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7166913165 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/75#issuecomment-7166913165). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-25T15:29:02Z. --- Ran the packed dot-product test at `2c6ba52` (clean PR head on `main` `90b529f`): **System** - GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB), driver 32.0.16.2124 - CPU: Intel Core i5-12400F, 64 GB RAM - OS: Windows 11 Pro build 26200 x64 - Toolchain: Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXIL validator 1.9.2609.5 (`VICTORY_DXIL`), debug build **Results** - `cargo test --locked -p victory-shader --lib packed_dot_products_and_clamps_execute_cleanly -- --nocapture`: 1 passed, 0 failed, 0 ignored, 212 filtered out (exit 0), with no device skip under `--nocapture` - `cargo test --locked -p victory-shader --lib -- --test-threads=1`: 211 passed, 0 failed, 2 ignored (exit 0) **What this adds** The existing report in the thread is an RTX 3060 (Ampere). This adds a Blackwell wave32 part on driver 32.0.16.2124 with DXIL validator 1.9.2609.5; the packed-dot test, which executes on the host GPU and WARP, passes here. **Not tested** The title's shader pack, live pipeline creation, retail runs, a separate Intel Arc control lane, the console compiler's DXC, release profile, AMD GPUs. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
UnkwnDev commented 2026-11-25 16:13:09 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by UnkwnDev on 2026-11-25T15:40:07Z.


Updated in db7f615 with three fixes from downstream review and Intel Arc A770 hardware testing (thanks @IIKurumiII and @Aniseto for testing on RTX 3060 / 5070 Ti):

  1. Fixed a double-negation bug on v_dot2_f32_f16 where fsrc already negated src2 when v.neg[2] was set, restricting explicit v.neg >> 2 negation to v_dot2c_f32_f16.
  2. Added Module::eval_u32 and Lower::dot4_packed / Lower::dot4_const so constant multiplicands in v_dot4_i32_i8, v_dot4_u32_u8, and v_dot4c_i32_i8 expand in scalar arithmetic rather than 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 negated v_dot2_f32_f16 accumulators (2.0, -4.0), f16 denormals (0x0001, 0x03FF), and constant dot4 multiplicands.

Verified on Intel Arc A770 + WARP after the final edit:

  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: exit 0
  • cargo test -p victory-shader --lib -- --test-threads=1: 211 passed, 0 failed, 2 ignored
  • cargo test -p xtask --locked: 4 passed, 0 failed
<!-- greyfinch-sync:Zettrox/ztrx:comment:7167197102 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/75#issuecomment-7167197102). Originally posted by [UnkwnDev](https://github.com/UnkwnDev) on 2026-11-25T15:40:07Z. --- Updated in `db7f615` with three fixes from downstream review and Intel Arc A770 hardware testing (thanks @IIKurumiII and @Aniseto for testing on RTX 3060 / 5070 Ti): 1. Fixed a double-negation bug on `v_dot2_f32_f16` where `fsrc` already negated `src2` when `v.neg[2]` was set, restricting explicit `v.neg >> 2` negation to `v_dot2c_f32_f16`. 2. Added `Module::eval_u32` and `Lower::dot4_packed` / `Lower::dot4_const` so constant multiplicands in `v_dot4_i32_i8`, `v_dot4_u32_u8`, and `v_dot4c_i32_i8` expand in scalar arithmetic rather than 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 negated `v_dot2_f32_f16` accumulators (`2.0`, `-4.0`), f16 denormals (`0x0001`, `0x03FF`), and constant dot4 multiplicands. Verified on Intel Arc A770 + WARP after the final edit: - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: exit 0 - `cargo test -p victory-shader --lib -- --test-threads=1`: 211 passed, 0 failed, 2 ignored - `cargo test -p xtask --locked`: 4 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/75:upstream-pr/75'
git switch 'upstream-pr/75'

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/75'
git switch 'upstream-pr/75'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/75'
git switch 'upstream-pr/75'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/75'
git switch 'main'
git merge --squash 'upstream-pr/75'
git switch 'main'
git merge --ff-only 'upstream-pr/75'
git switch 'main'
git merge 'upstream-pr/75'
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
Zettrox/ztrx!75
No description provided.