startup: lower v_pk_max_f16 and v_pk_min_f16 in gfx2hlsl (Part of #2022) #2927
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2927"
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 Leyukaka on 2026-11-26T21:31:40Z.
Part of #2022 (claim).
Change (
tools/startup/gfx2hlsl.py):v_pk_max_f16andv_pk_min_f16lower per lane throughpacked_half.Sources. Each source may be a single VGPR, a numeric SGPR (
S(), afterreject_lane_mask_data), a 32-bit hex literal or the inline0. It is read as a full word.op_sel[i]picks its low or high half for the low result, andop_sel_hi[i]for the high result, with defaults 0 and 1. This is the packed-source rule thattools/pixel_aot.pyimplements invop3p_f16_word.Result. It is the selected binary16 encoding of one input, so nothing goes through a float conversion.
minmax16_bitsin the preamble:(x & 0x7fff) > 0x7c00), not with a floatisnan();0x7e00when both are (that payload is not hardware-proven);-0below+0, so mixed zeros give-0for min and+0for max in either order.The one-NaN and signed-zero rules are those of
pixel_aot.py'sminmax16_num. Unlike it,minmax16_bitsworks on the encodings and returns0x7e00for two NaNs, whereminmax16_numreturns its second operand.Still refused:
vcc,exec, ranges, symbolic SGPRs);neg_lo,neg_hi,clampand other modifiers.v_pk_add/mul/fma_f16still take VGPRs only, and thepacked_halfdocstring now says which forms accept what.Tests (Windows 11, Python 3.14, DXC from the Windows SDK 10.0.26100, on main
6ee878d8plus this commit):tests/startup_gfx2hlsl_pk_minmax_check.py: ok. It checks:0, each with default, reversed and mixed selectors;... draw <dxc> <offscreen_check> warpandhardware: ok on WARP (Microsoft Basic Render Driver) and an NVIDIA GeForce RTX 5080. A source-built program is read back against a CPU reference, both halves separately, for:0with an explicit high selector;startup_gfx2hlsl_f16_alu_check,startup_translator_check,startup_gfx2hlsl_refusals_check,shader_signed_zero_minmax_check,docs_links_check,bidi_controls_check.Mutation checks, run by hand:
op_sel/op_sel_hiroles fails the controls and the WARP draw.Measured on a local capture (counts and instruction shape only):
v_pk_mul_f16with a literal source, which this PR keeps refused.v_pk_max_f16:v_pk_mul_f16literal.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T21:54:54Z.
Independent AMD RDNA 4 result on
3d848649: the emitted formula matches the reference on the card, and only a draw pins the helper body. Measurements only.The open point in
tools/startup/gfx2hlsl.pystays open: the two-NaN payload (0x7e00) has no hardware confirmation, and an AMD run cannot close it (see Limits). What the card adds is a second vendor for the draw, plus the three mutants below.Environment
10.0.26200.9974(build and UBR fromver).1002:7550, driver32.0.32029.2010; in-box WARP1414:008c, driver10.0.26100.9818.19.44.35230x64 (toolset14.44.35207), DXC1.9.2602.17, FXC10.0.26100.9457.debug_layer=unavailableon both adapters: no API validation in any run below.3d848649(base6ee878d8),git status --porcelain --untracked-files=noempty before the matrix and after every restore.Commands
XBOX2WINDOWS_ADAPTERis set with the quoted form, so the name carries no trailing space.Observed
startup_gfx2hlsl_pk_minmax_controls,_warp,_hardware(ctest -N, 3 entries);ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_pk_minmax' -V→100% tests passed out of 3. The hardware entry returned 0, not a 77 skip, and the renderer printed its adapter inside the draw log:selectorsgroup's max program at shift 0 (sources: a literal, an SGPR-held constant and an inline zero), all fourstoreOutputvalues are computed SSA values, none is an immediate. The readback therefore comes from the integer formula, not from a compile-time constant.ctest -R '^startup_gfx2hlsl_f16_alu'→ 4 entries,100% tests passed out of 4;tests/shader_signed_zero_minmax_check.py draw <dxc> <offscreen_check> hardwareexit 0. The WARP draw also returns 0 here, which reproduces your WARP result on a second machine.Three helper-body mutants (mine; the fixture documents a different set)
Each one edits
minmax16_bitsintools/startup/gfx2hlsl.py(Python, so no rebuild). For each: the applied hunk and the mutated sha256 are in the log, and aftergit checkout --the file's sha256 is back to1c1cec187e8401ec07291e13b1d224a9238cd11c2f124f780ff9d79b155aca38,git status --porcelain --untracked-files=nois empty, and the same draw returns 0 again.(a & 0x7fffu) > 0x7c00u→>= 0x7c00uon both operands (infinity read as NaN): controls exit 0, card draw exit 1 —nan_and_range_minshift 16,expected …4000fc00 actual …40007e00.0x7e00u→0x7c01u: controls exit 0, card draw exit 1 —nan_and_range_minshift 0,expected …40007e00,…40008001 actual …40007c01,…40008001(the third word, as a payload change should).if (b_nan) return a;→return 0x7dffu;: controls exit 0, card draw exit 1 —nan_and_range_minshift 0, second word40003c00→40007dff.The controls exit 0 on all three by construction:
controls()compares the emitted call sites (minmax16_bits(<args>, <flag>)) and the body comes from the shared preamble, which it never inspects. With mutant 2 applied, five Python control fixtures still exit 0 —startup_gfx2hlsl_pk_minmax_check.py,startup_gfx2hlsl_f16_alu_check.py,startup_translator_check.py,startup_gfx2hlsl_refusals_check.py,startup_gfx2hlsl_bit_alu_check.py.No test under
tests/*.pynamesminmax16_bits(findstr /s /c:"minmax16_bits" tests\*.pyreturns only the new fixture), and only a draw that calls it executes it.CI, precisely
pull_request: the Windows step runsctest --preset pr(.github/workflows/windows.yml:489), and that preset is an explicit include list inCMakePresets.jsonwith nopk_minmaxentry — so none of the three entries runs before merge.main:ctest --preset dev --no-tests=error --parallel 4 -E '_hardware$'(:494) runs_controlsand_warp;_hardwarestays excluded.tests/checks/python-linux/startup_gfx2hlsl_pk_minmax.txtandrun_checks_parallel.py --from-dir, with the bare path, and the fixture's no-argument mode iscontrols().So the helper body is pinned by nothing before merge, and by the WARP draw after merge. Adding
startup_gfx2hlsl_pk_minmax_(controls|warp)to theprinclude regex would move that to the PR, one line.Limits
v_pk_min_f16; nothing here says the console instruction behaves like the helper.0x7e00and mutant 2 shows the draw enforces that constant instead of testing it against hardware. This run cannot settle it.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T05:00:42Z.
Review: APPROVED
Reviewed
3d84864956c7f9edec94545d8de1c2268371b37d. The Release main integration build passedstartup_gfx2hlsl_pk_minmax_(controls|warp|hardware). Checked half-selection validation, ordering of signed zero, and the one-NaN case. The canonical payload for two NaNs remains documented as unverified against the guest hardware. Independent Windows 11 26200.9974 testing used WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 where applicable. Required Windows CI passed.