shader: a phi read only through another phi keeps its missing incoming value #699

Closed
arthercz wants to merge 4 commits from upstream-pr/699 into main
arthercz commented 2026-11-24 07:02:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by arthercz on 2026-11-24T07:02:26Z.


Closes #604.

The emitter refused a branch on a live s_memtime read but accepted the same read through two conditional joins: fill_phis substitutes zero for a missing incoming value of a phi no reader marks, and Lower::get marked only the phi a comparison reads directly. A phi whose value flows solely into another phi's arguments was never marked, so its missing timestamp value silently became zero instead of surfacing the refusal the direct read gets.

The fix follows incoming phi dependencies from the phis actual readers mark (fixpoint) before the substitution decision. A dead phi (read by nothing live) still lowers with the zero substitution, matching the issue's expectation.

The regression test is Dathinel's probe from the issue (test-only commit 4b2ea70f), applied unmodified; it compares the direct and the twice-joined read and expects the dead-timestamp variant to keep lowering.

Verified: cargo test -p victory-shader --features host a_missing_value_stays_missing_through_two_live_joins passes; cargo test --workspace 266 passed; cargo clippy --workspace --all-features clean.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6576488940 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/699). Originally posted by [arthercz](https://github.com/arthercz) on 2026-11-24T07:02:26Z. --- Closes #604. The emitter refused a branch on a live `s_memtime` read but accepted the same read through two conditional joins: `fill_phis` substitutes zero for a missing incoming value of a phi no reader marks, and `Lower::get` marked only the phi a comparison reads directly. A phi whose value flows solely into another phi's arguments was never marked, so its missing timestamp value silently became zero instead of surfacing the refusal the direct read gets. The fix follows incoming phi dependencies from the phis actual readers mark (fixpoint) before the substitution decision. A dead phi (read by nothing live) still lowers with the zero substitution, matching the issue's expectation. The regression test is Dathinel's probe from the issue ([test-only commit 4b2ea70f](https://github.com/Dathinel/VIctory/commit/4b2ea70f0940a4317dc934000d249dce0fce50f6)), applied unmodified; it compares the direct and the twice-joined read and expects the dead-timestamp variant to keep lowering. Verified: `cargo test -p victory-shader --features host a_missing_value_stays_missing_through_two_live_joins` passes; `cargo test --workspace` 266 passed; `cargo clippy --workspace --all-features` clean.
LAKSHYA-cmd-tech commented 2026-11-24 08:02:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T07:16:33Z.

Review: APPROVED


Tested on Windows 11 MSVC (rustc 1.98.1):

  • cargo test -p victory-shader: 70 passed, 0 failed (including emit::lower::tests::a_missing_value_stays_missing_through_two_live_joins)
  • cargo xtask policy: 151 files ok

Fixpoint propagation correctly ensures phis whose values flow exclusively into subsequent join phis retain their missing incoming status rather than erroneously substituting zero.

<!-- greyfinch-sync:Marvisak/VIctory:review:6035137726 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/699#pullrequestreview-6035137726). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T07:16:33Z. **Review:** APPROVED --- Tested on Windows 11 MSVC (rustc 1.98.1): - cargo test -p victory-shader: 70 passed, 0 failed (including emit::lower::tests::a_missing_value_stays_missing_through_two_live_joins) - cargo xtask policy: 151 files ok Fixpoint propagation correctly ensures phis whose values flow exclusively into subsequent join phis retain their missing incoming status rather than erroneously substituting zero.
catminou4 commented 2026-11-24 09:05:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T08:05:05Z.

Review: COMMENTED


Heads-up on the branch shape: this PR's diff against main includes #692's fmt commit, #691's WinRT speech commit, and a WARP opt-out commit — only the tip commit db0257e ("shader: a phi read only through another phi…") is this PR's own change. That's why it's unmergeable/conflicting as-is. Retargeting the base or rebasing onto main after #691/#692 land would make the actual change reviewable.

Reviewed the tip commit itself (52+/7- in emit/lower.rs):

  • fill_phis now transitively propagates "read" from read_phis through phi incoming args, so a phi consumed only by another phi is treated as read — a missing incoming value now raises Stop::Retry instead of being zero-substituted on its way to a live read. Dead phis keep the zero substitution. The comment explains exactly this.
  • The synthetic compute-program tests (lowers gained an rsrc2 parameter) exercise the branch-on-live-timestamp-read path.

Verification on macOS 26 arm64, rustc 1.98.1: cargo test -p victory-shader --locked on the head: 57 passed / 0 failed (against its own base). The change is in the portable lowering path, so this is real coverage; the GPU-visible outcome still needs the Windows shader run.

<!-- greyfinch-sync:Marvisak/VIctory:review:6035646454 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/699#pullrequestreview-6035646454). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T08:05:05Z. **Review:** COMMENTED --- Heads-up on the branch shape: this PR's diff against `main` includes #692's fmt commit, #691's WinRT speech commit, and a WARP opt-out commit — only the tip commit `db0257e` ("shader: a phi read only through another phi…") is this PR's own change. That's why it's unmergeable/conflicting as-is. Retargeting the base or rebasing onto main after #691/#692 land would make the actual change reviewable. Reviewed the tip commit itself (52+/7- in `emit/lower.rs`): - `fill_phis` now transitively propagates "read" from `read_phis` through phi incoming args, so a phi consumed only by another phi is treated as read — a missing incoming value now raises `Stop::Retry` instead of being zero-substituted on its way to a live read. Dead phis keep the zero substitution. The comment explains exactly this. - The synthetic compute-program tests (`lowers` gained an `rsrc2` parameter) exercise the branch-on-live-timestamp-read path. Verification on macOS 26 arm64, rustc 1.98.1: `cargo test -p victory-shader --locked` on the head: **57 passed / 0 failed** (against its own base). The change is in the portable lowering path, so this is real coverage; the GPU-visible outcome still needs the Windows shader run.
iurysf commented 2026-11-24 09:06:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T08:16:39Z.


Measured offline against main c2e7254 with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17, comparing outcomes program by program:

failed rejected by validator validated
main 3,734 185 21,983
main + this PR 4,067 (+333) 175 21,660 (−323)
  • No program is fixed. 323 programs that emitted and validated on main now fail, and 10 previously rejected ones now fail too. Their new refusals are mostly "a descriptor read only as data" (227), then "a scalar memory read as data" (32), "a structured buffer of unknown stride" (23), "the first half of an interpolation" (20) and "a lane mask read as data" (17).
  • So following phi dependencies to a fixpoint marks many more phis as read, and their missing incoming values (zero-substituted on main) now surface as other refusals, well beyond the s_memtime case in #604.
  • Some of those zeroes may be wrong in the same silent way as the timestamp. Still, losing 323 working programs is a large in-game cost. Could the stricter marking be limited to the value kinds where a zero is known to be wrong (timestamps), or applied only when the missing edge carries such a value?

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125938926 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/699#issuecomment-7125938926). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-24T08:16:39Z. --- Measured offline against main `c2e7254` with `victory translate --list --validate` over the title's `shaders.rpf` + executable (26,096 programs), dxil.dll 1.9.2602.17, comparing outcomes program by program: | | failed | rejected by validator | validated | |---|---:|---:|---:| | main | 3,734 | 185 | 21,983 | | main + this PR | **4,067 (+333)** | 175 | **21,660 (−323)** | - No program is fixed. **323 programs that emitted and validated on main now fail**, and 10 previously rejected ones now fail too. Their new refusals are mostly "a descriptor read only as data" (227), then "a scalar memory read as data" (32), "a structured buffer of unknown stride" (23), "the first half of an interpolation" (20) and "a lane mask read as data" (17). - So following phi dependencies to a fixpoint marks many more phis as read, and their missing incoming values (zero-substituted on main) now surface as other refusals, well beyond the `s_memtime` case in #604. - Some of those zeroes may be wrong in the same silent way as the timestamp. Still, losing 323 working programs is a large in-game cost. Could the stricter marking be limited to the value kinds where a zero is known to be wrong (timestamps), or applied only when the missing edge carries such a value? AI-assisted.
slint6614-dev commented 2026-11-24 10:03:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T09:30:31Z.


Measured on the full retail shader pack (26,503 containers) with victory translate --validate --pipelines (pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines.

This PR conflicts with current main (lower.rs), so it was measured on its own base against main 1f858b0, which predates #612 (VS/PS 12272 / 12172, CS 1693 / 1670, MS 8191 / 8129).

With this PR: VS/PS 12220 / 12130, CS 1440 / 1417, MS 8163 / 8101. That is the same loss of 323 validated programs (42 VS/PS, 253 CS, 28 MS) as the merged #612 shows (see my measurement there), with the same refusal reasons. So it fixes #604 the same way, but it now duplicates #612.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7127511551 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/699#issuecomment-7127511551). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T09:30:31Z. --- Measured on the full retail shader pack (26,503 containers) with `victory translate --validate --pipelines` (pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. This PR conflicts with current main (`lower.rs`), so it was measured on its own base against main 1f858b0, which predates #612 (VS/PS 12272 / 12172, CS 1693 / 1670, MS 8191 / 8129). With this PR: VS/PS 12220 / 12130, CS **1440 / 1417**, MS 8163 / 8101. That is the same loss of 323 validated programs (42 VS/PS, 253 CS, 28 MS) as the merged #612 shows (see my measurement there), with the same refusal reasons. So it fixes #604 the same way, but it now duplicates #612.
upstream-sync closed this pull request 2026-11-25 01:04:50 +00:00
Marvisak commented 2026-11-25 01:07:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:27:40Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

The fix for #604 (a phi read only through another phi is live) is already in main through #612 (commit 3dd467c), and this copy carries a workspace-wide cargo fmt.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148532965 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/699#issuecomment-7148532965). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:27:40Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. The fix for #604 (a phi read only through another phi is live) is already in main through #612 (commit 3dd467c), and this copy carries a workspace-wide cargo fmt. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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
Marvisak/VIctory!699
No description provided.