fix(shader): honor f64 comparison input denormal mode #6850
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6850"
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 Ondra97 on 2026-10-16T14:15:58Z.
What
v_cmp*_f64compared subnormal operands unchanged even when the shader'sFLOAT_MODErequires input denormals to be flushed. For example, comparing the f64 bit patterns0x0000000000000001 < 0x0000000000000002in mode 0 returned true instead of false, producing the wrong predicate.The shared f64 comparison path now converts zero-exponent inputs to signed zero when bit 0 of the f16/f64 denormal field is clear (modes 0 and 2). Modes 1 and 3 and the legacy unknown mode retain their behavior. Class comparisons continue to inspect the original bits.
Semantic references: AMD RDNA2 ISA, section 6.4, LLVM's AMDGPU denormal modes, and the prior gfx1036 audit of mode-sensitive VopcCompareF64 results. I did not perform a new AMD or PS5 hardware measurement; the debt entry records that limit.
The existing GPU fixture covers all four denormal modes with IEEE off/on, plus the unknown mode. It checks 236,160 predicate results over edge pairs and deterministic random inputs, including VCC/EXEC, class and existing source-modifier forms. Opposing f32 denormal settings check that the f16/f64 field controls this path. Each of the nine shader variants is compiled once.
Related #6007 changes f32 comparisons and #6760 changes f64 min/max; neither implements this f64 comparison fix.
Tested
Base
82ddae75b6761757f3d3ba9c0723647469270f76, final head23c9bd7e860146860de99f2f6856073e2a48a47b. The base is still upstream main at publication. No dependency, build-script, workflow or binary changes are included. The complete upstream delta332b0b1b79feb39a6e5fc5d4e4a5dfe4491d27b5..82ddae75b6761757f3d3ba9c0723647469270f76and this patch were statically reviewed before execution, including new files and build/test execution paths.Windows (native host): AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER, driver 617.42 / 32.0.16.1742; Windows 11 Pro 10.0.26300. WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF.Vulkan was required with
ANYPS5_REQUIRE_VULKAN=1;ANYPS5_GPU=NVIDIA GeForce RTX 4070 Ti SUPERselected the device and its actual selection was verified in the verbose logs.ANYPS5_NO_SHADER_CACHE=1andrequest.useCache=falsedisabled the AnyPS5 shader cache. Driver caches were not controlled. Guest wave32.Before / after — Windows (native host)
Same final
agc_driver_vopc_compare_f64fixture, hardware, inputs, Release configuration and cache settings; one invocation per variant. The negative control restored the base's unmodified comparison source, then the fixed bytes were restored and checked.This demonstrates the predicate correction; it is not a performance or title benchmark.
4fe92c9c23c7bd861d63664d4efde3033b6226f6) temporarily applied. It was removed and is not in these commits.Reproduction from the configured full build, with the environment above:
Linux (VirtualBox): Ubuntu 24.04.5 LTS, kernel 7.0.0-31-generic, GCC 13.3.0; VirtualBox 7.2.20 on the Windows host above, 8 vCPU / 8 GiB assigned. Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF. Graphics: not exercised.agc_structurizer,agc_shader_mode_register,agc_shader_control_flowandagc_constant_phi: 4/4 passed, 0 failures, 0 skips.The existing Linux build retained its CMake cache paths through its compatibility directory:
Linux graphics/Vulkan tests: NOT RUN — intentionally excluded from VirtualBox validation. Native/bare-metal Linux was not tested. Native Linux GPU validation: not tested.
The full CTest suite was not run. No title was run, and no title fix, FPS improvement or new AMD/PS5 measurement is claimed. Hosted full builds require a collaborator's manual dispatch under the current CI policy.
Checklist
main; open PR implementations/tests and complete file lists of large PRs checked; no other open PR implements this f64 comparison changeImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T14:40:02Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/shader.mdL25docs/dev/debt/shader.mdL25docs/dev/debt/shader.mdL25Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
docs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T16:24:39Z.
Review: COMMENTED
Red/green on native Linux, which the description lists as not tested, on two more Vulkan drivers.
Machine: NVIDIA GeForce RTX 3070, driver 595.99.02, Vulkan 1.4.329, plus lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same machine. Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. Head23c9bd7e8merged intomain452494439(clean merge). Device checked in theSelected GPUlog line (RTX 3070 subgroup 32, llvmpipe subgroup 8).agc_driver_vopc_compare_f64passes 3/3main'sCompareInstructions.cppmode 0, IEEE off round 0 thread 9 compare 37 is 1, expected 0The related set from the description (
^(agc_driver_(vopc_compare.*|vop3_compare.*|vcmp.*|f64.*|f32_compare.*|f32_denormal_flush)|agc_(shader_mode_register|structurizer|shader_control_flow|constant_phi)|patched_libraries)$,-j1): 22/22 pass on the RTX 3070 and 22/22 on lavapipe, no skips.Not run: Windows, AMD, the full suite.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T08:55:49Z.
AMD / Windows run of this PR at
23c9bd7e8: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release.agc_driver_vopc_compare_f64: pass (vopc f64 compare tests passed, 5.12 s)AI-assisted: yes (run made on the device above).
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-19T07:43:07Z.
Native data for the matrix the debt entry says hasn't been measured: RX 6700 XT (gfx1031, RDNA 2), the instructions run directly through HIP, all four f16/f64 denormal modes, IEEE 0 and 1 (f32 denormals kept). Inputs are the 196 pairs of 14 f64 values: ±0, the smallest and largest denormals, a mid denormal, ±the smallest normal, ±1 and ±infinity. 132 pairs contain a denormal. For each mode I compared every result with the mode-3 (kept) result for the same pair after flushing each denormal input to its signed zero:
v_cmp_eq_f64,v_cmp_neq_f64,v_cmp_lt_f64,v_cmp_le_f64,v_cmp_gt_f64v_cmp_class_f64with the denormal mask (0x90)The same in IEEE 0 and 1. So the compares flush their inputs to signed zero exactly when bit 0 of the field is clear, including the split modes, and the class compare sees the original bits in every mode, which is what this PR implements. Desktop RDNA 2, not gfx1013.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T12:08:54Z.
Checked the zero-exponent flush against the f16/f64 denormal field (bit 0 clear = modes 0 and 2), the class compare keeping the original bits, and the nine-mode test (the f32 field is set opposite to the f64 one, so it pins the right field). The test fails on
main(mode 0 compare 37) and passes with the change, matching the RTX 3070/lavapipe, Radeon 780M and RX 6700 XT runs in this thread; merged.