shader: lower v_min_f16 and v_max_f16 in the direct compute path #3125
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3125"
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 R0D4X on 2026-11-27T16:16:38Z.
Fixes #3124. Refs #2935.
What this changes
v_min_f16(VOP20x3a/ VOP3A0x13a) andv_max_f16(VOP20x39/ VOP3A0x139) insrc/gfx1013_direct_compute.inlusing exact 32-bit integer IEEE-754 binary16 ordering while preservingD[31:16].-0.0h < +0.0h, implements IEEE-754minNum/maxNum(returning the non-NaN operand if one is NaN and canonical0x7e00if both are NaN), supports VOP3Aabs/negandclamp, and refuses unsupported modifiers (omod,op_sel, unusedsrc2).Tests & docs added
tests/native_minmax_f16_check.py&tests/cmake/native_minmax_f16.cmake:native_minmax_f16_controls: validates emitted integer DXIL (icmp slt i32/icmp sgt i32), refuses invalid modifiers, and verifies that theignore_signed_zero,propagate_nan,no_clamp, andzero_highnegative controls each differ.native_minmax_f16_hardware: dispatches 8 binary16 pairs (±0.0hin both orders, normals, subnormals,±Inf, single/dual NaN) across VOP2 and VOP3A with pre-seededD[31:16], matching 2048 result words and 16 sentinel guards.docs/experiments/native-minmax-f16.md: experiment note and reproduction commands.Verification
eeaa3d7810.0.26300.9974), MSVC19.44.35230, Windows SDK / DXC10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver32.0.16.2124).ctest --preset dev --no-tests=error -R '^native_minmax_f16_|^native_ldexp_' -V: 4/4 passed (0 skipped).ctest --preset release --no-tests=error -R '^native_minmax_f16_|^native_ldexp_': 4/4 passed (0 skipped).tests/docs_links_check.py&tests/bidi_controls_check.py: passed.Scope: covers synthetic direct-DXIL compute fixtures for
v_min_f16andv_max_f16only; does not establish full-game execution.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T18:09:19Z.
Review: COMMENTED
Review of
eeaa3d78(comment only, no Windows run yet).The ordering key (negative values mapped below -0, then a signed compare), the NaN handling and the kept D[31:16] read correctly to me.
One thing should change before merge: inline float constants.
half_srctakesoperand32(i, i.src[j])and keeps the low 16 bits, but for sources 240-248operand32returns the f32 bit pattern. For 0.5, 1.0, 2.0, 4.0 and their negatives that low half is 0, sov_max_f16 v4, 1.0, v3compares against +0 instead of 1.0h. Thev_add_f16block in the same file maps these sources throughhalves[]. Could you do the same, or refuse 240-248, and add an inline-constant case to the fixture? The same point was raised on #3135 and applies to #3123 and the merged #3120, so one follow-up could cover all of them.Command:
git diff origin/main...pull/3125/head -- src/(read), compared with thev_add_f16operand path insrc/gfx1013_direct_compute.inl.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T18:50:44Z.
Review: APPROVED
Correct lowering of
v_min_f16andv_max_f16using exact integer-based IEEE-754 binary16 ordering. The key function correctly handles signed zero ordering, NaN semantics (minNum/maxNum with canonical dual-NaN), VOP3A abs/neg/clamp, and properly rejects unsupported modifiers. Test suite covers all edge cases including ±0 ordering, subnormals, Inf, single/dual NaN, and negative controls. Approved.Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T00:02:58Z.
This PR shares the same inline float constant bug that tedin7 already flagged on this PR and on #3135:
half_srccallsoperand32(i, i.src[j])which returns f32 bit patterns for src 240-248 (e.g.,0x3f800000for 1.0), then masks the low 16 bits to get0. Sov_max_f16 v4, 1.0, v3compares against +0 instead of 1.0h. The fix is identical: map sources 240-248 through ahalves[]array like thev_add_f16block does (line ~1207-1212), or refuse them. Please add an inline-constant case to the fixture.Missing graphics guard. The v_add_f16 block has
if (graphics_input) return false;. Your new block lacks this, so direct compute lowering now applies to vertex/fragment shaders too. Add the same guard unless that's intentional.CMake guard. Same issue as #3135: uses
X2W_HAVE_DXCAPI AND EXISTS INTAKE_PYTHONinstead ofTARGET compile_dxil AND TARGET native_store_replay AND EXISTS .... Please match the pattern used by other native fragments.NaN vs Inf test coverage. The NaN check
(a & 0x7FFF) > 31744(> 0x7C00) correctly catches NaNs (exponent=0x1F, non-zero mantissa). But no source inCASEShas exponent=0x1F with zero mantissa (+Inf/-Inf), which should pass through min/max unchanged. Please add ±Inf to the fixture.VOP2 abs/neg not tested. The lowering supports
i.abs & (1u << j)andi.neg & (1u << j)for both sources, but the test program only runs VOP3A with neg/abs/clamp. Either test VOP2 forms with abs/neg or narrow the description.Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T00:54:51Z.
I tried merging
mainb1e92256intoeeaa3d78to clear the conflict, and did not push, because the merged tree fails an existing test.The conflict was textual only, in
src/gfx1013_direct_compute.inl. This PR'sv_min_f16/v_max_f16block and #3187'sv_fma_f16block were added at the same place, and both end in the same clamp-and-store tail. Keeping both blocks, each with its own tail, gives a tree that adds exactly this PR's 29 lines overmainand removes nothing. The local merge commit is6b89c0bc.devandreleasebuild.The failure:
native_f16_alu_irfails in Debug and in Release:tests/native_f16_alu_check.pyhas a refusal control from #2964,vop2(0x3a, 3, 257, 2)(VOP2v_min_f16), that expectsdirect DXIL lowering for v_min_f16. This PR now lowers that program, so the control's expectation no longer holds. The same control is at this PR's head (line 277), so I expect the head fails it on its own as well; I did not build the head alone to confirm.A possible direction (unconfirmed): point that refusal control at a binary16 op that is still unlowered, so it keeps checking the refusal path. That is your call, since it edits an existing test.
Other results on the merged tree:
native_*_f16*family,native_half_int_cvtandnative_direct_containerpass indevandrelease/O2. That includes this PR'snative_minmax_f16_*.native_{f16_alu,fma_f16,frexp_f16,minmax_f16,packed_f16_compute,packed_f16_pixel}_hardwarepass at-j 1in both presets, with no skips.dev, excludingstartup_audio_*, has 3 failures. The other two,native_rtv_variant_warpandstartup_compute_dispatch_native_warp, aremain's existingrevision.txtfailures since #2820.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T07:01:19Z.
Thanks for the min/max lowering. I reviewed
eeaa3d78, the current head, and the earlier review points aren't on the branch yet. Two things need fixing before this can merge, and one test gap would be worth closing:tests/native_f16_alu_check.pyhasvop2(0x3a, 3, 257, 2)expectingdirect DXIL lowering for v_min_f16(line 277 on this branch, 395 on current main). This PR lowers that program, sonative_f16_alu_irfails. pigalot's comment above measuredAssertionError: ('direct DXIL lowering for v_min_f16', 0, '')on the merged tree. CI missed it because the Windows job runs onlyctest --preset pr(41 tests, none of themnative_f16_aluornative_minmax). Could you point that control at a binary16 op that is still unlowered?half_srckeepsoperand32(i, i.src[j]) & 65535, but for sources 240-248constant32returns the f32 pattern (inline_float_words,0x3f800000for 1.0). Sov_max_f16 v4, 1.0, v3compares against +0h, and 1/(2π) becomes0xf983. Main'sv_fma_f16block maps these throughhalves[](0x3800, 0xb800, 0x3c00, ...). Either that or refusing 240-248 works, plus one inline-constant case (every fixture source is now a VGPR set byv_mov_lit).controlsdoesn't check results. It asserts only that'icmp slt i32 'and'icmp sgt i32 'appear in the dump, so a lowering with min and max swapped would still pass. Thereference() != reference(...)lines test only the Python model. Values are checked only by thehardwareleg, which skips on WARP and isn't in CI.Two earlier requests need no work. ±Inf is already a case (
(0x00007C00, 0x0000FC00)), and VOP2 has no abs/neg fields to test (DPP and SDWA are refused). Minor, and consistent with some existing blocks: there's no FP16 MODE check and nographics_inputguard, and the CMake guard doesn't testTARGET compile_dxil.On the conflict:
git merge-treeagainst mainbbf4687breports one file,src/gfx1013_direct_compute.inl, where #3187'sv_fma_f16block landed in the same spot. Your 29 lines still go in unchanged right before that block, giving +29/−0 against main (and +75/−0 together with #3123's block), so the rebase should be mechanical.This was a static review: code reading plus
git merge-tree. I didn't build or run anything.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-28T09:20:56Z.
Merged current
main(3f780716) and addressed all review points:tests/native_f16_alu_check.pyfromv_min_f16(now lowered by this PR) tov_sin_f16(vop1(0x60, 3, 257)), sonative_f16_alu_irpasses.240..248inhalf_srcthroughpacked_f16_inline_constant(halves[]) instead of truncating the f32 pattern, and added an inline-constant batch (240..247) totests/native_minmax_f16_check.pywith DXIL constant assertions and aninline_as_zeronegative control.if (graphics_input) return false;and tightened the CMake guard toTARGET compile_dxil AND TARGET native_store_replay AND EXISTS ${INTAKE_PYTHON}.Verified on NVIDIA GeForce RTX 5080 (
10de:2c02, driver32.0.16.2140), Windows 11 (10.0.26300.9974), MSVC19.44.35230, SDK DXC10.0.26100.0:ctest --preset dev --no-tests=error -R '^native_minmax_f16_|^native_f16_alu|^native_fma_f16_': 9/9 passed (0 skipped).ctest --preset release --no-tests=error -R '^native_minmax_f16_|^native_f16_alu|^native_fma_f16_': 9/9 passed (0 skipped).Ready for re-review!
Commit:
1442d8eaImported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T09:37:27Z.
Thanks for the quick turnaround. I re-reviewed
1442d8ea(git diff 3f780716 1442d8ea, since the fixes ride in the merge commit) and built its trial merge with main32dc3d7c(clang-cl cross-build, CPU legs under Wine, no GPU).Fixed from round 1
v_sin_f16(vop1(0x60, 3, 257)).native_f16_alu_check.py irpasses with435 results match the model; 39 refusals carry the named diagnostic.packed_f16_inline_constant. The inline program's DXIL has14336(0.5h) and17408(4.0h) 19 times each. Thegraphics_inputand CMake guards are in too, thanks.Still needs a change
controlschecks'15360' in dump and '16384' in dump. I changed the range test tor >= 240 && r <= 0, which turns the mapping off and brings the round-1 bug back.native_minmax_f16_check.py controlsstill exits 0, and the dump still has153609 times and16384once. The clamp lowering emits"15360", and the VGPR literal0x4000in the 246 case supplies16384. Asserting14336/17408instead would catch it (19 → 0). A CPU value check against the model, likenative_f16_alu_check.py ir, would be stronger."slt"/"sgt"in the min/maxcmpalso leavescontrolsat exit 0, so results are still checked only by thehardwareleg. One CPU value check would cover this and point 1. The omod refusal check does work: droppingi.scalefrom the refusal makescontrolsfail withAssertionError: ('omod', …).Minor: 248 (1/2π →
0x3118) is mapped but isn't inINLINE_CASES.docs/experiments/native-minmax-f16.mddoesn't mention inline constants yet.CI run 46130052346 passed on this head, but
ctest --preset prran 73 tests, andgrep -cfinds 0native_minmaxand 0native_f16_alulines in the Windows job log, so CI hasn't run these tests. The CPU legs pass for me. I couldn't check the GPU leg.git merge-tree --write-tree origin/main 1442d8eais clean against32dc3d7c.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-28T09:55:18Z.
Thanks for the thorough re-review @JohnConnorNPC! Addressed both points and the minor notes in
58468b35:native_minmax_f16_ir): Added anirleg intests/native_minmax_f16_check.py(registered intests/cmake/native_minmax_f16.cmakevianative_compute_ir_dump+native_f16_alu_check.interpret) that evaluates all 59 emitted results on CPU (32 main + 27 inline across all 9 inline float constants240..248) against the Python model, plus both modifier refusals. Turning off the inline mapping or swappingslt/sgtnow fails on CPU without requiring a GPU.248(1/(2*pi)->0x3118): ExtendedINLINE_CASESto all 9 inline constants240..248(3 ops each, 27 words/lane + 5 sentinel words/lane) and updatedcontrolsto assert14336(0.5h),17408(4.0h), and12568(0x3118), none of which appear outside the inline-constant mapping.docs/experiments/native-minmax-f16.mdto document inline float constants240..248andnative_minmax_f16_ir.Verified on NVIDIA GeForce RTX 5080 (
10de:2c02, driver32.0.16.2140), Windows 11 (10.0.26300.9974), MSVC19.44.35230, SDK DXC10.0.26100.0:ctest --preset dev --no-tests=error -R '^native_minmax_f16_|^native_f16_alu|^native_fma_f16_': 10/10 passed (0 skipped).ctest --preset release --no-tests=error -R '^native_minmax_f16_|^native_f16_alu|^native_fma_f16_': 10/10 passed (0 skipped).tests/docs_links_check.py&tests/bidi_controls_check.py: passed.Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T18:05:47Z.
Review: APPROVED
GPU review of
58468b35.v_pk_min_f16rules: one NaN returns the other operand, two NaNs return0x7E00,-0orders below+0, clamp as before; SDWA, DPP, omod, op_sel and src2 are refused.maind418f70ewith this PR and 11 other open PRs merged locally:native_minmax_f16_ir,_controls,_hardware,native_f16_alu_irandnative_f16_alu_hardwarepass. Changing the one-NaN select (select(a_nan, b, ...)→select(a_nan, a, ...)) makesnative_minmax_f16_irandnative_minmax_f16_hardwarefail.Not covered: no FP16 denorm/MODE refusal as
v_pk_min_f16has; no input reaches it today because accepted MODE writes are forced to the default.Approve.