Shaders: decode and lower v_dot8_i32_i4 #2766

Open
lcg007xd-c wants to merge 1 commit from upstream-pr/2768 into main
lcg007xd-c commented 2026-11-25 20:07:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-11-25T20:07:22Z.


What this fixes

VOP3P opcode 0x18, v_dot8_i32_i4, is missing from gfx10/opcodes.rs. Its neighbours 0x16 v_dot4_i32_i8, 0x17 v_dot4_u32_u8 and 0x19 v_dot8_u32_u4 are all there, so any program using it fails at decode. AMD's RDNA2 ISA guide lists it, and so does LLVM's llvm-mc --disassemble -mcpu=gfx1030, which I used to cross-check the table. None of the open dot-product PRs (#157, #1292, #2092, #2202, #2408) add this entry.

The change

  • Opcode table: adds (0x018, "v_dot8_i32_i4").
  • Lowering: joins the existing v_dot4_i32_i8 arm, so op_sel/op_sel_hi select the halves exactly as they do there, and clamp or neg_hi stays refused. The result is eight signed nibble products added to the accumulator with 32-bit wrapping (RDNA2 ISA: D.i32 = Σ S0.i4[k] · S1.i4[k] + S2.i32). Each nibble is shifted to the top of the dword and shifted back arithmetically. The code is plain 32-bit shl/ashr/mul/add, with no 64-bit integers and no new DXIL op.

Tests

  • emit::lower::tests::signed_nibble_dot_product_decodes_and_lowers (runs on every host): the encoding decodes to v_dot8_i32_i4, a program that stores the result translates, and the clamped form is refused. It fails without the table entry.
  • emit::semantics_tests::nibble_dot_products_match_the_hardware (Windows, as with the other probes): runs the instruction on the hardware adapter and WARP and compares it with a CPU model. The edge inputs are all -8, all 7, all -1, alternating nibbles, and accumulators at i32::MAX/MIN. A second test, nibble_dot_model_follows_the_isa, pins down the model itself with values worked out by hand.

Run here (Linux, Rust 1.98.1):

  • cargo test -p victory-shader --lib: 159 passed, 0 failed, 2 ignored. Building the shader tests on Linux needs #2766; the commit itself is independent of it.
  • cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.

Not run here: the hardware probe, since I have no Windows machine with a GPU. CI's Windows job will run it on WARP.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5498340080 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2768). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T20:07:22Z. --- ## What this fixes VOP3P opcode **0x18, `v_dot8_i32_i4`**, is missing from `gfx10/opcodes.rs`. Its neighbours 0x16 `v_dot4_i32_i8`, 0x17 `v_dot4_u32_u8` and 0x19 `v_dot8_u32_u4` are all there, so any program using it fails at decode. AMD's RDNA2 ISA guide lists it, and so does LLVM's `llvm-mc --disassemble -mcpu=gfx1030`, which I used to cross-check the table. None of the open dot-product PRs (#157, #1292, #2092, #2202, #2408) add this entry. ## The change - **Opcode table:** adds `(0x018, "v_dot8_i32_i4")`. - **Lowering:** joins the existing `v_dot4_i32_i8` arm, so `op_sel`/`op_sel_hi` select the halves exactly as they do there, and clamp or `neg_hi` stays refused. The result is eight signed nibble products added to the accumulator with 32-bit wrapping (RDNA2 ISA: `D.i32 = Σ S0.i4[k] · S1.i4[k] + S2.i32`). Each nibble is shifted to the top of the dword and shifted back arithmetically. The code is plain 32-bit `shl`/`ashr`/`mul`/`add`, with no 64-bit integers and no new DXIL op. ## Tests - **`emit::lower::tests::signed_nibble_dot_product_decodes_and_lowers`** (runs on every host): the encoding decodes to `v_dot8_i32_i4`, a program that stores the result translates, and the clamped form is refused. It fails without the table entry. - **`emit::semantics_tests::nibble_dot_products_match_the_hardware`** (Windows, as with the other probes): runs the instruction on the hardware adapter and WARP and compares it with a CPU model. The edge inputs are all `-8`, all `7`, all `-1`, alternating nibbles, and accumulators at `i32::MAX`/`MIN`. A second test, `nibble_dot_model_follows_the_isa`, pins down the model itself with values worked out by hand. **Run here** (Linux, Rust 1.98.1): - `cargo test -p victory-shader --lib`: 159 passed, 0 failed, 2 ignored. Building the shader tests on Linux needs #2766; the commit itself is independent of it. - `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings`: clean. **Not run here:** the hardware probe, since I have no Windows machine with a GPU. CI's Windows job will run it on WARP. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
cloph-dsp commented 2026-11-25 21:03:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T20:29:36Z.


Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no clippy/rustup.

  • \cargo test --locked -p victory-shader --lib signed_nibble_dot_product_decodes_and_lowers --quiet\ -> 1 passed, 0 failed.
  • \cargo test --locked -p victory-shader --lib nibble_dot --quiet\ -> 3 passed, 0 failed (model, hardware and WARP semantics paths).
  • \cargo test --locked -p victory-shader --lib emit::lower::tests --quiet\ -> 28 passed, 0 failed.
  • \git diff --check origin/main..HEAD\ clean; negative control: all three new test names are absent from origin/main.
  • Hardware path exercised on RTX 5060 Laptop (driver 621.24) and WARP; no extracted content used.
  • Full victory-shader lib was not run: \emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index\ crashes on unmodified base 13f91ca on this machine (pre-existing).

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173750867 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2768#issuecomment-7173750867). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T20:29:36Z. --- Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no clippy/rustup. - \cargo test --locked -p victory-shader --lib signed_nibble_dot_product_decodes_and_lowers --quiet\ -> 1 passed, 0 failed. - \cargo test --locked -p victory-shader --lib nibble_dot --quiet\ -> 3 passed, 0 failed (model, hardware and WARP semantics paths). - \cargo test --locked -p victory-shader --lib emit::lower::tests --quiet\ -> 28 passed, 0 failed. - \git diff --check origin/main..HEAD\ clean; negative control: all three new test names are absent from origin/main. - Hardware path exercised on RTX 5060 Laptop (driver 621.24) and WARP; no extracted content used. - Full victory-shader lib was not run: \emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index\ crashes on unmodified base 13f91ca on this machine (pre-existing). AI-assisted (Hy4 flash).
fuzeofficlal commented 2026-11-25 21:03:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:38:08Z.


Reviewed and verified 5bab6d4f on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll) against main (13f91ca).

Code review

  • VOP3P 0x018 decoding, op_sel/op_sel_hi 16-bit half selection, per-nibble (x << (28 - 4 * n)) >> 28 signed [-8, +7] sign-extension via Shl + AShr, wrapping Add (no nsw/nuw), and v.clamp rejection all check out cleanly.
  • Minor consistency note: lower.rs:5941 checks v.clamp || v.neg_hi != 0 (matching existing v_dot4_i32_i8), leaving v.neg != 0 (fields.rs:590, w1 >> 29) unchecked; checking v.neg != 0 too would strictly reject all negation modifier bits on VOP3P.

Verification (Windows 11, RTX 5090 + WARP + dxil.dll)

  • cargo test --locked -p victory-shader --lib --features host semantics_tests::: 35 passed, 0 failed, 1 ignored (all 3 nibble_dot tests pass on both RTX 5090 and WARP).
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 184 files ok.
  • Clean git merge-tree vs 13f91ca, #2771, #2774, and #2766.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173961231 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2768#issuecomment-7173961231). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:38:08Z. --- Reviewed and verified `5bab6d4f` on Windows 11 (RTX 5090 + WARP + Windows SDK `10.0.26100.0` `dxil.dll`) against `main` (`13f91ca`). ### Code review - `VOP3P` `0x018` decoding, `op_sel`/`op_sel_hi` 16-bit half selection, per-nibble `(x << (28 - 4 * n)) >> 28` signed `[-8, +7]` sign-extension via `Shl` + `AShr`, wrapping `Add` (no `nsw`/`nuw`), and `v.clamp` rejection all check out cleanly. - Minor consistency note: `lower.rs:5941` checks `v.clamp || v.neg_hi != 0` (matching existing `v_dot4_i32_i8`), leaving `v.neg != 0` (`fields.rs:590`, `w1 >> 29`) unchecked; checking `v.neg != 0` too would strictly reject all negation modifier bits on `VOP3P`. ### Verification (Windows 11, RTX 5090 + WARP + `dxil.dll`) - `cargo test --locked -p victory-shader --lib --features host semantics_tests::`: **35 passed, 0 failed, 1 ignored** (all 3 `nibble_dot` tests pass on both RTX 5090 and WARP). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **184 files ok**. - Clean `git merge-tree` vs `13f91ca`, `#2771`, `#2774`, and `#2766`.
Marvisak commented 2026-11-26 00:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:21:32Z.


Automated triage for the maintainers.

This adds VOP3P opcode 0x18 v_dot8_i32_i4 to crates/victory-shader/src/gfx10/opcodes.rs (its neighbours 0x16, 0x17 and 0x19 are already there) and lowers it in crates/victory-shader/src/emit/lower.rs (valu_op) by sharing the v_dot4_i32_i8 arm. That keeps the same op_sel/op_sel_hi half selection and the same refusal of clamp/neg_hi, and computes eight sign-extended nibble products plus the accumulator with 32-bit wrapping, as the public RDNA2 ISA guide defines it. I checked the shl/ashr sign extension, that the products cannot overflow, and that the CPU model in semantics_tests.rs matches the hand-worked cases. The decode/lower test runs on every host and the semantics probe runs on Windows. CI (check) passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177451408 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2768#issuecomment-7177451408). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:21:32Z. --- <!-- victory-triage v1 head=52a9929e8072753c7fdf0dc8aed194b545a65719 verdict=merge-candidate at=2026-11-25T23:21:25Z --> Automated triage for the maintainers. This adds VOP3P opcode 0x18 `v_dot8_i32_i4` to `crates/victory-shader/src/gfx10/opcodes.rs` (its neighbours 0x16, 0x17 and 0x19 are already there) and lowers it in `crates/victory-shader/src/emit/lower.rs` (`valu_op`) by sharing the `v_dot4_i32_i8` arm. That keeps the same op_sel/op_sel_hi half selection and the same refusal of clamp/neg_hi, and computes eight sign-extended nibble products plus the accumulator with 32-bit wrapping, as the public RDNA2 ISA guide defines it. I checked the shl/ashr sign extension, that the products cannot overflow, and that the CPU model in `semantics_tests.rs` matches the hand-worked cases. The decode/lower test runs on every host and the semantics probe runs on Windows. CI (`check`) passes. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 03:47:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:47:01Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib nibble_dot: 3 passed, 0 failed (v_dot8_i32_i4: 245 inputs, 0 mismatches on both RTX 5090 hardware and WARP, 0 hardware/WARP differences).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068280529 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2768#pullrequestreview-6068280529). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T03:47:01Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, `dxil.dll` validator active): - `cargo test -p victory-shader --lib nibble_dot`: **3 passed, 0 failed** (`v_dot8_i32_i4`: 245 inputs, 0 mismatches on both RTX 5090 hardware and WARP, 0 hardware/WARP differences). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-27 00:53:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:53:23Z.

Review: APPROVED


LGTM! Verified v_dot8_i32_i4 (VOP3P 0x018) semantics and lowering:

  • Signed 4-bit nibble extraction (-8..=7 via shl (28 - 4*n) + ashr 28) and wrapping 32-bit accumulation match RDNA2 hardware across all 245 tested triples on RTX 5090, WARP, and native RDNA2 (nibble_dot_products_match_the_hardware, nibble_dot_model_follows_the_isa).
  • Sharing the op_sel / op_sel_hi 16-bit half-selection logic with v_dot4_i32_i8 matches RDNA2 v_dot8_i32_i4 behavior, while unsupported clamp and neg_hi/neg_lo modifiers are rejected cleanly (signed_nibble_dot_product_decodes_and_lowers).
  • rustfmt --edition 2024 --check on the modified lines, cargo xtask policy (191 files ok), and cargo clippy (-D warnings) all pass cleanly.
<!-- greyfinch-sync:Marvisak/VIctory:review:6082090880 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2768#pullrequestreview-6082090880). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T00:53:23Z. **Review:** APPROVED --- LGTM! Verified `v_dot8_i32_i4` (`VOP3P` `0x018`) semantics and lowering: - Signed 4-bit nibble extraction (`-8..=7` via `shl (28 - 4*n)` + `ashr 28`) and wrapping 32-bit accumulation match RDNA2 hardware across all 245 tested triples on RTX 5090, WARP, and native RDNA2 (`nibble_dot_products_match_the_hardware`, `nibble_dot_model_follows_the_isa`). - Sharing the `op_sel` / `op_sel_hi` 16-bit half-selection logic with `v_dot4_i32_i8` matches RDNA2 `v_dot8_i32_i4` behavior, while unsupported `clamp` and `neg_hi`/`neg_lo` modifiers are rejected cleanly (`signed_nibble_dot_product_decodes_and_lowers`). - `rustfmt --edition 2024 --check` on the modified lines, `cargo xtask policy` (`191 files ok`), and `cargo clippy` (`-D warnings`) all pass cleanly.
lcg007xd-c commented 2026-12-01 13:32:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-12-01T13:32:02Z.


@greptileai Please review the latest changes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7312775302 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2768#issuecomment-7312775302). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-12-01T13:32:02Z. --- @greptileai Please review the latest changes. <!-- nexus-review-request:3f8660ba4930 -->
lcg007xd-c commented 2026-12-01 14:24:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-12-01T14:24:06Z.


@Marvisak @Dukestar69 Please review this contribution when you have time.

@greptileai Please review the current changes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7314190482 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2768#issuecomment-7314190482). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-12-01T14:24:06Z. --- @Marvisak @Dukestar69 Please review this contribution when you have time. @greptileai Please review the current changes. <!-- nexus-review-pass:20261201-conflicts -->
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/2768:upstream-pr/2768'
git switch 'upstream-pr/2768'

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