shader: record the pixel_aot binary16 denormal mode and draw an f16 subnormal control #543

Merged
roansystemlabs merged 2 commits from upstream-pr/549 into main 2026-11-22 12:21:46 +00:00
roansystemlabs commented 2026-11-22 10:47:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-22T10:47:59Z.


Refs #312. Builds on #363 (merged).

What

  • F16_DENORM_MODE = "preserve" in tests/pixel_aot_check.py, recorded as the harness assumption (as #363 does for f32), with the reason it holds by construction: v_pk_*_f16 widens each half from its encoding (widen16), computes in binary32 and narrows in integer arithmetic (pack16_rne). Every binary16 subnormal, and every product or sum of two, is a binary32 normal, so a binary32 flush cannot reach it, and DXIL has no f16 denormal attribute (-denorm only sets fp32-denorm-mode).
  • CPU-side control (called from check_controls, so it also runs on the Linux Python job): pins the reference words, checks that the lowered body calls widen16 and pack16_rne, and that it contains no f32tof16, f16tof32, half, min16float or float16_t. If a future lowering switches to driver conversions or native halves, the mode-independence claim stops being true and this fails.
  • Draw control in pixel_aot_e64_{hardware,warp}, next to the f32 control from #363. The required row is v_pk_add_f16 on two normal inputs whose sum is the subnormal 0x8001 (following the DXIL fadd FTZ text, as suggested in #312). Supplementary rows: v_pk_max_f16 on the least (0x0001) and largest (0x03ff) binary16 subnormals, v_pk_mul_f16 that produces the subnormal 0x0200 from normal inputs, and v_pk_fma_f16 whose halves round to nearest even (0x05fe0002). The words go through the lossless integer readback, because 0x80000200 is a binary32 subnormal as a word. One preserve reference must pass under both -denorm preserve and -denorm ftz; a reference that flushes binary16 subnormals must fail.
  • docs/experiments.md: one paragraph with the assumption, the control and its limits.

This is narrower than the per-fixture f16 mode I offered in #312: no fixture asks for f16 FTZ today, and the lowering cannot produce it, so an explicit flush in the emitted HLSL would have no user yet. It can be added with the first fixture that needs it.

Test

Measured at commit 95728c7 on 075413d; rebased onto 579f58f as 419f93b, keeping both the DPP must_reject from #408 and the new call in check_controls (the only conflict). Re-run there: CPU checks exit 0; 17 of the 18 pixel_aot_* entries passed, and pixel_aot_predicate_rounding_hardware timed out at 60 s with other load on the machine, then passed alone in 59.9 s. Windows 11 (26200), NVIDIA GeForce RTX 3070 driver 32.0.16.2101, WARP 10.0.26100.9818, DXC 10.0.26100.0, D3D12 debug layer enabled.

python -B tests/pixel_aot_check.py
ctest --preset dev --no-tests=error -R "^pixel_aot_e64_(hardware|warp)$" -V
ctest --preset dev --no-tests=error
  • python -B tests/pixel_aot_check.py: exit 0.
  • pixel_aot_e64_hardware passed in 9.6 s, pixel_aot_e64_warp in 2.5 s, debug_errors=0 debug_warnings=0. The new draw, including its negative case, takes about 1.0 s on the RTX 3070 and 0.35 s on WARP.
  • Full suite: 249 passed, 4 skipped (bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp, cpu_aot_crypto_sha), 1 timeout: pixel_aot_predicate_rounding_hardware at the 60 s limit. This PR does not touch that test; run alone it passes in 55.3 s on this machine, which looks like the per-case device cost in #448.

Negative controls, each observed failing on both adapters:

  • flushed f16 reference: exported 84018001 03ff0001 80000200 05fe0002 vs expected 84018000 00000000 80000000 00000000 → pixel_mismatch, exit 1 (built into the test)
  • one bit flipped in the expected v14 word → exit 1
  • translator mutated so pack16_rne flushes subnormal results → exported 84018000 00000000 80000000 05fe0000 → exit 1
  • translator mutated so widen16 flushes subnormal inputs → exit 1
  • CPU side: lowering mutated to call f16tof32, or to declare a lane as half → AssertionError

Not claimed

  • The Scarlett FLOAT_MODE f16 bits are unmeasured; this records the harness assumption only.
  • The compressed-export path narrows with the driver's f32tof16 and is not covered here.
  • f64 stays out of scope, as approved.

AI-assisted: prepared with an AI coding agent and reviewed by a human before posting.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6541476635 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/549). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-22T10:47:59Z. --- Refs #312. Builds on #363 (merged). ## What - `F16_DENORM_MODE = "preserve"` in `tests/pixel_aot_check.py`, recorded as the harness assumption (as #363 does for f32), with the reason it holds by construction: `v_pk_*_f16` widens each half from its encoding (`widen16`), computes in binary32 and narrows in integer arithmetic (`pack16_rne`). Every binary16 subnormal, and every product or sum of two, is a binary32 normal, so a binary32 flush cannot reach it, and DXIL has no f16 denormal attribute (`-denorm` only sets `fp32-denorm-mode`). - CPU-side control (called from `check_controls`, so it also runs on the Linux Python job): pins the reference words, checks that the lowered body calls `widen16` and `pack16_rne`, and that it contains no `f32tof16`, `f16tof32`, `half`, `min16float` or `float16_t`. If a future lowering switches to driver conversions or native halves, the mode-independence claim stops being true and this fails. - Draw control in `pixel_aot_e64_{hardware,warp}`, next to the f32 control from #363. The required row is `v_pk_add_f16` on two normal inputs whose sum is the subnormal `0x8001` (following the DXIL `fadd` FTZ text, as suggested in #312). Supplementary rows: `v_pk_max_f16` on the least (`0x0001`) and largest (`0x03ff`) binary16 subnormals, `v_pk_mul_f16` that produces the subnormal `0x0200` from normal inputs, and `v_pk_fma_f16` whose halves round to nearest even (`0x05fe0002`). The words go through the lossless integer readback, because `0x80000200` is a binary32 subnormal as a word. One preserve reference must pass under both `-denorm preserve` and `-denorm ftz`; a reference that flushes binary16 subnormals must fail. - `docs/experiments.md`: one paragraph with the assumption, the control and its limits. This is narrower than the per-fixture f16 mode I offered in #312: no fixture asks for f16 FTZ today, and the lowering cannot produce it, so an explicit flush in the emitted HLSL would have no user yet. It can be added with the first fixture that needs it. ## Test Measured at commit `95728c7` on `075413d`; rebased onto `579f58f` as `419f93b`, keeping both the DPP `must_reject` from #408 and the new call in `check_controls` (the only conflict). Re-run there: CPU checks exit 0; 17 of the 18 `pixel_aot_*` entries passed, and `pixel_aot_predicate_rounding_hardware` timed out at 60 s with other load on the machine, then passed alone in 59.9 s. Windows 11 (26200), NVIDIA GeForce RTX 3070 driver 32.0.16.2101, WARP 10.0.26100.9818, DXC 10.0.26100.0, D3D12 debug layer enabled. python -B tests/pixel_aot_check.py ctest --preset dev --no-tests=error -R "^pixel_aot_e64_(hardware|warp)$" -V ctest --preset dev --no-tests=error - `python -B tests/pixel_aot_check.py`: exit 0. - `pixel_aot_e64_hardware` passed in 9.6 s, `pixel_aot_e64_warp` in 2.5 s, `debug_errors=0 debug_warnings=0`. The new draw, including its negative case, takes about 1.0 s on the RTX 3070 and 0.35 s on WARP. - Full suite: 249 passed, 4 skipped (`bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp`, `cpu_aot_crypto_sha`), 1 timeout: `pixel_aot_predicate_rounding_hardware` at the 60 s limit. This PR does not touch that test; run alone it passes in 55.3 s on this machine, which looks like the per-case device cost in #448. Negative controls, each observed failing on both adapters: - flushed f16 reference: exported `84018001 03ff0001 80000200 05fe0002` vs expected `84018000 00000000 80000000 00000000` → `pixel_mismatch`, exit 1 (built into the test) - one bit flipped in the expected v14 word → exit 1 - translator mutated so `pack16_rne` flushes subnormal results → exported `84018000 00000000 80000000 05fe0000` → exit 1 - translator mutated so `widen16` flushes subnormal inputs → exit 1 - CPU side: lowering mutated to call `f16tof32`, or to declare a lane as `half` → AssertionError ## Not claimed - The Scarlett `FLOAT_MODE` f16 bits are unmeasured; this records the harness assumption only. - The compressed-export path narrows with the driver's `f32tof16` and is not covered here. - f64 stays out of scope, as approved. AI-assisted: prepared with an AI coding agent and reviewed by a human before posting.
upstream-sync closed this pull request 2026-11-24 06:43:38 +00:00
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!543
No description provided.