startup: gfx2hlsl f32 nlt/nle/ngt/nge (FXC) and u/o (DXC) compares are wrong on NaN without IEEE-strict compiles #1936
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#1936
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@MasterDomino on GitHub · 2026-11-24 21:48 UTC · original
Summary
Six f32 VOPC conditions in
tools/startup/gfx2hlsl.pyare exact in HLSL but give the wrong result on NaN sources after compilation with default flags. Neither compiler treats float compares as IEEE-strict unless asked: FXC needs/Gisand DXC needs-Gis.nlt/nle/ngt/nge!(a < b)etc.ps_5_1, default flagsge/gt/le/lt(the negation folded into the opposite relation)u(a != a || b != b)ps_6_0, default flags0.0stored to all four channelso(a == a && b == b)ps_6_0, default flagsThe startup cache compiles every
gfx2hlslpair with FXC and no flags (translate_tointools/startup/gfx2hlsl.pyrunsfxc /T <profile> /E main), so the FXC row reaches real translated stages. Of 186 locally translated HLSL stages, 3 contain an n-form compare. That is an aggregate count; no other local data is used here. No local stage hasuoro, and the DXC row currently affects only DXC builds of the same text (tests and any future DXC path).This is the same class as #1920 (
lg/nlg), where DXC's fast compares broke less-or-greater. #1930 fixes those two with a bit test of both source words.Measured
Every f32 condition the compare table lowers was drawn through
gfx2hlsl, one source-built pixel program per condition. The 16 × 16 pixels cover every pair of 16 source words: ±0, ±min denormal, ±1.0, ±max finite, ±inf, ±quiet NaN, ±signalling NaN and ±NaN with a payload. Each image was compared with the ISA reference (denormals kept or flushed) and with a "NaN-blind" model: the n-forms false on NaN,ufalse andotrue.fc9517aa(#1930's head, onmainb96960b7).fxc.exeanddxc.exe./Gis-Gisnltnlengtngeuoflteqlegtgeneq, andlgnlg(#1930)WARP and the RX 9070 XT agree in every cell, so the result is decided by the bytecode, not the driver. The FXC listing for
nltends inge r0.x, r0.x, r0.y; with/Gisit keepslt [precise(x)]and inverts the select. The DXCulisting has nofcmpand stores0.000000e+00to all four channels; with-Gisthe compares stay.neqis not affected: both compilers turn!(a == b)into an unordered not-equal, which is still true on NaN.Proposed fix
Make the lowering independent of compiler flags, as #1930 does for
lg, rather than add/Gisto the cache build. A flag would change every float operation in every translated stage, not only these compares.nlt/nle/ngt/nge:!(ORDERED && a OP b), the same shape asnlgafter #1930.ORDEREDis the integer test(w & 0x7fffffffu) <= 0x7f800000uon both source words, read before neg/abs. Any rewrite of the inner relation is then masked by an integer NaN test.o:ORDERED.u:!ORDERED.The completion condition:
x != xandx == xfolded to constants). The new text must hold under all three; the old text must fail under the rewrite that broke it.I'd like to take this. It builds on #1930's bit test, so the PR will be stacked on that branch.
AI-assisted.
@R0Y00 on GitHub · 2026-11-24 21:53 UTC · original
Please take the narrow per-predicate fix on top of #1930. Keep the normal production compiler flags and use bit-level NaN classification for the six reported conditions. Keep the existing denormal reference explicit in the raw-pixel comparison. For the regression, run the default FXC and DXC paths with the pre-fix text as the negative control, and record strict-flag runs as a diagnostic comparison. This separates the localized predicate change from a cache-wide compiler policy change.
@MasterDomino on GitHub · 2026-11-24 22:00 UTC · original
PR: #1949, stacked on #1930 and to be merged after it. It is the narrow per-predicate fix with compiler flags unchanged:
nlt/nle/ngt/ngeread!(ORDERED && a OP b);oandureadORDEREDand!ORDERED.Negative control: the default-flag FXC and DXC paths run the pre-fix text. It fails on the compiler that rewrote it (156 NaN pixels on WARP and the RX 9070 XT) and matches that rewrite's image.
Diagnostic (recorded, not checked): with
/Gisand-Gis, the pre-fix and the fixed text both match every pixel.Denormals: the raw-pixel comparison still names the image it matched, kept or flushed. Both backends flushed, consistently across the fixtures whose image depends on it.
AI-assisted.