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

Closed
github-bot wants to merge 0 commits from github-bot/gh-92 into main AGit
Owner

@⁠murillojndem on GitHub · 2026-12-01 10:48 UTC · original
amd/lds-past-the-allocation → main · +184 −14 · 4 files · 1 commits · closed without merging

What

On the console an LDS access past the program's allocation reads 0 and its write is dropped. The translation took every LDS address as in bounds (lower.rs: "taken as dword-aligned and in bounds"), with two outcomes:

  • A constant address past the group-shared array makes DXIL that the validator refuses ("Access to out-of-bounds memory is disallowed", at getelementptr [128 x i32] ... i32 128 in the test below), so the program is not translated.
  • A computed one is undefined on the host. On an RX 7900 XT a read past the end returns what a write past the end put there (0x0badf00d in the test), where the console reads 0.

Change

emit/lower.rs, the DS lowering:

  • Each dword an LDS access touches comes with whether it lies in the program's own LDS. Reads give 0 outside it. Writes (dwords, bytes and halves, write2) and atomics there are skipped. A returning atomic gives 0 to a lane outside it, and a lane EXEC leaves out keeps its register.
  • The host index stays inside the group-shared array whatever the address. The index select is tagged Tag::Clamp, so VICTORY_SHADER_CENSUS counts it.
  • The bound is the program's allocation, a new Shader::lds_program set where lds_dwords is first set (compute and mesh programs). It is not lds_dwords: the translation appends dwords of its own after the program's (the wave64 exchange on 32-lane hosts, the halves dword).

TRANSLATOR_VERSION goes from 4 to 5.

This ports Marvisak/VIctory@eabb6b8 (by wwwwwwww3333333, upstream PR 1949, for upstream issue 1870), which bounds by the group-shared size; here that size can be larger than the program's allocation, hence lds_program.

Tests

New tests in emit::valu_tests, ten probes each on 64 threads with 512 bytes of LDS: a read past the end, a write past the end that must land nowhere, a byte write and a byte read past the end, a read at offset 65532, read2 with its second dword past the end, a returning atomic past the end without and under EXEC (with EXEC leaving every lane out the register must keep its old value), and an address that wraps at 32 bits back inside. lds_past_the_allocation_at_a_constant_address has the address known at translation, lds_past_the_allocation_at_a_computed_address computes it from an input.

On main 5d91fde, the constant-address test fails DXIL validation (on WARP and the card alike), and the computed-address one passes on WARP but fails on the RX 7900 XT (driver 32.0.32015.7029): a read past the end: 0x0badf00d, want 0x00000000. With this branch both pass on WARP and on the card.

Also run:

  • victory-shader --lib on WARP: 311 passed, 4 failed, 4 ignored (main: 309, 4, 4). The four failures are the same on main: three fail PSV0 validation with the SDK 10.0.22621 dxil.dll on this PC, and a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is is a hardware-only test that VICTORY_WARP=1 sends to WARP.
  • victory-shader --lib on the RX 7900 XT (and WARP, through the same harness): 312 passed, 3 failed, 4 ignored (main: 310, 3, 4). The three failures are the PSV0 ones.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • cargo test -p xtask: repository_passes_policy passes (lower.rs is 635,800 bytes of the 655,360-byte limit). documented_switches_are_read fails, the same way as on main (VICTORY_NAME in README.md).

Limits

  • Cost: every LDS dword now has a compare and a select, each store and atomic a branch of its own, and the per-dword index may keep the host compiler from merging the dwords of a b64, b128 or read2 access. Not measured in a title.
  • The tests build wave64: false programs, where lds_program and lds_dwords are equal, so they do not reach the case that needs lds_program. cmpst, min_f32/max_f32, a write2 or b64 that straddles the end and the d16 forms are not probed.
  • Mesh programs take their LDS size from the record's byte count. If the console allocates mesh LDS in larger granules, as it does for compute, an access in that padding now reads 0 where the console would keep the data. Not checked.
  • I built and tested victory-shader only. My checkout leaves out crates/victory-formats/src/bcpack-tables.bin, so I did not build -p victory or run the workspace clippy.
  • No in-game run and no fps numbers.
  • No environment switch. Given the cost above, an opt-out switch could make sense here; I can add one if you want it.
  • Other translator PRs bump the version too (#72 goes to 6, #90 and #91 to 5). Whichever lands later needs the next number.

The same change is open as DexNom/VIctory#227.

Generated with Claude Code

**@⁠murillojndem** on GitHub · 2026-12-01 10:48 UTC · [original](https://github.com/eikkapine/victory-amd/pull/92) `amd/lds-past-the-allocation` → `main` · +184 −14 · 4 files · 1 commits · closed without merging ## What On the console an LDS access past the program's allocation reads 0 and its write is dropped. The translation took every LDS address as in bounds (`lower.rs`: "taken as dword-aligned and in bounds"), with two outcomes: - A constant address past the group-shared array makes DXIL that the validator refuses ("Access to out-of-bounds memory is disallowed", at `getelementptr [128 x i32] ... i32 128` in the test below), so the program is not translated. - A computed one is undefined on the host. On an RX 7900 XT a read past the end returns what a write past the end put there (`0x0badf00d` in the test), where the console reads 0. ## Change `emit/lower.rs`, the DS lowering: - Each dword an LDS access touches comes with whether it lies in the program's own LDS. Reads give 0 outside it. Writes (dwords, bytes and halves, `write2`) and atomics there are skipped. A returning atomic gives 0 to a lane outside it, and a lane EXEC leaves out keeps its register. - The host index stays inside the group-shared array whatever the address. The index select is tagged `Tag::Clamp`, so `VICTORY_SHADER_CENSUS` counts it. - The bound is the program's allocation, a new `Shader::lds_program` set where `lds_dwords` is first set (compute and mesh programs). It is not `lds_dwords`: the translation appends dwords of its own after the program's (the wave64 exchange on 32-lane hosts, the `halves` dword). `TRANSLATOR_VERSION` goes from 4 to 5. This ports Marvisak/VIctory@eabb6b8 (by wwwwwwww3333333, upstream PR 1949, for upstream issue 1870), which bounds by the group-shared size; here that size can be larger than the program's allocation, hence `lds_program`. ## Tests New tests in `emit::valu_tests`, ten probes each on 64 threads with 512 bytes of LDS: a read past the end, a write past the end that must land nowhere, a byte write and a byte read past the end, a read at offset 65532, `read2` with its second dword past the end, a returning atomic past the end without and under EXEC (with EXEC leaving every lane out the register must keep its old value), and an address that wraps at 32 bits back inside. `lds_past_the_allocation_at_a_constant_address` has the address known at translation, `lds_past_the_allocation_at_a_computed_address` computes it from an input. On main 5d91fde, the constant-address test fails DXIL validation (on WARP and the card alike), and the computed-address one passes on WARP but fails on the RX 7900 XT (driver 32.0.32015.7029): `a read past the end: 0x0badf00d, want 0x00000000`. With this branch both pass on WARP and on the card. Also run: - `victory-shader --lib` on WARP: 311 passed, 4 failed, 4 ignored (main: 309, 4, 4). The four failures are the same on main: three fail PSV0 validation with the SDK 10.0.22621 `dxil.dll` on this PC, and `a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is` is a hardware-only test that `VICTORY_WARP=1` sends to WARP. - `victory-shader --lib` on the RX 7900 XT (and WARP, through the same harness): 312 passed, 3 failed, 4 ignored (main: 310, 3, 4). The three failures are the PSV0 ones. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - `cargo test -p xtask`: `repository_passes_policy` passes (`lower.rs` is 635,800 bytes of the 655,360-byte limit). `documented_switches_are_read` fails, the same way as on main (`VICTORY_NAME` in README.md). ## Limits - Cost: every LDS dword now has a compare and a select, each store and atomic a branch of its own, and the per-dword index may keep the host compiler from merging the dwords of a `b64`, `b128` or `read2` access. Not measured in a title. - The tests build `wave64: false` programs, where `lds_program` and `lds_dwords` are equal, so they do not reach the case that needs `lds_program`. `cmpst`, `min_f32`/`max_f32`, a `write2` or `b64` that straddles the end and the d16 forms are not probed. - Mesh programs take their LDS size from the record's byte count. If the console allocates mesh LDS in larger granules, as it does for compute, an access in that padding now reads 0 where the console would keep the data. Not checked. - I built and tested `victory-shader` only. My checkout leaves out `crates/victory-formats/src/bcpack-tables.bin`, so I did not build `-p victory` or run the workspace clippy. - No in-game run and no fps numbers. - No environment switch. Given the cost above, an opt-out switch could make sense here; I can add one if you want it. - Other translator PRs bump the version too (#72 goes to 6, #90 and #91 to 5). Whichever lands later needs the next number. The same change is open as DexNom/VIctory#227. Generated with [Claude Code](https://claude.com/claude-code)
On the console an LDS access past the program's allocation reads 0 and
its write is dropped. The translation took every LDS address as in
bounds ("taken as dword-aligned and in bounds"), with two outcomes:
- A constant address past the group-shared array makes DXIL that the
  validator refuses ("Access to out-of-bounds memory is disallowed"),
  so the program is not translated.
- A computed one is undefined on the host. On an RX 7900 XT a read past
  the end returns what a write past the end put there (0x0badf00d in
  the test), where the console reads 0.

Each dword an LDS access touches now comes with whether it lies in the
program's own LDS. Reads give 0 outside it; writes and atomics there
are skipped; a returning atomic gives 0 to a lane outside it, and a
lane EXEC leaves out keeps its register. The host index stays in the
group-shared array whatever the address. The bound is the program's
allocation, a new Shader::lds_program set where lds_dwords is first
set (compute and mesh programs), not lds_dwords: the translation
appends dwords of its own after the program's (the wave64 exchange on
32-lane hosts, the halves dword). The index select is tagged as a clamp
for VICTORY_SHADER_CENSUS.

Port of Marvisak/VIctory eabb6b8 (upstream PR 1949, issue 1870), which
bounds by the group-shared size; here that size can be larger than the
program's allocation, hence lds_program.

Tests lds_past_the_allocation_at_a_constant_address and
lds_past_the_allocation_at_a_computed_address run ten probes on 64
threads with 512 bytes of LDS: reads, byte and dword writes, read2, a
returning atomic with and without EXEC, and an address that wraps at
32 bits back inside. Without the change the first fails DXIL validation
and the second reads 0x0badf00d past the end on an RX 7900 XT.

TRANSLATOR_VERSION 4 -> 5, since programs with LDS accesses translate
differently.

Co-authored-by: wwwwwwww3333333 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 10:49:35 +00:00
github-bot closed this pull request 2026-12-01 18:59:38 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.