fix(shader): handle ordered NaN comparisons #3541
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3541"
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 MarcZX10 on 2026-10-11T12:44:48Z.
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
+infinitysupplied as a shader constant. The existingagc_driver_f32_compare_constanttest covers both operations.FPOrdLessThan32andFPOrdGreaterThan32now 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 withFPOrdNotEqual32, covering the earlier AMD ordered not-equal issue (#825). This handles bothNaN < +infinityand+infinity > NaNwithout a constant-specific specialization.Tested
agc_driver_f32_compare_constant_tests.Recompileof the existing register-operand comparison shader confirmed the+infinitycomparison path; the integrated checks also cover the symmetric greater-than case.agc_driver_f32_compare_constantwas skipped locally because this container has no Vulkan device. The #3595 author reported this test passing 3/3 on AMD Windows with the shared ordered NaN check; issue #3536 records the failing baseline.python3 tools/check_conventions.py --base upstream/mainpassed.git diff --check upstream/main...HEADpassed.Checklist
main; no other open PR implements the same behaviorImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T12:46:58Z.
I also compiled the existing register-operand comparison shader offline through
Recompileand confirmed that its+infinityRHS reaches this specialization. The CTest runtime still skips here without a Vulkan device, so the AMD Windows result remains unverified on my side.Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-11T15:17:19Z.
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. Basemaina11c8f7(same base as this PR). For the "with this PR" runs I applied your exactSpirvAluEmitterMath.cppchange onto that base.On
main(no fix):agc_driver_f32_compare_constant: passes on both GPUs. The #3536 miscompile (v_cmp_lt_f32 NaN, +inf-from-register → 1) does not reproduce here — my AMD iGPU driver differs from the reported Radeon 860M / 24.30.58.08, so I can't confirm the crash-side fix on this hardware, only that it doesn't regress.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
BothOrderedBits32AND onFPOrdLessThan32/FPOrdGreaterThan32/FPOrdNotEqual32shows 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.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-11T17:11:09Z.
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, onmaina11c8f7f7, with the AMD Vulkan cache andshader_cacheemptied before each run:agc_driver_f32_compare_constantpasses 3/3. It fails onmain, and it fails atv_cmp_gt_f32 0x7f800000, 0x7fc00000with only less-than guarded.ctest -R agc_passes 374/374.Closing #3595 in favour of this one.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:43:06Z.
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_compareandagc_driver_vopc_compare_tablepass 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.