Shaders: out-of-range relative VGPR reads return v0 #3602
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3602"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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->VGPR0is used), an out-of-range source VGPR index in a relative move (v_movrels_b32,v_movrelsd_b32,v_movrelsd_2_b32) readsv0rather than constant0. Onmain,Lower::valuinitialized the dynamic select chain with0andir.rsdid not record a read dependency onv0.Changes
crates/victory-shader/src/emit/lower.rs(520,768bytes /+205vsmain,3,520bytes below the524,288limit):indexed_srcselect chain frominst.read(Reg::V(0))when present (falling back to0only if absent).crates/victory-shader/src/ir.rs(effects):(Reg::V(0), NONE)torforsrc_indexedmoves only when*reg != 0andm0_max.is_none_or(|m| u16::from(*reg) + u16::from(m) >= vgprs), matchingindexed'svgprsbound and avoiding spuriousv0dependencies on bounded in-range moves or duplicatev0entries whensreg == 0.crates/victory-shader/src/range.rs:a_bound_must_survive_what_the_bounded_moves_writeto expectv0in the unbounded (N = 4) case while keeping the bounded (N = 6) case unchanged.crates/victory-shader/src/emit/valu_tests.rs:movrels_outside_the_register_array_reads_v0usingM0 = 255(v[5 + 255] = v[260], independent of the#1340M0[7:0]width question).Verification
main): https://github.com/Moon0755/VIctory/actions/runs/46061365377 (failure— solely onmovrels_outside_the_register_array_reads_v0:left: 0,right: 3405691582)gemini/ci-movrels-oob-v0,2abede7): https://github.com/Moon0755/VIctory/actions/runs/46061360162 (success— full workspace CI + both Clippy builds clean)2abede7):movrels_outside_the_register_array_reads_v0(1/1),relative_moves(2/2),range::tests::(3/3), both Clippy configs, andcargo xtask policy(191 files ok) clean.M0[7:0]width dispute (#1340), separate runtime tests forv_movrelsd_b32/v_movrelsd_2_b32/v_swaprel_b32,v_movreldOOB write drop,dxil.dll1.7, game files. Synthetic tests only (AI-assisted).— Devin & Neon
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T20:29:04Z.
Verification of head
2abede7eagainst base main63bcca43(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 testmovrels_outside_the_register_array_reads_v0and the updatedrangetest pass on head.Control: base plus only this PR's test hunks (valu_tests.rs, range.rs): both
movrels_outside_the_register_array_reads_v0andrange::tests::a_bound_must_survive_what_the_bounded_moves_writefail (6 failed vs 4 on base), so the tests detect the missing behaviour.Clippy:
cargo clippy -p victory-shader --all-targets -- -D warningsclean 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)
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T15:59:45Z.
AMD Radeon 780M (RDNA3) + WARP, Windows 11, head
2abede7.63bcca4+ this PR's test): fails on the hardware adapter. An out-of-rangev_movrelssource reads 0 instead of v0 (0xCAFEBABE).victory-shader+victory-gpu --features diagnostics): 552 passed.AI-assisted (Claude).
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
2abede7on main63bcca4(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 withVICTORY_WARP=1, where every device is WARP, also passed.range::tests::a_bound_must_survive_what_the_bounded_moves_writeis CPU-only (it checks the reads thatir.rsrecords), so the card plays no part in it.Negative control: main's
emit/lower.rsandir.rs, with the test hunks invalu_tests.rsandrange.rskept (therange.rshunk is insidemod tests).git diff --stat HEAD: 2 files, 1 insertion, 13 deletions.git diff --stat 63bcca4: onlyvalu_tests.rs(15 insertions) andrange.rs(1 insertion, 1 deletion). Result: 0 passed, 2 failed, in 3 of 3 runs on hardware and 3 of 3 withVICTORY_WARP=1:movrels_outside_the_register_array_reads_v0:hardware: an out-of-range source is v0,left: 0,right: 3405691582(0xCAFEBABE). WithVICTORY_WARP=1the label is stillhardware, but that run is WARP too, and it also reads0. In the hardware runs the assertion stops at this card's leg, so WARP's value comes from theVICTORY_WARP=1runs.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 nov0read for the unbounded move, the same in every run.That is the
left: 0,right: 3405691582of the description's fork CI control and the 0 instead of0xCAFEBABEon kilolimaVI's 780M. On main, the RTX 3070 and WARP both read 0 forv[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: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_zerosandsynthetic_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:
M0[7:0]width question (#1340),v_movrelsd_b32,v_movrelsd_2_b32andv_swaprel_b32on the GPU, and the droppedv_movreldwrite past the end;M0values other than 255, and bounded moves that only reach the end of the VGPRs;lower.rssize note);AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.