Skip to content

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

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
roansystemlabs:f16/denorm-mode
Nov 22, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
roansystemlabs:f16/denorm-mode

Conversation

@roansystemlabs

@roansystemlabs roansystemlabs commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

What

  • F16_DENORM_MODE = "preserve" in tests/pixel_aot_check.py, recorded as the harness assumption (as shader: make the pixel_aot f32 denormal mode explicit and accept NaN by class #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 shader: make the pixel_aot f32 denormal mode explicit and accept NaN by class #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 pixel_aot: make the denormal mode explicit and treat NaN payloads as vendor-dependent #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 tests: pixel_aot draws spend most of their time creating a D3D12 device per case #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.

…ubnormal control

Refs R0Y00#312. Record F16_DENORM_MODE = preserve as the harness assumption. The packed f16
lowering widens halves from their encodings and narrows in integer arithmetic, and binary16
subnormals are binary32 normals, so -denorm cannot flush them; DXIL has no f16 denormal
attribute. A CPU-side control pins the lowering free of f32tof16/f16tof32 and native halves.
A draw runs a required v_pk_add_f16 row (normal + normal -> subnormal, per DXIL fadd FTZ) and
supplementary v_pk_max/mul/fma_f16 rows through the integer readback under -denorm preserve
and ftz against one preserve reference; a flushed reference must fail.
… are carried

The pixel_aot f16 denormal control counted widen16 and pack16_rne calls exactly, which would
fail on a harmless change to how the lowering reuses widened halves. Check that both helpers
are used and that no driver conversion or native 16-bit type (now including float16_t)
appears. Note in docs/experiments.md that the packed result is held as binary32 bits and only
reinterpreted by packed f16 consumers and the export.
@R0Y00
R0Y00 merged commit 915a9ee into R0Y00:main Nov 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants