shader: intersect definitions at joins in the pixel input mask scan #2790

Merged
RenzoWit35 merged 1 commit from upstream-pr/2798 into main 2026-11-26 10:17:31 +00:00
RenzoWit35 commented 2026-11-26 10:11:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-26T10:11:44Z.


Follow-up to #1669, for the branch-skipped definition reported in its review. In that case a forward conditional branch skips a write to v2, and the join then reads v2. The scanner reported v2 as neither live-in nor ambiguous, so a mask without v2 could rank as consistent. #1669 was merged before this fix was pushed, so it comes as a separate PR.

Change

tools/startup/ps_input_scan.py:

  • must_defined() computes, for each instruction, the vector registers written on every path from the entry. It is a forward fixpoint over bit sets that intersects the incoming edges at each join. s_endpgm and s_branch do not fall through. A branch with an unknown target joins every instruction. Code that no path reaches keeps the previous linear rule.
  • A read is a first read if the register is not written earlier in program order, or is not written on every path to the read. The new rule can only add first reads, never remove them.
  • The loop rule is unchanged: inside a backward span, a register written later in program order is still ambiguous and does not vote. Alias and I/J evidence still need a register that no path has written.
  • branch_of() factors out the branch decoding that control_flow() already did.

tests/startup_ps_input_scan_check.py:

  • diamond_skip skips the v2 write; its live-in set is [1, 2]. diamond_both writes v2 on both edges; its live-in set is [1].
  • A decoy mask without v2 must fail C1, both in the unit check and end to end. In a corpus where the decoy sits at header +16/+20, ps.header pair32@8 must stay the unique full match.
  • alias_block has the same shape (a forward branch skips v_mov_b32 v4, v0), so its expected live-in set becomes [0, 1, 4]. Its pair evidence was already dropped and still is.
  • Table cases with literal values for the two mutations from the #1669 review:
    • The I/J pair start bits 0, 1, 2, 4, 5 and 6 (and none of the other ten), through both consistent() and the cached Judge path.
    • The exact enable/address words that tag_values() returns for context-run, context-index, byte-address and mm tags.

docs/experiments.md describes the join rule.

Unchanged: mask agreement and packed-position agreement are reported apart, and packed agreement does not vote. Output is aggregates only. No runtime code is touched.

Verification

Environment: Windows 11, Python 3.14.5, branch cut from current main.

  • python -B tests/startup_ps_input_scan_check.py: ps_input_scan checks passed.
  • Negative control: the same check against the scanner on main fails with AssertionError: ('alias_block', ([0, 1], [], [])). Before alias_block was updated, the standalone diamond corpus gave verdict: unique full match ps.header pair32@16: the decoy won, with 8 tight against 7.
  • Mutations that the check now catches: dropping bit 6 from PAIR_BITS, setting CONTEXT_INDEX['ena'] to 0x1B4, and replacing must_defined() with "everything defined".
  • The workflow's run_checks_parallel.py list (203 checks) on this branch: everything passes except tests/dxc_cache_check.py. That one fails in a subprocess.run of its DXC stub on this Windows machine, and this PR does not touch DXC or the stub.

Not run: the Linux job. The change is pure Python with no path or platform handling.

Evidence and follow-up

Limitation: a read on a path that never runs, such as a lane-masked read of an undefined register, now counts as live-in. That can make the right location fail C1, but it cannot make a mask without that register pass.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6624340148 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2798). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-26T10:11:44Z. --- Follow-up to #1669, for the branch-skipped definition reported in its review. In that case a forward conditional branch skips a write to v2, and the join then reads v2. The scanner reported v2 as neither live-in nor ambiguous, so a mask without v2 could rank as consistent. #1669 was merged before this fix was pushed, so it comes as a separate PR. ## Change `tools/startup/ps_input_scan.py`: - `must_defined()` computes, for each instruction, the vector registers written on every path from the entry. It is a forward fixpoint over bit sets that intersects the incoming edges at each join. `s_endpgm` and `s_branch` do not fall through. A branch with an unknown target joins every instruction. Code that no path reaches keeps the previous linear rule. - A read is a first read if the register is not written earlier in program order, or is not written on every path to the read. The new rule can only add first reads, never remove them. - The loop rule is unchanged: inside a backward span, a register written later in program order is still ambiguous and does not vote. Alias and I/J evidence still need a register that no path has written. - `branch_of()` factors out the branch decoding that `control_flow()` already did. `tests/startup_ps_input_scan_check.py`: - `diamond_skip` skips the v2 write; its live-in set is `[1, 2]`. `diamond_both` writes v2 on both edges; its live-in set is `[1]`. - A decoy mask without v2 must fail C1, both in the unit check and end to end. In a corpus where the decoy sits at header +16/+20, `ps.header pair32@8` must stay the unique full match. - `alias_block` has the same shape (a forward branch skips `v_mov_b32 v4, v0`), so its expected live-in set becomes `[0, 1, 4]`. Its pair evidence was already dropped and still is. - Table cases with literal values for the two mutations from the #1669 review: - The I/J pair start bits 0, 1, 2, 4, 5 and 6 (and none of the other ten), through both `consistent()` and the cached `Judge` path. - The exact enable/address words that `tag_values()` returns for context-run, context-index, byte-address and mm tags. `docs/experiments.md` describes the join rule. Unchanged: mask agreement and packed-position agreement are reported apart, and packed agreement does not vote. Output is aggregates only. No runtime code is touched. ## Verification Environment: Windows 11, Python 3.14.5, branch cut from current `main`. - `python -B tests/startup_ps_input_scan_check.py`: `ps_input_scan checks passed`. - Negative control: the same check against the scanner on `main` fails with `AssertionError: ('alias_block', ([0, 1], [], []))`. Before `alias_block` was updated, the standalone diamond corpus gave `verdict: unique full match ps.header pair32@16`: the decoy won, with 8 tight against 7. - Mutations that the check now catches: dropping bit 6 from `PAIR_BITS`, setting `CONTEXT_INDEX['ena']` to 0x1B4, and replacing `must_defined()` with "everything defined". - The workflow's `run_checks_parallel.py` list (203 checks) on this branch: everything passes except `tests/dxc_cache_check.py`. That one fails in a `subprocess.run` of its DXC stub on this Windows machine, and this PR does not touch DXC or the stub. Not run: the Linux job. The change is pure Python with no path or platform handling. ## Evidence and follow-up Limitation: a read on a path that never runs, such as a lane-masked read of an undefined register, now counts as live-in. That can make the right location fail C1, but it cannot make a mask without that register pass. AI-assisted.
upstream-sync closed this pull request 2026-11-26 11:02:51 +00:00
tedin7 commented 2026-11-26 11:02:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:16:12Z.

Review: COMMENTED


Review of head 8d97c0ca against origin/main. Verdict: sound, no blocking findings.

What I checked

  • must_defined() is a forward must-analysis: intersect at joins, entry state empty, s_endpgm/s_branch do not fall through, unknown-target branches join everywhere, unreachable code keeps -1 so the old linear rule stays in charge. The sets only lose bits, so the loop ends.
  • The new read rule only adds first reads (not written OR not defined on every path), and the loop/ambiguous rule is unchanged. That matches the PR text.
  • control_flow() now reuses branch_of() and gives the same targets, spans and unknown as before.
  • The change is Python only (scanner, its check, docs). It does not touch gfx2hlsl.py, the generated HLSL or the pixel inputs, so no D3D12 readback test is needed.

Commands run (Linux worktree at this head)

  • python3 tests/startup_ps_input_scan_check.py -> passes
  • python3 tests/docs_links_check.py -> passes; python3 tests/bidi_controls_check.py -> passes
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: drop the not everywhere >> register & 1 clause -> check fails (AssertionError)
  • Mutation 2: value &= out[p] changed to |= (union instead of intersection) -> check fails (AssertionError)
  • Both mutations reverted afterwards.

Not done by this review: the Windows run (pending, will be posted as a receipt) and CI on this head was still pending when I looked.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6072240060 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2798#pullrequestreview-6072240060). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:16:12Z. **Review:** COMMENTED --- Review of head 8d97c0ca against origin/main. Verdict: sound, no blocking findings. What I checked - `must_defined()` is a forward must-analysis: intersect at joins, entry state empty, `s_endpgm`/`s_branch` do not fall through, unknown-target branches join everywhere, unreachable code keeps -1 so the old linear rule stays in charge. The sets only lose bits, so the loop ends. - The new read rule only adds first reads (`not written` OR `not defined on every path`), and the loop/ambiguous rule is unchanged. That matches the PR text. - `control_flow()` now reuses `branch_of()` and gives the same targets, spans and `unknown` as before. - The change is Python only (scanner, its check, docs). It does not touch `gfx2hlsl.py`, the generated HLSL or the pixel inputs, so no D3D12 readback test is needed. Commands run (Linux worktree at this head) - `python3 tests/startup_ps_input_scan_check.py` -> passes - `python3 tests/docs_links_check.py` -> passes; `python3 tests/bidi_controls_check.py` -> passes - `git diff --check origin/main...HEAD` -> clean - Mutation 1: drop the `not everywhere >> register & 1` clause -> check fails (AssertionError) - Mutation 2: `value &= out[p]` changed to `|=` (union instead of intersection) -> check fails (AssertionError) - Both mutations reverted afterwards. Not done by this review: the Windows run (pending, will be posted as a receipt) and CI on this head was still pending when I looked. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 11:02:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:16:41Z.


Win2025 WARP receipt for head 8d97c0ca (Python-only change: the pipeline builds nothing for these files).

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 8d97c0ca1b70886fec7917e39cc28e30c5477477:

  • Windows Python checks: tests/startup_ps_input_scan_check.py ok (7.3s)
  • Wall: 12.5s

Command: x2w_pipe.py win2025 2798 --wait 7200 --keep-release --py-checks tests/startup_ps_input_scan_check.py (log line PYCHECK name=tests/startup_ps_input_scan_check.py rc=0).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189149494 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2798#issuecomment-7189149494). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:16:41Z. --- Win2025 WARP receipt for head 8d97c0ca (Python-only change: the pipeline builds nothing for these files). Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `8d97c0ca1b70886fec7917e39cc28e30c5477477`: - **Windows Python checks**: `tests/startup_ps_input_scan_check.py` ok (`7.3s`) - Wall: `12.5s` Command: `x2w_pipe.py win2025 2798 --wait 7200 --keep-release --py-checks tests/startup_ps_input_scan_check.py` (log line `PYCHECK name=tests/startup_ps_input_scan_check.py rc=0`). AI-assisted; commands listed were executed locally.
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!2790
No description provided.