Skip to content

Shader: return the RDNA2 v_fract_f16 infinity word - #3032

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/fract-f16-infinity
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/fract-f16-infinity

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as the v_fract_f16 infinity result.

What and why

A pixel shader can treat a half-precision result as integer bits. The fixture extracts the sign of v_fract_f16(+inf) and converts it to an MRT channel. Upstream's CPU output was 0.0. The result word on gfx1036 is 0xfe00 for either infinity, giving a channel of 1.0. With DX10 clamp enabled the clamped result is positive zero. The translator now selects those results explicitly. The reference comes from the published RDNA2 exhaustive measurement.

Tested

  • The hand-written pixel shader assembled with LLVM for gfx1013 and gfx1030. Before and after, 1/1 synthetic shader translated, assembled as SPIR-V, and passed Vulkan 1.2 spirv-val.
  • The CPU regression failed on main. The two result halves were 0x7e00 and the derived color channel was 0.0. The updated translator returned 0xfe00 twice and the channel became 1.0. The test also checks the preserved upper halves, clamped positive and negative infinity, and a finite control (1.5 gives 0.5).
  • Five focused CPU test modules passed on Windows, 74 tests and 893 subtests. No local GPU or game corpus was used.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

AI-assisted with Codex.

Both infinity signs produce a negative quiet NaN on gfx1036. A shader can inspect that sign as integer data and use it to choose a color. Select the measured result explicitly and handle its DX10 clamp before FClamp.
@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 2b71ac98728aba91c8553a4e5109ecd4f31e39e1 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Independent Linux Vulkan check of 2b71ac98 on an RTX 5090 (595.99.02, subgroup 32). I adapted the PR's synthetic pixel fixture by setting the clamped operand to each of its three test values in separate draws. All 4,096 pixels per draw matched the expected raw RGBA words.

Clamped operand R G B A
1.5 1357fe00 2468fe00 3f800000 12343800
+inf 1357fe00 2468fe00 3f800000 12340000
-inf 1357fe00 2468fe00 3f800000 12340000

Reverting only the translator hunk and repeating the 1.5 control produced 13577fff 24687fff 00000000 12343800 at every pixel. The patch fixes both infinity words and the sign-derived channel while preserving the upper halves and the finite control. Every tested module passed SPIR-V validation for Vulkan 1.2. Synthetic inputs only. AI-assisted.

AI-assisted verification.

@CaravelaLabs

Copy link
Copy Markdown
Contributor

Tested 2b71ac98 merged onto main 16282101 on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5, subgroup 32..64), Mesa 25.2.8, Ubuntu 24.04, LLVM 23.1.6, SPIRV-Tools 2026.4: pass.

  • python -I scripts/run_gpu_tests.py --build runtime/build/linux: 172/189 passed, 15 skipped, identical per test to plain main 16282101 on this machine. The two failures in both runs, cs_signed_zero_nan and cs_w32_salu64, are the known Mesa 25.2 RADV ones (GPU test results (one comment per GPU and driver) #166, docs/testing.md).
  • tests/semantic/test_fract_f16_infinity.py: 1 passed.
  • GPU probe: a throwaway hand-written compute fixture (not committed, no game data) with the cases below, translated by this branch and run with vk_compute_test (wave32). v_fract_f16 of +inf and -inf (high halves kept), clamp of +inf and a 1.5 control: 0x1357fe00 0x2468fe00 0x12340000 0x55553800, the gfx1036 words.
  • FYI: plain main already gives 0xfe00 for both infinities on RADV (its Fract(inf) happens to return a negative NaN), so the old behaviour is driver-dependent, and the explicit select makes it the same everywhere. A small robustness thought, not blocking: the select passes the NaN through a float OpSelect before f16_bits bitcasts it; selecting 0xfe00 on the uint after f16_out's narrowing (as fract already does for 0x3bff) would not depend on a driver keeping a float NaN's sign bits. RADV keeps it, so there's nothing observed here.

gfx1151 is RDNA 3.5, not RDNA2: this shows the translated SPIR-V gives the modelled words on a real driver, not that RDNA2 hardware does. AI-assisted (Claude Code).

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 2b71ac98 on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), Python 3.12.10, Vulkan SDK 1.4.363, llvm-mc 23.1.6.

python -m unittest discover -s tests/semantic fails on this branch (main 16282101: 4142 OK):

ERROR: test_fract_f16_infinity (unittest.loader._FailedTest.test_fract_f16_infinity)
ImportError: Failed to import test module: test_fract_f16_infinity
  File "tests\semantic\test_fract_f16_infinity.py", line 5, in <module>
    from conftest import Shader, requires_tools
ModuleNotFoundError: No module named 'conftest'

Shader and requires_tools live in tests/conftest.py, which is not on the path when discovery runs from tests/semantic, and no other file in tests/semantic imports conftest. This is the command the CI semantic-tests job runs (.github/workflows/ci.yml), so that job should fail the same way. The other tests in tests/semantic take their helpers from tests/semantic/support.py.

The GPU side is fine: run_gpu_tests.py 143/189 passed, 46 skipped, 0 failed, same as main, with ps_f16_vop1b and ps_fnan_fract (the two shaders whose SPIR-V changes) passing.

AI-assisted (Claude Code).

The semantic CI job discovers tests with unittest. Run the numerical fixture there and retain compiled shader validation in the tool-backed pytest job.
@evilclanker9000

Copy link
Copy Markdown
Contributor Author

I reproduced the Windows conftest import failure. The regression now uses unittest.TestCase and the existing semantic support helpers. python -I -m unittest discover -s tests/semantic -p test_fract_f16_infinity.py -v passed all three input words. Running the same test against 16282101 gave a word mismatch on the finite-input case and an undefined FClamp for each infinity input. The existing assembly fixture also passed the LLVM-backed translation and Vulkan 1.2 SPIR-V validation test in the outer pytest suite.

Test-only commit ffb0933d.

@TheMrBeez

Copy link
Copy Markdown

Tested ffb0933 (base 16282101): native gfx1036 measurement plus run-time operands on two GPUs. Pass. AI-assisted run, synthetic shaders only, no game files.

1. Native hardware. AMD Radeon iGPU (Ryzen 9 9950X3D, gfx1036, driver 25.10.30.02), raw v_fract_f16 through tools/hw_oracle, wave32 and wave64, MODE.IEEE 1 and 0 (all identical). The destination starts as 0xabcd1111:

source v_fract_f16_e32 v_fract_f16_e64 … clamp
0x12347c00 (+inf) 0xabcdfe00 0xabcd0000
0x1234fc00 (−inf) 0xabcdfe00 0xabcd0000
0x12343e00 (1.5) 0xabcd3800 0xabcd3800

So it's 0xfe00 for either infinity, +0 with clamp (the assembler's default DX10_CLAMP = 1), and the high half kept, as the PR models.

2. On the GPU, with a run-time operand. A hand-written compute shader (not part of this PR) takes the half from s4 (VKC_SGPRS) and starts both destinations as s5 = 0xabcd0000, so constant folding can't hide anything and a lost high half would show:

source base 16282101, RTX 5080 (621.01) base, gfx1036 iGPU this PR, both GPUs
+inf abcd7fff ✗, clamp abcd0000 abcdfe00, abcd0000 abcdfe00, abcd0000 ✓
−inf abcd7fff ✗, clamp abcd0000 abcdfe00, abcd0000 abcdfe00, abcd0000 ✓
1.5 abcd3800, abcd3800 same same ✓

So before the change the result depended on the driver: NVIDIA gave 0x7fff, while AMD's happened to give the hardware word. With the change, both match the hardware.

Also: python -m unittest discover -s tests/semantic -p test_fract_f16_infinity.py Ran 1 test, OK (the conftest fix works on Windows); scripts/run_gpu_tests.py with this translator: RTX 5080 143/189 (46 skipped, wave64), iGPU 174/189 (15 skipped), no failures. Windows 11 Pro 10.0.26200, Vulkan SDK 1.4.363.0, llvm-mc and AMD clang from rocm-sdk-core 10.0.0.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix itself is correct: main fails (0x13577E00 != 0x1357FE00), the 0xfe00 infinity word matches the gfx1036 measurement / f16 invalid-result rule, and both mutations are caught (0xFFC00000 -> 0x7FC00000 fails; removing the clamp special-case fails). But the test wiring is broken in the suite it was added to:

  • tests/semantic/test_fract_f16_infinity.py is pytest-only in a directory CI runs with unittest discover; python -m unittest discover -s tests/semantic raises ModuleNotFoundError: No module named 'conftest'.
  • @requires_tools also needs llvm-mc, which the semantic CI job does not have.

Please either move the test to the pytest-set files (PYTEST_FILE_MARKERS) or rewrite it as a stdlib unittest module that assembles/translates without requiring conftest, and gate the LLVM dependency explicitly so the semantic job runs it rather than erroring. The code change can stay as-is.

Keep the targeted regression and the intervening upstream changes together for review.
@bielfreedom

Copy link
Copy Markdown

Tested ffb0933d (on its base 16282101) on AMD Radeon RX 9070 XT (RDNA4), AMD driver 32.0.32029.2010 (subgroup 32..64), Windows 11 Pro build 26200, with Vulkan validation on (LEONIDA_VK_VALIDATION=1, Vulkan SDK 1.4.363, VK_LOADER_LAYERS_DISABLE=~implicit~): pass, no regression.

  • python -m unittest discover -s tests/semantic (includes this PR's ps_fract_f16_infinity fixture and test): 4143 tests OK.
  • scripts/run_gpu_tests.py: 194 shaders, 194 translated, 194 pass spirv-val; 175/189 passed, 14 skipped, 0 failures. The skips are the shaders run by the d3d12 tests and ps_w64x_readlane.
  • Full ctest: 119/119, 0 validation errors.

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.

@Yourrespawn

Copy link
Copy Markdown
Contributor

Tested a1f6db98 on NVIDIA GeForce RTX 4080 (Ada, subgroup 32..32), driver 617.14, Vulkan API 1.4.351, Windows 11 Pro 10.0.26200: pass.

  • Semantic suite: 7323 OK, 1 expected failure (Python 3.12.10)
  • run_gpu_tests.py (fresh runtime build): 153/199 passed, 0 failed, 46 skipped (native wave64, expected on this 32-lane GPU); ps_fnan_fract 4096/4096 pixels exact — the gfx1036 word 0xfe00 for v_fract_f16(±inf) reaches the MRT channel on NVIDIA too

A testing note worth its own paragraph for other GPU testers: my first run of this branch showed a baffling ps_array_resinfo failure (4096 pixels reporting array-layer count 1 instead of 12). Bisecting against main pinned it to the SHADER-33 commit (07bd05f) — but the real cause was my stale runtime build: that commit's translator emits BaseVertex/BaseInstance builtins (DrawParameters) that the pre-#2543 harness binaries don't enable, and the mismatch surfaced in an unrelated fixture. After rebuilding runtime/build from the current tree the fixture passes outright (1/1), and this branch's full suite is green. So: rebuild before comparing GPU suites when the checkout's runtime C++ is newer than the build — no bug here, and no main regression on this machine.

AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine.

@ItsNotRexed
ItsNotRexed merged commit fec8aa5 into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants