fix(shader): check f32 product tininess after rounding #3098
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3098"
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 MarcZX10 on 2026-10-10T22:11:14Z.
What
Carry the disclosed fix for #2682 from AlxcBTW/AnyPS5#18. The two original commits are preserved with AlxcBTW as author.
flushTinyProductnow detects f32 tininess after rounding the product to 24 bits, matching the reported RDNA2 behavior, and uses six IR instructions instead of twenty for each checked product.Relationship to #2839
#2839 implements the same tininess boundary with coverage for all four f32 rounding modes and mixed f16/f32
v_fma_mix_f32sources. This PR carries AlxcBTW's six-instruction round-to-nearest lowering; the broader check in #2839 uses about twenty IR instructions. Both changeflushTinyProduct, so they cannot be merged unchanged together. The distinct contribution here is the smaller round-to-nearest lowering; the additional modes and mixed-source cases still need consolidation before this PR is ready to merge.Tested
vector_constant_factor_tininess_testsandagc_driver_f32_constant_factor_tininess_tests.vector_constant_factor_tininesspassed (1/1).agc_driver_f32_constant_factor_tininesspassed on Mesa lavapipe (1/1).python3 tools/check_conventions.py --base upstream/mainandgit diff --checkpassed.Checklist
main; the overlap with #2839 and this PR's distinct six-instruction lowering are documented aboveNotImplemented_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 AlxcBTW on 2026-10-10T22:13:50Z.
@MarcZX100 thanks for carrying it. For reviewers, the hardware check of these exact commits is SleglJan's RDNA2 run in #2682 (gfx1036,
tools/hw-oracle, main versus AlxcBTW/AnyPS5#18 cherry-picked): https://github.com/boykopovar/AnyPS5/issues/2682#issuecomment-6097552373. I'll close the fork PR once this is merged.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-10T22:18:31Z.
@MarcZX100 @CouchRiv the overlap bot is right: #2839 implements the same tininess-after-rounding check, and it goes further. It follows the
FLOAT_MODEf32 round mode (measured in all four modes), and it coversv_fma_mix_f32with mixed f16/f32 sources. My commits handle the round-to-nearest case only. So I'd suggest reviewing #2839 and closing this carry, to avoid two conflicting versions of the same fix. If the shorter IR from mine (six instructions per checked product instead of twenty) is worth keeping, I'm happy to port that onto #2839 afterwards as a separate change.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T22:19:55Z.
Thanks for the comparison. I agree #2839 has broader measured coverage, including all four f32 round modes and mixed f16/f32
v_fma_mix_f32. The distinct contribution carried here is the six-instruction round-to-nearest check versus the roughly twenty-instruction general check. Since both changeflushTinyProduct, they should not be merged unchanged as separate implementations. I have updated this PR to disclose the overlap and its scope; the broader cases need consolidation before this PR is merge-ready.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T22:30:29Z.
Review: COMMENTED
The attribution is right and worth saying first: this is AlxcBTW's fix, carried with the original commits and authorship intact. That is how someone else's work should land.
The lowering is clever, and the sentence I would add is about which rounding it inherits. Scaling the product by a power of two and comparing bit patterns lets the tininess test reuse the emitted multiply, so the test rounds exactly the way the product does — that is what removes the significand product and the carry, and it is why the test file pins "one comparison, no
UMulHi" rather than counting instructions. What "after rounding" then means depends on the emitted multiply, and there is no f32 rounding control in this tree — it lowers to a plainOpFMul, so the rounding it carries is the host's, round-to-nearest. For a shader whose f32 rounding is directed, the test therefore inherits the wrong rounding — which is precisely the gap you flag against #2839. A clause in the debt entry naming which rounding the inherited multiply carries would save the next reader assuming it is the shader's.The discriminating vector deserves to be named as such.
{2, 2, 0x00800000}is the case the new behaviour exists for: a product that a pre-rounding test flushes and that survives once rounding is applied, because it lands on the smallest normal. It is also the only vector this PR adds, so the new behaviour rests on that row — and, behind it, the reported RDNA2 result that you say plainly you did not re-measure. Marking it in the test as the row the change exists for would make that dependence visible instead of implicit.And one thing the test does not pin. It checks the shape — one tiny comparison and no significand product — and it counts opcodes by type rather than in total. If six instructions instead of twenty is part of the value here, a total-count assertion would turn that from a description into a regression guard.
On the overlap you declare: it is real, and declaring it up front is the part reviewers usually have to reconstruct. Nothing in this says the smaller lowering is the disposable half — the round-to-nearest form is the one that will actually be used most.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T00:21:08Z.
@MarcZX100 now that #2839 has landed, this carry can't go in beside it, as you said. I rebuilt the round-to-nearest lowering on top of #2839 instead of beside it:
perf/tininess-rne-short-check(4e7511dc), one commit on main. It can replace the two carried commits here.To nearest even only (no known float mode, and the 0xc0 most titles use),
flushTinyProductdecides tininess with one multiply: one factor times 2^64, times the other factor, compared with 2^-62. The three directed modes and the before-rounding check ofv_mad_legacy_f32keep #2839's significand check.v_fma_mix_f32reaches the check through the same call asv_fma_f32and takes the short path too: its f32 sources are flushed before the multiply, and its f16 sources convert to normal f32 values, so the decision is the same. The flush ofv_mul_f32 v5, v6, v7goes from 34 IR instructions to 12.Dextroid17's review, as it applies to this version:
OpFMullike the product, with no f32 rounding mode requested, so the check relies on the driver rounding to nearest even. It is used only when the shader's mode is nearest even, so the directed-rounding gap is gone: those modes keep #2839's check.F32ConstantFactorTininessnames0x3f7ffffe * 0x00800001, the row a check before rounding flushes, and checks it on its own.vector_constant_factor_tininesspins the instructions the flush adds beyond the product: 12 to nearest even, and 36 for the directed path of the same instruction.Equivalence with #2839 to nearest even:
agc_driver_f32_denormal_flush,agc_driver_f32_constant_factor_tininessandvector_constant_factor_tininesspass. Fork CI: run 38096876119: Windows 756/756. Linux 749/752, with the same three failures as main (agc_unit_shadow,agc_driver_flat_apertures,agc_driver_image_packed16_load).I did not measure anything new on hardware. The RDNA2 rows are SleglJan's (#2682) and #2839's.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:07:54Z.
Closing: #2839 is in and already checks tininess after rounding, in all four modes. The shorter nearest-even path can come as its own PR on top of it, with numbers.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T02:14:21Z.
@oneandonlydean agreed, #2839 is the implementation to keep. I rebuilt the shorter nearest-even check on top of it as one commit, AlxcBTW/AnyPS5#35. It only replaces #2839's round-to-nearest check and leaves the directed modes and the
v_mad_legacy_f32path as they are. Against main on an RTX 5070, 39 of 155 Sword of the Sea compute shaders have checked products. Their SPIR-V shrinks by 10.4%, NVIDIA pipeline creation for the six heaviest drops from 132 s to 109 s (median of 3, fresh driver cache), and av_mul/v_fma-heavy dispatch takes 45% less GPU time, with outputs bit-identical to #2839's on its own tininess shaders. The intake workflow closes PRs from new authors, so would you carry #35?AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T04:58:24Z.
Thanks for preparing the follow-up and sharing the equivalence and performance results. I found that upstream PR #3278 already carries the exact source commit
4e7511dcfrom AlxcBTW/AnyPS5#35, with your authorship preserved. To avoid a duplicate PR, I won't open another carry. #3278's applicable checks are still running; Windows relinker is pending, while the other applicable checks pass. Full Linux and Windows builds are skipped by project policy.Pull request closed