Shaders: LDS accesses past the program's allocation read 0 and drop writes #118

Open
github-bot wants to merge 1 commit from github-bot/gh-118 into main AGit
Owner

@⁠DiosET3RN0 on GitHub · 2026-11-27 18:24 UTC · original
DiosET3RN0:lds-bounds → main · +92 −11 · 3 files · 1 commits · open

What

ds lowering assumes every LDS address is in bounds
(shortcut: LDS addresses are taken as dword-aligned and in bounds). On the
console an access past the program's LDS reads 0 and drops the write; in DXIL
an out-of-range groupshared index is undefined behaviour.

It matters more on 32-lane (NVIDIA) hosts: the translator puts its own dwords
right after the program's LDS (lane exchange, halves, pairs, and the ticket
of #30), so a title overflow lands on exactly the words the wave64-on-32
lowering depends on.

How

  • Shader::lds_title_dwords: the LDS size the console program declares, set
    where lds_dwords is set for CS and MS, before the layer's own dwords are added.
  • In ds, each dword access checks index < lds_title_dwords, uses an index
    clamped into range, and: reads give 0 out of range; writes are guarded per
    dword; atomics (ds_add…, cmpst, min/max_f32) do not run and return 0
    (lanes switched off by EXEC keep their value, as before).
  • Only the dword-alignment assumption stays as a shortcut:.
  • Cost: one compare and one select per LDS access; constant addresses fold.
  • The shader cache key here is the translator's source fingerprint, so cached
    translations are redone on their own.

3 files, +92/−11. Same change as avatarmanz/VIctory-7900XTX#336.

Tests

New GPU test ds_past_the_program_lds_reads_zero_and_drops_writes (512-byte
LDS; addresses 4 and 508 in bounds; 512, 0x10000 and 0xFFFFFFFC out).

On an RTX 4060 8 GB (32-lane waves), Windows 11, driver 621.24, Rust 1.98.1:

  • cargo test -p victory-shader --locked --no-fail-fast: main 288 passed,
    0 failed; this branch 289 passed, 0 failed (the new test included).
  • Control: with the bounds check disabled on purpose the new test fails at byte
    0x200, the first out-of-range access.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.

Not run in the game (no game files on this machine). It should change nothing
for programs that stay inside their LDS.

AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

**@⁠DiosET3RN0** on GitHub · 2026-11-27 18:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/118) `DiosET3RN0:lds-bounds` → `main` · +92 −11 · 3 files · 1 commits · open ## What `ds` lowering assumes every LDS address is in bounds (`shortcut: LDS addresses are taken as dword-aligned and in bounds`). On the console an access past the program's LDS reads 0 and drops the write; in DXIL an out-of-range `groupshared` index is undefined behaviour. It matters more on 32-lane (NVIDIA) hosts: the translator puts its own dwords right after the program's LDS (lane exchange, halves, pairs, and the `ticket` of #30), so a title overflow lands on exactly the words the wave64-on-32 lowering depends on. ## How - `Shader::lds_title_dwords`: the LDS size the console program declares, set where `lds_dwords` is set for CS and MS, before the layer's own dwords are added. - In `ds`, each dword access checks `index < lds_title_dwords`, uses an index clamped into range, and: reads give 0 out of range; writes are guarded per dword; atomics (`ds_add…`, `cmpst`, `min/max_f32`) do not run and return 0 (lanes switched off by EXEC keep their value, as before). - Only the dword-alignment assumption stays as a `shortcut:`. - Cost: one compare and one select per LDS access; constant addresses fold. - The shader cache key here is the translator's source fingerprint, so cached translations are redone on their own. 3 files, +92/−11. Same change as avatarmanz/VIctory-7900XTX#336. ## Tests New GPU test `ds_past_the_program_lds_reads_zero_and_drops_writes` (512-byte LDS; addresses 4 and 508 in bounds; 512, 0x10000 and 0xFFFFFFFC out). On an **RTX 4060 8 GB** (32-lane waves), Windows 11, driver 621.24, Rust 1.98.1: - `cargo test -p victory-shader --locked --no-fail-fast`: `main` 288 passed, 0 failed; this branch 289 passed, 0 failed (the new test included). - Control: with the bounds check disabled on purpose the new test fails at byte 0x200, the first out-of-range access. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean. Not run in the game (no game files on this machine). It should change nothing for programs that stay inside their LDS. AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
On the console an LDS access past the program's allocation reads 0 and
drops the write; in DXIL an out-of-range groupshared index is undefined
behaviour, and the dwords right after the program's are the layer's own
(lane exchange, halves, pairs, ticket), so an overflow corrupted them.

Each LDS dword access now checks the index against the size the program
declares (lds_title_dwords), uses a clamped index, reads 0 out of range,
guards writes per dword, and skips atomics (returning 0). Only the
dword-alignment shortcut remains.

New GPU test ds_past_the_program_lds_reads_zero_and_drops_writes; it
fails without the check (at byte 0x200) and passes with it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 18:28:17 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/shader.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/118/head:github-bot/gh-118'
git switch 'github-bot/gh-118'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-118'
git switch 'github-bot/gh-118'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-118'
git switch 'github-bot/gh-118'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-118'
git switch 'main'
git merge --squash 'github-bot/gh-118'
git switch 'main'
git merge --ff-only 'github-bot/gh-118'
git switch 'main'
git merge 'github-bot/gh-118'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.