rdna2spirv: f16 interp deltas and toward-zero p2 narrow (SHADER-468) #1181

Open
github-bot wants to merge 2 commits from github-bot/gh-1181 into main AGit
Owner

@⁠whoalin1 on GitHub · 2026-11-24 19:42 UTC · original
whoalin1:shader-468-f16-varying → main · +520 −40 · 6 files · 2 commits · open

Claimed in the coordination issue as: SHADER-468 (claim)

Depends on: none

What and why

For a 16-bit (f16) interpolation channel, the SPI writes the P10/P20 delta words as per-half f16 differences of the two packed halves, and v_interp_p2_f16 narrows its result toward zero (the driver's ISA runs the pair inside s_round_mode 0x000c, MODE.FP16_ROUND toward zero — LLVM's SIModeRegister documents the same requirement). The translation used the f32 difference of the decoded halves and narrowed to nearest even.

Measured on real RDNA2 hardware (tools/f16_interp_probe.py, 12 hand-written draws, 98,304 pixel samples, Ryzen 5 7600 iGPU / gfx1036, AMD Windows driver 24.10.24):

model samples explained
rdna2 (this PR: f16-rounded deltas, f32 sum, toward-zero narrow) 98,274
same model, nearest-even narrow 62,226
same model, f32 deltas (old translation) 89,993
f16 accumulated sum 86,919

The remaining 30 misses are documented in the docs/design.md row (26 f16-subnormal boundary cases, 4 exact-grid-boundary perspective cases).

Changes:

  • tools/rdna2spirv.py: Gen.f16_round rounds an f32 to the nearest f16 value via integer-built bits + UnpackHalf2x16 (unfooldable per OLD-512/OLD-513); the interpolation weighting rounds P1−P0 / P2−P0 to f16 for 16-bit-channel reads; v_interp_p2_f16 narrows with f16_bits(rtz=True).
  • runtime/test/vk_harness.cpp: VKH_PC_BYTES must be a multiple of 4 (VkPushConstantRange), both-stage capability scan covers Float16/StorageInputOutput16/Float64, VKH_SHADER_INFO=1 dumps driver ISA.
  • tools/f16_interp_probe.py (new measurement tool, hand-written GLSL only), tests/semantic/test_interp_f16_round.py (new), test_interp_p1lv_f16.py oracle updated to the measured model, docs/design.md contract row updated.

Tested

  • py -3.14 -I scripts/run_semantic_tests.py tests/semantic: 471 files, 6,170 tests, 0 failed
  • py -3.14 -m unittest discover -s tests/semantic -p "test_interp*.py": 207 tests OK; -p "test_f16*.py": 49 OK (40 env skips)
  • scripts/check_no_game_data.py on all changed files: clean
  • tools/f16_interp_probe.py --gpu amd re-run after the change: rdna2 model 98,274/98,304 (identical measurement)
  • GPU suite (run_gpu_tests.py): --filter interp 3/3 and --filter f16 20/20 on both GPUs below, LEONIDA_VK_VALIDATION=1 on AMD: 0 validation errors

GPUs tested: AMD Radeon Graphics (Ryzen 5 7600 iGPU, gfx1036-class RDNA2, driver 24.10.24, Vulkan 1.3.280, Windows 11); NVIDIA GeForce RTX 4070 SUPER (driver 610.88, Windows 11)

AI-assisted: yes (Devin)

Checklist

  • Based on current main and merges cleanly
  • One topic; follow-up work goes in a new pull request
  • No game data, keys or decryption — the probe uses hand-written GLSL fixtures only
  • Translator rule change recorded in the docs/design.md contract table with how it was confirmed (on-hardware measurement)
**@⁠whoalin1** on GitHub · 2026-11-24 19:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1181) `whoalin1:shader-468-f16-varying` → `main` · +520 −40 · 6 files · 2 commits · open Claimed in the coordination issue as: SHADER-468 ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)) Depends on: none ### What and why For a 16-bit (`f16`) interpolation channel, the SPI writes the P10/P20 delta words as **per-half f16 differences** of the two packed halves, and `v_interp_p2_f16` narrows its result **toward zero** (the driver's ISA runs the pair inside `s_round_mode 0x000c`, MODE.FP16_ROUND toward zero — LLVM's SIModeRegister documents the same requirement). The translation used the f32 difference of the decoded halves and narrowed to nearest even. Measured on real RDNA2 hardware (`tools/f16_interp_probe.py`, 12 hand-written draws, 98,304 pixel samples, Ryzen 5 7600 iGPU / gfx1036, AMD Windows driver 24.10.24): | model | samples explained | |---|---| | rdna2 (this PR: f16-rounded deltas, f32 sum, toward-zero narrow) | **98,274** | | same model, nearest-even narrow | 62,226 | | same model, f32 deltas (old translation) | 89,993 | | f16 accumulated sum | 86,919 | The remaining 30 misses are documented in the `docs/design.md` row (26 f16-subnormal boundary cases, 4 exact-grid-boundary perspective cases). Changes: - `tools/rdna2spirv.py`: `Gen.f16_round` rounds an f32 to the nearest f16 value via integer-built bits + `UnpackHalf2x16` (unfooldable per OLD-512/OLD-513); the interpolation weighting rounds P1−P0 / P2−P0 to f16 for 16-bit-channel reads; `v_interp_p2_f16` narrows with `f16_bits(rtz=True)`. - `runtime/test/vk_harness.cpp`: `VKH_PC_BYTES` must be a multiple of 4 (VkPushConstantRange), both-stage capability scan covers Float16/StorageInputOutput16/Float64, `VKH_SHADER_INFO=1` dumps driver ISA. - `tools/f16_interp_probe.py` (new measurement tool, hand-written GLSL only), `tests/semantic/test_interp_f16_round.py` (new), `test_interp_p1lv_f16.py` oracle updated to the measured model, `docs/design.md` contract row updated. ### Tested - `py -3.14 -I scripts/run_semantic_tests.py tests/semantic`: **471 files, 6,170 tests, 0 failed** - `py -3.14 -m unittest discover -s tests/semantic -p "test_interp*.py"`: 207 tests OK; `-p "test_f16*.py"`: 49 OK (40 env skips) - `scripts/check_no_game_data.py` on all changed files: clean - `tools/f16_interp_probe.py --gpu amd` re-run after the change: rdna2 model 98,274/98,304 (identical measurement) - GPU suite (`run_gpu_tests.py`): `--filter interp` 3/3 and `--filter f16` 20/20 on **both** GPUs below, `LEONIDA_VK_VALIDATION=1` on AMD: 0 validation errors GPUs tested: AMD Radeon Graphics (Ryzen 5 7600 iGPU, gfx1036-class RDNA2, driver 24.10.24, Vulkan 1.3.280, Windows 11); NVIDIA GeForce RTX 4070 SUPER (driver 610.88, Windows 11) AI-assisted: yes (Devin) ### Checklist - [x] Based on current `main` and merges cleanly - [x] One topic; follow-up work goes in a new pull request - [x] No game data, keys or decryption — the probe uses hand-written GLSL fixtures only - [x] Translator rule change recorded in the `docs/design.md` contract table with how it was confirmed (on-hardware measurement)
Measured on the RDNA2 iGPU (gfx1036, tools/f16_interp_probe.py, 98,304
samples over 12 native draws): the SPI writes P10/P20 for a 16-bit
channel as per-half f16 differences (round to nearest even), the
weighted sum stays f32, and v_interp_p2_f16 narrows toward zero --
the driver's ISA runs the pair inside s_round_mode 0x000c, so the
narrow is toward zero whatever the shader's own MODE writes are.
The rdna2 model explains 98,274 of 98,304 samples; the previous
translation (f32 deltas, nearest-even narrow) explains 62,226.

- Gen.f16_round: f32 -> nearest-f16 value via f16_bits +
  UnpackHalf2x16 (integer-built bits, so no driver folds the round
  trip away, #512/#513); applied to the P1-P0 / P2-P0 deltas of
  16-bit-channel reads in attribute().
- v_interp_p2_f16 narrows with f16_bits(rtz=True) and keeps the
  SHADER-430 partial-write high half via write_lo16.
- vk_harness: scan both stages for Float16 / StorageInputOutput16 /
  Float64 capabilities (77 when the device lacks them), enable the
  matching Vulkan 1.1/1.2 features, VKH_PC_BYTES to shrink the
  push-constant range for hand-written fixtures, and VKH_SHADER_INFO
  to dump the driver's fragment disassembly.
- tests/semantic/test_interp_f16_round.py: the two telling cases
  (f16 delta overflow to inf; toward-zero vs nearest-even tie).
- tests/semantic/test_interp_p1lv_f16.py: reference oracle updated
  to the measured model (f16 deltas, f32 sum, toward-zero narrow).
- docs/design.md: 16-bit interpolation row records the SHADER-468
  measurements and remaining unverified items.

Co-Authored-By: Devin <[email protected]>
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:41:48 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 19:45 UTC · original · approved these changes

### Clean-Room & Technical Verification

  • Mergeability: Clean 3-way merge against upstream main (6293c1c4f), zero merge conflicts.
  • Clean-Room Compliance: 100% compliant with clean-room requirements. Hand-written GLSL fixtures only; no game data, retail binaries, or keys.
  • Hardware & ISA Fidelity:
    • Gen.f16_round correctly unpacks integer-built bits via UnpackHalf2x16, avoiding folding regressions across driver optimization passes.
    • Per-half f16 difference rounding in attribute() accurately reflects SPI parameter writing behavior for 16-bit channels.
    • v_interp_p2_f16 forced RTZ (rtz=True) directly aligns with AMD driver hardware mode register settings (s_round_mode 0x000c) around the interpolation pair.
    • Comprehensive hardware validation (98,274 / 98,304 samples explained on RDNA2 gfx1036).
  • Test Coverage:
    • tests/semantic/test_interp_f16_round.py: 2/2 passed.
    • tests/semantic/test_interp_p1lv_f16.py: 36/36 passed.
    • Contract documented in docs/design.md.

LGTM! Approved.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 19:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1181#pullrequestreview-6046180922) · **approved these changes** ### Clean-Room & Technical Verification - **Mergeability**: Clean 3-way merge against upstream `main` (`6293c1c4f`), zero merge conflicts. - **Clean-Room Compliance**: 100% compliant with clean-room requirements. Hand-written GLSL fixtures only; no game data, retail binaries, or keys. - **Hardware & ISA Fidelity**: - `Gen.f16_round` correctly unpacks integer-built bits via `UnpackHalf2x16`, avoiding folding regressions across driver optimization passes. - Per-half f16 difference rounding in `attribute()` accurately reflects SPI parameter writing behavior for 16-bit channels. - `v_interp_p2_f16` forced RTZ (`rtz=True`) directly aligns with AMD driver hardware mode register settings (`s_round_mode 0x000c`) around the interpolation pair. - Comprehensive hardware validation (98,274 / 98,304 samples explained on RDNA2 `gfx1036`). - **Test Coverage**: - `tests/semantic/test_interp_f16_round.py`: 2/2 passed. - `tests/semantic/test_interp_p1lv_f16.py`: 36/36 passed. - Contract documented in `docs/design.md`. LGTM! Approved.
Author
Owner

@⁠Deedlyy on GitHub · 2026-11-24 20:09 UTC · original

Recommendation: [WAIT]

Reasoning: f16 interpolation now uses per-half f16 P10/P20 deltas and toward-zero narrowing in v_interp_p2_f16, which the author measured on real RDNA2 with a new 313-line probe tool, and the vk harness is extended. It's a precision change to every f16 interpolant, and nobody has independently reproduced it. Before merging, someone should run the new semantic tests and the probe/harness on a second GPU (ideally another RDNA2 and one non-AMD) to confirm the measurement. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main.

Impact level: 5/10

**@⁠Deedlyy** on GitHub · 2026-11-24 20:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1181#issuecomment-7143123516) **Recommendation:** [WAIT] **Reasoning:** f16 interpolation now uses per-half f16 P10/P20 deltas and toward-zero narrowing in `v_interp_p2_f16`, which the author measured on real RDNA2 with a new 313-line probe tool, and the vk harness is extended. It's a precision change to every f16 interpolant, and nobody has independently reproduced it. Before merging, someone should run the new semantic tests and the probe/harness on a second GPU (ideally another RDNA2 and one non-AMD) to confirm the measurement. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. **Impact level:** 5/10
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 20:10 UTC · original

Verified af76fefad on Arch Linux (Python 3.14):

  • PYTHONPATH=tests/semantic python3 -m unittest tests/semantic/test_interp_f16_round.py tests/semantic/test_interp_p1lv_f16.py: 38 tests passed (0.109 s)

AI-assisted: yes

**@⁠madhyn** on GitHub · 2026-11-24 20:10 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1181#issuecomment-7143141228) Verified `af76fefad` on Arch Linux (Python 3.14): - `PYTHONPATH=tests/semantic python3 -m unittest tests/semantic/test_interp_f16_round.py tests/semantic/test_interp_p1lv_f16.py`: **38 tests passed** (0.109 s) AI-assisted: yes
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 18:22 UTC · original · approved these changes

Approving e4eed02. Merged into current main (b9320a1) with no conflicts. The full translator suite, including the new test_interp_f16_round.py and the updated test_interp_p1lv_f16.py, gives 491 files / 6,294 tests with only test_int32_to_f64 failing, the same baseline failure as main here (Linux, Python 3.13).

The translator change matches the model the probe selects. P10/P20 of a 16-bit channel are rounded to f16 through f16_bits, so no driver can fold the round trip away, while the weights and sum stay f32. v_interp_p2_f16 now narrows toward zero regardless of MODE, which follows from the s_round_mode 0x000c the AMD compiler puts around the pair. I can't repeat the gfx1036 measurement here; the code does what the write-up says it measured.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 18:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1181#pullrequestreview-6062813526) · **approved these changes** Approving e4eed02. Merged into current main (b9320a1) with no conflicts. The full translator suite, including the new `test_interp_f16_round.py` and the updated `test_interp_p1lv_f16.py`, gives 491 files / 6,294 tests with only `test_int32_to_f64` failing, the same baseline failure as main here (Linux, Python 3.13). The translator change matches the model the probe selects. P10/P20 of a 16-bit channel are rounded to f16 through `f16_bits`, so no driver can fold the round trip away, while the weights and sum stay f32. `v_interp_p2_f16` now narrows toward zero regardless of MODE, which follows from the `s_round_mode 0x000c` the AMD compiler puts around the pair. I can't repeat the gfx1036 measurement here; the code does what the write-up says it measured. AI-assisted (Claude).
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 19:08 UTC · original

Real-hardware probe results on e4eed0218 (current head):

AMD RDNA2 iGPU (AMD Radeon(TM) Graphics, subgroup 32..64), 98,304 samples over 12 draws:

model explained
rdna2 98,274/98,304
translator_rne 62,226/98,304
translator_rtz 89,993/98,304
f16_acc 86,919/98,304

The remaining 30 rdna2 misses are the already-described corner cases: subnormal-range values and exact f16-grid/perspective-weight cases. The next-best model is still 8,281 samples behind, so this strongly supports the implemented per-half f16 delta + f32 weighted sum + toward-zero p2 narrow model rather than the old RNE model.

NVIDIA RTX 4070 SUPER: the probe cannot run on this device because it reports no storageInputOutput16; with the harness guard in this branch it exits honestly as unsupported instead of crashing or producing meaningless data:

unsupported: ps.spv uses 16-bit shader input/output and the device has no storageInputOutput16

vk_harness rebuilt cleanly (BUILD_RC=0). Logs are local in leonida-s468/.scratch/f16_{amd,nv}.log. AI-assisted verification with Devin.

**@⁠whoalin1** on GitHub · 2026-11-25 19:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1181#issuecomment-7171870041) Real-hardware probe results on `e4eed0218` (current head): **AMD RDNA2 iGPU** (`AMD Radeon(TM) Graphics`, subgroup 32..64), 98,304 samples over 12 draws: | model | explained | | --- | ---: | | `rdna2` | 98,274/98,304 | | `translator_rne` | 62,226/98,304 | | `translator_rtz` | 89,993/98,304 | | `f16_acc` | 86,919/98,304 | The remaining 30 `rdna2` misses are the already-described corner cases: subnormal-range values and exact f16-grid/perspective-weight cases. The next-best model is still 8,281 samples behind, so this strongly supports the implemented per-half f16 delta + f32 weighted sum + toward-zero p2 narrow model rather than the old RNE model. **NVIDIA RTX 4070 SUPER**: the probe cannot run on this device because it reports no `storageInputOutput16`; with the harness guard in this branch it exits honestly as unsupported instead of crashing or producing meaningless data: ```text unsupported: ps.spv uses 16-bit shader input/output and the device has no storageInputOutput16 ``` `vk_harness` rebuilt cleanly (`BUILD_RC=0`). Logs are local in `leonida-s468/.scratch/f16_{amd,nv}.log`. AI-assisted verification with Devin.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1181/head:github-bot/gh-1181'
git switch 'github-bot/gh-1181'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1181'
git switch 'github-bot/gh-1181'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1181'
git switch 'github-bot/gh-1181'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1181'
git switch 'main'
git merge --squash 'github-bot/gh-1181'
git switch 'main'
git merge --ff-only 'github-bot/gh-1181'
git switch 'main'
git merge 'github-bot/gh-1181'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.