Shaders: lower v_mad_i64_i32; test the 64-bit integer vector operations against their definitions #635

Open
Gruzzberry wants to merge 1 commit from upstream-pr/635 into main
Gruzzberry commented 2026-11-25 03:40:31 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Gruzzberry on 2026-11-25T03:40:31Z.


Summary

v_mad_u64_u32 is lowered; its signed sibling v_mad_i64_i32 (a signed 32 x 32 multiply plus a 64-bit addend, into a 64-bit result) is not, so a program using it is refused as Unsupported { what: "v_mad_i64_i32" } and its pipelines are dropped. This lowers it as the same operation on sign-extended factors, and adds a test of the 64-bit integer vector operations (the three 64-bit shifts and both multiply-adds) against the definitions in the RDNA2 instruction set document.

What is in it

  • crates/victory-shader/src/emit/lower.rs: a "v_mad_i64_i32" arm next to "v_mad_u64_u32": sign-extend both factors to 64 bits, multiply, add the 64-bit addend, write the two result dwords. The carry out is not modelled: the lane-mask value of the instruction's carry destination is Val::Missing("the carry of a signed multiply-add"), so a program that reads it is refused as for any lane mask read as data, and one that ignores it (the usual address computation) translates.
  • crates/victory-shader/src/emit/int64_tests.rs (new, registered in emit/mod.rs): two tests, one-thread compute shaders run twice (low dword of the result, then the high one) on the hardware adapter and WARP:
    • shifts_of_64_bits_use_the_low_six_bits_of_the_count: v_lshlrev_b64, v_lshrrev_b64, v_ashrrev_i64 with counts 0, 1, 31, 32, 33, 63, 64, 65 and 0xffffffc1 over 64 values built from the halves' sign and carry edges.
    • multiply_add_of_32_by_32_plus_64_matches_the_definition: v_mad_u64_u32 and v_mad_i64_i32 over eight values for each factor and four addends (0, 2^32-1, -1, and 2^63+1).
  • valu_tests.rs only gains pub(super) on five helpers the new module shares.

Before the lowering, multiply_add_of_32_by_32_plus_64_matches_the_definition stops at lower: Unsupported { offset: 36, what: "v_mad_i64_i32" }. With it, both operations and the three shifts agree with the definitions on WARP.

Does the title use it?

No: victory translate over the whole shader pack (26,148 programs, base 2119b0e) translates all of them and refuses none for this instruction. The change is coverage; the test is the main point. If you would rather have the test alone, drop the lower.rs hunk and the signed multiply-add half of the second test.

Tested

  • Machine: NVIDIA GeForce RTX 4070 12 GB, Intel i7-13700K, 64 GB, Windows 11 26200, Rust 1.98.1. Branch rebased on c96b4f2, one commit.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean. Without --all-features it fails on c96b4f2 itself (placed_filler_twins in victory-gpu/src/resource.rs is never used); this change adds no warning.
  • cargo xtask policy: 170 files ok.
  • cargo test --workspace --locked on the RTX 4070 (default adapter, run directly): victory-shader 214 passed, 2 failed (emit::rect::tests::the_rectangle_stage_is_a_geometry_shader and rectangles_are_drawn_whole, the PSV0 validator issue of #61); every other crate passes. c96b4f2 without this change: 212 passed, the same 2 failed.
  • VICTORY_WARP=1 cargo test --workspace --locked (every GPU test on WARP): victory-shader 210 passed, 6 failed. The same 6 fail on c96b4f2 (208 passed): the two emit::rect ones, and ds_min_max_f32_order_floats_and_return_the_old_value, v_permlane16_and_x16_read_the_lanes_their_selectors_pick, whole_wave_f64_sum_and_cvt_f32_f64 and a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is, which need a 32-lane device that VICTORY_WARP=1 takes away. No new failure.

Not tested

  • The carry out of v_mad_i64_i32 (not modelled; the RDNA2 document's wording for the signed form is not what I rely on).
  • 64-bit compares (open in #135) and the other 64-bit operations (v_add_co_u32 chains, f64).
  • AMD and Intel adapters.

AI use

Claude Code (Claude Sonnet 5.5) wrote the lowering and the tests and ran the checks above on my machine. The reference functions follow the RDNA2 instruction set document. Nothing is taken from the game.

🤖 Generated with Claude Code

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6596669502 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/635). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-11-25T03:40:31Z. --- ## Summary `v_mad_u64_u32` is lowered; its signed sibling `v_mad_i64_i32` (a signed 32 x 32 multiply plus a 64-bit addend, into a 64-bit result) is not, so a program using it is refused as `Unsupported { what: "v_mad_i64_i32" }` and its pipelines are dropped. This lowers it as the same operation on sign-extended factors, and adds a test of the 64-bit integer vector operations (the three 64-bit shifts and both multiply-adds) against the definitions in the RDNA2 instruction set document. ## What is in it - `crates/victory-shader/src/emit/lower.rs`: a `"v_mad_i64_i32"` arm next to `"v_mad_u64_u32"`: sign-extend both factors to 64 bits, multiply, add the 64-bit addend, write the two result dwords. The carry out is not modelled: the lane-mask value of the instruction's carry destination is `Val::Missing("the carry of a signed multiply-add")`, so a program that reads it is refused as for any lane mask read as data, and one that ignores it (the usual address computation) translates. - `crates/victory-shader/src/emit/int64_tests.rs` (new, registered in `emit/mod.rs`): two tests, one-thread compute shaders run twice (low dword of the result, then the high one) on the hardware adapter and WARP: - `shifts_of_64_bits_use_the_low_six_bits_of_the_count`: `v_lshlrev_b64`, `v_lshrrev_b64`, `v_ashrrev_i64` with counts 0, 1, 31, 32, 33, 63, 64, 65 and `0xffffffc1` over 64 values built from the halves' sign and carry edges. - `multiply_add_of_32_by_32_plus_64_matches_the_definition`: `v_mad_u64_u32` and `v_mad_i64_i32` over eight values for each factor and four addends (0, 2^32-1, -1, and 2^63+1). - `valu_tests.rs` only gains `pub(super)` on five helpers the new module shares. Before the lowering, `multiply_add_of_32_by_32_plus_64_matches_the_definition` stops at `lower: Unsupported { offset: 36, what: "v_mad_i64_i32" }`. With it, both operations and the three shifts agree with the definitions on WARP. ## Does the title use it? No: `victory translate` over the whole shader pack (26,148 programs, base `2119b0e`) translates all of them and refuses none for this instruction. The change is coverage; the test is the main point. If you would rather have the test alone, drop the `lower.rs` hunk and the signed multiply-add half of the second test. ## Tested - Machine: NVIDIA GeForce RTX 4070 12 GB, Intel i7-13700K, 64 GB, Windows 11 26200, Rust 1.98.1. Branch rebased on `c96b4f2`, one commit. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean. Without `--all-features` it fails on `c96b4f2` itself (`placed_filler_twins` in `victory-gpu/src/resource.rs` is never used); this change adds no warning. - `cargo xtask policy`: 170 files ok. - `cargo test --workspace --locked` on the RTX 4070 (default adapter, run directly): `victory-shader` 214 passed, 2 failed (`emit::rect::tests::the_rectangle_stage_is_a_geometry_shader` and `rectangles_are_drawn_whole`, the PSV0 validator issue of #61); every other crate passes. `c96b4f2` without this change: 212 passed, the same 2 failed. - `VICTORY_WARP=1 cargo test --workspace --locked` (every GPU test on WARP): `victory-shader` 210 passed, 6 failed. The same 6 fail on `c96b4f2` (208 passed): the two `emit::rect` ones, and `ds_min_max_f32_order_floats_and_return_the_old_value`, `v_permlane16_and_x16_read_the_lanes_their_selectors_pick`, `whole_wave_f64_sum_and_cvt_f32_f64` and `a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is`, which need a 32-lane device that `VICTORY_WARP=1` takes away. No new failure. ## Not tested - The carry out of `v_mad_i64_i32` (not modelled; the RDNA2 document's wording for the signed form is not what I rely on). - 64-bit compares (open in #135) and the other 64-bit operations (`v_add_co_u32` chains, f64). - AMD and Intel adapters. ## AI use Claude Code (Claude Sonnet 5.5) wrote the lowering and the tests and ran the checks above on my machine. The reference functions follow the RDNA2 instruction set document. Nothing is taken from the game. 🤖 Generated with [Claude Code](https://claude.com/claude-code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
HAL9000RELOADED commented 2026-11-25 13:06:05 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T13:00:13Z.


An AMD run of this PR's new tests. multiply_add_of_32_by_32_plus_64_matches_the_definition and shifts_of_64_bits_use_the_low_six_bits_of_the_count pass 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://github.com/fxceless/victory-fork/pull/637#issuecomment-7163143604

<!-- greyfinch-sync:fxceless/victory-fork:comment:7163153570 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/635#issuecomment-7163153570). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T13:00:13Z. --- An AMD run of this PR's new tests. `multiply_add_of_32_by_32_plus_64_matches_the_definition` and `shifts_of_64_bits_use_the_low_six_bits_of_the_count` pass 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://github.com/fxceless/victory-fork/pull/637#issuecomment-7163143604
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/635:upstream-pr/635'
git switch 'upstream-pr/635'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/635'
git switch 'upstream-pr/635'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/635'
git switch 'upstream-pr/635'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/635'
git switch 'main'
git merge --squash 'upstream-pr/635'
git switch 'main'
git merge --ff-only 'upstream-pr/635'
git switch 'main'
git merge 'upstream-pr/635'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!635
No description provided.