Skip to content

Shader: encode NaN as zero in normalized typed buffer stores - #1315

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:codex/normalized-buffer-store-nan
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:codex/normalized-buffer-store-nan

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as normalized typed stores, following the BUILD-161 native measurement.

What and why

All 2,046 binary16 NaN encodings stored byte 0x00 in RGBA8_SNORM on native gfx1036. The translated store on main wrote 0x81 for every one of them on both tested GPUs. GLSL.std.450 FClamp leaves its result undefined for NaN.

Produce one NaN-to-zero conversion per source component and share it among the UNORM/SNORM packing branches before clamp, scale and rounding. The floating-point and integer formats continue to read the original component words. The tests check full-precision and packed inputs, both normalized formats, a signaling NaN, a quiet NaN, an infinity, a rounding tie, and retention of a raw NaN payload by 32_FLOAT and 32_UINT stores.

Tested

  • Source-built raw RDNA2 kernels, AMD Radeon Graphics gfx1036, Windows 32.0.21045.16010: every binary16 encoding was packed into one RGBA8 component through buffer_store_format_d16_xyzw, for both SNORM and UNORM and in wave32 and wave64. Every finite byte matched the independent reference (clamp, multiply by 127 or 255, nearest-even integer); both infinities saturated and every NaN stored zero. Guard dwords survived.
  • Four synthetic compute shaders translated and passed spirv-val on c0ac5fd and this change. On RTX 5080 (616.92) and the same Radeon, the baseline had precisely 2,046/65,536 incorrect SNORM bytes per adapter, and zero UNORM errors. Here all 65,536 bytes match native per format and adapter. A negative control reducing just the V# byte count by four left the last dword at its initial sentinel with every prior byte preserved. No Vulkan VUID.
  • pytest tests/test_translate.py: 371 passed, two skipped. The four normalized-store cases failed on the parent. python -m unittest discover -s tests/semantic: 1,171 tests, one skipped.
  • The Windows Runtime job on the base has a separate predicated-copy test failure.

Checklist

  • All inputs were generated from source. No game data, keys or decryption.
  • The measured normalized-store rule is in the buffer format stores row of docs/design.md.

AI-assisted.

The buffer unit encodes every half NaN as zero. Passing NaN to FClamp instead produced the negative signed-normalized endpoint on both translated backends.
@kapitche

Copy link
Copy Markdown
Contributor

Tested b9893db on Windows 11 with llvm-mc 23.1.6 (Linux had no llvm-mc, so the new tests skipped there): pass.

@ItsNotRexed
ItsNotRexed merged commit 3277d0d into ItsNotRexed:main Nov 22, 2026
9 of 10 checks passed
@freemanovec

Copy link
Copy Markdown
Contributor

Tested b9893db9 on Intel(R) HD Graphics 530 (SKL GT2), Mesa 26.2.7-arch1.1 (ANV), Arch Linux: pass. AI-only review and run.

  • Code review: clean and scoped — computes OpIsNan → 0 once per source component and feeds it only to unorm/snorm branches, leaving float and integer formats on the original bits; docs/design.md updated and tests cover both unpacked and d16 normalized stores plus unnormalized NaN preservation.
  • python3 -I tests/semantic/test_buffer_load_format.py: 22/22 OK; tests/semantic/test_norm_decode.py: 6/6 OK (pytest not installed here for tests/test_translate.py).
  • scripts/run_gpu_tests.py (llvm-mc 23.1.5, SPIRV-Tools v2026.4): cs_store (1/1 pass) and cs_fmt_1010102 (1/1 pass, 64/64 words exact).

No game files.

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.

4 participants