Repository navigation
shader: read inline float sources as binary16 in v_frexp_mant_f16 and v_frexp_exp_i16_f16 - #3147
Conversation
… v_frexp_exp_i16_f16 The lowering masked the f32 pattern of an inline float (240-248) to its low 16 bits, so v_frexp_mant_f16 v3, 1.0 gave 0x0000 instead of 0x3800. Read the binary16 table that v_add_f16 already uses, now shared as inline_half_words, and add native_frexp_f16_ir, which evaluates the emitted IR for all nine constants without a GPU or DXC.
tedin7
left a comment
There was a problem hiding this comment.
Review of d8b40a7 (updated with main). Comment only.
This fixes the inline-constant gap I pointed out on #3123 and #3125 for the already merged #3120: v_frexp_mant_f16 / v_frexp_exp_i16_f16 now read sources 240-248 as their binary16 values, through a shared inline_half_words table that v_add_f16 also uses now (same nine values as its old local halves[], so that path is unchanged). The new native_frexp_f16_ir test needs no GPU: it evaluates the emitted IR for all nine inline constants, abs/neg/clamp forms and a VGPR source against frexp_f16, with two pinned rows independent of the lowering, so it runs in CI and on WARP hosts.
The change is in src/gfx1013_direct_compute.inl, which the cpp-migration branch also changes; it merges cleanly there and the native sweep passes on that merge too (comment below).
Windows results are in the comment below.
Commands: git diff origin/main...pull/3147/head (read), git merge-tree --write-tree origin/cpp-migration pull/3147/head, plus the Windows commands listed in the comment.
AI-assisted; commands listed were executed locally.
|
Windows Server 2025 verification of
AI-assisted; commands listed were executed locally. |
Refs #3120.
What this changes
v_frexp_mant_f16andv_frexp_exp_i16_f16insrc/gfx1013_direct_compute.inlread their source withand(operand32(src0), 65535). For an inline float (encodings 240–248),constant32returns the f32 bitpattern (
0x3f800000for 1.0), so the op saw the low half of that pattern,0x0000. As a resultv_frexp_mant_f16 v3, 1.0gave0x0000instead of0x3800, andv_frexp_exp_i16_f16 v3, 1.0gave0instead of
1.The fix makes an inline float read its binary16 value, as
v_add_f16already does in the same file. Thenine-entry table that
v_add_f16kept locally (halves[]) is now a shared member,inline_half_words,next to
inline_float_words, and both ops read it. Register, literal and integer-constant sources areunchanged, and so is
v_add_f16.Test added
native_frexp_f16_ir(tests/native_frexp_f16_check.py ir, registered intests/cmake/native_frexp_f16.cmake) needs no GPU and no DXC. It builds one compute container, dumps theIR with
native_compute_ir_dump, and evaluates lane 0 withinterpret()fromnative_f16_alu_check.py.It covers 22 results:
|-2.0|withclamp,-1.0and-1/(2pi);Each result keeps a seeded
D[31:16]. Two rows are pinned independently of the lowering:1and mantissa0x3800;1/(2pi)(0x3118) gives exponent0xfffeand mantissa0x3918.Verification
Commit
a7b31d1fon429f11d5. The tools were cross-built on Linux with clang-cl 19 and the xwin SDK(
ninja -j1 native_compute_ir_dump, Release). The checks ran with an embeddable Windows Python under Wine(Proton Experimental):
python -B tests/native_frexp_f16_check.py ir native_compute_ir_dump.exe:429f11d5): fails, 19 of 22 rows wrong. The first one is row 4,v_frexp_mant_f16 v3, 1.0: gotbeef0000, expectedbeef3800.22 results matched, inline floats read as binary16.recorded), rebuilt, and the check failed with the same 19 rows. After restoring the file (hash
matched) and rebuilding, it passed again.
python -B tests/native_f16_alu_check.py ir native_compute_ir_dump.exe: passes before and after,82 results match the model; 16 refusals carry the named diagnostic. This showsv_add_f16reads theshared table unchanged.
ctest -N --no-tests=error -R '^native_frexp_f16_': listsnative_frexp_f16_controls,native_frexp_f16_hardwareandnative_frexp_f16_ir.tests/docs_links_check.pyandtests/bidi_controls_check.py: pass.Not run:
native_frexp_f16_controls, because it callsdxc.exe.native_frexp_f16_hardware, because no GPU was used.A Windows reviewer can run all three with:
CI: the PR job runs the
prpresets. Their fixed test allowlist contains nonative_*test, and theprbuild preset does not buildnative_compute_ir_dump. So PR CI checks that the change compiles, notthe new test.
Scope: a synthetic direct-compute IR fixture for the inline-float source of these two ops only. It does
not establish full-game execution.
This PR was AI-assisted.