Shaders: LDS accesses outside the program's allocation read 0 and drop their writes #1769
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1769
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1769"
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?
@Impre-visible on GitHub · 2026-11-24 22:15 UTC · original
Impre-visible:fix/lds-out-of-bounds→main· +27 −0 · 2 files · 1 commits · openWhat
Lower::dsincrates/victory-shader/src/emit/lower.rstook every LDS address as in bounds (its own comment called it a shortcut: "out-of-bounds console accesses read 0 and drop writes"). This gives LDS accesses that console behaviour:lds_dwords, unsigned);A small
and_guardhelper narrows a lane guard. One test,lds_accesses_are_bounded_by_the_allocation, lowers a write, a read and an atomic with a returned value and checks that each got its bound (a test-only counter besidenonuniform_handles).Why it matters
A title compute program can be written for one thread group and still be dispatched with several: its LDS addresses then come from the global thread id, and in every group but the first they lie far outside the allocation. On the console that is harmless. On the host the writes land in whatever group-shared variable sits next to the LDS array.
With a wave64-on-32-lane implementation that keeps its own synchronisation state in group-shared memory (#1433's console flow:
phase,arrived,finishednext tolds), those stray writes can corrupt that state, and its wait loops are not covered by the loop limit. On my machine this is what ended every run at world entry.Measured
Linux, Wine (GE-Proton11-6) + vkd3d-proton, GTX 1660 6 GB (32-lane waves), NVIDIA 620.73.04. Test tree: #1433 with #1492 merged by hand plus #1077 #1175 #523 #530 #1040 #1406 #542 #1056 #1392 #1516 #1388 #1189 #1523 (details in my comment on #1581).
Without this change, in that tree:
NVRM: Xid 109 ... CTX SWITCH TIMEOUT16 to 28 s before the title stops, GPU at 100 % for about 8 s first, VIctory then waiting forever on the submission's fence.32x1x1dispatch of a small program that uses LDS.VICTORY_SHADER_LOOP_LIMIT=64does not help, which fits a spin outside the program's own loops.With this change, same tree, nothing skipped, 3 runs:
So the immediate hang is gone; the world is not stable yet for other reasons.
Validity of what is emitted: on this branch (plus #226's two lines applied locally, without which main's SPIR-V fails on NVIDIA anyway), vkd3d-proton converted 1,484 modules in a run into the world and
spirv-valaccepts all of them. (My first attempt used the float predicateULTinstead ofIULTfor the bound, which the unit tests did not catch andspirv-valdid; that is fixed here.)Not tested
cargo test -p victory-shader --lib: 97 passed, 1 ignored. Builds forx86_64-pc-windows-msvcwith and without--features diagnostics.cargo clippy: not run here.🤖 Generated with Claude Code
683ad7a) into fix/lds-out-of-bounds cd90d74741940d32f) into fix/lds-out-of-bounds 38e1d553e338e1d553e3toc2ee29ac05@DesertGamer on GitHub · 2026-11-24 22:16 UTC · original
VIctory V2: community PRs, merged and tested
Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.
Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).
⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.
Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2
Unofficial community fork of Marvisak/VIctory, GPL-3.0.
@rminzao on GitHub · 2026-11-24 23:09 UTC · original
Gap with the sub-dword LDS paths
Besides the rebase conflict already mentioned, the bound doesn't reach every LDS address:
mainhas byte/halfword LDS lowering (0b35b7f). Those read and write paths calldword(self, offset)and need the newinsideresult applied too. The PR body still calls those accesses "still unsupported", which is out of date.lds_straddle, which builds the following dword (index + 1) directly instead of going throughdword. With both PRs merged, a halfword at byte 3 of the last dword still reads or writes past the allocation, the corruption this PR is meant to stop. Whichever merges second needs aninsidecheck on that second element.The new test only counts calls to the closure, so it can't catch a wrong predicate (as with the
ULT/IULTmix-up that slipped through). A test with an address just past the allocation, checking that it reads 0 and the write is dropped, would catch that.Static review (AI-assisted), read against
mainat70564ae; nothing was run on a GPU.@Impre-visible on GitHub · 2026-11-25 00:17 UTC · original
Merged today's
maininto this branch.mainadded byte and halfword LDS reads and writes through the samedwordhelper, so they now get the same bound: a read outside the allocation gives 0, the atomics of a write outside are skipped.cargo test -p victory-shader --lib: 120 passed, 1 ignored; builds forx86_64-pc-windows-msvcwith and without--features diagnostics. The unit test still covers the dword forms only, and the merged result has not been run in the title yet.🤖 Generated with Claude Code
@jules47800 on GitHub · 2026-11-25 01:25 UTC · original
Hardware check of this PR with the device test from #1870. AMD RX 6600 XT (RDNA2, driver 32.0.21045.29003) and WARP, Windows 11, Rust 1.98.1 MSVC, DXC 1.9.2609 validator. Synthetic programs only, no game files.
This PR's test checks the lowering (a counter). #1870 has a test that runs the translated program on the device:
lds_out_of_bounds_reads_zero_and_drops_writes. It covers b32 write/read at +512 and +65532,ds_read_i8at +600,ds_write_b8at +513,ds_read2_b32with offset1 800 bytes,ds_add_rtn_u32at +512, a 32-bit wrap back inside (own - 16, offset 16), and a returning atomic under a partial EXEC.42363ab+ that testcd90d74+ that test42363ab+ that testcargo test -p victory-shader --lib: 248 passed, 0 failed, 3 ignored; both clippy configurations clean with-D warnings#1870 measured the same 306/340 on an RX 6750 XT, so this isn't specific to one card. #1870 is the same fix written separately. If this PR lands, #1870 can close. Its test is worth bringing along: it is about 40 lines in
semantics_tests.rs, and the existingdshelper only needs itsoffsetwidened tou16to encode offset1.Not checked: the title (no game files here), and the
lds_straddlepath from #1795 raised above.@Marvisak on GitHub · 2026-11-25 02:17 UTC · original · edited 2026-11-26 07:21 UTC
Automated triage for the maintainers.
Proposed close: already in
main. Thanks for rebuilding the branch and saying so plainly. As you note, #1949 put the LDS bound intomain. Thedwordhelper inLower::ds(crates/victory-shader/src/emit/lower.rs) compares the dword index withlds_dwords(IULT), reads 0 and drops writes outside the allocation.mainalso has the device testlds_out_of_bounds_reads_zero_and_drops_writes(emit/semantics_tests.rs), which checks the actual behaviour on hardware and WARP.What's left here is a test-only counter (
lds_bounds) and a test that counts how many times the bound is emitted. It doesn't check what the bound does, whichmain's device test already covers. So there isn't enough left to merge.This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label
triage: proposed close.CI: passing.
Generated by Claude Code
@Impre-visible on GitHub · 2026-11-25 05:00 UTC · original
Merged the current
main(940d32f) into this branch; it merges without conflict now. Builds forx86_64-pc-windows-msvcwith and without--features diagnostics;cargo test -p victory-shader --lib: 145 passed, 2 ignored.🤖 Generated with Claude Code
@upipibi on GitHub · 2026-11-25 05:45 UTC · original
The Windows run the Not-tested list mentions. Ran on Windows 11 with an RTX 3070 (Ampere, 32-lane waves, driver 616.56), debug build, at
38e1d55,cargo test -p victory-shader --locked: 245 passed, 3 failed, 3 ignored. The newlds_accesses_are_bounded_by_the_allocationpasses on NVIDIA. The 3 failures are #1744's NVIDIA failures onmain. Same asmainon this hardware.AI-assisted (Claude Code).
@Mericas77 on GitHub · 2026-11-25 12:25 UTC · original
NVIDIA counterpart of the RX 6600 XT check above: on an RTX 4070,
mainkeeps the out-of-bounds LDS write too, and this PR drops it.Setup: RTX 4070 (Ada, 32-lane waves), driver 621.01, Windows 11, Rust 1.100.0.
mainat940d32fand this PR at38e1d55, each with #1870'slds_out_of_bounds_reads_zero_and_drops_writesadded. Synthetic programs only, no game files.cargo test -p victory-shader --locked --lib lds_ -- --test-threads=1, 3 runs each, same result every run:main940d32f+ the testds_read_b32 [own + 512]reads backb, so the write landed. Probes 2 and 3 (b8 at +513, read2 at +800,ds_add_rtn_u32at +512, 32-bit wrap, partial EXEC) show 0 differences.lds_accesses_are_bounded_by_the_allocationandlds_bytes_and_halves_match_the_hardwarealso pass.That is the same 306/340 as on the RX 6750 XT and RX 6600 XT, so this is not AMD-specific. On NVIDIA, the stray write lands in the group-shared memory next to the array.
Full shader suite (
cargo test -p victory-shader --locked --lib -- --test-threads=1):main244 passed, 4 failed, 3 ignored; this PR 246 passed, 3 failed, 3 ignored. The 3 left are the known NVIDIA failures from #1744 (a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware). None of them is about LDS.AI-assisted.
@Impre-visible on GitHub · 2026-11-25 12:27 UTC · original
@Mericas77 thank you, that closes the gap I could not close myself: this PR had only a WARP-level test plus title runs on one NVIDIA card, and you now show on hardware that
mainkeeps the out-of-bounds write on NVIDIA as well (306/340, same as the two AMD cards) and that this branch drops it.Summary of the independent checks so far, for the maintainers:
main+ #1870's testThe hardware test that proves it is the one from #1870 (
lds_out_of_bounds_reads_zero_and_drops_writes), written by @wwwwwwww3333333, not by me. I have not copied it into this branch because it is their work. If they agree, I will add it here with their authorship kept (aCo-authored-bycommit), or the maintainers can take the lowering from either place and the test from #1870; both changes bound the same accesses the same way.🤖 Generated with Claude Code
@qtLkz on GitHub · 2026-11-25 13:14 UTC · original
Native Windows run, which the description lists as not done: RTX 4070 Ti (Ada), driver 621.01, Windows 11 Pro build 26300, Rust 1.98.1 pinned, this PR merged on main
940d32f(clean merge).cargo test -p victory-shader --lib --locked -- --nocapture --test-threads=1emit::lower::tests::lds_accesses_are_bounded_by_the_allocation ... okstride_tests,synthetic_tests::gathers_at_a_level_match_the_hardware) are the same as on plain main on this card (#2317, fixed by #2315 + #2322). Nothing new from this PR.Limit: the new test checks the lowering (one bound per LDS access), it doesn't dispatch on the GPU, and I didn't run a title. This doesn't answer the NVIDIA group-shared layout question.
AI-assisted (Claude).
@wwwwwwww3333333 on GitHub · 2026-11-26 05:48 UTC · original
@Impre-visible yes, please take
lds_out_of_bounds_reads_zero_and_drops_writesfrom #1870 into this PR. A Co-authored-by line is fine, and thanks for asking. Keeping the lowering and the test in one place makes it easier to review.@Impre-visible on GitHub · 2026-11-26 05:54 UTC · original
Rebuilt this branch on
main63bcca4. The conflict was in the LDS lowering. #1949 (the patch from #1870, thanks @wwwwwwww3333333) already bounds every LDS access the same way, so I kept main's lowering and dropped ours. Main also already haslds_out_of_bounds_reads_zero_and_drops_writes, so nothing was left to bring over from #1870.What remains is one test-only commit: a counter of the bounds the lowering emits, and
lds_accesses_are_bounded_by_the_allocation, which runs on any host (the device test is Windows-only). If that isn't wanted, this PR can close as superseded by #1949.Linux:
cargo test -p victory-shader --lib, 173 passed, 2 ignored (with main's Windows-only validator calls fenced locally, not committed). Windows target: both CI clippy runs pass.🤖 Generated with Claude Code
@catminou4 on GitHub · 2026-11-24 22:18 UTC · original · reviewed
Merge conflict with current main (
70564ae) — the LDS-allocation bounding change (and_guard + lds_accesses_are_bounded_by_the_allocation test, reads-out-of-allocation → 0 and drops) needs a rebase. The approach looks right statically: bounds are checked against the program's LDS allocation rather than a fixed size. Happy to re-test after rebase.@wwwwwwww3333333 on GitHub · 2026-11-26 08:46 UTC · original
@Impre-visible thanks for rebuilding this on
63bcca4and for checking against #1949. I ranc2ee29aon an RX 6750 XT (RDNA2, driver 32.0.21045.29003, Windows 11, Rust 1.98.1):lds_accesses_are_bounded_by_the_allocationandlds_out_of_bounds_reads_zero_and_drops_writesboth pass, and the wholevictory-shadersuite is 303 passed, 0 failed, 3 ignored (main on this machine: 302 passed, 0 failed).For what it's worth, the counter test is useful on its own: the device test for #1949 only runs on Windows, and this one also checks the lowering off Windows. Whether it stays open is the maintainer's decision, and closing it as superseded is fine by me too.
Unit tests only, no game files.
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.