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

Open
Moon0755 wants to merge 1 commit from upstream-pr/3597 into main
Moon0755 commented 2026-11-27 20:05:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-27T20:05:43Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5532459512 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3597). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-27T20:05:43Z. --- 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
oni-swr commented 2026-11-27 20:29:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T20:29:02Z.


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)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7227549231 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3597#issuecomment-7227549231). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-27T20:29:02Z. --- 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)
kilolimaVI commented 2026-11-28 15:59:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T15:59:34Z.


AMD Radeon 780M (RDNA3) + WARP, Windows 11, head a7b9122.

  • Before (main 63bcca4 + this PR's test): fails on the hardware adapter. A 32_32_UINT element at byte 16 of a 20-byte view reads 0x22222222 instead of 0.
  • After: passes, 5 of 5 runs.
  • Full suite (victory-shader + victory-gpu --features diagnostics): 552 passed.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7241890524 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3597#issuecomment-7241890524). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-28T15:59:34Z. --- AMD Radeon 780M (RDNA3) + WARP, Windows 11, head `a7b9122`. - **Before** (main `63bcca4` + this PR's test): fails on the hardware adapter. A `32_32_UINT` element at byte 16 of a 20-byte view reads `0x22222222` instead of 0. - **After:** passes, 5 of 5 runs. - Full suite (`victory-shader` + `victory-gpu --features diagnostics`): 552 passed. AI-assisted (Claude).
upipibi commented 2026-11-28 16:38:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T16:38:43Z.


NVIDIA row for this PR: it passes on Ampere, and its test fails on this card without the fix, at the same value as on the 780M and in the description.

RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head a7b9122 on main 63bcca4 (one commit, clean).

  • cargo test --locked -p victory-shader --lib -- typed_elements_ending_past_the_buffer_read_zero --nocapture: 1 passed, 0 failed, 0 ignored, in 3 of 3 runs. Each run checks this card and then WARP, at byte 12 and at byte 16. Three more runs with VICTORY_WARP=1, where every device is WARP, also passed.

  • Negative control: main's emit/lower.rs, with the test kept in valu_tests.rs. git diff --stat HEAD: 1 file, 18 deletions. git diff --stat 63bcca4: only valu_tests.rs (71 insertions, 1 deletion). Result: 0 passed, 1 failed, in 3 of 3 runs on hardware and 3 of 3 with VICTORY_WARP=1:

    • hardware: 32_32_UINT element at byte 16 of a 20-byte view, left: 572662306 (0x22222222), right: 0. With VICTORY_WARP=1 the label is still hardware, but that run is WARP too.
    • The in-bounds element at byte 12 passed on both adapters before that.
    • In the hardware runs the assertion stops at this card's leg, so WARP's value at byte 16 comes from the VICTORY_WARP=1 runs. Both read 0x22222222.

    That is the 0x22222222 instead of 0 that the description's fork CI control and kilolimaVI's 780M give. On main, this card returns the in-bounds dword at 16 and 0 for the dword past the end, the same as AMD and WARP.

  • cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index:

    • this PR: 299 passed, 3 failed, 3 ignored;
    • main 63bcca4: 298 passed, 3 failed, 3 ignored.

    The 3 failures are the same on both: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and synthetic_tests::gathers_at_a_level_match_the_hardware. The skipped test crashes the binary on this card (open issue #2571).

  • The PR does not touch victory-gpu, so I did not run its lib suite.

Nothing NVIDIA-specific: the 3070 reads the partial element the same way as the 780M and WARP on main, and reads zero with the PR.

Not tested:

  • the cases the description leaves out: DST_SEL swizzles, OOB modes 0-2, stride, swizzle or idxen addressing, d16 and narrow formats, sub-dword elements;
  • the merges with #3572, #3602, #3587 or #2997 (oni-swr's lower.rs size note);
  • clippy, a title run.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7242401519 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3597#issuecomment-7242401519). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-28T16:38:43Z. --- NVIDIA row for this PR: it passes on Ampere, and its test fails on this card without the fix, at the same value as on the 780M and in the description. RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head `a7b9122` on main `63bcca4` (one commit, clean). - `cargo test --locked -p victory-shader --lib -- typed_elements_ending_past_the_buffer_read_zero --nocapture`: 1 passed, 0 failed, 0 ignored, in 3 of 3 runs. Each run checks this card and then WARP, at byte 12 and at byte 16. Three more runs with `VICTORY_WARP=1`, where every device is WARP, also passed. - Negative control: main's `emit/lower.rs`, with the test kept in `valu_tests.rs`. `git diff --stat HEAD`: 1 file, 18 deletions. `git diff --stat 63bcca4`: only `valu_tests.rs` (71 insertions, 1 deletion). Result: 0 passed, 1 failed, in 3 of 3 runs on hardware and 3 of 3 with `VICTORY_WARP=1`: - `hardware: 32_32_UINT element at byte 16 of a 20-byte view`, `left: 572662306` (`0x22222222`), `right: 0`. With `VICTORY_WARP=1` the label is still `hardware`, but that run is WARP too. - The in-bounds element at byte 12 passed on both adapters before that. - In the hardware runs the assertion stops at this card's leg, so WARP's value at byte 16 comes from the `VICTORY_WARP=1` runs. Both read `0x22222222`. That is the `0x22222222` instead of 0 that the description's fork CI control and kilolimaVI's 780M give. On main, this card returns the in-bounds dword at 16 and 0 for the dword past the end, the same as AMD and WARP. - `cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index`: - this PR: 299 passed, 3 failed, 3 ignored; - main `63bcca4`: 298 passed, 3 failed, 3 ignored. The 3 failures are the same on both: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` and `synthetic_tests::gathers_at_a_level_match_the_hardware`. The skipped test crashes the binary on this card (open issue #2571). - The PR does not touch `victory-gpu`, so I did not run its lib suite. Nothing NVIDIA-specific: the 3070 reads the partial element the same way as the 780M and WARP on main, and reads zero with the PR. Not tested: - the cases the description leaves out: `DST_SEL` swizzles, OOB modes 0-2, stride, swizzle or `idxen` addressing, `d16` and narrow formats, sub-dword elements; - the merges with #3572, #3602, #3587 or #2997 (oni-swr's `lower.rs` size note); - clippy, a title run. AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3597:upstream-pr/3597'
git switch 'upstream-pr/3597'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3597'
git switch 'upstream-pr/3597'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3597'
git switch 'upstream-pr/3597'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3597'
git switch 'main'
git merge --squash 'upstream-pr/3597'
git switch 'main'
git merge --ff-only 'upstream-pr/3597'
git switch 'main'
git merge 'upstream-pr/3597'
git push origin 'main'
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!3597
No description provided.