pixel_aot: build export16 on the integer binary16 helpers #2709

Merged
Ybucaille merged 1 commit from upstream-pr/2717 into main 2026-11-26 03:44:37 +00:00
Ybucaille commented 2026-11-26 03:23:28 +00:00 (Migrated from github.com)

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


Refs #614

Change

export16 in the pixel_aot preamble rounds a binary32 toward zero to a binary16 and widens it again. It used the driver conversions f32tof16 / f16tof32, and NVIDIA's Vulkan compiler folds f16tof32(f32tof16(x)) into x. The correction step then compares the input with itself, so the rounding is lost: draw-core-vulkan on NVIDIA read 3e14a000 instead of 3e148000 at pixel x=16 (reported on #614 and #2297).

It now uses the preamble's integer helpers: narrow16 (round to nearest even, from the encoding) and widen16, then steps the half back by one when it exceeds the input in magnitude. That is the same algorithm as before, but no driver conversion is left to fold. export16 moves below narrow16 so HLSL sees the declarations in order.

Edge cases, by reasoning: ±0 keeps its sign (no step); a value rounding up into the next binade steps back to the largest half of the lower binade; a finite value of 65520 or more gives 0x7c00 then 0x7bff (65504), as before; infinity stays infinity. Subnormal halves are exact, because widen16 cannot flush them.

Test

tests/pixel_aot_check.py draw-core-vulkan <dxc> <device> (Linux, DXC 1.10.2605.37):

device flag before after
NVIDIA RTX 3060 Laptop, 620.70.06 --allow-denorm-mismatch exit 1, pixel_mismatch x=16 y=0 exit 0
Intel UHD (TGL), ANV, Mesa 26.2.7 none exit 0 exit 0
lavapipe, Mesa 26.2.7 --allow-denorm-mismatch exit 0 exit 0

Negative control: with the step-back line removed, Intel exits 1 with pixel_mismatch x=16 y=0, so the draw does check the rounding.

Not run here: the D3D12 draw-core on Windows. A Windows Release run of pixel_aot_warp / pixel_aot_hardware (draw-core) would confirm that WARP and a GPU still match bit for bit; the reference values do not change, since the algorithm is the same.

docs/experiments.md: the Vulkan section now states the cause instead of a hypothesis.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6618808826 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2717). Originally posted by [Ybucaille](https://github.com/Ybucaille) on 2026-11-26T03:23:28Z. --- Refs #614 ## Change `export16` in the `pixel_aot` preamble rounds a binary32 toward zero to a binary16 and widens it again. It used the driver conversions `f32tof16` / `f16tof32`, and NVIDIA's Vulkan compiler folds `f16tof32(f32tof16(x))` into `x`. The correction step then compares the input with itself, so the rounding is lost: `draw-core-vulkan` on NVIDIA read `3e14a000` instead of `3e148000` at pixel x=16 (reported on #614 and #2297). It now uses the preamble's integer helpers: `narrow16` (round to nearest even, from the encoding) and `widen16`, then steps the half back by one when it exceeds the input in magnitude. That is the same algorithm as before, but no driver conversion is left to fold. `export16` moves below `narrow16` so HLSL sees the declarations in order. Edge cases, by reasoning: ±0 keeps its sign (no step); a value rounding up into the next binade steps back to the largest half of the lower binade; a finite value of 65520 or more gives `0x7c00` then `0x7bff` (65504), as before; infinity stays infinity. Subnormal halves are exact, because `widen16` cannot flush them. ## Test `tests/pixel_aot_check.py draw-core-vulkan <dxc> <device>` (Linux, DXC 1.10.2605.37): | device | flag | before | after | |---|---|---|---| | NVIDIA RTX 3060 Laptop, 620.70.06 | `--allow-denorm-mismatch` | exit 1, `pixel_mismatch x=16 y=0` | exit 0 | | Intel UHD (TGL), ANV, Mesa 26.2.7 | none | exit 0 | exit 0 | | lavapipe, Mesa 26.2.7 | `--allow-denorm-mismatch` | exit 0 | exit 0 | Negative control: with the step-back line removed, Intel exits 1 with `pixel_mismatch x=16 y=0`, so the draw does check the rounding. Not run here: the D3D12 `draw-core` on Windows. A Windows Release run of `pixel_aot_warp` / `pixel_aot_hardware` (`draw-core`) would confirm that WARP and a GPU still match bit for bit; the reference values do not change, since the algorithm is the same. `docs/experiments.md`: the Vulkan section now states the cause instead of a hypothesis. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-26 04:04:31 +00:00
tedin7 commented 2026-11-26 04:04:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:32:16Z.

Review: COMMENTED


Review of head 861f1deb (comment only).

Checked:

  • export16 now uses narrow16 (round to nearest even) and widen16, then steps the half back by one when it exceeds the input in magnitude. Round-to-nearest-even is at most one step above the truncated value, so this gives round toward zero. Walked the edge cases: +/-0 (no step), round up into the next binade, finite value >= 65520 (0x7c00 -> 0x7bff = 65504), infinity (stays infinity), negative sign bit kept. All match the PR text.
  • export16 is moved below narrow16/widen16, so HLSL sees the declarations in order.
  • Sibling callers of export16 (mesh_shadow_check, mesh_lit_check, pixel_sample_lod_check, pixel_sample_offset_check, pixel_aot_check) use the preamble, so they exercise the new code.
  • docs/experiments.md text matches the change.

Commands run (Linux, PR head merged with current main, clean merge):

  • git diff --check origin/main...HEAD: clean
  • python3 tests/docs_links_check.py: ok
  • python3 tests/bidi_controls_check.py: ok

Not run here: DXC mutation of the helper (no DXC on this host). Behavior is guarded by the existing D3D12 WARP pixel_aot tests; Windows WARP run follows.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068188104 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2717#pullrequestreview-6068188104). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:32:16Z. **Review:** COMMENTED --- Review of head 861f1deb (comment only). Checked: - `export16` now uses `narrow16` (round to nearest even) and `widen16`, then steps the half back by one when it exceeds the input in magnitude. Round-to-nearest-even is at most one step above the truncated value, so this gives round toward zero. Walked the edge cases: +/-0 (no step), round up into the next binade, finite value >= 65520 (0x7c00 -> 0x7bff = 65504), infinity (stays infinity), negative sign bit kept. All match the PR text. - `export16` is moved below `narrow16`/`widen16`, so HLSL sees the declarations in order. - Sibling callers of `export16` (mesh_shadow_check, mesh_lit_check, pixel_sample_lod_check, pixel_sample_offset_check, pixel_aot_check) use the preamble, so they exercise the new code. - docs/experiments.md text matches the change. Commands run (Linux, PR head merged with current main, clean merge): - `git diff --check origin/main...HEAD`: clean - `python3 tests/docs_links_check.py`: ok - `python3 tests/bidi_controls_check.py`: ok Not run here: DXC mutation of the helper (no DXC on this host). Behavior is guarded by the existing D3D12 WARP pixel_aot tests; Windows WARP run follows. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:44:24Z.


Win2025 WARP receipt for head 861f1deb (PR head, 3 behind main).

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 861f1debbf6b0253c2dfeb6bcc67cac298d6088c:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target offscreen_check -- -j 2): 87.90s (configure 21.37s)
    • Test (ctest --preset dev -R '^(pixel_aot|pixel_sample|mesh_shadow|mesh_lit|pixel_compare)' --parallel 2 --no-tests=error --output-on-failure): 206/206 passed (252.28s: pixel_aot_bits_warp 12.96s, pixel_aot_warp 13.27s, pixel_aot_three_way_warp 4.72s, pixel_aot_buffer_color_warp 4.88s, pixel_aot_core_vector_warp 12.13s, pixel_aot_predicate_rounding_warp 7.23s, pixel_aot_sample_clamp_controls 0.91s, pixel_aot_sample_clamp_compile 2.52s, mesh_lit_draw_hardware 2.14s, pixel_aot_comparisons_warp 11.21s, mesh_lit_fallback_hardware 1.90s, `mesh_
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target offscreen_check -- -j 2): 252.29s (configure 3.70s)
    • Test (ctest --preset release -R '^(pixel_aot|pixel_sample|mesh_shadow|mesh_lit|pixel_compare)' --parallel 2 --no-tests=error --output-on-failure): 206/206 passed (179.56s: pixel_aot_bits_warp 7.88s, pixel_aot_warp 8.23s, pixel_aot_three_way_warp 4.11s, pixel_aot_core_vector_warp 4.65s, pixel_aot_buffer_color_warp 3.68s, pixel_aot_predicate_rounding_warp 4.63s, pixel_aot_sample_clamp_controls 0.52s, pixel_aot_sample_clamp_compile 1.56s, mesh_lit_draw_hardware 0.85s, pixel_aot_comparisons_warp 4.13s, mesh_lit_fallback_hardware 1.04s, `mesh_
  • Windows Python checks: tests/form_coverage_check.py ok (14.4s), tests/mesh_clip_cull_check.py ok (4.5s), tests/mesh_dynamic_geometry_check.py ok (0.3s), tests/mesh_heap_sampler_check.py ok (0.7s), tests/pso_readiness_check.py ok (0.9s), tests/rdna2_tools_check.py ok (2.8s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.3s), tests/startup_gfx2hlsl_cvt_pk_int16_check.py ok (0.3s), tests/startup_gfx2hlsl_f32_lg_check.py ok (1.5s), tests/startup_gfx2hlsl_f32_nan_check.py ok (5.5s), tests/startup_gfx2hlsl_scalar_null_check.py ok (0.3s), `tests/startup
  • sccache: 26/1250 hits; wall 605.4s

Commands: x2w_pipe.py win2025 2717 --no-skip-build --targets offscreen_check --regex pixel_aot|pixel_sample|mesh_shadow|mesh_lit|pixel_compare (dev + release).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181981458 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2717#issuecomment-7181981458). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:44:24Z. --- Win2025 WARP receipt for head 861f1deb (PR head, 3 behind main). Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `861f1debbf6b0253c2dfeb6bcc67cac298d6088c`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target offscreen_check -- -j 2`): `87.90s` (configure `21.37s`) - Test (`ctest --preset dev -R '^(pixel_aot|pixel_sample|mesh_shadow|mesh_lit|pixel_compare)' --parallel 2 --no-tests=error --output-on-failure`): **206/206 passed** (`252.28s`: `pixel_aot_bits_warp` `12.96s`, `pixel_aot_warp` `13.27s`, `pixel_aot_three_way_warp` `4.72s`, `pixel_aot_buffer_color_warp` `4.88s`, `pixel_aot_core_vector_warp` `12.13s`, `pixel_aot_predicate_rounding_warp` `7.23s`, `pixel_aot_sample_clamp_controls` `0.91s`, `pixel_aot_sample_clamp_compile` `2.52s`, `mesh_lit_draw_hardware` `2.14s`, `pixel_aot_comparisons_warp` `11.21s`, `mesh_lit_fallback_hardware` `1.90s`, `mesh_ - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target offscreen_check -- -j 2`): `252.29s` (configure `3.70s`) - Test (`ctest --preset release -R '^(pixel_aot|pixel_sample|mesh_shadow|mesh_lit|pixel_compare)' --parallel 2 --no-tests=error --output-on-failure`): **206/206 passed** (`179.56s`: `pixel_aot_bits_warp` `7.88s`, `pixel_aot_warp` `8.23s`, `pixel_aot_three_way_warp` `4.11s`, `pixel_aot_core_vector_warp` `4.65s`, `pixel_aot_buffer_color_warp` `3.68s`, `pixel_aot_predicate_rounding_warp` `4.63s`, `pixel_aot_sample_clamp_controls` `0.52s`, `pixel_aot_sample_clamp_compile` `1.56s`, `mesh_lit_draw_hardware` `0.85s`, `pixel_aot_comparisons_warp` `4.13s`, `mesh_lit_fallback_hardware` `1.04s`, `mesh_ - **Windows Python checks**: `tests/form_coverage_check.py` ok (`14.4s`), `tests/mesh_clip_cull_check.py` ok (`4.5s`), `tests/mesh_dynamic_geometry_check.py` ok (`0.3s`), `tests/mesh_heap_sampler_check.py` ok (`0.7s`), `tests/pso_readiness_check.py` ok (`0.9s`), `tests/rdna2_tools_check.py` ok (`2.8s`), `tests/startup_gfx2hlsl_cmp16_check.py` ok (`0.3s`), `tests/startup_gfx2hlsl_cvt_pk_int16_check.py` ok (`0.3s`), `tests/startup_gfx2hlsl_f32_lg_check.py` ok (`1.5s`), `tests/startup_gfx2hlsl_f32_nan_check.py` ok (`5.5s`), `tests/startup_gfx2hlsl_scalar_null_check.py` ok (`0.3s`), `tests/startup - `sccache`: 26/1250 hits; wall `605.4s` Commands: x2w_pipe.py win2025 2717 --no-skip-build --targets offscreen_check --regex pixel_aot|pixel_sample|mesh_shadow|mesh_lit|pixel_compare (dev + release). AI-assisted; commands listed were executed locally.
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!2709
No description provided.