fix(shader): emit ordered not-equal through an integer NaN check #1473
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1473"
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 LeandroLP23 on 2026-10-08T08:40:09Z.
Closes #825.
What
FPOrdNotEqual32, whichv_cmp_lg_f32/v_cmpx_lg_f32and the f16 LG compares lower to, is now emitted asOpFUnordNotEqual(a, b) && (bits(a) & 0x7fffffff) <= 0x7f800000 && (bits(b) & 0x7fffffff) <= 0x7f800000instead ofOpFOrdNotEqual. The two agree for every input.The AMD Windows driver returns 1 for a NaN operand when an ordered not-equal feeds a ballot on a 32-wide subgroup, which is how VCC is read for e32 compares in wave32.
OpFOrdNotEqual,FOrdLessThan || FOrdGreaterThan,FUnordNotEqual && !IsNan && !IsNanand an integer OR of the two compares all fail the same way, so the driver appears to fold any float form; checking NaN on the bits avoids it (analysis in #825). The image compare emulation's not-equal (SpirvImageEmitter.cpp) feeds a select, not a ballot, and is unchanged. Recorded in TechnicalDebt.Failing rows on
mainAMD Radeon 860M (RDNA 3.5, device 0x1114), Windows driver 32.0.13058.8001, Vulkan 1.3.302,
agc_driver_vopc_compare_table, wave32 run only; e64, wave64 and wave64 split pass:Tested
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release with
BUILD_TESTING=ON,main8388121a.ctestagc_driver_vopc_compare_tablemain, passesVK_DRIVER_FILES)mainOther AMD GPUs on Windows (
maind70b8998and fullctestunless the row says otherwise), with and without this PR:mainvopc_compare_tablefails (same lane 29 row)vopc_compare*5/5 repeatsvopc_compare_tablepassesvopc_compare_tablefails (same lane 29 row)ctest505/507, the failure isagc_driver_shader_clock(#1615, also onmain)vopc_compare_tablefails (lane 29cmp_lg_f32_e32/cmp_lg_f16_e32, lane 31cmp_lg_f16_e32) onmainf8c2f0721edba8b1, withvopc_compareandvopc_compare_f64; fullctestat this head not reportedNot tested on NVIDIA or Intel.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T08:48:56Z.
#1465 changes the same function to
OpFUnordNotEqual && !(OpIsNan(a) || OpIsNan(b)). That is the third form listed in #825: on the affected AMD driver it still returns 1 on the NaN rows, so it does not fixagc_driver_vopc_compare_tablethere; only the integer check does.Imported from boykopovar/AnyPS5. Originally posted by yahya308 on 2026-10-08T13:49:56Z.
Tested on Windows 11, MinGW-w64 GCC 16.2.0 (not the CI 15.2.0), Release,
BUILD_TESTING=ON, main0596a7a2+ this PR, full ctest withANYPS5_REQUIRE_VULKAN=1 --repeat until-fail:3:vopc_compare_tablefails (wave32 lane 29cmp_lg_f32_e32is 1, expected 0)On the 780M,
sdwa_integer_clampandsdwa_integer_selectorsfail on both main and this PR (vkCreateComputePipelines-3); unrelated to this change.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by yahya308 on 2026-10-08T14:11:54Z.
Follow-up after updating the AMD driver to 32.0.31041.1004 (2026-08-17), same setup: on main,
vopc_compare_tablestill fails on the 780M with the same row (wave32 lane 29cmp_lg_f32_e32is 1, expected 0). With this PR the full ctest passes, 447/447 (pixel_interlocknow runs on this driver and passes). The two SDWA failures I mentioned earlier were an old-driver issue and are gone on this driver.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T18:00:37Z.
Linux results on both vendors. Nobara 44 (Linux 7.2), GCC 16.2.1, Release, this PR cherry-picked onto
main4b005b22:main4b005b22main+ this PRvopc_compare_tablepasses (13 of 13 earlier runs);-R agc_driver183/183vopc_compare_table3 of 3 (--repeat until-fail:3);-R agc_driver183/183-R agc_driver183/183vopc_compare_table3 of 3;-R agc_driver183/183Both devices pass with and without the PR, so it causes no regressions here. RADV on RDNA2 doesn't miscompile the float form either, which is consistent with a bug in AMD's Windows compiler.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T22:18:45Z.
Rebased onto
mainae91d978; no conflicts.Imported from boykopovar/AnyPS5. Originally posted by tezzgod74 on 2026-10-09T12:31:58Z.
RDNA 4 result: the same rows fail on
mainand pass with this PR.Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,
-DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON, this PR cherry-picked ontomaind70b8998, fullctestwithANYPS5_GPUset to each device:maind70b8998main+ this PRvopc_compare_tablefails (wave32 lane 29cmp_lg_f32_e32is 1, expected 0)vopc_compare_tablepassesThe
vopc_compare*tests also passed 5 repeated runs on the RX 9060 XT with this PR. The 14 iGPU failures are unrelated and identical with and without it: #2138 (fixed by #2191), #2009, and the two SDWA f16 tests (#1463). The failing rows on this device are listed in #825.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by joelfernandes23 on 2026-10-09T13:02:19Z.
Tested this PR on an RX 7900 XT (RDNA 3), extending the reported RDNA 3.5 coverage.
Environment: Windows 11 Pro 10.0.26200, Ryzen 7 7700X, 32 GB RAM, AMD driver 32.0.31041.1004; Vulkan 1.4.349, device 0x744c. WinLibs MinGW-w64 GCC 15.2.0 UCRT/POSIX/SEH r7, Release, BUILD_TESTING=ON, SPIRV-Tools validation OFF. ANYPS5_GPU=7900 XT and ANYPS5_REQUIRE_VULKAN=1.
Main
d70b89989473ba1f6ae13e44e079e67f1f8a44b0failsagc_driver_vopc_compare_tablewith:Applied PR head
ca7313a5eb7de15b7e51395ab55722a47edf33bcto that main. The test passed 20/20 consecutive runs. Restored and rebuilt main: the same comparison failure returned.Full CTest with this PR, four workers outside the sandbox: 505 passed, 1 failed, 1 skipped (507 total). The failure was
agc_driver_shader_clock, withmemtime: lane 0 went back from 1030789 to 3880. I independently reproduced that clock failure on restored, unchanged main (1031570 to 4600), consistent with #1615. The skipped test wasguest_video_out_wqhd_detection_no_vulkan.No title testing. No changes to the PR implementation were made.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-09T13:05:35Z.
Thanks @tezzgod74 and @joelfernandes23, added both runs (RDNA 4 and RDNA 3) to the description.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T13:21:29Z.
Reviewed the complete implementation and the cross-device test reports. The integer NaN check is equivalent to ordered not-equal for all f32 values, and the reports cover RDNA 3.5, RDNA 4, RDNA 3 and an RDNA 2 control. One contribution-rule follow-up: this PR currently targets base
f1451396, while upstream main isd70b8998. Please rebase onto current main so the exact current-head checks run before merge; your reportedd70b8998hardware runs provide useful additional evidence.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-09T13:38:19Z.
Rebased onto
maind70b8998(1edba8b1). Release build here on the Radeon 860M: all 212agc_driver*tests pass, andagc_driver_vopc_compare_tablepasses 5/5 repeats.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T13:41:01Z.
Review: APPROVED
Reviewed the complete diff on rebased head 1edba8b1. The bitwise NaN classification implements ordered-not-equal for all binary32 inputs, while avoiding the measured AMD driver miscompile when the result feeds a ballot. The report now covers RDNA 3.5, RDNA 4, RDNA 3 and an RDNA 2 control; the author also reports 212 AGC tests passing and five repeats of the affected test on the Radeon 860M. Conventions and the official Linux, Windows, and macOS relinker jobs pass. No blocking issue found.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:30:37Z.
Checked on the HW oracle (gfx1035, IEEE=0, f32 denormals flushed):
v_cmp_lg_f32in e32 and e64 over 225 operand pairs (±0, denormals, inf, quiet/signaling NaNs,0x7fffffff,0xfffffffe) matches ordered not-equal, so the bitwise NaN form is equivalent. Build + the 289 AGC/AgcDriver tests pass locally; the Windows/AMD results from @yahya308, @tezzgod74, @joelfernandes23 and @PYTHONRETARDE cover the failing driver.Added one commit: the TechnicalDebt line sat right after the f32 denormals entries and conflicted with #2045 and #2046; moved it to a spot that merges cleanly with both (checked with
git merge-tree). Merging once CI is green.