Shader emitter accepts an unsupported timestamp read after two SSA joins #604

Closed
opened 2026-11-26 04:09:44 +00:00 by github-bot · 2 comments
Owner

@⁠Dathinel on GitHub · 2026-11-24 05:26 UTC · original

On Windows x64 at d2a4bae1, the shader emitter rejects a branch that reads an unsupported s_memtime result directly, but accepts the same read after two conditional assignments. The timestamp is still observable when the workgroup has X = 0 and Y = 1.

The synthetic compute shader enables the X and Y group-id SGPRs (rsrc2 = 3 << 7). Its relevant operations are:

s_memtime s[6:7]
if group_id_x != 0: s6 = 0
if group_id_y != 1: s6 = 1
branch on s6 != 0
Case Lowering result
Direct branch on the low timestamp dword Refused with a scalar memory read as data
Branch on the dword after both joins Accepted

I would expect the two live reads to agree. Reading the group id at the final branch instead makes the timestamp dead and should still lower. This concerns the emitter's acceptance decision; the experiment used no game data or native hardware reference.

Lower::get marks the phi used by the final comparison. The earlier phi is read only by the later phi. In fill_phis, an unmarked phi may substitute zero for a missing incoming value. Following incoming phi dependencies from the actual readers made the live and dead controls pass locally.

Reproducer: test-only commit 4b2ea70f. To run it on the stated base, apply the test-only commit, then run:

cargo test --frozen -p victory-shader --features host a_missing_value_stays_missing_through_two_live_joins -- --nocapture

On the original emitter, the assertion prints left: None (joined) and right: Some("a scalar memory read as data") (direct). I found this while testing #521; it also reproduces on unmodified main with only the test added. AI tools assisted with the reproducer and independent review.

**@⁠Dathinel** on GitHub · 2026-11-24 05:26 UTC · [original](https://github.com/Marvisak/VIctory/issues/604) On Windows x64 at `d2a4bae1`, the shader emitter rejects a branch that reads an unsupported `s_memtime` result directly, but accepts the same read after two conditional assignments. The timestamp is still observable when the workgroup has X = 0 and Y = 1. The synthetic compute shader enables the X and Y group-id SGPRs (`rsrc2 = 3 << 7`). Its relevant operations are: ```text s_memtime s[6:7] if group_id_x != 0: s6 = 0 if group_id_y != 1: s6 = 1 branch on s6 != 0 ``` | Case | Lowering result | |---|---| | Direct branch on the low timestamp dword | Refused with `a scalar memory read as data` | | Branch on the dword after both joins | Accepted | I would expect the two live reads to agree. Reading the group id at the final branch instead makes the timestamp dead and should still lower. This concerns the emitter's acceptance decision; the experiment used no game data or native hardware reference. `Lower::get` marks the phi used by the final comparison. The earlier phi is read only by the later phi. In `fill_phis`, an unmarked phi may substitute zero for a missing incoming value. Following incoming phi dependencies from the actual readers made the live and dead controls pass locally. Reproducer: [test-only commit 4b2ea70f](https://github.com/Dathinel/VIctory/commit/4b2ea70f0940a4317dc934000d249dce0fce50f6). To run it on the stated base, apply the test-only commit, then run: ```sh cargo test --frozen -p victory-shader --features host a_missing_value_stays_missing_through_two_live_joins -- --nocapture ``` On the original emitter, the assertion prints `left: None` (joined) and `right: Some("a scalar memory read as data")` (direct). I found this while testing #521; it also reproduces on unmodified `main` with only the test added. AI tools assisted with the reproducer and independent review.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:09:44 +00:00
Author
Owner

@⁠LAKSHYA-cmd-tech on GitHub · 2026-11-24 07:50 UTC · original

PR #699 (shader: a phi read only through another phi keeps its missing incoming value) addresses this issue directly.

In fill_phis, PR #699 properly tracks incoming phi dependencies through multiple joins rather than only marking immediately read phis, ensuring that an unlowered/missing incoming value (such as s_memtime's a scalar memory read as data) correctly propagates its missing status through cascaded phi nodes instead of being silently substituted with zero.

We verified PR #699 against your reproducer a_missing_value_stays_missing_through_two_live_joins, and the test passes cleanly on Windows 11 MSVC.

**@⁠LAKSHYA-cmd-tech** on GitHub · 2026-11-24 07:50 UTC · [original](https://github.com/Marvisak/VIctory/issues/604#issuecomment-7125438335) PR #699 (`shader: a phi read only through another phi keeps its missing incoming value`) addresses this issue directly. In `fill_phis`, PR #699 properly tracks incoming phi dependencies through multiple joins rather than only marking immediately read phis, ensuring that an unlowered/missing incoming value (such as `s_memtime`'s `a scalar memory read as data`) correctly propagates its missing status through cascaded phi nodes instead of being silently substituted with zero. We verified PR #699 against your reproducer `a_missing_value_stays_missing_through_two_live_joins`, and the test passes cleanly on Windows 11 MSVC.
Author
Owner

@⁠Dathinel on GitHub · 2026-11-24 08:04 UTC · original

Thanks for checking #699. I reran the two-join regression on its head db0257e2 and also applied the two-phi loop fixture previously tested on #612. Both pass. With the loop fixture, the live timestamp is refused just like a direct read, while the dead timestamp and constant controls both lower. #612 at 3dd467cc gave the same results on these inputs.

I'd review #612 first for this issue. Both PRs carry the same two-join regression. #612 changes one file. The phi fix in #699 is also a one-file commit, but the full branch includes three earlier commits covering formatting, narration and WARP selection. Either fix would cover the reproduced case.

One integration detail if using #699's tip alone: on main@db89843, keep both the new regression and scalar_bit_tests_lower from #117. The latter still calls lowers(&words); passing the previous default as lowers(&words, 0) resolved E0061. With those tests preserved, cargo test --frozen -p victory-shader --lib reported 79 passed and 1 ignored on Windows. AI-assisted.

**@⁠Dathinel** on GitHub · 2026-11-24 08:04 UTC · [original](https://github.com/Marvisak/VIctory/issues/604#issuecomment-7125685874) Thanks for checking #699. I reran the two-join regression on its head `db0257e2` and also applied the [two-phi loop fixture previously tested on #612](https://git.gtahub.st/github/Marvisak--VIctory/pulls/612). Both pass. With the loop fixture, the live timestamp is refused just like a direct read, while the dead timestamp and constant controls both lower. #612 at `3dd467cc` gave the same results on these inputs. I'd review **#612 first** for this issue. Both PRs carry the same two-join regression. #612 changes one file. The phi fix in #699 is also a one-file commit, but the full branch includes three earlier commits covering formatting, narration and WARP selection. Either fix would cover the reproduced case. One integration detail if using #699's tip alone: on `main@db89843`, keep both the new regression and `scalar_bit_tests_lower` from #117. The latter still calls `lowers(&words)`; passing the previous default as `lowers(&words, 0)` resolved E0061. With those tests preserved, `cargo test --frozen -p victory-shader --lib` reported 79 passed and 1 ignored on Windows. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#604
No description provided.