Shaders: follow EXEC set from a scalar the section made constant #90

Closed
dutch2005 wants to merge 1 commit from upstream-pr/90 into main
dutch2005 commented 2026-11-25 13:45:24 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by dutch2005 on 2026-11-25T13:45:24Z.


Why

A whole-wave section that sets EXEC from a scalar it computed itself (s_mov_b32 s5, -1 then s_mov_b32 exec_lo, s5) stopped the section simulation at the EXEC write, because only inline constants and literals were followed. The lanes after it then lost their shape. Ported from the open upstream PR Marvisak/VIctory#2382 (by Calvix2k); this tree still stops at the scalar copy.

What

  • The section simulation remembers scalars it set to a constant (sconst) and follows an EXEC write from one of them.
  • A non-constant write to a scalar drops what it held.
  • Adds the upstream regression test: s_or_saveexec, s_mov s5, -1, s_mov exec_lo, s5, v_mov v2, 7, restore; v2 keeps shape K(7).

Review fix

gut0to found that a 64-bit scalar move writes two SGPR halves but inst.writes carries one constant value, so tracking it per half could seed the wrong value for a later s_mov_b32 exec_hi. Only plain s_mov_b32 moves now seed the map; a pure seeds_scalar_constant helper and test lock that rule.

Testing

  • cargo test -p victory-shader --lib scalar_constant -- --test-threads=1 — 2 passed, 0 failed: the original EXEC-from-scalar case and the wide-move exclusion.
  • Mutation coverage on the diff: 9 caught, 1 equivalent. The equivalent mutant is the code != NULL guard in constant (the null SGPR is not readable and sconst never holds it); documented in PR #108's policy.
  • Full workspace on all fixes: 562 passed, 0 failed (before the latest test additions).

Notes

No change for sections whose EXEC is set directly from an inline constant or literal; only the scalar-copy form is newly followed.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6605906380 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/90). Originally posted by [dutch2005](https://github.com/dutch2005) on 2026-11-25T13:45:24Z. --- ## Why A whole-wave section that sets `EXEC` from a scalar it computed itself (`s_mov_b32 s5, -1` then `s_mov_b32 exec_lo, s5`) stopped the section simulation at the `EXEC` write, because only inline constants and literals were followed. The lanes after it then lost their shape. Ported from the open upstream PR Marvisak/VIctory#2382 (by Calvix2k); this tree still stops at the scalar copy. ## What - The section simulation remembers scalars it set to a constant (`sconst`) and follows an `EXEC` write from one of them. - A non-constant write to a scalar drops what it held. - Adds the upstream regression test: `s_or_saveexec`, `s_mov s5, -1`, `s_mov exec_lo, s5`, `v_mov v2, 7`, restore; v2 keeps shape `K(7)`. ## Review fix gut0to found that a 64-bit scalar move writes two SGPR halves but `inst.writes` carries one constant value, so tracking it per half could seed the wrong value for a later `s_mov_b32 exec_hi`. Only plain `s_mov_b32` moves now seed the map; a pure `seeds_scalar_constant` helper and test lock that rule. ## Testing - `cargo test -p victory-shader --lib scalar_constant -- --test-threads=1` — 2 passed, 0 failed: the original EXEC-from-scalar case and the wide-move exclusion. - Mutation coverage on the diff: **9 caught, 1 equivalent**. The equivalent mutant is the `code != NULL` guard in `constant` (the null SGPR is not readable and `sconst` never holds it); documented in PR #108's policy. - Full workspace on all fixes: 562 passed, 0 failed (before the latest test additions). ## Notes No change for sections whose `EXEC` is set directly from an inline constant or literal; only the scalar-copy form is newly followed.
gut0to commented 2026-11-25 14:49:34 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T14:49:34Z.

Review: COMMENTED


AI-assisted review: I checked the IR write expansion and the affected EXEC path.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6059864091 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/90#pullrequestreview-6059864091). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-25T14:49:34Z. **Review:** COMMENTED --- AI-assisted review: I checked the IR write expansion and the affected EXEC path.
gut0to commented 2026-11-25 14:49:34 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T14:49:34Z.

Code review location: crates/victory-shader/src/emit/wave.rs; line 380

@@ -372,6 +374,23 @@ fn simulate(insts: &[Inst], wave: u32, saved: Value) -> Found {
             {
                 masked.push(w);
             }
+            // A copy of a constant keeps it (an `s_mov_b*` from an
+            // inline constant or from a scalar the section itself set
+            // to one); anything else drops what the scalar held.
+            for &(_, w) in &inst.writes {

Could this track each written dword separately for s_mov_b64? inst.writes contains both SGPR halves, but this loop stores the same u64 in each. For s_mov_b64 s[4:5], 1, the upper SGPR is 0; recording it as 1 can make a later s_mov_b32 exec_hi, s5 simulate the wrong lanes. Please add a 64-bit move regression case and split the tracked value into low/high halves. AI-assisted review.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4696638090 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/90#discussion_r4696638090). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-25T14:49:34Z. **Code review location:** `crates/victory-shader/src/emit/wave.rs`; line 380 ~~~~diff @@ -372,6 +374,23 @@ fn simulate(insts: &[Inst], wave: u32, saved: Value) -> Found { { masked.push(w); } + // A copy of a constant keeps it (an `s_mov_b*` from an + // inline constant or from a scalar the section itself set + // to one); anything else drops what the scalar held. + for &(_, w) in &inst.writes { ~~~~ --- Could this track each written dword separately for s_mov_b64? inst.writes contains both SGPR halves, but this loop stores the same u64 in each. For s_mov_b64 s[4:5], 1, the upper SGPR is 0; recording it as 1 can make a later s_mov_b32 exec_hi, s5 simulate the wrong lanes. Please add a 64-bit move regression case and split the tracked value into low/high halves. AI-assisted review.
ySKELLETONX commented 2026-11-25 16:35:42 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ySKELLETONX on 2026-11-25T16:35:42Z.


Tested on an RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.32015.2008, Windows 11 Pro build 26300, Rust 1.98.1, at d64ca87: cargo test -p victory-shader --lib --locked: 267 passed, 0 failed, 6 ignored, hardware dispatch tests included (main at 01aadd1: 266 passed). The PR has moved to 8b89fe8 since. Workspace tests only; not run in the title.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7168229997 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/90#issuecomment-7168229997). Originally posted by [ySKELLETONX](https://github.com/ySKELLETONX) on 2026-11-25T16:35:42Z. --- Tested on an RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.32015.2008, Windows 11 Pro build 26300, Rust 1.98.1, at `d64ca87`: `cargo test -p victory-shader --lib --locked`: **267 passed, 0 failed, 6 ignored**, hardware dispatch tests included (`main` at `01aadd1`: 266 passed). The PR has moved to `8b89fe8` since. Workspace tests only; not run in the title.

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
Belobug/VIctory-Belobug-AMD!90
No description provided.