Shaders: LDS accesses past the program's allocation read 0 and drop writes (#1870) #1949

Manually merged
github merged 1 commit from gh-pr/1949/head into gh-pr/1949/base 2026-11-26 04:49:44 +00:00
Owner

@⁠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 UTC

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":

  • Reads select 0 when outside.
  • Stores, byte/half stores and atomics run only where the lane guard and inside both hold.
  • Returning atomics give 0 outside; lanes EXEC leaves out keep their register.
  • The host index is clamped, so it never leaves the array.

The address stays addr + offset wrapping 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):

  • The new lds_out_of_bounds_reads_zero_and_drops_writes (3 probes) fails on main on hardware and passes with this on hardware and WARP.
  • victory-shader: 247 passed, 0 failed (main alone: 246).
  • 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

**@⁠wwwwwwww3333333** on GitHub · 2026-11-25 01:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1949) `wwwwwwww3333333:fix/lds-bounds` → `main` · +89 −14 · 2 files · 1 commits · merged 2026-11-25 21:52 UTC 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": - Reads select 0 when outside. - Stores, byte/half stores and atomics run only where the lane guard and inside both hold. - Returning atomics give 0 outside; lanes EXEC leaves out keep their register. - The host index is clamped, so it never leaves the array. The address stays `addr + offset` wrapping 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): - The new `lds_out_of_bounds_reads_zero_and_drops_writes` (3 probes) fails on main on hardware and passes with this on hardware and WARP. - victory-shader: 247 passed, 0 failed (main alone: 246). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. Unit tests only, no game files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:44 +00:00
github manually merged commit 25f6c55a2a into gh-pr/1949/base 2026-11-26 04:49:44 +00:00
Author
Owner

@⁠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 25f6c55 applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 144 passed, 0 failed, 2 ignored. All tests pass. The new lds_out_of_bounds_reads_zero_and_drops_writes test 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 main ccfb029). The PR introduces no new clippy warnings.

Not tested: Windows MSVC build, the title itself. AI-assisted.

**@⁠Headache3318** on GitHub · 2026-11-25 02:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7150259476) Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `25f6c55` applied cleanly onto current `main` `ccfb029`. - `cargo test -p victory-shader --locked`: 144 passed, 0 failed, 2 ignored. All tests pass. The new `lds_out_of_bounds_reads_zero_and_drops_writes` test 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 main `ccfb029`). The PR introduces no new clippy warnings. Not tested: Windows MSVC build, the title itself. AI-assisted.
Author
Owner

@⁠BaggyALPHA on GitHub · 2026-11-25 02:48 UTC · original

Independent Windows validation on RTX 3080 (driver 621.24), with 25f6c55 applied to upstream 940d32f.

  • lds_out_of_bounds_reads_zero_and_drops_writes passed 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).

**@⁠BaggyALPHA** on GitHub · 2026-11-25 02:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7151205521) Independent Windows validation on RTX 3080 (driver 621.24), with `25f6c55` applied to upstream `940d32f`. - `lds_out_of_bounds_reads_zero_and_drops_writes` passed 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).
Author
Owner

@⁠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 in crates/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 the outside value for guarded atomics. For compute, lds_dwords is the hardware allocation (lds_bytes(), in 512-byte units). One small open point: for mesh programs it is ms.lds_bytes rounded only to dwords, so an access just past the declared size but inside what the hardware actually allocates would now read 0. The new lds_out_of_bounds_reads_zero_and_drops_writes checks 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

**@⁠Marvisak** on GitHub · 2026-11-25 08:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7156897742) <!-- victory-triage v1 head=25f6c55a2a6b4c09020c3496a990607e65a3340a verdict=merge-candidate at=2026-11-25T08:19:59Z --> 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 in `crates/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 the `outside` value for guarded atomics. For compute, `lds_dwords` is the hardware allocation (`lds_bytes()`, in 512-byte units). One small open point: for mesh programs it is `ms.lds_bytes` rounded only to dwords, so an access just past the declared size but inside what the hardware actually allocates would now read 0. The new `lds_out_of_bounds_reads_zero_and_drops_writes` checks 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](https://claude.ai/code)_
Author
Owner

@⁠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 25f6c55a onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 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).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 11:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7160677180) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 25f6c55a onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 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).
Author
Owner

@⁠wwwwwwww3333333 on GitHub · 2026-11-26 02:28 UTC · original

Thanks for the review. You are right about mesh programs: lds_dwords there is the record's RECORD_LDS rounded to dwords, while compute uses the hardware allocation from COMPUTE_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_bytes that 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.

**@⁠wwwwwwww3333333** on GitHub · 2026-11-26 02:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7180842229) Thanks for the review. You are right about mesh programs: `lds_dwords` there is the record's `RECORD_LDS` rounded to dwords, while compute uses the hardware allocation from `COMPUTE_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_bytes` that 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.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1949
No description provided.