Recompiler: specialize constant-mask v_cmp_class_f32 in direct DXIL #2282

Manually merged
github merged 1 commit from gh-pr/2282/head into gh-pr/2282/base 2026-11-26 05:25:37 +00:00
Owner

@⁠ramon-victor on GitHub · 2026-11-25 12:22 UTC · original
ramon-victor:opt/dxil-v-cmp-class-const-mask → main · +244 −4 · 2 files · 1 commits · merged 2026-11-25 18:38 UTC

Specializes v_cmp_class_f32 in the direct DXIL translator when the 10-bit class mask operand ub is a compile-time constant (the common case in console shaders, e.g. 0x003 NaN, 0x204 Inf, 0x207 NaN|Inf, 0x1F8 finite, 0x060 zero, 0x200 +Inf, 0x004 -Inf).

Instead of emitting the ~23-instruction 10-class fclass select tree followed by a dynamic shift and mask, Lw::fclass_const partitions IEEE-754 binary32 into contiguous raw bit intervals (using u & 0x7FFF_FFFF for sign-symmetric masks and raw u otherwise), merges adjacent selected classes, picks whichever of mask or !mask & 0x3FF needs fewer intervals, and tests each interval with 1–2 integer comparisons directly on the bit pattern (never invoking float ops, so FTZ denormals and sNaN payloads stay exact). Common masks like NaN, Inf, NaN|Inf, Finite, Zero, +Inf, and -Inf lower to 1–2 instructions.

Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/lower_valu.rs: dispatch v_cmp_class_f32 (v_cmpx_class_f32) to Lw::fclass_const when self.s.m.const_u64(ub) is Some(k), keeping dynamic masks on Lw::fclass.
  • crates/xcl/src/gpu/dxil/prelude.rs:
    • Add Lw::fclass_const, F32_ABS_CLASSES, F32_RAW_CLASSES, and merged_class_intervals.
    • Add fclass_const_tests::fclass_const_intervals_match_all_1024_masks_and_boundaries verifying every one of the 1,024 10-bit masks across 20 class boundary bit patterns against the ISA class table, and fclass_const_tests::gpu_direct_v_cmp_class_f32_const_mask_validates_and_matches_isa checking DXIL validation, disassembly (0 selects), and GPU execution across 12 masks and 12 bit patterns (±0, ±denorm, ±normal, ±Inf, ±sNaN, ±qNaN).

On a seeded 600-program sample (xcl shaders <archive> --direct --sample 600 --seed 3 --max-bytes 40000 --validate --threads 8, 573 programs within the cap), all 573/573 validate cleanly (0 validator failures):

  • Total emitted DXIL: 41,323,736 B -> 41,256,696 B (-67,040 B, -0.16%)

Tested

  • Hardware and toolchain: NVIDIA GeForce RTX 3070 (8 GiB, driver 621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro 26300, rustc 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0).
  • cargo test -p xcl --lib gpu::dxil::prelude::fclass_const_tests (debug): 2 passed; 0 failed (exhaustive 1,024-mask boundary verification + 12-mask GPU execution test on RTX 3070).
  • .\scripts\test.ps1 (debug, full workspace): 1252 passed; 0 failed; 46 ignored (25 GPU sub-checks skipped on this wave32 adapter: 21 no wave64, 1 no heap windows, 3 per-lane #1426 refusals).
  • cargo build --release -p xcl + direct DXIL validation sweep on 573 sampled retail shader programs: 573/573 translated and dxil.dll-validated (0 failures).

Regression run

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB
xcl-smoke v1
commit: d041801d4129a89a8485f82a56ada91b2ea42df9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14450 MB

Not tested

  • Native wave64 GPU hardware (AMD/Intel): RTX 3070 only supports wave32, so native wave64 tests skip on this adapter.
  • Sample-gated tests (XCL_SAMPLE_* env vars unset).

AI use

  • Antigravity (Gemini 4 Neon): implemented constant-mask binary32 class-interval lowering in prelude.rs and lower_valu.rs, added exhaustive 1,024-mask and GPU ISA tests, and ran the workspace test suite, 573-shader validation benchmark, and 60 s smoke regression run.
**@⁠ramon-victor** on GitHub · 2026-11-25 12:22 UTC · [original](https://github.com/xcl-dev/xcl/pull/2282) `ramon-victor:opt/dxil-v-cmp-class-const-mask` → `main` · +244 −4 · 2 files · 1 commits · merged 2026-11-25 18:38 UTC Specializes `v_cmp_class_f32` in the direct DXIL translator when the 10-bit class mask operand `ub` is a compile-time constant (the common case in console shaders, e.g. `0x003` NaN, `0x204` Inf, `0x207` NaN|Inf, `0x1F8` finite, `0x060` zero, `0x200` +Inf, `0x004` -Inf). Instead of emitting the ~23-instruction 10-class `fclass` select tree followed by a dynamic shift and mask, `Lw::fclass_const` partitions IEEE-754 binary32 into contiguous raw bit intervals (using `u & 0x7FFF_FFFF` for sign-symmetric masks and raw `u` otherwise), merges adjacent selected classes, picks whichever of `mask` or `!mask & 0x3FF` needs fewer intervals, and tests each interval with 1–2 integer comparisons directly on the bit pattern (never invoking float ops, so FTZ denormals and sNaN payloads stay exact). Common masks like NaN, Inf, NaN|Inf, Finite, Zero, +Inf, and -Inf lower to 1–2 instructions. Part of #1269. **What is in it** - `crates/xcl/src/gpu/dxil/lower_valu.rs`: dispatch `v_cmp_class_f32` (`v_cmpx_class_f32`) to `Lw::fclass_const` when `self.s.m.const_u64(ub)` is `Some(k)`, keeping dynamic masks on `Lw::fclass`. - `crates/xcl/src/gpu/dxil/prelude.rs`: - Add `Lw::fclass_const`, `F32_ABS_CLASSES`, `F32_RAW_CLASSES`, and `merged_class_intervals`. - Add `fclass_const_tests::fclass_const_intervals_match_all_1024_masks_and_boundaries` verifying every one of the 1,024 10-bit masks across 20 class boundary bit patterns against the ISA class table, and `fclass_const_tests::gpu_direct_v_cmp_class_f32_const_mask_validates_and_matches_isa` checking DXIL validation, disassembly (0 selects), and GPU execution across 12 masks and 12 bit patterns (±0, ±denorm, ±normal, ±Inf, ±sNaN, ±qNaN). On a seeded 600-program sample (`xcl shaders <archive> --direct --sample 600 --seed 3 --max-bytes 40000 --validate --threads 8`, 573 programs within the cap), all 573/573 validate cleanly (`0` validator failures): - Total emitted DXIL: `41,323,736 B -> 41,256,696 B` (`-67,040 B`, `-0.16%`) **Tested** - Hardware and toolchain: NVIDIA GeForce RTX 3070 (8 GiB, driver `621.24`, wave32), AMD Ryzen 7 5700X, Windows 11 Pro `26300`, `rustc 1.99.0` (`x86_64-pc-windows-msvc`), DXC/DXIL `1.8.2502.11` (Windows SDK `10.0.26100.0`). - `cargo test -p xcl --lib gpu::dxil::prelude::fclass_const_tests` (debug): `2 passed; 0 failed` (exhaustive 1,024-mask boundary verification + 12-mask GPU execution test on RTX 3070). - `.\scripts\test.ps1` (debug, full workspace): `1252 passed; 0 failed; 46 ignored` (25 GPU sub-checks skipped on this wave32 adapter: 21 `no wave64`, 1 `no heap windows`, 3 per-lane `#1426` refusals). - `cargo build --release -p xcl` + direct DXIL validation sweep on 573 sampled retail shader programs: `573/573` translated and `dxil.dll`-validated (`0` failures). **Regression run** ``` xcl-smoke v1 commit: f087b998d0d51a9f11bbfa0761967a63e778edd9 gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14467 MB ``` ``` xcl-smoke v1 commit: d041801d4129a89a8485f82a56ada91b2ea42df9 gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1617 (PresentX 1617) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14450 MB ``` **Not tested** - Native wave64 GPU hardware (AMD/Intel): RTX 3070 only supports wave32, so native wave64 tests skip on this adapter. - Sample-gated tests (`XCL_SAMPLE_*` env vars unset). **AI use** - Antigravity (Gemini 4 Neon): implemented constant-mask binary32 class-interval lowering in `prelude.rs` and `lower_valu.rs`, added exhaustive 1,024-mask and GPU ISA tests, and ran the workspace test suite, 573-shader validation benchmark, and 60 s smoke regression run.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:25:36 +00:00
github manually merged commit d041801d41 into gh-pr/2282/base 2026-11-26 05:25:37 +00:00
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 13:00 UTC · original

The AMD native wave64 run listed as untested, plus an RTX 3060: the new test passes on both, NaN and infinity classes included.

Head d041801 applied on main 1a0bbe3, debug, Windows 11 Pro 26200, cargo test -p xcl --lib -- gpu:: --test-threads=4:

  • RX 9070 XT (RDNA4, driver 32.0.32029.2010, waves 32..64): gpu_direct_v_cmp_class_f32_const_mask_validates_and_matches_isa ok. 631 passed, 2 failed, 22 ignored, 6 SKIPPED, the same as main plus the new test; the 2 failures are the AMD fuzz seeds tracked in #2115.
  • RTX 3060 (driver 32.0.16.1088): the new test ok; 633 passed, 0 failed, 22 ignored.

Not tested: a title with XCL_DIRECT_DXIL=1.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-25 13:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2282#issuecomment-7163150086) The AMD native wave64 run listed as untested, plus an RTX 3060: the new test passes on both, NaN and infinity classes included. Head `d041801` applied on `main` `1a0bbe3`, debug, Windows 11 Pro 26200, `cargo test -p xcl --lib -- gpu:: --test-threads=4`: - **RX 9070 XT** (RDNA4, driver 32.0.32029.2010, waves 32..64): `gpu_direct_v_cmp_class_f32_const_mask_validates_and_matches_isa` ok. 631 passed, 2 failed, 22 ignored, 6 SKIPPED, the same as `main` plus the new test; the 2 failures are the AMD fuzz seeds tracked in #2115. - **RTX 3060** (driver 32.0.16.1088): the new test ok; 633 passed, 0 failed, 22 ignored. Not tested: a title with `XCL_DIRECT_DXIL=1`. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

@⁠nnonno91 on GitHub · 2026-11-25 15:00 UTC · original

Independent exact-head GPU check of d041801d4129a89a8485f82a56ada91b2ea42df9 with additional sign-specific and NaN-only class masks.

Tested

  • Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, SDK DXC/DXIL 1.8.2502.11, unoptimized profile. Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742.
  • Temporarily expanded the constant-mask GPU fixture from 12 masks and 12 bit patterns to 16 masks and 20 patterns. Added separate signaling-NaN, quiet-NaN, negative-subnormal and positive-subnormal masks, plus bit patterns around the normal/subnormal and signaling/quiet boundaries.
  • cargo test --locked -p xcl --lib fclass_const_tests -- --nocapture --test-threads=1 with each GPU selected via XCL_ADAPTER gave 2 passed, 0 failed, 0 ignored and no skips on each. All 320 mask/input comparisons per GPU matched the reference. DXIL validation, the zero-select assertion and the existing exhaustive CPU mask test also passed. The fixture changes were restored.

Not tested

Retail inputs, performance, the parent, native wave64 execution of this wave32 fixture, and the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) added the temporary boundary values, ran the tests and wrote this report.

**@⁠nnonno91** on GitHub · 2026-11-25 15:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2282#issuecomment-7166152218) Independent exact-head GPU check of `d041801d4129a89a8485f82a56ada91b2ea42df9` with additional sign-specific and NaN-only class masks. **Tested** - Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, SDK DXC/DXIL 1.8.2502.11, unoptimized profile. Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742. - Temporarily expanded the constant-mask GPU fixture from 12 masks and 12 bit patterns to 16 masks and 20 patterns. Added separate signaling-NaN, quiet-NaN, negative-subnormal and positive-subnormal masks, plus bit patterns around the normal/subnormal and signaling/quiet boundaries. - `cargo test --locked -p xcl --lib fclass_const_tests -- --nocapture --test-threads=1` with each GPU selected via `XCL_ADAPTER` gave 2 passed, 0 failed, 0 ignored and no skips on each. All 320 mask/input comparisons per GPU matched the reference. DXIL validation, the zero-select assertion and the existing exhaustive CPU mask test also passed. The fixture changes were restored. **Not tested** Retail inputs, performance, the parent, native wave64 execution of this wave32 fixture, and the full workspace suite. **AI use** OpenAI Codex (GPT-6.2 Sol) added the temporary boundary values, ran the tests and wrote this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 17:20 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 17:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/2282#issuecomment-7169352889) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.