shader: lower pull-model barycentrics and supply 1/W for pixel POS_W_FLOAT #562

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

@⁠Sheffy007 on GitHub · 2026-11-28 04:30 UTC · original
Sheffy007:feat/pull-model-barycentrics-pos-w → main · +246 −8 · 4 files · 1 commits · open

Closes #561
Refs #258, #410, #525

cc @⁠Olima34

Summary

  1. Lower Barycentric::PerspectivePullModel (SPI_PS_INPUT_ADDR bit 3: <I / W, J / W, 1 / W>).
    • On GFX10 hardware, PERSP_PULL_MODEL_ENA loads pixel-centre <I / W, J / W, 1 / W> into three entry VGPRs, which shaders read as data to evaluate screen-space derivatives/offsets and recover perspective (I, J). Lower::barycentric previously returned Val::Missing(BARYCENTRICS_READ) for B::PerspectivePullModel (the remaining "barycentrics read directly" pixel-shader refusals in #525).
    • Lowers indices 0 and 1 as perspective-centre SV_Barycentrics.yz / SV_Position.w and index 2 as 1.0 / SV_Position.w, declaring SV_Position in ISG1 (or widening an unshared narrow SV_Position row to 4 columns) when the input signature does not yet carry SV_Position.w.
  2. Supply 1.0 / SV_Position.w (1 / W) for Input::Position(3) (POS_W_FLOAT, SPI_PS_INPUT_ADDR bit 11).
    • On GFX10 hardware, POS_W_FLOAT holds 1 / W (which console shaders invert with v_rcp_f32 to read HLSL SV_Position.w), whereas DXIL loadInput on SV_Position channel 3 returns W. Returning 1.0 / SV_Position.w avoids the W^2 error when console pixel shaders execute v_rcp_f32 on POS_W_FLOAT.

Verification

  • cargo test -p victory-shader --locked (424 passed, including pull_model_barycentrics_and_pos_w_emit_with_or_without_sv_position)
  • cargo test -p victory-gpu --lib mesh_tests --locked -- --test-threads=1 (24 passed on Metal GPU, including pull_model_barycentrics_and_pixel_pos_w_match_perspective_weights across a perspective triangle with vertex w = 1, 2, 4)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy
**@⁠Sheffy007** on GitHub · 2026-11-28 04:30 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/558) `Sheffy007:feat/pull-model-barycentrics-pos-w` → `main` · +246 −8 · 4 files · 1 commits · open Closes #561 Refs #258, #410, #525 cc @⁠Olima34 ### Summary 1. **Lower `Barycentric::PerspectivePullModel` (`SPI_PS_INPUT_ADDR` bit 3: `<I / W, J / W, 1 / W>`).** - On GFX10 hardware, `PERSP_PULL_MODEL_ENA` loads pixel-centre `<I / W, J / W, 1 / W>` into three entry VGPRs, which shaders read as data to evaluate screen-space derivatives/offsets and recover perspective `(I, J)`. `Lower::barycentric` previously returned `Val::Missing(BARYCENTRICS_READ)` for `B::PerspectivePullModel` (the remaining `"barycentrics read directly"` pixel-shader refusals in #525). - Lowers indices `0` and `1` as perspective-centre `SV_Barycentrics.yz / SV_Position.w` and index `2` as `1.0 / SV_Position.w`, declaring `SV_Position` in `ISG1` (or widening an unshared narrow `SV_Position` row to 4 columns) when the input signature does not yet carry `SV_Position.w`. 2. **Supply `1.0 / SV_Position.w` (`1 / W`) for `Input::Position(3)` (`POS_W_FLOAT`, `SPI_PS_INPUT_ADDR` bit 11).** - On GFX10 hardware, `POS_W_FLOAT` holds `1 / W` (which console shaders invert with `v_rcp_f32` to read HLSL `SV_Position.w`), whereas DXIL `loadInput` on `SV_Position` channel 3 returns `W`. Returning `1.0 / SV_Position.w` avoids the `W^2` error when console pixel shaders execute `v_rcp_f32` on `POS_W_FLOAT`. ### Verification - `cargo test -p victory-shader --locked` (424 passed, including `pull_model_barycentrics_and_pos_w_emit_with_or_without_sv_position`) - `cargo test -p victory-gpu --lib mesh_tests --locked -- --test-threads=1` (24 passed on Metal GPU, including `pull_model_barycentrics_and_pixel_pos_w_match_perspective_weights` across a perspective triangle with vertex `w = 1, 2, 4`) - `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 04:36:22 +00:00
github-bot force-pushed github-bot/gh-558 from bb2b0f3a8c to 88470c9d41 2026-11-28 04:41:59 +00:00 Compare
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 18:31 UTC · original · approved these changes

Reviewed and verified locally on head 88470c9d (worktree /private/tmp/review-558):

  • cargo test -p victory-shader --locked: all green, including pull_model_barycentrics_and_pos_w_emit_with_or_without_sv_position and pixel_system_inputs_and_multiple_barycentrics_populate_isg1.
  • cargo test -p victory-gpu --lib mesh_tests --locked -- --test-threads=1: green on the Metal GPU, including pull_model_barycentrics_and_pixel_pos_w_match_perspective_weights (perspective triangle, vertex w = 1, 2, 4).
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: exit 0.
  • cargo xtask policy: exit 0.

The lowering is right: pull-model indices 0/1 become perspective-centre SV_Barycentrics divided by SV_Position.w, index 2 becomes 1/W, and SV_Position is declared in ISG1 (widened to 4 columns when it shares its row) when the signature lacks .w; POS_W_FLOAT (kind 3, col 3) now returns 1/W so console shaders that run v_rcp_f32 on it get W back without the W^2 error. The two-barycentric-modes rule is now "same perspective-ness", which matches D3D's constraint better than a flat count of two. Approving — this clears the remaining "barycentrics read directly" pixel-shader refusals from #525 and closes #561.

**@⁠AnastasisKon** on GitHub · 2026-11-28 18:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/558#pullrequestreview-6099561475) · **approved these changes** Reviewed and verified locally on head 88470c9d (worktree /private/tmp/review-558): - cargo test -p victory-shader --locked: all green, including pull_model_barycentrics_and_pos_w_emit_with_or_without_sv_position and pixel_system_inputs_and_multiple_barycentrics_populate_isg1. - cargo test -p victory-gpu --lib mesh_tests --locked -- --test-threads=1: green on the Metal GPU, including pull_model_barycentrics_and_pixel_pos_w_match_perspective_weights (perspective triangle, vertex w = 1, 2, 4). - cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: exit 0. - cargo xtask policy: exit 0. The lowering is right: pull-model indices 0/1 become perspective-centre SV_Barycentrics divided by SV_Position.w, index 2 becomes 1/W, and SV_Position is declared in ISG1 (widened to 4 columns when it shares its row) when the signature lacks .w; POS_W_FLOAT (kind 3, col 3) now returns 1/W so console shaders that run v_rcp_f32 on it get W back without the W^2 error. The two-barycentric-modes rule is now "same perspective-ness", which matches D3D's constraint better than a flat count of two. Approving — this clears the remaining "barycentrics read directly" pixel-shader refusals from #525 and closes #561.
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/562/head:github-bot/gh-558'
git switch 'github-bot/gh-558'

Merge

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