fix(shader): round v_fract_f32, v_fract_f16 and v_fract_f64 in directed FLOAT_MODE rounding modes #26047
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26047"
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-23T05:33:22Z.
What
v_fract_f32,v_fract_f16andv_fract_f64computex - floor(x), which is inexact for a negative input whose fractional part is below 0.5 (the result lies in (0.5, 1)). The hardware rounds that result once in theFLOAT_MODEround field of the instruction's precision (f32 forv_fract_f32, f16/f64 for the others) and then clamps it below 1. The recompiler always rounded to nearest even, so with round toward +infinity, -infinity or zero it was one unit off on those inputs, and it threw "does not model directed rounding" whens_round_modeselected a directed mode at run time.fract(|x|)with1 - result; both are exact, and as non-negative floats they compare as unsigned integers, so f64 needs no f64 compare. The result is positive, so toward zero is toward -infinity. For f64 the step applies only to finite operands, so ±Inf keeps the default NaN0xfff8000000000000in every mode; the f32 and f16 paths already select their invalid result after the step.convertF32ToF16Bits.RoundingMode.cppclassifiesVFractF32asDirected32andVFractF16/VFractF64asDirected16, so a mode set bys_round_modeis modelled instead of rejected.Found by a differential sweep of 332 VOP1/VOP2/VOP3/VOPC/VOP3P opcodes through
tools/hw-oracleon an RX 5700 XT (gfx1010, RDNA1, the PS5's gfx10.1 generation) against the same bodies throughagc_oracle_runner; at default float modes everything else that differed is already covered by open PRs or deferred debt entries. #19710 leavesv_fract_f32unmodelled, and no open PR changes fract rounding.Tested
Windows 11, Radeon RX 5700 XT (gfx1010), AMD driver 32.0.21045.5002.
x - floor(x)once in the mode, clamp below 1" exactly (0 mismatches over about 384,000 results).agc_oracle_runnerwith this change matches that model with 0 mismatches in all 48 configurations, and matches the hardware on 3000 rows with the mode set bys_round_mode(f32, f16 and f64 in one body).maindiffers from the hardware on 4 to 41 of 2628 rows per instruction and mode.agc_driver_fract_directed_rounding: 36 inputs per precision (including -Inf, +Inf and two quiet NaNs) with the hardware's results for round modes 1 to 3, run with FLOAT_MODE 0xc0 and 0xf0 at IEEE 0 and 1, once declared inFLOAT_MODEand once set bys_round_mode(24 of 24 runs pass). Onmainit fails:v_fract_f32 FLOAT_MODE 0xc5, IEEE=0 of 0xb5de8693 is 0x3f7fffe4, expected 0x3f7fffe5. Without the finite guard (first commit,39d4a28c17) it fails:v_fract_f64 FLOAT_MODE 0xca, IEEE=0 of 0xfff0000000000000 is 0xfff7ffffffffffff, expected 0xfff8000000000000.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 atab2742cac5(maina2d8d409dbmerged; the same change as5584985d4dbelow), 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 40 of 40 passed (the newagc_driver_fract_directed_roundingadded). 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 38 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.py --base origin/mainandtools/debt_fold.py --checkpass.maina2d8d409db(b4ea14a5cc): #26096 had movedVLdexpF64out of the sameUnmodelledlist, so the conflict resolves to neither line.main's766c72537cremovedapplyF16ResultModifiersand now applies the f16 output modifier and clamp to the final bits, soab2742cac5converts the directedv_fract_f16result withconvertF32ToF16Bitsalone; the modifier and clamp are then applied once, after rounding, as on the round-to-nearest path.tools/check_conventions.pypasses onab2742cac5.main9900bfa949as39d4a28c17,cf6cadcf41and5584985d4d, with the same diff in all six changed files asab2742cac5againsta2d8d409db, andmain5ab4337794was merged in81e03e9d38with no conflicts.tools/check_conventions.pypasses on81e03e9d38; the GPU tests above were not rerun after the rebase.tools/pr_overlap.py --branchreports one-line conflicts in theRoundingUseOfopcode lists ofRoundingMode.cppwith #19505, #19710 and #22446, which move other opcodes out of the sameUnmodelledlists; none of them changes fract. #20187 could not be compared automatically; its hunks are infloatBinaryand two header members, away from this change.Hardware model check (tools/hw-oracle)
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-23T05:55:21Z.
Review: COMMENTED
Reviewed — comments
The directed rounding implementation is present, but the new execution test has no registered CTest entry, so the reported test coverage is not reproducible through the repository’s test registration.
What I ran
Reviewed head
09832d98abb1b2ede57425c21f1345a7712a4a61using the prepared diff andrepo_read.pyreader. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
FractDirectedRounding.cppis picked up as an execution-test source, but the repository’s CTest registrations are defined intests/cmakefragments. Noagc_driver_fract_directed_rounding_tests.cmakefragment or matching registration exists, so ordinary CTest runs will not invoke this test. Add the matching registration fragment. Changed line:core/libs/prx/libSceAgcDriver/tests/execution/FractDirectedRounding.cpp:233.Not verified
files.json; the five changed files listed there were read.To get this to a good state
Nothing is required. Optional: register the new execution test with CTest so it runs in the project’s test workflow.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T06:35:24Z.
Review: CHANGES_REQUESTED
The f64 directed-rounding correction also runs on infinity and can turn the quiet invalid-operation result into a signaling NaN.
For
V_FRACT_F64(-Inf)(0xfff0000000000000), the existingEmitFPFract64result is canonical quiet NaN0xfff8000000000000. InroundFractF64,FPFract64(abs(-Inf))produces the same negative canonical qNaN, while1 + -resultpropagates positive qNaN0x7ff8000000000000. For RTN/RTZ, the unsignedless(rest, part)comparison is therefore true; the input is negative andpartis nonzero, so the correction decrements the qNaN to0xfff7ffffffffffff, which is signaling. The outernanselection only recognizes an originally NaN operand, not infinity, so it does not restore the quiet result.Please restrict the correction to its finite domain (or otherwise preserve the existing special result) and add
-Infto the f64 declared/runtime rounding fixture.+Infand NaN payloads are also useful special controls. The f32/f16 paths already select their invalid-infinity result after their correction, so this blocker is specific to the f64 ordering.The current fixture's 32 rows contain no infinities or NaNs. This is a static review of exact head
09832d98abb1b2ede57425c21f1345a7712a4a61; I did not run a GPU binary.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T07:41:53Z.
Review: APPROVED
Re-reviewed the requested head
7f67fa3692c0da2de411db4b928d290d5952fdb3. The finite guard fully resolves my previous-Infblocker: Inf/NaN values can no longer enter the directed-rounding bit step, while finite values keep the existing selection.Independent CPU A/B used the exact parent/head
float64Unary,roundFractF64,quietNan64,flushF64Bitsand float-mode logic with the head's 36-lane fixture:-InfRTN/RTZ result0xfff7ffffffffffff;An additional 256-case matrix across all four round/denorm fields and both IEEE modes used signed Inf, qNaN and sNaN payloads. Parent had 16 mismatches on the same
-Infpath; head had 0. IEEE-off kept the established sNaN input bits, while IEEE-on quieted them with sign/payload preserved. The new runtime and declared-code fixture variants both pin the special rows to exact words.The author also reports native RX 5700 XT/gfx1010 measurements for the four modes and a concrete old-head negative control; I did not run a local SPIR-V or GPU dispatch. Diff/convention/CI status was checked separately by the existing reviews.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T07:46:37Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes implement directed rounding for the three fract instructions, and the inspected code and supplied test results support the change.
What I ran
Reviewed head
7f67fa3692c0da2de411db4b928d290d5952fdb3. I read the prepared description, commit list, manifest, diff, and changed source files, plus the f16 conversion helper used by the change. I did not run commands or tests; test results below are author reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The new Vulkan test and other reported checks were not run by this reviewer. I did not inspect every changed file's full text; the new execution test was read only through line 100, and the rest of that test and the full
RoundingMode.cppwere not read. The author reports RDNA1 measurements; PS5 gfx1013 behavior was not measured.Files read:
core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp,core/shader/recompiler/Translation/src/FloatInstructions.cpp,core/shader/recompiler/Translation/src/Float64Instructions.cpp,core/shader/recompiler/Translation/src/RoundingMode.cpp,core/shader/recompiler/Translation/src/TranslationContext/SubwordPacking.cpp,core/libs/prx/libSceAgcDriver/tests/execution/FractDirectedRounding.cpp(lines 1–100), anddocs/dev/debt/changes/fract-directed-rounding.md. Also readreview/description.md,review/commits.md,review/manifest.json, andreview/diff.patch.review/files.jsonwas not available as a review-folder document.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T12:35:44Z.
Review: APPROVED
Reviewed — looks good
The reviewed change implements directed rounding for the three fract operations, and the supplied test report covers declared and runtime modes on the stated RDNA1 hardware; I did not run the reported checks.
What I ran
Reviewed head
ab2742cac58552db32188432f34ce89d00cab96f. Read the prepared description, commits, manifest and diff, plus the full changed execution test and relevant float translation functions and declarations throughrepo_read.py. No commands or tests were run by me. The PR description reports Windows 11 and an RX 5700 XT; gfx1013 console behavior was not measured.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the reported hardware oracle, execution tests, conventions check, debt check, or inspect CI output. The changed files read were
core/libs/prx/libSceAgcDriver/tests/execution/FractDirectedRounding.cpp,core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp,core/shader/recompiler/Translation/src/Float64Instructions.cpp,core/shader/recompiler/Translation/src/FloatInstructions.cpp,core/shader/recompiler/Translation/src/RoundingMode.cpp, anddocs/dev/debt/changes/fract-directed-rounding.md. The last two changed files were present in the diff but not read at full text; the review manifest was only partially read, so the complete reviewed/excluded file inventory is not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:30:23Z.
Review: COMMENTED
I followed the ULP step for the f32 and f64 paths and the f16 conversion from its exact f32 intermediate. The fixture checks infinities and NaN bits alongside the rounding cases. Its
DenormPreserverefusal on unsupported hosts can leave denormal-preservation rows unexecuted while CTest passes. Please include the printed executed-case count when reporting validation so that the coverage of the preserved-denormal modes is clear. The paired shader tests and the three-precision 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.