Shaders: typed buffer elements crossing the record end read zero #3597

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

@⁠Moon0755 on GitHub · 2026-11-27 20:05 UTC · original
Moon0755:fix/typed-element-spill → main · +89 −1 · 2 files · 1 commits · open

On RDNA2 (gfx1036, measured natively in Leonida docs/design.md), typed buffer loads (buffer_load_format_* / tbuffer_load_format_*) are all-or-nothing against the buffer end: an element whose offset + element_size extends past the view's byte width returns 0 in every data channel (with missing channels past the format keeping (0, 0, 0, 1)), rather than returning partial data from leading in-bounds dwords. On main, Lower::format_load issued per-dword rawBufferLoad calls and kept data from leading dwords even when trailing dwords were out of bounds.

Changes

  • crates/victory-shader/src/emit/lower.rs (Lower::format_load, 521,509 bytes / +946 vs main, 2,779 bytes below the 524,288 limit):
    • Query getDimensions on the raw view h (already post-raw_view, so off and width share the same coordinate space), compute whole = (off + total / 8 >= off) && (off + total / 8 <= width), and select 0 for every decoded format channel when !whole while leaving constant-1 missing channels intact.
    • Note: merges cleanly with #3572 in lower.rs.
  • crates/victory-shader/src/emit/valu_tests.rs:
    • Added typed_elements_ending_past_the_buffer_read_zero covering tbuffer_load_format_xy (32_32_UINT, format 62, 8 bytes) on a 20-byte raw view at byte 12 (in-bounds control) and byte 16 (ending past the buffer -> 0).

Verification

  • Fork CI control (test only on main): https://github.com/Moon0755/VIctory/actions/runs/46058009518 (failure — 302 passed, 1 failed solely on typed_elements_ending_past_the_buffer_read_zero: 0x22222222 instead of 0)
  • Fork CI fix (devin/ci-typed-element-spill): https://github.com/Moon0755/VIctory/actions/runs/46058009634 (success — 303 passed / 0 failed, Clippy + diagnostics Clippy clean, asset policy: 191 files ok)
  • Local verification (a7b9122): typed_elements_ending_past_the_buffer_read_zero (1/1) and tbuffer (1/1) pass on hardware + WARP; both Clippy configs and cargo xtask policy (191 files ok) clean.
  • Not tested: DST_SEL swizzles on typed OOB, OOB modes 0..=2, stride/swizzle/idxen, d16 / narrow-count variants of wide formats, dxil.dll 1.7, game files. Synthetic tests only (AI-assisted).

— Devin & Neon

**@⁠Moon0755** on GitHub · 2026-11-27 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/3597) `Moon0755:fix/typed-element-spill` → `main` · +89 −1 · 2 files · 1 commits · open On RDNA2 (`gfx1036`, measured natively in Leonida `docs/design.md`), typed buffer loads (`buffer_load_format_*` / `tbuffer_load_format_*`) are all-or-nothing against the buffer end: an element whose `offset + element_size` extends past the view's byte width returns `0` in every data channel (with missing channels past the format keeping `(0, 0, 0, 1)`), rather than returning partial data from leading in-bounds dwords. On `main`, `Lower::format_load` issued per-dword `rawBufferLoad` calls and kept data from leading dwords even when trailing dwords were out of bounds. ### Changes - **`crates/victory-shader/src/emit/lower.rs`** (`Lower::format_load`, `521,509` bytes / `+946` vs `main`, `2,779` bytes below the `524,288` limit): - Query `getDimensions` on the raw view `h` (already post-`raw_view`, so `off` and `width` share the same coordinate space), compute `whole = (off + total / 8 >= off) && (off + total / 8 <= width)`, and select `0` for every decoded format channel when `!whole` while leaving constant-1 missing channels intact. - Note: merges cleanly with `#3572` in `lower.rs`. - **`crates/victory-shader/src/emit/valu_tests.rs`**: - Added `typed_elements_ending_past_the_buffer_read_zero` covering `tbuffer_load_format_xy` (`32_32_UINT`, format `62`, `8` bytes) on a `20`-byte raw view at byte `12` (in-bounds control) and byte `16` (ending past the buffer -> `0`). ### Verification - **Fork CI control** (test only on `main`): https://github.com/Moon0755/VIctory/actions/runs/46058009518 (`failure` — 302 passed, 1 failed solely on `typed_elements_ending_past_the_buffer_read_zero`: `0x22222222` instead of `0`) - **Fork CI fix** (`devin/ci-typed-element-spill`): https://github.com/Moon0755/VIctory/actions/runs/46058009634 (`success` — 303 passed / 0 failed, Clippy + diagnostics Clippy clean, `asset policy: 191 files ok`) - **Local verification** (`a7b9122`): `typed_elements_ending_past_the_buffer_read_zero` (`1/1`) and `tbuffer` (`1/1`) pass on hardware + WARP; both Clippy configs and `cargo xtask policy` (`191 files ok`) clean. - **Not tested**: `DST_SEL` swizzles on typed OOB, OOB modes `0..=2`, stride/swizzle/`idxen`, `d16` / narrow-count variants of wide formats, `dxil.dll` 1.7, game files. Synthetic tests only (AI-assisted). — Devin & Neon
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:09:21 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 20:29 UTC · original

Verification of head a7b91220 against base main 63bcca43 (heads/base re-checked unchanged before testing).

Hardware: Windows 11 Pro 26200, WARP only (no physical GPU); dxil.dll 1.8.2502.11 (SDK 26100).

Tests (cargo test -p victory-shader): head 299 passed / 4 failed / 3 ignored; base 298 passed / 4 failed / 3 ignored. The 4 failures are the same on base and head (synthetic_tests that need a wave-32 pipeline or hardware-specific gather behaviour, unsupported on WARP), so they are pre-existing and unrelated. The new test typed_elements_ending_past_the_buffer_read_zero passes on head.

Control: base plus only this PR's valu_tests.rs hunks: the new test fails (5 failed vs 4 on base), so it detects the missing behaviour.

Clippy: cargo clippy -p victory-shader --all-targets -- -D warnings clean on head.

Review: no defects found. The bounds rule (off + size no wrap and <= width from getDimensions, whole element otherwise all data channels 0) matches the claim, and the default channels (0,0,0,1) for channels past the format are still applied after the select. Sub-dword elements are checked on their own end byte. I only checked this against WARP, not hardware.

Size: lower.rs 521,509 bytes (main 520,563), under the 524,288 limit. Textual merge of #3597 + #3602: clean, 521,714. Adding #3587: 522,154. Adding #2997 as well: clean merge but 525,571, which is 1,283 over the limit (main + #2997 alone is 523,980, fine). So the four together will not fit in lower.rs without moving code out.

AI-assisted (Claude Sonnet 5.5)

**@⁠oni-swr** on GitHub · 2026-11-27 20:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3597#issuecomment-7227549231) Verification of head a7b91220 against base main 63bcca43 (heads/base re-checked unchanged before testing). **Hardware:** Windows 11 Pro 26200, WARP only (no physical GPU); dxil.dll 1.8.2502.11 (SDK 26100). **Tests (`cargo test -p victory-shader`):** head 299 passed / 4 failed / 3 ignored; base 298 passed / 4 failed / 3 ignored. The 4 failures are the same on base and head (synthetic_tests that need a wave-32 pipeline or hardware-specific gather behaviour, unsupported on WARP), so they are pre-existing and unrelated. The new test `typed_elements_ending_past_the_buffer_read_zero` passes on head. **Control:** base plus only this PR's `valu_tests.rs` hunks: the new test fails (5 failed vs 4 on base), so it detects the missing behaviour. **Clippy:** `cargo clippy -p victory-shader --all-targets -- -D warnings` clean on head. **Review:** no defects found. The bounds rule (`off + size` no wrap and `<= width` from getDimensions, whole element otherwise all data channels 0) matches the claim, and the default channels (0,0,0,1) for channels past the format are still applied after the select. Sub-dword elements are checked on their own end byte. I only checked this against WARP, not hardware. **Size:** lower.rs 521,509 bytes (main 520,563), under the 524,288 limit. Textual merge of #3597 + #3602: clean, 521,714. Adding #3587: 522,154. Adding #2997 as well: clean merge but 525,571, which is 1,283 over the limit (main + #2997 alone is 523,980, fine). So the four together will not fit in lower.rs without moving code out. AI-assisted (Claude Sonnet 5.5)
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3597'
git switch 'github-bot/gh-3597'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3597'
git switch 'github-bot/gh-3597'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3597'
git switch 'main'
git merge --squash 'github-bot/gh-3597'
git switch 'main'
git merge --ff-only 'github-bot/gh-3597'
git switch 'main'
git merge 'github-bot/gh-3597'
git push origin 'main'
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!3597
No description provided.