Shaders: lower mul_hi without INT64 #2148
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!2148
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@scoresby13 on GitHub · 2026-11-25 06:09 UTC · original
scoresby13:shader/mul-hi-no-int64→main· +163 −10 · 2 files · 1 commits · closed without mergingSummary
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.
@sinan-cmyk on GitHub · 2026-11-25 08:20 UTC · original
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).
@Marvisak on GitHub · 2026-11-25 11:24 UTC · original
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
@steven-seagull27 on GitHub · 2026-11-26 03:27 UTC · original
@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.@scoresby13 on GitHub · 2026-11-26 07:08 UTC · original
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