fix(shader): round v_add_f64 and v_mul_f64 in the directed FLOAT_MODE rounding modes #22034
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22034"
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-17T02:49:30Z.
What
v_add_f64andv_mul_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.Measured rule on RDNA2 (gfx1031), which this PR implements:
How:
FPAddRound64andFPMulRound64, take the rounding mode as a constant. They always lower to integer functions (f64_add_round_N,f64_mul_round_N), also on devices with native Float64, because SPIR-V has no directed rounding for arithmetic. They need the Int64 capability and cost more than the native operation.VAddF64andVMulF64move from unmodelled to directed inRoundingMode.cpp.Not covered: an output modifier that overflows the result in a directed mode still gives infinity; that case is not measured.
v_fma_f64,v_ldexp_f64,v_fract_f64andv_div_fmas_f64are untouched.Tested
Windows 10 22H2, RX 6750 XT (gfx1031), AMD driver 32.0.21045.16010, on main
3b7ffd7a05; rebased onto521fb7fec4afterwards, which changes nothing undercore/shaderorcore/libs/prx/libSceAgcDriver.agc_driver_f64_add_mul_directed_rounding: 96 pairs, 12 modes, plain, negated, absolute and clamp forms, run with device Float64 and again with the Float64 capability removed. On main it fails:FLOAT_MODE 0xf4 row 0 v_add_f64 ... of 0x0000000000000001 and 0x9fe0000000000000 is 0x9fe0000000000000, expected 0x9fdfffffffffffff. This device does not reportshaderDenormPreserveFloat64, so 184 clamp-form values with a denormal result are not checked by the test here; the hardware comparison of the same forms matched.directed64inagc_shader_mode_register: on main it hits the "does not model directed rounding" throw.agc_driver_f64_add_mul_denormal_modes,f64_integer_arithmetic,f64_arithmetic,f64_arithmetic_nan,f64_fma_denormal_modes,f64_roundingandcvt_f32_f64_denormal_resultpass, and the 8 GPU tests pass under the Vulkan validation layer with no VUID messages.^(agc_|shader|vector_)suite: 1,949 of 1,954 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. Twoagc_driver_runtime_buffer_spanstests timed out at 4 in parallel and pass on their own.tools/check_conventions.py --base origin/mainpasses.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
Bug Fixes
Tests
Documentation
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T03:10:41Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
29b22568f8c157d8e42e0573bee1e89cdaf2dc08, basemain.repo_read.py):Results
test,NanResultBits,DefineIntegerFunctionIsFloat64OpcoderangeFindings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cpp:844—test(spv::OpINotEqual, sign, sign)is always false, so the rounding-3 branch is "never away". It is correct, but a plain false constant would read more clearly. Optional.Sources
roundPackrounding branchesIsFloat64OpcoderangeDirected16handlingNot verified
agc_driver_f64_add_mul_directed_rounding,directed64, and the 1,949 of 1,954 suite run. These are author-reported; I did not run them.core/libs/prx/libSceAgcDriver/tests/execution/F64AddMulDirectedRounding.cpp: the expected-value table (about lines 31–2514) was not read, so this file is not fully reviewed.floatMode. This was not traced. The testverifyDirectedF64Arithmeticasserts it.To get this to a good state
Nothing is required.
Optional: simplify the rounding-3 "away" test noted above.
Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T07:44:43Z.
Review: COMMENTED
macOS GPU test (Apple M4, MoltenVK 1.4.2, validation layer 1.4.363.1, x86-64 build under Rosetta)
Base:
upstream/maina72186d3cf+ #22056 + #22074 (both needed for the macOS build); PR head29b22568f8merged on top. Built clean (only the known libcurl link failure, #17425).Env per AGENTS.md:
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer,ctest -R 'recorder|constant_phi|masked_select|sample_bit_descriptor|pixel_ancillary|scalar_buffer|shader_mode_registers|agc_driver_f64|command_batch|awaited_slot|agc_driver_idle|detiler' -V, 3 runs each on base and PR.VUID-errors.Insert instance layer "VK_LAYER_KHRONOS_validation"; none logswas not found but was requested. The tests without layer lines (agc_constant_phi,agc_masked_select,agc_command_batch_*,pixel_ancillary, ...) never touch the loader.agc_driver_f64_*tests skip (the M4 has noshaderFloat64);agc_driver_recorderfails witha kept vertex window was not mirrored(#20831); the recorder tests each log oneVUID-VkDeviceCreateInfo-sType-uniquefor a duplicatedVkPhysicalDevicePortabilitySubsetFeaturesKHRin the test's own device (#21965).agc_driver_f64_add_mul_directed_rounding: passes 3/3 with the layer inserted and 0VUID-. It reportsdevice Float64 0, so on the M4 it checks the emulated f64 path, not native f64 (0 clamped values with an f64 denormal result not checked; they need DenormPreserve 64).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T00:58:17Z.
Review: DISMISSED
Reviewed — comments
Changes are required before merge: verify that the declared rounding direction matches the intended GPU mode and update the rounding implementation if it does not.
What I ran
Reviewed head
4ed9f8366abecaf3669cd53e1b3f472973976b55from the prepared patch and pinned reader. No build or tests were run.Results
Findings
Blocking
roundPackmaps the three non-nearest modes as follows: rounding value 1 increments a positive result, value 2 increments a negative result, and value 3 never increments. The translation passes(FLOAT_MODE >> 2) & 3directly as that value (core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cpp:844-845;core/shader/recompiler/Translation/src/Float64Instructions.cpp:31-33). The description and new test’s mode table identify 1 as up, 2 as down, and 3 as toward zero. Under that mapping, value 1 should increment negative results too (toward +∞), and value 2 should increment positive results too (toward −∞). As written, the helper instead implements toward-zero for 1 and 2, and nearest for 3. Correct the direction predicates and expected cases before merging.Non-blocking
None.
Not verified
No build, test suite, hardware execution, or CI run was performed. The author reports hardware and test results in
description.md; those were not independently reproduced. All 15 changed files were included in the manifest, but only the changed hunks and targeted source ranges were read; the remaining file contents were not reviewed.To get this to a good state
Correct the directed-rounding predicates, then rerun the directed arithmetic tests across all three modes and both positive and negative inexact results.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T03:22:48Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: fix the toward-zero rounding path, which currently never increments a non-exact result.
What I ran
Reviewed head
aa3bbebeb586a954634e3126b7b786b5eb44e918. I read the prepared description, commit list, manifest and diff, then inspected the affected float64 translation and rounding helper. No commands or tests were run.Results
Findings
Blocking
core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cpp:844makesawayfalse for rounding mode 3 by comparingsignwith itself usingINotEqual. The following increment condition therefore never increments, so toward-zero rounding truncates the significand for all inexact results. Compute whether the result is negative and select the rounding direction accordingly; toward zero should not increment.Non-blocking
None.
Sources
Not verified
No tests or builds were run. All changed files listed as included in the manifest were available in the prepared review folder; the deleted gfx1036 debt fragment was excluded because it has no new text.
To get this to a good state
Correct mode 3 handling in
roundPack, then rerun the directed f64 arithmetic test and relevant shader tests on the new head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T23:17:57Z.
Review: COMMENTED
Reviewed — comments
The directed-rounding implementation is wired through translation and SPIR-V emission, but I did not read every changed line or rerun the reported checks, so a formal approval is not justified.
What I ran
No commands or tests were run. I inspected the prepared diff and selected repository files at head
eb209553a6cbee02d69efbe99fab12319d3b0612using the pinnedrepo_read.pyreader.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
I read
description.md,commits.md,manifest.json, and selected ranges ofdiff.patch. In the repository I read selected ranges fromShaderModeRegisters.cpp,F64AddMulDirectedRounding.cpp,IrOpcode.hpp,IrOpcode.cpp,MaskedSelectEliminator.cpp,SpirvAnalysis.hpp,SpirvEmitterInstructions.hpp,SpirvEmitterState.hpp,SpirvAluEmitterFloat64.cpp,SpirvAnalysis.cpp,SpirvFlowEmitter.cpp,SpirvModuleSetup.cpp,TranslationContext.hpp,Float64Instructions.cpp,RoundingMode.cpp, andfix-f64-add-mul-directed-rounding.md.I did not read the full 2,600-line
F64AddMulDirectedRounding.cpp, every changed line in the other files, or the deleted debt document. I did not run the reported hardware, Vulkan, or convention checks, and did not verify the reported results independently.To get this to a good state
Nothing is required. Optional: complete the review of the test vectors and remaining changed lines, and rerun the checks on this head before a formal approval.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T23:19:13Z.
Review: COMMENTED
Actionable comments posted: 4
b0203005-105b-4b20-b859-551993d8cc1cReviewing files that changed from the base of the PR and between
1dff9f49a2andeb209553a6.core/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cppcore/libs/prx/libSceAgcDriver/tests/execution/F64AddMulDirectedRounding.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/fix-f64-add-mul-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; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T05:50:26Z.
Review: COMMENTED
Reviewed — comments
The review covered all included changed files at head
8508c0b25d1a91842af872a4f90120a0a3a509a0; implementation and test behavior appear sound from the inspected source, but I did not run checks and the deleted file was not read, so approval is not justified.What I ran
No commands or tests were run. I inspected the prepared diff and pinned source with the review reader; no merged preview was run.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
docs/dev/debt/changes/shader-f64-add-mul-denorm-gfx1036.mdhad no head text and was not read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:13:35Z.
Review: COMMENTED
The trial merge onto
a1b75b0947was clean. I reviewed the software path for directed FP64 add and multiply, including signed-zero cancellation and the underflow check before limited-exponent rounding. Keep the tie and sign cases with the new execution fixture when the series is rebased. Paired validation against the existing FMA subnormal control 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.