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

Open
opened 2026-11-27 20:31:11 +00:00 by Sheffy007 · 2 comments
Sheffy007 commented 2026-11-27 20:31:11 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T20:31:11Z.


Refs #4, #258

In world runs (#4), 8 pixel programs are refused as "the first half of an interpolation" (and #374 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.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6654027139 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/455). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T20:31:11Z. --- Refs #4, #258 In world runs (#4), 8 pixel programs are refused as `"the first half of an interpolation"` (and #374 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 commented 2026-11-27 20:31:12 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T20:31:12Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7227583444 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/455#issuecomment-7227583444). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T20:31:12Z. --- /claim
github-actions[bot] commented 2026-11-27 20:31:22 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T20:31:22Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7227586187 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/455#issuecomment-7227586187). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T20:31:22Z. --- Claimed by @Sheffy007. Open a draft pull request with `Refs #455` in its description within 24 hours, or the claim expires.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS#455
No description provided.