GPU: require texture copy footprints to fit a complete row #3032

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3034 into main
andrewpozdnakov7-jpg commented 2026-11-26 04:12:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T04:12:11Z.


CopyTextureRegion uses PlacedFootprint to size upload staging and to read back the requested rows. Each calculation now checks that the full unpadded row fits within RowPitch. For block compression, the row size is the number of horizontal blocks times the bytes per block.

The same synthetic footprint test on 63bcca4 accepts an undersized pitch for both RGBA8 and BC1 through both calculations. This revision rejects both, including a small region within the incomplete footprint. Exact-fit and padded pitches still return the expected row offsets and final byte count. The regression tests the layout calculations directly.

Valid guest upload and readback tests and the full Agility WARP GPU suite passed (247 passed, one ignored). The diff applies cleanly beside either #3006 or #3022. Strict GPU Clippy with and without diagnostics and the repository asset policy passed. This follows the optional row-width notes in #3006 and #3022. D3D12_SUBRESOURCE_FOOTPRINT Coordination claim

AI-assisted with Codex. Synthetic inputs.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6619335588 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3034). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T04:12:11Z. --- `CopyTextureRegion` uses `PlacedFootprint` to size upload staging and to read back the requested rows. Each calculation now checks that the full unpadded row fits within `RowPitch`. For block compression, the row size is the number of horizontal blocks times the bytes per block. The same synthetic footprint test on `63bcca4` accepts an undersized pitch for both RGBA8 and BC1 through both calculations. This revision rejects both, including a small region within the incomplete footprint. Exact-fit and padded pitches still return the expected row offsets and final byte count. The regression tests the layout calculations directly. Valid guest upload and readback tests and the full Agility WARP GPU suite passed (247 passed, one ignored). The diff applies cleanly beside either #3006 or #3022. Strict GPU Clippy with and without diagnostics and the repository asset policy passed. This follows the optional row-width notes in #3006 and #3022. [D3D12_SUBRESOURCE_FOOTPRINT](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_subresource_footprint) [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7182324697) AI-assisted with Codex. Synthetic inputs.
fuzeofficlal commented 2026-11-26 05:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T04:15:03Z.

Review: APPROVED


Looks clean and minimal on 374aaded.

  • PlacedFootprint::row_layout computes u64::from(self.width).div_ceil(block) * element (overflow-free for all u32 widths) and rejects footprints whose row_pitch is smaller than an unpadded row.
  • Sharing row_layout() between bytes() and rows() ensures both upload (list.rs:726) and readback (list.rs:853) cleanly reject short-pitch footprints rather than returning overlapping per-row byte ranges or undersized spans.
  • The unit test covers both uncompressed (R8G8B8A8, format 28) and block-compressed (BC1, format 71) formats across valid, undersized, and exact-fit row pitches.
<!-- greyfinch-sync:Marvisak/VIctory:review:6068466294 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3034#pullrequestreview-6068466294). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T04:15:03Z. **Review:** APPROVED --- Looks clean and minimal on `374aaded`. - `PlacedFootprint::row_layout` computes `u64::from(self.width).div_ceil(block) * element` (overflow-free for all `u32` widths) and rejects footprints whose `row_pitch` is smaller than an unpadded row. - Sharing `row_layout()` between `bytes()` and `rows()` ensures both upload (`list.rs:726`) and readback (`list.rs:853`) cleanly reject short-pitch footprints rather than returning overlapping per-row byte ranges or undersized spans. - The unit test covers both uncompressed (`R8G8B8A8`, format 28) and block-compressed (`BC1`, format 71) formats across valid, undersized, and exact-fit row pitches.
kotekompotek commented 2026-11-26 05:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:36:43Z.

Review: APPROVED


LGTM — row_layout centralizes the row-fits-pitch requirement for both bytes() and rows(); the test hits the boundary exactly (row 260/264 at pitch 256 refused; width-1 → exactly 256 accepted). Format arithmetic checks out (28=RGBA8→260, 71=BC→264).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068608444 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3034#pullrequestreview-6068608444). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:36:43Z. **Review:** APPROVED --- LGTM — row_layout centralizes the row-fits-pitch requirement for both bytes() and rows(); the test hits the boundary exactly (row 260/264 at pitch 256 refused; width-1 → exactly 256 accepted). Format arithmetic checks out (28=RGBA8→260, 71=BC→264).
pawrenity commented 2026-11-26 05:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pawrenity on 2026-11-26T05:04:09Z.


VERIFY-3034: verified 374aade on NVIDIA GeForce RTX 4070, Windows 11 (MSVC). No defects found.

  • Regression: the new a_placed_footprint_pitch_covers_a_complete_row, with only the test hunk applied to origin/main 63bcca4, fails with accepted short row pitches: [(28, true, true), (71, true, true)] (both RGBA8 and BC1 accepted through bytes() and rows()). It passes at head.
  • cargo test -p victory-gpu --lib at head: 230 passed, 1 ignored, 2 failed. The two failures are dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, which also fail on main on this card (capped view heap). The existing footprint, upload and readback tests in resource::tests all pass.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings is clean, with and without --features diagnostics.
  • Trial merge onto origin/main 63bcca4 is clean.

Review (reading only): the row size ceil(width / block) * element matches D3D12_SUBRESOURCE_FOOTPRINT (RowPitch must hold at least one full row; BC rows are counted in 4x4 blocks). The test values check out: 65 RGBA8 texels are 260 bytes, 129 BC1 texels are 33 blocks of 8 = 264 bytes, and one texel fewer gives exactly 256. Buffer footprints (format 0) and the internally generated copyable_footprints layouts never fall below the row size, so they are unaffected. When a pitch is too short, the upload path (list.rs ~726) returns without recording, as it already does for an unsized format. The readback path (list.rs ~853) reports it as refused!("a region outside its footprint"), so the log reason is slightly loose for this case but the behaviour is correct.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183151581 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3034#issuecomment-7183151581). Originally posted by [pawrenity](https://github.com/pawrenity) on 2026-11-26T05:04:09Z. --- VERIFY-3034: verified `374aade` on NVIDIA GeForce RTX 4070, Windows 11 (MSVC). No defects found. - Regression: the new `a_placed_footprint_pitch_covers_a_complete_row`, with only the test hunk applied to origin/main `63bcca4`, fails with `accepted short row pitches: [(28, true, true), (71, true, true)]` (both RGBA8 and BC1 accepted through `bytes()` and `rows()`). It passes at head. - `cargo test -p victory-gpu --lib` at head: 230 passed, 1 ignored, 2 failed. The two failures are `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`, which also fail on main on this card (capped view heap). The existing footprint, upload and readback tests in `resource::tests` all pass. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` is clean, with and without `--features diagnostics`. - Trial merge onto origin/main `63bcca4` is clean. Review (reading only): the row size `ceil(width / block) * element` matches D3D12_SUBRESOURCE_FOOTPRINT (RowPitch must hold at least one full row; BC rows are counted in 4x4 blocks). The test values check out: 65 RGBA8 texels are 260 bytes, 129 BC1 texels are 33 blocks of 8 = 264 bytes, and one texel fewer gives exactly 256. Buffer footprints (format 0) and the internally generated `copyable_footprints` layouts never fall below the row size, so they are unaffected. When a pitch is too short, the upload path (`list.rs` ~726) returns without recording, as it already does for an unsized format. The readback path (`list.rs` ~853) reports it as `refused!("a region outside its footprint")`, so the log reason is slightly loose for this case but the behaviour is correct. AI-assisted (Claude Code).
Dukestar69 commented 2026-11-26 07:01:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:48:58Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):

  • Diff review: Validating row <= row_pitch inside PlacedFootprint::row_layout() cleanly rejects malformed copy footprints whose row pitch cannot hold a complete unpadded row in both bytes() and rows().
  • cargo test -p victory-gpu resource::tests -- --test-threads=1: 19 passed, 0 failed (including a_placed_footprint_pitch_covers_a_complete_row).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6069677472 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3034#pullrequestreview-6069677472). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:48:58Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090): - Diff review: Validating `row <= row_pitch` inside `PlacedFootprint::row_layout()` cleanly rejects malformed copy footprints whose row pitch cannot hold a complete unpadded row in both `bytes()` and `rows()`. - `cargo test -p victory-gpu resource::tests -- --test-threads=1`: 19 passed, 0 failed (including `a_placed_footprint_pitch_covers_a_complete_row`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Marvisak commented 2026-11-26 07:01:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:18:18Z.


Automated triage for the maintainers.

PlacedFootprint::bytes and rows (crates/victory-gpu/src/resource.rs) now return None when RowPitch is shorter than one unpadded row (ceil(width / block) * element). Both CopyTextureRegion paths in list.rs pass the title's footprint to the host with only its offset changed. Without this check, a too-short pitch reaches host D3D12, which requires RowPitch to hold a full row (public D3D12_SUBRESOURCE_FOOTPRINT docs). With it, the upload path skips the copy and the readback path refuses it, as both already do for unsized formats. main already checks the 256-byte pitch alignment, so this completes the validation. Unsized formats (element returns None) behave as before. I checked the test values: 65 RGBA8 texels = 260 bytes, and 129 BC1 texels = 33 blocks of 8 bytes = 264. The change is defensive, since a well-formed title call never hits it, but it is small and keeps an invalid call away from the host driver. It sits beside #3006 and #3022 in the same file, and the author says it applies cleanly with either.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184297322 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3034#issuecomment-7184297322). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:18:18Z. --- <!-- victory-triage v1 head=374aadedaef9d6c7edf7eeb4316b3f481e62e202 verdict=merge-candidate at=2026-11-26T06:24:00Z --> Automated triage for the maintainers. `PlacedFootprint::bytes` and `rows` (`crates/victory-gpu/src/resource.rs`) now return `None` when `RowPitch` is shorter than one unpadded row (`ceil(width / block) * element`). Both `CopyTextureRegion` paths in `list.rs` pass the title's footprint to the host with only its offset changed. Without this check, a too-short pitch reaches host D3D12, which requires `RowPitch` to hold a full row (public `D3D12_SUBRESOURCE_FOOTPRINT` docs). With it, the upload path skips the copy and the readback path refuses it, as both already do for unsized formats. `main` already checks the 256-byte pitch alignment, so this completes the validation. Unsized formats (`element` returns `None`) behave as before. I checked the test values: 65 RGBA8 texels = 260 bytes, and 129 BC1 texels = 33 blocks of 8 bytes = 264. The change is defensive, since a well-formed title call never hits it, but it is small and keeps an invalid call away from the host driver. It sits beside #3006 and #3022 in the same file, and the author says it applies cleanly with either. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
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/3034:upstream-pr/3034'
git switch 'upstream-pr/3034'

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