Skip to content

Recompiler tests: GPU checks for v_max3_u16, v_min3_u16 and v_med3_u16 - #738

Open
13hourstilliland wants to merge 1 commit into
xcl-dev:mainfrom
13hourstilliland:recomp-tests-max3-min3-med3-u16
Open

13hourstilliland wants to merge 1 commit into
xcl-dev:mainfrom
13hourstilliland:recomp-tests-max3-min3-med3-u16

Conversation

@13hourstilliland

Copy link
Copy Markdown
Contributor

Adds a GPU test for three RDNA2 instructions that emit.rs translates but no test runs: v_max3_u16, v_min3_u16 and v_med3_u16. Test only, no runtime change.

What is in it

  • gpu_valu_16_bit_unsigned_min3_max3_med3 in crates/xcl/src/gpu/recomp/tests.rs, after gpu_grouped_loads_bounds_and_inactive_lanes (away from the lines open PRs add to): one kernel with all 3 instructions, run as wave64 where the adapter has it and as wave32 everywhere (gpu_waves), 32 rounds of operands per lane: u16 edges (0, 1, 2, 0x00F1, 0x7FFE, 0x7FFF, 0x8000, 0x8001, 0xFFFE, 0xFFFF) and random halves, always with non-zero bits in each source's high half, each lane compared with the RDNA2 definition computed on the CPU (sort the three low halves). Only the low 16 bits of the result are compared: the AMD machine-readable RDNA2 spec (VOP3 OP_SEL field) says op_sel[3] = 0 zeroes the high half, while LLVM's GCNSubtarget::zeroesHigh16BitsOfDest says gfx10 preserves it, so the high half is left unchecked.
  • A failure lists the lane, instruction, operands, result and expected value, and counts the wrong results per instruction.
  • Checked that it catches bugs, on a local copy, measured on 91f9a5e (the base of this branch): with the reference changed (reference with v_med3_u16 returning the minimum: wave32, 984 wrong (V_MED3_U16: 984), no other instruction) the test fails; with max3 with the inner op as min, min3 with the inner op as max, and med3 with the third operand replaced by the second applied to emit.rs all at once it fails and names every instruction (wave32, 1940 wrong (V_MAX3_U16: 659, V_MIN3_U16: 635, V_MED3_U16: 646), 635 to 659 wrong per instruction). Those edits are not in the PR.
  • The other 16-bit integer instructions are covered by Tests: 16-bit integer VALU ops and the byte / half SADs on the GPU #638 and Tests: packed 16-bit integer VOP3P ops on the GPU, with swapped halves #657, which are not touched here.

Tested

  • NVIDIA GeForce RTX 3070 8 GB, driver 610.88; Intel Core i5-12600K; Windows 11 Home build 26200
  • Rust 1.100.0 stable-x86_64-pc-windows-gnu (MinGW linker), DXC 1.9.2609.5, debug build, commit 3f81263 (on main 91f9a5e)
  • cargo test --workspace --no-fail-fast -- --test-threads=4, run in the interactive desktop session: 693 passed, 0 failed, 41 ignored (lib: 653 passed, 0 failed, 21 ignored; e2e 3 of 3; gpu_valu_16_bit_unsigned_min3_max3_med3 ok). main 91f9a5e on the same machine: 692 passed, 0 failed, 41 ignored (lib: 652 passed, 0 failed, 21 ignored)
  • SKIPPED (no wave64 on this GPU): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

Not tested

  • The wave64 path: the RTX 3070 has 32-lane waves only, so the test ran as wave32. Not run on AMD.
  • The MSVC toolchain (stable-x86_64-pc-windows-msvc): built with the GNU toolchain only.
  • A release build.
  • A retail title: not needed for a test-only change (no crates/xcl/src runtime file changes).

AI use

  • Hermes Agent with Claude Opus 5.5: wrote the test, ran the tests and the mutation check on the hardware above, and wrote this description.

emit.rs translates v_max3_u16, v_min3_u16 and v_med3_u16, but no test
runs them.

gpu_valu_16_bit_unsigned_min3_max3_med3 assembles the three as VOP3 and
runs them in every wave size the GPU has (gpu_waves), 32 rounds of
operands per lane: u16 edges (0, 1, 2, 0x00F1, 0x7FFE, 0x7FFF, 0x8000,
0x8001, 0xFFFE, 0xFFFF) and random halves, always with non-zero bits in
each source's high half, against a plain Rust reference (sort the three
low halves). Only the low 16 bits of the result are compared: the AMD
machine-readable RDNA2 spec (VOP3 OP_SEL field) says op_sel[3] = 0 zeroes
the high half, while LLVM's GCNSubtarget::zeroesHigh16BitsOfDest says
gfx10 preserves it.

Measured on an RTX 3070 (wave32 only):
- reference with v_med3_u16 returning the minimum: the test fails with
  "wave32, 984 wrong (V_MED3_U16: 984)".
- one wrong emitter expression per instruction, all at once: "wave32,
  1940 wrong (V_MAX3_U16: 659, V_MIN3_U16: 635, V_MED3_U16: 646)".
- the real emitter: 1 passed.

Assisted-by: Hermes Agent (Claude Opus 5.5)
@13hourstilliland
13hourstilliland marked this pull request as ready for review November 24, 2026 04:22
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 3f812638b55811d96d57047b6629d699828aab15 on AMD RDNA4. I merged it onto current main 64b3f35 locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, mesh shaders), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 702 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 661 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_valu_16_bit_unsigned_min3_max3_med3 passes.

Review: med3 is the middle of the three sorted values and only D[15:0] is compared, as the ISA defines. Overlap: #638's description says #445 has the 16-bit min3 / max3 / med3; if #445 covers the unsigned forms too, one of the two is enough.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@futurepro62

Copy link
Copy Markdown

An NVIDIA run, since the report above is on RDNA4 (native wave64). Tested exact head 3f81263 (on its base 91f9a5e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 693 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new test ran and passed (not skipped): gpu::recomp::tests::gpu_valu_16_bit_unsigned_min3_max3_med3 ... ok.
    Not tested
  • AMD (covered above), a release build.

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@ItsMrDubey

Copy link
Copy Markdown

Test report for 3f812638b55811d96d57047b6629d699828aab15 (this PR's head)

Tested

  • NVIDIA GeForce RTX 4070 Ti 12 GB (Ada), driver 617.14; Intel Core i9-10900K, 32 GB RAM; Windows 11 Pro build 26300
  • Rust 1.88.0 (stable-x86_64-pc-windows-msvc), debug; DXC 1.9.2602.17 from Windows SDK 10.0.26100
cargo build --workspace
cargo test --workspace --no-fail-fast -- --test-threads=4

16 test binaries: 692 passed, 1 failed, 41 ignored. Same machine, main 64b3f3559: 700 passed, 1 failed, 41 ignored.

This PR's tests:

  • gpu::recomp::tests::gpu_valu_16_bit_unsigned_min3_max3_med3: ok

Failures:

16 test binaries instead of main's 17 because this branch predates tests/sparse_reinit.rs; nothing crashed.

SKIPPED (no wave64 on this GPU): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.

AI use: Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report from their output.

@luckyteagirl

Copy link
Copy Markdown

Native RDNA2 check of the untouched destination half

The PR description notes the ambiguity over the upper 16 bits. On the RX 6800M (gfx1031), native v_min3_u16, v_max3_u16 and v_med3_u16 all preserved the untouched destination half.

Tested

  • Windows 11 build 26200, Radeon RX 6800M, display driver 30.0.13002.13003, AMD OpenCL 3302.6 (PAL,LC).
  • The inline ISA kernel initialized each destination to 0xA55AC33C. It wrote the low half with default op_sel, and a separate instruction wrote the high half with op_sel:[0,0,0,1]. The three source low halves supplied the u16 operands. Their high halves were nonzero.
  • For all three instructions and 16 input triples, the written half matched a CPU-sorted reference. The untouched half retained 0xA55A for low writes and 0xC33C for high writes. Four work-items per case agreed.

For inputs 0x0000, 0xFFFF and 0x7FF8, the native median results were 0xA55A7FF8 for the default write and 0x7FF8C33C for the high-half write.

Not tested

The PR's translated GPU test and other GPU generations. This measures the three native RDNA2 instructions.

AI use

OpenAI Codex (GPT-6 family, exact model variant unavailable) wrote and ran the probe and drafted this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

off-goal Does not bear on the current goal (world loading); waits until it is reached

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants