Shaders: LDS accesses past the program's allocation read 0 and drop writes (#1870) #1947
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1949"
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 wwwwwwww3333333 on 2026-11-25T01:38:55Z.
Fixes #1870.
The DS lowering took LDS addresses as in bounds. On the host an out-of-bounds group-shared index is undefined behavior. On an RX 6750 XT the write is kept and reads back (306 of 340 inputs), while WARP returns 0.
Now each LDS dword access carries "inside the program's LDS":
The address stays
addr + offsetwrapping at 32 bits, as LLVM's DS offset folding assumes on GFX7+. The alignment part of the shortcut stays: I found nothing saying which alignment mode the console runs in.Tests (RX 6750 XT, Windows 11, Rust 1.98.1 MSVC, on
42363ab):lds_out_of_bounds_reads_zero_and_drops_writes(3 probes) fails on main on hardware and passes with this on hardware and WARP.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.Unit tests only, no game files.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-25T02:03:06Z.
Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head
25f6c55applied cleanly onto currentmainccfb029.cargo test -p victory-shader --locked: 144 passed, 0 failed, 2 ignored. All tests pass. The newlds_out_of_bounds_reads_zero_and_drops_writestest is GPU-specific (requires dxil.dll/WARP) and is skipped on Linux.cargo clippy -p victory-shader --all-targets -- -D warnings: 4 pre-existing errors in test code (fail identically on mainccfb029). The PR introduces no new clippy warnings.Not tested: Windows MSVC build, the title itself. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by BaggyALPHA on 2026-11-25T02:48:07Z.
Independent Windows validation on RTX 3080 (driver 621.24), with
25f6c55applied to upstream940d32f.lds_out_of_bounds_reads_zero_and_drops_writespassed in three runs. The test reported both hardware and WARP in every run. All three probes checked 340 inputs each, with zero CPU-model mismatches on either backend and zero hardware/WARP differences.cargo test -p victory-shader --locked --lib semantics_tests::lds -- --test-threads=1: 2 passed, 0 failed.This was focused synthetic coverage. No game files were used. AI-assisted (OpenAI Codex).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:14:08Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. LDS accesses past the program's allocation read 0 and drop writes — out-of-bounds LDS safety; hardware-verification worthwhile on Windows.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:20:07Z.
Automated triage for the maintainers.
Merge candidate.
The PR adds a bounds check against the program's LDS (
s.lds_dwords) to the DS lowering incrates/victory-shader/src/emit/lower.rs. Reads outside it give 0. Stores, byte/half stores and atomics run only where both the lane guard and the bounds check hold. A returning atomic gives 0 to active lanes that are out of bounds, and lanes outside EXEC keep their old register. The host index is clamped, so it never leaves the array.main's own shortcut comment already described the console behaviour ("out-of-bounds console accesses read 0 and drop writes"). On the host, an out-of-bounds groupshared index is undefined, and the issue shows the hardware and WARP giving different results. I checked how the guards are combined in the read, read2, byte/half, store and atomic paths, and theoutsidevalue for guarded atomics. For compute,lds_dwordsis the hardware allocation (lds_bytes(), in 512-byte units). One small open point: for mesh programs it isms.lds_bytesrounded only to dwords, so an access just past the declared size but inside what the hardware actually allocates would now read 0. The newlds_out_of_bounds_reads_zero_and_drops_writeschecks against the CPU model on both hardware and WARP. Fixes #1870.CI: no check runs reported for this head. Two contributors report the new test passing on Windows (RTX 3080, hardware and WARP).
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T11:09:49Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
25f6c55aontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
upstream-sync referenced this pull request2026-11-25 15:04:06 +00:00
Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-26T02:28:49Z.
Thanks for the review. You are right about mesh programs:
lds_dwordsthere is the record'sRECORD_LDSrounded to dwords, while compute uses the hardware allocation fromCOMPUTE_PGM_RSRC2(512-byte granules).I left it as is on purpose for now, for three reasons. I don't know which granule the console allocates mesh LDS in. In NGG the space past the program's LDS also holds the vertex and primitive data, so it may not be free for the program. And rounding up raises the groupshared size we report to the host, which counts against the mesh shader limits, so programs near the limit could stop validating.
If someone with a dump can share two counts, they would settle it without any shader data: how many mesh programs have
lds_bytesthat is not a multiple of 512, and how many would go over the host's mesh groupshared limit if rounded up. If the first is 0, nothing changes. If it isn't and the second is 0, I'll send the rounding as a small follow-up with a test.