Shaders: lower v_mul_hi_u32_u24 and v_mul_hi_i32_i24 #156

Manually merged
github merged 1 commit from gh-pr/156/head into gh-pr/156/base 2026-11-26 03:52:32 +00:00
Owner

@⁠Rareuncommon on GitHub · 2026-11-24 01:00 UTC · original
Rareuncommon:shaders/mul-hi-24 → main · +61 −0 · 1 files · 1 commits · merged 2026-11-25 00:18 UTC

Rebuilt on main ffe310e (344704e replaces 8142a94): the lowering is the same, the test helper now uses main's lower_with and root.

v_mul_hi_u32_u24 and v_mul_hi_i32_i24, which the emitter refuses by name, now translate. One file, crates/victory-shader/src/emit/lower.rs (61 added).

What is in it

  • The lowering (12 lines, next to v_mul_u32_u24 / v_mul_i32_i24): the high dword of the same 48-bit product. The low 24 bits of each operand are zero- or sign-extended with the shift pair the low-dword forms already use, then multiplied through the existing mul_hi.
  • A test helper, lowers_valu, in the lower test module: a one-thread compute program with four root constants copied to v1..v4 and a buffer_store_dword of v0, so a vector instruction can be checked for lowering on any host, without a GPU. It is built with the test module's lower_with and is the non-GPU half of what valu_tests::build_valu_cs builds.
  • A test, the_24_bit_multiplies_lower_both_halves, that lowers all four 24-bit multiplies (VOP2 0x09 to 0x0C).

Tested

macOS 27 arm64, Rust 1.98.1, debug, no GPU and no game files:

  • cargo test -p victory-shader: 97 passed, 0 failed, 1 ignored (96 on main ffe310e, plus the new test).
  • cargo fmt -p victory-shader -- --check: no diff in the lines this PR adds. cargo clippy -p victory-shader --all-targets --locked -- -D warnings stops on two unused imports in emit/mod.rs on macOS, on main as well (their users are Windows-only), so clippy as CI runs it was not checked here. cargo xtask policy: 154 files ok.
  • Before the change, a one-instruction program with either opcode stopped with "v_mul_hi_u32_u24 is not supported" / "v_mul_hi_i32_i24 is not supported".

Checked on hardware by others (see the comments)

  • @⁠Lyrnc: v_mul_hi_u32_u24, v_mul_hi_i32_i24 and the two low-dword forms on RDNA2 silicon (gfx1036), 500 operand pairs each, all matching the rule above.
  • @⁠DaviTostes: cargo test -p victory-shader on Arch Linux, 57 passed.

These are measurements of the instruction rule on hardware, not runs of this PR's emitted DXIL.

Not tested (by me)

  • The values: nothing here has executed the emitted DXIL. The value tests (valu_tests, diff_tests) are Windows-only and need a GPU, which I do not have. A run on a GPU by someone who has one would be welcome.
  • The Windows-only crates (victory-gpu, victory-hle, victory-loader) were not built.
  • I cannot say how many of the title's programs use these two; I have no game files.

Independent of #148 (different instructions; both add a test to the same module, so whichever lands second may need a trivial rebase, which I will do).

No game data: the test input is hand-written instruction words.

AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

**@⁠Rareuncommon** on GitHub · 2026-11-24 01:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/156) `Rareuncommon:shaders/mul-hi-24` → `main` · +61 −0 · 1 files · 1 commits · merged 2026-11-25 00:18 UTC Rebuilt on `main` `ffe310e` (`344704e` replaces `8142a94`): the lowering is the same, the test helper now uses main's `lower_with` and `root`. `v_mul_hi_u32_u24` and `v_mul_hi_i32_i24`, which the emitter refuses by name, now translate. One file, `crates/victory-shader/src/emit/lower.rs` (61 added). **What is in it** - The lowering (12 lines, next to `v_mul_u32_u24` / `v_mul_i32_i24`): the high dword of the same 48-bit product. The low 24 bits of each operand are zero- or sign-extended with the shift pair the low-dword forms already use, then multiplied through the existing `mul_hi`. - A test helper, `lowers_valu`, in the `lower` test module: a one-thread compute program with four root constants copied to `v1..v4` and a `buffer_store_dword` of `v0`, so a vector instruction can be checked for lowering on any host, without a GPU. It is built with the test module's `lower_with` and is the non-GPU half of what `valu_tests::build_valu_cs` builds. - A test, `the_24_bit_multiplies_lower_both_halves`, that lowers all four 24-bit multiplies (VOP2 0x09 to 0x0C). **Tested** macOS 27 arm64, Rust 1.98.1, debug, **no GPU and no game files**: - `cargo test -p victory-shader`: 97 passed, 0 failed, 1 ignored (96 on `main` `ffe310e`, plus the new test). - `cargo fmt -p victory-shader -- --check`: no diff in the lines this PR adds. `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` stops on two unused imports in `emit/mod.rs` on macOS, on `main` as well (their users are Windows-only), so clippy as CI runs it was not checked here. `cargo xtask policy`: 154 files ok. - Before the change, a one-instruction program with either opcode stopped with "v_mul_hi_u32_u24 is not supported" / "v_mul_hi_i32_i24 is not supported". **Checked on hardware by others (see the comments)** - @⁠Lyrnc: `v_mul_hi_u32_u24`, `v_mul_hi_i32_i24` and the two low-dword forms on RDNA2 silicon (gfx1036), 500 operand pairs each, all matching the rule above. - @⁠DaviTostes: `cargo test -p victory-shader` on Arch Linux, 57 passed. These are measurements of the instruction rule on hardware, not runs of this PR's emitted DXIL. **Not tested** (by me) - The values: nothing here has executed the emitted DXIL. The value tests (`valu_tests`, `diff_tests`) are Windows-only and need a GPU, which I do not have. A run on a GPU by someone who has one would be welcome. - The Windows-only crates (`victory-gpu`, `victory-hle`, `victory-loader`) were not built. - I cannot say how many of the title's programs use these two; I have no game files. Independent of #148 (different instructions; both add a test to the same module, so whichever lands second may need a trivial rebase, which I will do). No game data: the test input is hand-written instruction words. AI-assisted: yes (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The high dword of the 48-bit product whose low dword v_mul_u32_u24 and v_mul_i32_i24 already give: the low
24 bits of each operand, zero- or sign-extended, through the existing mul_hi.

The test module gets lowers_valu, a one-thread compute program with root constants in v1..v4 and a buffer
store of v0 (built with lower_with), so a vector instruction can be checked for lowering without a GPU.

AI-assisted (Claude Code).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:30 +00:00
github manually merged commit 344704e028 into gh-pr/156/base 2026-11-26 03:52:32 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:30 UTC · original

Tested 8142a94 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 57 passed, 0 failed (2 test binaries), including the {adds} test{'s' if adds != 1 else ''} this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/156#issuecomment-7119173803) Tested `8142a94` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **57 passed, 0 failed** (2 test binaries), including the {adds} test{'s' if adds != 1 else ''} this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used.
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-24 06:02 UTC · original

RDNA2 hardware check of the rule: matches.

AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) runs v_mul_hi_u32_u24, v_mul_hi_i32_i24, v_mul_u32_u24 and v_mul_i32_i24 on 500 operand pairs. 100 are pairs of edge values (0, 1, 0x7fffff, 0x800000, 0xffffff, 0x1000000, 0xff800000, 0xffffffff, …), which put junk in the upper 8 bits and hit the sign bit of the 24-bit field. The other 400 are random. RDNA2 desktop silicon, not the console's. No game data.

match
v_mul_hi_u32_u24: bits 63:32 of (a & 0xffffff) * (b & 0xffffff) 500/500
v_mul_hi_i32_i24: bits 63:32 of sext24(a) * sext24(b) (sign-filled) 500/500
the two low-dword forms, same operand rule 500/500

So "the high dword of the same 48-bit product, operands zero- or sign-extended from 24 bits" is what the hardware does, and the upper 8 bits of each operand are ignored.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.

**@⁠Lyrnc** on GitHub · 2026-11-24 06:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/156#issuecomment-7123512962) RDNA2 hardware check of the rule: **matches.** AMD Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036 (RDNA2)**, AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) runs `v_mul_hi_u32_u24`, `v_mul_hi_i32_i24`, `v_mul_u32_u24` and `v_mul_i32_i24` on 500 operand pairs. 100 are pairs of edge values (`0`, `1`, `0x7fffff`, `0x800000`, `0xffffff`, `0x1000000`, `0xff800000`, `0xffffffff`, …), which put junk in the upper 8 bits and hit the sign bit of the 24-bit field. The other 400 are random. RDNA2 desktop silicon, not the console's. No game data. | | match | |---|---| | `v_mul_hi_u32_u24`: bits 63:32 of `(a & 0xffffff) * (b & 0xffffff)` | 500/500 | | `v_mul_hi_i32_i24`: bits 63:32 of `sext24(a) * sext24(b)` (sign-filled) | 500/500 | | the two low-dword forms, same operand rule | 500/500 | So "the high dword of the same 48-bit product, operands zero- or sign-extended from 24 bits" is what the hardware does, and the upper 8 bits of each operand are ignored. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
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!156
No description provided.