Skip to content

shader: map inline binary16 float constants in v_floor/ceil/trunc/rndne_f16 - #3322

Merged
tedin7 merged 3 commits into
R0Y00:mainfrom
R0D4X:fix/native-round-f16-inline
Nov 28, 2026
Merged

tedin7 merged 3 commits into
R0Y00:mainfrom
R0D4X:fix/native-round-f16-inline

Conversation

@R0D4X

@R0D4X R0D4X commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #3318. Refs #2935.

What this changes

  • Maps inline float constants (src0 in 240..248) through inline_half_words[r - 240] in the v_floor_f16, v_ceil_f16, v_trunc_f16, and v_rndne_f16 lowering in src/gfx1013_direct_compute.inl (matching v_frexp_mant_f16/v_frexp_exp_i16_f16), instead of truncating the f32 bit pattern.
  • Adds if (graphics_input) return false; to the binary16 rounding block and tightens tests/cmake/native_round_f16.cmake to TARGET compile_dxil AND TARGET native_store_replay.

Tests & docs updated

  • tests/native_round_f16_check.py: adds an inline-constant batch (0.5, -0.5, 1.0, -1.0, 2.0, -2.0, 4.0, 1/(2*pi) = 0x3118) across all four opcodes, DXIL constant checks (14336, 12568), and an inline_as_zero negative control.
  • docs/experiments/native-round-f16.md: documents inline binary16 float constant coverage.

Verification

  • Commit: 13059b79
  • Environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK / DXC 10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2140).
  • ctest --preset dev --no-tests=error -R '^native_round_f16_|^native_frexp_f16_' -V: 5/5 passed (0 skipped).
  • ctest --preset release --no-tests=error -R '^native_round_f16_|^native_frexp_f16_': 5/5 passed (0 skipped).
  • tests/docs_links_check.py & tests/bidi_controls_check.py: passed.

Scope: covers synthetic direct-DXIL compute fixtures for v_floor_f16, v_ceil_f16, v_trunc_f16, and v_rndne_f16 only; does not establish full-game execution.

@Leyukaka

Copy link
Copy Markdown
Collaborator

Is excluding graphics stages here intentional?

if (graphics_input) return false; removes the only direct DXIL lowering of v_floor_f16, v_ceil_f16, v_trunc_f16 and v_rndne_f16 (src/gfx1013_direct_compute.inl 1506 on main). The direct graphics path sets graphics_input (src/gfx1013_direct_graphics.inl 1309) and calls alu.arithmetic (1989), so vertex and pixel stages that lower these ops on main would get direct DXIL lowering for v_floor_f16 (line 4021).

v_frexp_*_f16, v_fract_f16 and v_cvt_norm_*_f16 have no such guard, and tests/native_fract_f16_check.py compiles v_fract_f16 through gfx1013-container-ps. If the exclusion is intended, please give the reason and say that graphics stages now refuse these ops, both in the PR text and in the experiment note, and add a graphics-stage refusal control.

@R0D4X

R0D4X commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Good catch @Leyukaka — excluding graphics stages was unintentional. These four ops use pure integer bit manipulation with no FP16 mode dependence and already lower in direct graphics stages on main.

Removed if (graphics_input) return false; in f5cbd971 so this PR stays strictly scoped to mapping inline binary16 float constants 240..248 for both compute and graphics stages.

Re-verified on NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2140), Windows 11 (10.0.26300.9974), MSVC 19.44.35230, SDK DXC 10.0.26100.0:

  • ctest --preset dev --no-tests=error -R '^native_round_f16_' -V: 2/2 passed (0 skipped).
  • ctest --preset release --no-tests=error -R '^native_round_f16_' -V: 2/2 passed (0 skipped).

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 3df02e65 (the PR's own change is unchanged; the new head only merges current main).

What I checked:

  • src/gfx1013_direct_compute.inl: in the v_floor_f16 / v_ceil_f16 / v_trunc_f16 / v_rndne_f16 lowering, source operands 240..248 now read their binary16 pattern from inline_half_words[r - 240], the same table the neighbouring v_frexp_*_f16 lowering already uses. Before, the f32 bit pattern of the inline constant was truncated to 16 bits. Abs/neg modifiers are applied after the lookup, as before.
  • The 240..248 range matches the table size; other sources still use the masked operand.
  • Tests: native_round_f16_controls (the DXIL must contain the inline 0.5 and 1/(2*pi) f16 words) and native_round_f16_hardware (real D3D12 readback on WARP against a plain Python binary16 reference for the new inline-constant program as well as the main one; it ran and did not skip).
  • #3135 added the rounding lowering; no other open PR covers this slice.

Commands run:

  • Linux: git diff --check origin/main...HEAD clean, python3 -m py_compile tests/native_round_f16_check.py ok.
  • Windows Server 2025, D3D12 WARP 1.0.22, -R '^native_round_f16_(controls|hardware)$': dev 2/2 passed, release 2/2 passed.
  • Mutation 1 (the inline range starts at 241): native_round_f16_hardware fails at inline word 9 (got beef0000, expected beef3c00).
  • Mutation 2 (inline word sign flipped): both tests fail (DXIL check, and readback at inline word 8).

No blocking findings. The receipt follows in a separate comment.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head 3df02e6 after updating with main.

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target compile_dxil native_store_replay -- -j 6): 5.65s (configure 1.67s)
    • Test (ctest --preset dev -R '^native_round_f16_(controls|hardware)$' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (0.75s: native_round_f16_controls 0.37s, native_round_f16_hardware 0.38s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target compile_dxil native_store_replay -- -j 6): 31.91s (configure 1.59s)
    • Test (ctest --preset release -R '^native_round_f16_(controls|hardware)$' --parallel 6 --no-tests=error --output-on-failure): 2/2 passed (0.67s: native_round_f16_controls 0.30s, native_round_f16_hardware 0.30s)
  • sccache: 14/18 hits; wall 38.9s

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 93357dc into R0Y00:main Nov 28, 2026
5 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.

shader: map inline binary16 float constants in v_floor/ceil/trunc/rndne_f16

3 participants