shader: lower the binary16 interpolation forms #3613

Open
github-bot wants to merge 7 commits from github-bot/gh-3611 into main AGit
Owner

@⁠lambirou on GitHub · 2026-11-30 13:51 UTC · original
lambirou:shader/f16-interp → main · +531 −17 · 12 files · 7 commits · open

Part of the f16 interpolation slice (Refs #839).

This adds the three binary16 interpolation forms: v_interp_p1ll_f16, v_interp_p1lv_f16 and v_interp_p2_f16, in the attribute profile without a sampler and under the entry mask. The compr layout places the two halves of attr0.x in TEXCOORD0.xy and the two halves of attr0.y in .zw. p1ll/p1lv record a typed partial and p2 writes narrow16(uv.<component>) as a half16 result, so only the low 16 bits are defined. The p1lv source must be a VGPR whose selected half is finite and proven; half_denorm="preserve" is required and round-toward-zero is refused.

Refusals: modifiers, clamp, omod, op_sel, non-VGPR sources, attributes beyond attr0.y, a sampled programme, a missing/different m0, a non-entry mask, unaudited readers, the full-word, pack and export uses, and reading the p1 partial.

Tests

  • pixel_aot_f16_interp_warp and _hardware pass (2/2) on WARP and the AMD Radeon RX 9060 XT (driver 32.0.32029.2010).
  • The draw covers exact and inexact weights, the p1ll/p1lv/p2 stages and a reader chain; five mutations report pixel_mismatch on both adapters.
  • check_f16_interp_controls pins the three forms and every spelling, proof, mode, scheduling and reader refusal; form_coverage_check.py passes and keeps the f32 interpolation, the MIMG sample forms and the packs uncovered.
  • rdna2_tools_check.py passes 162 tests (19 LLVM-dependent skips); pixel_aot_attribute and pixel_aot_e64_spellings still pass (6/6).
  • Expected full table after the merge: 1,623/1,968 gfx1013 and 1,577/1,863 gfx1030 (measured baseline 1,620/1,574 plus these three).

Limits

The AOT translator has no LDS binding: the desktop rasteriser evaluates the plane, as for the f32 pair, and the lowering does not consume the Scarlett P0/P10/P20 binary16 words directly. Exact equality with the native calculation for non-exact binary16 vertices remains an assumption. The high half of the p2 destination is not observed. The path is limited to attr0.x/y, the entry mask and programmes without a sampler; runtime or non-finite p1lv sources are refused.

AI-assisted.

**@⁠lambirou** on GitHub · 2026-11-30 13:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3611) `lambirou:shader/f16-interp` → `main` · +531 −17 · 12 files · 7 commits · open Part of the f16 interpolation slice (Refs #839). This adds the three binary16 interpolation forms: `v_interp_p1ll_f16`, `v_interp_p1lv_f16` and `v_interp_p2_f16`, in the attribute profile without a sampler and under the entry mask. The `compr` layout places the two halves of `attr0.x` in `TEXCOORD0.xy` and the two halves of `attr0.y` in `.zw`. p1ll/p1lv record a typed partial and p2 writes `narrow16(uv.<component>)` as a `half16` result, so only the low 16 bits are defined. The p1lv source must be a VGPR whose selected half is finite and proven; `half_denorm="preserve"` is required and round-toward-zero is refused. Refusals: modifiers, `clamp`, omod, `op_sel`, non-VGPR sources, attributes beyond `attr0.y`, a sampled programme, a missing/different `m0`, a non-entry mask, unaudited readers, the full-word, pack and export uses, and reading the p1 partial. ## Tests - `pixel_aot_f16_interp_warp` and `_hardware` pass (2/2) on WARP and the AMD Radeon RX 9060 XT (driver 32.0.32029.2010). - The draw covers exact and inexact weights, the p1ll/p1lv/p2 stages and a reader chain; five mutations report `pixel_mismatch` on both adapters. - `check_f16_interp_controls` pins the three forms and every spelling, proof, mode, scheduling and reader refusal; `form_coverage_check.py` passes and keeps the f32 interpolation, the MIMG sample forms and the packs uncovered. - `rdna2_tools_check.py` passes 162 tests (19 LLVM-dependent skips); `pixel_aot_attribute` and `pixel_aot_e64_spellings` still pass (6/6). - Expected full table after the merge: **1,623/1,968** gfx1013 and **1,577/1,863** gfx1030 (measured baseline 1,620/1,574 plus these three). ## Limits The AOT translator has no LDS binding: the desktop rasteriser evaluates the plane, as for the f32 pair, and the lowering does not consume the Scarlett P0/P10/P20 binary16 words directly. Exact equality with the native calculation for non-exact binary16 vertices remains an assumption. The high half of the p2 destination is not observed. The path is limited to `attr0.x/y`, the entry mask and programmes without a sampler; runtime or non-finite p1lv sources are refused. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 13:55:38 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-11-30 20:40 UTC · original · requested changes

Reviewed 188818b0 by reading the diff; not built or run.

Verdict: changes requested. v_interp_p1lv_f16 drops its VGPR P0 operand, so an accepted program can produce the wrong value.

  • MUST p1lv computes P10·I + S2.half: the VGPR half replaces the attribute's P0. After p2, the guest result is P0' + P10·I + P20·J, where P0' is S2. The lowering proves S2 finite and then discards its value (tools/pixel_aot.py, form == "p1lv" branch). The completed p2 always emits narrow16(uv.<c>) (p2 branch), which is the host-interpolated attribute with its own P0. That is right only when S2 equals P0, which the translator cannot know. The draw shows it: v20 = 0x3c003800 gives S2 = 0.5 (low) and 1.0 (high). At vertex 0 of tests/pixel_aot_vs.hlsl, attr0.y's halves are uv.z = 0.25 and uv.w = 1.0, so the high row matches only by coincidence. For the low-half rows, hardware returns uv.z + 0.25, while the lowering and its reference return uv.z. No mutation changes S2, so the draw cannot see this. Suggest either refusing p1lv in this slice (keep p1ll + p2), or binding P0 explicitly (e.g. a flat input like #3625's TEXCOORD1), lowering to narrow16(uv.c − P0 + S2) and deciding where it rounds.
  • Checked, no finding:
    • p1ll + p2 matches the host plane when P0 comes from the attribute, and narrow16 is RNE. The 1 + uv/64 vertices separate RNE from truncation.
    • The compr halves map attr0.x to .xy and attr0.y to .zw, and the high bit picks the second of each pair.
    • Refused: modifiers, clamp/omod/op_sel, non-VGPR sources, attributes above attr0.y, a sampled program, non-entry masks, unpaired p1/p2, and round-toward-zero (the generic binary16 gate).
    • The half16 result only reaches the audited readers.

Tests: the draw compares against TEXCOORD0 with two mutations (halves swapped, channel swapped). Neither changes S2, so the p1lv operand is unpinned. The controls run in the Linux LLVM job (passed). pixel_aot_f16_interp_{warp,hardware} are not in the Windows pr preset filter. The offscreen_check changes add only the f16/fine batch entry points.

**@⁠lukaslw-lab** on GitHub · 2026-11-30 20:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3611#pullrequestreview-6120174424) · **requested changes** Reviewed `188818b0` by reading the diff; not built or run. **Verdict: changes requested.** `v_interp_p1lv_f16` drops its VGPR `P0` operand, so an accepted program can produce the wrong value. - **MUST** `p1lv` computes `P10·I + S2.half`: the VGPR half *replaces* the attribute's `P0`. After `p2`, the guest result is `P0' + P10·I + P20·J`, where `P0'` is `S2`. The lowering proves `S2` finite and then discards its value (`tools/pixel_aot.py`, `form == "p1lv"` branch). The completed `p2` always emits `narrow16(uv.<c>)` (`p2` branch), which is the host-interpolated attribute with its own `P0`. That is right only when `S2` equals `P0`, which the translator cannot know. The draw shows it: `v20 = 0x3c003800` gives `S2` = 0.5 (low) and 1.0 (high). At vertex 0 of `tests/pixel_aot_vs.hlsl`, attr0.y's halves are `uv.z = 0.25` and `uv.w = 1.0`, so the `high` row matches only by coincidence. For the low-half rows, hardware returns `uv.z + 0.25`, while the lowering and its reference return `uv.z`. No mutation changes `S2`, so the draw cannot see this. Suggest either refusing `p1lv` in this slice (keep `p1ll` + `p2`), or binding `P0` explicitly (e.g. a flat input like #3625's `TEXCOORD1`), lowering to `narrow16(uv.c − P0 + S2)` and deciding where it rounds. - Checked, no finding: - `p1ll` + `p2` matches the host plane when `P0` comes from the attribute, and `narrow16` is RNE. The `1 + uv/64` vertices separate RNE from truncation. - The compr halves map `attr0.x` to `.xy` and `attr0.y` to `.zw`, and the `high` bit picks the second of each pair. - Refused: modifiers, clamp/omod/op_sel, non-VGPR sources, attributes above `attr0.y`, a sampled program, non-entry masks, unpaired `p1`/`p2`, and round-toward-zero (the generic binary16 gate). - The `half16` result only reaches the audited readers. Tests: the draw compares against `TEXCOORD0` with two mutations (halves swapped, channel swapped). Neither changes `S2`, so the `p1lv` operand is unpinned. The controls run in the Linux LLVM job (passed). `pixel_aot_f16_interp_{warp,hardware}` are not in the Windows `pr` preset filter. The `offscreen_check` changes add only the f16/fine batch entry points.
Keep both vertex-input additions in pixel_aot_vs.hlsl: the fine uv path used by the binary16 interpolation fixture and main's flat p0 values for draw-interp-mov. Keep draw-f16-interp and draw-interp-mov in the pixel draw dispatch.
Author
Owner

@⁠Leyukaka on GitHub · 2026-12-01 16:09 UTC · original · reviewed

The fine draw does not exercise rounding for the P1LL/P2 pairs. In both test programs those pairs read X and Y. At the 64 pixel centers, the fine X values are 1 + (2x + 1)/1024, and Y follows the same formula with y. Every one is exactly representable in binary16. Counting where nearest-even differs from truncation gives X=0, Y=0, Z=32, W=0. Only the P1LV/P2 pair on Z detects the truncating-reference mutation.

For example, changing only the fine X input to 1 + u/128 would give 32 pixels where rounding matters for a P1LL/P2 result. Please add a mutation that truncates only that result. Its readback should then differ on X while the P1LV/P2 outputs remain unchanged.

**@⁠Leyukaka** on GitHub · 2026-12-01 16:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3611#pullrequestreview-6135136091) · **reviewed** The fine draw does not exercise rounding for the P1LL/P2 pairs. In both test programs those pairs read X and Y. At the 64 pixel centers, the fine X values are 1 + (2x + 1)/1024, and Y follows the same formula with y. Every one is exactly representable in binary16. Counting where nearest-even differs from truncation gives X=0, Y=0, Z=32, W=0. Only the P1LV/P2 pair on Z detects the truncating-reference mutation. For example, changing only the fine X input to 1 + u/128 would give 32 pixels where rounding matters for a P1LL/P2 result. Please add a mutation that truncates only that result. Its readback should then differ on X while the P1LV/P2 outputs remain unchanged.
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/3613/head:github-bot/gh-3611'
git switch 'github-bot/gh-3611'

Merge

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