Shaders: lower mul_hi without INT64 #741

Open
github-bot wants to merge 1 commit from github-bot/gh-741 into main AGit
Owner

@⁠scoresby13 on GitHub · 2026-11-25 06:09 UTC · original
scoresby13:shader/mul-hi-no-int64 → main · +137 −10 · 2 files · 1 commits · open

Summary

Lowers Lower::mul_hi (s_mul_hi_u32, s_mul_hi_i32, v_mul_hi_u32, v_mul_hi_i32) in victory-shader using pure 32-bit DXIL operations instead of 64-bit integer multiplication, removing flags::INT64 (SFI0 bit 0x8000 / Int64ShaderOps) from shaders that use 32-bit high-multiply instructions.

Details

  • Splits each 32-bit factor into 16-bit halves and computes the exact unsigned 32-bit high dword via 16x16 partial products without intermediate unsigned overflow (Hacker's Delight 8-2).
  • When signed is true, applies sign-bit masks (a >>s 31) & b and (b >>s 31) & a subtracted from the unsigned high word to produce the exact signed high dword.
  • Adds CPU-only SFI0 validation (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 4 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: 171 files ok)
  • cargo test -p victory-shader --locked mul_hi -- --nocapture (2 passed, 0 failed)

No game data was used. AI-assisted.

**@⁠scoresby13** on GitHub · 2026-11-25 06:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/741) `scoresby13:shader/mul-hi-no-int64` → `main` · +137 −10 · 2 files · 1 commits · open ## Summary Lowers `Lower::mul_hi` (`s_mul_hi_u32`, `s_mul_hi_i32`, `v_mul_hi_u32`, `v_mul_hi_i32`) in `victory-shader` using pure 32-bit DXIL operations instead of 64-bit integer multiplication, removing `flags::INT64` (`SFI0` bit `0x8000` / `Int64ShaderOps`) from shaders that use 32-bit high-multiply instructions. ## Details - Splits each 32-bit factor into 16-bit halves and computes the exact unsigned 32-bit high dword via `16x16` partial products without intermediate unsigned overflow (Hacker's Delight 8-2). - When `signed` is true, applies sign-bit masks `(a >>s 31) & b` and `(b >>s 31) & a` subtracted from the unsigned high word to produce the exact signed high dword. - Adds CPU-only `SFI0` validation (`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 4 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: 171 files ok`) - `cargo test -p victory-shader --locked mul_hi -- --nocapture` (2 passed, 0 failed) No game data was used. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:03 +00:00
Author
Owner

@⁠avt0m4t48 on GitHub · 2026-11-25 06:28 UTC · original

Independent check of 597d6ba05dce318007003c55a7720a133f7a2f23 against its parent 8dd30ab472697c47b141c273c2a00f8ce1c00520. I emitted four synthetic compute shaders using dynamic root constants, one each for signed and unsigned scalar and vector mul_hi. I evaluated the disassembled DXIL that supplies the LDS store and compared it with the high word of a full-width product. Both revisions matched all 8,768 input pairs per opcode, including ordered boundary pairs, seeded random values, and values biased toward partial-product carries.

All four base shaders set the SFI0 INT64 bit and emitted i64 arithmetic. All four head shaders cleared the bit and emitted only i32 arithmetic. The unmodified head also passed the Linux shader library suite (172 passed, 2 ignored) and cargo check --locked -p victory-shader --tests --target x86_64-pc-windows-msvc.

The arithmetic check ran on the CPU. Windows execution, WARP/GPU readback, and Microsoft DXIL validation remain unverified by this check. No game files were used.

**@⁠avt0m4t48** on GitHub · 2026-11-25 06:28 UTC · [original](https://github.com/fxceless/victory-fork/pull/741#issuecomment-7154835131) Independent check of `597d6ba05dce318007003c55a7720a133f7a2f23` against its parent `8dd30ab472697c47b141c273c2a00f8ce1c00520`. I emitted four synthetic compute shaders using dynamic root constants, one each for signed and unsigned scalar and vector `mul_hi`. I evaluated the disassembled DXIL that supplies the LDS store and compared it with the high word of a full-width product. Both revisions matched all **8,768 input pairs per opcode**, including ordered boundary pairs, seeded random values, and values biased toward partial-product carries. All four base shaders set the SFI0 `INT64` bit and emitted i64 arithmetic. All four head shaders cleared the bit and emitted only i32 arithmetic. The unmodified head also passed the Linux shader library suite (172 passed, 2 ignored) and `cargo check --locked -p victory-shader --tests --target x86_64-pc-windows-msvc`. The arithmetic check ran on the CPU. Windows execution, WARP/GPU readback, and Microsoft DXIL validation remain unverified by this check. No game files were used.
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 13:00 UTC · original

An AMD run of this PR's new tests. mul_hi_matches_rdna2_without_int64 passes, and so does the CPU-side mul_hi_needs_no_int64 on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with the Agility SDK runtime from #402. They ran on the hardware device; WARP skips on this machine. Nothing else in the workspace regresses.

The setup, and the same run for eight related shader PRs, are in one table on #637: #637

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 13:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/741#issuecomment-7163156898) An AMD run of this PR's new tests. `mul_hi_matches_rdna2_without_int64` passes, and so does the CPU-side `mul_hi_needs_no_int64` on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with the Agility SDK runtime from #402. They ran on the hardware device; WARP skips on this machine. Nothing else in the workspace regresses. The setup, and the same run for eight related shader PRs, are in one table on #637: https://git.gtahub.st/github/fxceless--victory-fork/pulls/637
Author
Owner

@⁠scoresby13 on GitHub · 2026-11-26 07:08 UTC · original

Sharing an upstream benchmark update for context: upstream Marvisak/VIctory#3007 lowers the 32-bit mul_hi forms using DXIL's native UMul/IMul (dx.op.binaryWithTwoOutputs.i32) intrinsic rather than 16x16 partial products, which also removes SFI0 INT64 and measured faster in an RTX 5080 benchmark reported on Marvisak/VIctory#2148.

Leaving this PR open (alongside #726) in case you'd prefer to merge the verified 16x16 lowering as-is or adapt UMul/IMul.

AI-assisted.

**@⁠scoresby13** on GitHub · 2026-11-26 07:08 UTC · [original](https://github.com/fxceless/victory-fork/pull/741#issuecomment-7185143910) Sharing an upstream benchmark update for context: upstream `Marvisak/VIctory#3007` lowers the 32-bit `mul_hi` forms using DXIL's native `UMul`/`IMul` (`dx.op.binaryWithTwoOutputs.i32`) intrinsic rather than 16x16 partial products, which also removes `SFI0` `INT64` and measured faster in an RTX 5080 benchmark reported on `Marvisak/VIctory#2148`. Leaving this PR open (alongside #726) in case you'd prefer to merge the verified 16x16 lowering as-is or adapt `UMul`/`IMul`. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/741/head:github-bot/gh-741'
git switch 'github-bot/gh-741'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-741'
git switch 'github-bot/gh-741'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-741'
git switch 'github-bot/gh-741'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-741'
git switch 'main'
git merge --squash 'github-bot/gh-741'
git switch 'main'
git merge --ff-only 'github-bot/gh-741'
git switch 'main'
git merge 'github-bot/gh-741'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.