Skip to content

shader: lower v_cvt_f16_u16, v_cvt_f16_i16, v_cvt_u16_f16 and v_cvt_i16_f16 in the direct compute path - #3159

Merged
tedin7 merged 2 commits into
R0Y00:mainfrom
legacy-code-archaeologist:shader/direct-cvt-f16-i16
Nov 27, 2026
Merged

tedin7 merged 2 commits into
R0Y00:mainfrom
legacy-code-archaeologist:shader/direct-cvt-f16-i16

Conversation

@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor

Lowers v_cvt_f16_u16, v_cvt_f16_i16, v_cvt_u16_f16, and v_cvt_i16_f16 (VOP1 and VOP3A) in the direct C++ compute path (src/gfx1013_direct_compute.inl), preserving D[31:16] and enforcing the binary16 MODE contract via half_binary.

Verification

Measured on Windows 10.0.26100 (dev preset) at upstream/main 429f11d5 + 6772a597:

  • ctest --preset dev --no-tests=error -R '^native_cvt_f16_i16_' -V:
    • native_cvt_f16_i16_ir (passed, 1.09s): evaluates DXIL IR via native_compute_ir_dump across 82 conversion cases (VGPR, SGPR, literal, inline ints/floats, VOP3 clamp/abs/neg/-|x|, RNE ties, saturation, subnormals, infinities, NaNs, non-zero upper halves) and 38 refusals (DPP, SDWA, omod, op_sel, illegal abs/neg/clamp, src1, and MODE writes).
    • native_cvt_f16_i16_controls (passed, 3.84s): compiles all 82 conversions to DXIL via compile_dxil and verifies all 38 refusals.
    • native_cvt_f16_i16_hardware (skipped, exit 77): Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback is not measured.
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 47/47 passed (54.43s).
  • python -B tests/docs_links_check.py: passed (101 Markdown files, 589 links).
  • Broken-lowering sensitivity check: 5 deliberate mutations (zero_high_half, drop_ordered_nan, swap_signed, drop_clamp, wrong_inline_float) each failed native_cvt_f16_i16_ir (exit 1).

Fixes #3148
Refs #2935

AI-assisted.

…16_f16 in direct compute

Lower VOP1 and VOP3A v_cvt_f16_u16, v_cvt_f16_i16, v_cvt_u16_f16 and v_cvt_i16_f16 in DirectCompute::float_alu() preserving D[31:16] on gfx10.

Int16/u16 -> f16 converts via sitofp/uitofp and packed_half_rne() round-to-nearest-even (with optional VOP3 clamp to [0.0, 1.0]); f16 -> i16/u16 widens via legacyF16ToF32, truncates toward zero, saturates to [-32768, 32767] / [0, 65535], maps NaN to 0, and supports VOP3 abs/neg.

Also add all four conversions to half_binary in DirectCompute::lower() so the default binary16 rounding/denormal MODE contract is enforced.

Fixes R0Y00#3148

Refs R0Y00#2935

AI-assisted.

@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 7adec5b (updated with main). Comment only.

The four conversions read inline float sources 240-248 as their binary16 values (the same nine constants as inline_half_words, which #3147 just made a shared member; the local halves[] copy here could use it in a follow-up), and literal and inline integer sources as their low 16 bits. f16 -> i16/u16 truncates through fptosi/fptoui only on an in-range value, saturates out-of-range values to the type bounds and maps NaN to 0; i16/u16 -> f16 goes through f32 and packed_half_rne, which is exact because every 16-bit integer is exact in f32. Unsupported forms (DPP, SDWA, omod, op_sel high half, modifiers on the integer source, an unknown rounding or denormal mode) are refused. native_cvt_f16_i16_ir checks 82 cases at the IR level without a GPU, so the semantics are covered on WARP hosts and in CI even though the _hardware leg skips.

src/gfx1013_direct_compute.inl is also changed on cpp-migration; this merges cleanly there and the native sweep passes on that merge (comment below).

Commands: git diff origin/main...pull/3159/head (read), git merge-tree --write-tree origin/cpp-migration pull/3159/head, plus the Windows commands in the comment below.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Windows Server 2025 verification of 7adec5b78f8c0467765ef7857bb4db10be3ed5f5 (D3D12 WARP, MSVC 14.44.35207):

  • dev: cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump; ctest --preset dev -R <native sweep>: 100% tests passed out of 143 (84 passed, 59 hardware legs skipped), including native_cvt_f16_i16_ir and native_cvt_f16_i16_controls
  • release: same targets with --preset release; ctest --preset release -R <native sweep>: 100% tests passed out of 143 (84 passed, 59 skipped)
  • The same dev and release sweep on this head merged with cpp-migration (a0f67731): 100% tests passed out of 143 in both presets

<native sweep> = every native_* test except native_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 9802008 into R0Y00:main Nov 27, 2026
5 checks passed
@xiaoqi72665

Copy link
Copy Markdown
Contributor

@legacy-code-archaeologist Thanks for #3159. During #3185's rebase regression on 5b145ca, the stock conversion hardware fixture reached its last guard assertion and raised AttributeError: module 'native_f16_alu_check' has no attribute 'SENTINEL' (tests/native_cvt_f16_i16_check.py). The preceding 82 conversion comparisons across both groups passed. With an ignored local diagnostic copy comparing the entire 2064-DWORD buffer to the expected conversion positions plus 0x69696969 guards, RX 7900 XT and app-local WARP passed in both Debug and Release on Win10. Suggested minimal fix: construct the full expected buffer (including zeros in the actual guard check), rather than filtering zero words. IR and compile controls also passed. No changes to your files in #3185. AI-assisted, tested locally by Buhe.

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: lower v_cvt_f16_u16, v_cvt_f16_i16, v_cvt_u16_f16 and v_cvt_i16_f16 in the direct compute path

3 participants