Skip to content

fix(shader): handle ordered NaN comparisons - #3541

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
MarcZX10:codex/amd-ordered-nan-compare-3536
Oct 11, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
MarcZX10:codex/amd-ordered-nan-compare-3536

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes #3536. The AMD Radeon 860M Windows driver returns true for ordered less-than or greater-than when one operand is NaN and the other is +infinity supplied as a shader constant. The existing agc_driver_f32_compare_constant test covers both operations.

FPOrdLessThan32 and FPOrdGreaterThan32 now AND their native ordered comparison with an integer bit check that both operands are ordered. This returns false for every NaN input while preserving results for all ordered values. The same bit check is shared with FPOrdNotEqual32, covering the earlier AMD ordered not-equal issue (#825). This handles both NaN < +infinity and +infinity > NaN without a constant-specific specialization.

Tested

Checklist

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

@github-actions github-actions Bot added the shader core/shader label Oct 11, 2026
@MarcZX10

Copy link
Copy Markdown
Contributor Author

I also compiled the existing register-operand comparison shader offline through Recompile and confirmed that its +infinity RHS reaches this specialization. The CTest runtime still skips here without a Vulkan device, so the AMD Windows result remains unverified on my side.

MarcZX10 and others added 2 commits October 11, 2026 14:36
…than

On the AMD Windows driver 32.0.13058.8001 (Radeon 860M), a NaN compared
less than +infinity, or +infinity greater than a NaN, gives 1 when the
infinity reaches the shader as a constant, as in
agc_driver_f32_compare_constant's register operand case (boykopovar#3536). The
same driver returns 1 for a NaN in an ordered not-equal (boykopovar#825), which is
presumably what its compiler turns these compares into. FPOrdLessThan32
and FPOrdGreaterThan32 now AND their result with the integer NaN check
FPOrdNotEqual32 already uses, which gives the same result for every
input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1cfbde5)
@MarcZX10
MarcZX10 force-pushed the codex/amd-ordered-nan-compare-3536 branch from f106957 to d668b7c Compare October 11, 2026 14:36
@MarcZX10 MarcZX10 changed the title fix(shader): handle NaN below positive infinity fix(shader): handle ordered NaN comparisons Oct 11, 2026
@github-actions github-actions Bot added the docs label Oct 11, 2026
@klosixgaming-arch

Copy link
Copy Markdown
Contributor

Cross-GPU verification on Windows (this is the data your container couldn't produce — no Vulkan device there).

Setup: Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, Release; NVIDIA RTX 5090 and AMD Radeon iGPU; ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1. Base main a11c8f7 (same base as this PR). For the "with this PR" runs I applied your exact SpirvAluEmitterMath.cpp change onto that base.

On main (no fix):

With this PR:

  • agc_driver_f32_compare_constant: passes on both GPUs.
  • agc_driver_vopc_compare (all ordered/unordered f32/f16 compare predicates): passes on both GPUs.

So the added BothOrderedBits32 AND on FPOrdLessThan32 / FPOrdGreaterThan32 / FPOrdNotEqual32 shows no regression to any compare predicate on either NVIDIA or AMD here. I did not observe a case where it changes a result that was already correct, consistent with the "same for every input" claim.

Written with AI assistance.

@LeandroLP23

Copy link
Copy Markdown
Contributor

Thanks @MarcZX100. The final tree of this head (d668b7c2b) is identical to #3595's, so the Radeon 860M results posted there apply to it as is. Those results are from Windows 11 (26300), AMD driver 32.0.13058.8001, Release, on main a11c8f7f7, with the AMD Vulkan cache and shader_cache emptied before each run:

  • agc_driver_f32_compare_constant passes 3/3. It fails on main, and it fails at v_cmp_gt_f32 0x7f800000, 0x7fc00000 with only less-than guarded.
  • ctest -R agc_ passes 374/374.

Closing #3595 in favour of this one.

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked: the change is an AND of the native ordered compare with a bit-level "both operands ordered" check, so results are identical for every input; agc_driver_f32_compare_constant, agc_driver_vopc_compare and agc_driver_vopc_compare_table pass on Linux, and the Radeon 860M run by @LeandroLP23 (3/3, fails on main) plus @klosixgaming-arch's NVIDIA/AMD run show no regression. TechnicalDebt entry matches the code. Merging.

@adriadam10
adriadam10 merged commit aab41de into boykopovar:main Oct 11, 2026
15 checks passed
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_f32_compare_constant fails on the AMD Windows driver: v_cmp_lt_f32 NaN < +inf from a register gives 1

4 participants