Repository navigation
Shader: preserve the first NaN payload in binary f32 min and max - #3057
Conversation
RDNA2 keeps the first quiet NaN word when both operands are quiet NaNs. A shader can convert its sign and payload into a finite color, while NMin and NMax alone may discard both operands in this case.
|
Tested
|
|
Tested
Tools: llvm-mc 21.1.8 with AMDGPU target, SPIRV-Tools 2026.1, GCC 13.3.0, Python 3.12.3. No code was edited or pushed; only synthetic fixtures were used. AI-assisted. |
Kam471
left a comment
There was a problem hiding this comment.
Verified on the PR head: python -I -m pytest for the new test -> 1 passed, related suite 20 passed / 38 subtests, docs-row test 2 passed. The 4 rows / 16 output words check both-qNaN orders and finite/±0; mutating to main's translator fails at index 0 (0x3F000000 instead of 0x3F200080), so the test is non-vacuous. The rule (NMin/NMax plus OpIsNan(y) ? x : r) gives one-NaN -> other operand and both-NaN -> first operand, matching the measured RX 6800 (gfx1030) result in docs/design.md / docs/shader_validation.md:999, also confirmed on gfx1150. No game data or absolute paths. Approve.
Minor: OpIsNan is emitted even when y is a non-NaN constant, adding a little SPIR-V; sNaN, clamp and min3 are not covered by the new fixture.
The semantic CI job discovers tests with unittest. Run the numerical fixture there and retain compiled shader validation in the tool-backed pytest job.
|
Tested 1. Native hardware, a second RDNA2. AMD Radeon iGPU (Ryzen 9 9950X3D, A note on signalling NaNs, which the PR doesn't claim anything about (sNaN =
2. On the GPU, with run-time operands. A hand-written compute shader (not part of this PR) reads x =
So before the change NVIDIA's driver returned its canonical NaN and AMD's returned one operand regardless of order. With the change, both give the hardware words in both orders. 3. The test file. I can reproduce @zzEmmazz's report: Also: |
|
I reproduced the |
|
Follow-up: the head moved to
|
Keep the targeted regression and the intervening upstream changes together for review.
|
Tested
The new fixture is a CPU (interpreter) fixture, so the changed lowering was not run on hardware here. This run shows it breaks nothing else on AMD. AI-assisted (Claude Code). No game files. |
|
Tested
Not tested: AMD/Intel GPUs, Linux/Wine. Tested with AI assistance (Claude); synthetic shaders only, no game data. |
Claimed in the coordination issue as SHADER-568, binary f32 min/max quiet NaN selection.
What and why
On RX 6800, binary
v_min_f32andv_max_f32returned the first quiet NaN with its sign and payload when both operands were quiet NaNs. GLSL.std.450 NMin/NMax permit an arbitrary NaN in this case. Select the first operand when the second is NaN. A shader that inspects the resulting bits then sees the measured word. Original gfx1030 measurements and translator change.Tested
0x3f000000. After, min and max give0x3f200080in the first operand order and0xbf110040in the reverse order. Single-NaN and signed-zero controls passed for both opcodes.Checklist
docs/design.md, with how it was confirmed.AI-assisted with Codex.