fix(shader): choose f64 arithmetic NaN results on the bits #18536
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18536"
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-11T20:40:47Z.
What
v_add_f64,v_mul_f64,v_fma_f64andv_div_fmas_f64take their NaN result from the SPIR-V backend, which always quiets the first NaN source. On RDNA2 (gfx1031, RX 6750 XT; the PS5's gfx1013 is not measured) two cases differ:v_add/mul/fma_f64as still left to the driver.v_fma_f64andv_div_fmas_f64(VCC clear and set), an inf * 0 product gives the default NaN0xfff8000000000000even when src2 is a NaN, and the recompiler returned src2. f32 and f16 fma already follow this rule.The change:
FusedMultiplyAdd): a NaN src2 no longer wins over an invalid product. That makes the backend's choice the full IEEE=1 rule.nanResultF64, IEEE=0 only): picks the first NaN source after its modifiers, unquieted; src2 loses to an invalid product.float64OperationandvDivFmasF64use it.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. The results below were run onmain65351c2931and on this branch as it was then, based on it, unless noted. The code was tested as291c2d7a95; the commit since differs only in a shorter shader.md sentence.Rebased on 2026-11-14 onto main
0f4538fa02as3c1ebd954c, because #16889 edited the shader.md entry above this one. The code diff is unchanged (same patch ID) and the shader.md change is the same line. Rerun at3c1ebd954c:v_add_f64of0x7ff4000000000001and0x7ff8000000000003.VUID-lines.^(agc_|shader|vector_), 4 at a time: 1,782 tests: 1,756 passed, 21 skipped, 4 failed, 1 not run. Against the same run onmain(1,781 tests), the extra test is the new one, which passes, and three failed here but passed there:agc_driver_linear_readback_label_off,agc_driver_frame_replay_rewind_storeandagc_storage_dcc_mip_writeback. Rerun one at a time, those three pass 6 times out of 6 on this branch and onmain.agc_driver_sample_order_grid_referencefails onmaintoo.agc_driver_upload_cache_read_only_flushdoes not build with MinGW onmain(it callssetenv).RDNA2 measurement (hardware oracle, HIP runtime), compared value by value with the recompiler through
HW_ORACLE_RUNTIME=vulkan.absornegon each source position in some of them:v_add_f64, including the subtraction form;v_mul_f64;v_fma_f64with the operands permuted and with the inline constants 0 and 1.0 (inf * 0 with a NaN src2);v_div_fmas_f64with VCC clear and set.v_div_fmas_f64keeps denormal factors, as shader.md already records, so with denormals flushed inf * denormal stays infinite there and is not an invalid product.mainTests:
agc_driver_f64_arithmetic_nan: 32 of the pairs through 8 of the forms. The expected values are RDNA2's.mainwith only this test file added it fails:f64 arithmetic nan: no float mode lane 0 v_add_f64 of 0x7ff4000000000001 and 0x7ff8000000000003 is 0x7ffc000000000001, expected 0x7ff4000000000001.agc_driver_f64_arithmetic: its run without a float mode (IEEE=0) expected the signalling-NaN rows 7, 13, 29 and 30 quieted in the add, mul and fma columns.v_fma_f64of inf, 0 and0x7ff4000000000001, which returns0x7ffc000000000001where the hardware gives0xfff8000000000000.^(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 2x checkerboard differs from the exact path in 2,427 samples). It is the odd-row failure that #18229 reports on an RX 6700 XT; #9503 addresses it (not run here).-R "^agc_driver_(f64|div|nan|vopc_compare_f64|cvt_f32_f64|f32_arithmetic_nan).*$"(28 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_spirvopens none.VUID-line on either side.Debt: shader.md no longer lists the f64 arithmetic as left to the driver, and records the measured rule in one sentence.
check_conventions.pywarns that this entry is over 1,000 characters. It is already 3,118 onmain0f4538fa02; this adds 200.Overlap, rechecked at
3c1ebd954c:pr_overlap.py --branchreports no conflict in code. It cannot see conflicts in the debt files:.gitattributesmerges them with the union driver, which GitHub ignores. A plain three-way merge ofshader.mdagainst the 98 open PRs that touch it adds conflicts with four:None changes this change's text, so a resolution keeps both sides.
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