DXIL: lower Lw::mul_hi to umul_wide and imul_wide #2162
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2172"
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 ivall/xcl. Originally posted by O5-7 on 2026-11-25T07:04:26Z.
Lower RDNA2 32x32→high-32 multiplication (
Lw::mul_hi) directly to DXILdx.op.binaryWithTwoOuts.i32(umul_wide, op 42, andimul_wide, op 41) instead of widening operands toi64, multiplying in 64 bits, shifting right by 32, and truncating back toi32.This covers
s_mul_hi_u32,s_mul_hi_i32,v_mul_hi_u32,v_mul_hi_i32,v_mul_hi_u32_u24, andv_mul_hi_i32_i24and avoids unnecessary 64-bit integer operations andFeature::Int64Opsflags.Part of #1269
What is in it
crates/xcl/src/gpu/dxil/lower.rs: replaceLw::mul_hiwithif signed { self.s.imul_wide(a, b).0 } else { self.s.umul_wide(a, b).0 }(+1/-5 lines).crates/xcl/src/gpu/dxil/core_tests.rs: addmul_hi_lowers_to_dxil_wide_mulverifying DXIL validation and disassembly emitdx.op.binaryWithTwoOuts.i32opcodes 42 (UMul) and 41 (IMul) withoutmul i64orsext i32.crates/xcl/src/gpu/recomp/tests.rs: addgpu_mul_hi_edge_casestesting scalar and vectormul_hi(u32,i32,u24,i24with dirty upper 8 bits and sign/boundary inputs) against 64-bit CPU reference.(V_MUL_HI_U32, V_MUL_HI_I32)pairs, wave32):n = 1changes2272→2348bytes (firstdx.types.twoi32/binaryWithTwoOutsdeclarations);n = 64drops5748→5676bytes (-72bytes) and removes alli64arithmetic.Tested
32.0.15.9579, wave32), AMD Ryzen 7 9700X, Windows 11 Pro10.0.26100,rustc 1.100.0, DXC1.8.2502.11(XCL_DXC_DIR=D:\Windows Kits\10\bin\10.0.26100.0\x64), debug & release builds.cargo test --workspace -- --test-threads=4: 1156 passed, 0 failed, 46 ignored (24 SKIPPEDhardware-capability / policy checks: native wave64 unavailable on RTX 5080 and rejected direct-pathf16arithmetic), includingmul_hi_lowers_to_dxil_wide_mulandgpu_mul_hi_edge_cases.XCL_DIRECT_DXIL=1targeted GPU parity runs on RTX 5080 (gpu_mul_hi_edge_cases,gpu_scalar_sext_mulhi_and_vector_i24_sub_co_ci_u64_shifts): both passed.Regression run
main:
PR:
Not tested
XCL_DIRECT_DXIL=1in thesmoke.ps1launch (because on unmergedmainwithout PR #2101,D:\Windows Kits\...inXCL_DXC_DIRis intercepted by the{game}D-drive VFS mount inside the host process;XCL_DIRECT_DXIL=1was verified in unit/GPU tests).AI use
Lw::mul_hito emitumul_wide/imul_wide, added the disassembly and GPU edge-case tests, and ran the test suite andscripts/smoke.ps1regression checks.Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-25T07:12:02Z.
Independent native Windows AMD check of exact PR head
3a599afdb71b1994ae09df4772a73c98d176bdf7. The PR description lists native wave64 as untested.Tested
30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5; debug tests.XCL_ADAPTER=6800M,XCL_REQUIRE_GPU=wave64,XCL_DIRECT_DXIL=1;cargo test --locked -p xcl --lib -j 2 gpu_mul_hi_edge_cases -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, 0 SKIPPED. The fixture runs both wave64 and wave32 and checks scalar/vector signed and unsigned high-multiply cases, including 24-bit operands, against CPU reference values.XCL_DIRECT_DXIL=0: 1 passed, 0 failed, 0 ignored, 0 SKIPPED.mul_hi_lowers_to_dxil_wide_mulon this head: 1 passed, 0 failed, 0 ignored (DXIL intrinsic validation/disassembly unit test).This checks the focused GPU and DXIL tests. I did not run the full workspace suite or a paired title smoke on this PR. No claim about speed or title shader use follows from these tests.
AI-assisted checkout, testing, log verification, and report drafting with OpenAI Codex (GPT-6). No game data was used.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T07:28:06Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T12:05:54Z.
Regression run of
aeab3278on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon568e7db7, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 104 % of
main's frames, 100 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T18:24:49Z.
Code review on
8f131d4(Lw::mul_hi -> umul_wide/imul_wide in lower.rs + disassembly & GPU edge-case tests): diff is clean and CI is green. Only item needed before merge: an exact-head8f131d4AMD GPU pass of gpu_mul_hi_edge_cases with XCL_DIRECT_DXIL=1 (previous RX 6800M run was on3a599afand the RX 9070 smoke on eab327 leaves XCL_DIRECT_DXIL unset).Imported from ivall/xcl. Originally posted by O5-7 on 2026-11-26T02:51:05Z.
Review: COMMENTED
Rebased onto main (
b49be18) to resolve trailing conflicts in core_tests.rs and recomp/tests.rs (now at01c4d20), and re-verified mul_hi (default + XCL_DIRECT_DXIL=1), workspace suite, and 60s smoke. Ready for an AMD XCL_DIRECT_DXIL=1 check on01c4d20.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T08:15:15Z.
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T23:10:47Z.
Independent desktop NVIDIA verification of PR #2172 at head
01c4d2068185c915a2e742358f5f2c2067d0a6f5(1commit; exact parent & merge-base:b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted release tests & build (
01c4d206)cargo test --release -p xcl --lib mul_hi_lowers_to_dxil_wide_mul -- --nocapture1 passed; 0 failed; 0 ignored; 1337 filtered out(0.01s)cargo test --release -p xcl --lib gpu_mul_hi_edge_cases -- --nocapture(3 consecutive runs, on-GPU RTX 4060)1 passed; 0 failed; 0 ignored; 1337 filtered out× 3 (0.23s,0.20s,0.20s)cargo test --release -p xcl --lib gpu::dxil::185 passed; 0 failed; 3 ignored; 1150 filtered out(3.35s;dispatch_chain_native_wave64_builds_wholeself-skipped on Wave32-only RTX 4060)cargo test --release -p xcl --lib gpu::recomp::402 passed; 0 failed; 20 ignored; 916 filtered out(4.95s; Wave64-only and#1426-refused subcases self-skipped as expected)cargo build --release -p xcl --bin xcl1m 12s, exit0)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, cached baseline on the same machine):PR #2172 (
01c4d2068185c915a2e742358f5f2c2067d0a6f5):Runtime log observations (
xcl.log)9222log lines,0[ERROR]/ device-removal / panic lines.19528 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample14015 MB committed by the process; video memory 6116 MB local, 4683 MB non-local.Limits of coverage
dx.op.binaryWithTwoOutsUMul/IMullowering (mul_hi_lowers_to_dxil_wide_mul) and on-GPU execution (gpu_mul_hi_edge_cases, 3/3 runs on RTX 4060) passed alongside fullgpu::dxil::andgpu::recomp::.gpu::dxil::andgpu::recomp::self-skipped on the Wave32-only RTX 4060, and the existing#[ignore]dump/fuzz/benchmark tests remained ignored. The 60 s warm-cache retail smoke confirms end-to-end stability and zero regression ontitle: 29640639(frame-count delta vs. cached parent smoke reflects single-run startup variance, not this PR).AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by vakaobr on 2026-11-27T12:53:58Z.
A note for the Mac path before this lands: on D3DMetal (Apple silicon, CrossOver), the two ops this PR switches to do not behave as on Windows. Measured on an M5 Pro, macOS 27.2.1, CrossOver 26.3 + D3DMetal, with the DXIL writer's own tests, not this PR's head:
UMul(opcode 42) can break Apple's shader converter.integer_ops_match_cpu(which hasUMul,IMulandUDiv) reports "has overflowed its stack" and then hangs at 0% CPU; withUMulreplaced it finishes in 0.2 s.raw_loads_in_root_windows_respect_exec_and_bounds(whose window address usesUMul) timed out in my earlier runs and passes without it.IMul(opcode 41) gives a wrong high half:1 * 0x9e377939returns0where it should be0xffffffff(integer_ops_match_cpuop #16, the first mismatch it reports).So on a Mac this PR would send every
s_mul_hi_*/v_mul_hi_*in the direct translator through those two ops, where the currenti64lowering avoids both. For the one existing use (window_at'sstride * index) I build the high half from 16-bit parts on a Mac (util::mac_host), as the HLSL kernel'smul_hi_u32does: vakaobr/xcl@9592cd1. If this goes in, keeping the current lowering whenmac_host()is true would avoid both problems.Not tested: this PR's head commit on a Mac, Windows.
AI use: Claude Code with Claude Opus 5.5 found the
UMulhang, ran the tests on my machine and drafted this comment. I checked it before posting.Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-27T18:00:55Z.
Tested on AMD / Linux:
01c4d206(RX 9070 16 GB, RDNA4, Mesa 26.3.1 RADV; Ryzen 5 9600X, 32 GB; CachyOS; Proton Experimentalexperimental-11.0-20261112with vkd3d-proton masterec207194plus a local patch dropping thelpVtblchecks of command allocators and lists; DXC 1.9.2609.5; Rust 1.96.0,x86_64-pc-windows-gnudebug build, tests run under Wine)The head as it is (base
b49be183), withmainf9a0cb80the same session as the baseline.Tests (
XCL_REQUIRE_GPU=wave64)cargo test -p xcl --lib -- mul_hi --test-threads=1: 2 passed, 0 failed, 0 ignored (mul_hi_lowers_to_dxil_wide_mul,gpu_mul_hi_edge_cases).cargo test --workspace --no-fail-fast -- --test-threads=4with--skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole(the first loses the RADV device here, the other two run out of memory under Wine): the lib binary ended partway with a device removal (0x887a0005), which happens intermittently onmainhere too (1 of its 3 four-thread runs). Lib again with--test-threads=1and the same skips: 1301 passed, 9 failed, 27 ignored;mainf9a0cb80lib the same session: 1323 passed, 9 failed, 27 ignored (--test-threads=1and two--test-threads=4runs). All failures are amongmain's. The other binaries fail the same 3 tests as onmainhere (e2e,pls_quota,predication_e2e).d3d12_resource_and_syncended the process, as it does onmainhere.Not tested
AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:31:12Z.
Triage (#1607) – head
01c4d20No open or merged PR moves
Lw::mul_hitoUMul/IMul; main still widens to i64.#3525 reports that D3DMetal's converter hangs on
UMulin some programs and thatIMul's high half is wrong there. On a Mac this change would emitIMulfor every signedmul_hi, so it would need the same halves fallback as #3525.Minor:
mul_hi_lowers_to_dxil_wide_mulcallsvalidate::validatebefore thedxc::location()check.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.