Shaders: v_min3/max3/med3 integer variants (i32, u32) have no synthetic hardware tests #800

Closed
opened 2026-11-26 04:13:59 +00:00 by github-bot · 4 comments
Owner

@⁠kss306 on GitHub · 2026-11-24 11:10 UTC · original

Six integer three-way operations are implemented in crates/victory-shader/src/emit/lower.rs but have no synthetic hardware tests in crates/victory-shader/src/emit/valu_tests.rs. Their float siblings (v_med3_f32, v_min3_f32, v_max3_f32) are tested; the integer variants are not.

Affected instructions

Instruction VOP3 opcode Tested sibling
v_min3_i32 0x152 v_min3_f32 (0x151) ✓
v_min3_u32 0x153 v_min3_f32 (0x151) ✓
v_max3_i32 0x155 v_max3_f32 (0x154) ✓
v_max3_u32 0x156 v_max3_f32 (0x154) ✓
v_med3_i32 0x158 v_med3_f32 (0x157) ✓
v_med3_u32 0x159 v_med3_f32 (0x157) ✓

Implementation evidence

lower.rs, valu_op() around line 4889:

"v_min3_i32" | "v_max3_i32" | "v_min3_u32" | "v_max3_u32" | "v_med3_i32"
| "v_med3_u32" => {
    let (a, b, d) = (s(self, 0)?, s(self, 1)?, s(self, 2)?);
    let signed = name.ends_with("i32");
    let (lt, gt) = if signed {
        (pred::SLT, pred::SGT)
    } else {
        (pred::IULT, pred::IUGT)
    };
    let pick = |l: &mut Self, p, x, y| {
        let t = l.s.m.cmp(c, p, x, y);
        l.s.m.select(c, t, x, y)
    };
    match &name[2..6] {
        "min3" => { let t = pick(self, lt, a, b); pick(self, lt, t, d) }
        "max3" => { let t = pick(self, gt, a, b); pick(self, gt, t, d) }
        _ => {  // med3
            let lo = pick(self, lt, a, b);
            let hi = pick(self, gt, a, b);
            let t  = pick(self, lt, hi, d);
            pick(self, gt, lo, t)
        }
    }
}

The signed/unsigned predicate switch (SLT/SGT vs IULT/IUGT) is the only difference from the float path and is exercised by no test.

Missing test

valu_tests.rs contains fn v_med3_f32_matches_rdna2_with_nan() (line 262) and fn v_med3_f16_matches_rdna2_with_nan() (line 335) for the float variants. No function in the file references opcodes 0x152–0x159.

Suggested test

Add fn v_med3_min3_max3_integer_matches_rdna2() to valu_tests.rs:

#[test]
fn v_med3_min3_max3_integer_matches_rdna2() {
    // Build one shader per instruction.
    let make = |op: u32| build_valu_cs(&vop3(op, 0, vgpr(1), vgpr(2), vgpr(3)));

    let min3_i = make(0x152); // v_min3_i32
    let min3_u = make(0x153); // v_min3_u32
    let max3_i = make(0x155); // v_max3_i32
    let max3_u = make(0x156); // v_max3_u32
    let med3_i = make(0x158); // v_med3_i32
    let med3_u = make(0x159); // v_med3_u32

    // (a, b, c, min_i32, max_i32, med_i32, min_u32, max_u32, med_u32)
    let cases: &[([u32; 4], u32, u32, u32, u32, u32, u32)] = &[
        // Plain ascending order
        ([1, 2, 3, 0], 1, 3, 2, 1, 3, 2),
        // Reversed
        ([3, 2, 1, 0], 1, 3, 2, 1, 3, 2),
        // All equal
        ([7, 7, 7, 0], 7, 7, 7, 7, 7, 7),
        // Two equal (low)
        ([1, 1, 5, 0], 1, 5, 1, 1, 5, 1),
        // Two equal (high)
        ([5, 9, 9, 0], 5, 9, 9, 5, 9, 9),
        // Signed: negative values
        ([((-3i32) as u32), ((-1i32) as u32), 2, 0],
            (-3i32) as u32, 2, (-1i32) as u32,
            2, ((-1i32) as u32), ((-3i32) as u32)), // unsigned: -3=0xFFFFFFFD is largest
        // Signed extremes
        ([0x8000_0000, 0x7FFF_FFFF, 0, 0],
            0x8000_0000, 0x7FFF_FFFF, 0,
            0, 0x8000_0000 /*UINT_MAX-1*/ , 0x7FFF_FFFF),
    ];

    let inputs: Vec<[u32; 4]> = cases.iter().map(|c| c.0).collect();

    let check = |name: &str, shader: &_, expected: fn(&([u32;4], u32, u32, u32, u32, u32, u32)) -> u32| {
        run_cases(shader, &inputs, |backend, i, inp, got| {
            let want = expected(&cases[i]);
            assert_eq!(got, want, "{backend}: {name}({:#010x}, {:#010x}, {:#010x}) = {got:#010x}, want {want:#010x}", inp[0], inp[1], inp[2]);
        });
    };

    check("v_min3_i32", &min3_i, |c| c.1);
    check("v_max3_i32", &max3_i, |c| c.2);
    check("v_med3_i32", &med3_i, |c| c.3);
    check("v_min3_u32", &min3_u, |c| c.4);
    check("v_max3_u32", &max3_u, |c| c.5);
    check("v_med3_u32", &med3_u, |c| c.6);
}

No game data needed; the test skips when no SM 6.6 device is available and runs on WARP.

AI-assisted: found with Kiro (Claude) and independently confirmed by five separate analysis passes without cross-contamination; no hardware run, no game data.

**@⁠kss306** on GitHub · 2026-11-24 11:10 UTC · [original](https://github.com/Marvisak/VIctory/issues/800) Six integer three-way operations are implemented in `crates/victory-shader/src/emit/lower.rs` but have no synthetic hardware tests in `crates/victory-shader/src/emit/valu_tests.rs`. Their float siblings (`v_med3_f32`, `v_min3_f32`, `v_max3_f32`) are tested; the integer variants are not. ## Affected instructions | Instruction | VOP3 opcode | Tested sibling | |---|---|---| | `v_min3_i32` | 0x152 | `v_min3_f32` (0x151) ✓ | | `v_min3_u32` | 0x153 | `v_min3_f32` (0x151) ✓ | | `v_max3_i32` | 0x155 | `v_max3_f32` (0x154) ✓ | | `v_max3_u32` | 0x156 | `v_max3_f32` (0x154) ✓ | | `v_med3_i32` | 0x158 | `v_med3_f32` (0x157) ✓ | | `v_med3_u32` | 0x159 | `v_med3_f32` (0x157) ✓ | ## Implementation evidence `lower.rs`, `valu_op()` around line 4889: ```rust "v_min3_i32" | "v_max3_i32" | "v_min3_u32" | "v_max3_u32" | "v_med3_i32" | "v_med3_u32" => { let (a, b, d) = (s(self, 0)?, s(self, 1)?, s(self, 2)?); let signed = name.ends_with("i32"); let (lt, gt) = if signed { (pred::SLT, pred::SGT) } else { (pred::IULT, pred::IUGT) }; let pick = |l: &mut Self, p, x, y| { let t = l.s.m.cmp(c, p, x, y); l.s.m.select(c, t, x, y) }; match &name[2..6] { "min3" => { let t = pick(self, lt, a, b); pick(self, lt, t, d) } "max3" => { let t = pick(self, gt, a, b); pick(self, gt, t, d) } _ => { // med3 let lo = pick(self, lt, a, b); let hi = pick(self, gt, a, b); let t = pick(self, lt, hi, d); pick(self, gt, lo, t) } } } ``` The signed/unsigned predicate switch (`SLT`/`SGT` vs `IULT`/`IUGT`) is the only difference from the float path and is exercised by no test. ## Missing test `valu_tests.rs` contains `fn v_med3_f32_matches_rdna2_with_nan()` (line 262) and `fn v_med3_f16_matches_rdna2_with_nan()` (line 335) for the float variants. No function in the file references opcodes `0x152`–`0x159`. ## Suggested test Add `fn v_med3_min3_max3_integer_matches_rdna2()` to `valu_tests.rs`: ```rust #[test] fn v_med3_min3_max3_integer_matches_rdna2() { // Build one shader per instruction. let make = |op: u32| build_valu_cs(&vop3(op, 0, vgpr(1), vgpr(2), vgpr(3))); let min3_i = make(0x152); // v_min3_i32 let min3_u = make(0x153); // v_min3_u32 let max3_i = make(0x155); // v_max3_i32 let max3_u = make(0x156); // v_max3_u32 let med3_i = make(0x158); // v_med3_i32 let med3_u = make(0x159); // v_med3_u32 // (a, b, c, min_i32, max_i32, med_i32, min_u32, max_u32, med_u32) let cases: &[([u32; 4], u32, u32, u32, u32, u32, u32)] = &[ // Plain ascending order ([1, 2, 3, 0], 1, 3, 2, 1, 3, 2), // Reversed ([3, 2, 1, 0], 1, 3, 2, 1, 3, 2), // All equal ([7, 7, 7, 0], 7, 7, 7, 7, 7, 7), // Two equal (low) ([1, 1, 5, 0], 1, 5, 1, 1, 5, 1), // Two equal (high) ([5, 9, 9, 0], 5, 9, 9, 5, 9, 9), // Signed: negative values ([((-3i32) as u32), ((-1i32) as u32), 2, 0], (-3i32) as u32, 2, (-1i32) as u32, 2, ((-1i32) as u32), ((-3i32) as u32)), // unsigned: -3=0xFFFFFFFD is largest // Signed extremes ([0x8000_0000, 0x7FFF_FFFF, 0, 0], 0x8000_0000, 0x7FFF_FFFF, 0, 0, 0x8000_0000 /*UINT_MAX-1*/ , 0x7FFF_FFFF), ]; let inputs: Vec<[u32; 4]> = cases.iter().map(|c| c.0).collect(); let check = |name: &str, shader: &_, expected: fn(&([u32;4], u32, u32, u32, u32, u32, u32)) -> u32| { run_cases(shader, &inputs, |backend, i, inp, got| { let want = expected(&cases[i]); assert_eq!(got, want, "{backend}: {name}({:#010x}, {:#010x}, {:#010x}) = {got:#010x}, want {want:#010x}", inp[0], inp[1], inp[2]); }); }; check("v_min3_i32", &min3_i, |c| c.1); check("v_max3_i32", &max3_i, |c| c.2); check("v_med3_i32", &med3_i, |c| c.3); check("v_min3_u32", &min3_u, |c| c.4); check("v_max3_u32", &max3_u, |c| c.5); check("v_med3_u32", &med3_u, |c| c.6); } ``` No game data needed; the test skips when no SM 6.6 device is available and runs on WARP. **AI-assisted:** found with Kiro (Claude) and independently confirmed by five separate analysis passes without cross-contamination; no hardware run, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:59 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 11:56 UTC · original

I added one synthetic test for the six integer min3, med3, and max3 instructions. It checks the decoded opcode names and uses CPU sorting in the requested signed or unsigned order as the oracle. The main triplet puts the same three bit patterns at different ranks in the two orderings, and all six operand permutations are checked. Ties and the signed and unsigned boundaries have separate cases.

All 66 readbacks passed on the hardware D3D12 adapter and on WARP, with neither backend skipped. The changed file passed rustfmt, and Clippy and the repo asset check passed. Test-only commit d7aabea

**@⁠fuzeofficlal** on GitHub · 2026-11-24 11:56 UTC · [original](https://github.com/Marvisak/VIctory/issues/800#issuecomment-7130749041) I added one synthetic test for the six integer min3, med3, and max3 instructions. It checks the decoded opcode names and uses CPU sorting in the requested signed or unsigned order as the oracle. The main triplet puts the same three bit patterns at different ranks in the two orderings, and all six operand permutations are checked. Ties and the signed and unsigned boundaries have separate cases. All 66 readbacks passed on the hardware D3D12 adapter and on WARP, with neither backend skipped. The changed file passed rustfmt, and Clippy and the repo asset check passed. [Test-only commit `d7aabea`](https://github.com/fuzeofficlal/VIctory/commit/d7aabeaa3599de6eeeab15b35c44076539a6342a)
Author
Owner

@⁠towiice on GitHub · 2026-11-24 11:57 UTC · original

I implemented the synthetic hardware tests for all six integer operations (v_min3_i32, v_min3_u32, v_max3_i32, v_max3_u32, v_med3_i32, v_med3_u32) as proposed, covering ascending, reversed, equal, signed negative, and signed extreme boundaries:
Branch: https://github.com/towiice/VIctory/tree/test/valu-integer-min3-max3-med3 (commit 89fa58e)

Hardware Test Results:

  • Hardware: NVIDIA GeForce GTX 1650 SUPER (Turing TU116, 4 GB VRAM, 32-wide subgroups / wave32, driver 610.88), Windows 11 x64 (26H2 / 10.0.26300), DXC v1.9.2609, toolchain stable-x86_64-pc-windows-gnullvm.
  • Test command: cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader --lib v_med3_min3 -- --nocapture
  • Result: 1 passed, 0 failed (5.27 s). Both hardware GPU and WARP passed with zero errors. Full victory-shader suite: 121 passed, 0 failed, 1 ignored.

Since direct PR creation on this repository is currently restricted to collaborators, the commit is ready on the branch above if a maintainer wants to pull it.

**@⁠towiice** on GitHub · 2026-11-24 11:57 UTC · [original](https://github.com/Marvisak/VIctory/issues/800#issuecomment-7130778020) I implemented the synthetic hardware tests for all six integer operations (`v_min3_i32`, `v_min3_u32`, `v_max3_i32`, `v_max3_u32`, `v_med3_i32`, `v_med3_u32`) as proposed, covering ascending, reversed, equal, signed negative, and signed extreme boundaries: Branch: https://github.com/towiice/VIctory/tree/test/valu-integer-min3-max3-med3 (commit `89fa58e`) **Hardware Test Results:** - Hardware: NVIDIA GeForce GTX 1650 SUPER (Turing TU116, 4 GB VRAM, 32-wide subgroups / wave32, driver 610.88), Windows 11 x64 (26H2 / 10.0.26300), DXC v1.9.2609, toolchain `stable-x86_64-pc-windows-gnullvm`. - Test command: `cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader --lib v_med3_min3 -- --nocapture` - Result: **1 passed, 0 failed** (5.27 s). Both hardware GPU and WARP passed with zero errors. Full `victory-shader` suite: **121 passed, 0 failed, 1 ignored**. Since direct PR creation on this repository is currently restricted to collaborators, the commit is ready on the branch above if a maintainer wants to pull it.
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 11:58 UTC · original

Added the requested synthetic hardware test v_min3_max3_med3_integers_match_rdna2 covering all six integer three-way instructions (v_min3_i32 0x152, v_min3_u32 0x153, v_max3_i32 0x155, v_max3_u32 0x156, v_med3_i32 0x158, v_med3_u32 0x159) across signed/unsigned boundary triplets (i32::MIN, -1/u32::MAX, 0, 1, i32::MAX), all 6 permutations, and duplicate values.

External PRs are currently collaborators_only, so the verified commit (combined with #799 and #802 in crates/victory-shader/src/emit/valu_tests.rs, based on main ffe310e) is ready on my fork:

Verification (Windows 11 Pro 26100, AMD Radeon RX 9060 XT driver 32.0.32029.2010 + WARP, Rust 1.98.1):

  • rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs: PASS
  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default + --features diagnostics): PASS
  • cargo test -p victory-shader --locked -- valu_tests: 16/16 PASS (verified on both RX 9060 XT and WARP via run_cases)
  • cargo test --workspace --locked: PASS (0 failed)

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 11:58 UTC · [original](https://github.com/Marvisak/VIctory/issues/800#issuecomment-7130800976) Added the requested synthetic hardware test `v_min3_max3_med3_integers_match_rdna2` covering all six integer three-way instructions (`v_min3_i32` `0x152`, `v_min3_u32` `0x153`, `v_max3_i32` `0x155`, `v_max3_u32` `0x156`, `v_med3_i32` `0x158`, `v_med3_u32` `0x159`) across signed/unsigned boundary triplets (`i32::MIN`, `-1`/`u32::MAX`, `0`, `1`, `i32::MAX`), all 6 permutations, and duplicate values. External PRs are currently `collaborators_only`, so the verified commit (combined with #799 and #802 in `crates/victory-shader/src/emit/valu_tests.rs`, based on `main` `ffe310e`) is ready on my fork: - Branch: https://github.com/geiyiliyabumo/VIctory/tree/test/valu-f32-class-int3-f16-zero - Commit: https://github.com/geiyiliyabumo/VIctory/commit/9a173fc **Verification (Windows 11 Pro 26100, AMD Radeon RX 9060 XT driver `32.0.32029.2010` + WARP, Rust `1.98.1`):** - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs`: PASS - `cargo xtask policy`: PASS (`154 files ok`) - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default + `--features diagnostics`): PASS - `cargo test -p victory-shader --locked -- valu_tests`: **16/16 PASS** (verified on both RX 9060 XT and WARP via `run_cases`) - `cargo test --workspace --locked`: PASS (0 failed) *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠Altorru on GitHub · 2026-11-24 12:17 UTC · original

v_med3_min3_max3_integer_matches_rdna2 covers all six opcodes (0x152/0x153/0x155/0x156/0x158/0x159) with ascending, reversed, equal and duplicated operands, signed negatives, and INT_MIN/INT_MAX. Implemented in fork PR Altorru/VIctory#1 (upstream PR creation is collaborator-only), commit bb3a37b. Windows CI passed: cargo test --workspace on https://github.com/Altorru/VIctory/actions/runs/45391712656, where the new test ran on WARP. No game data.

**@⁠Altorru** on GitHub · 2026-11-24 12:17 UTC · [original](https://github.com/Marvisak/VIctory/issues/800#issuecomment-7131240044) v_med3_min3_max3_integer_matches_rdna2 covers all six opcodes (0x152/0x153/0x155/0x156/0x158/0x159) with ascending, reversed, equal and duplicated operands, signed negatives, and INT_MIN/INT_MAX. Implemented in fork PR Altorru/VIctory#1 (upstream PR creation is collaborator-only), commit bb3a37b. Windows CI passed: cargo test --workspace on https://github.com/Altorru/VIctory/actions/runs/45391712656, where the new test ran on WARP. No game data.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#800
No description provided.