shader: allow safe entry interpolation in pixel loops (Part of #3814) #3831

Merged
timbot103 merged 1 commit from upstream-pr/3831 into main 2026-12-02 10:11:30 +00:00
timbot103 commented 2026-12-02 07:57:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T07:57:20Z.


Allows safe entry attribute interpolation (v_interp_mov_f32 flat fetches and same-block v_interp_p1_f32/v_interp_p2_f32 pairs whose entry barycentrics are preserved on all reaching CFG paths) after branches in looping pixel shaders, clearing "looping graphics shader uses an entry input operation after a branch" (~315 pixel stages in #3814, including the main second wall exposed by #3815).

Part of #3814. Refs #3640, #3641, #3703, #3815.
(Opened as Draft per #3514 until an active review slot frees.)

Summary

  • src/gfx1013_direct_graphics.inl (emit_graphics_loops):
    • Replaces the read.pc > last_loop_edge linear scan with an exact CFG dataflow over g.overwritten_inputs (recording all lowered VGPR writes per block, including v_interp_p1_f32 and implicit v_swap_b32 destinations, and propagating them across all CFG edges including back-edges).
    • Allows flat v_interp_mov_f32 loads before, inside, and after loops (subject to the existing selector/attribute checks in graphics.interpolate).
    • Allows same-block v_interp_p1_f32/v_interp_p2_f32 pairs in any pixel loop block whenever no in-block prefix write and no reaching CFG path (including loop back-edges) clobbers the barycentric source VGPR. Allows P1 to overwrite its own source after consuming it when no path returns to that read, while refusing if P1 overwrites P2's source or a back-edge returns to the read.
    • Keeps Encoding::Fetch, op == 3, cross-block split P1/P2 pairs, non-barycentric sources, and invalid flat selectors strictly refused.
  • tests/native_pixel_loop_entry_inputs_check.py + tests/cmake/native_pixel_loop_entry_inputs.cmake + docs/experiments/native-pixel-loop-entry-inputs.md:
    • native_pixel_loop_entry_inputs_controls (runs automatically in the pr CTest preset): 4 positive shapes (CMPX if/else join before loop, smooth interpolation inside loop, flat loads before/inside/after loop, smooth P1 self-overwrite after loop) + 9 fail-closed refusal controls (loop clobbers I/J after pair, loop P1 overwrites own source, pre-loop arm clobber, v_swap_b32 clobber, P1 clobbers P2 source, split pair, non-barycentric source, invalid flat selector).
    • native_pixel_loop_entry_inputs_warp & native_pixel_loop_entry_inputs_hardware: four 8×2 draws on WARP and RTX 5080, each paired with a wrong-trip-count mismatch control (all 16 pixels differ).

Verification

Host: Windows 11 (10.0.26200.9974), MSVC 19.44.35230 (C++20 /W4, zero new warnings), DXC 1.9.2602.17, inbox WARP (10.0.26100.9818), NVIDIA GeForce RTX 5080 (32.0.16.2140; D3D12 debug layer unavailable). Base origin/main f365f125.

  • ctest --preset pr --no-tests=error -R "^native_pixel_loop_entry_inputs_controls$": 1/1 passed.
  • Debug (dev) & Release (release): 15/15 passed in both configs (native_pixel_loop_entry_inputs_{controls,warp,hardware}, native_pixel_cmpx_*, native_pixel_compare_mask_*, native_pixel_dxil, native_graphics_wqm_*, native_direct_container), zero skips.
  • tests/bidi_controls_check.py, tests/docs_links_check.py, git diff --check origin/main..HEAD: all clean.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5602281279 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3831). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T07:57:20Z. --- Allows safe entry attribute interpolation (`v_interp_mov_f32` flat fetches and same-block `v_interp_p1_f32`/`v_interp_p2_f32` pairs whose entry barycentrics are preserved on all reaching CFG paths) after branches in looping pixel shaders, clearing `"looping graphics shader uses an entry input operation after a branch"` (~315 pixel stages in #3814, including the main second wall exposed by #3815). Part of #3814. Refs #3640, #3641, #3703, #3815. *(Opened as Draft per #3514 until an active review slot frees.)* ## Summary - **`src/gfx1013_direct_graphics.inl` (`emit_graphics_loops`):** - Replaces the `read.pc > last_loop_edge` linear scan with an exact CFG dataflow over `g.overwritten_inputs` (recording all lowered VGPR writes per block, including `v_interp_p1_f32` and implicit `v_swap_b32` destinations, and propagating them across all CFG edges including back-edges). - Allows flat `v_interp_mov_f32` loads before, inside, and after loops (subject to the existing selector/attribute checks in `graphics.interpolate`). - Allows same-block `v_interp_p1_f32`/`v_interp_p2_f32` pairs in any pixel loop block whenever no in-block prefix write and no reaching CFG path (including loop back-edges) clobbers the barycentric source VGPR. Allows P1 to overwrite its own source after consuming it when no path returns to that read, while refusing if P1 overwrites P2's source or a back-edge returns to the read. - Keeps `Encoding::Fetch`, `op == 3`, cross-block split P1/P2 pairs, non-barycentric sources, and invalid flat selectors strictly refused. - **`tests/native_pixel_loop_entry_inputs_check.py` + `tests/cmake/native_pixel_loop_entry_inputs.cmake` + `docs/experiments/native-pixel-loop-entry-inputs.md`:** - `native_pixel_loop_entry_inputs_controls` (runs automatically in the `pr` CTest preset): 4 positive shapes (CMPX if/else join before loop, smooth interpolation inside loop, flat loads before/inside/after loop, smooth P1 self-overwrite after loop) + 9 fail-closed refusal controls (loop clobbers I/J after pair, loop P1 overwrites own source, pre-loop arm clobber, `v_swap_b32` clobber, P1 clobbers P2 source, split pair, non-barycentric source, invalid flat selector). - `native_pixel_loop_entry_inputs_warp` & `native_pixel_loop_entry_inputs_hardware`: four 8×2 draws on WARP and RTX 5080, each paired with a wrong-trip-count mismatch control (all 16 pixels differ). ## Verification Host: Windows 11 (`10.0.26200.9974`), MSVC `19.44.35230` (C++20 `/W4`, zero new warnings), DXC `1.9.2602.17`, inbox WARP (`10.0.26100.9818`), NVIDIA GeForce RTX 5080 (`32.0.16.2140`; D3D12 debug layer unavailable). Base `origin/main` `f365f125`. - `ctest --preset pr --no-tests=error -R "^native_pixel_loop_entry_inputs_controls$"`: **1/1 passed**. - **Debug (`dev`) & Release (`release`):** 15/15 passed in both configs (`native_pixel_loop_entry_inputs_{controls,warp,hardware}`, `native_pixel_cmpx_*`, `native_pixel_compare_mask_*`, `native_pixel_dxil`, `native_graphics_wqm_*`, `native_direct_container`), zero skips. - `tests/bidi_controls_check.py`, `tests/docs_links_check.py`, `git diff --check origin/main..HEAD`: all clean.
lukaslw-lab commented 2026-12-02 08:05:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T08:05:41Z.

Review: APPROVED


Reviewed 7f029c4e (draft) by reading the diff; not built or run.

Verdict: approve. The CFG dataflow is a sound replacement for the old "after the last back edge" scan, and it fails closed. No MUST.

  • SHOULD No measured stage count. The ~315 is the #3814 first-refusal count. Those stages can stop at the next wall, so a ps86 census on f365f125 before and after would give the real gain (follow-up is fine).
  • Checked, no finding:
    • Completeness: every VGPR write reaches after_graphics_write → overwritten_inputs (gfx1013_direct_graphics.inl:1912), including load destinations and both v_swap_b32 operands. So dropping the explicit Image/MUBUF/LDS ranges of the old entry_barycentric loses nothing. The set is cleared per block (:1587), so written[label] is that block's own writes.
    • The dataflow handles back edges: a write later in the read's own block reaches the read only through a back edge into that block, and the in-block prefix is still refused at lowering (:66, :1608).
    • P1 reads I and P2 reads J (src == base + (op==1)). Each is recorded separately, so a clobber of only J is still caught. MOV has no VGPR source.
    • interpolate loads the attribute from the input signature (load(generic(...))) and uses I/J only as provenance. Interpolating inside a loop with lane-varying trip counts therefore needs no derivatives or helper lanes.
    • Split pairs across blocks still hit "intermediate interpolation value consumed in loop", and Fetch and op 3 stay refused.

Tests: _controls (4 shapes, 9 refusals, including a back-edge clobber, v_swap_b32 and P1 overwriting P2's source) is in the pr filter. _warp/_hardware have wrong-trip-count controls and ran only locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6146848407 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3831#pullrequestreview-6146848407). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T08:05:41Z. **Review:** APPROVED --- Reviewed `7f029c4e` (draft) by reading the diff; not built or run. **Verdict: approve.** The CFG dataflow is a sound replacement for the old "after the last back edge" scan, and it fails closed. No MUST. - **SHOULD** No measured stage count. The ~315 is the #3814 first-refusal count. Those stages can stop at the next wall, so a `ps86` census on `f365f125` before and after would give the real gain (follow-up is fine). - Checked, no finding: - Completeness: every VGPR write reaches `after_graphics_write` → `overwritten_inputs` (`gfx1013_direct_graphics.inl:1912`), including load destinations and both `v_swap_b32` operands. So dropping the explicit Image/MUBUF/LDS ranges of the old `entry_barycentric` loses nothing. The set is cleared per block (`:1587`), so `written[label]` is that block's own writes. - The dataflow handles back edges: a write later in the read's own block reaches the read only through a back edge into that block, and the in-block prefix is still refused at lowering (`:66`, `:1608`). - P1 reads I and P2 reads J (`src == base + (op==1)`). Each is recorded separately, so a clobber of only J is still caught. MOV has no VGPR source. - `interpolate` loads the attribute from the input signature (`load(generic(...))`) and uses I/J only as provenance. Interpolating inside a loop with lane-varying trip counts therefore needs no derivatives or helper lanes. - Split pairs across blocks still hit "intermediate interpolation value consumed in loop", and `Fetch` and op 3 stay refused. Tests: `_controls` (4 shapes, 9 refusals, including a back-edge clobber, `v_swap_b32` and P1 overwriting P2's source) is in the `pr` filter. `_warp`/`_hardware` have wrong-trip-count controls and ran only locally.
timbot103 commented 2026-12-02 09:34:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T09:34:21Z.


Promoted to Ready for review now that #3806 and #3826 merged (keeping at 5/5 non-draft PRs per #3514). Re-checked CLEAN / MERGEABLE against origin/main (45c809ab) with all CI checks green.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7341127187 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3831#issuecomment-7341127187). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T09:34:21Z. --- Promoted to Ready for review now that #3806 and #3826 merged (keeping at 5/5 non-draft PRs per #3514). Re-checked `CLEAN / MERGEABLE` against `origin/main` (`45c809ab`) with all CI checks green.
R0Y00 commented 2026-12-02 10:07:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T10:07:23Z.

Review: APPROVED


Independent Windows Debug result at 7f029c4e: ctest --preset dev --no-tests=error -j 1 -R '^native_pixel_loop_entry_inputs_(controls|warp|hardware)$' --output-on-failure passed 3/3. The control-flow refusals and both pixel readbacks passed. Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the offscreen fixture's D3D12 debug layer enabled.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6148697604 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3831#pullrequestreview-6148697604). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T10:07:23Z. **Review:** APPROVED --- Independent Windows Debug result at `7f029c4e`: `ctest --preset dev --no-tests=error -j 1 -R '^native_pixel_loop_entry_inputs_(controls|warp|hardware)$' --output-on-failure` passed 3/3. The control-flow refusals and both pixel readbacks passed. Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the offscreen fixture's D3D12 debug layer enabled.
lukaslw-lab commented 2026-12-02 10:34:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T10:34:33Z.


Census follow-up for the SHOULD in my review: f365f125 + this PR alone, same capture and method as #3814 (6,436 distinct pixel stages). Counts only. None lost, no validation failures.

Build Pixel translated Moved off looping graphics shader uses an entry input operation after a branch
f365f125 272 —
f365f125 + #3831 272 315 of 315

All 315 now stop at the same next wall, graphics readfirstlane requires a wave-uniform reaching value, so the interpolation part is cleared and the loop's v_readfirstlane is what remains.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7342671304 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3831#issuecomment-7342671304). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T10:34:33Z. --- Census follow-up for the SHOULD in my review: `f365f125` + this PR alone, same capture and method as #3814 (6,436 distinct pixel stages). Counts only. **None lost**, no validation failures. | Build | Pixel translated | Moved off `looping graphics shader uses an entry input operation after a branch` | |---|---:|---:| | `f365f125` | 272 | — | | `f365f125` + #3831 | 272 | **315 of 315** | All 315 now stop at the same next wall, `graphics readfirstlane requires a wave-uniform reaching value`, so the interpolation part is cleared and the loop's `v_readfirstlane` is what remains.
Sign in to join this conversation.
No reviewers
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
R0Y00/Xbox2Windows!3831
No description provided.