shader: pin the lockstep rewrites with unit tests #478

Open
opened 2026-11-27 21:58:20 +00:00 by AnastasisKon · 4 comments
AnastasisKon commented 2026-11-27 21:58:20 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T21:58:20Z.


What

crates/victory-shader/src/emit/lockstep.rs rewrites a wave's instructions before DXIL is emitted, so the two host waves of a console wave arrive together: a mask branch becomes a 64-bit compare with zero plus an SCC branch of the same distance, and a group barrier goes around each LDS write (never around a read). A change there is invisible until a shader is refused or lowered wrongly, and nothing pins the rewrites.

What this pins

  • branches: s_cbranch_execz becoming s_cmp_eq_u64 over the EXEC pair plus s_cbranch_scc1, the compare writing SCC, the branch reading it, and the original branch distance and opcode kept; s_cbranch_execnz, s_cbranch_vccz and s_cbranch_vccnz picking the matching compare over EXEC or VCC;
  • lds_barriers: a barrier around each LDS write and none around a read;
  • a branch already on SCC, and a branch that is not on a mask, left untouched.

Test-only: hand-assembled GFX10 words (gfx_refusal_tests.rs's approach, built through ir::build), no game data, no behaviour change, no new dependencies.

How it was tested

  • cargo test -p victory-shader (new unit tests)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy
  • Shader corpus sweep: not applicable, no translation changes.
  • Game run: not needed.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6655104384 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/478). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T21:58:20Z. --- ## What `crates/victory-shader/src/emit/lockstep.rs` rewrites a wave's instructions before DXIL is emitted, so the two host waves of a console wave arrive together: a mask branch becomes a 64-bit compare with zero plus an SCC branch of the same distance, and a group barrier goes around each LDS write (never around a read). A change there is invisible until a shader is refused or lowered wrongly, and nothing pins the rewrites. ## What this pins - `branches`: `s_cbranch_execz` becoming `s_cmp_eq_u64` over the EXEC pair plus `s_cbranch_scc1`, the compare writing SCC, the branch reading it, and the original branch distance and opcode kept; `s_cbranch_execnz`, `s_cbranch_vccz` and `s_cbranch_vccnz` picking the matching compare over EXEC or VCC; - `lds_barriers`: a barrier around each LDS write and none around a read; - a branch already on SCC, and a branch that is not on a mask, left untouched. Test-only: hand-assembled GFX10 words (`gfx_refusal_tests.rs`'s approach, built through `ir::build`), no game data, no behaviour change, no new dependencies. ## How it was tested - `cargo test -p victory-shader` (new unit tests) - `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy` - Shader corpus sweep: not applicable, no translation changes. - Game run: not needed.
AnastasisKon commented 2026-11-27 21:58:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T21:58:29Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7228916950 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/478#issuecomment-7228916950). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T21:58:29Z. --- /claim
github-actions[bot] commented 2026-11-27 21:58:45 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T21:58:45Z.


Claimed by @AnastasisKon. Open a draft pull request with Refs #478 in its description within 24 hours, or the claim expires.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7228920693 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/478#issuecomment-7228920693). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T21:58:45Z. --- Claimed by @AnastasisKon. Open a draft pull request with `Refs #478` in its description within 24 hours, or the claim expires.
AnastasisKon commented 2026-11-28 12:44:44 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T12:44:44Z.


/release - done without a PR: on branch vibe/lockstep-rewrite-tests-4f9c68, in my fork's main. The lockstep rewrites are pinned by a_branch_on_scc_or_a_non_mask_branch_is_untouched, an_execz_branch_becomes_a_compare_with_zero_and_an_scc_branch and execnz_vccz_and_vccnz_use_the_matching_compare.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7239437355 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/478#issuecomment-7239437355). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T12:44:44Z. --- /release - done without a PR: on branch `vibe/lockstep-rewrite-tests-4f9c68`, in my fork's `main`. The lockstep rewrites are pinned by `a_branch_on_scc_or_a_non_mask_branch_is_untouched`, `an_execz_branch_becomes_a_compare_with_zero_and_an_scc_branch` and `execnz_vccz_and_vccnz_use_the_matching_compare`.
github-actions[bot] commented 2026-11-28 12:44:53 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T12:44:53Z.


Released. This issue is free to claim.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7239438921 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/478#issuecomment-7239438921). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T12:44:53Z. --- Released. This issue is free to claim.
Sign in to join this conversation.
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
LakshanSivakumar/Native-Victory-macOS#478
No description provided.