fix(shader): round v_mad_legacy_f32 and v_mac_legacy_f32 in the directed FLOAT_MODE rounding modes #26100
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26100"
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:37:20Z.
What
In the directed
FLOAT_MODEf32 round modes,v_mad_legacy_f32andv_mac_legacy_f32round their product and then their sum in the mode, each once. The translation rounded both to nearest even (the mode was rejected when set bys_round_mode), so 298 to 479 of 2400 random rows per directed mode differed from the hardware.vFmaLegacyF32rounds the product withdirectedF32(a, b, 0, productZeroSign)and the sum withdirectedF32(product, 1, c)when the f32 round field is directed. That is the exact product-sum of #19710, used there forv_mad_f32the same way, so this PR depends on #19710. The zero factor rule, the product flush (after rounding, from #26098, now onmain) and the result flush stay as they are; a sum of two zeros is -0 when rounding toward negative infinity and either is -0.RoundingMode.cppmovesVMadLegacyF32andVMacLegacyF32to theDirected32group ofVMadF32.F32DenormalFlushchecks the legacy tiny products in round mode 2 too. #26098 skips that mode because the hardware's -0 for +0 + -0 there (lanes 4, 21 and 30) is this change's zero-sum sign.Found by a differential sweep of VOP1/VOP2/VOP3 opcodes through
tools/hw-oracleon an RX 5700 XT (gfx1010, RDNA1, the PS5's gfx10.1 generation) against the same bodies throughagc_oracle_runner, in the directedFLOAT_MODEround modes. #26098 has merged, so this branch is now #19710's headf4604adaa4withmaina2d8d409dbmerged (a00c6029c6); this change is the commitsbd666c65aeande0aae5d0b2. In that merge,floatTernarykeeps the directed block and takesmain'snanFastnoteNanarm (#23344) as the first arm of the NaN handling, andShaderModeRegisters.cpp's check list is sized 24, since #19710,main'soutputModifierRoundingand #25959 each added one.Tested
Windows 11, Radeon RX 5700 XT (gfx1010), AMD driver 32.0.21045.5002.
agc_oracle_runnerequals the hardware on all 182016 rows (both instructions, 32 configurations each), and on 34128 rows withs_round_mode1 to 3 at f32 denormal modes 0 and 3.agc_driver_legacy_directed_rounding: 32 rows (sum and product rounding, signed zeros, overflow, the 2^-126 boundary) through both instructions with the hardware's results for round modes 1 to 3, run with FLOAT_MODE 0xc0 and 0xf0 at IEEE 0 and 1, declared and set bys_round_mode(24 of 24 runs pass).directedF32on RDNA1 hardware for the product and sum shapes above; #19710 itself was tested on NVIDIA.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|f32_denormal_flush|fract|f16_denormal_flush|f64_rounding|dx10_clamp|f32_result_clamp|unused_nan|dpp_no_form|vcvt_pk_u8)|vector_constant_factor_tininess|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,mainata2d8d409dband this branch ata00c6029c6(maina2d8d409dbmerged), each from its own build directory with all execution tests enabled and its test targets relinked from that commit:main39 of 39 passed, this branch 53 of 53 passed (#19710 adds the 13agc_driver_f32_directed_roundingtests, this changeagc_driver_legacy_directed_rounding).vector_constant_factor_tininesspasses, andagc_driver_f32_denormal_flushpasses with round mode 2 included. On both,agc_driver_float16_unused_nan_payloadsreports itself skipped (the RX 5700 XT has no native f16 conversions with RTE rounding and kept f16 denormals).Insert instance layer "VK_LAYER_KHRONOS_validation"appears 37 and 51 times, once per GPU test (agc_shader_mode_registerandvector_constant_factor_tininesscreate no Vulkan instance);was not found but was requestedappears 0 and 0 times, andVUID-0 and 0 times.tools/check_conventions.pyona00c6029c6reports 0 errors and onedebt-lengthwarning, in #19710's own debt edit.tools/pr_overlap.py --branchlists the files #19710 changes (Recompiler.hpp, the shader debt file,FloatInstructions.cpp,TranslationContext.hpp) against the PRs that touch them; this change itself only editsvFmaLegacyF32, two lines ofRoundingUseOfand adds its test and fragment. The test count here (53) is higher than onmain(39) because #19710 adds the 13agc_driver_f32_directed_roundingtests and this change addsagc_driver_legacy_directed_rounding.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
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T09:28:03Z.
Review: APPROVED
Reviewed exact head
4e0fa10d8f698ad69277bd282bfa7713faecac44. No blocker found in this PR's own legacy MAD/MAC delta, assuming its declared #19710 and #26098 dependencies land first.An independent exact-rational evaluator reproduced all 96 values in
LegacyDirectedRounding.cpp. Static source review confirms thatv_mad_legacy_f32/v_mac_legacy_f32round the product and the sum separately, keep the legacy zero-factor decision ahead of infinity/NaN handling, preserve the fixed input/output FTZ policy, saturate finite overflow according to direction, and select signed zero for exact cancellation from MODE/backend rules. The test is registered through the existing CMake glob/default registration. Its 32 lanes do not independently exercise NaN input payload selection; the broader hardware campaign reported by the author was not reproduced here.Merge against current
main, own-delta diff, and debt folding are clean. Conventions has only the two reported warnings inherited from the dependencies. A combined preview with #26101 conflicts inShaderModeRegisters.cpp, so those stacks need an ordinary rebase/coordination. The failed intake job reports a GitHub API 504 while fetching PR pages, not a source/test failure; Windows is still running.I did not compile this head, execute a shader, or run a GPU test. This approval is based on the exact source, independent arithmetic evaluation, and existing test wiring only.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T10:33:55Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: register the new f32 directed-rounding execution target with the default build before its CTest cases invoke it.
What I ran
Reviewed head
4e0fa10d8f698ad69277bd282bfa7713faecac44from the prepared diff and pinned repository reader. I did not run build or test commands.Results
Findings
Blocking
core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_f32_directed_rounding_tests.cmake:6adds CTest cases that executeagc_driver_f32_directed_rounding_tests, but no target with that name is declared in the changed CMake fragment or the library CMake file. The library CMake creates execution-test targets asEXCLUDE_FROM_ALLand registers their defaults separately; this fragment neither enables that target for the default build nor adds it to the default CTest registration. Consequently a normal build/CTest run will not provide the executable these cases launch. Add explicit target activation (and confirm its build dependencies are included) before registering these cases.Non-blocking
None.
Not verified
The author reports RX 5700 XT differential runs and CTest results; these were not independently run in this review. No console hardware measurement was performed. The prepared diff excludes no changed files; all changed files listed as reviewed were read.
To get this to a good state
Register and build
agc_driver_f32_directed_rounding_testsin the normal test configuration, then run its six CTest cases and the existing shader mode register test on the updated head.Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T13:23:55Z.
Review: COMMENTED
Rechecked current head
4f6d1435d40506a126fbed8146ce7aa71f7e1185. I still find no blocker in this PR's own legacy MAD/MAC delta, and an independent exact-rational reference reproduced all 128 cells in the updated table.I am not approving the combined head yet because its declared #19710 dependency remains red in
vector_constant_factor_tininess. That dependency's exact head is an ancestor here and fails the same check in its own Windows job. The current head's hosted Windows job reached the 90-minute limit, while the external focused run completed 36/37 and reported that same inherited failure.No additional change is requested in this PR's own commits. Please update the dependency when #19710 fixes its structural checker and re-request review on the resulting head. No GPU test was run on my machine.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-24T23:28:31Z.
Review: COMMENTED
Reviewed — no blocking findings
The implementation changes legacy MAD/MAC to round the product and sum in the directed f32 mode; I found no verified blocking defect in the code inspected, but the review is incomplete.
What I ran
Reviewed head
4f6d1435d40506a126fbed8146ce7aa71f7e1185. I read the prepared description, commit list, manifest and diff, then inspected the directed rounding implementation, emitter logic, rounding-use classification and related test changes. No commands or tests were run.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
I read the changed implementation in
core/shader/recompiler/Translation/src/FloatInstructions.cpp, relevant sections ofcore/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cppandcore/shader/recompiler/Translation/src/RoundingMode.cpp, plus portions ofcore/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cpp,core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_f32_directed_rounding_tests.cmake,core/libs/prx/libSceAgcDriver/tests/execution/F32DenormalFlush.cpp,core/libs/prx/libSceAgcDriver/tests/execution/F32DirectedRounding.cppandcore/libs/prx/libSceAgcDriver/tests/execution/LegacyDirectedRounding.cppfrom the diff. I did not read all added lines in these files, nor the other changed files listed inreview/manifest.json; therefore this is not a complete review. Tests and hardware behavior were not independently verified. The author reports one failing validation test attributed to a dependency.To get this to a good state
Nothing is required. Optional: complete inspection of the remaining changed lines and independently run the reported checks on this head.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T04:45:00Z.
Review: COMMENTED
Actionable comments posted: 5
223aef71-6231-45ef-aadc-0ff2bbaffe05Reviewing files that changed from the base of the PR and between
c64b9d323fande0aae5d0b2.core/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_f32_directed_rounding_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/F32DenormalFlush.cppcore/libs/prx/libSceAgcDriver/tests/execution/F32DirectedRounding.cppcore/libs/prx/libSceAgcDriver/tests/execution/LegacyDirectedRounding.cppcore/libs/prx/libSceAgcDriver/tests/execution/LegacyProductTininess.cppcore/libs/tests/VectorConstantFactorTininess.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cppcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/FloatInstructions.cppcore/shader/recompiler/Translation/src/RoundingMode.cppdocs/dev/debt/changes/legacy-mad-mac-directed-rounding.mddocs/dev/debt/changes/legacy-product-tininess.mddocs/dev/debt/shader.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T04:49:38Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
e0aae5d0b2fab44cf3d4e8e0679308efe3209636. I usedrepo_read.pyto inspect the prepared diff and relevant changed code; I ran no tests or other commands.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not read every changed file in full or inspect all callers and surrounding implementations. In particular, the new execution tests, remaining portions of the interpolation backend, and portions of the older tininess test were not inspected. No test results were independently verified. The prepared bundle includes 13 changed files; the diff was read, and portions of the changed implementation and test code were inspected.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T00:18:55Z.
Review: COMMENTED
Actionable comments posted: 1
a8167271-5443-472a-ab0d-46131ec5c291Reviewing files that changed from the base of the PR and between
e0aae5d0b2anda00c6029c6.core/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cppcore/libs/prx/libSceAgcDriver/tests/execution/F32DenormalFlush.cppcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/FloatInstructions.cppcore/shader/recompiler/Translation/src/RoundingMode.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T07:37:56Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The directed f32 lowering omits denormal result flushing, so supported modes can return subnormal results where the hardware flushes them.
What I ran
Reviewed head
a00c6029c6648136af721703098e358e69525945using the prepared diff andrepo_read.pyfor targeted source context. No tests or build checks were run.Results
Findings
Blocking
core/shader/recompiler/Translation/src/FloatInstructions.cpp:745:directedF32encodes the IEEE and rounding fields, but omits the denormal input/result flush flags used byFPInterpolateF32. In particular, directed add/sub paths can return a subnormal sum when theFLOAT_MODEresult mode requires flushing it. Add the appropriate flush flags from the active denormal mode when buildingmode, and cover a directed tiny-sum case in the execution test.Non-blocking
None.
Sources
Not verified
No tests were run. Read the prepared description, commits, manifest and full diff, plus targeted portions of
FloatInstructions.cpp,SpirvAluEmitterFloat64.cpp,OperandAccess.cpp,RoundingMode.cpp, andLegacyDirectedRounding.cpp. The manifest lists 13 changed files; the other changed files were not read from their full head contents.To get this to a good state
Add the active denormal flush flags to
directedF32's interpolation mode and test directed tiny sums in the result-flush modes. Then rerun the relevant shader mode and execution tests.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:30:18Z.
Review: COMMENTED
The order in
vFmaLegacyF32keeps the product round and product flush ahead of the second directed round. The separate zero-sum path uses the correct choice between AND and OR of the zero sign bits for the measured modes. The diff also brings in #19710, so please keep its F32 arithmetic coverage when rebasing and report the two legacy opcodes against a base containing #19710 if attributing changes to this patch alone. The common denormal and MODE tests and the legacy execution fixture are queued on lavapipe.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.