Skip to content

Shaders: lower six integer operations; test the integer vector and scalar ops and the scalar compares against their definitions - #636

Open
Gruzzberry wants to merge 1 commit into
fxceless:mainfrom
Gruzzberry:gz/salu-integer-ops
Open

Gruzzberry wants to merge 1 commit into
fxceless:mainfrom
Gruzzberry:gz/salu-integer-ops

Conversation

@Gruzzberry

Copy link
Copy Markdown

Summary

The integer vector and scalar operations had no test that compares them with what the RDNA2 instruction set document defines, so a wrong shift mask, a swapped operand or a missing operation would only show up as a wrong picture. This adds three table-driven tests that run each operation as a one-thread compute shader over edge values and compare the result with the definition written out in Rust. Everything that was lowered agreed with its definition; six operations were not lowered at all, so a program using one was refused as Unsupported and its pipelines dropped. They are lowered here, since a table row for each is what the tests need.

What is in it

One commit.

  • lower.rs: v_mul_hi_u32_u24 and v_mul_hi_i32_i24 (bits 47:32 of the product of the operands' low 24 bits, sign-extended from bit 23 for the signed one) through the existing mul_hi on the widened operands; s_absdiff_i32 (an SCC writer already in ir.rs) and s_pack_ll_b32_b16, s_pack_lh_b32_b16, s_pack_hh_b32_b16.
  • valu_tests.rs:
    • integer_operations_match_the_rdna2_definitions: 38 vector operations (bfi, bfm, bcnt, bfrev, not, xnor, xor3, or3, and_or, xad, add3, lshl_add, add_lshl, lshl_or, the three reversed shifts, mul_lo, mul_hi in 32 and 24 bits, mul_u32_u24/i32_i24, mad_u32_u24/i32_i24, min3/max3/med3 signed and unsigned, v_perm_b32 with every selector class, alignbit, alignbyte, ffbl, ffbh unsigned and signed) over 128 cases built from edges (shifts around 0, 31 and 32, the 24-bit and sign boundaries, runs of ones). mbcnt_of_the_first_lane_counts_no_lane_below_it covers v_mbcnt_lo/hi_u32_b32 on lane 0; it needs a 32-lane wave, so it runs on the hardware adapter only (and skips under VICTORY_WARP=1).
    • scalar_integer_operations_match_the_rdna2_definitions: 40 SOP1/SOP2 operations over 96 cases.
    • scalar_compares_set_scc_as_the_rdna2_document_defines: s_cmp_{eq,lg,gt,ge,lt,le}_{i32,u32} and s_bitcmp0/1_b32 over 121 pairs, and s_cmpk_* against five immediates (sign-extended for the signed forms, zero-extended for the unsigned ones), SCC read back through s_cselect_b32.

Before the lowering, the vector test stops at Unsupported { what: "v_mul_hi_u32_u24" } and the scalar one at s_absdiff_i32. With it every operation in the tables agrees with its definition.

Does the title use them?

No. victory translate over the whole shader pack (26,148 programs, base 2119b0e) translates all of them, and none of the programs the later stages refuse is refused for one of these operations. So the lowering changes are coverage, not a fix for something the title hits; the tests are the point of the PR. If you would rather have only the tests, drop the lower.rs hunks and the table rows for the six operations.

Overlap to know about: s_sext_i32_i8/i16 (#182), s_bcnt0_i32_b32 (#171) and s_ff0_i32_b32 (#233) are left out on purpose, since open PRs lower them. #278 adds hardware tests for integer min3/max3/med3 and s_bfe_u32, which this table also covers (together with every other operation in it).

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 216 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 212 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 whatever Host::new(false) gives and WARP, so they run there too, but I did not.
  • Wave64 forms of the scalar operations (the tests use one 32-lane wave).
  • The 64-bit scalar and vector operations (s_*_b64, v_*_i64).

AI use

Claude Code (Claude Sonnet 5.5) read the code, wrote the tests and the lowering changes, and ran the checks above on my machine. The reference functions follow the RDNA2 instruction set document's definitions; the opcode numbers come from the repository's own gfx10/opcodes.rs. Nothing is taken from the game.

🤖 Generated with Claude Code

🤖 Generated with Claude Code

…alar ops and the scalar compares against their definitions

The integer vector and scalar operations had no test that compares them with
the RDNA2 instruction set document. Three tests run each operation as a
one-thread compute shader over edge values and compare the result with the
definition written out in Rust, on the hardware adapter and WARP:

 - 38 integer vector operations (bit fields, funnel shifts, 24-bit and high
   multiplies, three-input adds and logic, min3/max3/med3, v_perm_b32 with
   every selector class, find-first-bit) over 128 cases, and v_mbcnt of lane
   0 on the hardware adapter alone;
 - 40 scalar SOP1/SOP2 operations over 96 cases;
 - the scalar compares: s_cmp_* i32/u32, s_bitcmp0/1 and the s_cmpk_* forms
   against five immediates, with SCC read back through s_cselect_b32.

Everything that was lowered agreed with its definition. Six operations were
not lowered at all, so a program using one was refused as "unsupported" and
its pipelines dropped; they are lowered here: v_mul_hi_u32_u24 and
v_mul_hi_i32_i24 (through the 64-bit product of the widened operands),
s_absdiff_i32 and s_pack_ll/lh/hh_b32_b16. The title's shader pack has no
program using them (a translate run over all 26148 programs refuses none for
these), so the lowerings are coverage. The sign extensions and the zero-bit
counts are left to the open PRs that lower them.

Assisted-by: Claude Code (Claude Sonnet 5.5)
oceansde012 pushed a commit to oceansde012/victory-gta6 that referenced this pull request Nov 25, 2026
HLE: implement the RPC runtime's GUID calls
(cherry picked from commit ff15f98)
@HAL9000RELOADED

Copy link
Copy Markdown

An AMD run of this PR's new tests. integer_operations_match_the_rdna2_definitions, scalar_integer_operations_match_the_rdna2_definitions, scalar_compares_set_scc_as_the_rdna2_document_defines and mbcnt_of_the_first_lane_counts_no_lane_below_it 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: #637 (comment)

PiloteCode pushed a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
HLE: implement the RPC runtime's GUID calls
HAL9000RELOADED added a commit to HAL9000RELOADED/victory-fork that referenced this pull request Nov 26, 2026
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