perf(shader): pick f16 min, max and med3 results on the bits #3590
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3590"
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 boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-11T13:54:29Z.
What
v_min_f16,v_max_f16,v_min3_f16,v_max3_f16,v_med3_f16,v_pk_min_f16andv_pk_max_f16now pick their result on the f16 bits instead of computing it in f32. The NaN,IEEE_MODE, f16 input denormal flush (#2876) and clamp rules are unchanged.Background. The result of these instructions is always one of the sources, or, for two zeros, their sign bits combined.
How.
minMaxF16Bitsturns each f16 into an integer ordering key: sign-extend the 16 bits, then flip the magnitude of negative values. It compares the keys as signed integers, selects the source bits, and keeps the existing rule for two zeros (AND of the bits for max, OR for min). The scalar pair, min3/max3 and med3 paths and the packed lanes all use it. The NaN rules that follow are untouched.I first compared the f32 conversions instead of integer keys, which works on NVIDIA and lavapipe. On an Intel UHD it fails: once these instructions no longer convert to f16, the module declares no f16
DenormPreserve, and Intel'sUnpackHalf2x16then turns f16 denormals into zero.v_min_f16 0x81ff, 0x01ffgave 0x01ff. The integer keys don't depend on that conversion.Before / after on an RTX 4060 Laptop (Ada, driver 591.86). SASS instructions per instruction come from
APS5_PIPELINE_STATSbinary size over a chain of 16 instructions,FLOAT_MODE0xc0:v_min_f16v_max_f16v_min3_f16v_max3_f16v_med3_f16v_pk_min_f16v_pk_max_f16All other opcodes in the sweep compile to the same size.
Why results don't change.
v_med3_f16takes the min3 path when any source is NaN, as before.Tested
Windows 11, MinGW-w64 GCC 15.2.0, Release,
mainat1c75f4d2. RTX 4060 Laptop (driver 591.86), Intel UHD Graphics (Raptor Lake, driver 101.6790) and lavapipe from Mesa 25.2.8 (the version CI installs; Windows build,GALLIUM_OVERRIDE_CPU_CAPS=avx).agc_driver_float16_min_max_bits:op_seland clamp, and packedop_sel,op_sel_hi,neg_lo,neg_hiand clamp.FLOAT_MODE, 0xc0 with eachDX10_CLAMP×IEEE_MODEcombination, 0x30 and 0xb0 (f16 input denormals flushed; scalar only, since packed f16 throws there).mainmatched the model on all three devices (155,648 results each) before the change, and this branch does too.v_max3_f16 ... is 0x00008000, expected 0x00000000.Float64or interpolation features, lavapipeagc_driver_interpolation_f16.agc_driver_*,agc_shader_*,agc_spirv_*,vector_*,agc_masked_select,agc_validate_program,agc_denormal*,agc_float16_*; 320 tests):agc_driver_flat_loads*,agc_driver_global_loads*,agc_driver_flat_apertures_2,agc_driver_flat_apertures_4(then0xc0000409) andagc_driver_pixel_interlock, which fail the same way onmain.agc_driver_image_plane_address_on_line_implicit_lod, which fails the same way withmain's recompiler, and an intermittent segfault inagc_driver_depth_fast_clear_submit, which crashed in 7 of 12 runs withmain's recompiler.Limits.
v_med3_f16still computes both the min3 used for NaN sources and the median, and selects between them.laneBitsinpackedFloat16(lines 34-43 onmain), so whichever lands second needs a small rebase; I'll do it.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:39:43Z.
Checked on RADV and CI's lavapipe: the new
agc_driver_float16_min_max_bitspasses (155,648 results) along with the existing f16/min-max tests, and the HW oracle (gfx1035, IEEE=0, f16 denormals kept) matches the selection and two-zero rules ofv_min/max/min3/max3/med3_f16on 1024 rows without NaN. Integer keys are monotonic as described, and the result is unchanged frommain. Merging once CI is green.