perf(shader): treat f32 min, max, med3, floor and ceil results as denormal-free #4490
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4490"
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-12T13:24:58Z.
What
In the float modes that flush f32 denormals, the result flush after
v_min/max/min3/max3/med3_f32andv_floor/ceil_f32is now dropped when it can't change the value.Background.
FLOAT_MODEbits 5:4 = 0, as in titles' shaders; #1850),writeOperandflushes these instructions' results to a signed zero with an explicit select.f32DenormalFlushForgives them 3.DenormalFlushEliminatordrops a flush whose value it can show is never a denormal: flushed values, conversions from integers or f16, sign changes, selects and phis of such values.How.
DenormalFreeValues::computenow treats:FPMin32,FPMax32,FPMinTri32,FPMaxTri32andFPMedTri32as denormal-free when every operand is, through the same loop phis already use;FPFloor32andFPCeil32as always denormal-free.Why results don't change.
EmitMinMaxF32ValueandEmitFPMedTri32return one operand's bits, or theand/orof two zeros when both are zero. So they produce a denormal only if an operand is one.GLSLstd450FloorandCeilreturn an integer, a signed zero, an infinity or a NaN, none of which is a denormal.Limit: IEEE mode.
ieeeMinMaxF32selects a quieted operand (bits | 0x00400000) for a signaling NaN, andfloatUnarydoes the same for a NaN input. The eliminator can't show thatorgives no denormal, so these results keep their flush.Before / after on an RTX 4060 Laptop (Ada, driver 591.86). SASS instructions per instruction come from the
APS5_PIPELINE_STATSbinary size over a chain of 16 instructions, withFLOAT_MODE0xc0 and IEEE mode off:v_min_f32v_max_f32v_max_f32DPPquad_perm:[1,0,3,2]v_min3_f32v_max3_f32v_med3_f32v_floor_f32v_ceil_f32v_max_f323,608,v_min_f321,568,v_min3_f32539,v_max3_f32371,v_med3_f32371,v_floor_f32284,v_ceil_f32144.Tested
Windows 11, MinGW-w64 GCC 15.2.0, Release, this branch on
mainat2ccbd376f. Devices:RTX 4060 Laptop (Ada, driver 591.86)
Intel UHD Graphics (Raptor Lake, driver 101.6790)
lavapipe from Mesa 25.2.8 (llvmpipe, LLVM 21.1.7): the version CI installs; Windows build with
GALLIUM_OVERRIDE_CPU_CAPS=avx.agc_denormal_flush_elimination, three new cases:v_maxorv_med3with an unknown operand keeps it;Results:
agc_driver_f32_denormal_flushrunsv_min_f32,v_max3_f32,v_med3_f32,v_floor_f32andv_ceil_f32over denormal and special rows captured on hardware with f32 denormals flushed (#1850). It passes on the three devices, and so doesagc_driver_f32_min_max_nan.Shader and driver tests (
agc_driver_*,agc_shader_*,agc_spirv_*,vector_*,agc_masked_select,agc_validate_program,agc_denormal*,agc_float16_*; 338 tests):agc_driver_flat_loads*,agc_driver_global_loads*,agc_driver_flat_apertures*,agc_driver_pixel_interlock.agc_driver_ds_swizzleandagc_driver_f32_dot2_rounding, which fail the same way onmain.agc_driver_depth_fast_clear_submit. It segfaults in 3 of 4 runs here, and did so intermittently withmain's code before this change too.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 xXPBSXx on 2026-10-13T06:56:46Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main
88107b7detogether with thirteen other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it:tests/DenormalFlushElimination.cpp(agc_denormal_flush_elimination): 3 of 3 runs passed.Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-13T21:53:57Z.
Thanks @xXPBSXx for the RTX 4080 SUPER run.