Shaders: lower v_mul_hi_u32_u24 and v_mul_hi_i32_i24 #156

Merged
Rareuncommon merged 1 commit from upstream-pr/156 into main 2026-11-25 00:18:32 +00:00
Rareuncommon commented 2026-11-24 01:00:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Rareuncommon on 2026-11-24T01:00:41Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572175204 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/156). Originally posted by [Rareuncommon](https://github.com/Rareuncommon) on 2026-11-24T01:00:41Z. --- 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)
catminou4 commented 2026-11-24 06:45:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T06:45:21Z.

Review: COMMENTED


Verified locally on macOS 26 arm64, rustc 1.98.1 (aarch64-apple-darwin) at head 8142a945:

  • cargo test -p victory-shader --locked: compiles clean, all ungated tests pass (no regressions vs main's 56).

Scope note: valu_tests/image_tests in victory-shader are #[cfg(all(test, windows))] — they need the Windows host backend (D3D12/dxil.dll), so they did not run here. What I verified is compilation on macOS plus all ungated tests. For this PR that means the new v_mul_hi lowering coverage still needs a Windows run before merge — I can't execute it on this machine. The lowering changes themselves compile everywhere.

<!-- greyfinch-sync:Marvisak/VIctory:review:6034817075 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/156#pullrequestreview-6034817075). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T06:45:21Z. **Review:** COMMENTED --- Verified locally on macOS 26 arm64, rustc 1.98.1 (aarch64-apple-darwin) at head 8142a945: - `cargo test -p victory-shader --locked`: compiles clean, all ungated tests pass (no regressions vs main's 56). Scope note: `valu_tests`/`image_tests` in victory-shader are `#[cfg(all(test, windows))]` — they need the Windows host backend (D3D12/dxil.dll), so they did **not** run here. What I verified is compilation on macOS plus all ungated tests. For this PR that means the new v_mul_hi lowering coverage still needs a Windows run before merge — I can't execute it on this machine. The lowering changes themselves compile everywhere.
DaviTostes commented 2026-11-24 06:54:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:30:53Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119173803 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/156#issuecomment-7119173803). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:30:53Z. --- 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.
Lyrnc commented 2026-11-24 06:56:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:02:17Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123512962 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/156#issuecomment-7123512962). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:02:17Z. --- 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.
upstream-sync closed this pull request 2026-11-25 01:02:49 +00:00
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!156
No description provided.