fix(shader): check NaN on the bits for ordered less-than and greater-than #3595

Closed
LeandroLP23 wants to merge 1 commit from upstream-pr/3595 into main
LeandroLP23 commented 2026-10-11 13:58:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-11T13:58:39Z.


What

agc_driver_f32_compare_constant (from #2408) fails on the AMD Windows driver (#3536):

AGC graphics: f32 compare constant: no float mode, register operand lane 20 v_cmp_lt_f32 0x7fc00000, 0x7f800000 is 1, expected 0

A NaN compared less than +infinity gives 1, and so does +infinity compared greater than a NaN (the next failure in the same test once less-than is fixed). Both happen only when the infinity reaches the shader as a constant. The same driver returns 1 for a NaN in an ordered not-equal on a 32-wide subgroup ballot (#825). An ordered x < +inf is equivalent to an ordered x != +inf, so the driver's compiler presumably rewrites these compares into that not-equal. I haven't confirmed that in the driver's output.

FPOrdLessThan32 and FPOrdGreaterThan32 now AND their result with the integer NaN check that FPOrdNotEqual32 has used since #825. The check moves into a shared BothOrderedBits32. The result is the same for every input. The TechnicalDebt entry for #825 now covers all three compares.

Tested

Radeon 860M (RDNA 3.5), Windows 11 (26300), AMD driver 32.0.13058.8001, WinLibs GCC 15.2.0 r7, Release, main a11c8f7f7. The AMD Vulkan cache and shader_cache were emptied before each run.

Emitter agc_driver_f32_compare_constant
this PR passes 3/3
main fails as above
less-than guarded, greater-than not fails at v_cmp_gt_f32 0x7f800000, 0x7fc00000 is 1, expected 0

With this PR, ctest -R agc_ passes 374/374 (main: 373/374) and the other shader tests pass 156/156. tools/check_conventions.py --base origin/main passes.

Fork CI: https://github.com/LeandroLP23/AnyPS5/actions/runs/38143672108

  • Linux (lavapipe): agc_driver_f32_compare_constant passes. The three failures also happen on main: agc_driver_image_plane_address_on_line_implicit_lod, guest_kernel_stack_protect and agc_driver_emulated_color_compare, which fails the same way in #3578's run, a change that doesn't touch the shader code.
  • Windows (no GPU): guest_filesystem (#3518), guest_kernel_sys (#3510) and windows_exceptions (#3411) fail as on main.

Fixes #3536

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819591980 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3595). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-11T13:58:39Z. --- ### What `agc_driver_f32_compare_constant` (from #2408) fails on the AMD Windows driver (#3536): ``` AGC graphics: f32 compare constant: no float mode, register operand lane 20 v_cmp_lt_f32 0x7fc00000, 0x7f800000 is 1, expected 0 ``` A NaN compared less than +infinity gives 1, and so does +infinity compared greater than a NaN (the next failure in the same test once less-than is fixed). Both happen only when the infinity reaches the shader as a constant. The same driver returns 1 for a NaN in an ordered not-equal on a 32-wide subgroup ballot (#825). An ordered `x < +inf` is equivalent to an ordered `x != +inf`, so the driver's compiler presumably rewrites these compares into that not-equal. I haven't confirmed that in the driver's output. `FPOrdLessThan32` and `FPOrdGreaterThan32` now AND their result with the integer NaN check that `FPOrdNotEqual32` has used since #825. The check moves into a shared `BothOrderedBits32`. The result is the same for every input. The TechnicalDebt entry for #825 now covers all three compares. ### Tested Radeon 860M (RDNA 3.5), Windows 11 (26300), AMD driver 32.0.13058.8001, WinLibs GCC 15.2.0 r7, Release, `main` `a11c8f7f7`. The AMD Vulkan cache and `shader_cache` were emptied before each run. | Emitter | `agc_driver_f32_compare_constant` | |---|---| | this PR | passes 3/3 | | `main` | fails as above | | less-than guarded, greater-than not | fails at `v_cmp_gt_f32 0x7f800000, 0x7fc00000 is 1, expected 0` | With this PR, `ctest -R agc_` passes 374/374 (`main`: 373/374) and the other shader tests pass 156/156. `tools/check_conventions.py --base origin/main` passes. Fork CI: https://github.com/LeandroLP23/AnyPS5/actions/runs/38143672108 - Linux (lavapipe): `agc_driver_f32_compare_constant` passes. The three failures also happen on `main`: `agc_driver_image_plane_address_on_line_implicit_lod`, `guest_kernel_stack_protect` and `agc_driver_emulated_color_compare`, which fails the same way in #3578's run, a change that doesn't touch the shader code. - Windows (no GPU): `guest_filesystem` (#3518), `guest_kernel_sys` (#3510) and `windows_exceptions` (#3411) fail as on `main`. Fixes #3536 ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-11 14:36:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T14:36:40Z.


I integrated the shared ordered NaN bit check into my PR #3541, including both less-than and greater-than. The implementation uses BothOrderedBits32 for FPOrdNotEqual32, FPOrdLessThan32, and FPOrdGreaterThan32, and the updated TechnicalDebt entry covers all three operations. I preserved your commit as the second commit in #3541 so your authorship stays attached to the change. I believe #3541 is now the better single PR to review because it includes this shared fix alongside the focused #3536 reproducer and validation context: https://github.com/boykopovar/AnyPS5/pull/3541. Thanks for working through the symmetric greater-than failure too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110127904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3595#issuecomment-6110127904). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T14:36:40Z. --- I integrated the shared ordered NaN bit check into my PR #3541, including both less-than and greater-than. The implementation uses `BothOrderedBits32` for `FPOrdNotEqual32`, `FPOrdLessThan32`, and `FPOrdGreaterThan32`, and the updated TechnicalDebt entry covers all three operations. I preserved your commit as the second commit in #3541 so your authorship stays attached to the change. I believe #3541 is now the better single PR to review because it includes this shared fix alongside the focused #3536 reproducer and validation context: https://github.com/boykopovar/AnyPS5/pull/3541. Thanks for working through the symmetric greater-than failure too.
LeandroLP23 commented 2026-10-11 17:11:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-11T17:11:10Z.


Closing in favour of #3541, whose final tree is identical to this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111550604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3595#issuecomment-6111550604). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-11T17:11:10Z. --- Closing in favour of #3541, whose final tree is identical to this one.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3595
No description provided.