Skip to content

DXIL: lower Lw::mul_hi to umul_wide and imul_wide - #2172

Open
O5-7 wants to merge 1 commit into
xcl-dev:mainfrom
O5-7:dxil/mul-hi-wide
Open

O5-7 wants to merge 1 commit into
xcl-dev:mainfrom
O5-7:dxil/mul-hi-wide

Conversation

@O5-7

@O5-7 O5-7 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Lower RDNA2 32x32→high-32 multiplication (Lw::mul_hi) directly to DXIL dx.op.binaryWithTwoOuts.i32 (umul_wide, op 42, and imul_wide, op 41) instead of widening operands to i64, multiplying in 64 bits, shifting right by 32, and truncating back to i32.

This covers s_mul_hi_u32, s_mul_hi_i32, v_mul_hi_u32, v_mul_hi_i32, v_mul_hi_u32_u24, and v_mul_hi_i32_i24 and avoids unnecessary 64-bit integer operations and Feature::Int64Ops flags.

Part of #1269

What is in it

  • crates/xcl/src/gpu/dxil/lower.rs: replace Lw::mul_hi with if 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: add mul_hi_lowers_to_dxil_wide_mul verifying DXIL validation and disassembly emit dx.op.binaryWithTwoOuts.i32 opcodes 42 (UMul) and 41 (IMul) without mul i64 or sext i32.
  • crates/xcl/src/gpu/recomp/tests.rs: add gpu_mul_hi_edge_cases testing scalar and vector mul_hi (u32, i32, u24, i24 with dirty upper 8 bits and sign/boundary inputs) against 64-bit CPU reference.
  • Synthetic compute shader measurement (1 and 64 (V_MUL_HI_U32, V_MUL_HI_I32) pairs, wave32): n = 1 changes 2272 → 2348 bytes (first dx.types.twoi32 / binaryWithTwoOuts declarations); n = 64 drops 5748 → 5676 bytes (-72 bytes) and removes all i64 arithmetic.

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 5080 (driver 32.0.15.9579, wave32), AMD Ryzen 7 9700X, Windows 11 Pro 10.0.26100, rustc 1.100.0, DXC 1.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 SKIPPED hardware-capability / policy checks: native wave64 unavailable on RTX 5080 and rejected direct-path f16 arithmetic), including mul_hi_lowers_to_dxil_wide_mul and gpu_mul_hi_edge_cases.
  • XCL_DIRECT_DXIL=1 targeted 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:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1680 (PresentX 1680)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 13673 MB

PR:

xcl-smoke v1
commit: 01c4d2068185c915a2e742358f5f2c2067d0a6f5
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1685 (PresentX 1685)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13629 MB

Not tested

  • Native wave64 GPU execution (skipped automatically on wave32-only RTX 5080 hardware).
  • Running the title with XCL_DIRECT_DXIL=1 in the smoke.ps1 launch (because on unmerged main without PR VFS: exempt xcl.exe and host tool dirs from console drive mounts #2101, D:\Windows Kits\... in XCL_DXC_DIR is intercepted by the {game} D-drive VFS mount inside the host process; XCL_DIRECT_DXIL=1 was verified in unit/GPU tests).

AI use

  • Antigravity (Gemini 4 Neon): updated Lw::mul_hi to emit umul_wide/imul_wide, added the disassembly and GPU edge-case tests, and ran the test suite and scripts/smoke.ps1 regression checks.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent native Windows AMD check of exact PR head 3a599afdb71b1994ae09df4772a73c98d176bdf7. The PR description lists native wave64 as untested.

Tested

  • Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 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.
  • The same GPU command with XCL_DIRECT_DXIL=0: 1 passed, 0 failed, 0 ignored, 0 SKIPPED.
  • mul_hi_lowers_to_dxil_wide_mul on 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.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@O5-7
O5-7 force-pushed the dxil/mul-hi-wide branch 2 times, most recently from 838eb4e to aeab327 Compare November 25, 2026 11:58
@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of aeab3278 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 568e7db7, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB
xcl-smoke v1
commit: aeab32784f743a3308e995181f272e7605a974c2
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB

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.

@raylitebull

Copy link
Copy Markdown
Member

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-head 8f131d4 AMD GPU pass of gpu_mul_hi_edge_cases with XCL_DIRECT_DXIL=1 (previous RX 6800M run was on 3a599af and the RX 9070 smoke on �eab327 leaves XCL_DIRECT_DXIL unset).

Replace the 64-bit extend/mul/shift/trunc expansion in Lw::mul_hi with
dx.op.binaryWithTwoOuts UMul (op 42) and IMul (op 41), extracting the
high dword directly and avoiding i64 ops and Feature::Int64Ops across
s_mul_hi_u32/i32, v_mul_hi_u32/i32, and v_mul_hi_u32_u24/i32_i24.

Part of xcl-dev#1269

Assisted-by: Antigravity (Gemini 4 Neon)

@O5-7 O5-7 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased onto main (b49be18) to resolve trailing conflicts in core_tests.rs and recomp/tests.rs (now at 01c4d20), and re-verified mul_hi (default + XCL_DIRECT_DXIL=1), workspace suite, and 60s smoke. Ready for an AMD XCL_DIRECT_DXIL=1 check on 01c4d20.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #2172 at head 01c4d2068185c915a2e742358f5f2c2067d0a6f5 (1 commit; exact parent & merge-base: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, Wave32-only Ada), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (01c4d206)

Command Result
cargo test --release -p xcl --lib mul_hi_lowers_to_dxil_wide_mul -- --nocapture 1 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_whole self-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 xcl Clean build (1m 12s, exit 0)

Paired quiet 60 s retail smoke (title: 29640639)

Exact parent & merge-base (b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, cached baseline on the same machine):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14018 MB

PR #2172 (01c4d2068185c915a2e742358f5f2c2067d0a6f5):

xcl-smoke v1
commit: 01c4d2068185c915a2e742358f5f2c2067d0a6f5
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1592 (PresentX 1592)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14016 MB

Runtime log observations (xcl.log)

  • 9222 log lines, 0 [ERROR] / device-removal / panic lines.
  • Final draw/memory telemetry in log: 19528 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample 14015 MB committed by the process; video memory 6116 MB local, 4683 MB non-local.

Limits of coverage

  • dx.op.binaryWithTwoOuts UMul/IMul lowering (mul_hi_lowers_to_dxil_wide_mul) and on-GPU execution (gpu_mul_hi_edge_cases, 3/3 runs on RTX 4060) passed alongside full gpu::dxil:: and gpu::recomp::.
  • Wave64-only GPU subcases in gpu::dxil:: and gpu::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 on title: 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).

@vakaobr

vakaobr commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

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 has UMul, IMul and UDiv) reports "has overflowed its stack" and then hangs at 0% CPU; with UMul replaced it finishes in 0.2 s. raw_loads_in_root_windows_respect_exec_and_bounds (whose window address uses UMul) timed out in my earlier runs and passes without it.
  • IMul (opcode 41) gives a wrong high half: 1 * 0x9e377939 returns 0 where it should be 0xffffffff (integer_ops_match_cpu op Olympus: reject invalid mesh branch targets #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 current i64 lowering avoids both. For the one existing use (window_at's stride * index) I build the high half from 16-bit parts on a Mac (util::mac_host), as the HLSL kernel's mul_hi_u32 does: vakaobr/xcl@9592cd1. If this goes in, keeping the current lowering when mac_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 UMul hang, ran the tests on my machine and drafted this comment. I checked it before posting.

@ClosetPie107

Copy link
Copy Markdown

Tested on AMD / Linux: 01c4d206 (RX 9070 16 GB, RDNA4, Mesa 26.3.1 RADV; Ryzen 5 9600X, 32 GB; CachyOS; Proton Experimental experimental-11.0-20261112 with vkd3d-proton master ec207194 plus a local patch dropping the lpVtbl checks of command allocators and lists; DXC 1.9.2609.5; Rust 1.96.0, x86_64-pc-windows-gnu debug build, tests run under Wine)

The head as it is (base b49be183), with main f9a0cb80 the 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=4 with --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 on main here too (1 of its 3 four-thread runs). Lib again with --test-threads=1 and the same skips: 1301 passed, 9 failed, 27 ignored; main f9a0cb80 lib the same session: 1323 passed, 9 failed, 27 ignored (--test-threads=1 and two --test-threads=4 runs). All failures are among main's. The other binaries fail the same 3 tests as on main here (e2e, pls_quota, predication_e2e). d3d12_resource_and_sync ended the process, as it does on main here.

Not tested

  • A retail title
  • Native Windows, NVIDIA / Intel

AI use

  • Claude Code (Claude Opus 5.5) wrote the test scripts, ran the builds and tests on my machine and wrote this report.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 01c4d20

No open or merged PR moves Lw::mul_hi to UMul/IMul; main still widens to i64.
#3525 reports that D3DMetal's converter hangs on UMul in some programs and that IMul's high half is wrong there. On a Mac this change would emit IMul for every signed mul_hi, so it would need the same halves fallback as #3525.
Minor: mul_hi_lowers_to_dxil_wide_mul calls validate::validate before the dxc::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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants