shader: lower the binary16 rounding ops in pixel_aot #874

Merged
JB2WIN merged 1 commit from upstream-pr/881 into main 2026-11-23 15:43:32 +00:00
JB2WIN commented 2026-11-23 15:28:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T15:28:26Z.


Change

This is the second binary16 slice from #839. It follows the same rules as #854. tools/pixel_aot.py now lowers v_floor_f16, v_ceil_f16, v_trunc_f16 and v_rndne_f16 in the e32 and _e64 encodings.

  • Semantics: LLVM 15.0.7 VOP1Instructions.td L449-452 maps these four ops to ffloor, fceil, ftrunc and frint. frint rounds to nearest even under the default rounding mode.
  • Lowering: the operand goes through widen16, then the binary32 floor/ceil/trunc/round, then narrow16. HLSL round is DXIL Round_ne. The narrowing is exact because the rounded value of a finite half is itself a representable half.
  • Rules carried over from #854:
    • the operand must be proven finite;
    • the binary16 denormal entry profile must be explicit;
    • the result is computed at translation time as well, so chains stay provable;
    • the result is a half16 low half, read only by the audited readers;
    • clamp, omod and modifiers are refused.
  • Changed expectations: v_ceil_f16_e32 and v_rndne_f16_e32 sat in the rounding-mode neighbour list. They were only refused there because the entry profile was unknown, not because the form was unsupported. They are replaced by v_fract_f16_e32 and v_rcp_f16_e32, which are still unsupported.
  • Still out of scope: v_fract_f16, because of its clamp near 1, plus min/max and the transcendental ops.

Refs #839. AI-assisted (Claude Code).

Verification

Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at fc89b9e.

  • Draw draw-f16-round (pixel_aot_f16_round_{hardware,warp}): results are read back as integers and compared with an independent reference. The cases cover:
    • ±0, and negative inputs that round to -0: trunc(-0.5), ceil(-0.3) and rndne(-0.4);
    • rndne halfway values at 0.5, 1.5, 2.5 and -2.5, and at ±1022.5 and ±1023.5, where the ulp is 0.5;
    • values from 1024 up, where the ulp is 1 or 2, including 2047, 2048, 2050 and 4094;
    • ±65504 and ± subnormals.
  • Reference: checked offline over every finite binary16 value for all four ops against Python struct/math/round, including the sign of zero.
  • Mutations: each was detected on both adapters:
    • floor and ceil swapped;
    • trunc replaced by floor on negative inputs;
    • rndne replaced by round-half-away;
    • the sign of a -0 result lost;
    • the source read from its high half.
  • Dev-time check (not committed): with the new branch disabled, the new controls fail inside check_f16_round_controls.
  • Commands:
    • ctest --preset dev --no-tests=error -R "^pixel_aot_f16_round_": 2/2 passed, 22.8 s on the RTX 3080.
    • Full ctest --preset dev --no-tests=error -j4: 453/453 passed. The only skips are capability skips.
    • The LLVM 15 binary round trip passes, with byte pins for the e32/e64 encodings. It runs locally through a clang -cc1as shim standing in for llvm-mc.
    • The controls, form_coverage_check.py (8 forms in both TSVs, 7 neighbours uncovered), rdna2_tools_check.py, pso_readiness_check.py and docs_links_check.py all pass.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6562698247 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/881). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T15:28:26Z. --- ## Change This is the second binary16 slice from #839. It follows the same rules as #854. `tools/pixel_aot.py` now lowers `v_floor_f16`, `v_ceil_f16`, `v_trunc_f16` and `v_rndne_f16` in the e32 and `_e64` encodings. - **Semantics:** LLVM 15.0.7 [`VOP1Instructions.td` L449-452](https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/llvm/lib/Target/AMDGPU/VOP1Instructions.td#L449-L452) maps these four ops to `ffloor`, `fceil`, `ftrunc` and `frint`. `frint` rounds to nearest even under the default rounding mode. - **Lowering:** the operand goes through `widen16`, then the binary32 `floor`/`ceil`/`trunc`/`round`, then `narrow16`. HLSL `round` is DXIL `Round_ne`. The narrowing is exact because the rounded value of a finite half is itself a representable half. - **Rules carried over from #854:** - the operand must be proven finite; - the binary16 denormal entry profile must be explicit; - the result is computed at translation time as well, so chains stay provable; - the result is a `half16` low half, read only by the audited readers; - `clamp`, omod and modifiers are refused. - **Changed expectations:** `v_ceil_f16_e32` and `v_rndne_f16_e32` sat in the rounding-mode neighbour list. They were only refused there because the entry profile was unknown, not because the form was unsupported. They are replaced by `v_fract_f16_e32` and `v_rcp_f16_e32`, which are still unsupported. - **Still out of scope:** `v_fract_f16`, because of its clamp near 1, plus `min`/`max` and the transcendental ops. Refs #839. AI-assisted (Claude Code). ## Verification Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at `fc89b9e`. - **Draw `draw-f16-round`** (`pixel_aot_f16_round_{hardware,warp}`): results are read back as integers and compared with an independent reference. The cases cover: - ±0, and negative inputs that round to -0: `trunc(-0.5)`, `ceil(-0.3)` and `rndne(-0.4)`; - `rndne` halfway values at 0.5, 1.5, 2.5 and -2.5, and at ±1022.5 and ±1023.5, where the ulp is 0.5; - values from 1024 up, where the ulp is 1 or 2, including 2047, 2048, 2050 and 4094; - ±65504 and ± subnormals. - **Reference:** checked offline over every finite binary16 value for all four ops against Python `struct`/`math`/`round`, including the sign of zero. - **Mutations:** each was detected on both adapters: - `floor` and `ceil` swapped; - `trunc` replaced by `floor` on negative inputs; - `rndne` replaced by round-half-away; - the sign of a -0 result lost; - the source read from its high half. - **Dev-time check (not committed):** with the new branch disabled, the new controls fail inside `check_f16_round_controls`. - **Commands:** - `ctest --preset dev --no-tests=error -R "^pixel_aot_f16_round_"`: 2/2 passed, 22.8 s on the RTX 3080. - Full `ctest --preset dev --no-tests=error -j4`: 453/453 passed. The only skips are capability skips. - The LLVM 15 binary round trip passes, with byte pins for the e32/e64 encodings. It runs locally through a `clang -cc1as` shim standing in for `llvm-mc`. - The controls, `form_coverage_check.py` (8 forms in both TSVs, 7 neighbours uncovered), `rdna2_tools_check.py`, `pso_readiness_check.py` and `docs_links_check.py` all pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:13 +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!874
No description provided.