shader: join pending loads at masked arm boundaries #1981

Merged
avt0m4t48 merged 1 commit from upstream-pr/1988 into main 2026-11-24 22:46:53 +00:00
avt0m4t48 commented 2026-11-24 22:38:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by avt0m4t48 on 2026-11-24T22:38:07Z.


Refs #987. Track pending loads at the start of each masked arm. When an arm can skip its wait, carry the outstanding loads from that arm's incoming state into the join. This covers a load issued in THEN whose wait can be skipped in ELSE, and avoids reinstating pending loads that an unconditional ELSE wait already resolved.

The old translator reproduced both errors with both region openers. The offline and LLVM 15 binary suites passed. Four source-built binaries round-tripped, and all eight variants that drop or delay the wait were rejected. DXC compiled the four generated pixel shaders. A local Vulkan compute wrapper around their emitted bodies used synthetic ramp samples and matched all 768 lane outputs on Lavapipe. Eight deliberately wrong mask cases mismatched.

The patch adds the fixtures to the existing WARP and hardware draw test route. Those D3D12 readbacks remain unverified here. Documentation links, bidi scan and git diff --check passed. AI-assisted using Codex. Source-built inputs only.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6592817167 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1988). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-24T22:38:07Z. --- Refs #987. Track pending loads at the start of each masked arm. When an arm can skip its wait, carry the outstanding loads from that arm's incoming state into the join. This covers a load issued in THEN whose wait can be skipped in ELSE, and avoids reinstating pending loads that an unconditional ELSE wait already resolved. The old translator reproduced both errors with both region openers. The offline and LLVM 15 binary suites passed. Four source-built binaries round-tripped, and all eight variants that drop or delay the wait were rejected. DXC compiled the four generated pixel shaders. A local Vulkan compute wrapper around their emitted bodies used synthetic ramp samples and matched all 768 lane outputs on Lavapipe. Eight deliberately wrong mask cases mismatched. The patch adds the fixtures to the existing WARP and hardware draw test route. Those D3D12 readbacks remain unverified here. Documentation links, bidi scan and `git diff --check` passed. AI-assisted using Codex. Source-built inputs only.
upstream-sync closed this pull request 2026-11-24 23:03:27 +00:00
tedin7 commented 2026-11-24 23:03:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:46:01Z.

Review: COMMENTED


Review of head 05ef4d9293.

Result: 0 P1, 0 P2.

Reading: the masked if/else lowering now keeps the outstanding-load state per arm (arm_outstanding). It is refreshed at the else transition and joined at the restore only when the last arm has a skip. The scc opener never carries a skip, because the skip target must match a saved exec pair, so dropping its state is safe. The change touches only tools/pixel_aot.py, tests/pixel_aot_check.py and docs/experiments.md. No CMake change, no new dependency. The new code is a lowering fix with tests written from the ISA behaviour, so nothing is copied from elsewhere.

Commands run locally:

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts
  • python3 tests/docs_links_check.py: PASS (18 files, 387 links)
  • python3 tests/bidi_controls_check.py: PASS
  • git diff --check origin/main...HEAD: PASS
  • python3 -B tests/pixel_aot_check.py (full controls, Linux): PASS
  • Win2025 (x2w_pipe.py win2025 1988, ^pixel_aot_region_scalar_load_(warp|hardware)$): Debug 2/2 pass, Release /O2 2/2 pass, tests/pixel_aot_check.py ok
  • GitHub CI: Windows build/test, Linux Python checks and gfx1013 fixtures pass

Mutations, each reverted with git checkout -- .:

  1. Disabled the join at close (if region["skip"] is not None: replaced by if False:). Killed by check_region_wait_controls.
  2. Removed the arm_outstanding refresh at the else transition. Killed by the new check_region_else_wait_controls.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048586767 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1988#pullrequestreview-6048586767). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T22:46:01Z. **Review:** COMMENTED --- Review of head 05ef4d92932adb5d6864f20c113a6274991c0618. Result: 0 P1, 0 P2. Reading: the masked if/else lowering now keeps the outstanding-load state per arm (`arm_outstanding`). It is refreshed at the else transition and joined at the restore only when the last arm has a skip. The scc opener never carries a skip, because the skip target must match a saved exec pair, so dropping its state is safe. The change touches only `tools/pixel_aot.py`, `tests/pixel_aot_check.py` and `docs/experiments.md`. No CMake change, no new dependency. The new code is a lowering fix with tests written from the ISA behaviour, so nothing is copied from elsewhere. Commands run locally: - `git merge-tree --write-tree --name-only origin/main HEAD`: clean, no conflicts - `python3 tests/docs_links_check.py`: PASS (18 files, 387 links) - `python3 tests/bidi_controls_check.py`: PASS - `git diff --check origin/main...HEAD`: PASS - `python3 -B tests/pixel_aot_check.py` (full controls, Linux): PASS - Win2025 (`x2w_pipe.py win2025 1988`, `^pixel_aot_region_scalar_load_(warp|hardware)$`): Debug 2/2 pass, Release /O2 2/2 pass, `tests/pixel_aot_check.py` ok - GitHub CI: Windows build/test, Linux Python checks and gfx1013 fixtures pass Mutations, each reverted with `git checkout -- .`: 1. Disabled the join at close (`if region["skip"] is not None:` replaced by `if False:`). Killed by `check_region_wait_controls`. 2. Removed the `arm_outstanding` refresh at the else transition. Killed by the new `check_region_else_wait_controls`. AI-assisted; commands listed were executed locally.
ChazY11 commented 2026-11-24 23:03:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T22:46:56Z.


Ran it and broke the join four ways — all caught

Windows 11 build 26300.9974, device-free path:

out/pe-env/Scripts/python.exe -B tests/pixel_aot_check.py      # exit 0

Mutations to tools/pixel_aot.py, each reverted:

mutation result
back to the old predicate region.get("skipped") caught
join with an empty state instead of region["arm_outstanding"] caught
never record arm_outstanding (always empty) caught
record arm_outstanding but never use it (if False:) caught

The third and fourth are the pair worth having: one breaks the data, the other keeps the data but drops the decision, and a fixture that only checked "the emitted HLSL compiles" would pass both. Yours fails both.

What the change is doing, restated so a reader can check me

The old code reinstated the region's pre-opener outstanding state after a skip, which is right when the whole region skipped and wrong when only the final arm skipped:

old:  if region["skipped"]:  before = region["outstanding"]        # pre-opener snapshot
new:  if region["skip"] is not None:  before = region["arm_outstanding"]   # that arm's incoming state

Moving the snapshot from the region to each arm is what fixes both symptoms in the description — a load issued in THEN whose wait is skipped in
ELSE now survives the join, and an ELSE that did wait unconditionally no longer has its resolved loads reinstated. Those are the same defect
seen from two directions, and the mutation table above exercises both because the join is the single place either can go wrong.

On the verification in the description

The eight deliberately wrong mask cases and the Lavapipe run (768 lane outputs) are the strongest part: a synthetic ramp through the emitted
bodies checks the values, not the text. I did not reproduce that here — no Vulkan wrapper in this environment — so what I can attest to is the
Python-level join behaviour and that the offline suite covers it.

The D3D12 readbacks added to the WARP and hardware routes did not run for me either (they need the draw route built); the description lists them
as unverified, which is accurate.

One question, not a defect

region["arm_outstanding"] is written at the end of every arm in the loop, including arms whose wait always ran. For those, the recorded state
equals the incoming state, so the join is a no-op — correct, but it means the name covers two meanings: "what this arm left outstanding" and
"what the join should carry". If that ever needs splitting, the unconditional-wait arm is the one to look at.

Verdict

Reviewed. Four independent ways to break the join, four failures; the value-level harness in the description covers what the text checks cannot.

Notes

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146637766 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1988#issuecomment-7146637766). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T22:46:56Z. --- ## Ran it and broke the join four ways — all caught Windows 11 build 26300.9974, device-free path: ```powershell out/pe-env/Scripts/python.exe -B tests/pixel_aot_check.py # exit 0 ``` Mutations to `tools/pixel_aot.py`, each reverted: | mutation | result | |---|---| | back to the old predicate `region.get("skipped")` | **caught** | | join with an empty state instead of `region["arm_outstanding"]` | **caught** | | never record `arm_outstanding` (always empty) | **caught** | | record `arm_outstanding` but never use it (`if False:`) | **caught** | The third and fourth are the pair worth having: one breaks the data, the other keeps the data but drops the decision, and a fixture that only checked "the emitted HLSL compiles" would pass both. Yours fails both. ## What the change is doing, restated so a reader can check me The old code reinstated the *region's* pre-opener outstanding state after a skip, which is right when the whole region skipped and wrong when only the final arm skipped: ```text old: if region["skipped"]: before = region["outstanding"] # pre-opener snapshot new: if region["skip"] is not None: before = region["arm_outstanding"] # that arm's incoming state ``` Moving the snapshot from the region to each arm is what fixes both symptoms in the description — a load issued in THEN whose wait is skipped in ELSE now survives the join, and an ELSE that did wait unconditionally no longer has its resolved loads reinstated. Those are the same defect seen from two directions, and the mutation table above exercises both because the join is the single place either can go wrong. ## On the verification in the description The eight deliberately wrong mask cases and the Lavapipe run (768 lane outputs) are the strongest part: a synthetic ramp through the emitted bodies checks the *values*, not the text. I did not reproduce that here — no Vulkan wrapper in this environment — so what I can attest to is the Python-level join behaviour and that the offline suite covers it. The D3D12 readbacks added to the WARP and hardware routes did not run for me either (they need the draw route built); the description lists them as unverified, which is accurate. ## One question, not a defect `region["arm_outstanding"]` is written at the end of every arm in the loop, including arms whose wait always ran. For those, the recorded state equals the incoming state, so the join is a no-op — correct, but it means the name covers two meanings: "what this arm left outstanding" and "what the join should carry". If that ever needs splitting, the unconditional-wait arm is the one to look at. ## Verdict Reviewed. Four independent ways to break the join, four failures; the value-level harness in the description covers what the text checks cannot. ## Notes - AI-assisted review.
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!1981
No description provided.