Recompiler: specialize constant-mask v_cmp_class_f32 in direct DXIL #2282
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2282
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2282/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCSpecializes
v_cmp_class_f32in the direct DXIL translator when the 10-bit class mask operandubis a compile-time constant (the common case in console shaders, e.g.0x003NaN,0x204Inf,0x207NaN|Inf,0x1F8finite,0x060zero,0x200+Inf,0x004-Inf).Instead of emitting the ~23-instruction 10-class
fclassselect tree followed by a dynamic shift and mask,Lw::fclass_constpartitions IEEE-754 binary32 into contiguous raw bit intervals (usingu & 0x7FFF_FFFFfor sign-symmetric masks and rawuotherwise), merges adjacent selected classes, picks whichever ofmaskor!mask & 0x3FFneeds 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: dispatchv_cmp_class_f32(v_cmpx_class_f32) toLw::fclass_constwhenself.s.m.const_u64(ub)isSome(k), keeping dynamic masks onLw::fclass.crates/xcl/src/gpu/dxil/prelude.rs:Lw::fclass_const,F32_ABS_CLASSES,F32_RAW_CLASSES, andmerged_class_intervals.fclass_const_tests::fclass_const_intervals_match_all_1024_masks_and_boundariesverifying every one of the 1,024 10-bit masks across 20 class boundary bit patterns against the ISA class table, andfclass_const_tests::gpu_direct_v_cmp_class_f32_const_mask_validates_and_matches_isachecking 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 (0validator failures):41,323,736 B -> 41,256,696 B(-67,040 B,-0.16%)Tested
621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro26300,rustc 1.99.0(x86_64-pc-windows-msvc), DXC/DXIL1.8.2502.11(Windows SDK10.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: 21no wave64, 1no heap windows, 3 per-lane#1426refusals).cargo build --release -p xcl+ direct DXIL validation sweep on 573 sampled retail shader programs:573/573translated anddxil.dll-validated (0failures).Regression run
Not tested
XCL_SAMPLE_*env vars unset).AI use
prelude.rsandlower_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.@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
d041801applied onmain1a0bbe3, debug, Windows 11 Pro 26200,cargo test -p xcl --lib -- gpu:: --test-threads=4:gpu_direct_v_cmp_class_f32_const_mask_validates_and_matches_isaok. 631 passed, 2 failed, 22 ignored, 6 SKIPPED, the same asmainplus the new test; the 2 failures are the AMD fuzz seeds tracked in #2115.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.
@nnonno91 on GitHub · 2026-11-25 15:00 UTC · original
Independent exact-head GPU check of
d041801d4129a89a8485f82a56ada91b2ea42df9with additional sign-specific and NaN-only class masks.Tested
cargo test --locked -p xcl --lib fclass_const_tests -- --nocapture --test-threads=1with each GPU selected viaXCL_ADAPTERgave 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.
@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!