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

Merged
HailLucifer666 merged 1 commit from upstream-pr/1658 into main 2026-11-25 00:14:59 +00:00
HailLucifer666 commented 2026-11-24 20:33:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by HailLucifer666 on 2026-11-24T20:33:31Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6590861559 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1658). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-24T20:33:31Z. --- **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.
catminou4 commented 2026-11-24 23:04:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T22:19:50Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Staging::detile stays inside the staging buffer: the copyable-footprints helper now accounts for D3D12 omitting trailing row-pitch padding on the final row of the final subresource (pitchrowsdepth can exceed total-offset). 2 tests. Subtle API quirk handled explicitly — good.

<!-- greyfinch-sync:Marvisak/VIctory:review:6048311033 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1658#pullrequestreview-6048311033). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T22:19:50Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Staging::detile stays inside the staging buffer: the copyable-footprints helper now accounts for D3D12 omitting trailing row-pitch padding on the final row of the final subresource (pitch*rows*depth can exceed total-offset). 2 tests. Subtle API quirk handled explicitly — good.
acetonahard-code commented 2026-11-24 23:05:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by acetonahard-code on 2026-11-24T22:12:41Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145945212 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1658#issuecomment-7145945212). Originally posted by [acetonahard-code](https://github.com/acetonahard-code) on 2026-11-24T22:12:41Z. --- 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>
upstream-sync closed this pull request 2026-11-25 01:06:58 +00:00
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!1657
No description provided.