shader: read inline float sources as binary16 in v_frexp_mant_f16 and v_frexp_exp_i16_f16 #3147
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3147"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-27T18:22:27Z.
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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T20:28:00Z.
Review: COMMENTED
Review of
d8b40a7681(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_f16now read sources 240-248 as their binary16 values, through a sharedinline_half_wordstable thatv_add_f16also uses now (same nine values as its old localhalves[], so that path is unchanged). The newnative_frexp_f16_irtest needs no GPU: it evaluates the emitted IR for all nine inline constants, abs/neg/clamp forms and a VGPR source againstfrexp_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 thecpp-migrationbranch 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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T20:28:02Z.
Windows Server 2025 verification of
d8b40a76814668bd39b63cf0da8cd567d3e133b5(D3D12 WARP, MSVC 14.44.35207):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 133 (77 passed, 56 hardware legs skipped), includingnative_frexp_f16_irandnative_frexp_f16_controls--preset release;ctest --preset release -R <native sweep>: 100% tests passed out of 133 (77 passed, 56 skipped)cpp-migration(a0f67731): 100% tests passed out of 133 in both presets<native sweep>= everynative_*test exceptnative_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR.AI-assisted; commands listed were executed locally.