shader: lower v_min3_f16, v_max3_f16, and v_med3_f16 in direct Compute and Pixel DXIL #3268
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3268
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3266"
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?
@legacy-code-archaeologist on GitHub · 2026-11-28 02:49 UTC · original
legacy-code-archaeologist:shader/direct-minmax-med3-f16→main· +408 −1 · 3 files · 2 commits · merged 2026-11-29 13:21 UTCLowers VOP3
v_min3_f16(0x351),v_max3_f16(0x354), andv_med3_f16(0x357) in direct Compute and Pixel DXIL.Fixes #3266. Refs #2935.
Summary
src/gfx1013_direct_compute.inl:v_min3_f16,v_max3_f16, andv_med3_f16inDirectCompute::float_alu()withabs[2:0],neg[2:0],clamp(NaN/negative ->+0.0, positive subnormals preserved,> 0x3bff->1.0),op_sel[3:0](high-half source reads on VGPRs and destination high/low half placement preserving the other 16 bits ofvdst), VGPR/SGPR/literal/inline sources, exact 16-bit signed-zero (-0.0 < +0.0) and NaN ordering (includingv_med3_f16returningminof numeric inputs when any input is NaN), and the binary16 denormal mode gate ((mode_bits & 0xc0u) == 0xc0u).omod, high-halfop_selon non-VGPR sources, special scalar sources (106..127/253), and non-default or unknown binary16 denormal modes (half_binary = trueinDirectCompute::lower()).tests/native_minmax_med3_f16_check.py,tests/cmake/native_minmax_med3_f16.cmake:24cases across all 3 opcodes: all 6 distinct permutations ofmed3_f16, signed zeros (-0.0/+0.0), binary16 subnormals and±Inf, 1/2/3-NaN inputs,abs/neg,clamp,op_sel[3:0]with0xDEADCAFEdestination half preservation, SGPR/literal/inline sources, and partialEXEC_LO(0xAAAAAAAA) lane preservation.7refusals:omod != 0, high-halfop_selon SGPR and inline float constants,vcc_losource,s_denorm_mode 0x3, and conditionalMODEwrite.Verification (
devandrelease/O2, Windows10.0.26100)ctest --preset dev --no-tests=error -V -R '^native_minmax_med3_f16_'&ctest --preset release --no-tests=error -V -R '^native_minmax_med3_f16_':native_minmax_med3_f16_ir: Passed (24cases matched exact model;7refusals matched).native_minmax_med3_f16_controls: Passed (24cases compiled to DXIL;7refusals verified).native_minmax_med3_f16_pixel_warp: Passed (Microsoft Basic Render Driver10.0.26100.9711,12pixel draws /24cases matched;debug_layer=unavailable).native_minmax_med3_f16_pixel_hardware: Passed (12pixel draws /24cases matched;NVIDIA Quadro M1000M,32.0.15.7371,debug_layer=unavailable).native_minmax_med3_f16_compute_hardware: Skipped (77) (Intel(R) HD Graphics 530, vendor8086, device191b, driver31.0.101.2111lacks SM 6.6 wave32 — needs testing on a wave32-capable GPU).ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 71/71 passed (0skips).rc=8): droppingany_naninv_med3_f16(med3_one_nan_uses_min), dropping high-halfop_sel & 8udestination placement (max3_opsel_dst_hi), and removingv_med3_f16fromhalf_binary = true(cond_modeunhandleds_denorm_mode) all failednative_minmax_med3_f16_ir.AI-assisted.
@Leyukaka on GitHub · 2026-11-28 04:27 UTC · original
I reviewed the diff (not run). I found nothing wrong in the lowering. There are three gaps in the fixture cases, though:
med3_clamp_nan_to_zerouses (0x7E01,0x8000,0x0000). With one NaN, med3 takes the min of the two numbers, -0. So the clamp sees0x8000, never a NaN, and theis_nan(result)term of the clamp is never true in any case.clampwould reach it: the pre-clamp result is0x7E00, which must clamp to +0.0x7E00would clamp to0x3c00(1.0).min3_clamp_neg_subnormaluses (0x0001,0x3800,0x3C00), which are all positive. The only negative value that reaches the clamp is -0, in the case above, although the fixture comment lists negative values, -0 and NaN.0x8001or0xBC00withclampwould check that its sign takes it to +0.is_nan(c)fromany_nanwould still pass every case.0x4200,0x3800,0x7E01) would catch it: the expected result is0x3800; without the term,0x4200.AI-assisted.
@pigalot on GitHub · 2026-11-28 04:40 UTC · original · requested changes
I reviewed
8223b4b7merged overmain240e0fb9. The merge is clean (treeab12c114) andgit diff --cached --checkis clean. I first ran everything overdbb933d1, then reran the builds and tests over240e0fb9, which addsv_pk_fmac_f16and the f16 rounding ops to the same file.I found nothing wrong with the lowering itself. Three of its terms have no case that tells them apart, though: two of Leyukaka's gaps (I reran both as mutants) and one more. I'm requesting the cases, not code changes.
What I traced. VOP3
0x351/0x354/0x357arev_min3_f16/v_max3_f16/v_med3_f16, and decode already names them. The lowering is integer selects on the 16-bit patterns, using the same order key and NaN rule asmain'sv_pk_min_f16/v_pk_max_f16:x ^ (x >= 0x8000 ? 0xffff : 0x8000)puts -0 below +0;0x7e00.v_med3_f16ismax(min(a, b), min(max(a, b), c)). If any input is NaN, it ismin3instead, as the RDNA 2 ISA pseudo-code forV_MED3defines.The rest:
+0, and anything above0x3bffto1.0;op_sel[3]places the result in the high half and keeps the other half ofvdst;op_selon a non-VGPR source, omod, DPP/SDWA and special scalar sources are refused;half_binary.What I ran. I built
compile_dxil native_store_replay offscreen_check native_compute_ir_dump native_global_srv_heap_replay native_compute_manifest_reasonsindevandrelease, then ran:_warptests skip with 77, the same WARP capability skips as onmain, in both Debug and Release/O2.native_minmax_med3_f16_ir,_controlsand_pixel_warppass.native_minmax_med3_f16_compute_hardwareruns here (it skipped on your Intel adapter), and so do_pixel_hardwareand the packed/f16 neighbours.tests/cmake/native_minmax_med3_f16.cmakeis new, somainregisters none of these tests.main'sv_pk_min/max_f16conventions; gfx1013 itself is not measured here.Mutants. Each was rebuilt in
dev, then I rannative_minmax_med3_f16_(ir|controls|pixel_warp|pixel_hardware|compute_hardware). The first twelve ran overdbb933d1; N1 and N2 ran over240e0fb9.x ^ 0x8000)max(min(a, b), c)nan or signchanged tonan and sign-0case)absignoredop_selsource reads the low halfor i1 false, sign)any_nanignores src2 (is_nan(a) or is_nan(b))193..208) sign-flipped(mode_bits & 0xc0) != 0xc0removedRestored and rebuilt afterwards;
git diff --quietis clean.Cases that would kill the survivors (expected values from the lowering as written):
med3_clamp_nan_to_zerohands it0x8000. For example,med3_three_nanswithclamp=1is0x7e00before the clamp and0x0000after it. Without the NaN term it is0x3c00.med3with a NaN only in src2.med3(0x4200, 0x3800, 0x7E01)gives0x3800. With N2 it gives0x4200.half_bitsmaps193..208to(192 - r) & 0xffff, and no case reads that branch: the only193in the test is the EXECs_mov.min3with src0 = inline-1(193), as the PR reads it0xffff, a NaN pattern, and0x3C00,0x4000gives0x3c00. With the sign flipped, src0 becomes0x0001, and the result is0x0001.Leyukaka's other point holds too, though no mutant isolates it. The only sign-set input that reaches the clamp is
-0. Aclampcase with a negative nonzero result, such as0xBC00, would pin the sign term for real negatives.Non-blocking: the in-op denormal gate can't be reached.
mode_bitsstarts at0xf0, and changes only throughconsume_half_mode. That function already refuses any MODE write that changes the binary16 bits whilehalf_binaryis set, so both refusal controls stop there. The same holds for the existingv_pk_min/max_f16gate. I'd keep the line as defence in depth; this survivor needs no case.Verdict: changes requested on
8223b4b7, for cases 1–3. I'll re-run the mutants on the new head.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32; I did not check the debug-layer status.
CI:
Build and test on Windowspasses on8223b4b7.This reply was AI-assisted.
@legacy-code-archaeologist on GitHub · 2026-11-28 05:14 UTC · original
Thanks @pigalot and @Leyukaka — added the 5 requested fixture cases to
tests/native_minmax_med3_f16_check.py(bringing the suite from 24 to 29 cases total, 28 non-partial Pixel cases across 14 draws):med3_nan_src2:med3(0x4200, 0x3800, 0x7E01) -> 0x3800med3_two_nans:med3(0x7E01, 0x3800, 0x7D02) -> 0x3800min3_clamp_negative:min3(0xBC00, 0x3800, 0x3C00)withclamp=1(-1.0 -> 0x0000)med3_three_nans_clamp:med3(0x7E01, 0x7D02, 0x7F03)withclamp=1(0x7E00 -> 0x0000)min3_inline_neg_int:min3(src0=193, 0x3C00, 0x4000) -> 0x3C00(193reads0xFFFFNaN)Verification (
devandreleasepresets):ctest --preset dev --no-tests=error --output-on-failure -j 1 -V -R '^native_minmax_med3_f16_':native_minmax_med3_f16_ir(29cases,7refusals),native_minmax_med3_f16_controls(29cases compiled,7refusals),native_minmax_med3_f16_pixel_warp(14draws /28cases), andnative_minmax_med3_f16_pixel_hardwarepassed;native_minmax_med3_f16_compute_hardwareskipped (77on local Intel HD Graphics 53031.0.101.2111lacking SM 6.6 wave32)ctest --preset release --no-tests=error --output-on-failure -j 1 -V -R '^native_minmax_med3_f16_':4passed,1skipped (77on Intel HD Graphics 530)Sensitivity mutant checks on
dev(native_minmax_med3_f16_ir):clamp: killed at slot 23 (med3_three_nans_clamp,0xdead3c00 != 0xdead0000)cfromany_naninv_med3_f16: killed at slot 14 (med3_nan_src2,0xdead4200 != 0xdead3800)193..208(192u - r->r - 192u): killed at slot 26 (min3_inline_neg_int,0xdead0001 != 0xdead3c00)AI-assisted.
bbab9bd2d4todf6c0545ea@legacy-code-archaeologist on GitHub · 2026-11-28 05:34 UTC · original
Rebased onto
upstream/main(d649e470) to resolve thesrc/gfx1013_direct_compute.inlconflict after #3271 merged, and re-verifiednative_minmax_med3_f16_*in bothdevandrelease:4passed (native_minmax_med3_f16_ir29 cases / 7 refusals,controls,pixel_warp14 draws / 28 cases,pixel_hardware),1skipped (native_minmax_med3_f16_compute_hardware77on local Intel HD Graphics 53031.0.101.2111lacking SM 6.6 wave32).AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-28 07:01 UTC · original
Thank you for the added cases. I reviewed
df6c0545merged locally into currentmain(bbf4687b). The merge is clean, with no conflict files andgit diff --checkempty. This is a comment, not a review state.Requested changes. All three cases from the review on
8223b4b7are on this head (med3_three_nans_clamp,med3_nan_src2,min3_inline_neg_int), and so is the negative-clamp case from the earlier comment (min3_clamp_negative). I rebuilt each mutant and ranctest -R '^native_minmax_med3_f16_(ir|controls)$'; every one now failsir:(23, 'med3_three_nans_clamp', '0xdead3c00', '0xdead0000')any_nanignores src2 →(14, 'med3_nan_src2', '0xdead4200', '0xdead3800')193..208sign flipped →(26, 'min3_inline_neg_int', '0xdead0001', '0xdead3c00')cmp("eq", result, "32768")) →(20, 'min3_clamp_negative', '0xdead3c00', '0xdead0000')op_sel[3]placement mutant →(24, 'max3_opsel_dst_hi', '0xdead4400', '0x4400cafe')On the unmodified merge,
native_minmax_med3_f16_irreports "29 cases matched exact model; 7 refusals matched" and_controlsreports "compiled 29 cases to DXIL; verified 7 refusals". I ran this with a Linux cross build under Wine, not on Windows, and ran no WARP or GPU tests (pixel_warp,pixel_hardware,compute_hardware). CI is green, but its Windows job runsctest --preset pr("100% tests passed out of 70"), and none of the new tests is in it (minmax_med3appears 0 times in the job log). Soir/controlsare measured only by local runs. Small things, none blocking:git grep -E 'v_(min3|max3|med3)_f16' -- '*.md'finds nothing, while the f32 forms are indocs/experiments.md. A short paragraph on the med3 NaN rule, the clamp andop_selwould help.(mode_bits & 0xc0u) != 0xc0ucan't be reached, becauseconsume_half_moderefuses first. Fine to keep as defence in depth.From our side this looks ready, pending the re-review on the new head.
This comment was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-28 08:31 UTC · original
Thanks for the work here. This branch no longer merges with current
main(c6f23813):git merge-tree --write-tree origin/main df6c0545exits 1 with a conflict insrc/gfx1013_direct_compute.inl.Could you merge or rebase current
maininto the branch, resolve that conflict, and re-run the tests this PR adds, so reviewers can look at the refreshed head?This comment was AI-assisted.
@pigalot on GitHub · 2026-11-28 08:43 UTC · original · approved these changes
I retested
df6c0545merged overmainc6f23813. This supersedes my changes-requested review on8223b4b7.What changed.
git range-diffshows that the lowering commit (b82ba196) is the same as8223b4b7, apart from the rebase context in thehalf_binarylist.df6c0545adds five cases totests/native_minmax_med3_f16_check.py, and the model supplies their expected values. Each of my earlier findings:med3_three_nans_clampsends0x7e00into the clamp.med3with a NaN only in src2: addressed bymed3_nan_src2.med3_two_nansadds the two-NaNs-one-number case.min3_inline_neg_intreads inline-1(193).min3_clamp_negativeclamps0xBC00to+0.Merge with
main. The branch conflicts withc6f23813insrc/gfx1013_direct_compute.inl. #3294 addedv_cvt_norm_i16_f16/v_cvt_norm_u16_f16to the samehalf_binarylist. Keeping both sides resolves it:With that resolution, the tree is
2eab42a7andgit diff --cached --checkis clean. I didn't push it.What I ran on that tree. I built
compile_dxil native_store_replay offscreen_check native_compute_ir_dump native_global_srv_heap_replay native_compute_manifest_reasonsindevandrelease, then ran:/O2.native_minmax_med3_f16_compute_hardwareand_pixel_hardware.Mutants. Each was rebuilt in
dev, then I rannative_minmax_med3_f16_*, hardware included. All 13 are killed now; the three marked "now killed" survived on8223b4b7:max(min(a, b), c)nan or signchanged tonan and signabsignoredop_selsource reads the low halfany_nanignores src2Restored and rebuilt afterwards;
git diff --quietis clean. I didn't rerun the in-op denormal-gate mutant. It can't be reached, as I noted on8223b4b7, and this push doesn't change that.Verdict: approve on
df6c0545. It can't merge untilmainis merged in; the resolution above is the whole conflict.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32; I did not check the debug-layer status.
CI:
Build and test on Windowspasses ondf6c0545.This reply was AI-assisted.
github-bot referenced this pull request2026-11-28 19:04:52 +00:00
github-bot referenced this pull request2026-11-28 20:27:46 +00:00
@Leyukaka on GitHub · 2026-11-29 10:10 UTC · original
@legacy-code-archaeologist
git merge-tree --write-tree origin/main df6c0545(mainc3259f27) exits 1 with one conflict, insrc/gfx1013_direct_compute.inl: thehalf_binaryop list where this branch addsv_min3_f16,v_max3_f16andv_med3_f16afterv_fract_f16. On main that list now ends withv_ldexp_f16,v_cvt_norm_i16_f16,v_cvt_norm_u16_f16(lines 4754-4756). The first main commit that conflicts is116f1db3from your #3294 (merged as24c958ff);3926a289(#3125) then addsv_ldexp_f16in the same place. Could you merge main into the branch?@Leyukaka on GitHub · 2026-11-29 12:10 UTC · original
Taking this over since there has been no activity for 2 h; will hand back if you resume.
Plan: merge current
mainintodf6c0545with your two commits unchanged, resolve the one conflict (thehalf_binaryop list insrc/gfx1013_direct_compute.inl) as the union of both sides, and open a new PR that keeps your authorship.I don't build third-party code locally, so I will not run the merged head. The pull-request CI job runs
ctest --preset pr, whose filter does not includenative_minmax_med3_f16_*, so those tests need a run by a reviewer on the new head.