Shaders: lower v_mul_hi_u32_u24 and v_mul_hi_i32_i24 #156
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!156
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/156/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCRebuilt on
mainffe310e(344704ereplaces8142a94): the lowering is the same, the test helper now uses main'slower_withandroot.v_mul_hi_u32_u24andv_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
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 existingmul_hi.lowers_valu, in thelowertest module: a one-thread compute program with four root constants copied tov1..v4and abuffer_store_dwordofv0, so a vector instruction can be checked for lowering on any host, without a GPU. It is built with the test module'slower_withand is the non-GPU half of whatvalu_tests::build_valu_csbuilds.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 onmainffe310e, 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 warningsstops on two unused imports inemit/mod.rson macOS, onmainas well (their users are Windows-only), so clippy as CI runs it was not checked here.cargo xtask policy: 154 files ok.Checked on hardware by others (see the comments)
v_mul_hi_u32_u24,v_mul_hi_i32_i24and the two low-dword forms on RDNA2 silicon (gfx1036), 500 operand pairs each, all matching the rule above.cargo test -p victory-shaderon 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)
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.victory-gpu,victory-hle,victory-loader) were not built.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 on GitHub · 2026-11-24 01:30 UTC · original
Tested
8142a94on 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.victory-gpuE0425.No game data used.
@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_u24andv_mul_i32_i24on 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.v_mul_hi_u32_u24: bits 63:32 of(a & 0xffffff) * (b & 0xffffff)v_mul_hi_i32_i24: bits 63:32 ofsext24(a) * sext24(b)(sign-filled)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.