fix(shader): emit unordered f32 relations as negated ordered ones #3357

Merged
reyani-dev merged 1 commit from upstream-pr/3357 into main 2026-10-11 08:52:35 +00:00
reyani-dev commented 2026-10-11 08:47:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T08:47:39Z.


What

On NVIDIA (RTX 4070 Laptop GPU, Windows driver 616.92), agc_driver_f32_compare_constant, added in #2408, aborts with exit code 3 before it checks anything. The abort is inside NVIDIA's shader compiler (nvgpucomp64.dll, under vkCreateComputePipelines). The test passes on the AMD Radeon 780M here and on RADV (#2408).

Narrowed with the test's own shader:

  • Of its nine constants, only +inf (0x7f800000) triggers it.
  • Of the twelve predicates, only v_cmp_ngt_f32 and v_cmp_nlt_f32 do.

These compile to OpFUnordLessThanEqual / OpFUnordGreaterThanEqual against +inf, which are always true for non-NaN input. The abort also happens with CompareInstructions.cpp from before #2408, so it isn't #2408's folding: any shader doing an unordered relational compare against +inf hits it on this driver.

The four unordered relational emitters now emit the negated inverse ordered relation, for example OpFUnordLessThanEqual(a, b) becomes OpLogicalNot(OpFOrdGreaterThan(a, b)). That is the same predicate for every input, NaN and signed zeros included: unord(a <= b) = isnan(a) || isnan(b) || a <= b = !ord(a > b). OpFUnordEqual/OpFUnordNotEqual and the ordered forms are unchanged. SpirvSpecialization already treats OpLogicalNot and the ordered forms as foldable, like the unordered ones.

The existing agc_driver_f32_compare_constant covers it: all twelve predicates, both operand orders, NaN, ±inf, ±0 and denormal rows.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, with VK_LOADER_DRIVERS_DISABLE=*dzn* (#3255), on main 04ab4a86:

  • NVIDIA RTX 4070 Laptop GPU (616.92):
    • On main, agc_driver_f32_compare_constant aborts (exit 3) every run. With only the +inf constant and ngt or nlt kept, it still aborts; with any other constant or predicate it passes.
    • With this change the full test passes, and ctest -R "^agc_|video_out|^shader|recompiler" passes 372/372.
  • AMD Radeon 780M (ANYPS5_GPU=AMD): the same set gives 368/372 both with and without this change. The four failures (vopc_compare_table, sdwa_integer_clamp, sdwa_integer_selectors, interpolation_f16) fail the same way with main's emitter, so they are existing AMD-on-Windows issues, not this change.
  • check_conventions.py passes, and pr_overlap.py reports no overlap.

Not run on Linux; the change is in the SPIR-V emitter shared by all hosts, and RADV already passed the test.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4817829934 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3357). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T08:47:39Z. --- ### What On NVIDIA (RTX 4070 Laptop GPU, Windows driver 616.92), `agc_driver_f32_compare_constant`, added in #2408, aborts with exit code 3 before it checks anything. The abort is inside NVIDIA's shader compiler (`nvgpucomp64.dll`, under `vkCreateComputePipelines`). The test passes on the AMD Radeon 780M here and on RADV (#2408). Narrowed with the test's own shader: - Of its nine constants, only `+inf` (`0x7f800000`) triggers it. - Of the twelve predicates, only `v_cmp_ngt_f32` and `v_cmp_nlt_f32` do. These compile to `OpFUnordLessThanEqual` / `OpFUnordGreaterThanEqual` against `+inf`, which are always true for non-NaN input. The abort also happens with `CompareInstructions.cpp` from before #2408, so it isn't #2408's folding: any shader doing an unordered relational compare against `+inf` hits it on this driver. The four unordered relational emitters now emit the negated inverse ordered relation, for example `OpFUnordLessThanEqual(a, b)` becomes `OpLogicalNot(OpFOrdGreaterThan(a, b))`. That is the same predicate for every input, NaN and signed zeros included: `unord(a <= b) = isnan(a) || isnan(b) || a <= b = !ord(a > b)`. `OpFUnordEqual`/`OpFUnordNotEqual` and the ordered forms are unchanged. `SpirvSpecialization` already treats `OpLogicalNot` and the ordered forms as foldable, like the unordered ones. The existing `agc_driver_f32_compare_constant` covers it: all twelve predicates, both operand orders, NaN, ±inf, ±0 and denormal rows. ### Tested Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, with `VK_LOADER_DRIVERS_DISABLE=*dzn*` (#3255), on `main` `04ab4a86`: - **NVIDIA RTX 4070 Laptop GPU (616.92):** - On `main`, `agc_driver_f32_compare_constant` aborts (exit 3) every run. With only the `+inf` constant and `ngt` or `nlt` kept, it still aborts; with any other constant or predicate it passes. - With this change the full test passes, and `ctest -R "^agc_|video_out|^shader|recompiler"` passes 372/372. - **AMD Radeon 780M (`ANYPS5_GPU=AMD`):** the same set gives 368/372 both with and without this change. The four failures (`vopc_compare_table`, `sdwa_integer_clamp`, `sdwa_integer_selectors`, `interpolation_f16`) fail the same way with `main`'s emitter, so they are existing AMD-on-Windows issues, not this change. - `check_conventions.py` passes, and `pr_overlap.py` reports no overlap. Not run on Linux; the change is in the SPIR-V emitter shared by all hosts, and RADV already passed the test. ### Checklist - [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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-11 08:52:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:52:32Z.


Checked the four rewrites against the identity unord(a op b) = !ord(inverse op) (NaN and signed zeros included); Eq/NotEqual and the ordered forms are untouched, and SpirvSpecialization already folds OpLogicalNot and the ordered relations. Built on current main: agc_driver_f32_compare_constant, agc_driver_f32_denormal_flush and agc_driver_vopc_compare_* pass on RADV, plus the scoped AGC ctest (392/394; the two "Not Run" are unrelated to this change). The NVIDIA abort itself can't be reproduced here, so that part rests on your RTX 4070 run. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107313755 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3357#issuecomment-6107313755). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T08:52:32Z. --- Checked the four rewrites against the identity `unord(a op b) = !ord(inverse op)` (NaN and signed zeros included); `Eq`/`NotEqual` and the ordered forms are untouched, and `SpirvSpecialization` already folds `OpLogicalNot` and the ordered relations. Built on current main: `agc_driver_f32_compare_constant`, `agc_driver_f32_denormal_flush` and `agc_driver_vopc_compare_*` pass on RADV, plus the scoped AGC ctest (392/394; the two "Not Run" are unrelated to this change). The NVIDIA abort itself can't be reproduced here, so that part rests on your RTX 4070 run. Merging once CI is green.
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!3357
No description provided.