shader: settle copy propagation when phis oscillate #54

Manually merged
github merged 3 commits from gh-pr/54/head into gh-pr/54/base 2026-11-26 14:44:12 +00:00
Owner

@⁠Sandile-0511 on GitHub · 2026-11-26 11:35 UTC · original
Sandile-0511:fix/copy-propagation-settles → main · +71 −3 · 2 files · 3 commits · merged 2026-11-26 12:57 UTC

What this changes

Every run of the title logged 22 pixel pieces refused with GFX10 code at 0x0: copies that do not settle. Tracer::propagate_copies is an optimistic fixpoint, and its phi rule is not monotone: a phi whose arguments are all copies of one value can see them disagree within a sweep, stand for itself for one sweep, then return to the copy. When such phis feed each other across nested loops the sweeps cycle (period 3 in the reproduction), so raising MAX_ROUNDS would not help.

The first MAX_ROUNDS sweeps are unchanged, so every program that settles today gets the same result. After that, a phi that still changes is pinned to stand for itself, as a real join does. That loses copy information for those phis but never names a wrong origin. The loop is bounded and the old error stays as a backstop.

The reproducing shape is a register saved to a second register and restored inside an inner loop, inside a loop whose entry value is itself an outer loop's phi. That the 22 real pieces have this shape is a guess; I did not inspect them.

How it was tested

  • cargo test -p victory-shader: 220 passed, 0 failed, 2 ignored. New test resource::tests::copies_restored_in_nested_loops_settle (13 hand-assembled instructions); it failed before the change with exactly Unsupported { offset: 0, what: "copies that do not settle" }.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings (clean, run on a Mac)
  • cargo xtask policy (365 files ok)
  • Ran the game in a combined local build: the 22 "copies that do not settle" warnings no longer appear. Whether those pieces then translate fully or stop at a later refusal was not checked one by one.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none made about the console)
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
**@⁠Sandile-0511** on GitHub · 2026-11-26 11:35 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/54) `Sandile-0511:fix/copy-propagation-settles` → `main` · +71 −3 · 2 files · 3 commits · merged 2026-11-26 12:57 UTC ## What this changes Every run of the title logged 22 pixel pieces refused with `GFX10 code at 0x0: copies that do not settle`. `Tracer::propagate_copies` is an optimistic fixpoint, and its phi rule is not monotone: a phi whose arguments are all copies of one value can see them disagree within a sweep, stand for itself for one sweep, then return to the copy. When such phis feed each other across nested loops the sweeps cycle (period 3 in the reproduction), so raising `MAX_ROUNDS` would not help. The first `MAX_ROUNDS` sweeps are unchanged, so every program that settles today gets the same result. After that, a phi that still changes is pinned to stand for itself, as a real join does. That loses copy information for those phis but never names a wrong origin. The loop is bounded and the old error stays as a backstop. The reproducing shape is a register saved to a second register and restored inside an inner loop, inside a loop whose entry value is itself an outer loop's phi. That the 22 real pieces have this shape is a guess; I did not inspect them. ## How it was tested - [x] `cargo test -p victory-shader`: 220 passed, 0 failed, 2 ignored. New test `resource::tests::copies_restored_in_nested_loops_settle` (13 hand-assembled instructions); it failed before the change with exactly `Unsupported { offset: 0, what: "copies that do not settle" }`. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` (clean, run on a Mac) - [x] `cargo xtask policy` (365 files ok) - [x] Ran the game in a combined local build: the 22 "copies that do not settle" warnings no longer appear. Whether those pieces then translate fully or stop at a later refusal was not checked one by one. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none made about the console) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:44:10 +00:00
github manually merged commit d517508a4f into gh-pr/54/base 2026-11-26 14:44:12 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 11:51 UTC · original · requested changes

The nested-loop test reproduces copies that do not settle on main and passes here. Please add a short note to docs/native-host.md explaining that the fallback keeps unsettled phis as joins and can retain less copy information.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 11:51 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/54#pullrequestreview-6073656459) · **requested changes** The nested-loop test reproduces `copies that do not settle` on main and passes here. Please add a short note to `docs/native-host.md` explaining that the fallback keeps unsettled phis as joins and can retain less copy information.
Author
Owner

@⁠Sandile-0511 on GitHub · 2026-11-26 12:30 UTC · original

Added a "Copy propagation that does not settle" note to the translator list in docs/native-host.md: after MAX_ROUNDS sweeps a phi that still changes is kept as a join, which never names a wrong origin but can retain less copy information, so something traced through it may be refused later. Programs that settle within MAX_ROUNDS are unaffected.

**@⁠Sandile-0511** on GitHub · 2026-11-26 12:30 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/54#issuecomment-7192093151) Added a "Copy propagation that does not settle" note to the translator list in `docs/native-host.md`: after `MAX_ROUNDS` sweeps a phi that still changes is kept as a join, which never names a wrong origin but can retain less copy information, so something traced through it may be refused later. Programs that settle within `MAX_ROUNDS` are unaffected.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 12:48 UTC · original · approved these changes

Thanks, the earlier requests are addressed and the checks pass (tests incl. Metal, Windows clippy, policy). Approved.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/54#pullrequestreview-6074381736) · **approved these changes** Thanks, the earlier requests are addressed and the checks pass (tests incl. Metal, Windows clippy, policy). Approved.
This discussion has been locked. Commenting is limited to contributors.
No description provided.