shader: lower and verify RDNA2 binary32 floating-point vector comparisons #849

Merged
agilesh08 merged 2 commits from upstream-pr/855 into main 2026-11-23 14:31:40 +00:00
agilesh08 commented 2026-11-23 13:50:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-23T13:50:59Z.


## Change

Lowers and verifies all 16 RDNA2 binary32 floating-point vector comparison predicates (v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f32) across VOPC (_e32), VOP3 (_e64), and whole-dword SDWA forms in tools/pixel_aot.py:

  • Synthetic Fixture & IEEE-754 Oracle (tests/pixel_aot_check.py): Adds f32_compares() and f32_compares_reference() covering all 16 predicates across _e32 (vcc_lo), _e64 (s52/s53/vcc_lo), input modifiers (-s44, |s45|, s53, -|s44|), scalar literals, and whole-dword SDWA selections across ordered values, equal values, signed zeroes (+0.0 vs -0.0), quiet/signaling NaNs, infinities, and extreme exponents.
  • Negative Boundary Controls (tests/pixel_aot_check.py, tests/rdna2_tools_check.py): Rejects SGPR destinations on explicit _e32 ("VOPC e32 destination must be vcc"), unsupported modifiers (clamp, op_sel), sub-dword SDWA selections (src0_sel:WORD_0, src1_sel:BYTE_2), untracked registers, and exec-writing neighbours (v_cmpx_lt_f32_e32, v_cmpx_lt_f32_e64).
  • Coverage & ISA Classification (tests/form_coverage_check.py, tests/rdna2_tools_check.py, docs/experiments.md): Expands tracked comparison coverage from 122 to 156 forms across gfx1013.tsv and rdna2.tsv (adding 17 VOPC and 17 VOP3 binary32 forms) while asserting v_cmpx_lt_f32 remains excluded.

Verification

On Windows x64 (D:\XboxToWin repo\.venv\Scripts\python.exe -B):

  • python -B tests/form_coverage_check.py: passed (156 comparison forms validated across gfx1013.tsv and rdna2.tsv).
  • python -B tests/rdna2_tools_check.py: passed (75 tests passed).
  • python -B tests/pso_readiness_check.py: passed.
  • python -B tests/docs_links_check.py (13 files, 171 links) and python -B tests/bidi_controls_check.py (695 files): 0 errors.
  • Full suite of 23 platform-independent Python checks and git -c core.whitespace=cr-at-eol diff --check upstream/main: 23/23 passed, 0 errors.
  • Native DXC + WARP pixel execution runs in GitHub Actions windows.yml CI.

Evidence and follow-up

Uses 100% synthetic RDNA2 shader fixtures and an independent Python IEEE-754 reference oracle. No commercial binaries, game files, or copyrighted dumps are included.

Assisted by AI.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6560802609 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/855). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-23T13:50:59Z. --- ## Change Lowers and verifies all 16 RDNA2 binary32 floating-point vector comparison predicates (`v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f32`) across VOPC (`_e32`), VOP3 (`_e64`), and whole-dword SDWA forms in `tools/pixel_aot.py`: - **Synthetic Fixture & IEEE-754 Oracle (`tests/pixel_aot_check.py`):** Adds `f32_compares()` and `f32_compares_reference()` covering all 16 predicates across `_e32` (`vcc_lo`), `_e64` (`s52`/`s53`/`vcc_lo`), input modifiers (`-s44`, `|s45|`, `s53`, `-|s44|`), scalar literals, and whole-dword SDWA selections across ordered values, equal values, signed zeroes (`+0.0` vs `-0.0`), quiet/signaling NaNs, infinities, and extreme exponents. - **Negative Boundary Controls (`tests/pixel_aot_check.py`, `tests/rdna2_tools_check.py`):** Rejects SGPR destinations on explicit `_e32` (`"VOPC e32 destination must be vcc"`), unsupported modifiers (`clamp`, `op_sel`), sub-dword SDWA selections (`src0_sel:WORD_0`, `src1_sel:BYTE_2`), untracked registers, and exec-writing neighbours (`v_cmpx_lt_f32_e32`, `v_cmpx_lt_f32_e64`). - **Coverage & ISA Classification (`tests/form_coverage_check.py`, `tests/rdna2_tools_check.py`, `docs/experiments.md`):** Expands tracked comparison coverage from 122 to 156 forms across `gfx1013.tsv` and `rdna2.tsv` (adding 17 VOPC and 17 VOP3 binary32 forms) while asserting `v_cmpx_lt_f32` remains excluded. ## Verification On Windows x64 (`D:\XboxToWin repo\.venv\Scripts\python.exe -B`): - `python -B tests/form_coverage_check.py`: passed (156 comparison forms validated across `gfx1013.tsv` and `rdna2.tsv`). - `python -B tests/rdna2_tools_check.py`: passed (75 tests passed). - `python -B tests/pso_readiness_check.py`: passed. - `python -B tests/docs_links_check.py` (13 files, 171 links) and `python -B tests/bidi_controls_check.py` (695 files): 0 errors. - Full suite of 23 platform-independent Python checks and `git -c core.whitespace=cr-at-eol diff --check upstream/main`: 23/23 passed, 0 errors. - Native DXC + WARP pixel execution runs in GitHub Actions `windows.yml` CI. ## Evidence and follow-up Uses 100% synthetic RDNA2 shader fixtures and an independent Python IEEE-754 reference oracle. No commercial binaries, game files, or copyrighted dumps are included. Assisted by AI. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:45:06 +00:00
R0Y00 commented 2026-11-24 06:49:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T14:17:15Z.


I reproduced the comparison failures on WARP and pushed a focused fix. The reference now reinterprets integer immediates as binary32 bits (so 1 is not 1.0). With that corrected, the ordered -abs(NaN) <= 2.0 comparison still incorrectly set channel 1 bit 17 on WARP. The lowerer now classifies the source bits explicitly before accepting an ordered result. I also switched both instruction mutations to inputs that distinguish the changed predicate or modifier.

The full comparison draw passed on WARP and RTX 4060 Laptop, including a signaling NaN input, and the LLVM 15 binary/negative tests passed. The updated head is waiting for GitHub CI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7103768303 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/855#issuecomment-7103768303). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T14:17:15Z. --- I reproduced the comparison failures on WARP and pushed a focused fix. The reference now reinterprets integer immediates as binary32 bits (so 1 is not 1.0). With that corrected, the ordered -abs(NaN) <= 2.0 comparison still incorrectly set channel 1 bit 17 on WARP. The lowerer now classifies the source bits explicitly before accepting an ordered result. I also switched both instruction mutations to inputs that distinguish the changed predicate or modifier. The full comparison draw passed on WARP and RTX 4060 Laptop, including a signaling NaN input, and the LLVM 15 binary/negative tests passed. The updated head is waiting for GitHub CI.
thepatrickworld commented 2026-11-24 06:49:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-23T16:11:24Z.


pixel_aot_comparisons_hardware is red on RDNA4 at 041ca68; the cause is denormal flushing, not the comparator.

Environment: Windows 11 25H2 (build 26200.9711), MSVC 19.44 + DXC from VS 2022 BuildTools, adapter AMD Radeon RX 9070 XT (vendor 1002, device 7550), driver 32.0.32029.2010, debug_layer=unavailable, commit 041ca68 (ancestor of main a2da089).

Command and result:

ctest --preset dev --no-tests=error -R "^pixel_aot_"

93/94 passed in 295 s. The failure:

13/94 Test #326: pixel_aot_comparisons_hardware ...........***Failed    2.68 sec
AssertionError: Expected ['pass', 'mismatch', 'pass', ...],
                got      ['pass', 'mismatch', 'mismatch', ...]

pixel_aot_comparisons_warp passes on the same commit and the same build (6.05 s).

The case

Second case file of the batch (f32-cmp-1.case), the "equal values and signed zeros" set (+0.0, -0.0, -1.0, 1.0), channel 0 only:

expected_bits=0008cccc actual_bits=000ccccc

0x0008cccc ^ 0x000ccccc = 0x00040000 — only bit 18 differs. Every other bit, and every other channel, matches.

Bit 18 is the integer-literal case, v_cmp_eq_f32_e32 vcc_lo, 1, v16, lowered to:

bool cmp99 = ... && (asfloat(1u) == alu24);

(tools/pixel_aot.py; cmp99 in the generated source). asfloat(1u) is the subnormal 1.401298e-45; alu24 is the runtime rhs, here -0.0.

So the flag turns on whether 1.4e-45 == -0.0. The Python reference (word_to_float(1), with the comment "Integer immediates are interpreted as binary32 bits, not converted") says no, and WARP agrees. On this RDNA4 part, FP32 flushes subnormals to +0, and +0.0 == -0.0 is true, so the GPU sets the bit. The disagreement is FTZ, not the predicate, the encoding or the mask accumulation.

Two consequences

  1. The expectation only holds on a denormal-preserving implementation, so it cannot hold on the hardware this test is named for. The point of the case — that an integer immediate is a bit pattern, not a converted float — survives with a normal operand (the set already has 0x3f800000 at bit 21 for exactly that), or the flush can be made explicit in the lowering with the reference updated to match.
  2. For console fidelity the DXIL is the optimistic side. RDNA2 FP32 flushes the same way under a D3D-style API, so asfloat(1u) == x is probably not what the console computes either. I have not verified that on Scarlett silicon — it is an inference from this GPU and the shared FP32 mode — but if it holds, the fix belongs in the translator rather than in the fixture, and this test would have to encode the flushed behaviour.

The -bad- controls are fine: each one reports its injected channel, so they still isolate what they are meant to isolate.

Why CI does not see it

_hardware tests return 77 without a physical GPU, so a main that reads green can still be red on every RDNA machine. This is the first entry in that category I have found.

Reproduce with:

ctest --preset dev --no-tests=error -R '^pixel_aot_comparisons_hardware$' --output-on-failure

Happy to re-run this on the same adapter once the case is fixed, and to check the flushed reading against the rest of the comparison sets.

AI-assisted; the run and the HLSL inspection were executed locally on the adapter above. The FTZ reading and the line references come from a separate review pass and were reproduced here at 041ca68.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7106749285 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/855#issuecomment-7106749285). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-23T16:11:24Z. --- **`pixel_aot_comparisons_hardware` is red on RDNA4 at `041ca68`; the cause is denormal flushing, not the comparator.** Environment: Windows 11 25H2 (build 26200.9711), MSVC 19.44 + DXC from VS 2022 BuildTools, adapter **AMD Radeon RX 9070 XT** (vendor `1002`, device `7550`), driver `32.0.32029.2010`, `debug_layer=unavailable`, commit `041ca68` (ancestor of `main` `a2da089`). Command and result: ``` ctest --preset dev --no-tests=error -R "^pixel_aot_" ``` **93/94 passed in 295 s.** The failure: ``` 13/94 Test #326: pixel_aot_comparisons_hardware ...........***Failed 2.68 sec AssertionError: Expected ['pass', 'mismatch', 'pass', ...], got ['pass', 'mismatch', 'mismatch', ...] ``` `pixel_aot_comparisons_warp` passes on the same commit and the same build (6.05 s). ### The case Second case file of the batch (`f32-cmp-1.case`), the "equal values and signed zeros" set (`+0.0, -0.0, -1.0, 1.0`), channel 0 only: ``` expected_bits=0008cccc actual_bits=000ccccc ``` `0x0008cccc ^ 0x000ccccc = 0x00040000` — **only bit 18 differs.** Every other bit, and every other channel, matches. Bit 18 is the integer-literal case, `v_cmp_eq_f32_e32 vcc_lo, 1, v16`, lowered to: ```hlsl bool cmp99 = ... && (asfloat(1u) == alu24); ``` (`tools/pixel_aot.py`; `cmp99` in the generated source). `asfloat(1u)` is the subnormal `1.401298e-45`; `alu24` is the runtime rhs, here `-0.0`. So the flag turns on whether `1.4e-45 == -0.0`. The Python reference (`word_to_float(1)`, with the comment "Integer immediates are interpreted as binary32 bits, not converted") says no, and WARP agrees. On this RDNA4 part, FP32 flushes subnormals to `+0`, and `+0.0 == -0.0` is true, so the GPU sets the bit. The disagreement is FTZ, not the predicate, the encoding or the mask accumulation. ### Two consequences 1. **The expectation only holds on a denormal-preserving implementation**, so it cannot hold on the hardware this test is named for. The point of the case — that an integer immediate is a bit pattern, not a converted float — survives with a normal operand (the set already has `0x3f800000` at bit 21 for exactly that), or the flush can be made explicit in the lowering with the reference updated to match. 2. **For console fidelity the DXIL is the optimistic side.** RDNA2 FP32 flushes the same way under a D3D-style API, so `asfloat(1u) == x` is probably not what the console computes either. I have not verified that on Scarlett silicon — it is an inference from this GPU and the shared FP32 mode — but if it holds, the fix belongs in the translator rather than in the fixture, and this test would have to encode the flushed behaviour. The `-bad-` controls are fine: each one reports its injected channel, so they still isolate what they are meant to isolate. ### Why CI does not see it `_hardware` tests return 77 without a physical GPU, so a main that reads green can still be red on every RDNA machine. This is the first entry in that category I have found. Reproduce with: ``` ctest --preset dev --no-tests=error -R '^pixel_aot_comparisons_hardware$' --output-on-failure ``` Happy to re-run this on the same adapter once the case is fixed, and to check the flushed reading against the rest of the comparison sets. _AI-assisted; the run and the HLSL inspection were executed locally on the adapter above. The FTZ reading and the line references come from a separate review pass and were reproduced here at `041ca68`._
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
R0Y00/Xbox2Windows!849
No description provided.