Shaders: lower v_cmp_class_f16 and v_cmpx_class_f16 #140

Merged
lordon1a merged 1 commit from upstream-pr/140 into main 2026-11-24 07:51:40 +00:00
lordon1a commented 2026-11-24 00:53:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T00:53:51Z.


Summary

Extends Lower::compare() in crates/victory-shader/src/emit/lower.rs to lower v_cmp_class_f16 and v_cmpx_class_f16 (already decoded by gfx10/opcodes.rs), sharing the existing IEEE-754 class-mask lowering with v_cmp_class_f32.

Rather than widening via legacyF16ToF32 (which would normalize f16 denormals into f32 normals and quiet f16 signalling NaNs), f16 inputs are classified directly on the raw 16-bit halfword from half_src(inst, 0) (exponent shift 10, sign bit 15, exponent mask 0x1F, mantissa mask 0x03FF, quiet bit 0x0200), applying VOP3 abs/neg directly on sign bit 15 so sNaNs are preserved.

Verification

Tested on Windows 11 (rustc 1.100.0, x86_64-pc-windows-gnullvm, Intel Iris Xe 8086:46a6 driver 32.0.101.7088):

  • Negative control (main@4c0bb89 lower.rs with the new test):
    cargo test -p victory-shader v_cmp_class_f16_matches_rdna2 -> FAILED: lower: Unsupported { offset: 44, what: "v_cmp_class_f16" }.
  • With this PR:
    • cargo test -p victory-shader v_cmp_class_f16_matches_rdna2 -> ok (all 10 IEEE-754 binary16 classes including +/-sNaN, +/-qNaN, +/-inf, +/-normal, +/-denormal, +/-0.0, plus op_sel:[1,0] high half and neg modifier preserving sNaN).
    • cargo test -p victory-shader -- --skip v_med3_f32_matches_rdna2_with_nan -> 69 passed, 0 failed (skipping only the pre-existing main Intel Xe med3 failure tracked in #110).
  • cargo xtask policy: 151 files ok (synthetic GFX10 shader only; zero game data).
  • cargo clippy -p victory-shader --all-targets: 0 new warnings.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572095111 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/140). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T00:53:51Z. --- ## Summary Extends `Lower::compare()` in `crates/victory-shader/src/emit/lower.rs` to lower `v_cmp_class_f16` and `v_cmpx_class_f16` (already decoded by `gfx10/opcodes.rs`), sharing the existing IEEE-754 class-mask lowering with `v_cmp_class_f32`. Rather than widening via `legacyF16ToF32` (which would normalize f16 denormals into f32 normals and quiet f16 signalling NaNs), `f16` inputs are classified directly on the raw 16-bit halfword from `half_src(inst, 0)` (exponent shift 10, sign bit 15, exponent mask `0x1F`, mantissa mask `0x03FF`, quiet bit `0x0200`), applying VOP3 `abs`/`neg` directly on sign bit 15 so sNaNs are preserved. ## Verification Tested on Windows 11 (`rustc 1.100.0`, `x86_64-pc-windows-gnullvm`, Intel Iris Xe `8086:46a6` driver `32.0.101.7088`): - **Negative control** (`main@4c0bb89` `lower.rs` with the new test): `cargo test -p victory-shader v_cmp_class_f16_matches_rdna2` -> **FAILED**: `lower: Unsupported { offset: 44, what: "v_cmp_class_f16" }`. - **With this PR**: - `cargo test -p victory-shader v_cmp_class_f16_matches_rdna2` -> **ok** (all 10 IEEE-754 binary16 classes including `+/-sNaN`, `+/-qNaN`, `+/-inf`, `+/-normal`, `+/-denormal`, `+/-0.0`, plus `op_sel:[1,0]` high half and `neg` modifier preserving sNaN). - `cargo test -p victory-shader -- --skip v_med3_f32_matches_rdna2_with_nan` -> **69 passed, 0 failed** (skipping only the pre-existing `main` Intel Xe `med3` failure tracked in #110). - `cargo xtask policy`: **151 files ok** (synthetic GFX10 shader only; zero game data). - `cargo clippy -p victory-shader --all-targets`: 0 new warnings. AI-assisted.
copilot-pull-request-reviewer[bot] commented 2026-11-24 00:54:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T00:54:05Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Marvisak/VIctory:review:6031962941 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/140#pullrequestreview-6031962941). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-24T00:54:05Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
DaviTostes commented 2026-11-24 06:54:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:05:45Z.


Tested 1823079 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 56 passed, 0 failed (2 test binaries), including the test this PR adds for v_cmp_class_f16 / v_cmpx_class_f16.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118749622 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/140#issuecomment-7118749622). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:05:45Z. --- Tested `1823079` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **56 passed, 0 failed** (2 test binaries), including the test this PR adds for `v_cmp_class_f16` / `v_cmpx_class_f16`. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
marquezinii commented 2026-11-24 06:55:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T05:15:57Z.


Ran 1823079 merged onto main d2a4bae (clean; the branch was 6 commits behind) on NVIDIA. valu_tests runs each case on the hardware device and on WARP.

  • NVIDIA GeForce RTX 5070 12 GB (32-lane waves), driver 621.24; Windows 11 Pro 26300; Rust 1.98.1 (pinned) x86_64-pc-windows-msvc, debug
  • v_cmp_class_f16_matches_rdna2: ok on both
  • cargo test -p victory-shader --lib -- --test-threads=1: 70 passed, 0 failed
  • cargo test --workspace -- --test-threads=1: 265 passed, 0 failed, 4 ignored
<!-- greyfinch-sync:Marvisak/VIctory:comment:7122783733 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/140#issuecomment-7122783733). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T05:15:57Z. --- Ran `1823079` merged onto `main` `d2a4bae` (clean; the branch was 6 commits behind) on NVIDIA. `valu_tests` runs each case on the hardware device and on WARP. - NVIDIA GeForce RTX 5070 12 GB (32-lane waves), driver 621.24; Windows 11 Pro 26300; Rust 1.98.1 (pinned) `x86_64-pc-windows-msvc`, debug - `v_cmp_class_f16_matches_rdna2`: ok on both - `cargo test -p victory-shader --lib -- --test-threads=1`: 70 passed, 0 failed - `cargo test --workspace -- --test-threads=1`: 265 passed, 0 failed, 4 ignored
Lyrnc commented 2026-11-24 06:56:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:26:51Z.


RDNA2 hardware check of the class bits: match.

Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. v_cmp_class_f16 vcc, v4, (1 << bit) for each of the 10 mask bits, over 11 halves (junk in the high half), with FP16 denormals kept and flushed.

half bit set on the hardware (0 sNaN, 1 qNaN, 2 -inf, 3 -normal, 4 -denormal, 5 -0, 6 +0, 7 +denormal, 8 +normal, 9 +inf)
0x0000, 0x8000 6, 5
0x0001, 0x83ff 7, 4
0x3c00, 0xbc00 8, 3
0x7c00, 0xfc00 9, 2
0x7e00, 0xfe00 1, 1
0x7c01 (sNaN) 0
  • Exactly one bit per value, the class your table uses.
  • A denormal is still classified as a denormal when the FP16 denormal mode flushes: identical table in both modes. So the lowering doesn't need MODE for this.
  • Not measured: the neg modifier on the high half.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123942013 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/140#issuecomment-7123942013). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:26:51Z. --- RDNA2 hardware check of the class bits: **match.** **Setup.** AMD Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036 (RDNA2)**, AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. `v_cmp_class_f16 vcc, v4, (1 << bit)` for each of the 10 mask bits, over 11 halves (junk in the high half), with FP16 denormals kept and flushed. | half | bit set on the hardware (0 sNaN, 1 qNaN, 2 -inf, 3 -normal, 4 -denormal, 5 -0, 6 +0, 7 +denormal, 8 +normal, 9 +inf) | |---|---| | `0x0000`, `0x8000` | 6, 5 | | `0x0001`, `0x83ff` | 7, 4 | | `0x3c00`, `0xbc00` | 8, 3 | | `0x7c00`, `0xfc00` | 9, 2 | | `0x7e00`, `0xfe00` | 1, 1 | | `0x7c01` (sNaN) | 0 | - Exactly one bit per value, the class your table uses. - A denormal is still classified as a denormal when the FP16 denormal mode flushes: identical table in both modes. So the lowering doesn't need MODE for this. - Not measured: the `neg` modifier on the high half. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
upstream-sync closed this pull request 2026-11-24 08:01:50 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!140
No description provided.