Shader tests: vector compares, carries, conversions and float arithmetic against the RDNA2 definitions #637

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

@⁠Gruzzberry on GitHub · 2026-11-25 03:40 UTC · original
Gruzzberry:gz/compare-ops-isa → main · +574 −5 · 3 files · 1 commits · open

Summary

Only v_cmp_lg on a NaN and v_cmp_class_f16 had a test that compares the lowered instruction with the definition in the RDNA2 instruction set document. The other float conditions (ordered and negated, with NaNs and signed zeros), the integer compares, v_cmp_class_f32, the carry-in/carry-out adds and subtracts and the float-to-integer conversions had none: a swapped ordered/unordered pair or a carry that is off by one would show only as a wrong picture. This adds a new test module that pins each of them to its definition, written out in Rust, over edge values. Every operation agrees with its definition, so there is no behaviour change; the PR is tests only.

What is in it

crates/victory-shader/src/emit/isa_tests.rs (new, registered in emit/mod.rs), seven tests. Each instruction is one one-thread compute shader (the instruction, then v_cndmask_b32 where the result is a mask bit), run on the hardware adapter and WARP:

  • float_compares_match_the_rdna2_conditions: the fourteen float conditions of v_cmp_*_f32 (lt eq le gt lg ge o u nge nlg ngt nle neq nlt) over all pairs of 16 operands: zeros of both signs, ±1, 0.5, 2, ±1e10, ±inf, a quiet, a negative quiet and a signalling NaN, the largest finite and the smallest normal.
  • integer_compares_match_the_rdna2_conditions: lt eq le gt ne ge for i32 and u32 over all pairs of nine operands around the sign and wrap boundaries.
  • class_f32_tests_the_ten_classes: v_cmp_class_f32 on 15 operands covering every class (signalling and quiet NaN of both signs, ±inf, ±normal, ±denormal, ±0) against each single-class mask and some combined ones.
  • carry_arithmetic_matches_the_rdna2_definitions: v_add_co_u32, v_sub_co_u32, v_subrev_co_u32 and the three _ci forms with a carry in (the carry-in mask comes from a v_cmp_ne_u32, because the translator only accepts carries it can track): the result and the carry or borrow out, over all pairs of nine operands and both carry-ins.
  • conversions_and_rounding_match_the_rdna2_definitions: v_cvt_u32_f32, v_cvt_i32_f32, v_cvt_flr_i32_f32, v_cvt_rpi_i32_f32 (NaN to 0, saturation at the 32-bit limits), v_trunc/ceil/rndne/floor_f32, v_cvt_f32_i32/u32 (round to nearest even) and v_cvt_f32_ubyte0-3.
  • float_arithmetic_with_nan_and_infinity_matches_the_rdna2_definitions: v_min_f32/v_max_f32 (a NaN operand gives the other one) and v_add/sub/subrev/mul_f32 over infinities and NaNs.
  • packed_integer_operations_match_the_rdna2_definitions: the fourteen packed 16-bit integer operations (v_pk_mad/mul_lo/add/sub/min/max in both signs, the three shifts) over 100 cases with different halves in every source, each with four op_sel/op_sel_hi combinations (whole sources, swapped halves, low result from the high halves and the reverse).

valu_tests.rs only gains pub(super) on five helpers (vop3, sgpr, vgpr, build_valu_cs, run_cases) that the new module shares.

Overlap to know about: #278 adds a hardware test of v_cmp_class_f32 (and integer min3/max3/med3); class_f32_tests_the_ten_classes here covers the same instruction over every class and mask, in the same harness, so one of the two can be trimmed when both are ready.

Left out on purpose: v_cmp_f_f32 and v_cmp_tru_f32, which lower as a real compare of the operands and remove the WARP device (#136, #152, #160); v_fma_f32 (fused on AMD and not on WARP, #136); the order of -0 and +0 in min/max.

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 219 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 215 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

  • AMD and Intel adapters (the tests run on any adapter Host::new(false) returns).
  • 64-bit compares and the f16 forms (v_cmp_*_f16 beyond the class test already there).

AI use

Claude Code (Claude Sonnet 5.5) wrote the tests and ran the checks above on my machine. The reference functions follow the RDNA2 instruction set document's definitions; opcode numbers come from the repository's gfx10/opcodes.rs. 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/637) `Gruzzberry:gz/compare-ops-isa` → `main` · +574 −5 · 3 files · 1 commits · open ## Summary Only `v_cmp_lg` on a NaN and `v_cmp_class_f16` had a test that compares the lowered instruction with the definition in the RDNA2 instruction set document. The other float conditions (ordered and negated, with NaNs and signed zeros), the integer compares, `v_cmp_class_f32`, the carry-in/carry-out adds and subtracts and the float-to-integer conversions had none: a swapped ordered/unordered pair or a carry that is off by one would show only as a wrong picture. This adds a new test module that pins each of them to its definition, written out in Rust, over edge values. Every operation agrees with its definition, so there is no behaviour change; the PR is tests only. ## What is in it `crates/victory-shader/src/emit/isa_tests.rs` (new, registered in `emit/mod.rs`), seven tests. Each instruction is one one-thread compute shader (the instruction, then `v_cndmask_b32` where the result is a mask bit), run on the hardware adapter and WARP: - `float_compares_match_the_rdna2_conditions`: the fourteen float conditions of `v_cmp_*_f32` (`lt eq le gt lg ge o u nge nlg ngt nle neq nlt`) over all pairs of 16 operands: zeros of both signs, ±1, 0.5, 2, ±1e10, ±inf, a quiet, a negative quiet and a signalling NaN, the largest finite and the smallest normal. - `integer_compares_match_the_rdna2_conditions`: `lt eq le gt ne ge` for i32 and u32 over all pairs of nine operands around the sign and wrap boundaries. - `class_f32_tests_the_ten_classes`: `v_cmp_class_f32` on 15 operands covering every class (signalling and quiet NaN of both signs, ±inf, ±normal, ±denormal, ±0) against each single-class mask and some combined ones. - `carry_arithmetic_matches_the_rdna2_definitions`: `v_add_co_u32`, `v_sub_co_u32`, `v_subrev_co_u32` and the three `_ci` forms with a carry in (the carry-in mask comes from a `v_cmp_ne_u32`, because the translator only accepts carries it can track): the result and the carry or borrow out, over all pairs of nine operands and both carry-ins. - `conversions_and_rounding_match_the_rdna2_definitions`: `v_cvt_u32_f32`, `v_cvt_i32_f32`, `v_cvt_flr_i32_f32`, `v_cvt_rpi_i32_f32` (NaN to 0, saturation at the 32-bit limits), `v_trunc/ceil/rndne/floor_f32`, `v_cvt_f32_i32/u32` (round to nearest even) and `v_cvt_f32_ubyte0-3`. - `float_arithmetic_with_nan_and_infinity_matches_the_rdna2_definitions`: `v_min_f32`/`v_max_f32` (a NaN operand gives the other one) and `v_add/sub/subrev/mul_f32` over infinities and NaNs. - `packed_integer_operations_match_the_rdna2_definitions`: the fourteen packed 16-bit integer operations (`v_pk_mad/mul_lo/add/sub/min/max` in both signs, the three shifts) over 100 cases with different halves in every source, each with four `op_sel`/`op_sel_hi` combinations (whole sources, swapped halves, low result from the high halves and the reverse). `valu_tests.rs` only gains `pub(super)` on five helpers (`vop3`, `sgpr`, `vgpr`, `build_valu_cs`, `run_cases`) that the new module shares. Overlap to know about: #278 adds a hardware test of `v_cmp_class_f32` (and integer `min3`/`max3`/`med3`); `class_f32_tests_the_ten_classes` here covers the same instruction over every class and mask, in the same harness, so one of the two can be trimmed when both are ready. Left out on purpose: `v_cmp_f_f32` and `v_cmp_tru_f32`, which lower as a real compare of the operands and remove the WARP device (#136, #152, #160); `v_fma_f32` (fused on AMD and not on WARP, #136); the order of `-0` and `+0` in min/max. ## 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` 219 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` 215 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 - AMD and Intel adapters (the tests run on any adapter `Host::new(false)` returns). - 64-bit compares and the f16 forms (`v_cmp_*_f16` beyond the class test already there). ## AI use Claude Code (Claude Sonnet 5.5) wrote the tests and ran the checks above on my machine. The reference functions follow the RDNA2 instruction set document's definitions; opcode numbers come from the repository's `gfx10/opcodes.rs`. Nothing is taken from the game. 🤖 Generated with [Claude Code](https://claude.com/claude-code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The f32 compare conditions had one direct test (v_cmp_lg on NaN) and
v_cmp_class_f16 had its own; the other conditions, the integer compares,
v_cmp_class_f32, the carry forms and the float-to-integer conversions had
none. These tests pin them to the instruction set document's definitions:
one one-thread compute shader per instruction over every pair (or each) of a
set of edge values, on the hardware adapter and WARP.

 - the fourteen float conditions of v_cmp_*_f32 (lt, eq, le, gt, lg, ge, o,
   u and the negated forms) over 16 operands: zeros of both signs, +-1,
   +-inf, a quiet, a negative quiet and a signalling NaN, the finite and
   normal limits;
 - the signed and unsigned integer conditions over nine operands around the
   sign and wrap boundaries;
 - v_cmp_class_f32 on every operand class (signalling and quiet NaN,
   +-inf, +-normal, +-denormal, +-0) against single-class and combined masks;
 - v_add_co_u32, v_sub_co_u32, v_subrev_co_u32 and the three _ci forms with a
   carry in: the result and the carry or borrow out;
 - v_cvt_u32_f32, v_cvt_i32_f32, v_cvt_flr_i32_f32, v_cvt_rpi_i32_f32 (NaN to
   0, saturation at the 32-bit limits), v_trunc/ceil/rndne/floor_f32,
   v_cvt_f32_i32/u32 (round to nearest even) and v_cvt_f32_ubyte0-3;
 - v_min_f32, v_max_f32 (a NaN gives the other operand), v_add/sub/subrev/
   mul_f32 over infinities and NaNs;
 - the fourteen packed 16-bit integer operations (v_pk_add/sub/mul_lo/mad/
   min/max in both signs, the three shifts) with four op_sel/op_sel_hi
   selector combinations, so both halves of every source are used in both
   result halves.

All agree with the definitions; no behaviour changes. v_cmp_f_f32 and
v_cmp_tru_f32 are left out on purpose (they remove the WARP device, see
#136). valu_tests.rs only gains pub(super) on the helpers the new module
shares.

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

@⁠HAL9000RELOADED on GitHub · 2026-11-25 12:59 UTC · original

One AMD run of the new GPU tests of nine open shader PRs: this one and #635, #636, #638, #639, #658, #726, #741, #808. Until now those tests had run only on NVIDIA, on WARP or in CI without a GPU. The table is kept here, and each of the other eight links to it, rather than repeating it nine times.

Setup

  • Machine: Radeon RX 7900 XTX (RDNA3, waves of 32 to 64 lanes), Adrenalin 32.0.32015.7029, i7-13700KF, Windows 10 Pro 22H2 (19045), Rust 1.98.1.
  • Agility SDK: Windows 10's in-box D3D12 stops at SM 6.5, so the tree carries #402 with its runtime (Agility SDK 1.620, SM 6.9).
  • Tools: DXIL validator and PC dxc from SDK 10.0.26100.
  • Tree: each PR merged onto main a253706 + #402 + the stack-headroom test fix from Marvisak/VIctory#742, then the whole workspace run with cargo test --workspace --no-fail-fast.
  • How the card was confirmed: WARP stays below SM 6.6 here and skips. These tests assert that at least one device ran, so the hardware device ran every case.
  • No game data used.
PR new tests on the RX 7900 XTX tested before on
#635 int64_tests::multiply_add_of_32_by_32_plus_64_matches_the_definition, …shifts_of_64_bits_use_the_low_six_bits_of_the_count pass RTX 4070, WARP
#636 integer_operations_match_the_rdna2_definitions, scalar_integer_operations_…, scalar_compares_set_scc_…, mbcnt_of_the_first_lane_counts_no_lane_below_it pass RTX 4070, WARP
#637 the seven isa_tests (float and integer compares, carries, conversions, float arithmetic, class_f32, packed integer) pass RTX 4070, WARP
#638 lds_atomics_match_the_rdna2_definitions (hardware only) pass RTX 4070
#639 scalar_64_bit_operations_match_the_rdna2_definitions pass RTX 4070, WARP
#658 v_cmp_f_and_t_64bit_match_rdna2 pass CI (no GPU); translation check on an RTX 5090
#726 v_shift_64_…, s_shift_64_matches_rdna2_without_int64, shifts_64_bit_need_no_int64 pass not stated
#741 mul_hi_matches_rdna2_without_int64, mul_hi_needs_no_int64 pass DXIL checks
#808 packed_dot_products_and_clamps_execute_cleanly (13 integer dot-product values) pass Intel Arc A770, WARP

Regressions: none in any of the nine. The only failures in these runs were:

  • victory-gpu's depth_bounds_pipeline_loads_and_filters_draws, which is Windows 10's in-box runtime (#850, #692);
  • warp_budget_saturates… (#849);
  • the occasional WARP access violation of the victory-gpu binary (#875).

All three are on main too.

Not covered: for #808, the two v_dot2_f32_f16 mismatches found in the emitted DXIL by an earlier review. Its test checks the integer dot products only.

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 12:59 UTC · [original](https://github.com/fxceless/victory-fork/pull/637#issuecomment-7163143604) One AMD run of the new GPU tests of nine open shader PRs: this one and #635, #636, #638, #639, #658, #726, #741, #808. Until now those tests had run only on NVIDIA, on WARP or in CI without a GPU. The table is kept here, and each of the other eight links to it, rather than repeating it nine times. **Setup** - **Machine:** Radeon RX 7900 XTX (RDNA3, waves of 32 to 64 lanes), Adrenalin 32.0.32015.7029, i7-13700KF, Windows 10 Pro 22H2 (19045), Rust 1.98.1. - **Agility SDK:** Windows 10's in-box D3D12 stops at SM 6.5, so the tree carries #402 with its runtime (Agility SDK 1.620, SM 6.9). - **Tools:** DXIL validator and PC dxc from SDK 10.0.26100. - **Tree:** each PR merged onto `main` `a253706` + #402 + the stack-headroom test fix from Marvisak/VIctory#742, then the whole workspace run with `cargo test --workspace --no-fail-fast`. - **How the card was confirmed:** WARP stays below SM 6.6 here and skips. These tests assert that at least one device ran, so the hardware device ran every case. - No game data used. | PR | new tests | on the RX 7900 XTX | tested before on | |---|---|---|---| | #635 | `int64_tests::multiply_add_of_32_by_32_plus_64_matches_the_definition`, `…shifts_of_64_bits_use_the_low_six_bits_of_the_count` | pass | RTX 4070, WARP | | #636 | `integer_operations_match_the_rdna2_definitions`, `scalar_integer_operations_…`, `scalar_compares_set_scc_…`, `mbcnt_of_the_first_lane_counts_no_lane_below_it` | pass | RTX 4070, WARP | | #637 | the seven `isa_tests` (float and integer compares, carries, conversions, float arithmetic, class_f32, packed integer) | pass | RTX 4070, WARP | | #638 | `lds_atomics_match_the_rdna2_definitions` (hardware only) | pass | RTX 4070 | | #639 | `scalar_64_bit_operations_match_the_rdna2_definitions` | pass | RTX 4070, WARP | | #658 | `v_cmp_f_and_t_64bit_match_rdna2` | pass | CI (no GPU); translation check on an RTX 5090 | | #726 | `v_shift_64_…`, `s_shift_64_matches_rdna2_without_int64`, `shifts_64_bit_need_no_int64` | pass | not stated | | #741 | `mul_hi_matches_rdna2_without_int64`, `mul_hi_needs_no_int64` | pass | DXIL checks | | #808 | `packed_dot_products_and_clamps_execute_cleanly` (13 integer dot-product values) | pass | Intel Arc A770, WARP | **Regressions:** none in any of the nine. The only failures in these runs were: - victory-gpu's `depth_bounds_pipeline_loads_and_filters_draws`, which is Windows 10's in-box runtime (#850, #692); - `warp_budget_saturates…` (#849); - the occasional WARP access violation of the `victory-gpu` binary (#875). All three are on `main` too. **Not covered:** for #808, the two `v_dot2_f32_f16` mismatches found in the emitted DXIL by an earlier review. Its test checks the integer dot products only.
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/637/head:github-bot/gh-637'
git switch 'github-bot/gh-637'

Merge

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