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

Merged
wwwwwwww3333333 merged 1 commit from upstream-pr/1949 into main 2026-11-25 21:52:34 +00:00
wwwwwwww3333333 commented 2026-11-25 01:38:55 +00:00 (Migrated from github.com)

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

  • 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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6595143549 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1949). Originally posted by [wwwwwwww3333333](https://github.com/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": - 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
Headache3318 commented 2026-11-25 02:06:31 +00:00 (Migrated from github.com)

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 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150259476 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7150259476). Originally posted by [Headache3318](https://github.com/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 `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.
BaggyALPHA commented 2026-11-25 03:03:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BaggyALPHA on 2026-11-25T02:48:07Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151205521 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7151205521). Originally posted by [BaggyALPHA](https://github.com/BaggyALPHA) on 2026-11-25T02:48:07Z. --- 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).
catminou4 commented 2026-11-25 04:06:10 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051314132 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1949#pullrequestreview-6051314132). Originally posted by [catminou4](https://github.com/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.
Marvisak commented 2026-11-25 09:06:12 +00:00 (Migrated from github.com)

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156897742 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7156897742). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:20:07Z. --- <!-- 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)_
sinan-cmyk commented 2026-11-25 12:03:38 +00:00 (Migrated from github.com)

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 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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160677180 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7160677180). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T11:09:49Z. --- ### 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).
upstream-sync closed this pull request 2026-11-25 22:03:17 +00:00
wwwwwwww3333333 commented 2026-11-26 03:05:11 +00:00 (Migrated from github.com)

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_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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180842229 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1949#issuecomment-7180842229). Originally posted by [wwwwwwww3333333](https://github.com/wwwwwwww3333333) on 2026-11-26T02:28:49Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1947
No description provided.