shader: follow known 16-bit VGPR halves across half ops, phis, and exports (#455) #468

Open
github-bot wants to merge 1 commit from github-bot/gh-464 into main AGit
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 21:24 UTC · original
Sheffy007:feat/known-half-register-reads → main · +929 −60 · 5 files · 1 commits · open

Closes #459
Refs #4, #258

Problem

When v_fma_mixlo_f16 or v_fma_mixhi_f16 writes one 16-bit half over a VGPR whose other half has no host form (such as a v_interp_p1ll_f16 scratch register or a barycentric input), Lower records the known half in low16 or high16 while leaving Val::Missing in vals. However:

  1. high16 had no source lookup helper, and low16/high16 were not consulted by v_fma_mix* (op_sel_hi high half), v_pack_b32_f16, v_pk_*, 16-bit VALU high-half sources, SDWA selects, half-shifts/half-masks/v_bfi_b32/v_bfe_*/v_perm_b32, a16/d16 image and LDS half accesses, or unguarded v_mov_b32/v_cndmask_b32 copies.
  2. write_half and low_half zeroed the kept half instead of preserving low16/high16 when completing a register, and reset_for_rect_corner did not clear high16.
  3. Lower::export neither clipped Target::Color channels to OSG1's cols nor consulted low16/high16 on compressed exports (exp ... compr on GFX10 enables register pairs via en 0x3 or 0xf even for 1- or 3-channel targets).
  4. fill_phis refused joins of known-half values whose transitive readers only read that half, and overwritten_movreld_edge only matched "barycentrics read directly" and not "the first half of an interpolation".

Changes

  • crates/victory-shader/src/emit/lower.rs, lower/rect.rs:
    • Add half16_src, value_half, src_half, and phi_half_only / only_reads_half, and clear high16 in reset_for_rect_corner.
    • Follow low16/high16 across v_fma_mix*, v_pack_b32_f16, v_pk_*, half_src, v_fmac_f16/v_mac_f16, SDWA selects, v_lshlrev_b32/v_lshrrev_b32/v_ashrrev_i32 (>= 16), half-mask v_and_b32/v_and_or_b32/v_lshl_add_u32/v_lshl_or_b32/v_bfi_b32/v_bfe_*/v_perm_b32, a16/d16 image and LDS half accesses, unguarded v_mov_b32/v_cndmask_b32 copies, and half-only fill_phis joins.
    • Preserve low16/high16 in write_half and low_half, and extend overwritten_movreld_edge to "the first half of an interpolation".
    • Restrict Target::Color exports to [col, col + cols), read value_half for half exports, and pad the trailing odd half of guessed 1-/3-channel exp ... compr pairs (// Guess:, documented in docs/native-host.md).
  • Tests:
    • export_tests::compressed_exports_and_half_ops_follow_known_16bit_halves
    • export_tests::half_only_phis_and_overwritten_movreld_loops_translate_while_other_half_reads_refuse
    • shader_tests::known_16bit_halves_draw_across_mix_pack_joins_and_odd_compressed_exports (Metal GPU execution)

Verification

  • cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy

cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-27 21:24 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/464) `Sheffy007:feat/known-half-register-reads` → `main` · +929 −60 · 5 files · 1 commits · open Closes #459 Refs #4, #258 ## Problem When `v_fma_mixlo_f16` or `v_fma_mixhi_f16` writes one 16-bit half over a VGPR whose other half has no host form (such as a `v_interp_p1ll_f16` scratch register or a barycentric input), `Lower` records the known half in `low16` or `high16` while leaving `Val::Missing` in `vals`. However: 1. `high16` had no source lookup helper, and `low16`/`high16` were not consulted by `v_fma_mix*` (`op_sel_hi` high half), `v_pack_b32_f16`, `v_pk_*`, 16-bit VALU high-half sources, SDWA selects, half-shifts/half-masks/`v_bfi_b32`/`v_bfe_*`/`v_perm_b32`, `a16`/`d16` image and LDS half accesses, or unguarded `v_mov_b32`/`v_cndmask_b32` copies. 2. `write_half` and `low_half` zeroed the kept half instead of preserving `low16`/`high16` when completing a register, and `reset_for_rect_corner` did not clear `high16`. 3. `Lower::export` neither clipped `Target::Color` channels to `OSG1`'s `cols` nor consulted `low16`/`high16` on compressed exports (`exp ... compr` on GFX10 enables register pairs via `en` `0x3` or `0xf` even for 1- or 3-channel targets). 4. `fill_phis` refused joins of known-half values whose transitive readers only read that half, and `overwritten_movreld_edge` only matched `"barycentrics read directly"` and not `"the first half of an interpolation"`. ## Changes - **`crates/victory-shader/src/emit/lower.rs`, `lower/rect.rs`:** - Add `half16_src`, `value_half`, `src_half`, and `phi_half_only` / `only_reads_half`, and clear `high16` in `reset_for_rect_corner`. - Follow `low16`/`high16` across `v_fma_mix*`, `v_pack_b32_f16`, `v_pk_*`, `half_src`, `v_fmac_f16`/`v_mac_f16`, SDWA selects, `v_lshlrev_b32`/`v_lshrrev_b32`/`v_ashrrev_i32` (`>= 16`), half-mask `v_and_b32`/`v_and_or_b32`/`v_lshl_add_u32`/`v_lshl_or_b32`/`v_bfi_b32`/`v_bfe_*`/`v_perm_b32`, `a16`/`d16` image and LDS half accesses, unguarded `v_mov_b32`/`v_cndmask_b32` copies, and half-only `fill_phis` joins. - Preserve `low16`/`high16` in `write_half` and `low_half`, and extend `overwritten_movreld_edge` to `"the first half of an interpolation"`. - Restrict `Target::Color` exports to `[col, col + cols)`, read `value_half` for `half` exports, and pad the trailing odd half of guessed 1-/3-channel `exp ... compr` pairs (`// Guess:`, documented in `docs/native-host.md`). - **Tests:** - `export_tests::compressed_exports_and_half_ops_follow_known_16bit_halves` - `export_tests::half_only_phis_and_overwritten_movreld_loops_translate_while_other_half_reads_refuse` - `shader_tests::known_16bit_halves_draw_across_mix_pack_joins_and_odd_compressed_exports` (Metal GPU execution) ## Verification - `cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask` - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy` cc @⁠Olima34
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:25:35 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 23:02 UTC · original

Thanks for this PR! An offline check of f880ac60, with no game run:

On current main (b998bb65) + #468: tests pass (victory-gpu on arm64, plus victory-hle, victory, xtask and victory-shader). Windows clippy (x86_64-pc-windows-gnullvm, -D warnings) is clean, and cargo xtask policy passes.

Corpus sweep (examples/sweep + tools/corpus/compare.sh, main → main + #468), on two local shader sets:

set newly translated output changed regressions other reason now
A (4,921 shaders) 1 pixel (was: barycentrics read directly) 52 pixel 0 0
B (4,129 shaders) 28 pixel: 22 barycentrics read directly, 4 "lane mask … not written by a scalar ALU instruction", 2 "first half of an interpolation" 90 pixel 0 0

Compute and vertex shaders are unchanged. All changed outputs are in pixel shaders, which fits the export and half-op changes.

Merging:

  • #468 merges cleanly with #413 and with the preview/graphics-2026-11-28 branch (b3c1a1b0).
  • On that preview branch the counts are the same as on main: +1 / 52 changed on A, +28 / 90 changed on B, 0 regressions.
  • With #413, the gains mostly overlap. #413 + #468 adds 3 shaders over #413 alone, all on B, with 0 regressions: pixel_4ced2d9a4b14e6cc, pixel_ef85b8efcc24a3b6 and pixel_ecc384d4a7ffd3e0. Outputs changed for 53 shaders on A and 124 on B.

I haven't checked the rendering of the changed outputs, since no game run was done.

**@⁠Olima34** on GitHub · 2026-11-27 23:02 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/464#issuecomment-7229823699) Thanks for this PR! An offline check of f880ac60, with no game run: **On current main (b998bb65) + #468:** tests pass (victory-gpu on arm64, plus victory-hle, victory, xtask and victory-shader). Windows clippy (`x86_64-pc-windows-gnullvm`, `-D warnings`) is clean, and `cargo xtask policy` passes. **Corpus sweep** (`examples/sweep` + `tools/corpus/compare.sh`, main → main + #468), on two local shader sets: | set | newly translated | output changed | regressions | other reason now | |---|---|---|---|---| | A (4,921 shaders) | 1 pixel (was: barycentrics read directly) | 52 pixel | 0 | 0 | | B (4,129 shaders) | 28 pixel: 22 barycentrics read directly, 4 "lane mask … not written by a scalar ALU instruction", 2 "first half of an interpolation" | 90 pixel | 0 | 0 | Compute and vertex shaders are unchanged. All changed outputs are in pixel shaders, which fits the export and half-op changes. **Merging:** - #468 merges cleanly with #413 and with the `preview/graphics-2026-11-28` branch (b3c1a1b0). - On that preview branch the counts are the same as on main: +1 / 52 changed on A, +28 / 90 changed on B, 0 regressions. - With #413, the gains mostly overlap. #413 + #468 adds 3 shaders over #413 alone, all on B, with 0 regressions: `pixel_4ced2d9a4b14e6cc`, `pixel_ef85b8efcc24a3b6` and `pixel_ecc384d4a7ffd3e0`. Outputs changed for 53 shaders on A and 124 on B. I haven't checked the rendering of the changed outputs, since no game run was done.
github-bot force-pushed github-bot/gh-464 from f880ac60df to 68b9b4c619 2026-11-28 00:42:34 +00:00 Compare
github-bot force-pushed github-bot/gh-464 from 68b9b4c619 to 6021d5f6d8 2026-11-28 00:51:18 +00:00 Compare
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/468/head:github-bot/gh-464'
git switch 'github-bot/gh-464'

Merge

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