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

Manually merged
github merged 2 commits from gh-pr/855/head into gh-pr/855/base 2026-11-26 22:23:46 +00:00
Owner

@⁠agilesh08 on GitHub · 2026-11-23 13:50 UTC · original
agilesh08:feat/shader-vopc-f32-compares → main · +288 −14 · 5 files · 2 commits · merged 2026-11-23 14:31 UTC

## 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.
**@⁠agilesh08** on GitHub · 2026-11-23 13:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/855) `agilesh08:feat/shader-vopc-f32-compares` → `main` · +288 −14 · 5 files · 2 commits · merged 2026-11-23 14:31 UTC ## 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.
Lower and verify the complete suite of 16 RDNA2 binary32 floating-point
vector comparisons (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 pixel_aot.

- Implement f32_compares() fixture in tests/pixel_aot_check.py exercising all
  16 predicates in e32 (vcc_lo) and e64 (s52/s53/vcc_lo) with input modifiers
  (-s44, |s45|, -|s44|), scalar literals, and whole-dword SDWA selections.
- Implement exact IEEE-754 reference oracle f32_compares_reference() and test
  against varied vector cases (ordered numbers, signed zeroes, NaNs, infinities).
- Verify negative controls: rejecting SGPR destinations on explicit e32,
  rejecting invalid modifiers (clamp, op_sel) on comparisons, rejecting
  untracked sources, sub-dword SDWA, and exec-writing neighbours (v_cmpx_*).
- Update tests/form_coverage_check.py to validate all 34 binary32 comparison forms
  (17 VOPC and 17 VOP3) in both gfx1013.tsv and rdna2.tsv (156 compare forms total).
- Extend tests/rdna2_tools_check.py with ISA categorization and instruction
  recognition tests for all 16 f32 comparison predicates.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:23:44 +00:00
github manually merged commit e114e89353 into gh-pr/855/base 2026-11-26 22:23:46 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 14:17 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-23 14:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/855#issuecomment-7103768303) 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.
Author
Owner

@⁠thepatrickworld on GitHub · 2026-11-23 16:11 UTC · original

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.

**@⁠thepatrickworld** on GitHub · 2026-11-23 16:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/855#issuecomment-7106749285) **`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`._
This discussion has been locked. Commenting is limited to contributors.
No description provided.