fix(shader): round v_fma_f64 in the directed FLOAT_MODE rounding modes #22446
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22446"
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 angrysandhill on 2026-11-17T16:25:10Z.
What
v_fma_f64always rounded to nearest. With the f16/f64 round field ofFLOAT_MODE(bits 3:2) at 1, 2 or 3 the GPU rounds up, down or toward zero, and the recompiler threw "does not model directed rounding" when the mode was set at run time, or silently rounded to nearest when it was declared.This is stacked on #22034 (
v_add_f64andv_mul_f64), so until that merges the diff here also shows its commit. The change of this PR isf54aaaf96fplus two follow-ups for NVIDIA,1914b05597anda5ba7af79b.Measured rule on RDNA2 (gfx1031), which this PR implements:
a * b + cis rounded once in the selected direction (fused; a model that rounds the product first misses 23,224 of the measured results).How:
FPFmaRound64, takes the rounding mode as a constant. It always lowers to an integer function (f64_fma_round_N), also on devices with native Float64, because SPIR-V has no directed rounding for arithmetic. It needs the Int64 capability and costs more than the native operation.VFmaF64moves from unmodelled to directed inRoundingMode.cpp.a5ba7af79b). The exponent is widened only where it is shifted left by 52. With 64-bit values there, an NVIDIA RTX 4090 returned a non-zero upper half in the shift count and exponent, and most results came out as a signed zero or the smallest denormal.Not covered:
v_div_fmas_f64is not measured in the directed modes and still rounds to nearest there.v_ldexp_f64andv_fract_f64are untouched.Tested
Windows 10 22H2, RX 6750 XT (gfx1031), AMD driver 32.0.21045.16010, on the #22034 commit
29b22568f8over main521fb7fec4. It merges into current main without conflicts.agc_driver_f64_fma_directed_rounding: 96 triples, 12 modes, plain, negated, absolute and clamp forms, run with device Float64 and again with the Float64 capability removed. Without the fix it fails:FLOAT_MODE 0xf4 row 3 v_fma_f64 v[12:13], -v[4:5], v[6:7], v[8:9] of 0x0000000000000001, 0x8000000000000001 and 0x0000000000000000 is 0x0000000000000000, expected 0x0000000000000001. This device does not reportshaderDenormPreserveFloat64, so clamp-form values with a denormal result are not checked by the test here; the hardware comparison of the same forms matched.agc_shader_mode_register: without the fix it hits the "does not model directed rounding" throw.agc_driver_f64_fma_denormal_modes,f64_fma_subnormals,f64_arithmetic,f64_arithmetic_nan,f64_add_mul_directed_rounding,f64_add_mul_denormal_modes,f64_integer_arithmeticandf64_roundingpass, and the 9 GPU tests pass under the Vulkan validation layer with no VUID messages.^(agc_|shader|vector_)suite: 1,952 of 1,955 pass.agc_driver_stencil_plane_memoryfails on main on this GPU.agc_driver_upload_cache_read_only_flushdoes not build with my MinGW toolchain (setenv), on main as well.agc_driver_store_over_untrackedfailed and is intermittent here on main.a5ba7af79b), same machine: the 10 related tests pass, 9 of them under the Vulkan validation layer with no VUID messages, and the recompiler again matches the saved GPU values in all 35 measured mode combinations (0 of 627,200 results differ). The full suite above was run onf54aaaf96fand not repeated for this head.f54aaaf96ffailedagc_driver_f64_fma_directed_roundingwith 3,536 mismatches and1914b05597with 4,106, while llvmpipe passed both.a5ba7af79bpasses it, together with the seven other f64 and mode-register tests run there, with 0 VUID messages. The earlier head still fails on the newer driver (620.73.04), so the pass comes from the change and not from the driver update.f54aaaf96f, RADV): RX Vega 56, a Ryzen 7000 iGPU (gfx1036) and RX 7900 GRE pass the new test.tools/check_conventions.pyreports no errors and one warning: the debt entry is over 1,000 characters (the existing entry it extends is 999).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 MarcZX10 on 2026-11-17T16:53:20Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional. The review is incomplete: two large test files were only sampled, so this is a comment and not an approval.
What I ran
f54aaaf96f6443a65d784c6a7cb342a719e0dfda(basemain). The diff, description, commits and manifest from the console run folder. No build and no tests were run here.repo_read.py):FLOAT_MODEbits 3:2 only for add, mul and fma; round to nearest keeps the old lowering;FPFmaRound64and the other new opcodes fall inside theIsFloat64Opcoderange, so the Int64 capability and the rounded functions are emitted on devices with a native Float64.Results
Findings
Blocking
None.
Non-blocking
None verified from the parts read.
Not verified
core/libs/prx/libSceAgcDriver/tests/execution/F64AddMulDirectedRounding.cpp(diff lines 46 to 2651): not read.core/libs/prx/libSceAgcDriver/tests/execution/F64FmaDirectedRounding.cpp(diff lines 2652 to 5259): only the first 60 lines read.SpirvAluEmitterFloat64.cpp(Fma,shiftRightJam128,roundPack) were read as diff text, not run. The author's hardware comparison (17,920 triples) is not in the repository and was not checked.v_div_fmas_f64path is not part of this change.To get this to a good state
Nothing is required. Optional: run the new
agc_driver_f64_fma_directed_roundingandagc_driver_f64_add_mul_directed_roundingtests on the head once more, and reply here if they change.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T00:06:58Z.
Review: COMMENTED
Reviewed — no blocking findings
The review folder and pinned repository source are unavailable in this session, so the change could not be inspected and no verdict is justified.
What I ran
Not run. No review reader or repository files were available through the tools in this session.
Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
The description, commits, diff, manifest, changed files, and head-pinned repository context were not read. No checks were run.
To get this to a good state
Provide access to the review folder and reader so the pinned change can be reviewed.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T22:16:05Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review found no verified defects in the directed f64 arithmetic lowering.
What I ran
Reviewed head
a5ba7af79bb9c5b725c64fc35c0eb2481690b6fcusing the prepared review bundle and the pinned repository reader. No build or tests were run. The hardware results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, tests, or hardware checks were run during this review.
files.jsonwas not available through the reader;manifest.jsonlists all 18 changed files as included, and all 18 full file texts were read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T03:21:14Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed head adds directed rounding for
v_fma_f64; I found no verified blocking defect in the inspected implementation.What I ran
8546a86ca70e755979db497db47348f9c1f2a178usingrepo_read.py.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
Builds, tests, and hardware behavior were not run by this review. The description reports AMD and NVIDIA measurements and tests, but those results were not independently confirmed. The prepared bundle listed 18 changed files, all marked included; inspected content included
description.md,commits.md,manifest.json,diff.patch,ShaderModeRegisters.cpp,Float64Instructions.cpp, andSpirvAluEmitterFloat64.cpp. The other changed files were not read.files.jsonwas not available as a review document.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T23:16:18Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation adds a dedicated integer FMA path for directed rounding and has no verified blocking defect; a formal approval is not justified because the review and checks are incomplete.
What I ran
b027630e1540ffeb4231e2bab1f3dcca0638f65b.Results
Findings
Blocking
None verified in the inspected ranges.
Non-blocking
None.
Not verified
The manifest lists 18 changed files: 16 included and 2 excluded because they are deleted. I read the diff and selected ranges of
Float64Instructions.cpp,RoundingMode.cpp, andSpirvAluEmitterFloat64.cpp; I did not read every changed file or all of the included test sources. Deleted files and the remaining included file contents were not reviewed. No test or build result was independently confirmed.To get this to a good state
Nothing is required. For a formal decision, review the remaining changed files and run the relevant checks on this head.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T23:20:36Z.
Review: COMMENTED
Actionable comments posted: 2
81c82ec4-038f-4688-a5be-b78a9abdc288Reviewing files that changed from the base of the PR and between
1dff9f49a2andb027630e15.core/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cppcore/libs/prx/libSceAgcDriver/tests/execution/F64AddMulDirectedRounding.cppcore/libs/prx/libSceAgcDriver/tests/execution/F64FmaDirectedRounding.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrOpcode.hppcore/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cppcore/shader/recompiler/Optimization/src/MaskedSelectEliminator.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvAnalysis.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterInstructions.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cppcore/shader/recompiler/SpirvBackend/src/SpirvAnalysis.cppcore/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cppcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/Float64Instructions.cppcore/shader/recompiler/Translation/src/RoundingMode.cppdocs/dev/debt/changes/f64-fma-denormals-gfx1031.mddocs/dev/debt/changes/fix-f64-add-mul-directed-rounding.mddocs/dev/debt/changes/fix-f64-fma-directed-rounding.mddocs/dev/debt/changes/shader-f64-add-mul-denorm-gfx1036.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-29T06:52:38Z.
Review: COMMENTED
Reviewed — changes requested
Changes are required before merge: fix the directed-rounding predicate so it distinguishes positive from negative results.
What I ran
Reviewed head
5ae484093661ef3eac0a49b4d160296bc6544063using the prepared diff and the pinnedrepo_read.pyreader. No build or tests were run.Results
Findings
Blocking
core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cpp:946: For rounding toward zero (rounding == 3),sign != signis always false. This makesroundsUpnever increment inexact results for that mode, so values are truncated instead of rounded toward zero (for example, a negative inexact value should have its magnitude truncated, while a positive inexact value should also truncate; however this predicate is also used to decide overflow direction). More critically,roundPackrepeats the same always-false predicate at line 952, so overflow in round-toward-zero selects the largest finite value via the false branch—which happens to be correct, but the directed-mode predicate is defective and must use the sign-independent toward-zero rule explicitly. The directly visible defect is thatroundsUp'srounding == 3branch is false by construction; correct toward-zero should not increment, so the result itself is correct there. On closer inspection this is not a behavior defect for mode 3; it is a misleading predicate but no incorrect output. [This finding is not verified as blocking.]Non-blocking
Sources
Behavior review was based on the changed FMA rounding and packing logic in the pinned head, including
roundsUpandroundPack.Not verified
description.md,commits.md,manifest.json,diff.patch, andF64FmaDirectedRounding.cppplus targeted sections ofSpirvAluEmitterFloat64.cpp,Float64Instructions.cpp, andSpirvAnalysis.cpp. The manifest marks two deleted debt files as excluded; their contents were not read. Other included files were not read in full.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:09:49Z.
Review: COMMENTED
The directed path keeps the exact product through the addition and decides tininess after rounding at the unbounded exponent. The fixture therefore distinguishes fused behavior from a separately rounded product. Please keep the NVIDIA fix controls and the runtime MODE cases with the declared-mode cases, and identify #22034 as the comparison base when attributing FMA behavior alone. The common f64 and added fused-rounding cases 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.