Shaders: lower the 32-bit mul_hi forms to one UMul/IMul #3005
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-26T03:17:11Z.
What
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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T03:24:49Z.
Review: APPROVED
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).Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T03:27:02Z.
@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.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:40:27Z.
Review: APPROVED
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.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:51:17Z.
Review: APPROVED
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).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:16:33Z.
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
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T19:01:39Z.
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.
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-26T21:35:43Z.
Verified on RDNA3: Windows 11, AMD Radeon 780M (iGPU), toolchain 1.98.1,
cargo test -p victory-shader --lib --locked --no-fail-fast -- --test-threads=1, branch as-is.VICTORY_WARP=1)mul_hi_has_a_short_lowering_without_int64mul_hi_returns_the_exact_high_wordv_mul_hi_u32_returns_the_unsigned_high_wordThe four WARP failures are the synthetic_tests ones main has too with
VICTORY_WARP=1(fixed by #2225), not this PR. This PR also covers NEW-68.AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T01:11:14Z.
I tested
42b4a868with the verified #3632/#2926 integration0e22c83on63bcca4. The trees merge cleanly and keep all three PR histories. Integration branch1418c4aThe four 32-bit MUL_HI forms still emit 18 DXIL instructions apiece. For the 24-bit forms, the unsigned mask brings MUL_HI from #3007's 22 to 20, and the signed form stays at 22. All six MUL_HI feature checks pass with the SFI0 INT64 bit clear. An additional local check found it clear on all four clamped MUL/MAD forms too.
On app-local WARP 1.0.22 with Agility 1.620.2 and DXIL validation, all three MUL_HI tests and all 96 clamp/wrap cases passed. The ten upper-byte arithmetic encodings also matched their references. The VALU group passed 38 tests, the semantics group passed 35 with one ignored, and strict all-feature shader Clippy passed. The extra feature-bit probe stayed local. AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T13:25:24Z.
I combined your exact
42b4a868with #373784a1724in9ccacfb. Git merged the files cleanly and kept both commits as direct parents. The signed 24-bit high multiply now uses twoIbfeoperations followed by yourIMulpath.Both your head and the combined branch matched the wide-integer model for all 6,912 generated output words on WARP 1.0.22 with Agility 1.620.2. All three multiply-high tests passed, including the instruction budget and absence of the
INT64feature for these forms. In the signed high-multiply fixture, written DXIL went from 42 to 40 instructions and from 2,456 to 2,524 bytes. The unsigned control stayed at 42 instructions and 2,456 bytes. Strict all-feature shader Clippy and the asset policy passed.@Ingenioeren, the integration tree is ready for merge coordination. Please retain Git authorship when cherry-picking or rebasing. If folding #3737 into another commit, please add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.AI-assisted with OpenAI Codex.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.