Skip to content

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

Closed
arthercz wants to merge 4 commits into
Marvisak:mainfrom
arthercz:phi-missing-fix
Closed

arthercz wants to merge 4 commits into
Marvisak:mainfrom
arthercz:phi-missing-fix

Conversation

@arthercz

Copy link
Copy Markdown

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.

…with-default

- cargo fmt: 168 formatting differences in 32 files
- xmem.rs: initialize PERFORMANCE_INFORMATION cb in the struct literal
  (clippy::field_reassign_with_default)
Speech streams were valid empty WAVE files, so the title's narration
(accessibility menus and the like) was silent. Route text (0x68) and
SSML (0xa8) through Windows.Media.SpeechSynthesis and hand the title the
spoken RIFF stream; when the host has no voice (no voices installed,
WinRT unavailable), keep the empty-WAVE fallback so the title still
plays the stream and goes on.

- streams become boxed handles, reclaimed by close (0x70); the
  synthesizer handle stays a fixed address
- enumerate_voices stays a no-op: no title of ours asks, and the host's
  default voice speaks
- the windows crate moves out of the diagnostics-only feature so its
  WinRT bindings link in release builds too

Verified on Windows 11: the unit test now speaks "Hello" and validates
the returned WAVE (RIFF chunk walk, PCM 16 kHz mono 16-bit, non-empty
data); cargo test --workspace 264 passed.
The diagnostics gate checked only the variable's presence, so
VICTORY_D3D12_WARP=0 still created the device on WARP; the workaround was
to remove the variable entirely (issue Marvisak#610).

Treat "0" like unset, keep documented "1" and presence-means-on for
other values, and keep the diagnostics feature gate. The predicate moves
into warp_selected/warp_selected_at, covered by a table test (unset, 0,
1, empty); README documents the opt-out.

Verified: cargo test -p victory-gpu --features diagnostics --locked
warp_ passes; cargo clippy --workspace --all-features clean.
…g value

The emitter refused a branch on a live timestamp read (s_memtime result)
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 became zero instead of the refusal the
direct read gets (issue Marvisak#604).

Follow incoming phi dependencies from the phis actual readers mark, by
fixpoint, before the substitution decision; a dead phi (read by nothing
live) still lowers with the zero substitution.

The regression test is Dathinel's probe from the issue (test-only commit
4b2ea70), applied unmodified.

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 LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

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 Shader emitter accepts an unsupported timestamp read after two SSA joins #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

Copy link
Copy Markdown

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.

@Marvisak

Copy link
Copy Markdown
Owner

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.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shader emitter accepts an unsupported timestamp read after two SSA joins

6 participants