Repository navigation
shader: record the pixel_aot binary16 denormal mode and draw an f16 subnormal control - #549
Merged
Merged
Conversation
…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.
roansystemlabs
force-pushed
the
f16/denorm-mode
branch
from
November 22, 2026 12:14
848d10a to
419f93b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #312. Builds on #363 (merged).
What
F16_DENORM_MODE = "preserve"intests/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_*_f16widens 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 (-denormonly setsfp32-denorm-mode).check_controls, so it also runs on the Linux Python job): pins the reference words, checks that the lowered body callswiden16andpack16_rne, and that it contains nof32tof16,f16tof32,half,min16floatorfloat16_t. If a future lowering switches to driver conversions or native halves, the mode-independence claim stops being true and this fails.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 isv_pk_add_f16on two normal inputs whose sum is the subnormal0x8001(following the DXILfaddFTZ text, as suggested in pixel_aot: make the denormal mode explicit and treat NaN payloads as vendor-dependent #312). Supplementary rows:v_pk_max_f16on the least (0x0001) and largest (0x03ff) binary16 subnormals,v_pk_mul_f16that produces the subnormal0x0200from normal inputs, andv_pk_fma_f16whose halves round to nearest even (0x05fe0002). The words go through the lossless integer readback, because0x80000200is a binary32 subnormal as a word. One preserve reference must pass under both-denorm preserveand-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
95728c7on075413d; rebased onto579f58fas419f93b, keeping both the DPPmust_rejectfrom #408 and the new call incheck_controls(the only conflict). Re-run there: CPU checks exit 0; 17 of the 18pixel_aot_*entries passed, andpixel_aot_predicate_rounding_hardwaretimed 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: exit 0.pixel_aot_e64_hardwarepassed in 9.6 s,pixel_aot_e64_warpin 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.bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp,cpu_aot_crypto_sha), 1 timeout:pixel_aot_predicate_rounding_hardwareat 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:
84018001 03ff0001 80000200 05fe0002vs expected84018000 00000000 80000000 00000000→pixel_mismatch, exit 1 (built into the test)pack16_rneflushes subnormal results → exported84018000 00000000 80000000 05fe0000→ exit 1widen16flushes subnormal inputs → exit 1f16tof32, or to declare a lane ashalf→ AssertionErrorNot claimed
FLOAT_MODEf16 bits are unmeasured; this records the harness assumption only.f32tof16and is not covered here.AI-assisted: prepared with an AI coding agent and reviewed by a human before posting.