Skip to content

fix(shader): emit ordered not-equal through an integer NaN check - #1473

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
LeandroLP23:fix/shader-lg-compare-amd-wave32
Oct 10, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
LeandroLP23:fix/shader-lg-compare-amd-wave32

Conversation

@LeandroLP23

@LeandroLP23 LeandroLP23 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #825.

What

FPOrdNotEqual32, which v_cmp_lg_f32/v_cmpx_lg_f32 and the f16 LG compares lower to, is now emitted as OpFUnordNotEqual(a, b) && (bits(a) & 0x7fffffff) <= 0x7f800000 && (bits(b) & 0x7fffffff) <= 0x7f800000 instead of OpFOrdNotEqual. 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 && !IsNan and 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 main

AMD 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:

wave32 lane 29 cmp_lg_f32_e32 row 00000000 fffffffe 00000000 fffffffe is 1, expected 0
wave32 lane 29 cmp_lg_f16_e32 row 00000000 fffffffe 00000000 fffffffe is 1, expected 0
wave32 lane 31 cmp_lg_f16_e32 row 007fffff 00007fff ff7fffff 7f7fffff is 1, expected 0

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release with BUILD_TESTING=ON, main 8388121.

Device Full ctest agc_driver_vopc_compare_table
AMD Radeon 860M, driver 32.0.13058.8001 423/423 fails on main, passes
lavapipe (Mesa 26.2.4, LLVM 23.1.2, selected with VK_DRIVER_FILES) 423/423, 22 skipped for its 8-lane subgroups passes, as on main

Other AMD GPUs on Windows (main d70b899 and full ctest unless the row says otherwise), with and without this PR:

Device Driver main with this PR Run by
AMD Radeon RX 9060 XT (RDNA 4, 0x7590) 32.0.31041.1004 vopc_compare_table fails (same lane 29 row) passes, 510/510; vopc_compare* 5/5 repeats @tezzgod74 (comment)
Ryzen 9 7950X iGPU (RDNA 2, 0x164e) 32.0.21045.5002 vopc_compare_table passes passes; the 14 other failures are the same with and without it @tezzgod74
AMD Radeon RX 7900 XT (RDNA 3, 0x744c) 32.0.31041.1004 vopc_compare_table fails (same lane 29 row) passes 20/20; full ctest 505/507, the failure is agc_driver_shader_clock (#1615, also on main) @joelfernandes23 (comment)
AMD Radeon RX 7800 XT (RDNA 3, 0x747e) 32.0.31041.1004 vopc_compare_table fails (lane 29 cmp_lg_f32_e32/cmp_lg_f16_e32, lane 31 cmp_lg_f16_e32) on main f8c2f07 passes 5/5 at 1edba8b1, with vopc_compare and vopc_compare_f64; full ctest at this head not reported @PYTHONRETARDE (comment)

Not tested on NVIDIA or Intel.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

@LeandroLP23

Copy link
Copy Markdown
Contributor Author

#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 fix agc_driver_vopc_compare_table there; only the integer check does.

@yahya308

yahya308 commented Oct 8, 2026

Copy link
Copy Markdown

Tested on Windows 11, MinGW-w64 GCC 16.2.0 (not the CI 15.2.0), Release, BUILD_TESTING=ON, main 0596a7a2 + this PR, full ctest with ANYPS5_REQUIRE_VULKAN=1 --repeat until-fail:3:

Device Driver main this PR
NVIDIA RTX 4070 Laptop 32.0.16.1074 447/447 447/447
AMD Radeon 780M (RDNA3) 32.0.11020.1002 vopc_compare_table fails (wave32 lane 29 cmp_lg_f32_e32 is 1, expected 0) passes

On the 780M, sdwa_integer_clamp and sdwa_integer_selectors fail on both main and this PR (vkCreateComputePipelines -3); unrelated to this change.

AI-assisted: yes (Claude Code).

@yahya308

yahya308 commented Oct 8, 2026

Copy link
Copy Markdown

Follow-up after updating the AMD driver to 32.0.31041.1004 (2026-08-17), same setup: on main, vopc_compare_table still fails on the 780M with the same row (wave32 lane 29 cmp_lg_f32_e32 is 1, expected 0). With this PR the full ctest passes, 447/447 (pixel_interlock now runs on this driver and passes). The two SDWA failures I mentioned earlier were an old-driver issue and are gone on this driver.

@fisherjoey

Copy link
Copy Markdown
Contributor

Linux results on both vendors. Nobara 44 (Linux 7.2), GCC 16.2.1, Release, this PR cherry-picked onto main 4b005b2:

Device main 4b005b2 main + this PR
RTX 5070 Ti, NVIDIA 595.91.07 vopc_compare_table passes (13 of 13 earlier runs); -R agc_driver 183/183 vopc_compare_table 3 of 3 (--repeat until-fail:3); -R agc_driver 183/183
RADV gfx1036 (RDNA2 iGPU), Mesa 26.2.1 passes (17 of 17 earlier runs); -R agc_driver 183/183 vopc_compare_table 3 of 3; -R agc_driver 183/183

Both 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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
@LeandroLP23
LeandroLP23 force-pushed the fix/shader-lg-compare-amd-wave32 branch from 4c0b476 to 3dc4a41 Compare October 8, 2026 22:18
@LeandroLP23

Copy link
Copy Markdown
Contributor Author

Rebased onto main ae91d97; no conflicts.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 8, 2026
@LeandroLP23
LeandroLP23 force-pushed the fix/shader-lg-compare-amd-wave32 branch from 3dc4a41 to ca7313a Compare October 9, 2026 07:13
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 9, 2026
@tezzgod74

Copy link
Copy Markdown
Contributor

RDNA 4 result: the same rows fail on main and 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 onto main d70b899, full ctest with ANYPS5_GPU set to each device:

Device main d70b899 main + this PR
AMD Radeon RX 9060 XT (RDNA 4, 0x7590), driver 32.0.31041.1004 509/510, vopc_compare_table fails (wave32 lane 29 cmp_lg_f32_e32 is 1, expected 0) 510/510
Ryzen 9 7950X iGPU (RDNA 2, 0x164e), driver 32.0.21045.5002 496/510, vopc_compare_table passes 496/510, same 14 failures

The 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

@joelfernandes23

Copy link
Copy Markdown
Contributor

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 d70b89989473ba1f6ae13e44e079e67f1f8a44b0 fails agc_driver_vopc_compare_table with:

vopc compare table wave32: lane 29 cmp_lg_f32_e32 is 1, expected 0

Applied PR head ca7313a5eb7de15b7e51395ab55722a47edf33bc to 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, with memtime: 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 was guest_video_out_wqhd_detection_no_vulkan.

No title testing. No changes to the PR implementation were made.

@LeandroLP23

Copy link
Copy Markdown
Contributor Author

Thanks @tezzgod74 and @joelfernandes23, added both runs (RDNA 4 and RDNA 3) to the description.

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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 f145139, while upstream main is d70b899. Please rebase onto current main so the exact current-head checks run before merge; your reported d70b899 hardware runs provide useful additional evidence.

@LeandroLP23

Copy link
Copy Markdown
Contributor Author

Rebased onto main d70b899 (1edba8b). Release build here on the Radeon 860M: all 212 agc_driver* tests pass, and agc_driver_vopc_compare_table passes 5/5 repeats.

@LeandroLP23
LeandroLP23 force-pushed the fix/shader-lg-compare-amd-wave32 branch from ca7313a to 1edba8b Compare October 9, 2026 13:38

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete diff on rebased head 1edba8b. 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.

LeandroLP23 and others added 2 commits October 10, 2026 01:27
The AMD Windows driver returns 1 for a NaN operand when any float form
of ordered not-equal feeds a ballot on a 32-wide subgroup, which is how
e32 compares are read in wave32. FPOrdNotEqual32 is now emitted as an
unordered not-equal with both operands checked for NaN on their bits,
which gives the same result for every input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…2 denormal entries

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on the HW oracle (gfx1035, IEEE=0, f32 denormals flushed): v_cmp_lg_f32 in 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.

@adriadam10
adriadam10 force-pushed the fix/shader-lg-compare-amd-wave32 branch from 1edba8b to 8404c49 Compare October 9, 2026 23:30
@adriadam10
adriadam10 merged commit 3fe03f7 into boykopovar:main Oct 10, 2026
7 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…pare-amd-wave32

fix(shader): emit ordered not-equal through an integer NaN check
@LeandroLP23
LeandroLP23 deleted the fix/shader-lg-compare-amd-wave32 branch October 10, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agc_driver_vopc_compare_table fails in wave32 for LG compares in the e32 encoding on AMD RDNA 3.5

7 participants