Shaders: lower the 32-bit mul_hi forms to one UMul/IMul #3007
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!3007
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3007"
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?
@Ingenioeren on GitHub · 2026-11-26 03:17 UTC · original
Ingenioeren:perf/v-mul-hi-u32→main· +129 −9 · 3 files · 1 commits · openWhat
Lower the signed and unsigned 32-bit scalar and vector
mul_hiforms through one DXIL helper. The two 24-bit vector forms use the same helper after sign- or zero-extending their operands to 32 bits.Why
This is an alternative to scoresby13’s #2148 with the same goal of removing the
INT64requirement formul_hi. DXILUMulandIMulreturn the high dword directly. The lowering uses one intrinsic call and one extract, which takes fewer DXIL instructions than expanding the multiply into 16×16 partial products. PR #2148 · DXIL multiply intrinsicsCounts are total written DXIL instructions for a synthetic compute shader with one instance of the listed opcode. All six shaders set the SFI0
INT64bit before the change and clear it after.origin/main)v_mul_hi_u32UMulv_mul_hi_i32IMuls_mul_hi_u32UMuls_mul_hi_i32IMulv_mul_hi_u32_u24UMulv_mul_hi_i32_i24IMulThe test-only
Module::written_instructions()helper is a byte-identical copy of the one in #2893, so whichever lands second drops its copy.How tested
origin/main(63bcca4) first. All 75 opcode/input combinations matched bit for bit after the change on both AMD Radeon RX 6750 XT hardware and WARP. Cases coveri32::MINmultiplied by itself,-1, andi32::MAX, plus-1 * -1,-1 * 1, zero, mixed signs, and the 24-bit sign boundary.cargo test -p victory-shader --locked --offline mul_hi -- --nocapturepassed all 3 tests, including the per-opcode instruction limits and SFI0 checks.cargo test -p victory-shader --locked --offlinereported 303 passed, 2 failed, and 3 ignored. The clean baseline reported 300 passed, 2 failed, and 3 ignored. Both runs had the same DXIL validator Pipeline State Validation mismatch inrectangles_get_their_fourth_cornerandelements_sharing_a_row_keep_their_order.resource_trackingintegration target reported 3 passed, 0 failed, and 1 ignored. The doc test target passed with zero tests.cargo clippy -p victory-shader --locked --offline --all-targetspassed.cargo run -p xtask --locked --offline -- policy --stagedpassed for all 3 files in the patch.What was not tested
No game was run. GPU coverage was limited to AMD Radeon RX 6750 XT hardware and WARP, with no NVIDIA run. Instruction counts are for DXIL. Native GPU instruction counts and execution time were outside this test scope.
AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
@steven-seagull27 on GitHub · 2026-11-26 03:27 UTC · original
@Ingenioeren I ran
42b4a868on an RTX 5080 (621.40) and built-in Microsoft WARP. All 75 of the PR's opcode/input cases passed on each. I also ran 32,768 independent input pairs through each of the six opcodes, including all 256 pairs from a boundary-value set and then deterministic pseudorandom words. The 24-bit forms received inputs with nonzero bits above bit 23. The scalar forms read their inputs in separate one-thread groups.Both devices returned 196,608/196,608 correct high dwords against a host reference using signed or unsigned 64-bit arithmetic. On the same corpus main
63bcca43and #21488c9e7ebamerged onto that main also had zero mismatches. On this PR all six single-op shaders cleared the INT64 feature bit. The four 32-bit cases emitted 18 DXIL instructions each and the two 24-bit cases emitted 22 each.I compared the emitted programs with D3D12 GPU timestamps on the RTX. Each lane applied
a = mul_hi(a, b) ^ seed64 times, using a distinct runtime input pair per lane, across 65,536 lanes. The timestamps bracket one dispatch. Every timed output was read back and checked. I rotated the three PSOs in each round, discarded three warmup rounds and took the median of the next 15. The two values in each cell are independent process runs, in microseconds.v_mul_hi_u32v_mul_hi_i32_i24On this workload, unsigned 32-bit stayed within 1% of main's median while clearing INT64. The signed 24-bit chain took about 14% less GPU time than main. Both intrinsic chains were quicker than the partial-product equivalents in every paired measured round. These timings cover the two synthetic chains above.
AI-assisted. No game files used.
@Marvisak on GitHub · 2026-11-26 06:16 UTC · original
Automated triage for the maintainers.
Lower::mul_hiinemit/lower.rsnow emits a singledx.op.binaryWithTwoOuts.i32call: opcode 41 (IMul) for signed and 42 (UMul) for unsigned. It takes element 0 ofdx.types.twoi32, which is the high dword per the public DXIL spec. This removes theINT64shader-feature requirement from all six*_mul_hi_*forms. I checked thatShader::opbuilds the matching(i32, i32, i32) -> %dx.types.twoi32signature, and that the three callers, including the 24-bit forms, still pass correctly extended 32-bit operands. The expected values in the newvalu_testsGPU cases are correct by hand, for example0x80000000 * 0xFFFFFFFFgives high word0x7FFFFFFFunsigned and0signed. Thewritten_instructionshelper is test-only.This covers the same ground as #2148 (16-bit partial products) with fewer instructions, so only one of the two should land. The PR notes that the helper duplicates one in #2893.
CI:
checkpassing.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 03:24 UTC · original · approved these changes
Code review on
42b4a868(static source inspection; no runtime GPU/DXIL validation executed):crates/victory-shader/src/emit/lower.rs:2494-2514cleanly lowersmul_hithroughdx.op.binaryWithTwoOuts.i32(IMul= 41 /UMul= 42, extracting the high dword at element 0), eliminating thei64widens/shifts and dropping theINT64feature flag requirement across all six scalar/vector 32-bit and 24-bit forms.bitcode.rs::written_instructionsaccurately matchesModule::write's live-instruction and block layout, the added instruction-count andSFI0INT64-absent assertions are well-scoped, and the resultingemit/lower.rsstays below the 512 KiB policy limit (522,175 B).@kotekompotek on GitHub · 2026-11-26 04:40 UTC · original · approved these changes
LGTM — IMulExtended(41)/UMulExtended(42) via binaryWithTwoOuts with the dx.types.twoi32 struct is the canonical DXIL form; drops the i64 widening+shift+trunc chain and its INT64 flag.
@Dukestar69 on GitHub · 2026-11-26 06:51 UTC · original · approved these changes
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP +dxil.dll):mul_hidirectly todx.op.binaryWithTwoOuts.i32(IMul= 41 /UMul= 42, extracting word 0) eliminatesi64casts/shifts and avoids requiring theINT64shader feature flag for 32-bit/24-bit high-multiply ops.cargo test -p victory-shader mul_hi -- --test-threads=1(RTX 5090 & WARP): all tests passed on both (includingmul_hi_has_a_short_lowering_without_int64and GPUvalu_tests).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@Jackster on GitHub · 2026-11-26 19:01 UTC · original
AMD check at
42b4a868(basemain63bcca43), on an RX 7900 XTX (RDNA3, driver 32.0.32029.2010, Windows 11) and Microsoft WARP on the same machine:cargo test -p victory-shader --lib mul_hi— the three PR tests pass, and the hardware backend actually ran (none of the "no SM 6.6 … skipped" lines).0x80000000/0xffffffffedges, and 24-bit forms fed with bits above bit 23. The sweep fails if the hardware backend did not run.cargo clippy -p victory-shader --all-targetsclean;cargo xtask policy— 191 files ok. (The 2026-11-26 06:48 status row'slower.rs525,583-byte flag is stale at this head; the file is 522,175 bytes.)cargo test -p victory-shader --libpassed: 307 passed, 0 failed, 3 ignored, with the hardware backend available (includes two local-only test additions; none of the PR's tests failed).valu_testswere re-derived independently and all match.Synthetic shaders only, no game files. AI-assisted.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.