Shaders: trace uniform v_mov_b32 and v_readfirstlane_b32 copies in resource tracking #2101

Closed
fuzeofficlal wants to merge 2 commits from upstream-pr/2103 into main
fuzeofficlal commented 2026-11-25 05:00:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T05:00:57Z.


Scope: preventive. It targets part 4 of #728 (uniform values moved through v_mov_b32 / v_readfirstlane_b32, and waterfalls where only some descriptor dwords vary); an offline census of the title's shaders shows no count change, so it can be held until a title needs it.

Refs #728.

Summary

  • Sound uniform VALU copy propagation (Tracer::copy_source / unguarded_copy): follow plain unguarded v_mov_b32 and v_readfirstlane_b32 copies only when the source holds a wave-uniform scalar or constant (!self.varies(t)), every lane reaching the block executes the instruction (lanes.guards[b][i].is_none()), and v_readfirstlane_b32 reads no lane outside the block's reach.
  • Mixed uniform/varying descriptor support (classify / first_lane_words / waterfall): when a subset of descriptor dwords folds to wave-uniform values while remaining dwords still vary across lanes, retain waterfall loop verification over the varying dwords instead of failing with "a descriptor partly read from the first lane".

Testing

  • Added positive unit and GPU/WARP dxil.dll-validated tests (uniform_values_moved_through_vgprs_and_readfirstlane_are_tracked, uniform_vgpr_readfirstlane_descriptor_runs_on_gpu_and_warp) across NVIDIA RTX 5090, AMD Radeon RDNA2, and D3D12 WARP.
  • Added 5 negative soundness tests in divergent_or_masked_vgprs_are_not_folded_through_readfirstlane verifying input VGPRs, source modifiers, EXEC-narrowed moves, non-loop divergent v_readfirstlane_b32, and mixed uniform/varying descriptors.
  • cargo test -p victory-shader, cargo clippy --workspace --all-targets --all-features -- -D warnings, and cargo xtask policy.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6597572657 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2103). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T05:00:57Z. --- > **Scope:** preventive. It targets part 4 of #728 (uniform values moved through `v_mov_b32` / `v_readfirstlane_b32`, and waterfalls where only some descriptor dwords vary); an offline census of the title's shaders shows no count change, so it can be held until a title needs it. Refs #728. ### Summary - **Sound uniform VALU copy propagation (`Tracer::copy_source` / `unguarded_copy`)**: follow plain unguarded `v_mov_b32` and `v_readfirstlane_b32` copies only when the source holds a wave-uniform scalar or constant (`!self.varies(t)`), every lane reaching the block executes the instruction (`lanes.guards[b][i].is_none()`), and `v_readfirstlane_b32` reads no lane outside the block's reach. - **Mixed uniform/varying descriptor support (`classify` / `first_lane_words` / `waterfall`)**: when a subset of descriptor dwords folds to wave-uniform values while remaining dwords still vary across lanes, retain waterfall loop verification over the varying dwords instead of failing with `"a descriptor partly read from the first lane"`. ### Testing - Added positive unit and GPU/WARP `dxil.dll`-validated tests (`uniform_values_moved_through_vgprs_and_readfirstlane_are_tracked`, `uniform_vgpr_readfirstlane_descriptor_runs_on_gpu_and_warp`) across NVIDIA RTX 5090, AMD Radeon RDNA2, and D3D12 WARP. - Added 5 negative soundness tests in `divergent_or_masked_vgprs_are_not_folded_through_readfirstlane` verifying input VGPRs, source modifiers, `EXEC`-narrowed moves, non-loop divergent `v_readfirstlane_b32`, and mixed uniform/varying descriptors. - `cargo test -p victory-shader`, `cargo clippy --workspace --all-targets --all-features -- -D warnings`, and `cargo xtask policy`.
catminou4 commented 2026-11-25 06:02:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T05:16:27Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

146 passed / 0 failed / 2 ignored. Uniform v_mov_b32 and v_readfirstlane_b32 copy tracing (+2 tests) — uniform-move tracing for the readfirstlane path; relates to #1718's helper-lane readfirstlane fix.

<!-- greyfinch-sync:Marvisak/VIctory:review:6052205574 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2103#pullrequestreview-6052205574). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T05:16:27Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 146 passed / 0 failed / 2 ignored. Uniform v_mov_b32 and v_readfirstlane_b32 copy tracing (+2 tests) — uniform-move tracing for the readfirstlane path; relates to #1718's helper-lane readfirstlane fix.
fiestorra commented 2026-11-25 07:03:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fiestorra on 2026-11-25T06:20:44Z.


Ran the census: it changes nothing on this archive — which makes the evidence question the important one

A 585-line change to address tracking is a change whose value should be visible somewhere, so I measured the place this tree usually measures:

main 940d32f:  validated 23,918 of 26,084   · 871 Flags must match usage  · 195 SGPR addresses  · …
this branch:   validated 23,918 of 26,084   · 867 Flags must match usage  · 195 SGPR addresses  · …

(same local 1.0.2.1 archive, 26,503 containers, validator SDK 10.0.26100 dxil.dll 1.9; the 871 → 867 difference is the four programs that #1767's note: reporting rewrites as a different class in my run, not a change of outcome — the totals and the class membership are the same.)

So: no program that failed before passes now, on this corpus. That is not an argument against the change — it refs #728, which is a specific pattern — but it means the description has no measurable "before/after" available here, and a reviewer should ask for the evidence that does exist:

  • which program or pattern does this fix, and does that pattern occur in the title's shaders at all? If it does, one container plus a before/after line is worth more than the change itself; if it does not, then say "preventive", because that word decides whether it should be merged now or held until a title needs it;
  • and if it does occur, does the emitted code differ in a way that would show in translate --count (#2115) — extra or fewer instructions — even when both versions validate? That is the only census-visible trace a change like this can leave when the modules already validated.

What I can vouch for is the shape of the reasoning, which is the part I looked at hardest because it is where a wrong uniform copy turns into a wrong descriptor for every lane:

  • the copy is followed only when the source does not vary (!self.varies(t)) — the condition that makes the whole thing sound;
  • only when every lane reaching the block executes the instruction (lanes.guards[b][i].is_none()), which is what keeps a guarded copy from being treated as uniform;
  • and v_readfirstlane_b32 only when it reads no lane outside the block's reach, which is the subtle one: readfirstlane picks the lowest active lane, and if that lane is not one the block executes, the "uniform" value it would propagate is a value from a lane that is not there.

Those three are exactly the conditions I would have written, and they are stated in the description rather than left implicit — which is why I am reviewing this rather than guessing at it.

Two practical notes:

  • it touches only crates/victory-shader/src/resource.rs, and merges cleanly with the three LDS-atomic pull requests in this window (#2113, #2116, #2119) — I tried each one against it, all clean. So it does not add to that pile;
  • the watermark note in the description ("a subset of descriptor dwords folds to wave-uniform values while remaining dwords stay varied") is the part with the most risk, since it changes what classify and the waterfall do together. If the parameter tracking table is the thing that breaks first, that is where I would look, and a test that pins a mixed descriptor — some dwords uniform, some not — is the one I would want in the patch rather than in a later bug report.

No game data is involved: counts and code.

Written with an AI assistant.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154694756 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2103#issuecomment-7154694756). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-25T06:20:44Z. --- **Ran the census: it changes nothing on this archive — which makes the evidence question the important one** A 585-line change to address tracking is a change whose value should be visible somewhere, so I measured the place this tree usually measures: ``` main 940d32f: validated 23,918 of 26,084 · 871 Flags must match usage · 195 SGPR addresses · … this branch: validated 23,918 of 26,084 · 867 Flags must match usage · 195 SGPR addresses · … ``` (same local 1.0.2.1 archive, 26,503 containers, validator SDK 10.0.26100 `dxil.dll` 1.9; the 871 → 867 difference is the four programs that #1767's `note:` reporting rewrites as a different class in my run, not a change of outcome — the totals and the class membership are the same.) So: **no program that failed before passes now, on this corpus.** That is not an argument against the change — it refs #728, which is a specific pattern — but it means the description has no measurable "before/after" available here, and a reviewer should ask for the evidence that does exist: - **which program or pattern does this fix**, and does that pattern occur in the title's shaders at all? If it does, one container plus a before/after line is worth more than the change itself; if it does not, then say "preventive", because that word decides whether it should be merged now or held until a title needs it; - **and if it does occur**, does the emitted code differ in a way that would show in `translate --count` (#2115) — extra or fewer instructions — even when both versions validate? That is the only census-visible trace a change like this can leave when the modules already validated. **What I can vouch for is the shape of the reasoning**, which is the part I looked at hardest because it is where a wrong uniform copy turns into a wrong descriptor for every lane: - the copy is followed only when the source **does not vary** (`!self.varies(t)`) — the condition that makes the whole thing sound; - only when **every lane reaching the block executes the instruction** (`lanes.guards[b][i].is_none()`), which is what keeps a guarded copy from being treated as uniform; - and `v_readfirstlane_b32` only when it **reads no lane outside the block's reach**, which is the subtle one: `readfirstlane` picks the lowest active lane, and if that lane is not one the block executes, the "uniform" value it would propagate is a value from a lane that is not there. Those three are exactly the conditions I would have written, and they are stated in the description rather than left implicit — which is why I am reviewing this rather than guessing at it. Two practical notes: - **it touches only `crates/victory-shader/src/resource.rs`**, and merges cleanly with the three LDS-atomic pull requests in this window (#2113, #2116, #2119) — I tried each one against it, all clean. So it does not add to that pile; - the watermark note in the description ("a subset of descriptor dwords folds to wave-uniform values while remaining dwords stay varied") is the part with the most risk, since it changes what `classify` and the waterfall do together. If the parameter tracking table is the thing that breaks first, that is where I would look, and a test that pins a **mixed** descriptor — some dwords uniform, some not — is the one I would want in the patch rather than in a later bug report. No game data is involved: counts and code. Written with an AI assistant.
fiestorra commented 2026-11-25 07:03:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fiestorra on 2026-11-25T06:21:11Z.


Correction to the numbers in my comment above: both sides are 867, and the 871 I quoted was mine, not this comparison

I wrote that "the 871 → 867 difference is the four programs that #1767's note: reporting rewrites as a different class". That is wrong, and I should not leave it standing.

The figures for the two builds in this comment are:

main 940d32f        summary of that class: 867   (plus the summary line itself: 868 matches)
this branch         summary of that class: 867   (same)

So this pull request changes nothing in the census — not the class, not the total. The 871 was a number from an earlier census run of mine, taken on a different tree state, and quoting it here made it look as though something moved by four programs when nothing moved at all.

The substantive point of the review is unchanged and is now cleaner: 23,918 validated and the same class counts before and after, so the evidence for this change has to be the specific program or pattern it fixes, not a corpus number. My apology for putting a misleading pair in front of you.

No game data is involved: counts.

Written with an AI assistant.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154702685 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2103#issuecomment-7154702685). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-25T06:21:11Z. --- **Correction to the numbers in my comment above: both sides are 867, and the 871 I quoted was mine, not this comparison** I wrote that "the 871 → 867 difference is the four programs that #1767's `note:` reporting rewrites as a different class". That is wrong, and I should not leave it standing. The figures for the two builds in this comment are: ``` main 940d32f summary of that class: 867 (plus the summary line itself: 868 matches) this branch summary of that class: 867 (same) ``` So **this pull request changes nothing in the census — not the class, not the total.** The 871 was a number from an earlier census run of mine, taken on a different tree state, and quoting it here made it look as though something moved by four programs when nothing moved at all. The substantive point of the review is unchanged and is now cleaner: **23,918 validated and the same class counts before and after**, so the evidence for this change has to be the specific program or pattern it fixes, not a corpus number. My apology for putting a misleading pair in front of you. No game data is involved: counts. Written with an AI assistant.
fuzeofficlal commented 2026-11-25 09:06:16 +00:00 (Migrated from github.com)

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


Thanks for running the census and for the correction — 23,918 before and after with identical class counts matches what I'd expect.

On the evidence question: the pattern is a wave-uniform value (a scalar, a constant, a table base or offset, or individual descriptor dwords) moved into a VGPR with v_mov_b32 and read back with v_readfirstlane_b32 outside a waterfall loop, plus the waterfall case where only some of a descriptor's dwords still differ between lanes. It comes from part 4 of the branch in #728; the gains reported there were for the whole branch, and its other parts have since landed on main separately (0b35b7f, 75677cb). I have no container showing this pattern failing on its own, and your census agrees, so this is preventive — fine to hold until a title needs it. I've said so at the top of the description.

On the mixed-descriptor risk, I pushed a_mixed_descriptor_proves_only_its_varying_dwords (d0a07fce): dword 0 is chosen per lane by v_cndmask_b32, dwords 1–3 are constants that reach v_readfirstlane_b32 through v_mov_b32, and the loop compares dword 0 only. It pins the traced source (a per-lane choice between the two built descriptors), one compare and one first-lane read in the waterfall proof; a variant comparing a constant dword instead must still be refused ("compares do not select the access's lanes"). Without the uniform folding the positive case is refused, and with the !varies condition dropped the source no longer traces per lane, so it covers both under- and over-folding.

cargo test -p victory-shader --locked passes except the three hardware-dependent tests that also fail on main on this non-RDNA2 machine; both clippy modes and cargo xtask policy are clean.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157001505 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2103#issuecomment-7157001505). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T08:25:11Z. --- Thanks for running the census and for the correction — 23,918 before and after with identical class counts matches what I'd expect. On the evidence question: the pattern is a wave-uniform value (a scalar, a constant, a table base or offset, or individual descriptor dwords) moved into a VGPR with `v_mov_b32` and read back with `v_readfirstlane_b32` outside a waterfall loop, plus the waterfall case where only some of a descriptor's dwords still differ between lanes. It comes from part 4 of the branch in #728; the gains reported there were for the whole branch, and its other parts have since landed on `main` separately (`0b35b7f`, `75677cb`). I have no container showing this pattern failing on its own, and your census agrees, so this is **preventive** — fine to hold until a title needs it. I've said so at the top of the description. On the mixed-descriptor risk, I pushed `a_mixed_descriptor_proves_only_its_varying_dwords` (`d0a07fce`): dword 0 is chosen per lane by `v_cndmask_b32`, dwords 1–3 are constants that reach `v_readfirstlane_b32` through `v_mov_b32`, and the loop compares dword 0 only. It pins the traced source (a per-lane choice between the two built descriptors), one compare and one first-lane read in the waterfall proof; a variant comparing a constant dword instead must still be refused ("compares do not select the access's lanes"). Without the uniform folding the positive case is refused, and with the `!varies` condition dropped the source no longer traces per lane, so it covers both under- and over-folding. `cargo test -p victory-shader --locked` passes except the three hardware-dependent tests that also fail on `main` on this non-RDNA2 machine; both clippy modes and `cargo xtask policy` are clean.
Marvisak commented 2026-11-25 11:05:29 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

In resource.rs, Tracer::copy_source now follows v_mov_b32/v_readfirstlane_b32 copies, and first_lane_words/classify take mixed uniform/varying descriptors. The soundness conditions are there:

  • !varies on the source;
  • unguarded_copy checks for no guard and that EXEC stays within the block's reach;
  • tests pin the mixed-descriptor case and over-folding.

However, by the author's own account and a census, no title program changes (23,918 validated before and after). This is a 640-line preventive change to descriptor tracking, where a wrong fold gives every lane a wrong descriptor. It should be held until a title program needs it. A container or pattern from the title showing the failure would change the verdict. CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159995701 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2103#issuecomment-7159995701). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:39:27Z. --- <!-- victory-triage v1 head=d0a07fceb4b028046fea5cf5c9736e4c657b186e verdict=needs-work at=2026-11-25T10:39:21Z --> Automated triage for the maintainers. In `resource.rs`, `Tracer::copy_source` now follows `v_mov_b32`/`v_readfirstlane_b32` copies, and `first_lane_words`/`classify` take mixed uniform/varying descriptors. The soundness conditions are there: - `!varies` on the source; - `unguarded_copy` checks for no guard and that EXEC stays within the block's reach; - tests pin the mixed-descriptor case and over-folding. However, by the author's own account and a census, no title program changes (23,918 validated before and after). This is a 640-line preventive change to descriptor tracking, where a wrong fold gives every lane a wrong descriptor. It should be held until a title program needs it. A container or pattern from the title showing the failure would change the verdict. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 16:06:52 +00:00
fuzeofficlal commented 2026-11-25 16:09:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T15:40:17Z.


Closing per triage feedback: this multi-hop copy tracking is preventive with zero change on the current shader corpus. Happy to revisit if a title shader hits this pattern.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167201293 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2103#issuecomment-7167201293). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T15:40:17Z. --- Closing per triage feedback: this multi-hop copy tracking is preventive with zero change on the current shader corpus. Happy to revisit if a title shader hits this pattern.

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!2101
No description provided.