Skip to content

perf(shader): drop the result flush of a product behind its tiny-product check - #7212

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:perf/denormal-free-guarded-products
Oct 18, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:perf/denormal-free-guarded-products

Conversation

@milescoviello

Copy link
Copy Markdown
Contributor

What

In a FLOAT_MODE that flushes f32 denormals (0xc0, which most titles use), each v_mul_f32 and v_mul_legacy_f32 is translated as:

  1. the product;
  2. the nearest-even tininess check from flushTinyProduct (one factor times 2^64, the product compared with 2^-62);
  3. the NaN result selection from nanResultF32;
  4. the result flush from writeOperand.

The check already turns every product that rounds below 2^-126 into a zero of its sign. So when both factors are denormal-free, a product it keeps is zero, infinite, NaN or at least 2^-126 in magnitude. That holds as long as the driver rounds the product the same way as the check's own multiply, which the check already relies on (see the f32 denormals debt entry). The result flush can't change such a value, but DenormalFlushEliminator (#2103) couldn't prove it and kept it. Every such v_mul_f32 result therefore carried a flush.

DenormalFlushEliminator now also treats these as denormal-free:

  • the product arm of a select whose condition is that tiny-product check of the same two factors, when both factors are denormal-free;
  • a select arm the select takes only when that arm's own bits are NaN ((x & 0x7fffffff) > 0x7f800000 or FPIsNan32, with or without the IEEE-mode quieting | 0x00400000), which covers the arms of the NaN result chain, including perf(shader): pick the f32 NaN result with one quiet and one fallback select #4287's form;
  • an and with a mask that has no significand bits (the sign-of-zero arm).

The comparison and subtraction matchers take the immediate only on the right, so 0x7f800000 > |x| is not read as a NaN test. A short debt entry records the rounding assumption next to the existing one.

Tested

Linux (Ubuntu 24.04, GCC 13.3, Release), RTX 4070 Ti, NVIDIA 595.99.02; main 66702f1.

  • agc_denormal_flush_elimination, 4 new cases:

    • a product behind its own tiny-product guard loses its flush; one behind a guard of other factors, another threshold, or a raw factor keeps it;
    • an arm taken only when its bits are NaN (plain, quieted, FPIsNan32) loses its flush; one under another value's test, or under the reversed comparison, keeps it;
    • sign and exponent masks lose their flush; a mask with significand bits keeps it;
    • two chained v_mul_f32 recompiled end to end (wave32) keep one f32 exponent mask, the first source's input flush.

    With main's DenormalFlushEliminator.cpp all four fail (the end-to-end case finds 3 masks). With this change they pass 3 of 3.

  • ctest ^agc_ (662 tests, NVIDIA): all pass.

  • On an Intel Arrow Lake iGPU (Mesa 26.1.6 ANV), the 104 ^agc_ tests whose names cover f32, f16, NaN, denormal, mul, fma, mad, div, clamp and rounding: 103 pass. agc_driver_sample_multisample_target fails the same way on main there; test(agc): skip the multisampled target test without storage image multisampling #7191 addresses it.

  • SPIR-V words with agc_shader_replay, main against this change, over every draw request dumped in a cold run:

Requests Smaller main words This change Change
Afterglow (PPSA47770), 4 1 2,174,613 2,018,604 -7.2%
MXGP 26 (PPSA30839), 50 43 2,002,047 1,956,354 -2.3%
Super Meat Boy 3D (PPSA31162), 61 51 3,550,764 3,429,102 -3.4%

None got larger.

  • NVIDIA build time of Afterglow's largest fragment shader as a pipeline library part (2,167,462 words on main, 2,011,453 with this change). The timer is local, around that vkCreateGraphicsPipelines call. Cold cache, alternating builds:

    • main: 24.9 s and 24.9 s;
    • this change: 21.4 s and 21.4 s.

    The title still exits on a cold cache: its own watchdog stops waiting for that submission after about 2 s.

  • Frame summary on Afterglow, warm caches. Each build ran once, then again with APS5_TRACE_SECONDS=20:15, same pad script. Both builds carry the local part timer, hence dirty. The title presents at 60 Hz, so frame time doesn't move. GPU time per present went from 6.88 to 6.66 ms, one capture each, which is within what I'd expect from noise. MXGP 26 and Super Meat Boy 3D gave no capture on either build. MXGP's warm runs abort on the computed s_swappc_b64 of AGC: MXGP 26 (PPSA30839) aborts on a compute shader that calls a function pointer read through a V# at the fixed address 0xF_E0040000 #6117, and Super Meat Boy 3D doesn't present within 90 s here. The two traces can be attached on request.

{"commit":"66702f1cffd3","dirty":true,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"20:15"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 595.99.02","os":"Linux 6.8.0-147-generic","resolution":"3840x2160","window":{"spec":"seconds 20:15","first_present":1162,"ms":15002.674},"presents":848,"frame_ms":{"p50":16.684,"p90":20.199,"p99":38.058,"max":47.950},"gpu_busy_ms_per_present":6.875,"worker_busy_pct":{"queue worker 0x0":22.577},"top_phases_ms_per_frame":{"VideoOut.Flip":5.680,"VideoOut.Flip.vblank_wait":4.939,"Driver.Packet":3.844,"Driver.Packet.draw":3.005,"Driver.Draw":2.994,"Driver.Draw.draw_enqueued":1.970,"Driver.Draw.shader_compile_and_link":0.886,"VideoOut.Flip.present":0.667},"trace_dropped":false,"trace":"aps5-trace-66702f1cffd3-3.json.gz"}
{"commit":"6e0886d76d03","dirty":true,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"20:15"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 595.99.02","os":"Linux 6.8.0-147-generic","resolution":"3840x2160","window":{"spec":"seconds 20:15","first_present":1158,"ms":15010.870},"presents":849,"frame_ms":{"p50":16.685,"p90":21.286,"p99":33.810,"max":55.188},"gpu_busy_ms_per_present":6.658,"worker_busy_pct":{"queue worker 0x0":23.052},"top_phases_ms_per_frame":{"VideoOut.Flip":5.696,"VideoOut.Flip.vblank_wait":5.011,"Driver.Packet":3.931,"Driver.Packet.draw":3.132,"Driver.Draw":3.121,"Driver.Draw.draw_enqueued":2.142,"Driver.Draw.shader_compile_and_link":0.850,"VideoOut.Flip.present":0.610},"trace_dropped":false,"trace":"aps5-trace-6e0886d76d03-3.json.gz"}
  • check_conventions.py passes. pr_overlap.py lists only docs/dev/debt/shader.md; the new entry is its own line and merges without conflict with each listed PR wherever main does.

Not checked on Windows, on AMD, or on a console.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti (595.99.02, Linux); Intel Arrow Lake iGPU (Mesa 26.1.6 ANV, Linux), float tests only
  • AI-assisted: yes

🤖 Generated with Claude Code

…uct check

A v_mul_f32 in a FLOAT_MODE that flushes f32 denormals emits the
nearest-even tininess check, the NaN result selection and then a
result flush. The check already turns every product that rounds below
2^-126 into a zero of its sign, so the flush can't change what it
keeps. DenormalFlushEliminator now proves that: a select arm guarded
by the tiny-product check of the same denormal-free factors, an arm a
select takes only when its own bits are NaN, and an and with a mask
that has no significand bits are denormal-free.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4278 core/libs/prx/libSceAgcDriver/tests/DenormalFlushElimination.cpp
core/shader/recompiler/Optimization/src/DenormalFlushEliminator.cpp
PR 5021 docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5500 docs/dev/debt/shader.md
PR 5941 docs/dev/debt/shader.md
PR 5958 docs/dev/debt/shader.md
PR 6009 docs/dev/debt/shader.md
PR 6094 docs/dev/debt/shader.md
PR 6222 docs/dev/debt/shader.md
PR 6235 docs/dev/debt/shader.md
PR 6243 docs/dev/debt/shader.md
PR 6317 docs/dev/debt/shader.md
PR 6412 docs/dev/debt/shader.md
PR 6454 docs/dev/debt/shader.md
PR 6488 docs/dev/debt/shader.md
PR 6767 docs/dev/debt/shader.md
PR 6977 docs/dev/debt/shader.md
PR 7223 docs/dev/debt/shader.md

@oneandonlydean
oneandonlydean merged commit e0644fb into boykopovar:main Oct 18, 2026
9 checks passed
TheBlenDed pushed a commit to TheBlenDed/AnyPS5 that referenced this pull request Oct 25, 2026
Pipodi pushed a commit to Pipodi/AnyPS5 that referenced this pull request Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants