shader: lower structured branches in masked pixel regions (Part of #3814) #3849

Merged
timbot103 merged 11 commits from upstream-pr/3849 into main 2026-12-03 06:28:41 +00:00
timbot103 commented 2026-12-02 09:01:27 +00:00 (Migrated from github.com)

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


Part of #3814 (branch enters a masked graphics region, 363 stages + branch enters a CMPX region, 53 stages = 416 stages).

Summary

Extends GraphicsMaskRegions and lower_graphics in src/gfx1013_direct_graphics.inl to handle structured forward branches inside and around masked pixel regions:

  • Lowers pixel SAVEEXEC, s_and_b64, and v_cmpx_ masked regions containing nested forward branches (nested SAVEEXEC, nested CMPX, or inner uniform scalar diamonds) using structured CFG lane branches (branch_saves / lane_branches / multimap branch_merges) instead of failing straight-line flattening.
  • Accepts external forward branches landing on a shared restore.pc when exec_anchor + preserves_exec proves the bypass edge already holds the parent EXEC mask (clearing inline CMPX predicates on the fallthrough predecessor before the join block so predicates never cross CFG edges).
  • Enforces strict pixel-arm invariants: refuses mid-arm interior entries, cross-arm/backward jumps, unproven EXEC writes inside pixel_arms, implicit-LOD/DPP/LDS/stores/atomics, saved-EXEC clobbers, and escaped arm scalars/mask tags.

Verification

  • Built compile_dxil, offscreen_check, and native_pixel_ir_dump in Debug (dev) and Release (release) with zero new C++20 /W4 warnings on edited lines.
  • ctest --preset pr --no-tests=error --output-on-failure -R '^native_pixel_branch_masked_region_controls$': passed (22 DXIL validations + 21 refusal checks).
  • Debug (dev) and Release (release): 14/14 passed in each build, zero skips.
  • Real GPU readbacks on WARP (10.0.26100.9818) and NVIDIA GeForce RTX 5080 (32.0.16.2140) on Windows 11 (26200.9974): 22 exact 8×2 draws + 22 wrong-reference checks passed per build/adapter.
  • tests/bidi_controls_check.py, tests/docs_links_check.py, and git diff --check origin/main..HEAD passed.
  • Opened as Draft under #3514's 5-PR ready cap.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5603192605 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3849). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T09:01:27Z. --- Part of #3814 (`branch enters a masked graphics region`, 363 stages + `branch enters a CMPX region`, 53 stages = 416 stages). ### Summary Extends `GraphicsMaskRegions` and `lower_graphics` in `src/gfx1013_direct_graphics.inl` to handle structured forward branches inside and around masked pixel regions: - Lowers pixel `SAVEEXEC`, `s_and_b64`, and `v_cmpx_` masked regions containing nested forward branches (nested SAVEEXEC, nested CMPX, or inner uniform scalar diamonds) using structured CFG lane branches (`branch_saves` / `lane_branches` / `multimap` `branch_merges`) instead of failing straight-line flattening. - Accepts external forward branches landing on a shared `restore.pc` when `exec_anchor` + `preserves_exec` proves the bypass edge already holds the parent EXEC mask (clearing inline CMPX predicates on the fallthrough predecessor before the join block so predicates never cross CFG edges). - Enforces strict pixel-arm invariants: refuses mid-arm interior entries, cross-arm/backward jumps, unproven EXEC writes inside `pixel_arms`, implicit-LOD/DPP/LDS/stores/atomics, saved-EXEC clobbers, and escaped arm scalars/mask tags. ### Verification - Built `compile_dxil`, `offscreen_check`, and `native_pixel_ir_dump` in Debug (`dev`) and Release (`release`) with zero new C++20 `/W4` warnings on edited lines. - `ctest --preset pr --no-tests=error --output-on-failure -R '^native_pixel_branch_masked_region_controls$'`: passed (**22 DXIL validations + 21 refusal checks**). - Debug (`dev`) and Release (`release`): 14/14 passed in each build, zero skips. - Real GPU readbacks on WARP (`10.0.26100.9818`) and NVIDIA GeForce RTX 5080 (`32.0.16.2140`) on Windows 11 (`26200.9974`): **22 exact 8×2 draws + 22 wrong-reference checks** passed per build/adapter. - `tests/bidi_controls_check.py`, `tests/docs_links_check.py`, and `git diff --check origin/main..HEAD` passed. - Opened as Draft under `#3514`'s 5-PR ready cap.
lukaslw-lab commented 2026-12-02 09:59:34 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed b8ec13a8 (draft) by reading the diff (core paths in full, the rest spot-checked) and running an offline pixel census of this PR alone; not otherwise built or run.

Verdict: approve. The structured lowering keeps every bypass edge tied to a proven parent EXEC, and every EXEC write or predicate that could cross an edge is refused. No MUST.

Census, f365f125 + this PR alone, same capture as #3814 (6,436 pixel stages): 272 translate on both builds, none lost, no validation failures. 1,377 stages change their first refusal (1,137 from graphics branch on a wave mask, 144 from branch enters a masked graphics region, 92 from lane-local arithmetic), but none reaches OK yet. Most (893) now stop at masked pixel arm has an unsupported exit or memory effect, and in a 120-stage sample that is an implicit-LOD image_sample (54), ds_swizzle_b32 (36) or image_atomic_umin (30) inside the arm. Those are correct refusals, so this PR clears the region structure and exposes the next wall.

  • NIT This conflicts with #3829, #3834, #3840, #3845, #3847 and #3848.
  • Checked, no finding:
    • Bypass edges: exec_anchor (:604) needs a copy that dominates every entry up to the point (no edge from before it or backwards) and preserves_exec on every path. Only then may an outer branch land on a shared restore (pixel_restore_edge, :627). An EXECZ inside a proven arm becomes br i1 false (:3286), which is sound because an invocation that reaches it in DXIL is in the guest EXEC.
    • Merges: branch_merges is now a multimap, and join_graphics folds every predicate at a pc into the control inputs (:1643), with a missing edge value ignored instead of throwing.
    • Arms: implicit-LOD images, DPP/DPP8, LDS, quad compares, mbcnt, stores and atomics are refused. Any EXEC write not recognised as a save, restore, complement, CMPX start or marker is refused (:1559). An inline CMPX predicate is cleared on the predecessor and refused if it reaches a block edge (:3273).
    • Pixel CMPX regions with a VCC capture now skip the masked-region pass (:1160). The census above shows no stage that translated on main is lost by it.
    • preserves_exec gains the wave32 copy/clobber rules and stops at s_endpgm, and wrexec clears EXEC knowledge.

Tests: _controls (22 validations, 21 refusals) is in the pr filter. The 22 draws with wrong-reference controls per adapter ran only locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6148569956 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3849#pullrequestreview-6148569956). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T09:59:34Z. **Review:** APPROVED --- Reviewed `b8ec13a8` (draft) by reading the diff (core paths in full, the rest spot-checked) and running an offline pixel census of this PR alone; not otherwise built or run. **Verdict: approve.** The structured lowering keeps every bypass edge tied to a proven parent EXEC, and every EXEC write or predicate that could cross an edge is refused. No MUST. Census, `f365f125` + this PR alone, same capture as #3814 (6,436 pixel stages): 272 translate on both builds, **none lost**, no validation failures. 1,377 stages change their first refusal (1,137 from `graphics branch on a wave mask`, 144 from `branch enters a masked graphics region`, 92 from lane-local arithmetic), but none reaches OK yet. Most (893) now stop at `masked pixel arm has an unsupported exit or memory effect`, and in a 120-stage sample that is an implicit-LOD `image_sample` (54), `ds_swizzle_b32` (36) or `image_atomic_umin` (30) inside the arm. Those are correct refusals, so this PR clears the region structure and exposes the next wall. - **NIT** This conflicts with #3829, #3834, #3840, #3845, #3847 and #3848. - Checked, no finding: - Bypass edges: `exec_anchor` (`:604`) needs a copy that dominates every entry up to the point (no edge from before it or backwards) and `preserves_exec` on every path. Only then may an outer branch land on a shared restore (`pixel_restore_edge`, `:627`). An EXECZ inside a proven arm becomes `br i1 false` (`:3286`), which is sound because an invocation that reaches it in DXIL is in the guest EXEC. - Merges: `branch_merges` is now a multimap, and `join_graphics` folds every predicate at a pc into the control inputs (`:1643`), with a missing edge value ignored instead of throwing. - Arms: implicit-LOD images, DPP/DPP8, LDS, quad compares, `mbcnt`, stores and atomics are refused. Any EXEC write not recognised as a save, restore, complement, CMPX start or marker is refused (`:1559`). An inline CMPX predicate is cleared on the predecessor and refused if it reaches a block edge (`:3273`). - Pixel CMPX regions with a VCC capture now skip the masked-region pass (`:1160`). The census above shows no stage that translated on `main` is lost by it. - `preserves_exec` gains the wave32 copy/clobber rules and stops at `s_endpgm`, and `wrexec` clears EXEC knowledge. Tests: `_controls` (22 validations, 21 refusals) is in the `pr` filter. The 22 draws with wrong-reference controls per adapter ran only locally.
timbot103 commented 2026-12-02 22:58:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T22:58:44Z.


Stacked on #3840. This branch includes #3840's commits; please land #3840 first.

f6a0b30e merges this PR onto #3840 as updated for main 67862ee4; the reviewed commit f5ccad25 is unchanged.

2816e59d fixes an interaction with #3840's arm-local scalar writes. Two invalid shaders were accepted: one overwrote the inner saved EXEC pair, and one read a scalar after the inner arm ended. Nested and shared CMPX restores now validate the saved EXEC pair and expire arm-local scalar writes the same way the standalone path does. Both shapes now refuse with specific diagnostics, and two refusal fixtures cover them.

Tests, Windows 11 26200 with RTX 5080 and WARP:

  • The pixel filter passed 42/42 in Debug and 42/42 in Release.
  • The PR preset passed 9/9.
  • This PR alone, merged onto 67862ee4, also passes its own three tests.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7361406092 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3849#issuecomment-7361406092). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T22:58:44Z. --- **Stacked on #3840.** This branch includes #3840's commits; please land #3840 first. `f6a0b30e` merges this PR onto #3840 as updated for main `67862ee4`; the reviewed commit `f5ccad25` is unchanged. `2816e59d` fixes an interaction with #3840's arm-local scalar writes. Two invalid shaders were accepted: one overwrote the inner saved EXEC pair, and one read a scalar after the inner arm ended. Nested and shared CMPX restores now validate the saved EXEC pair and expire arm-local scalar writes the same way the standalone path does. Both shapes now refuse with specific diagnostics, and two refusal fixtures cover them. Tests, Windows 11 26200 with RTX 5080 and WARP: - The pixel filter passed 42/42 in Debug and 42/42 in Release. - The PR preset passed 9/9. - This PR alone, merged onto `67862ee4`, also passes its own three tests.
timbot103 commented 2026-12-03 01:40:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-03T01:40:00Z.


Merged main (f3ab02fe) into this branch. The only conflict was the experiments index, where both entries are kept. It is still stacked on #3840, which is unchanged and Ready. The pixel filter passed 50/50 in Debug and 50/50 in Release, with 0 skips. The PR preset passed 9/9. A full Debug build of every target, including the C++17 native_compute_pack_refusal_check, succeeded.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7364598297 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3849#issuecomment-7364598297). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-03T01:40:00Z. --- Merged `main` (`f3ab02fe`) into this branch. The only conflict was the experiments index, where both entries are kept. It is still stacked on #3840, which is unchanged and Ready. The pixel filter passed 50/50 in Debug and 50/50 in Release, with 0 skips. The PR preset passed 9/9. A full Debug build of every target, including the C++17 `native_compute_pack_refusal_check`, succeeded.
timbot103 commented 2026-12-03 05:53:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-03T05:53:16Z.


No longer stacked: #3840 has merged. Merged main (8a2f84d1) into this branch. The resolution keeps main's #3840 fixture, compare-mask expiry and VCC skip handling alongside this PR's structured-arm and saved-EXEC checks. The diff against main now contains only this PR's five files. native_pixel_|native_graphics_|native_direct_container passed 63/63 in Debug and 63/63 in Release, with 0 skips (23 WARP and 20 RTX 5080 tests per configuration). The PR preset passed 1/1, and a full Debug build including the C++17 native_compute_pack_refusal_check succeeded. Marked Ready for review, keeping within 5 non-draft PRs per #3514.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7369221593 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3849#issuecomment-7369221593). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-03T05:53:16Z. --- No longer stacked: #3840 has merged. Merged `main` (`8a2f84d1`) into this branch. The resolution keeps main's #3840 fixture, compare-mask expiry and VCC skip handling alongside this PR's structured-arm and saved-EXEC checks. The diff against `main` now contains only this PR's five files. `native_pixel_|native_graphics_|native_direct_container` passed 63/63 in Debug and 63/63 in Release, with 0 skips (23 WARP and 20 RTX 5080 tests per configuration). The PR preset passed 1/1, and a full Debug build including the C++17 `native_compute_pack_refusal_check` succeeded. Marked Ready for review, keeping within 5 non-draft PRs per #3514.
R0Y00 commented 2026-12-03 06:28:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T06:28:35Z.

Review: APPROVED


Independently reviewed 13367a04. MSVC Debug on Windows 11 build 26300: branch_masked_region, masked_region_alu and varying_vcc_branch controls and GPU tests passed 9/9. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, debug layer enabled, zero skips. Inverting the structured CMPX comparison in a temporary build made nested-cmpx-flat fail on both backends (8 of 16 pixels differed). Removing either the local EXEC-preservation check or the structured-arm saved-EXEC overlap check in isolation was not distinguished by these controls. Source-built fixtures throughout.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6164727953 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3849#pullrequestreview-6164727953). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T06:28:35Z. **Review:** APPROVED --- Independently reviewed 13367a04. MSVC Debug on Windows 11 build 26300: branch_masked_region, masked_region_alu and varying_vcc_branch controls and GPU tests passed 9/9. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, debug layer enabled, zero skips. Inverting the structured CMPX comparison in a temporary build made nested-cmpx-flat fail on both backends (8 of 16 pixels differed). Removing either the local EXEC-preservation check or the structured-arm saved-EXEC overlap check in isolation was not distinguished by these controls. Source-built fixtures throughout.
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!3849
No description provided.