fix(shader): round v_ldexp_f64 in the directed FLOAT_MODE rounding modes #26096
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26096"
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:43Z.
What
v_ldexp_f64was lowered to a hostLdexpthat rounds to nearest even, so in the directedFLOAT_MODEf16/f64 round modes (round field 1 to 3, declared or set bys_round_mode) an overflow gave an infinity where the hardware gives the largest finite value (when the mode rounds toward zero for that sign), and a denormal result was rounded to nearest instead of in the mode. Scaling by a power of two is exact otherwise, so those are the only differences.ldexpF64builds the result from the (flushed) source's significand and exponent bits with integer operations only, with noFPLdexp64or other f64 float operation. In the normal range the result is exact and only the exponent changes. A subnormal result is the normalized significand shifted right, plus one unit when bits were shifted out and the mode rounds away from zero for that sign (which can carry into the minimum normal). An overflow gives an infinity, or the largest finite value when the mode rounds toward zero for that sign. Zeros, infinities and NaNs pass through, and the NaN and f64 output flush handling keeps running after it, as before. Round to nearest keeps the previousFPLdexp64lowering.shaderDenormPreserveFloat64gets noDenormPreserve 64, and Vulkan then lets it flush subnormalOpFMulresults. The first version of this PR (02b18ec684) scaled the result back withFPLdexp64to detect the rounding direction, which such a device could break (mihiii1337's review:0x1by 52 would step the exact minimum normal up by one unit).RoundingMode.cppclassifiesVLdexpF64asDirected16, so a mode set bys_round_modeis modelled instead of rejected.v_ldexp_f64records the measurement.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.Tested
Windows 11, Radeon RX 5700 XT (gfx1010), AMD driver 32.0.21045.5002.
src0 * 2^nonce in the mode; flush per the denormal field as before" exactly, except that a signaling NaN is returned unquieted at IEEE=0, whichmainalready does.maindiffers from it on 129 to 571 of the 1838 rows per directed configuration, and on none at round to nearest.02b18ec684),agc_oracle_runnermatched the model on all 32 configurations (0 mismatches), and the hardware on 11028 rows withs_round_mode4, 8 and 12 at f16/f64 denormal modes 0 and 3. That sweep was not rerun on811cc76112; the integer path is covered by the test and the exact-model check below.agc_driver_f64_ldexp_directed_rounding, with two tables of 32 inputs each and the hardware's results for round modes 1 to 3 in f16/f64 denormal modes 3 and 0:0x1by 52,0x0010000000000000by -1), results exactly at and just below the minimum normal, a round-up carrying into it, half-unit and 1.5-unit subnormals, exact overflow at 2^1024, and exponents of ±2^31. On the RX 5700 XT hardware oracle, all 384 results match (3 round modes × 2 denormal modes × IEEE 0 and 1 × 32 rows), and IEEE does not change any of them.s_round_mode: 48 of 48 runs pass. On a device that offersshaderDenormPreserveFloat64, every run is repeated withDenormPreserve 64turned off. The RX 5700 XT has noshaderDenormPreserveFloat64, so all its runs were already without it.s_round_mode, for a target withoutDenormPreserve 64and checks that the SPIR-V computes no f64 value. Round to nearest is checked to compute one, so the scan can detect them. This part needs no device. With 02b18ec684's lowering it fails:v_ldexp_f64 FLOAT_MODE 0xc4 computes an f64 value, which a device without DenormPreserve 64 may flush.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 at811cc76112, each run after its test targets were relinked:main21 of 21 passed, this branch 22 of 22 passed in 2 of 2 runs (with the newagc_driver_f64_ldexp_directed_rounding).Insert instance layer "VK_LAYER_KHRONOS_validation"appears 20 times onmainand 21 times in each branch run, once per GPU test (agc_shader_mode_registercreates no Vulkan instance).was not found but was requestedappears 0 times in every log, and so doesVUID-.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 --branchreports one-line conflicts in theUnmodelledf16/f64 list ofRoundingUseOfinRoundingMode.cpp: #22034 and #22446 (and #26101, stacked on #22446) remove the opcodes on the lines just aboveVLdexpF64, and #26047 removes the one just below; none of them changesv_ldexp_f64, and whichever lands second resolves the adjacent lines.ldexpF64is called in theresultexpression and declared next toquietNan64to stay clear of #22384 and #22446 in the same files. #20187 could not be compared automatically; itsTranslationContext.hpphunks add two unrelated members.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:09:01Z.
Review: COMMENTED
Reviewed — comments
The directed-rounding correction is supported by the inspected implementation and test cases; I did not run the reported validation, so this review does not justify approval.
What I ran
Reviewed head
02b18ec68402d278856865591c542de65afe57ccusing the prepared diff andrepo_read.py. No tests or build commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests or build were run. The hardware measurements and reported validation results were not independently verified. The prepared bundle excluded no changed files; all five changed files were read.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T09:42:57Z.
Review: CHANGES_REQUESTED
The directed-rounding correction works when f64 subnormals are preserved, but it can mis-step an already exact result on a Vulkan device where
shaderDenormPreserveFloat64is unavailable. The backend emitsDenormPreserve 64only when that property is supported; otherwise Vulkan permits denormal inputs or results ofOpFMulto be flushed to zero by default.A concrete source-path witness is positive min-subnormal (
0x0000000000000001) with exponent52, rounding toward +infinity, and guest f64 denorm mode 1 or 3. The forwardFPLdexp64result is exactly min-normal (0x0010000000000000). On an allowed host model which preserves the source operand but flushes the subnormal result of the inverse scaling at line 137,backbecomes zero. The new comparison then classifies the exact forward result as too small and returns0x0010000000000001. A second witness, min-normal with exponent-1in mode 3, becomes0x1instead of0x0008000000000000under the same model.Please make the inexact-direction test independent of host denormal handling, for example by comparing exponent/significand information in integer form, or provide a correct fallback when
DenormPreserve 64cannot be enabled. Add a regression that models the result-FTZ path.The CPU oracle matched all 192/192 checked-in rows and 108,096/108,096 additional exact-Fraction cases under RNE with gradual underflow; removing the correction differed in 49 checked-in rows. It also reproduced both result-FTZ witnesses above. This is an allowed Vulkan behavior model, not a measured physical-driver failure. The exact Windows job passed 227 other tests but its whitelist did not execute the new fixture; Linux was skipped. Merge, diff, conventions (zero errors, one existing debt-length warning), and debt folding passed. No shader or GPU test was run in this review.
Vulkan default denormal rule: https://docs.vulkan.org/spec/latest/appendices/spirvenv.html#spirvenv-precision-operation
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-23T12:38:08Z.
Review: COMMENTED
Windows check of head
02b18ec684on an NVIDIA GPU that lacksshaderDenormPreserveFloat64, the kind of device mihiii1337's change request is about, with an AMD GPU that has it as the control. Merged ontomain071799dc88(clean merge). I also ran mihiii1337's witness through the PR's test.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:vulkaninforeportsshaderDenormPreserveFloat64 = falseandshaderDenormFlushToZeroFloat64 = false, so the backend emits noDenormPreserve 64.1002:164e, Adrenalin 26.10.2):shaderDenormPreserveFloat64 = true.This was built together with #26174, #26178 and #26179, which touch other files.
agc_driver_f64_ldexp_directed_rounding,agc_driver_f64_ldexp_denormal_modes,agc_driver_f64_arithmetic,agc_driver_div_fixup_directed_roundingand the f16/f32/SDWA/VOP3 ldexp tests:main8 of 8, and with this PR 9 of 9 in 2 of 2 runs, on both GPUs. NoVUID-lines.F64LdexpDirectedRounding.cpp(0, exponent 1023) for source0x0000000000000001, exponent 52. The exact result is min-normal0x0010000000000000with f64 denormals kept (FLOAT_MODE0xc_), and0with them flushed (0x0_). The test's three directed round modes pass on both GPUs, with both denormal modes and both IEEE settings, declared and throughs_round_mode. So on this NVIDIA device the inverse scale at line 137 keeps the subnormal, and the forward result is not stepped.roundLdexpF64returning the round-to-nearest result,agc_driver_f64_ldexp_directed_roundingfails withv_ldexp_f64 FLOAT_MODE 0xc4, IEEE=0 of 0x37bdf5f56940975e by -917 is 0x3bebead, expected 0x3bebeae.This doesn't settle the change request. Vulkan still lets a device without
shaderDenormPreserveFloat64flush thatOpFMul; this one happens not to. It does show the PR works on a real device without the guarantee. If the comparison is made independent of the preserved subnormal, the witness row above would be a cheap regression case to keep.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T13:23:02Z.
Review: APPROVED
Rechecked exact head
811cc7611244ffd82721d3d1ec2cdae5d2bf6ebc. The no-shaderDenormPreserveFloat64case from my previous review is fixed.The new path handles the directed adjustment through an integer significand/exponent representation and pins both exact-result witnesses. Its SPIR-V scan runs before Vulkan execution; the emitted shift width is masked to 63, so the unused branch does not introduce an oversized SPIR-V shift.
The exact Hosted Windows selection passes 227/227, although it does not execute the new Vulkan case. Contributor-reported hardware evidence does: on a Quadro P3200 that exposes Float64 without Float64 denormal preserve, the new test fails on main and passes here; RTX 4070 and RTX 3070 runs also pass with validation enabled and no VUIDs. 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:04Z.
Review: APPROVED
Re-review on Windows of head
811cc76112, on the same RTX 5070 Ti as my earlier comment (shaderDenormPreserveFloat64 = false), with the Radeon iGPU (which has it) as the control.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 #26098 and #19532, which touch other files.agc_driver_f64_ldexp_directed_rounding,agc_driver_f64_ldexp_denormal_modes,agc_driver_f64_arithmetic,agc_driver_div_fixup_directed_rounding, the f16/f32/SDWA/VOP3 ldexp tests andagc_shader_mode_register:main9 of 9, and with this PR 10 of 10 in 2 of 2 runs, on both GPUs. NoVUID-lines.agc_driver_f64_ldexp_directed_roundingfails on the RTX withv_ldexp_f64 FLOAT_MODE 0xc4, IEEE=0 of 0xf7cf1df9ed6ce by 2048 is 0x7fefffffffffffff, expected 0x7ff0000000000000.The code: the directed path no longer computes any f64 value, which settles the question my earlier comment left open; that comment's probe only showed this device happens to keep the subnormal. The integer version reads right to me:
FindUMsb64, so a subnormal source works.Round to nearest keeps
FPLdexp64.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-24T23:33:06Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the reported measurements are author-supplied and the review did not run the test suite.
What I ran
Reviewed head
811cc7611244ffd82721d3d1ec2cdae5d2bf6ebc. No commands or tests were run. Read the prepared description, commits, diff, manifest and all five changed files; there were no exclusions listed in the manifest. The repository reader script and its search interface were not available through the provided tools, so I could not inspect additional callers or test registration.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The test harness's discovery or registration of the new execution test, additional callers, build results, hardware behavior, and the reported sweeps and CI checks were not independently verified. The changed files read were
core/libs/prx/libSceAgcDriver/tests/execution/F64LdexpDirectedRounding.cpp,core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp,core/shader/recompiler/Translation/src/Float64Instructions.cpp,core/shader/recompiler/Translation/src/RoundingMode.cpp, anddocs/dev/debt/changes/ldexp-f64-directed-rounding.md.To get this to a good state
Nothing is required. The optional next step is to confirm the new execution test is included in the project's test discovery and run the reported checks on this head.