fix(shader): round v_cvt_f32_f64 in the FLOAT_MODE f32 round mode #21508
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21508"
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-16T09:14:41Z.
What
v_cvt_f32_f64rounded to nearest even whatever theFLOAT_MODEf32 round mode. Measured on RDNA2 (gfx1031, RX 6750 XT; the PS5's gfx1013 is not measured), rounding 1 to 3 rounds the f64 value up, down or toward zero. This is the gap the "v_cvt_f32_f64f32 result" debt entry recorded after #18487.What the hardware does in the three directed modes:
0x3ff0000000000001gives0x3f800001when rounding up and0x3f800000otherwise.0x47f0000000000000gives0x7f800000when rounding up and0x7f7fffffwhen rounding down or toward zero.0x3680000000000000gives0x00000001when rounding up.0x0000000000000001rounded up gives0x00000001only then).The change:
float64Operation: with a known float mode and f32 rounding 1 to 3, the f32 bits are built from the two halves of the f64 source with integer operations: the truncated value, plus one when the value is inexact and the mode rounds away from zero for that sign. Infinities and NaNs keep the existing conversion. The tiny-result flush of #18487 still runs after it, unchanged. Round to nearest is untouched.RoundingUseOf: the conversion becomesDirected32, so a round mode set at run time (s_round_mode,s_setreg) is accepted for it where it threw "does not model directed rounding". It now also declares bit 0 of the f64 denormal field, which the directed result reads.Not in this change:
mul:2andmul:4of a value the modifier overflows. gfx1031 rounds that overflow as the mode says and the translation gives infinity. That is the f32 output modifier, which the debt file already records, and #19710 works on directed overflow for the f32 arithmetic.Overlap: #19505 edits the
RoundingUseOfcases directly below theVCvtF32F64case, so whichever merges second has a small textual conflict there; it is different work (scalar f16 arithmetic). #19605 and #19563 change other functions ofFloat64Instructions.cpp. No open PR mentionsv_cvt_f32_f64.Tested
Setup: Windows 10 Home 22H2 (10.0.19045), AMD Radeon RX 6750 XT (gfx1031), AMD Software Adrenalin 26.10.1 (driver 32.0.21045.16010), WinLibs GCC 15.2.0 r7 UCRT, Release,
BUILD_TESTING=ON.mainis0694c4cbd6, which this branch is based on.RDNA2 measurement (hardware oracle, HIP runtime), compared value by value with the recompiler through
HW_ORACLE_RUNTIME=vulkan.Values differing from RDNA2, of 3,328 per round mode:
mainA bit-level model of the rule above predicts all 13,312 measured values.
Tests:
agc_driver_cvt_f32_f64_directed_rounding: 96 sources through 8 forms (plain,-src,|src|,clamp,-|src|,-srcwithclamp, the_e64encoding,|src|withclamp) in FLOAT_MODE0xf1to0xf3,0xd1to0xd3,0xc1to0xc3and0xb1to0xb3: rounding up, down and toward zero with f32 denormals kept, with f32 results flushed, with f32 inputs and results flushed, and with f64 denormal inputs flushed. The expected values are RDNA2's; the recompiler with this change matches all 9,216.Target()uses it, with the hardware flush. On a device withoutDenormPreserve 32it leaves out the expected values that are f32 denormals, and the last line says how many. Here both passes run and nothing is left out.mainwith only the test files added it fails:v_cvt_f32_f64 directed rounding: emulated flush FLOAT_MODE 0x000000f1 row 2 v_cvt_f32_f64 v10, v[4:5] of 0x0000000000000001 is 0x00000000, expected 0x00000001.agc_driver_cvt_f32_f64_denormal_result: the directed modes no longer leave out0x381ffffff0000000, the normal source that needs rounding. Onmainwith that row back the test fails:FLOAT_MODE 0x000000d1 IEEE=0 lane 30 v_cvt_f32_f64 v14, -v[4:5] of 0x381ffffff0000000 is 0x81000000, expected 0x80ffffff.mul:2andmul:4of the largest finite f32 stay left out (the output modifier, above).agc_shader_mode_register: the run-time rounding check (directed32) now includes the conversion: a round mode set bys_round_modemust translate like the same mode declared, and unlike round to nearest. Onmainwith the test change it fails:instruction (opcode 15) at pc 4 runs with MODE rounding 193 set at run time, and the instruction does not model directed rounding.agc_driver_cvt_f32_f64_output_modifierpass.^(agc_|shader|vector_), 4 at a time: 1,940 tests: 1,916 passed, 22 skipped, 1 failed, 1 not run.agc_driver_stencil_plane_memoryfails onmain0694c4cbd6too, 3 of 3 runs on this device.agc_driver_upload_cache_read_only_flushdoes not compile with this toolchain onmain(setenvis not declared inUploadCacheReadOnlyFlush.cpp).agc_driver_store_over_untrackedpassed in this run; it fails intermittently onmainon this device (2 of 3 runs).agc_driver_cvt_f32_f64_directed_rounding,agc_driver_cvt_f32_f64_denormal_result,agc_driver_cvt_f32_f64_output_modifier,agc_driver_f64_rounding,agc_driver_f64_rounding_denormal_modesandagc_driver_nan_quieting, one at a time withctest -V,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1: all pass, every one logs the layer insertion, and no log has aVUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERS.python tools/check_conventions.py --base origin/main: all conventions checks passed.tools/debt_fold.py --checkstops onmainat another fragment (docs-nkwebkit-drop-readded-count-lines.md), so this PR's fragment was checked by hand: itschangekey occurs in exactly one entry ofshader.md.Not measured: the PS5's gfx1013, and hosts other than this one.
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-16T10:13:04Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and regression coverage support merging.
What I ran
Reviewed head
e48bb23f4a4e1c60519ebf294be66e8ec4590951. I inspected the prepared diff and targeted code throughrepo_read.py; I did not execute commands or tests. The PR description reports hardware-oracle and test runs, which I did not independently run.Results
Negative control
Not run by me. The author reports that the new regression tests fail on
mainwith the test changes alone.Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
No tests were run in this review, and gfx1013/PS5 behavior remains unmeasured as stated by the author. I read every changed file listed in the review bundle, including all 1,343 lines of the new regression test; the prepared manifest listed no excluded changed files.
To get this to a good state
Nothing is required.