fix(shader): flush the v_mad_legacy_f32 and v_mac_legacy_f32 product by its tininess after rounding #26098
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26098"
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 DannyOppenheimer on 2026-11-23T08:36:51Z.
What
v_mad_legacy_f32andv_mac_legacy_f32flush a product below 2^-126 to a zero of its sign in every f32 denormal mode. The translation decided that from the exact product (flushTinyProduct(..., afterRounding = false)), but on RDNA1 the hardware decides it after rounding the product to 24 bits with an unbounded exponent: a product just below 2^-126 that rounds up to it is kept. Soa * b + cwith such a product lost the 2^-126 term, for example0xbbc6f27d * 0x8424b4fe + -0gives0x00800000on the hardware and +0 before this change.vFmaLegacyF32callsflushTinyProductwith its default, after-rounding test, the onev_mul_f32uses.F32DenormalFlushand thevector_constant_factor_tininessfixture still expected the exact-product check.TinyLegacyExpectedis now one row per f32 round mode, measured on gfx1010, and the fixture expects the rounded check forv_mad_legacy_f32andv_mac_legacy_f32. Round mode 2 is not checked for the legacy forms here: the hardware gives -0 for a +0 + -0 sum there, which is the directed rounding #26100 adds.[f32 denormals]debt entry said the legacy product is checked on its exact value; the fragment fixes that sentence and removes the entry's stale duplicate onmain.Found while measuring the legacy forms for the directed round modes (a follow-up PR that depends on this one).
Tested
Windows 11, Radeon RX 5700 XT (gfx1010), AMD driver 32.0.21045.5002.
v_mad_legacy_f32 a, b, 0matches "flush when the product rounded to 24 bits with an unbounded exponent is below 2^-126" in all four round modes (0 mismatches); "flush when the exact product is below 2^-126" misses 99 to 116 rows per round to nearest and directed mode, and "flush when the product rounded into the denormal range is denormal" 41 to 87.agc_oracle_runnerwith this change equals the hardware on 45504 rows of both instructions at round to nearest (2400 random rows, the 144 edge combinations and 300 boundary products, in the four f32 denormal modes at IEEE 0 and 1);maindiffers on 21 to 22 rows per configuration, all of them boundary products.agc_driver_legacy_product_tininess: 32 rows (16 products that round up to 2^-126 and are kept, 8 that stay below it and are flushed, ordinary rows) through both instructions, run with FLOAT_MODE 0xc0, 0xd0, 0xe0 and 0xf0 at IEEE 0 and 1 (8 of 8 runs pass). The existingagc_driver_fma_legacy,agc_driver_mac_legacyandagc_driver_vop3_legacy_source_modifiersstill pass.ctest --test-dir build -R "agc_driver_.*(directed_rounding|legacy|div_fmas|division|f64_fma|f64_ldexp|ldexp_f32|vop3_cube|nan_quieting|f64_arithmetic|f32_output_modifier|cubema)|agc_shader_mode_register" -VwithANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, Khronos validation layer 1.4.369,mainat28f493e6d1and this branch at4f64d47e46, each run after its test targets were relinked:main21 of 21 passed, this branch 22 of 22 passed (with the newagc_driver_legacy_product_tininess).Insert instance layer "VK_LAYER_KHRONOS_validation"appears 20 and 21 times, once per GPU test (agc_shader_mode_registercreates no Vulkan instance);was not found but was requestedappears 0 and 0 times, andVUID-0 and 0 times.F32DenormalFlushlegacy rows through both instructions on gfx1010 at IEEE 0 and 1, f32 denormals flushed and kept, in each round mode, give the newTinyLegacyExpected.ctest --test-dir build -R "agc_driver_(legacy_product_tininess|f32_denormal_flush|fma_legacy|mac_legacy|vop3_legacy_source_modifiers|f32_add_mul_denormal_modes)$|^vector_constant_factor_tininess$" -Vwith the same environment and layer:mainat6555c1425a6 of 6 passed, this branch atd92354fed87 of 7;Insert instance layer5 and 6 times,was not found but was requested0 and 0,VUID-0 and 0.tools/check_conventions.py --base origin/mainpasses with onedebt-lengthwarning (the changed debt entry was already long) andtools/debt_fold.py --checkpasses.tools/pr_overlap.py --branchfinds no conflicting lines in open PRs. #20187 could not be compared automatically; itsFloatInstructions.cpphunk is infloatBinary, away fromvFmaLegacyF32.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T09:10:54Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed translation uses the after-rounding tininess check described in the PR, and the added test covers both legacy instructions across the listed float modes.
What I ran
Reviewed head
4f64d47e46a7c077412c8ecd2b7c7f8518ae458cusing the prepared diff andrepo_read.pysource reads. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
The changed call now relies on
flushTinyProduct's default after-rounding behavior: FloatInstructions.cpp at reviewed head. The helper applies its after-rounding path when requested: OperandAccess.cpp at reviewed head.Not verified
Automated checks were not run in this review; the reported hardware and CI results in the PR description were not independently verified. Files read:
core/libs/prx/libSceAgcDriver/tests/execution/LegacyProductTininess.cpp,core/shader/recompiler/Translation/src/FloatInstructions.cpp,docs/dev/debt/changes/legacy-product-tininess.md, andcore/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp. No changed files were excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T09:36:17Z.
Review: CHANGES_REQUESTED
The production change matches the intended after-rounding legacy-product model, but the exact hosted Windows run is red because the existing
vector_constant_factor_tininessfixture still expects the oldTininess::FullIR shape forv_mad_legacy_f32. Please update that expectation toTininess::Rounded; adding thev_mac_legacy_f32sibling would keep this structural regression check aligned with the two instructions covered by the new execution test.The exact Windows job passed 226 of 227 tests and failed only this fixture: it found zero full-exponent tiny-product checks where the stale expectation requires one.
I independently extracted the relevant translation decision into a CPU A/B harness. The head matched an integer oracle in 512 packed fixture assertions, 4,096 boundary cases, and 2,662 signed-zero/NaN/Inf/DAZ cases. The parent differed in 240 fixture assertions and 156 boundary cases, as expected. An instrumented legacy-MAD control changed from exponent/rounded/UMulHi counts
1/0/1on the parent to0/1/0on this head, confirming that the failing hosted test is stale rather than exposing a production regression. Legacy DAZ/FTZ remains forced independently of MODE bits.No GPU or shader execution was performed in this review. The separately reported real-GPU evidence is complementary, not part of my verification.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-23T11:36:39Z.
Review: COMMENTED
Windows check of head
4f64d47e46with GCC 16 on an NVIDIA and an AMD GPU, merged ontomainf5b7e1d1ac(clean merge). The reports so far are AMD (gfx1010, gfx1201, RADV) and the hosted Windows job, so this adds NVIDIA. It confirms the two stale expectations already raised, on both vendors.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2). This was built together with #25557, #24781 and #22251, which touch other files.^(agc_driver_.*legacy.*|agc_driver_f32_denormal_flush|.*tininess.*)$:main6 of 6. With this PR, 5 of 7 in 2 of 2 runs, on both GPUs. NoVUID-lines.agc_driver_legacy_product_tininesspasses, as doagc_driver_fma_legacy,agc_driver_mac_legacyandagc_driver_vop3_legacy_source_modifiers.agc_driver_f32_denormal_flushfails on the RTX as well as the Radeon, at the same first lane Helldiverr gives:lane 0 no float mode v_mad_legacy_f32 v18, v4, v5, v6 is 0x00800000, expected 0x00000000.vector_constant_factor_tininessfails withf32 constant factor: v_mad_legacy_f32 v5, v6, v7, v8 emits 0 exponent tiny product checks, expected 1, the staleTininess::Fullshape mihiii1337 pointed to.vFmaLegacyF32back toflushTinyProduct(..., nullptr, false), the newagc_driver_legacy_product_tininessfails withv_mad_legacy_f32 FLOAT_MODE 0xc0, IEEE=0 of 0xbb57f116, 0x497bea0, 0x80800000 is 0x80800000, expected 0x81000000. So the new test guards the change.So the production change behaves the same on NVIDIA. What's left is updating
TinyLegacyExpectedinF32DenormalFlush.cppand the constant-factor fixture to the after-rounding rule.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T13:22:59Z.
Review: APPROVED
Rechecked exact head
d92354fed81e0bbe8cb4a405d615ecf2a7d7fb1e. The structural-test blocker from my previous review is fixed.vector_constant_factor_tininessnow expectsTininess::Roundedfor both legacy MAD and MAC while retaining the directedTininess::Fullcontrol. The exact Hosted Windows job passes that test and the full selected set, 227/227. Contributor-reported focused runs also coverlegacy_product_tininessandf32_denormal_flushon multiple AMD generations and RTX 3070; reverting the product rule makes the targeted tests fail.The intentionally absent round-down signed-zero row remains scoped to the separate additive work described in #26100 and does not reopen this PR's after-rounding product fix. I did not run a GPU test on my machine for this review.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-24T17:09:07Z.
Review: APPROVED
Re-review on Windows of head
d92354fed8, on the same two GPUs as my earlier comment, where both stale expectations failed on NVIDIA as well as AMD.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2). Merged ontomain45fc4e23bb(clean merge), built together with #26096 and #19532, which touch other files.agc_driver_f32_denormal_flush,vector_constant_factor_tininess,agc_driver_legacy_product_tininess,agc_driver_fma_legacy,agc_driver_mac_legacyandagc_driver_vop3_legacy_source_modifiers:main6 of 6, and with this PR 7 of 7 in 2 of 2 runs, on both GPUs. The two that failed on4f64d47e46now pass. NoVUID-lines.vFmaLegacyF32back to the exact-product rule, three tests fail on the RTX:agc_driver_f32_denormal_flush(lane 0 no float mode v_mad_legacy_f32 ... is 0x00000000, expected 0x00800000),agc_driver_legacy_product_tininessandvector_constant_factor_tininess. So the updated expectations now pin the new rule.The translation is unchanged from
4f64d47e46. OnlyTinyLegacyExpectedand the constant-factor fixture moved to the after-rounding rule, which is what my comment asked for.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-24T23:34:02Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
d92354fed81e0bbe8cb4a405d615ecf2a7d7fb1eagainst the supplied diff. I inspected the listed changed lines and the tininess helper they use. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
Sources
Not verified
LegacyProductTininess.cppwas not verified.manifest.jsonwere read; no changed files were excluded.To get this to a good state
Nothing is required. Optional: confirm
LegacyProductTininess.cppis registered in the test build and CI configuration.