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

Closed
DiosET3RN0 wants to merge 1 commit from upstream-pr/118 into main
DiosET3RN0 commented 2026-11-27 18:24:00 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DiosET3RN0 on 2026-11-27T18:24:00Z.


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5531324867 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/118). Originally posted by [DiosET3RN0](https://github.com/DiosET3RN0) on 2026-11-27T18:24:00Z. --- ## 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)
trustno1-coder commented 2026-11-28 18:27:30 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T18:27:30Z.


Thanks for this. I'm closing it without merging because it conflicts with the current main in the files it changes, and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request. Thanks for the work.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7243804907 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/118#issuecomment-7243804907). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-28T18:27:30Z. --- Thanks for this. I'm closing it without merging because it conflicts with the current main in the files it changes, and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request. Thanks for the work.

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!118
No description provided.