Shaders: out-of-range relative VGPR reads return v0 #3602

Open
github-bot wants to merge 1 commit from github-bot/gh-3602 into main AGit
Owner

@⁠Moon0755 on GitHub · 2026-11-27 20:13 UTC · original
Moon0755:fix/movrels-oob-v0 → main · +29 −2 · 4 files · 1 commits · open

Per AMD RDNA2 ISA §3.6.1 (Out-of-Range behavior: vgpr >= vgpr_size -> VGPR0 is used), an out-of-range source VGPR index in a relative move (v_movrels_b32, v_movrelsd_b32, v_movrelsd_2_b32) reads v0 rather than constant 0. On main, Lower::valu initialized the dynamic select chain with 0 and ir.rs did not record a read dependency on v0.

Changes

  • crates/victory-shader/src/emit/lower.rs (520,768 bytes / +205 vs main, 3,520 bytes below the 524,288 limit):
    • Initialize the indexed_src select chain from inst.read(Reg::V(0)) when present (falling back to 0 only if absent).
  • crates/victory-shader/src/ir.rs (effects):
    • Add (Reg::V(0), NONE) to r for src_indexed moves only when *reg != 0 and m0_max.is_none_or(|m| u16::from(*reg) + u16::from(m) >= vgprs), matching indexed's vgprs bound and avoiding spurious v0 dependencies on bounded in-range moves or duplicate v0 entries when sreg == 0.
  • crates/victory-shader/src/range.rs:
    • Update a_bound_must_survive_what_the_bounded_moves_write to expect v0 in the unbounded (N = 4) case while keeping the bounded (N = 6) case unchanged.
  • crates/victory-shader/src/emit/valu_tests.rs:
    • Added movrels_outside_the_register_array_reads_v0 using M0 = 255 (v[5 + 255] = v[260], independent of the #1340 M0[7:0] width question).

Verification

  • Fork CI control (test only on main): https://github.com/Moon0755/VIctory/actions/runs/46061365377 (failure — solely on movrels_outside_the_register_array_reads_v0: left: 0, right: 3405691582)
  • Fork CI fix (gemini/ci-movrels-oob-v0, 2abede7): https://github.com/Moon0755/VIctory/actions/runs/46061360162 (success — full workspace CI + both Clippy builds clean)
  • Local verification (2abede7): movrels_outside_the_register_array_reads_v0 (1/1), relative_moves (2/2), range::tests:: (3/3), both Clippy configs, and cargo xtask policy (191 files ok) clean.
  • Not tested: M0[7:0] width dispute (#1340), separate runtime tests for v_movrelsd_b32/v_movrelsd_2_b32/v_swaprel_b32, v_movreld OOB write drop, dxil.dll 1.7, game files. Synthetic tests only (AI-assisted).

— Devin & Neon

**@⁠Moon0755** on GitHub · 2026-11-27 20:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/3602) `Moon0755:fix/movrels-oob-v0` → `main` · +29 −2 · 4 files · 1 commits · open Per AMD RDNA2 ISA §3.6.1 (*Out-of-Range behavior*: `vgpr >= vgpr_size` -> `VGPR0` is used), an out-of-range source VGPR index in a relative move (`v_movrels_b32`, `v_movrelsd_b32`, `v_movrelsd_2_b32`) reads `v0` rather than constant `0`. On `main`, `Lower::valu` initialized the dynamic select chain with `0` and `ir.rs` did not record a read dependency on `v0`. ### Changes - **`crates/victory-shader/src/emit/lower.rs`** (`520,768` bytes / `+205` vs `main`, `3,520` bytes below the `524,288` limit): - Initialize the `indexed_src` select chain from `inst.read(Reg::V(0))` when present (falling back to `0` only if absent). - **`crates/victory-shader/src/ir.rs`** (`effects`): - Add `(Reg::V(0), NONE)` to `r` for `src_indexed` moves only when `*reg != 0` and `m0_max.is_none_or(|m| u16::from(*reg) + u16::from(m) >= vgprs)`, matching `indexed`'s `vgprs` bound and avoiding spurious `v0` dependencies on bounded in-range moves or duplicate `v0` entries when `sreg == 0`. - **`crates/victory-shader/src/range.rs`**: - Update `a_bound_must_survive_what_the_bounded_moves_write` to expect `v0` in the unbounded (`N = 4`) case while keeping the bounded (`N = 6`) case unchanged. - **`crates/victory-shader/src/emit/valu_tests.rs`**: - Added `movrels_outside_the_register_array_reads_v0` using `M0 = 255` (`v[5 + 255] = v[260]`, independent of the `#1340` `M0[7:0]` width question). ### Verification - **Fork CI control** (test only on `main`): https://github.com/Moon0755/VIctory/actions/runs/46061365377 (`failure` — solely on `movrels_outside_the_register_array_reads_v0`: `left: 0`, `right: 3405691582`) - **Fork CI fix** (`gemini/ci-movrels-oob-v0`, `2abede7`): https://github.com/Moon0755/VIctory/actions/runs/46061360162 (`success` — full workspace CI + both Clippy builds clean) - **Local verification** (`2abede7`): `movrels_outside_the_register_array_reads_v0` (`1/1`), `relative_moves` (`2/2`), `range::tests::` (`3/3`), both Clippy configs, and `cargo xtask policy` (`191 files ok`) clean. - **Not tested**: `M0[7:0]` width dispute (`#1340`), separate runtime tests for `v_movrelsd_b32`/`v_movrelsd_2_b32`/`v_swaprel_b32`, `v_movreld` OOB write drop, `dxil.dll` 1.7, game files. Synthetic tests only (AI-assisted). — Devin & Neon
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:14:43 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 20:29 UTC · original

Verification of head 2abede7e against base main 63bcca43 (heads/base re-checked unchanged before testing).

Hardware: Windows 11 Pro 26200, WARP only (no physical GPU); dxil.dll 1.8.2502.11 (SDK 26100).

Tests (cargo test -p victory-shader): head 299 passed / 4 failed / 3 ignored; base 298 passed / 4 failed / 3 ignored. The 4 failures are identical on base and head (synthetic_tests that need a wave-32 pipeline or hardware-specific gather behaviour, unsupported on WARP), pre-existing and unrelated. The new test movrels_outside_the_register_array_reads_v0 and the updated range test pass on head.

Control: base plus only this PR's test hunks (valu_tests.rs, range.rs): both movrels_outside_the_register_array_reads_v0 and range::tests::a_bound_must_survive_what_the_bounded_moves_write fail (6 failed vs 4 on base), so the tests detect the missing behaviour.

Clippy: cargo clippy -p victory-shader --all-targets -- -D warnings clean on head.

Review: no defects found. lower.rs starts the select chain from v0 so an index past the program's registers reads v0. ir.rs adds a v0 read dependency when the source is M0-indexed, reg != 0 and the bound is unknown or can reach the end of the VGPRs, which is conservative and correct. A harmless over-approximation applies to v_swaprel_b32, which shares the dependency but has no lowering change. The range.rs expectation adds v0 to the second index's reads, consistent with that.

Size: lower.rs 520,768 bytes (main 520,563), under 524,288. Textual merge of #3597 + #3602: clean, 521,714; with #3587: 522,154; with #2997 too: clean but 525,571, 1,283 bytes over the limit.

AI-assisted (Claude Sonnet 5.5)

**@⁠oni-swr** on GitHub · 2026-11-27 20:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3602#issuecomment-7227549741) Verification of head 2abede7e against base main 63bcca43 (heads/base re-checked unchanged before testing). **Hardware:** Windows 11 Pro 26200, WARP only (no physical GPU); dxil.dll 1.8.2502.11 (SDK 26100). **Tests (`cargo test -p victory-shader`):** head 299 passed / 4 failed / 3 ignored; base 298 passed / 4 failed / 3 ignored. The 4 failures are identical on base and head (synthetic_tests that need a wave-32 pipeline or hardware-specific gather behaviour, unsupported on WARP), pre-existing and unrelated. The new test `movrels_outside_the_register_array_reads_v0` and the updated `range` test pass on head. **Control:** base plus only this PR's test hunks (valu_tests.rs, range.rs): both `movrels_outside_the_register_array_reads_v0` and `range::tests::a_bound_must_survive_what_the_bounded_moves_write` fail (6 failed vs 4 on base), so the tests detect the missing behaviour. **Clippy:** `cargo clippy -p victory-shader --all-targets -- -D warnings` clean on head. **Review:** no defects found. lower.rs starts the select chain from v0 so an index past the program's registers reads v0. ir.rs adds a v0 read dependency when the source is M0-indexed, reg != 0 and the bound is unknown or can reach the end of the VGPRs, which is conservative and correct. A harmless over-approximation applies to v_swaprel_b32, which shares the dependency but has no lowering change. The range.rs expectation adds v0 to the second index's reads, consistent with that. **Size:** lower.rs 520,768 bytes (main 520,563), under 524,288. Textual merge of #3597 + #3602: clean, 521,714; with #3587: 522,154; with #2997 too: clean but 525,571, 1,283 bytes over the limit. AI-assisted (Claude Sonnet 5.5)
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3602/head:github-bot/gh-3602'
git switch 'github-bot/gh-3602'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3602'
git switch 'github-bot/gh-3602'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3602'
git switch 'github-bot/gh-3602'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3602'
git switch 'main'
git merge --squash 'github-bot/gh-3602'
git switch 'main'
git merge --ff-only 'github-bot/gh-3602'
git switch 'main'
git merge 'github-bot/gh-3602'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!3602
No description provided.