Shaders: LDS accesses past the program's allocation read 0 and drop writes (#1870) #1949
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!1949
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1949/head"
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?
@wwwwwwww3333333 on GitHub · 2026-11-25 01:38 UTC · original
wwwwwwww3333333:fix/lds-bounds→main· +89 −14 · 2 files · 1 commits · merged 2026-11-25 21:52 UTCFixes #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
@Headache3318 on GitHub · 2026-11-25 02:03 UTC · original
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.
@BaggyALPHA on GitHub · 2026-11-25 02:48 UTC · original
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).
@Marvisak on GitHub · 2026-11-25 08:20 UTC · original
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
@sinan-cmyk on GitHub · 2026-11-25 11:09 UTC · original
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).
@wwwwwwww3333333 on GitHub · 2026-11-26 02:28 UTC · original
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.