Shaders: lower the 32-bit mul_hi forms to one UMul/IMul #3007

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

@⁠Ingenioeren on GitHub · 2026-11-26 03:17 UTC · original
Ingenioeren:perf/v-mul-hi-u32 → main · +129 −9 · 3 files · 1 commits · open

What

Lower the signed and unsigned 32-bit scalar and vector mul_hi forms 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 INT64 requirement for mul_hi. DXIL UMul and IMul return 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 intrinsics

Counts are total written DXIL instructions for a synthetic compute shader with one instance of the listed opcode. All six shaders set the SFI0 INT64 bit before the change and clear it after.

Opcode Intrinsic Before (origin/main) After
v_mul_hi_u32 UMul 21 18
v_mul_hi_i32 IMul 21 18
s_mul_hi_u32 UMul 21 18
s_mul_hi_i32 IMul 21 18
v_mul_hi_u32_u24 UMul 25 22
v_mul_hi_i32_i24 IMul 25 22

The 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

  • Recorded the reference high dwords on 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 cover i32::MIN multiplied by itself, -1, and i32::MAX, plus -1 * -1, -1 * 1, zero, mixed signs, and the 24-bit sign boundary.
  • cargo test -p victory-shader --locked --offline mul_hi -- --nocapture passed all 3 tests, including the per-opcode instruction limits and SFI0 checks.
  • cargo test -p victory-shader --locked --offline reported 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 in rectangles_get_their_fourth_corner and elements_sharing_a_row_keep_their_order.
  • Ran the remaining Cargo targets separately. The resource_tracking integration 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-targets passed. cargo run -p xtask --locked --offline -- policy --staged passed 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.

**@⁠Ingenioeren** on GitHub · 2026-11-26 03:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/3007) `Ingenioeren:perf/v-mul-hi-u32` → `main` · +129 −9 · 3 files · 1 commits · open ## What Lower the signed and unsigned 32-bit scalar and vector `mul_hi` forms 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 `INT64` requirement for `mul_hi`. DXIL `UMul` and `IMul` return 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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2148) · [DXIL multiply intrinsics](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#imul) Counts are total written DXIL instructions for a synthetic compute shader with one instance of the listed opcode. All six shaders set the SFI0 `INT64` bit before the change and clear it after. | Opcode | Intrinsic | Before (`origin/main`) | After | | --- | --- | ---: | ---: | | `v_mul_hi_u32` | `UMul` | 21 | 18 | | `v_mul_hi_i32` | `IMul` | 21 | 18 | | `s_mul_hi_u32` | `UMul` | 21 | 18 | | `s_mul_hi_i32` | `IMul` | 21 | 18 | | `v_mul_hi_u32_u24` | `UMul` | 25 | 22 | | `v_mul_hi_i32_i24` | `IMul` | 25 | 22 | The 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 - Recorded the reference high dwords on `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 cover `i32::MIN` multiplied by itself, `-1`, and `i32::MAX`, plus `-1 * -1`, `-1 * 1`, zero, mixed signs, and the 24-bit sign boundary. - `cargo test -p victory-shader --locked --offline mul_hi -- --nocapture` passed all 3 tests, including the per-opcode instruction limits and SFI0 checks. - `cargo test -p victory-shader --locked --offline` reported 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 in `rectangles_get_their_fourth_corner` and `elements_sharing_a_row_keep_their_order`. - Ran the remaining Cargo targets separately. The `resource_tracking` integration 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-targets` passed. `cargo run -p xtask --locked --offline -- policy --staged` passed 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.
Extract the high dword directly from DXIL UMul or IMul. The 24-bit forms use the same lowering after extending their operands.

Each synthetic shader emits three fewer DXIL instructions and clears its INT64 feature bit. The high dwords match main bit for bit on AMD hardware and WARP.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:19:58 +00:00
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 03:27 UTC · original

@⁠Ingenioeren I ran 42b4a868 on 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 63bcca43 and #2148 8c9e7eba merged 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) ^ seed 64 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.

64-step chain Main (64-bit multiply) #2148 (partial products) This PR (IMul/UMul)
v_mul_hi_u32 4.128 / 4.128 6.208 / 6.176 4.160 / 4.160
v_mul_hi_i32_i24 5.664 / 5.696 7.680 / 7.616 4.896 / 4.928

On 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.

**@⁠steven-seagull27** on GitHub · 2026-11-26 03:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3007#issuecomment-7181729656) @⁠Ingenioeren I ran `42b4a868` on 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 `63bcca43` and #2148 `8c9e7eba` merged 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) ^ seed` 64 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. | 64-step chain | Main (64-bit multiply) | #2148 (partial products) | This PR (IMul/UMul) | |---|---:|---:|---:| | `v_mul_hi_u32` | 4.128 / 4.128 | 6.208 / 6.176 | 4.160 / 4.160 | | `v_mul_hi_i32_i24` | 5.664 / 5.696 | 7.680 / 7.616 | 4.896 / 4.928 | On 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 06:16 UTC · original

Automated triage for the maintainers.

Lower::mul_hi in emit/lower.rs now emits a single dx.op.binaryWithTwoOuts.i32 call: opcode 41 (IMul) for signed and 42 (UMul) for unsigned. It takes element 0 of dx.types.twoi32, which is the high dword per the public DXIL spec. This removes the INT64 shader-feature requirement from all six *_mul_hi_* forms. I checked that Shader::op builds the matching (i32, i32, i32) -> %dx.types.twoi32 signature, and that the three callers, including the 24-bit forms, still pass correctly extended 32-bit operands. The expected values in the new valu_tests GPU cases are correct by hand, for example 0x80000000 * 0xFFFFFFFF gives high word 0x7FFFFFFF unsigned and 0 signed. The written_instructions helper 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: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 06:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/3007#issuecomment-7184267890) <!-- victory-triage v1 head=42b4a86846df9e45bfc3e44995df4ee99764e55d verdict=merge-candidate at=2026-11-26T06:18:00Z --> Automated triage for the maintainers. `Lower::mul_hi` in `emit/lower.rs` now emits a single `dx.op.binaryWithTwoOuts.i32` call: opcode 41 (`IMul`) for signed and 42 (`UMul`) for unsigned. It takes element 0 of `dx.types.twoi32`, which is the high dword per the public DXIL spec. This removes the `INT64` shader-feature requirement from all six `*_mul_hi_*` forms. I checked that `Shader::op` builds the matching `(i32, i32, i32) -> %dx.types.twoi32` signature, and that the three callers, including the 24-bit forms, still pass correctly extended 32-bit operands. The expected values in the new `valu_tests` GPU cases are correct by hand, for example `0x80000000 * 0xFFFFFFFF` gives high word `0x7FFFFFFF` unsigned and `0` signed. The `written_instructions` helper 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: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠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-2514 cleanly lowers mul_hi through dx.op.binaryWithTwoOuts.i32 (IMul = 41 / UMul = 42, extracting the high dword at element 0), eliminating the i64 widens/shifts and dropping the INT64 feature flag requirement across all six scalar/vector 32-bit and 24-bit forms.
  • bitcode.rs::written_instructions accurately matches Module::write's live-instruction and block layout, the added instruction-count and SFI0 INT64-absent assertions are well-scoped, and the resulting emit/lower.rs stays below the 512 KiB policy limit (522,175 B).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 03:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3007#pullrequestreview-6068143075) · **approved these changes** Code review on `42b4a868` (static source inspection; no runtime GPU/DXIL validation executed): - `crates/victory-shader/src/emit/lower.rs:2494-2514` cleanly lowers `mul_hi` through `dx.op.binaryWithTwoOuts.i32` (`IMul` = 41 / `UMul` = 42, extracting the high dword at element 0), eliminating the `i64` widens/shifts and dropping the `INT64` feature flag requirement across all six scalar/vector 32-bit and 24-bit forms. - `bitcode.rs::written_instructions` accurately matches `Module::write`'s live-instruction and block layout, the added instruction-count and `SFI0` `INT64`-absent assertions are well-scoped, and the resulting `emit/lower.rs` stays below the 512 KiB policy limit (`522,175 B`).
Author
Owner

@⁠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.

**@⁠kotekompotek** on GitHub · 2026-11-26 04:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/3007#pullrequestreview-6068634354) · **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.
Author
Owner

@⁠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):

  • Diff review: Lowering mul_hi directly to dx.op.binaryWithTwoOuts.i32 (IMul = 41 / UMul = 42, extracting word 0) eliminates i64 casts/shifts and avoids requiring the INT64 shader 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 (including mul_hi_has_a_short_lowering_without_int64 and GPU valu_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).

**@⁠Dukestar69** on GitHub · 2026-11-26 06:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3007#pullrequestreview-6069698598) · **approved these changes** Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + `dxil.dll`): - Diff review: Lowering `mul_hi` directly to `dx.op.binaryWithTwoOuts.i32` (`IMul` = 41 / `UMul` = 42, extracting word 0) eliminates `i64` casts/shifts and avoids requiring the `INT64` shader 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 (including `mul_hi_has_a_short_lowering_without_int64` and GPU `valu_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).
Author
Owner

@⁠Jackster on GitHub · 2026-11-26 19:01 UTC · original

AMD check at 42b4a868 (base main 63bcca43), 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).
  • Independent value sweep (local scratch, not part of this PR): 1,124 input pairs per form across all six forms, dispatched on both the 7900 XTX and WARP and checked against exact signed/unsigned 64-bit arithmetic — 6,744/6,744 correct on each backend, including signed negatives, 0x80000000/0xffffffff edges, and 24-bit forms fed with bits above bit 23. The sweep fails if the hardware backend did not run.
  • Emitted counts confirmed: 18/18/18/18/22/22 DXIL instructions for the six forms, and the SFI0 INT64 bit clear in all six containers.
  • cargo clippy -p victory-shader --all-targets clean; cargo xtask policy — 191 files ok. (The 2026-11-26 06:48 status row's lower.rs 525,583-byte flag is stale at this head; the file is 522,175 bytes.)
  • Full cargo test -p victory-shader --lib passed: 307 passed, 0 failed, 3 ignored, with the hardware backend available (includes two local-only test additions; none of the PR's tests failed).
  • The 23 hand-written expected values in the new valu_tests were re-derived independently and all match.

Synthetic shaders only, no game files. AI-assisted.

**@⁠Jackster** on GitHub · 2026-11-26 19:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/3007#issuecomment-7201113805) AMD check at `42b4a868` (base `main` `63bcca43`), 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). - Independent value sweep (local scratch, not part of this PR): 1,124 input pairs per form across all six forms, dispatched on both the 7900 XTX and WARP and checked against exact signed/unsigned 64-bit arithmetic — **6,744/6,744 correct on each backend**, including signed negatives, `0x80000000`/`0xffffffff` edges, and 24-bit forms fed with bits above bit 23. The sweep fails if the hardware backend did not run. - Emitted counts confirmed: 18/18/18/18/22/22 DXIL instructions for the six forms, and the SFI0 INT64 bit clear in all six containers. - `cargo clippy -p victory-shader --all-targets` clean; `cargo xtask policy` — 191 files ok. (The 2026-11-26 06:48 status row's `lower.rs` 525,583-byte flag is stale at this head; the file is 522,175 bytes.) - Full `cargo test -p victory-shader --lib` passed: 307 passed, 0 failed, 3 ignored, with the hardware backend available (includes two local-only test additions; none of the PR's tests failed). - The 23 hand-written expected values in the new `valu_tests` were re-derived independently and all match. Synthetic shaders only, no game files. AI-assisted.
This pull request can be merged automatically.
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/3007/head:github-bot/gh-3007'
git switch 'github-bot/gh-3007'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3007'
git switch 'github-bot/gh-3007'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3007'
git switch 'github-bot/gh-3007'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3007'
git switch 'main'
git merge --squash 'github-bot/gh-3007'
git switch 'main'
git merge --ff-only 'github-bot/gh-3007'
git switch 'main'
git merge 'github-bot/gh-3007'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3007
No description provided.