Shaders: uniform phis (loop counters) under v_readfirstlane addresses (stacked on #1225) #1231

Closed
LooperSalty wants to merge 2 commits from upstream-pr/1231 into main
LooperSalty commented 2026-11-24 16:36:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LooperSalty on 2026-11-24T16:36:03Z.


From a tester working with Claude (AI-assisted); measured on my own machine (i7-13700KF, RTX 4070 Super). No game data in the diff; test programs are synthetic.

Stacked on #1225: the first commit of this branch is #1225's, review only the last one. It extends the uniformity test added there to phis, so a code-table lookup walked by a loop counter (s_getpc_b64 + 4*i, i a VGPR phi with a uniform exit) is traced instead of refused as "an address read from the first lane of a per-lane value".

A phi is uniform when its arguments are and no lane-divergent branch (or loop it can leave lane by lane) can send lanes to it along different edges (greatest fixed point). Recognised uniform exits: execz, scc of uniform values, vcc from comparisons of uniform values. v_readlane_b32 is uniform; a guarded VALU write needs its old value uniform. The post-dominator helper is a private copy in resource/uniform.rs, so this does not depend on any other open PR.

Measured on an integration tree: PrefilterAndIntegrateIrradianceSH and IrradianceCache_IntegrateIrradianceSH now translate and validate (dxil.dll); compute programs emitted 2212 -> 2214 there.

cargo test -p victory-gpu -p victory-shader is green on this branch (based on origin/main ffe310e + #1225).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6586657777 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1231). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-24T16:36:03Z. --- From a tester working with Claude (AI-assisted); measured on my own machine (i7-13700KF, RTX 4070 Super). No game data in the diff; test programs are synthetic. **Stacked on #1225**: the first commit of this branch is #1225's, review only the last one. It extends the uniformity test added there to phis, so a code-table lookup walked by a loop counter (`s_getpc_b64` + 4*i, i a VGPR phi with a uniform exit) is traced instead of refused as "an address read from the first lane of a per-lane value". A phi is uniform when its arguments are and no lane-divergent branch (or loop it can leave lane by lane) can send lanes to it along different edges (greatest fixed point). Recognised uniform exits: `execz`, `scc` of uniform values, `vcc` from comparisons of uniform values. `v_readlane_b32` is uniform; a guarded VALU write needs its old value uniform. The post-dominator helper is a private copy in `resource/uniform.rs`, so this does not depend on any other open PR. Measured on an integration tree: PrefilterAndIntegrateIrradianceSH and IrradianceCache_IntegrateIrradianceSH now translate and validate (dxil.dll); compute programs emitted 2212 -> 2214 there. `cargo test -p victory-gpu -p victory-shader` is green on this branch (based on `origin/main` ffe310e + #1225).
MichaelSmithAI commented 2026-11-24 17:04:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T16:57:18Z.


We found a case where the old and new VGPR values are each uniform, but the value after restoring EXEC differs across lanes. In a 64-lane group, initialize v4 to 0 everywhere, set EXEC to lanes 10–63, write 42 to v4, restore EXEC, then read v4 with v_readfirstlane_b32. Lane 0 still holds 0, so the broadcast should give 0 to all 64 lanes.

We used this PR’s classifier at 8996aeb in a local composition with #439 to decide whether two 32-lane host waves needed to exchange a value. On an RTX 4090, both the straight-line masked write and the version with s_cbranch_execz took the cheaper route. The lower 32 lanes returned 0 and the upper 32 returned 42 in both test groups. A conservative check of which lanes execute the write and enter the join restored 0 to every lane in both forms. A constant computed before the divergent section and read inside it still used the cheaper route and returned 42.

For this PR’s address tracer, the question is whether unlaned() can substitute the per-lane source of such a read for the scalar address. The GPU result above exercises our routing use of the classifier. On the exact PR head, a synthetic code-table lookup confirmed that both masked-write forms were accepted with a per-lane dynamic address. A regression and conservative fix are in LooperSalty/victory#5. Both now receive the existing per-lane-address diagnostic while the uniform loop-counter control still passes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138463280 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1231#issuecomment-7138463280). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T16:57:18Z. --- We found a case where the old and new VGPR values are each uniform, but the value after restoring EXEC differs across lanes. In a 64-lane group, initialize v4 to 0 everywhere, set EXEC to lanes 10–63, write 42 to v4, restore EXEC, then read v4 with `v_readfirstlane_b32`. Lane 0 still holds 0, so the broadcast should give 0 to all 64 lanes. We used this PR’s classifier at `8996aeb` in a local composition with #439 to decide whether two 32-lane host waves needed to exchange a value. On an RTX 4090, both the straight-line masked write and the version with `s_cbranch_execz` took the cheaper route. The lower 32 lanes returned 0 and the upper 32 returned 42 in both test groups. A conservative check of which lanes execute the write and enter the join restored 0 to every lane in both forms. A constant computed before the divergent section and read inside it still used the cheaper route and returned 42. For this PR’s address tracer, the question is whether `unlaned()` can substitute the per-lane source of such a read for the scalar address. The GPU result above exercises our routing use of the classifier. On the exact PR head, a synthetic code-table lookup confirmed that both masked-write forms were accepted with a per-lane dynamic address. A regression and conservative fix are in [LooperSalty/victory#5](https://github.com/LooperSalty/victory/pull/5). Both now receive the existing per-lane-address diagnostic while the uniform loop-counter control still passes.
pablogonz12 commented 2026-11-24 18:05:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-24T17:16:23Z.


Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 (main's host build fails without it: E0425 host_resource), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped).

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 668 / 768 658 658

+2 programs translate and none is lost: "an address not from a root parameter" goes from 3 compute programs to 1, and no other reason moves. Same 10 SPIR-V validation failures as the base.

Not tested: in-game.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138945745 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1231#issuecomment-7138945745). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-24T17:16:23Z. --- Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main `ffe310e` plus #1017 (main's host build fails without it: `E0425 host_resource`), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped). | | translate | valid SPIR-V | RADV pipeline | |---|---|---|---| | base | 666 / 768 | 656 | 656 | | your head | 668 / 768 | 658 | 658 | +2 programs translate and none is lost: "an address not from a root parameter" goes from 3 compute programs to 1, and no other reason moves. Same 10 SPIR-V validation failures as the base. Not tested: in-game.
Zipettte commented 2026-11-24 18:06:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T17:59:40Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 8996aeb: cargo test -p victory-shader passes, 124 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140002415 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1231#issuecomment-7140002415). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T17:59:40Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 8996aeb: `cargo test -p victory-shader` passes, 124 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
upstream-sync closed this pull request 2026-11-25 01:06:00 +00:00
Marvisak commented 2026-11-25 01:08:05 +00:00 (Migrated from github.com)

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


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

Stacked on #1225 (uniform loop-counter phis under first-lane code addresses): main's reaches_pc already goes through phis.

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:7148670020 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1231#issuecomment-7148670020). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:35:25Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Stacked on #1225 (uniform loop-counter phis under first-lane code addresses): main's `reaches_pc` already goes through phis. 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!1231
No description provided.