Skip to content

Shaders: lower v_mul_hi_u32_u24 and v_mul_hi_i32_i24 - #156

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
Rareuncommon:shaders/mul-hi-24
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
Rareuncommon:shaders/mul-hi-24

Conversation

@Rareuncommon

@Rareuncommon Rareuncommon commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

@DaviTostes

Copy link
Copy Markdown

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

No game data used.

AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
…32_i24) into the integration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@Lyrnc

Lyrnc commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

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-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
KainanP pushed a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…fied together

Merges Marvisak#156 Marvisak#162 Marvisak#168 Marvisak#169 Marvisak#368 Marvisak#379 Marvisak#456 Marvisak#587 Marvisak#990 Marvisak#1021 Marvisak#1048 Marvisak#1052 Marvisak#1053
Marvisak#1095 Marvisak#1142 Marvisak#1190 Marvisak#1211 Marvisak#1223 Marvisak#1259 Marvisak#1293 on top of the bundle of Marvisak#1402
(which is on Marvisak#1319, on main ffe310e), each head unchanged. Hunks that
conflicted in emit/lower.rs, emit/valu_tests.rs and emit/diff_tests.rs were
merged by keeping both sides (additions next to each other); a PR was kept
only if cargo clippy -p victory-shader --all-targets -- -D warnings still
passed with it. No instruction name is handled in two places.

Marvisak#98 is not in this version: an offline measurement on a retail dump showed
it loses 31 programs that validate on Marvisak#1402.

cargo clippy --workspace --all-targets --locked -- -D warnings, with and
without --all-features, is clean and cargo test --workspace --locked passes
(381 passed, 6 ignored; main has 342 passed, 6 ignored).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@Marvisak
Marvisak merged commit 256d7b9 into Marvisak:main Nov 25, 2026
bodnjenie14 added a commit to bodnjenie14/VIctory that referenced this pull request Nov 25, 2026
Keep the existing LDS write/barrier proof and preserve descriptor record counts while reading addresses from the host heap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants