feat(shader): model f32 directed rounding for scalar arithmetic #19710
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19710"
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 akkadbakkad89 on 2026-11-13T21:06:47Z.
What
Issue #981 measured that scalar f32 arithmetic ignores a directed
FLOAT_MODEon gfx1036:v_add_f32/v_fma_f32produce round-nearest results under RTP/RTN/RTZ. This models directed f32 rounding for the scalar arithmetic family.The existing
FPInterpolateF32emitter is already an exact product-sum engine (f64 intermediate,AddRoundToOdd,RoundToPrecision) used byv_interp_*; it now reads the f32 round bits (newInterpolationRound32Shift) and calls the existingRoundToPrecisionDirected, with directed overflow (inf vs max-finite) and RTN negative-zero selection, mirroring the f16 support landed for #19505.RoundingModereclassifies the familyVAddF32/VSubF32/VSubrevF32/VMulF32/VFmaF32(fused) andVMacF32/VMadmkF32/VMadakF32/VMadF32(separately rounded) asDirected32. Translation lowers them through adirectedF32helper that builds the exact product-sum and rounds once; separately-rounded forms round the product then the sum.flushTinyProductis skipped on the directed path (the exact interpolator already resolved the boundary). Legacy/mixed-source and unmeasured ops (VMulLegacyF32,VMullitF32,VFractF32, f16-source forms) stayUnmodelledand still throw on runtime-directed modes.Tested
New
F32DirectedRounding.cppexecution test: 32 bit patterns x 8 ops x {denorm 0,3} x {IEEE 0,1} x round {1,2,3} x wave32/wave64, checked against a f64 TwoSum oracle plus the six gfx1036 reference rows posted in #981. 12 ctest variants, 32768 results each, all pass on NVIDIA GeForce RTX 3070 (driver 617.42, Windows 11) withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer; layer inserted, noVUID-errors.ShaderModeRegisters.cppverifies declared and runtimes_round_modewrites produce the same lowering for add/mul/fma and thatv_fract_f32/f16-mix remain rejected. Regression:agc_driver_interpolation_modes_tests,agc_driver_f16_fma_denormal_modes_tests,agc_driver_f32_fma_denormal_mode1/2_tests,agc_driver_fma_mix_f16_denormal_modes_testsall pass.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)floatTernarynear #19637'sv_fma_mix_f32NaN fix; whichever lands second rebases)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T20:50:22Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent directed rounding of mixed-source
v_fma_f32from bypassing the directed lowering.What I ran
Reviewed head
ef976bd9b1e64ac1dffe510cdf15e52b969a1820against the prepared diff; no tests were run. I read all nine changed files and the review bundle description, commits, manifest, and diff. All changed files were included; no files were excluded by rule.Results
Findings
Blocking
core/shader/recompiler/Translation/src/FloatInstructions.cpp:742:directedselects the exact f32 path forFPFma32regardless off32Sources, but mixed-source FMA operands are read throughreadMixF32at line 738. The subsequent!f32Sourceshandling at lines 757–761 only repairs NaN results; it does not undo the f32 product-sum lowering. Consequently, an f16-sourcev_fma_f32under directedFLOAT_MODEis rounded as an f32 fused operation instead of retaining the intended mixed-source behavior. Keep mixed-source FMA outside the directed path, or implement and verify its directed semantics explicitly.Non-blocking
None.
Not verified
The author reports Vulkan execution tests on an NVIDIA RTX 3070 and regression tests passing, but these were not run during this review. PS5 gfx1013 behavior was not measured, as the change description notes.
To get this to a good state
Exclude mixed-source
v_fma_f32from the directed lowering or implement its directed semantics, then rerun the mixed-source FMA and directed-rounding regression tests on the new head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T12:50:03Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes have no verified blocking defects; the author’s reported GPU runs were not run independently in this review.
What I ran
Reviewed head
bbdb4ab314bf0c678a14c1aa52de3e63f638c790using the prepared diff and pinned repository reader (repo_read.py). No test commands were run.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
I read all eight changed files listed as reviewed in
manifest.json, including every added line.files.jsonexclusions were not available as a separate artifact; the prepared review listing showed no excluded changed files. I did not run tests, validate builds, or independently confirm the reported NVIDIA/GPU measurements or other CI results.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T09:33:43Z.
Review: CHANGES_REQUESTED
The directed arithmetic agrees with the measured/reference tables, but two test blockers remain on exact head
84c57695cf1b4ce291e0a0a14a573c070ad9c07c.integer=1variants,target.supportedCapabilitiesis astd::spanassigned to the localcapabilitiesvector inside theif (selectedInteger)block. That vector is destroyed at line 190, before the firstRecompileRequestcopies/usestargetat line 200. Move the backing vector to the surrounding scope so it remains alive through every recompile.vector_constant_factor_tininess. The production path still emits the intended tiny-product flush, but the existing structure check recognizes only a directFPMul32/FPFma32keep arm. Directed multiplication now appears asFPInterpolateF32behind sign repair andBitCastF32U32, so the checker reports zero exponent checks. Extend the checker for the new IR form while retaining its assertion on the actual tininess-check cost, then rerun the CPU test.Independent exact-rational evaluation confirmed all 18
MeasuredRowsand all 98,304 values generated by the existingExpected(...)formula. Only 6 of the 18 measured tuples currently reach the shader integration matrix with the same relevant operands/modes; adding the remaining captured directed/tininess rows directly to that matrix would make the hardware provenance stronger. This is an integration-coverage request, not a newly found arithmetic mismatch.Merge preview is clean. The official Windows failure is https://github.com/boykopovar/AnyPS5/actions/runs/45041639365/job/137273514978. I did not execute the dangling-span path, compile this head, run a shader, or perform a GPU test.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T07:27:03Z.
Review: COMMENTED
Reviewed — comments
The change models directed rounding for the listed scalar f32 operations, but the f16-source FMA path remains unverified and is still lowered through the existing nearest-even path.
What I ran
Reviewed head
f4604adaa41c1d522b88ed9471b549fe9132e0e6. No build or tests were run; the author's reported GPU test runs were not independently verified.Results
Findings
Blocking
None.
Non-blocking
VFmaF32asDirected32for all source forms. InfloatTernary, the directed branch runs before the existing half-source special handling, so an op_sel half-source FMA is sent through the directed interpolator. This conflicts with the stated unmodelled behavior and may change semantics for these inputs. Please either keep half-source FMA rejected for directed rounding or implement and test its intended behavior.core/shader/recompiler/Translation/src/RoundingMode.cpp:134andcore/shader/recompiler/Translation/src/FloatInstructions.cpp:764.Not verified
ShaderModeRegisters.cpp,agc_driver_f32_directed_rounding_tests.cmake,F32DirectedRounding.cpp,VectorConstantFactorTininess.cpp,Recompiler.hpp,SpirvAluEmitterFloat64.cpp,TranslationContext.hpp,FloatInstructions.cpp,RoundingMode.cpp, anddocs/dev/debt/shader.md. No changed files were excluded from review.To get this to a good state
Nothing is required. Optional: clarify or correct the directed-rounding handling for f16-source
VFmaF32and add coverage for it.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T07:10:17Z.
Review: COMMENTED
Actionable comments posted: 2
d4cac7da-1048-4502-9b53-893789709b99Reviewing files that changed from the base of the PR and between
c6331cc61bandb5ebb4ee9d.core/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_f32_directed_rounding_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/F32DirectedRounding.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/shader.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T07:21:57Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The directed path also applies to half-selected
v_fma_f32sources, contrary to the documented unsupported behavior; gate it onf32Sourcesor preserve the existing lowering for mixed sources.What I ran
Inspected the prepared diff at head
643efc656d33e72846e70a8a9c2492be482b456busingrepo_read.py. No tests or build commands were run.Results
Findings
Blocking
core/shader/recompiler/Translation/src/FloatInstructions.cpp:795selects the directed path for everyFPFma32, including mixed-source instructions. The operands are first read withreadMixF32at line 791, so half-selected sources are converted and then rounded throughdirectedF32at lines 800–801. The debt note says these half-source forms retain nearest-even behavior and are unverified; this implementation changes that behavior. Gate the directed branch onf32Sourcesand retain the existing lowering for mixed sources, or verify and document the intended behavior.Non-blocking
None.
Not verified
Tests, builds, runtime behavior, and PS5 gfx1013 behavior were not verified. The author-reported test results in the PR description were not run during this review.
Read all changed files listed in the manifest:
ShaderModeRegisters.cpp,agc_driver_f32_directed_rounding_tests.cmake,F32DirectedRounding.cpp,VectorConstantFactorTininess.cpp,Recompiler.hpp,SpirvAluEmitterFloat64.cpp,TranslationContext.hpp,FloatInstructions.cpp,RoundingMode.cpp, andshader-f32-directed-rounding.md. No changed files were excluded by the manifest.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T07:24:28Z.
Review: COMMENTED
Actionable comments posted: 1
8c0974c2-6bd2-429b-b739-c6e1d23e3086Reviewing files that changed from the base of the PR and between
b5ebb4ee9dand643efc656d.core/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cppdocs/dev/debt/changes/shader-f32-directed-rounding.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T07:08:15Z.
Review: COMMENTED
Reviewed — no blocking findings
The prepared diff and full text for all 10 reviewed files were inspected at head
06fc4d95fabe8039b3ceabe72d6e4a4796ef2866; no blocking defect was verified, but source context outside the changed files remains unconfirmed.What I ran
Inspected the prepared diff and source snapshots using shell searches and excerpts. The reader search was attempted but failed when it tried to write its call log in the read-only run directory. No build or test was run.
Results
Negative control
Could not run a negative control; no test was run.
Findings
Blocking
None verified.
Non-blocking
None.
Sources
Not verified
All 10 files listed as reviewed in
files.jsonwere inspected from the prepared diff and included full-text snapshots;files.jsonlists no excluded files. Unchanged callers and helper implementations were not inspected because the pinned reader could not write its log. The author-reported GPU and regression test results were not independently run.To get this to a good state
Nothing is required. Optional: independently confirm the reported GPU and regression runs on this head.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:29:18Z.
Review: COMMENTED
The trial merge onto
c1601e56d5was clean. The PR opening says gfx1036 ignores directed rounding forv_add_f32andv_fma_f32, while the translator now applies that direction and the fixture describes measured gfx1036 rows. Please identify which instructions and modes the measured rows actually cover, and explain the intended behavior for the two instructions named in the opening. The fused and separately rounded paths should keep independent fixtures when the series is rebased. Local paired execution is pending.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.