fix(shader): flush a tiny v_cvt_f32_f64 result by the f32 denormal field #18487
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18487"
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-11T18:25:01Z.
What
Measured on RDNA2 (gfx1031, RX 6750 XT; the PS5's gfx1013 is not measured): with bit 1 of the
FLOAT_MODEf32 denormal field clear (fields 0 and 1),v_cvt_f32_f64gives a zero of the source's sign when the f64 source, rounded to 24 significant bits with an unbounded exponent in the f32 round mode, is below 2^-126. This is the tininess rule the f32 products already follow. So0x380fffffe0000000, whose conversion rounds up to0x00800000, gives0, while0x380ffffff0000000gives0x00800000.The translation flushed nothing. Field 1 kept f32 denormals on every host, and field 0, the
0xc0titles use, kept them on hosts that do not use the hardware f32 flush. Thev_cvt_f32_f64f32-denormal debt entry recorded this gap from gfx1101, and on #13847 oneandonlydean noted that "the separate conversion-denormal fix can remain a follow-up".The change:
float64Operation: forConvertF32F64, with a known float mode and bit 1 clear, compares the f64 source bits (afternegandabs) with the limit for the round mode and selects the zero of the source's sign. The compares are integer compares on the two halves, so they also cover the integer lowering of devices without Float64 (#13341).f32DenormalFlushFor, as the debt entry suggested: a flush of the f32 result keeps0x00800000for the sources that round up to it, where RDNA2 gives 0.RoundingUseOf: the conversion now reads bit 1 of the f32 denormal field, so it declares it (denorm32Out). Where that bit differs between the paths reaching the conversion, or comes from an SGPR, translation now refuses instead of guessing.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. Everything below was run onmainf57c971559and on this branch, which is based on it. This device uses the hardware f32 flush;APS5_NO_HW_F32_FLUSH=1turns it off.RDNA2 measurement (hardware oracle, HIP runtime), compared row by row with the recompiler through
HW_ORACLE_RUNTIME=vulkan.0x380fffffb0000000to0x380fffffffffffff, both signs), sources that convert to f32 denormals, 2^-150 and 1.5 × 2^-150, f64 denormals, ±0, 2^-126, 1, the largest finite f32, and infinities and NaNs.clamp,mul:2anddiv:2.Rows differing from RDNA2:
mainAPS5_NO_HW_F32_FLUSH=1APS5_NO_HW_F32_FLUSH=1main. Three causes, none in this change:mul:2of the largest finite f32 under rounding down or toward zero gives infinity where RDNA2 gives0x7f7fffff. That is the output modifier, not the conversion.clamp,mul:2anddiv:2of a flushed negative source give+0, as on RDNA2, through the existing f32 result path.Tests:
agc_driver_cvt_f32_f64_denormal_result: 32 sources through 8 forms (plain,clamp,mul:2,div:2,mul:4,-src,|src|,-srcwithclamp), with FLOAT_MODE0xc0,0xd0,0xe0and0xf0(f32 denormal field 0 to 3) at IEEE 0 and 1, rounding to nearest. Sinced9888e1c5falso FLOAT_MODE0xd1,0xd2and0xd3(field 1 rounding up, down and toward zero, IEEE 0), where the flush limit depends on the round mode. The expected values are RDNA2's.Target()uses it, with the hardware flush. On a device withoutDenormPreserve 32it leaves out the expected values that are f32 denormals (fields 2 and 3), and the last line says how many.mainwith only this test file added it fails in its emulated-flush pass, which runs on every device:v_cvt_f32_f64 denormal result: emulated flush FLOAT_MODE 0x000000c0 IEEE=0 lane 0 v_cvt_f32_f64 v10, v[4:5] of 0x3800000000000000 is 0x00400000, expected 0x00000000. WithAPS5_NO_HW_F32_FLUSH=1(the recompiler is told this device has no hardware flush) it fails with the same message.APS5_NO_HW_F32_FLUSH=1.0x381ffffff0000000, a normal source that needs rounding, is left out because the conversion itself still rounds to nearest (the debt entry).mul:2andmul:4of the largest finite f32 are left out too: the output modifier overflows them under rounding down and toward zero (see above).d9888e1c5fthe test passes both flush passes under the validation layer, with noVUID-line.rounding == 1u || rounding == 2u) fails it:emulated flush FLOAT_MODE 0x000000d1 IEEE=0 lane 8 v_cvt_f32_f64 v10, v[4:5] of 0x380fffffe8000000 is 0x00000000, expected 0x00800000. The version of the test befored9888e1c5fstill passes without that branch.0xd3, lane 10.^(agc_|shader|vector_), 4 at a time: 1,647 tests: 1,628 passed, 18 skipped, 1 failed.main: the same run onmain(1,646 tests) gives every test the same outcome. The only extra test is the new one, which passes.agc_driver_sample_order_grid_referencefails onmaintoo, with the same message ("the exact path did not render the checkerboard bit for bit like the reference"). It is the odd-row failure that #18229 reports on an RX 6700 XT; #9503 addresses it (not run here).-R "^(agc_driver_(cvt_|f64_|f32_|nan_|division|div_).*|agc_driver_.*(denormal|_nan|rounding).*|vector_half_double_output_modifiers)$"(81 onmain, which lacks the new one), 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.was not found but was requested by env var VK_INSTANCE_LAYERS. Every test that opens a device logs the layer insertion;agc_driver_f64_denorm_preserve_spirvandvector_half_double_output_modifierscheck only SPIR-V or IR and open none.VUID-line on either side.agc_driver_float16_unused_nan_payloadsskips on both sides, because this device has no native f16 conversions with RTE rounding and kept f16 denormals.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-12T14:27:49Z.
Review: COMMENTED
Reviewed — no blocking findings
I read the four changed files through their diff and the head functions they call, and found no concrete defect; nothing was built or run here.
What I ran
d94daee70c84f8b936108d5ced9299393514a3e8, basemain. Read-only review; no build, no test run.repo_read.py):search readF64Bits,search denorm32Out,search ULessThan,search SelectF32,search RoundingUseKind,search setsDirectedRounding,search GLOB_RECURSE,search tests/execution,cat SubwordPacking.cpp 36 60,cat RoundingMode.cpp 30 50,cat RoundingMode.cpp 360 413.0x380ffffff0000000(tie, rounds up to2^-126, not flushed),0x380fffffe0000000(flushed) and the directed cases againstbelow(0x380fffffe0000001)andbelow(0x3810000000000000).Results
readF64Bitsapplies both (SubwordPacking.cpp:36-53)tests/execution/*.cppis globbed (CMakeLists.txt:691-702)Findings
Blocking
None.
Non-blocking
Float64Instructions.cpp:48gates the directed branch (rounding == 1u || rounding == 2u, with the toward-zero case in lines 47-51).CvtF32F64DenormalResult.cppruns only the nearest-even modes (0xc0,0xd0,0xe0,0xf0, rounding bits 0), so lines 47-51 have no regression test in the tree. The PR says directed rounding is left out on purpose; the directed flush rule itself is only in the PR's measurements, not in a pinned test.Sources
readF64Bits:github.com/boykopovar/AnyPS5@d94daee70c/core/shader/recompiler/Translation/src/TranslationContext/SubwordPacking.cpp (L36-L53)github.com/boykopovar/AnyPS5@d94daee70c/core/shader/recompiler/Translation/src/Float64Instructions.cpp (L39-L54)github.com/boykopovar/AnyPS5@d94daee70c/core/shader/recompiler/Translation/src/RoundingMode.cpp (L395-L411)github.com/boykopovar/AnyPS5@d94daee70c/core/shader/recompiler/Translation/src/RoundingMode.cpp (L36-L42)github.com/boykopovar/AnyPS5@d94daee70c/core/libs/prx/libSceAgcDriver/CMakeLists.txt (L691-L702)Not verified
ULessThan,SelectF32andBitCastF32exist in the tree;LogicalOr,LogicalAnd,LogicalNot,IEqualandINotEqualwere not checked.CvtF32F64DenormalResult.cppare RDNA2 measurements from the author. I did not check them against hardware.docs/dev/debt/shader.md:197are author measurements; no test in the tree pins them.files/. Files excluded by rule: none.To get this to a good state
Float64Instructions.cpp:47-51) or mark it unpinned in the debt entry.HW_ORACLE.mdlink at the head SHA instead ofmain.agc_driver_cvt_f32_f64_denormal_resultand the^(agc_|shader|vector_)set on the new head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T00:14:16Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation and added regression test support merging.
What I ran
Reviewed head
d9888e1c5f89f9e13212703709e4e258133795c1. No commands or tests were run in this review. Read the prepared description, commits, manifest and diff, plus all four changed files throughrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently run the reported hardware measurements, test suites, validation layer, or build. PS5 gfx1013 behavior and other hosts remain unmeasured per the description. No files were excluded from review;
files.jsonwas not available through the reader, and the manifest lists all four changed files as included and read.To get this to a good state
Nothing is required.