Skip to content

Shaders: lower mul_hi without INT64 - #741

Open
scoresby13 wants to merge 1 commit into
fxceless:mainfrom
scoresby13:shader/mul-hi-no-int64
Open

scoresby13 wants to merge 1 commit into
fxceless:mainfrom
scoresby13:shader/mul-hi-no-int64

Conversation

@scoresby13

Copy link
Copy Markdown

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.

@avt0m4t48

Copy link
Copy Markdown

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.

@HAL9000RELOADED

Copy link
Copy Markdown

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 (comment)

@scoresby13

Copy link
Copy Markdown
Author

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.

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.

3 participants