GPU: keep Staging::detile inside the staging buffer and harden committed() #1658

Manually merged
github merged 1 commit from gh-pr/1658/head into gh-pr/1658/base 2026-11-26 04:40:16 +00:00
Owner

@⁠HailLucifer666 on GitHub · 2026-11-24 20:33 UTC · original
HailLucifer666:fix/texture-staging-oob-and-committed-guard → main · +71 −10 · 1 files · 1 commits · merged 2026-11-25 00:14 UTC

Issue:

  1. Staging::detile builds from_raw_parts_mut(data + offset, pitch * rows * depth). Because D3D12 GetCopyableFootprints does not pad the final row of the final subresource to RowPitch (e.g., 4x4 RGBA8: total = 784 while pitch * rows = 1024), the slice extends past the mapped upload buffer allocation (UB / page-boundary fault).
  2. committed(at, len) computes p + len unchecked (wraps to end < p in release and returns true) and checks only MEM_COMMIT, letting PAGE_NOACCESS / PAGE_GUARD pages pass.

Fix:

  • Keep Staging.size unconditionally and clamp each subresource slice to size - footprint.Offset via subresource_len().
  • Use checked_add / saturating_add and reject PAGE_NOACCESS | PAGE_GUARD in committed().
  • Added unit tests subresource_len_stays_inside_staging_total and committed_rejects_overflow_and_noaccess_pages.

Verification:

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (clean)
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings (clean)
  • cargo test -p victory-gpu --locked (52 passed, 0 failed, 1 ignored)
  • cargo test -p xtask --locked (4 passed, 0 failed)
  • No game files used.
**@⁠HailLucifer666** on GitHub · 2026-11-24 20:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1658) `HailLucifer666:fix/texture-staging-oob-and-committed-guard` → `main` · +71 −10 · 1 files · 1 commits · merged 2026-11-25 00:14 UTC **Issue:** 1. `Staging::detile` builds `from_raw_parts_mut(data + offset, pitch * rows * depth)`. Because D3D12 `GetCopyableFootprints` does not pad the final row of the final subresource to `RowPitch` (e.g., 4x4 RGBA8: `total = 784` while `pitch * rows = 1024`), the slice extends past the mapped upload buffer allocation (UB / page-boundary fault). 2. `committed(at, len)` computes `p + len` unchecked (wraps to `end < p` in release and returns `true`) and checks only `MEM_COMMIT`, letting `PAGE_NOACCESS` / `PAGE_GUARD` pages pass. **Fix:** - Keep `Staging.size` unconditionally and clamp each subresource slice to `size - footprint.Offset` via `subresource_len()`. - Use `checked_add` / `saturating_add` and reject `PAGE_NOACCESS | PAGE_GUARD` in `committed()`. - Added unit tests `subresource_len_stays_inside_staging_total` and `committed_rejects_overflow_and_noaccess_pages`. **Verification:** - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (clean) - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings` (clean) - `cargo test -p victory-gpu --locked` (52 passed, 0 failed, 1 ignored) - `cargo test -p xtask --locked` (4 passed, 0 failed) - No game files used.
GetCopyableFootprints does not pad the final row of the final subresource to RowPitch, so pitch * rows * depth in Staging::detile can exceed the mapped upload buffer size (UB in from_raw_parts_mut). committed() also used unchecked p + len (wrapping to end < p in release) and ignored PAGE_NOACCESS / PAGE_GUARD.

- Keep Staging.size unconditionally and clamp subresource slice length to size - footprint.Offset via subresource_len().
- Check overflow with checked_add / saturating_add and reject PAGE_NOACCESS / PAGE_GUARD in committed().
- Add regression tests for both.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:40:15 +00:00
github manually merged commit 4fc9d70fee into gh-pr/1658/base 2026-11-26 04:40:16 +00:00
Author
Owner

@⁠acetonahard-code on GitHub · 2026-11-24 22:12 UTC · original

Heads-up: #1191 (opened earlier today, Closes #935) fixes the same two things in texture.rs, the detile span past an unpadded last row and the overflow in committed(), as part of a larger rewrite. The two conflict.

Tested on Windows 11, RTX 4070 SUPER (driver 621.14), with the repo toolchain, merged into current main (70564ae):

cargo test -p victory-gpu passed failed ignored
main 76 2 1
main + this PR 78 2 1
main, --all-features 79 2 -
main + this PR, --all-features 81 2 -
  • The 2 new tests pass.
  • No GPU test skipped for lack of a device.
  • cargo clippy --all-targets -- -D warnings, with and without --all-features: clean.
  • Minor: cargo fmt --check would rewrap 3 blocks this PR adds (texture.rs). main isn't rustfmt-clean either, so take it or leave it.
  • Two victory-gpu tests fail on current main on this NVIDIA card: dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views. That's the 1,000,000-view heap cap, see #1744. They fail the same way with this PR, and no other test does.

I didn't test with game data.


Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.

**@⁠acetonahard-code** on GitHub · 2026-11-24 22:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1658#issuecomment-7145945212) Heads-up: #1191 (opened earlier today, `Closes #935`) fixes the same two things in `texture.rs`, the `detile` span past an unpadded last row and the overflow in `committed()`, as part of a larger rewrite. The two conflict. Tested on Windows 11, RTX 4070 SUPER (driver 621.14), with the repo toolchain, merged into current `main` (70564ae): | `cargo test -p victory-gpu` | passed | failed | ignored | |---|---|---|---| | `main` | 76 | 2 | 1 | | `main` + this PR | 78 | 2 | 1 | | `main`, `--all-features` | 79 | 2 | - | | `main` + this PR, `--all-features` | 81 | 2 | - | - The 2 new tests pass. - No GPU test skipped for lack of a device. - `cargo clippy --all-targets -- -D warnings`, with and without `--all-features`: clean. - Minor: `cargo fmt --check` would rewrap 3 blocks this PR adds (`texture.rs`). `main` isn't rustfmt-clean either, so take it or leave it. - Two `victory-gpu` tests fail on current `main` on this NVIDIA card: `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`. That's the 1,000,000-view heap cap, see #1744. They fail the same way with this PR, and no other test does. I didn't test with game data. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
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!1658
No description provided.