Shaders: lower mul_hi without INT64 #2146
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2148"
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?
Imported from Marvisak/VIctory. Originally posted by scoresby13 on 2026-11-25T06:09:27Z.
Summary
Lowers
Lower::mul_hi(s_mul_hi_u32,s_mul_hi_i32,v_mul_hi_u32,v_mul_hi_i32,v_mul_hi_u32_u24,v_mul_hi_i32_i24) invictory-shaderusing pure 32-bit DXIL operations instead of 64-bit integer multiplication, removingflags::INT64(SFI0bit0x8000/Int64ShaderOps) from shaders that use 32-bit/24-bit high-multiply instructions.Claimed on #1633.
Details
16x16partial products without intermediate unsigned overflow (Hacker's Delight 8-2).signedis true, applies sign-bit masks(a >>s 31) & band(b >>s 31) & asubtracted from the unsigned high word to produce the exact signed high dword.s_mul_hi_*,v_mul_hi_*, andv_mul_hi_*_24callers onmul_hiwithout requiringInt64ShaderOps.SFI0validation (emit::lower::tests::mul_hi_needs_no_int64) and GPU/WARP tests (emit::valu_tests::mul_hi_matches_rdna2_without_int64) covering all 144 ordered pairs of 12 edge-case 32-bit values across all 6 instructions.Testing
cargo clippy -p victory-shader --all-targets --locked -- -D warnings(passed)cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings(passed)cargo xtask policy(asset policy: 182 files ok)cargo test -p victory-shader --locked mul_hi -- --nocapture(2 passed, 0 failed)cargo test -p victory-shader --locked the_24_bit_multiplies_lower_both_halves -- --nocapture(1 passed, 0 failed)No game data was used. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T06:24:00Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, withdxil.dllvalidator):cargo test -p victory-shader --lib mul_hi_— 2 passed, 0 failed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1(mul_hi_needs_no_int64andmul_hi_matches_rdna2_without_int64)cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean pure-32-bit
mul_hilowering withoutINT64, thoroughly verified end-to-end on hardware and WARP. Looks great.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:49:53Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.145 passed / 0 failed / 2 ignored. mul_hi lowered without INT64 — multiply-high in 32-bit DXIL; part of the no-INT64 lowering cluster (#2104/#2133/#2063).
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:20:23Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
8c9e7ebaontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T11:24:13Z.
Automated triage for the maintainers.
Needs work. The arithmetic is right. What the PR is missing is a reason to make the change.
What I checked:
Lower::mul_hi(crates/victory-shader/src/emit/lower.rs) now builds the high dword from four 16×16 partial products. The steps match Hacker's Delightmulhu, and no intermediate overflows 32 bits. The signed result subtracts(a >> 31) & band(b >> 31) & a, which is the standardmulhscorrection. The 24-bit callers still sign- or zero-extend before the call.mul_hi_matches_rdna2_without_int64compares all 144 pairs of edge values on the GPU against a 64-bit reference, which is a real check.Why it isn't mergeable as is:
Int64ShaderOpson the host (crates/victory-gpu/src/host.rschecks only the 64-bit atomic caps), and every SM 6.6 GPU VIctory targets exposes it. The offline measurement on the thread found no change in validated programs (23,918 before and after).INT64anyway. It is still set bysrc64, thes_lshl_b64/s_lshr_b64/s_ashr_i64path and the 64-bit atomics, so many programs will declare it regardless.What would change the verdict: a host or driver that refuses
Int64ShaderOpsand so fails on these programs today, or a measured gain (for example programs that no longer declareINT64at all, with a host that cares). CI: passing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T03:27:16Z.
@scoresby13 I measured the partial-product cost raised in triage using your
8c9e7ebamerged onto main63bcca43. On the RTX 5080 and built-in WARP, all six forms on your branch matched the CPU reference for 32,768 input pairs each (196,608/196,608 high dwords per device).On the RTX, a chain of 64 dependent
v_mul_hi_u32operations per lane took 6.18–6.21 µs with your lowering, 4.13 µs on main, and 4.16 µs using #3007's DXIL intrinsic. A signed 24-bit chain gave 7.62–7.68, 5.66–5.70, and 4.90–4.93 µs respectively. These are medians from two independent runs with the three variants interleaved. The intrinsic keeps your INT64-removal goal and was faster than the partial products on both measured shaders. Fixtures, method and results on #3007.Imported from Marvisak/VIctory. Originally posted by scoresby13 on 2026-11-26T07:08:42Z.
Thank you @steven-seagull27 for the RTX 5080 benchmark and @Ingenioeren for #3007! Since #3007 (
Shaders: lower the 32-bit mul_hi forms to one UMul/IMul) dropsSFI0INT64using DXIL's nativeUMul/IMulintrinsic directly and runs faster without the 16x16 partial-product overhead, I'm closing this PR in favor of #3007.AI-assisted.
Pull request closed