perf(shader): check f32 product tininess in one multiply to nearest even #3278
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3278"
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 oneandonlydean on 2026-10-11T04:54:44Z.
Carried unchanged from @AlxcBTW's fork (AlxcBTW/AnyPS5#35,
4e7511dc, authorship kept); the intake pause closes PRs opened from that account.What
#2839 decides f32 product tininess after rounding in all four f32 round modes. It does this from the exponents and a
UMulHi/IMulof the significands, and builds the flushed value from them. To nearest even (no known float mode, and the 0xc0 most titles use), this replaces that with one multiply. One factor times 2^64, which is exact below 2^64, times the other factor rounds the exact product once to 24 bits in the normal range, and0 < |that| < 2^-62is tininess after rounding. A product that rounds up to 2^-126 is then not tiny and keeps the emitted product, which is 2^-126 there. The three directed modes and the before-rounding check ofv_mad_legacy_f32keep #2839's check. Its round-to-nearest branches are removed as unreachable.v_mul_f32 v5, v6, v7takes 12 IR instructions instead of 34, counted as the instructions the flush select needs beyond the product.vector_constant_factor_tininesspins 12 to nearest and 36 for the directed path of the same instruction. It also checks the shape of every row: the rounded 2^-62 compare to nearest, and #2839's exponent and significand checks toward +infinity, -infinity and zero and forv_mad_legacy_f32.OpFMullike the product, and no f32 rounding mode is requested, so the check relies on the driver rounding f32 to nearest even, as the products do.F32ConstantFactorTininessnames0x3f7ffffe * 0x00800001(lane 2) as the row a check before rounding flushes, which keeps the emitted0x00800000.Numbers
Main
77bd928a3against main77bd928a3with this commit (same diff), Windows 11, WinLibs GCC 15.2.0, Release, RTX 5070 Laptop (NVIDIA 616.92). Another process was sharing the GPU during the runs, so the GPU ran in two speed states. Each comparison below is within one state.Compile. 155 distinct compute recompile requests from Sword of the Sea (request version 15), replayed with
agc_shader_replay --spv:vkCreateComputePipelinesfor the six with the most checked products, fresh driver shader cache per run, median of 3 runs in alternating order:Runtime. The kernel is a loop of 8,192 iterations with 16 checked products each: two
v_fma_f32and twov_mul_f32chains, unrolled 4 times, with factors in registers. It runs in float mode 0xc0 over 8,192 groups of 32 lanes. Its SPIR-V is 8,914 → 7,074 words, and the outputs are identical in every run.APS5_PROFILE_GPU, per-program average per 10 s window), GPU at full speedEquivalence with #2839 to nearest even
TinyCodeandMixedTinyCodeshaders were run over 165,298 and 164,008 generated rows (boundary rows as above, f16 factors for the mixed forms, mostly zero addends) in six float modes (none, 0xc0, 0x00, 0xc1, 0xc2, 0xc3). The outputs of all 18 instructions are bit-identical with #2839's lowering and with this one.v_mul_f32also matches the exact reference on every row, about 34,000 of them kept at 2^-126 per mode. The same sweep with the compare off by one (<= 2^-62) differs on 33,995 rows per mode, so it does see the boundary.Tested
Windows 11, WinLibs GCC 15.2.0, Release, NVIDIA RTX 5070 Laptop only (AMD Vulkan driver hidden).
vector_constant_factor_tininess,agc_driver_f32_constant_factor_tininessandagc_driver_f32_denormal_flush(#2839's, in all its modes and with mixed sources) pass.agc_unit_shadow,agc_driver_flat_aperturestiming out,agc_driver_image_packed16_load).tools/check_conventions.py --base origin/mainandgit diff --checkpass.Checklist
main; no other open PR implements the same functions (based on6dcfc5b64, which includes #2839; merges cleanly into77bd928a3)NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code