startup: keep gfx2hlsl f32 n-forms, o and u exact under FXC and DXC #1949

Manually merged
github merged 1 commit from gh-pr/1949/head into gh-pr/1949/base 2026-11-26 23:44:42 +00:00
Owner

@⁠MasterDomino on GitHub · 2026-11-24 22:00 UTC · original
MasterDomino:startup/gfx2hlsl-f32-nan-forms → main · +513 −10 · 6 files · 1 commits · merged 2026-11-24 22:19 UTC

Fixes #1936. Builds on the bit test from #1930 (merged); rebased onto main cd5508e9.

What

This is the narrow per-predicate fix agreed on #1936. Compiler flags are unchanged.

Condition Before After
nlt nle ngt nge !(a OP b) !(ORDERED && a OP b)
o (a == a && b == b) ORDERED
u (a != a || b != b) !ORDERED

ORDERED is the integer test (w & 0x7fffffffu) <= 0x7f800000u on both source words, read before neg/abs, as lg/nlg use since #1930. neq and the ordered relations are unchanged: both compilers keep them exact on NaN (measured below).

Why

The startup cache compiles every gfx2hlsl pair with FXC and no flags (translate_to). Neither compiler keeps float compares IEEE-strict unless asked:

  • FXC compiles !(a < b) to ge a, b, and likewise for <=, >, >=. So nlt/nle/ngt/nge gave 0 on every NaN pair, where the ISA gives 1.
  • DXC folds a != a and a == a. So u was constant 0 and o constant 1.

With the integer NaN test in front, any rewrite of the float relation keeps the ISA result.

Tests

tests/startup_gfx2hlsl_f32_nan_check.py:

  • Controls (pure Python, also in the CI Python job):
    • All 510 f32 forms (v_cmp and v_cmpx; e32, and e64 under every neg/abs combination) are translated and evaluated over the 256 pairs of ±0, ±min denormal, ±1.0, ±max finite, ±inf, ±quiet, signalling and payload NaN.
    • Each form is evaluated under three models: IEEE compares; the FXC rewrite (a negation pushed into the opposite relation); and the DXC folds (reflexive float relations folded, and less-or-greater read as unordered not-equal, as in #1920). Every form equals the ISA reference under all three.
    • The pre-fix text of the six conditions holds under IEEE and fails all 204 of its forms under the model of the compiler that broke it.
    • The models themselves are checked against the pre-fix text.
    • An EXEC-masked lane check.
    • Run against the unfixed gfx2hlsl.py, the controls fail.
  • Draws (_warp, _hardware):
    • Every lowered condition except lg/nlg (13 of them) writes four results per pixel: e32, and e64 with (-a, |b|), (-|a|, -b) and (|a|, b). The six also keep pixels through v_cmpx_*_e64. 16 × 16 pixels cover every source pair, compiled with default-flag FXC ps_5_1 and DXC ps_6_0.
    • Every pixel must match the ISA image, and the report says whether the denormal-kept or the denormal-flushed image matched. The choice must be the same across the fixtures whose image depends on it (f, o and u don't).
    • Negative control: on the compiler that rewrote it, the pre-fix text must fail against both images and must match the image of that compiler's rewrite.
    • Diagnostic (recorded, not checked): the pre-fix and the fixed text drawn with /Gis and -Gis.
  • binary <llvm-mc> and decode <libLLVM> round-trip the 19 fixtures through LLVM 15. Both are added to the CI LLVM job.

tests/startup_gfx2hlsl_f32_lg_check.py pinned the old text of these six conditions. That pin moves to the new test; the other 7 conditions stay pinned there.

Results

Commit 583178d4 (on main cd5508e9); Windows 11 build 26300; Windows SDK 10.0.26100.0 FXC and DXC; D3D12 debug layer on.

  • WARP: Microsoft Basic Render Driver, 10.0.26100.9818.
  • Hardware: AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31044.16.
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_' -j 6
100% tests passed out of 39        (startup_gfx2hlsl_f32_nan, _warp, _hardware among them)
python -B tests/startup_gfx2hlsl_f32_nan_check.py draw <dxc> <offscreen_check> warp|hardware <fxc>
PASS                               (171 checks on each adapter, 0 skips)
python -B tests/startup_gfx2hlsl_f32_nan_check.py binary <llvm-mc 15.0.7>        PASS
python -B tests/startup_gfx2hlsl_f32_nan_check.py decode <LLVM-C.dll>            PASS
FXC (default) DXC (default) FXC /Gis (recorded) DXC -Gis (recorded)
Fixed text, all 13 conditions every pixel, both adapters every pixel, both adapters every pixel every pixel
Pre-fix nlt nle ngt nge fails, 156 NaN pixels; matches the NaN-blind image matched (recorded) every pixel every pixel
Pre-fix o u matched (recorded) fails, 156 NaN pixels; matches the folded image every pixel every pixel

Both backends flushed denormal compare sources to signed zero, which D3D allows, consistently across fixtures. WARP and the RX 9070 XT agree in every cell, so the bytecode decides it.

Not covered

  • f16/f64 compares and v_cmp_class_*, which are not lowered.
  • Other float operations under FXC's default flags. This PR changes no compiler policy.

🤖 Generated with Claude Code

**@⁠MasterDomino** on GitHub · 2026-11-24 22:00 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1949) `MasterDomino:startup/gfx2hlsl-f32-nan-forms` → `main` · +513 −10 · 6 files · 1 commits · merged 2026-11-24 22:19 UTC Fixes #1936. Builds on the bit test from #1930 (merged); rebased onto `main` `cd5508e9`. ## What This is the narrow per-predicate fix agreed on #1936. Compiler flags are unchanged. | Condition | Before | After | |---|---|---| | `nlt` `nle` `ngt` `nge` | `!(a OP b)` | `!(ORDERED && a OP b)` | | `o` | `(a == a && b == b)` | `ORDERED` | | `u` | `(a != a \|\| b != b)` | `!ORDERED` | `ORDERED` is the integer test `(w & 0x7fffffffu) <= 0x7f800000u` on both source words, read before neg/abs, as `lg`/`nlg` use since #1930. `neq` and the ordered relations are unchanged: both compilers keep them exact on NaN (measured below). ## Why The startup cache compiles every `gfx2hlsl` pair with FXC and no flags (`translate_to`). Neither compiler keeps float compares IEEE-strict unless asked: - **FXC** compiles `!(a < b)` to `ge a, b`, and likewise for `<=`, `>`, `>=`. So `nlt`/`nle`/`ngt`/`nge` gave 0 on every NaN pair, where the ISA gives 1. - **DXC** folds `a != a` and `a == a`. So `u` was constant 0 and `o` constant 1. With the integer NaN test in front, any rewrite of the float relation keeps the ISA result. ## Tests `tests/startup_gfx2hlsl_f32_nan_check.py`: - **Controls (pure Python, also in the CI Python job):** - All 510 f32 forms (v_cmp and v_cmpx; e32, and e64 under every neg/abs combination) are translated and evaluated over the 256 pairs of ±0, ±min denormal, ±1.0, ±max finite, ±inf, ±quiet, signalling and payload NaN. - Each form is evaluated under three models: IEEE compares; the FXC rewrite (a negation pushed into the opposite relation); and the DXC folds (reflexive float relations folded, and less-or-greater read as unordered not-equal, as in #1920). Every form equals the ISA reference under all three. - The pre-fix text of the six conditions holds under IEEE and fails all 204 of its forms under the model of the compiler that broke it. - The models themselves are checked against the pre-fix text. - An EXEC-masked lane check. - Run against the unfixed `gfx2hlsl.py`, the controls fail. - **Draws (`_warp`, `_hardware`):** - Every lowered condition except `lg`/`nlg` (13 of them) writes four results per pixel: e32, and e64 with `(-a, |b|)`, `(-|a|, -b)` and `(|a|, b)`. The six also keep pixels through `v_cmpx_*_e64`. 16 × 16 pixels cover every source pair, compiled with **default-flag** FXC `ps_5_1` and DXC `ps_6_0`. - Every pixel must match the ISA image, and the report says whether the denormal-kept or the denormal-flushed image matched. The choice must be the same across the fixtures whose image depends on it (`f`, `o` and `u` don't). - **Negative control:** on the compiler that rewrote it, the pre-fix text must fail against both images and must match the image of that compiler's rewrite. - **Diagnostic (recorded, not checked):** the pre-fix and the fixed text drawn with `/Gis` and `-Gis`. - `binary <llvm-mc>` and `decode <libLLVM>` round-trip the 19 fixtures through LLVM 15. Both are added to the CI LLVM job. `tests/startup_gfx2hlsl_f32_lg_check.py` pinned the old text of these six conditions. That pin moves to the new test; the other 7 conditions stay pinned there. ## Results Commit `583178d4` (on `main` `cd5508e9`); Windows 11 build 26300; Windows SDK 10.0.26100.0 FXC and DXC; D3D12 debug layer on. - **WARP:** Microsoft Basic Render Driver, 10.0.26100.9818. - **Hardware:** AMD Radeon RX 9070 XT (`1002:7550`), driver 32.0.31044.16. ``` ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_' -j 6 100% tests passed out of 39 (startup_gfx2hlsl_f32_nan, _warp, _hardware among them) python -B tests/startup_gfx2hlsl_f32_nan_check.py draw <dxc> <offscreen_check> warp|hardware <fxc> PASS (171 checks on each adapter, 0 skips) python -B tests/startup_gfx2hlsl_f32_nan_check.py binary <llvm-mc 15.0.7> PASS python -B tests/startup_gfx2hlsl_f32_nan_check.py decode <LLVM-C.dll> PASS ``` | | FXC (default) | DXC (default) | FXC `/Gis` (recorded) | DXC `-Gis` (recorded) | |---|---|---|---|---| | Fixed text, all 13 conditions | every pixel, both adapters | every pixel, both adapters | every pixel | every pixel | | Pre-fix `nlt` `nle` `ngt` `nge` | **fails**, 156 NaN pixels; matches the NaN-blind image | matched (recorded) | every pixel | every pixel | | Pre-fix `o` `u` | matched (recorded) | **fails**, 156 NaN pixels; matches the folded image | every pixel | every pixel | Both backends flushed denormal compare sources to signed zero, which D3D allows, consistently across fixtures. WARP and the RX 9070 XT agree in every cell, so the bytecode decides it. ## Not covered - f16/f64 compares and `v_cmp_class_*`, which are not lowered. - Other float operations under FXC's default flags. This PR changes no compiler policy. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The startup cache compiles gfx2hlsl pairs with FXC and no flags, and
neither compiler keeps float compares IEEE-strict unless asked. FXC
compiled !(a < b) to ge (and likewise for <=, >, >=), so v_cmp nlt, nle,
ngt and nge gave 0 on every NaN pair; DXC folded a != a and a == a, so u
was constant 0 and o constant 1. WARP and an RX 9070 XT agreed, and
/Gis or -Gis restored the ISA result.

The n-forms now read !(ORDERED && a OP b), and o and u read ORDERED and
!ORDERED, with ORDERED the bit test of both source words that lg uses
since #1920. neq is unchanged. Compiler flags are unchanged.

tests/startup_gfx2hlsl_f32_nan_check.py evaluates every f32 form under
IEEE compares and under models of both rewrites, and draws every lowered
condition but lg/nlg with FXC and DXC; the pre-fix text fails on the
compiler that rewrote it and matches that rewrite's image. Strict-flag
runs are recorded as a diagnostic.

Fixes #1936

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:44:40 +00:00
github manually merged commit 583178d403 into gh-pr/1949/base 2026-11-26 23:44:42 +00:00
Author
Owner

@⁠ChazY11 on GitHub · 2026-11-24 22:20 UTC · original

Ran both checks and broke all six changed predicates one at a time

Windows 11 build 26300.9974, device-free:

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_f32_nan_check.py    # exit 0
out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_f32_lg_check.py     # exit 0

Each predicate reverted to its pre-#1936 text, one at a time, running only the new check:

mutation result
nlt → !({0} < {1}) caught
nle → !({0} <= {1}) caught
ngt → !({0} > {1}) caught
nge → !({0} >= {1}) caught
o → ({0} == {0} && {1} == {1}) caught
u → `({0} != {0}
u → ({2}) (the negation dropped, i.e. u becomes o) caught

The last one matters: o and u are complements, so a test that only compared each against its own expected string would let a
swapped pair through if both were wrong the same way. Yours catches the single-character version.

The edit to the existing lg check does not weaken it

Removing six conditions from UNCHANGED and skipping them in the changed loop is the kind of edit that quietly drops coverage, so
I checked it two ways:

  • the set assertion in the same file now unions {'lg', 'nlg'} | set(NAN_FORMS), so a condition missing from both tables still
    fails the coverage line rather than being silently unchecked;
  • mutating the conditions that stayed in that file still fails it: neq → ({0} == {1}) caught, lt → {0} <= {1}
    caught.

So the six moved out, six moved in, and nothing fell between them.

What I like about the shape

o = ORDERED and u = !ORDERED reuses the integer test rather than writing a second NaN predicate, which is the reason a
backend cannot fold either to a constant. The comment names the two compiler behaviours (!Gis / -Gis) that forced this, so a
later reader knows why the text is not simply a == a.

What this does not establish

The whole point is what FXC and DXC emit, and this check compares emitted text and evaluates it on the CPU — the compiler side
rests on the measurements in the description. x != x folding under DXC without -Gis is asserted there, not re-measured here; I
have no DXC in this environment. That limitation is the honest one for this PR, and it is stated.

Verdict

Reviewed. Six behaviours, seven mutations, all caught, and the neighbouring check keeps its teeth.

Notes

  • AI-assisted review.
**@⁠ChazY11** on GitHub · 2026-11-24 22:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1949#issuecomment-7146100560) ## Ran both checks and broke all six changed predicates one at a time Windows 11 build 26300.9974, device-free: ```powershell out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_f32_nan_check.py # exit 0 out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_f32_lg_check.py # exit 0 ``` Each predicate reverted to its pre-#1936 text, one at a time, running only the new check: | mutation | result | |---|---| | `nlt` → `!({0} < {1})` | **caught** | | `nle` → `!({0} <= {1})` | **caught** | | `ngt` → `!({0} > {1})` | **caught** | | `nge` → `!({0} >= {1})` | **caught** | | `o` → `({0} == {0} && {1} == {1})` | **caught** | | `u` → `({0} != {0} || {1} != {1})` | **caught** | | `u` → `({2})` (the negation dropped, i.e. `u` becomes `o`) | **caught** | The last one matters: `o` and `u` are complements, so a test that only compared each against its own expected string would let a swapped pair through if both were wrong the same way. Yours catches the single-character version. ## The edit to the existing `lg` check does not weaken it Removing six conditions from `UNCHANGED` and skipping them in the `changed` loop is the kind of edit that quietly drops coverage, so I checked it two ways: - the set assertion in the same file now unions `{'lg', 'nlg'} | set(NAN_FORMS)`, so a condition missing from both tables still fails the coverage line rather than being silently unchecked; - mutating the conditions that **stayed** in that file still fails it: `neq` → `({0} == {1})` **caught**, `lt` → `{0} <= {1}` **caught**. So the six moved out, six moved in, and nothing fell between them. ## What I like about the shape `o = ORDERED` and `u = !ORDERED` reuses the integer test rather than writing a second NaN predicate, which is the reason a backend cannot fold either to a constant. The comment names the two compiler behaviours (`!Gis` / `-Gis`) that forced this, so a later reader knows why the text is not simply `a == a`. ## What this does not establish The whole point is what FXC and DXC emit, and this check compares emitted text and evaluates it on the CPU — the compiler side rests on the measurements in the description. `x != x` folding under DXC without `-Gis` is asserted there, not re-measured here; I have no DXC in this environment. That limitation is the honest one for this PR, and it is stated. ## Verdict Reviewed. Six behaviours, seven mutations, all caught, and the neighbouring check keeps its teeth. ## Notes - AI-assisted review.
Author
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-24 22:21 UTC · original

Hardware run of head 583178d4 on two GPU families the PR text does not list, plus WARP. Windows 11 Pro 26100.9168, DXC and FXC from Windows SDK 10.0.26100, dev preset, debug layer unavailable here. The adapter was selected with XBOX2WINDOWS_ADAPTER.

Adapter Driver startup_gfx2hlsl_f32_nan_* startup_gfx2hlsl_f32_lg_*
WARP 10.0.26100.8972 Passed Passed
NVIDIA Quadro M1000M (Maxwell, 10de:13b1) 32.0.15.7371 Passed Passed
Intel HD Graphics 530 (Gen9, 8086:191b) 31.0.101.2111 Passed Passed
  • Device-free checks: startup_gfx2hlsl_f32_nan and startup_gfx2hlsl_f32_lg pass.
  • Controls: every "old text fails against the ieee/flushed image" control mismatched as required, on all three adapters.
  • The 70 recorded: observations (old and new text with and without /Gis, and "without the NaN bit test" under FXC and DXC) are identical across the three adapters. Each is "all 256 pixels matched", with the same denormal note.

LLVM 15 (local):

  • decode with LLVM-C.dll 15.0.7: PASS.
  • binary not run. My local llvm-mc is a stand-in over clang -cc1as, which does not support -show-encoding, so the failure there is mine, not the PR's.

No changes made.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-24 22:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1949#issuecomment-7146134199) Hardware run of head 583178d4 on two GPU families the PR text does not list, plus WARP. Windows 11 Pro 26100.9168, DXC and FXC from Windows SDK 10.0.26100, `dev` preset, debug layer unavailable here. The adapter was selected with `XBOX2WINDOWS_ADAPTER`. | Adapter | Driver | `startup_gfx2hlsl_f32_nan_*` | `startup_gfx2hlsl_f32_lg_*` | |---|---|---|---| | WARP | 10.0.26100.8972 | Passed | Passed | | NVIDIA Quadro M1000M (Maxwell, 10de:13b1) | 32.0.15.7371 | Passed | Passed | | Intel HD Graphics 530 (Gen9, 8086:191b) | 31.0.101.2111 | Passed | Passed | - **Device-free checks:** `startup_gfx2hlsl_f32_nan` and `startup_gfx2hlsl_f32_lg` pass. - **Controls:** every "old text fails against the ieee/flushed image" control mismatched as required, on all three adapters. - **The 70 `recorded:` observations** (old and new text with and without `/Gis`, and "without the NaN bit test" under FXC and DXC) are identical across the three adapters. Each is "all 256 pixels matched", with the same denormal note. **LLVM 15 (local):** - `decode` with `LLVM-C.dll` 15.0.7: PASS. - `binary` not run. My local `llvm-mc` is a stand-in over `clang -cc1as`, which does not support `-show-encoding`, so the failure there is mine, not the PR's. No changes made.
This discussion has been locked. Commenting is limited to contributors.
No description provided.