Skip to content

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

Open
Gruzzberry wants to merge 1 commit into
fxceless:mainfrom
Gruzzberry:gz/compare-ops-isa
Open

Gruzzberry wants to merge 1 commit into
fxceless:mainfrom
Gruzzberry:gz/compare-ops-isa

Conversation

@Gruzzberry

Copy link
Copy Markdown

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 Shaders: write every PSV0 semantic name again, as DXC does (fixes #12) #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

…tic against the RDNA2 definitions

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
fxceless#136). valu_tests.rs only gains pub(super) on the helpers the new module
shares.

Assisted-by: Claude Code (Claude Sonnet 5.5)
@HAL9000RELOADED

Copy link
Copy Markdown

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

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:

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.

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.

2 participants