shader: follow known 16-bit VGPR halves across compressed exports, packed/half ops, and phis ("the first half of an interpolation") #459

Open
opened 2026-11-27 20:35:29 +00:00 by github-bot · 2 comments
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 20:31 UTC · original

Refs #4, #258

In world runs (#4), 8 pixel programs are refused as "the first half of an interpolation" (and #377 noted 2 pixel programs newly stopping at "the first half of an interpolation" after v_fma_mixlo_f16 / v_fma_mixhi_f16 pairing).

Cause

When a 16-bit write (v_fma_mixlo_f16 or v_fma_mixhi_f16) writes one 16-bit half of a VGPR that still holds a v_interp_p1ll_f16 / v_interp_p1_f32 partial value (Val::Missing("the first half of an interpolation")) or another untranslated input, Lower records the known half in low16 or high16 while keeping Val::Missing in vals. Several 16-bit readers and writers do not yet consult low16 / high16:

  1. Compressed pixel exports (exp mrtN ... compr) and 16-bit parameter exports (Lower::export): exporting an odd channel count (RGB with en = 0x7, or R with en = 0x1) after v_fma_mixlo_f16 (or an high-half channel after v_fma_mixhi_f16) calls self.i32_of(value) unconditionally even when half is Some(false) or Some(true).
  2. 16-bit and subword readers: high16 has no high16_src counterpart to low16_src, and neither is consulted by v_pack_b32_f16, Lower::packed_src (v_pk_*), VOP1 v_cvt_f32_f16 (opsel == 0), v_fma_mix_* high-half sources (opsel_hi && opsel), Lower::half_src (high), SDWA high-half selects in src / fsrc, v_lshrrev_b32 / v_ashrrev_i32 by >= 16, half-mask v_and_b32, or half-only constant v_perm_b32.
  3. Mixed 16-bit half pairs (write_half and low_half): pairing v_fma_mixlo_f16 / v_fma_mixhi_f16 with v_interp_p2_f16, v_cvt_f16_f32, or v_add_f16 drops the known low16 / high16 half and zeroes it instead of preserving it; reset_for_rect_corner also omits high16.clear().
  4. Phis read only in one 16-bit half (fill_phis) and overwritten_movreld_edge: phis whose consumers only read one 16-bit half refuse Val::Missing edges even when low16 / high16 holds that half on every live edge, and overwritten_movreld_edge only matches "barycentrics read directly" and not "the first half of an interpolation".

Plan

  • Add high16_src alongside low16_src, consult low16 / high16 across all single-half readers (export, v_pack_b32_f16, packed_src, half_src, v_fma_mix_*, v_cvt_f32_f16, SDWA src/fsrc, >= 16 right shifts, half-mask v_and_b32, constant v_perm_b32), preserve known halves in write_half / low_half, clear high16 in reset_for_rect_corner, and resolve single-half phi reads and "the first half of an interpolation" in overwritten_movreld_edge while keeping any read of an unknown half refused.
  • Add positive and negative unit tests in victory-shader and an end-to-end Metal GPU pixel readback test in victory-gpu.
**@⁠Sheffy007** on GitHub · 2026-11-27 20:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/455) Refs #4, #258 In world runs (#4), 8 pixel programs are refused as `"the first half of an interpolation"` (and #377 noted 2 pixel programs newly stopping at `"the first half of an interpolation"` after `v_fma_mixlo_f16` / `v_fma_mixhi_f16` pairing). ### Cause When a 16-bit write (`v_fma_mixlo_f16` or `v_fma_mixhi_f16`) writes one 16-bit half of a VGPR that still holds a `v_interp_p1ll_f16` / `v_interp_p1_f32` partial value (`Val::Missing("the first half of an interpolation")`) or another untranslated input, `Lower` records the known half in `low16` or `high16` while keeping `Val::Missing` in `vals`. Several 16-bit readers and writers do not yet consult `low16` / `high16`: 1. **Compressed pixel exports (`exp mrtN ... compr`) and 16-bit parameter exports (`Lower::export`):** exporting an odd channel count (`RGB` with `en = 0x7`, or `R` with `en = 0x1`) after `v_fma_mixlo_f16` (or an high-half channel after `v_fma_mixhi_f16`) calls `self.i32_of(value)` unconditionally even when `half` is `Some(false)` or `Some(true)`. 2. **16-bit and subword readers:** `high16` has no `high16_src` counterpart to `low16_src`, and neither is consulted by `v_pack_b32_f16`, `Lower::packed_src` (`v_pk_*`), VOP1 `v_cvt_f32_f16` (`opsel == 0`), `v_fma_mix_*` high-half sources (`opsel_hi && opsel`), `Lower::half_src` (`high`), SDWA high-half selects in `src` / `fsrc`, `v_lshrrev_b32` / `v_ashrrev_i32` by `>= 16`, half-mask `v_and_b32`, or half-only constant `v_perm_b32`. 3. **Mixed 16-bit half pairs (`write_half` and `low_half`):** pairing `v_fma_mixlo_f16` / `v_fma_mixhi_f16` with `v_interp_p2_f16`, `v_cvt_f16_f32`, or `v_add_f16` drops the known `low16` / `high16` half and zeroes it instead of preserving it; `reset_for_rect_corner` also omits `high16.clear()`. 4. **Phis read only in one 16-bit half (`fill_phis`) and `overwritten_movreld_edge`:** phis whose consumers only read one 16-bit half refuse `Val::Missing` edges even when `low16` / `high16` holds that half on every live edge, and `overwritten_movreld_edge` only matches `"barycentrics read directly"` and not `"the first half of an interpolation"`. ### Plan - Add `high16_src` alongside `low16_src`, consult `low16` / `high16` across all single-half readers (`export`, `v_pack_b32_f16`, `packed_src`, `half_src`, `v_fma_mix_*`, `v_cvt_f32_f16`, SDWA `src`/`fsrc`, `>= 16` right shifts, half-mask `v_and_b32`, constant `v_perm_b32`), preserve known halves in `write_half` / `low_half`, clear `high16` in `reset_for_rect_corner`, and resolve single-half phi reads and `"the first half of an interpolation"` in `overwritten_movreld_edge` while keeping any read of an unknown half refused. - Add positive and negative unit tests in `victory-shader` and an end-to-end Metal GPU pixel readback test in `victory-gpu`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:35:29 +00:00
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 20:31 UTC · original

/claim

**@⁠Sheffy007** on GitHub · 2026-11-27 20:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/455#issuecomment-7227583444) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-27 20:31 UTC · original

Claimed by @⁠Sheffy007. Open a draft pull request with Refs #455 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-27 20:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/455#issuecomment-7227586187) Claimed by @⁠Sheffy007. Open a draft pull request with `Refs #455` in its description within 24 hours, or the claim expires.
github-bot referenced this issue from a commit 2026-11-28 00:29:35 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.