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

Open
Moon0755 wants to merge 1 commit from upstream-pr/3602 into main
Moon0755 commented 2026-11-27 20:13:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-27T20:13:47Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5532545121 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3602). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-27T20:13:47Z. --- 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
oni-swr commented 2026-11-27 20:29:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T20:29:04Z.


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)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7227549741 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3602#issuecomment-7227549741). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-27T20:29:04Z. --- 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)
kilolimaVI commented 2026-11-28 15:59:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T15:59:45Z.


AMD Radeon 780M (RDNA3) + WARP, Windows 11, head 2abede7.

  • Before (main 63bcca4 + this PR's test): fails on the hardware adapter. An out-of-range v_movrels source reads 0 instead of v0 (0xCAFEBABE).
  • After: passes, 5 of 5 runs.
  • Full suite (victory-shader + victory-gpu --features diagnostics): 552 passed.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7241892563 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3602#issuecomment-7241892563). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-28T15:59:45Z. --- AMD Radeon 780M (RDNA3) + WARP, Windows 11, head `2abede7`. - **Before** (main `63bcca4` + this PR's test): fails on the hardware adapter. An out-of-range `v_movrels` source reads 0 instead of v0 (`0xCAFEBABE`). - **After:** passes, 5 of 5 runs. - Full suite (`victory-shader` + `victory-gpu --features diagnostics`): 552 passed. AI-assisted (Claude).
upipibi commented 2026-11-28 17:37:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T17:37:49Z.


NVIDIA row for this PR: it passes on Ampere. Both of its tests fail on this card without the fix, at the same value as on the 780M and in the description's fork CI control.

RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head 2abede7 on main 63bcca4 (one commit, clean).

  • cargo test --locked -p victory-shader --lib -- movrels_outside_the_register_array_reads_v0 a_bound_must_survive_what_the_bounded_moves_write --nocapture: 2 passed, 0 failed, 0 ignored, in 3 of 3 runs. In each run the GPU test checks this card and then WARP. Three more runs with VICTORY_WARP=1, where every device is WARP, also passed. range::tests::a_bound_must_survive_what_the_bounded_moves_write is CPU-only (it checks the reads that ir.rs records), so the card plays no part in it.

  • Negative control: main's emit/lower.rs and ir.rs, with the test hunks in valu_tests.rs and range.rs kept (the range.rs hunk is inside mod tests). git diff --stat HEAD: 2 files, 1 insertion, 13 deletions. git diff --stat 63bcca4: only valu_tests.rs (15 insertions) and range.rs (1 insertion, 1 deletion). Result: 0 passed, 2 failed, in 3 of 3 runs on hardware and 3 of 3 with VICTORY_WARP=1:

    • movrels_outside_the_register_array_reads_v0: hardware: an out-of-range source is v0, left: 0, right: 3405691582 (0xCAFEBABE). With VICTORY_WARP=1 the label is still hardware, but that run is WARP too, and it also reads 0. In the hardware runs the assertion stops at this card's leg, so WARP's value comes from the VICTORY_WARP=1 runs.
    • a_bound_must_survive_what_the_bounded_moves_write: index in v4, left: [8, 9, 10, 11, 12, 13, 14, 15, 1], right: [8, 9, 10, 11, 12, 13, 14, 15, 0, 1]. So main records no v0 read for the unbounded move, the same in every run.

    That is the left: 0, right: 3405691582 of the description's fork CI control and the 0 instead of 0xCAFEBABE on kilolimaVI's 780M. On main, the RTX 3070 and WARP both read 0 for v[5 + 255], and with the PR both read v0.

  • cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index:

    • this PR: 299 passed, 3 failed, 3 ignored;
    • main 63bcca4: 298 passed, 3 failed, 3 ignored (earlier run on this card).

    The PR adds one test. The 3 failures are the same on both: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and synthetic_tests::gathers_at_a_level_match_the_hardware. They come from the structured-view raw read on NVIDIA (#2178, #2323, issue #1835). The skipped test crashes the binary on this card (open issue #2571).

  • The PR does not touch victory-gpu, so I did not run its lib suite.

Nothing NVIDIA-specific: the lowering picks v0 or 0 before the driver sees it, so the 3070 gives the same result as the 780M and WARP on main and with the PR.

Not tested:

  • the cases the description leaves out: the M0[7:0] width question (#1340), v_movrelsd_b32, v_movrelsd_2_b32 and v_swaprel_b32 on the GPU, and the dropped v_movreld write past the end;
  • M0 values other than 255, and bounded moves that only reach the end of the VGPRs;
  • the merges with #3597, #3587 or #2997 (oni-swr's lower.rs size note);
  • clippy, a title run.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7243163982 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3602#issuecomment-7243163982). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-28T17:37:49Z. --- NVIDIA row for this PR: it passes on Ampere. Both of its tests fail on this card without the fix, at the same value as on the 780M and in the description's fork CI control. RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head `2abede7` on main `63bcca4` (one commit, clean). - `cargo test --locked -p victory-shader --lib -- movrels_outside_the_register_array_reads_v0 a_bound_must_survive_what_the_bounded_moves_write --nocapture`: 2 passed, 0 failed, 0 ignored, in 3 of 3 runs. In each run the GPU test checks this card and then WARP. Three more runs with `VICTORY_WARP=1`, where every device is WARP, also passed. `range::tests::a_bound_must_survive_what_the_bounded_moves_write` is CPU-only (it checks the reads that `ir.rs` records), so the card plays no part in it. - Negative control: main's `emit/lower.rs` and `ir.rs`, with the test hunks in `valu_tests.rs` and `range.rs` kept (the `range.rs` hunk is inside `mod tests`). `git diff --stat HEAD`: 2 files, 1 insertion, 13 deletions. `git diff --stat 63bcca4`: only `valu_tests.rs` (15 insertions) and `range.rs` (1 insertion, 1 deletion). Result: 0 passed, 2 failed, in 3 of 3 runs on hardware and 3 of 3 with `VICTORY_WARP=1`: - `movrels_outside_the_register_array_reads_v0`: `hardware: an out-of-range source is v0`, `left: 0`, `right: 3405691582` (`0xCAFEBABE`). With `VICTORY_WARP=1` the label is still `hardware`, but that run is WARP too, and it also reads `0`. In the hardware runs the assertion stops at this card's leg, so WARP's value comes from the `VICTORY_WARP=1` runs. - `a_bound_must_survive_what_the_bounded_moves_write`: `index in v4`, `left: [8, 9, 10, 11, 12, 13, 14, 15, 1]`, `right: [8, 9, 10, 11, 12, 13, 14, 15, 0, 1]`. So main records no `v0` read for the unbounded move, the same in every run. That is the `left: 0`, `right: 3405691582` of the description's fork CI control and the 0 instead of `0xCAFEBABE` on kilolimaVI's 780M. On main, the RTX 3070 and WARP both read 0 for `v[5 + 255]`, and with the PR both read v0. - `cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index`: - this PR: 299 passed, 3 failed, 3 ignored; - main `63bcca4`: 298 passed, 3 failed, 3 ignored (earlier run on this card). The PR adds one test. The 3 failures are the same on both: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` and `synthetic_tests::gathers_at_a_level_match_the_hardware`. They come from the structured-view raw read on NVIDIA (#2178, #2323, issue #1835). The skipped test crashes the binary on this card (open issue #2571). - The PR does not touch `victory-gpu`, so I did not run its lib suite. Nothing NVIDIA-specific: the lowering picks v0 or 0 before the driver sees it, so the 3070 gives the same result as the 780M and WARP on main and with the PR. Not tested: - the cases the description leaves out: the `M0[7:0]` width question (#1340), `v_movrelsd_b32`, `v_movrelsd_2_b32` and `v_swaprel_b32` on the GPU, and the dropped `v_movreld` write past the end; - `M0` values other than 255, and bounded moves that only reach the end of the VGPRs; - the merges with #3597, #3587 or #2997 (oni-swr's `lower.rs` size note); - clippy, a title run. AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3602:upstream-pr/3602'
git switch 'upstream-pr/3602'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3602'
git switch 'upstream-pr/3602'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3602'
git switch 'upstream-pr/3602'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3602'
git switch 'main'
git merge --squash 'upstream-pr/3602'
git switch 'main'
git merge --ff-only 'upstream-pr/3602'
git switch 'main'
git merge 'upstream-pr/3602'
git push origin 'main'
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!3602
No description provided.