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

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

@⁠Gruzzberry on GitHub · 2026-11-25 03:40 UTC · original
Gruzzberry:gz/scalar64-isa → main · +93 −0 · 2 files · 1 commits · open

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

**@⁠Gruzzberry** on GitHub · 2026-11-25 03:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/639) `Gruzzberry:gz/scalar64-isa` → `main` · +93 −0 · 2 files · 1 commits · open ## 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)
s_brev_b64 had no lowering: a program using it was refused as "unsupported"
and its pipelines were dropped, while s_brev_b32 and the rest of the 64-bit
scalar logic were lowered. Bit i of the pair goes to bit 63 - i, so each half
is reversed and the halves swap. (The title's shader pack has no program with
the instruction: a translate run over all 26148 programs refuses none for it.)

The new test runs the 64-bit scalar operations on the pairs s[0:1] and
s[2:3] as one-thread compute shaders over the sign and carry edges of the
halves, comparing both result dwords with the RDNA2 definition in Rust:
and, or, xor, andn2, orn2, nand, nor, xnor, not, brev, the three shifts
(count in the low six bits of the second operand), and the 64-bit bit count
and find-first-set. All agree on WARP; before the lowering the test stops at
s_brev_b64.

Assisted-by: Claude Code (Claude Sonnet 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:55 +00:00
Author
Owner

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

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: #637

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 13:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/639#issuecomment-7163155279) 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://git.gtahub.st/github/fxceless--victory-fork/pulls/637
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/639/head:github-bot/gh-639'
git switch 'github-bot/gh-639'

Merge

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