Repository navigation
Translator: typed-buffer f32->f16 rounds toward zero and saturates, measured on RDNA2 (SHADER-358) - #2216
Conversation
…s RDNA2 does (SHADER-358) Measured natively on gfx1036 (wave32 and wave64): stores into 16_FLOAT, 16_16_FLOAT and 16_16_16_16_FLOAT and d16 loads from 32-bit float formats round toward zero, give +-65504 for a finite value past the range, flush f32 denormals and keep a NaN's top payload bits without quieting it. The translator rounded to nearest even and overflowed to infinity. UNORM/SNORM d16 loads stay nearest even (re-measured). The new test holds 45 measured values in four forms; the old float tie case asserted the unmeasured rule and now holds the measured words. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested Independent Vulkan check of A wave32 readback checked
Both translated modules passed SPIR-V validation. All four CPU tests in AI-assisted verification. |
|
Tested
Independent check of SHADER-395 in #2078 is the same item; I noted it there (#2078 (comment)). AI-assisted (Claude Code): it built the branch, ran the tests on my GPU, wrote the cross-check and this report. |
|
Independent native check, merged locally onto Hardware: Radeon iGPU, gfx1036 (Ryzen 7 9800X3D), AMD driver 32.0.13036.4, Windows 10 22H2, through d16 narrowing: a
All 8 values match on this PR; main gets 4 of them wrong. Wider sweep: 480 typed-buffer load cases. They cover:
Results:
No game files. AI-assisted (Claude Code). |
SHADER-358 (Vonsek2), claim.
What the hardware does
All measurements are native, on an AMD Radeon RDNA2 iGPU (gfx1036, Ryzen 9 9950X3D, Windows 11, AMD driver 32.0.21045.16010), through
tools/hw_oraclewith AMD clang 23 (rocm-sdk-core10.0.0). Wave32 and wave64 gave identical words. The V#s use the runtime's selectors (X001, XY01, XYZW).f32 → f16 in the buffer unit rounds toward zero and saturates. This covers:
buffer_store_format_x/xy/xyzwinto16_FLOAT,16_16_FLOATand16_16_16_16_FLOAT;buffer_load_format_d16_x/xy/xyzwfrom32_FLOAT,32_32_FLOATand32_32_32_32_FLOAT.All six forms gave the same word for each of 45 values: halfway cases on both sides of even, above and below half an ulp, 65504/65520/65536, 1e10, ±inf, f16 denormal results, f32 denormals and 13 NaN encodings.
0x3f803000(1 + 3·2⁻¹¹)0x3c010x3c020x3f8018000x3c000x3c010x477ff000(65520)0x7bff(65504)0x7c00(inf)0x501502f9(1e10)0x7bff0x7c000x33c00000(1.5·2⁻²⁴)0x00010x00020x7fa00000(signalling NaN)0x7d00(not quieted)0x7f000x7f8000010x7c010x7e00Infinities stay infinite and f32 denormals give a signed zero. A NaN keeps its sign and the top 10 payload bits, or 1 if those bits are 0. Every finite case matches round-toward-zero with saturation at 65504, which is what @AlxcBTW measured for the stores on gfx1150 (finding).
UNORM/SNORM d16 loads are different: nearest even. I re-measured them on gfx1036:
8_UNORMand8_SNORMfor all 256 values,16_UNORMfor 680 values and16_SNORMfor 504. Nearest even of the exact quotient matched every one of them, and toward-zero matched about half. That is the rule #1759 already implements, so nothing changes for normalized formats.Change
tools/rdna2spirv.py:Gen.mem_f16narrows toward zero with saturation (f16_bits(rtz=True)) and applies the measured NaN rule.encode_formatuses it for the f16 kind (stores).d16_norm_f16selects it when the run-time or instruction format is a 32-bit float one.In the "d16 and f16 format narrowing" row of
docs/design.md, the sentence "Round to nearest even for these conversions is inferred, as in #489, not measured" is replaced with the measured rule.Tests
tests/semantic/test_buffer_f16_narrowing_hw.py: 45 measured values in four forms (store x into16_FLOAT, store xy into16_16_FLOAT, d16_x from32_FLOAT, d16_xy from32_32_FLOAT), with no model in the test.main'stools/(LEONIDA_TOOLS_DIR): 84 failures.tests/semantic/test_buffer_load_format.py::test_a_float_format_on_the_halfway_value_still_ties_to_evenasserted the unmeasured rule for the same two values. It is nowtest_a_float_format_rounds_toward_zero, with the words gfx1036 returns for them (0x3bff,0xbbfd).test_buffer_load_format.py,test_d16_pack.py,test_translate.py,test_d16_format_probe.py,test_buffer_format_narrow_int.py,test_mem_diff.pyand the new test: 72 passed.tools/mem_diff.py --programs 800 --seed 5: 800 pass.python -m unittest discover -s tests/semantic: 1,675 tests, OK (2 skipped).scripts/run_gpu_tests.py, all pass:cs_store;cs_fmt_1010102,cs_fmt_sint32,cs_fmt_xy_xyz;cs_tbuffer_store;cs_imgload_d16,cs_sample_lz_int_d16,cs_w32_lds_u8_d16,ps_texture_sample_d16.AI-assisted (Claude Code, Claude Opus 5.5), Vonsek2. Measured on the AMD RDNA2 iGPU (gfx1036, driver 32.0.21045.16010). GPU-checked on the NVIDIA RTX 5080 (driver 32.0.16.1692).
🤖 Generated with Claude Code