Shaders: lower s_brev_b64; test the scalar 64-bit operations against their definitions #639

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

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


Summary

s_brev_b64 has no lowering, so a program using it is refused as Unsupported { what: "s_brev_b64" } and its pipelines are dropped, while s_brev_b32 and the rest of the 64-bit scalar logic are lowered. Bit i of the pair goes to bit 63 - i: each half is reversed and the halves swap. This adds that, and a test that runs the 64-bit scalar operations against the definitions in the RDNA2 instruction set document.

What is in it

  • crates/victory-shader/src/emit/lower.rs: a "s_brev_b64" arm in the 64-bit scalar block (about a dozen lines): unary.i32 bit reverse of each half, written to the other half. It sets no SCC, as the document says.
  • crates/victory-shader/src/emit/valu_tests.rs: scalar_64_bit_operations_match_the_rdna2_definitions runs s_and/or/xor/andn2/orn2/nand/nor/xnor_b64, s_not_b64, s_brev_b64, the three shifts (s_lshl_b64, s_lshr_b64, s_ashr_i64: the count is the low six bits of the second operand, with counts from 0 to 65 and 0xffffffc1) and s_bcnt1_i32_b64 / s_ff1_i32_b64 on the pairs s[0:1] and s[2:3] as one-thread compute shaders over 180 cases built from the sign and carry edges of the halves, comparing both result dwords with the definition in Rust, on the hardware adapter and WARP. Everything but s_brev_b64 agreed on the first run.

Before the lowering the test stops at lower: Unsupported { offset: 36, what: "s_brev_b64" }; with it all fifteen operations agree on WARP.

Does the title use it?

No: victory translate over the whole shader pack (26,148 programs, base 2119b0e) refuses none for this instruction. The change is coverage, the test is the point. If you would rather have the test alone, drop the lower.rs hunk and the s_brev_b64 row.

Left out on purpose because open PRs lower them: s_bcnt0_i32_b64 (#171), s_flbit_i32_b64 and s_ff0_i32_b64 (#233).

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: 169 files ok.
  • cargo test --workspace --locked on the RTX 4070 (default adapter, run directly): victory-shader 213 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 209 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

  • Wave64 mask forms of these operations (the tests use data in SGPRs, not lane masks; EXEC/VCC use goes through the mask paths).
  • s_bfe_u64, s_bfe_i64, s_bfm_b64, s_bitset*_b64 and the 64-bit compares.

AI use

Claude Code (Claude Sonnet 5.5) wrote the lowering and the test 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:6596673214 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/639). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-11-25T03:40:49Z. --- ## Summary `s_brev_b64` has no lowering, so a program using it is refused as `Unsupported { what: "s_brev_b64" }` and its pipelines are dropped, while `s_brev_b32` and the rest of the 64-bit scalar logic are lowered. Bit i of the pair goes to bit 63 - i: each half is reversed and the halves swap. This adds that, and a test that runs the 64-bit scalar operations against the definitions in the RDNA2 instruction set document. ## What is in it - `crates/victory-shader/src/emit/lower.rs`: a `"s_brev_b64"` arm in the 64-bit scalar block (about a dozen lines): `unary.i32` bit reverse of each half, written to the other half. It sets no SCC, as the document says. - `crates/victory-shader/src/emit/valu_tests.rs`: `scalar_64_bit_operations_match_the_rdna2_definitions` runs `s_and/or/xor/andn2/orn2/nand/nor/xnor_b64`, `s_not_b64`, `s_brev_b64`, the three shifts (`s_lshl_b64`, `s_lshr_b64`, `s_ashr_i64`: the count is the low six bits of the second operand, with counts from 0 to 65 and `0xffffffc1`) and `s_bcnt1_i32_b64` / `s_ff1_i32_b64` on the pairs `s[0:1]` and `s[2:3]` as one-thread compute shaders over 180 cases built from the sign and carry edges of the halves, comparing both result dwords with the definition in Rust, on the hardware adapter and WARP. Everything but `s_brev_b64` agreed on the first run. Before the lowering the test stops at `lower: Unsupported { offset: 36, what: "s_brev_b64" }`; with it all fifteen operations agree on WARP. ## Does the title use it? No: `victory translate` over the whole shader pack (26,148 programs, base `2119b0e`) refuses none for this instruction. The change is coverage, the test is the point. If you would rather have the test alone, drop the `lower.rs` hunk and the `s_brev_b64` row. Left out on purpose because open PRs lower them: `s_bcnt0_i32_b64` (#171), `s_flbit_i32_b64` and `s_ff0_i32_b64` (#233). ## 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`: 169 files ok. - `cargo test --workspace --locked` on the RTX 4070 (default adapter, run directly): `victory-shader` 213 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` 209 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 - Wave64 mask forms of these operations (the tests use data in SGPRs, not lane masks; `EXEC`/`VCC` use goes through the mask paths). - `s_bfe_u64`, `s_bfe_i64`, `s_bfm_b64`, `s_bitset*_b64` and the 64-bit compares. ## AI use Claude Code (Claude Sonnet 5.5) wrote the lowering and the test 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:06 +00:00 (Migrated from github.com)

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


An AMD run of this PR's new tests. scalar_64_bit_operations_match_the_rdna2_definitions passes 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:7163155279 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/639#issuecomment-7163155279). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T13:00:17Z. --- An AMD run of this PR's new tests. `scalar_64_bit_operations_match_the_rdna2_definitions` passes 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/639:upstream-pr/639'
git switch 'upstream-pr/639'

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/639'
git switch 'upstream-pr/639'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/639'
git switch 'upstream-pr/639'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/639'
git switch 'main'
git merge --squash 'upstream-pr/639'
git switch 'main'
git merge --ff-only 'upstream-pr/639'
git switch 'main'
git merge 'upstream-pr/639'
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!639
No description provided.