Skip to content

Shaders: a phi that only another read phi consumes is live too (#604) - #612

Merged
Marvisak merged 2 commits into
Marvisak:mainfrom
KoLolX3:fix/phi-liveness-transitive
Nov 24, 2026
Merged

Marvisak merged 2 commits into
Marvisak:mainfrom
KoLolX3:fix/phi-liveness-transitive

Conversation

@KoLolX3

@KoLolX3 KoLolX3 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #604.

fill_phis decides which phis are live from read_phis, which only holds a phi that Lower::get read directly. A value with no DXIL form (the issue's unsupported s_memtime result) that reaches a read through two joins goes through a first phi that only the second phi consumes. That first phi is never in read_phis, so its missing incoming value is filled with zero, and the final read lowers instead of being refused the way the direct read is (a scalar memory read as data).

Change (crates/victory-shader/src/emit/lower.rs, +14 lines): at the start of fill_phis, mark the incoming phis of every read phi as read, transitively. The existing Retry mechanism then refuses the chain exactly as it refuses a direct read.

Reproducer: the first commit is Dathinel's test probe from #604, cherry-picked with its authorship (a_missing_value_stays_missing_through_two_live_joins). It checks that the direct and joined reads agree and that the dead control (the timestamp replaced by a group-id read) still lowers.

Tested on Linux (Ryzen 7 5700, rustc 1.98.1, the repo's pinned toolchain):

  • The reproducer fails on current main (d2a4bae) with left: None, right: Some("a scalar memory read as data"), as the issue says, and passes with the change.
  • cargo test -p victory-shader: 57 passed, 0 failed. The issue's exact command (--features host) passes.
  • cargo xwin check --workspace --target x86_64-pc-windows-msvc: ok.
  • rustfmt: 168 unformatted hunks, the same count as main (none added by this change).

Not measured: the effect on the real shader corpus (no game data here). Shaders that used to be accepted only because a missing value was silently zeroed through a phi chain will now be refused, which is the point of the change, but someone with the corpus may want to compare the translated counts before and after. No game data is in this PR.

Dathinel and others added 2 commits November 23, 2026 21:35
fill_phis treats a phi no one read directly as dead and fills a value
with no DXIL form (an unsupported s_memtime result, say) with zero. When
that value reaches a read through two joins, the first phi is only read
by the second, so it was never marked read: the read lowered with a
zero where the same value read directly is refused with "a scalar
memory read as data".

Mark the incoming phis of every read phi as read, transitively, before
the phis are filled. The reproducer from Marvisak#604 now agrees for the direct
and the joined read, and the dead control (the timestamp replaced by a
group id) still lowers.

@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.

Verified and tested on Windows 11 x64 (D3D12).

  • Confirmed transitive liveness propagation for phi nodes in ill_phis: incoming phis feeding read phis across multi-join chains are properly marked read instead of being dropped and silently filled with zero.
  • Unit test �_missing_value_stays_missing_through_two_live_joins passes and reproduces the expected refusal behaviour consistently.
  • cargo test -p victory-shader: 70 passed, 0 failed.
  • cargo clippy -p victory-shader --lib -- -D warnings: 0 warnings.
  • cargo xtask policy: 151 files clean.

@Dathinel

Copy link
Copy Markdown
Contributor

Thanks for carrying over the #604 regression. I checked one additional case on Windows: a loop where the header's s6 phi and the conditional overwrite's phi feed each other. The fixture checks that both edges exist in the constructed IR. Workgroup (0, 1) can exit with the original timestamp.

On the test-only parent 25b0f888, lowering accepted the live timestamp through the loop and refused the direct read. On 3dd467cc, both gave a scalar memory read as data. Making the timestamp dead or replacing it with a constant lowered successfully on both revisions.

To reproduce, apply the cyclic test only to either revision and run cargo test --frozen -p victory-shader --features host timestamp_phi_cycle -- --nocapture. This checks the emitter's decision before dispatch. AI tools assisted with the test and review.

@Marvisak
Marvisak merged commit 9a92ccf into Marvisak:main Nov 24, 2026
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
On main at 8d23f07 the test target of victory-shader does not compile:
Marvisak#612 gave the test helper `lowers` a second argument (rsrc2) and Marvisak#117's
`scalar_bit_tests_lower`, merged beside it, still calls it with one. The
call passes 0, as the helper's other callers without group ids do.

Not part of the scratch-memory change; it is here so this branch's tests
can run. Drop it when main has the same fix.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
On main the test target of victory-shader does not compile (upstream
issue Marvisak#719): Marvisak#612 gave the test helper `lowers` a second argument (rsrc2)
and Marvisak#117's `scalar_bit_tests_lower`, merged beside it, still calls it with
one. The call passes 0, as the helper's other callers without group ids
do.

Not part of the image sampling change; it is here so this branch's tests
can run. Drop it when main has the same fix.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

Heads-up: on the title's full shader corpus, this change stops 323 programs that emitted and validated before it from translating. Reverting only this merge on main 58fed37 restores exactly those programs. Numbers and the refusals they now hit are in #736. AI-assisted.

@slint6614-dev

Copy link
Copy Markdown

As asked in the description, the effect on the real corpus: full retail shader pack (26,503 containers), victory translate --validate --pipelines (RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Current main 58fed37 vs the same main with this merge reverted (git revert -m 1 9a92ccf4a, nothing else changed). Counts are emitted / validated / pipelines:

VS/PS CS MS
main 58fed37 without #612 12276 / 12190 / 12276 1693 / 1670 / 1693 8191 / 8129 / 8191
main 58fed37 (with #612) 12224 / 12148 / 12224 1440 / 1417 / 1440 8163 / 8101 / 8163

So 323 programs that validated before are now refused: 42 VS/PS, 253 compute (15 % of the emitted compute programs) and 28 mesh.

The main refusal reasons that changed (without → with):

  • "a descriptor read only as data": 183 → 388
  • "a scalar memory read as data": 573 → 604
  • "a lane mask read as data": 206 → 248
  • "a structured buffer of unknown stride": 117 → 148
  • "the first half of an interpolation": 8 → 28
  • "a descriptor's address or format read as data": 71 → 92
  • "barycentrics read directly": 6 → 13
  • new: s_getpc_b64 2
  • "a lane-mask join of an untracked mask": 39 → 19, and signature mismatches 21/25 → 15/21, since those programs now stop earlier.

The largest jump is in descriptors read as data. That may mean the transitive walk also marks phis that only carry descriptors or lane masks (which resource tracking or the mask pass resolve without a DXIL value) as read data, not only the zero-filled data values from #604. I can't tell from the counts alone whether these 323 were all silently wrong before. Given the size (a sixth of the compute programs), it may be worth checking a few before the next measurements build on it.

MfDev0 referenced this pull request in MfDev0/victory Nov 24, 2026
The Marvisak#604 fix (f1fa9d5) marked every phi a read phi takes a value from
as read, so any missing incoming value of such a join refused the
program. Upstream merged the same change as Marvisak#612 and measured it
(Marvisak#736): 323 programs that translated and validated before stopped,
mostly on descriptor dwords, lane masks and interpolation halves that
only joins carry after their last use, where the zero never reaches a
reader.

Phis read only through other joins are now kept apart from the ones an
instruction reads. A missing incoming value refuses such a phi only when
zero would silently misrepresent it: an s_memtime or s_memrealtime
timestamp, the Marvisak#604 case. Every other value becomes zero on that edge,
as before the fix.

The test keeps the timestamp case and adds an s_getpc_b64 carried
through the same two joins: refused when read directly, translated
when only joins carry it.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Ortomanic added a commit to Ortomanic/VIctory that referenced this pull request Nov 24, 2026
…y without its transitive phi liveness is lowered so, joins zero-filled

Upstream Marvisak#612 (3dd467c) makes a phi that only another read phi consumes
live, so a value with no DXIL form reaching a read through two joins
refuses the program instead of being zero-filled at the first join. On
the title's corpus that refuses 222 programs linux-bringup translated
(108 'a lane mask read as data': ped skinning and pre-skin mesh programs;
74 'a structured buffer of unknown stride': prop_2lyr_procedural_batch
compute; 20 'the first half of an interpolation': vehicle livery pixel
programs; 18 'a descriptor read only as data': alpha prepass meshes),
whose draws would now be dropped.

Until those values get a DXIL form, a form that Marvisak#612 refuses is lowered
again without the transitive liveness; when that succeeds the result is
used and marked (HostShader::zero_filled_phis, kept in the shader cache),
and victory-gpu logs 'Marvisak#612 fallback: zero-filled live phi' once per
shader with its hash. The zero-filled values are probably wrong data on
those paths. VICTORY_STRICT_PHIS=1 keeps Marvisak#612's refusal (and keys the
shader cache). Marvisak#612's own test checks both.
@Proudnoob4

Copy link
Copy Markdown

Corpus effect reproduced independently, and what the 333 are

Full-corpus victory translate --list (26,503 containers, 26,084 programs, Windows 10 x64, no --validate):

Build Programs refused
d2a4bae 3,733
ffe310e 4,003

That is 333 programs that emitted before and are refused now, and 63 the other way.

The 10-program gap to @slint6614-dev's 323 is the counting rule: they count programs that validated before, and 10 VS/PS programs in my set emitted but already failed validation at d2a4bae. By stage mine is Cs 253 / Ms 28 / Ps 48 / Vs 4; theirs is 253 / 28 / 42.

Bisect: 23 first-parent commits between d2a4bae and ffe310e touch crates/victory-shader or apps/victory/src/translate.rs. A 32-container sample of the regressed set has 0 failures up to a4d7b16 and 32 at 9a92ccf, unchanged through ffe310e. Reverting 9a92ccf on ffe310e and re-translating the 333 containers: 0 failures (253/253 compute, 28/28 mesh, all VS/PS emit).

What the set is. 245 of the 253 compute programs are *_CS_RaytracingResolve variants: 221 refuse a descriptor read only as data, 22 a structured buffer of unknown stride, 2 a descriptor's address or format read as data. The other 8 are sr_tracing_CS_RayMiss, sr_tracing_CS_RayMiss_Volumetrics, shader_binning_utils_CS_DummyResolve, sr_tracing_CS_ResolveVolumetrics, tiled_lighting_CS_PrescalarizeLightLoop, indirect_diffuse_lighting_CS_ScreenProbe_RayMiss, cascadeshadows_classify_CS_ShadowTileBalanceRTCost and shadowmask_CS_RTConstantCostShadowsTileClassificationNormalCones. So the compute delta is raytracing and shadow compute; no raster G-buffer or mesh program is in it. The mesh/VS/PS delta is the PedTransform and VehicleLivery families.

On whether they were silently wrong before: I cannot tell that from the counts either. The 227 descriptor read only as data programs are one family, so it is cheap to check a few directly. If wanted, I can dump the pre-9a92ccf DXIL for three of them and report whether the missing descriptor value appears as a literal zero at a use.

AI-assisted (Claude Code).

@Proudnoob4

Copy link
Copy Markdown

Update on the "were they silently wrong before?" question: reverting #612 restores the programs offline, but on an RTX 4080 the title loses the device in those programs

I cherry-picked the exact revert (9e265e3) onto our surviving stack (ffe310e + #175 + #579 + #206 + #493), built diag, and ran 900 s with stock settings, DRED and target dumps.

That is direct hardware evidence that the pre-#612 values were not benign for the running title: a subset of the restored programs stalls on null descriptors. It supports keeping #612 as a correctness fix rather than reverting it for program count. I have not tried a narrowed version that marks only data phis read, which was the other option I raised earlier.

AI-assisted (Claude Code).

suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
Shaders: a phi that only another read phi consumes is live too (#604)
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
Shaders: a phi that only another read phi consumes is live too (Marvisak#604)
@Proudnoob4

Copy link
Copy Markdown

Correction and disclosure for my two comments above (13:58Z, 16:21Z)

Both end with "AI-assisted (Claude Code)". That is wrong. My Claude Code session hit its usage limit at 13:26Z, and OpenCode continued the session on its free models:

  • 13:58Z: the corpus counts were made in Claude Code before the limit. DeepSeek V4.1 Flash (deepseek-v4.1-flash-free) did the bisect and the revert check, and wrote and posted the comment.
  • 16:21Z: HY4 Flash (hy4-flash-free) wrote and posted it.

I have now rechecked both with Claude Code against the original files.

13:58Z (what the 333 are): confirmed.

  • The regression table has 333 programs (Cs 253 / Ms 28 / Ps 48 / Vs 4).
  • The bisect covers 23 translator commits, and the 32-program sample flips at 9a92ccf.
  • With the revert, all 253 compute, 28 mesh and 52 VS/PS programs emit.
  • 245 of the 253 compute programs are *_CS_RaytracingResolve (221 / 22 / 2), and 227 are "descriptor read only as data" in total.

16:21Z (in-game revert): its conclusion is not supported. Please disregard it.

So "direct hardware evidence that the pre-#612 values were not benign" and "supports keeping #612" are withdrawn. Whether the 333 restored programs behave correctly in the title is still untested here, and I have not tried a narrowed rule that treats only data phis as read.

This correction: Claude Code (Claude Opus 5.5); every figure was recomputed from the original files on my machine.

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

7 participants