Reject overlapping depth slices in volume texture copies #21

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

@⁠Yoshi-233 on GitHub · 2026-11-25 12:26 UTC · original
Yoshi-233:fix/volume-copy-slice-stride → main · +47 −5 · 1 files · 1 commits · open

A 2×2×2 volume with two active bytes per row and a four-byte row pitch needs six bytes for each slice. On main, a depth pitch of zero or five is accepted. Tiling then reads the same bytes into successive slices, and detiling can overwrite bytes from the previous slice.

Compute the occupied extent through the end of the last active row and check it before either copy starts. A depth pitch of six is valid in this example, and a single-slice mip can still use zero.

Verification

The regression test failed against main and now passes for both linear and 4 KiB swizzled textures. It checks both copy directions, destination contents on error, a round trip at the minimum valid pitch, and the one-slice mip.

The full victory-formats library suite passed on both WSL and native Windows with 25 passed and 4 ignored on each. The staged asset-policy check passed. The repository-wide check still flags the existing 630,652-byte crates/victory-shader/src/emit/lower.rs against its 512 KiB limit.

Windows XG interface verification

On Windows build 26200 I also exercised the HLE's exported XGCreateTextureComputer and called both copy methods through its vtable. The synthetic R8_UNORM volume was 2×2×2 with two mips and a four-byte row pitch. With row-major and 4 KiB swizzled layouts and depth pitches of 0 and 5, main (71652a2) returned S_OK and modified the destination in all eight calls. At 28b2879, all eight returned E_INVALIDARG and the entire destination buffer retained its sentinel bytes.

Across both layouts, six valid round trips also preserved the active texels and output padding. These cover the minimum pitch of 6, a padded pitch of 8, and a single-slice mip with a pitch of 0.

**@⁠Yoshi-233** on GitHub · 2026-11-25 12:26 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/21) `Yoshi-233:fix/volume-copy-slice-stride` → `main` · +47 −5 · 1 files · 1 commits · open A 2×2×2 volume with two active bytes per row and a four-byte row pitch needs six bytes for each slice. On main, a depth pitch of zero or five is accepted. Tiling then reads the same bytes into successive slices, and detiling can overwrite bytes from the previous slice. Compute the occupied extent through the end of the last active row and check it before either copy starts. A depth pitch of six is valid in this example, and a single-slice mip can still use zero. ## Verification The regression test failed against main and now passes for both linear and 4 KiB swizzled textures. It checks both copy directions, destination contents on error, a round trip at the minimum valid pitch, and the one-slice mip. The full `victory-formats` library suite passed on both WSL and native Windows with 25 passed and 4 ignored on each. The staged asset-policy check passed. The repository-wide check still flags the existing 630,652-byte `crates/victory-shader/src/emit/lower.rs` against its 512 KiB limit. ## Windows XG interface verification On Windows build 26200 I also exercised the HLE's exported `XGCreateTextureComputer` and called both copy methods through its vtable. The synthetic R8_UNORM volume was 2×2×2 with two mips and a four-byte row pitch. With row-major and 4 KiB swizzled layouts and depth pitches of 0 and 5, main (`71652a2`) returned `S_OK` and modified the destination in all eight calls. At `28b2879`, all eight returned `E_INVALIDARG` and the entire destination buffer retained its sentinel bytes. Across both layouts, six valid round trips also preserved the active texels and output padding. These cover the minimum pitch of 6, a padded pitch of 8, and a single-slice mip with a pitch of 0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:33:15 +00:00
Author
Owner

@⁠Ekabusto on GitHub · 2026-11-25 12:47 UTC · original

Checked locally: cargo test -p victory-formats --lib passes (25 passed, 4 ignored), clippy clean, no conflicts.

The new bound is right: a depth slice must reach past the last active row. One point to be aware of: xg.rs:401/438 passes the title's own depth pitch. A title that passed a too-small pitch for a volume with more than one slice used to get an overlapping copy, and now gets an error. The callers inside the emulator (texture.rs:430, pitch * rows; texture.rs:873, linear.len()) always pass enough. Looks good to me.

Reviewed on Windows 11 (build 26300), Rust 1.98.1, each PR in its own worktree; no game data, not run in the game. AI-assisted (Claude Code).

**@⁠Ekabusto** on GitHub · 2026-11-25 12:47 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/21#issuecomment-7162864417) Checked locally: `cargo test -p victory-formats --lib` passes (25 passed, 4 ignored), clippy clean, no conflicts. The new bound is right: a depth slice must reach past the last active row. One point to be aware of: `xg.rs:401/438` passes the title's own depth pitch. A title that passed a too-small pitch for a volume with more than one slice used to get an overlapping copy, and now gets an error. The callers inside the emulator (`texture.rs:430`, `pitch * rows`; `texture.rs:873`, `linear.len()`) always pass enough. Looks good to me. Reviewed on Windows 11 (build 26300), Rust 1.98.1, each PR in its own worktree; no game data, not run in the game. AI-assisted (Claude Code).
Author
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 21:18 UTC · original · approved these changes

Verified on Linux (Rust 1.98.1)

  • cargo test -p victory-formats --lib on 28b2879: 25 passed, 0 failed, 4 ignored. Merged into current main with --no-commit: 25 passed, 0 failed.
  • Fail-without-fix: I put main's need computation back into Layout::walk and kept the new test. volume_depth_pitch_must_cover_the_last_active_row fails at texture.rs:1078 (left: Ok(()), right: Err(TooSmall)), so the pitch-0/5 case was accepted before. git status was clean afterwards.
  • cargo clippy -p victory-formats --target x86_64-pc-windows-msvc: 0 warnings, same as main.
  • git merge --no-commit --no-ff into main: merges cleanly.

Review notes

  • The bound is right. With depth_pitch >= slice_len = (height - 1) * row_pitch + bytes, slice z ends at z * dp + slice_len <= (z + 1) * dp, which is where slice z + 1 starts. Slices cannot overlap, in either copy direction, because tile and detile share walk.
  • m.height as usize - 1 can't underflow, because mip heights go through .max(1) (texture.rs:125/132).
  • For the record: the condition is sufficient but not necessary. An interleaved layout such as row_pitch = 4, bytes = 2, height = 2, depth_pitch = 2 puts slice 1's rows in slice 0's row padding without overlapping, and it is now refused as well. That seems fine to me, since no caller produces such a layout. I mention it only because the PR title says "overlapping". The doc comment (texture.rs:601, "must span the last active row") already states the exact rule.

Not verified

  • Behaviour through XGCreateTextureComputer on Windows (the HLE path in xg.rs), and any title that passes its own depth pitch.

Reviewed with Claude Code.

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:18 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/21#pullrequestreview-6065124156) · **approved these changes** ### Verified on Linux (Rust 1.98.1) - `cargo test -p victory-formats --lib` on 28b2879: 25 passed, 0 failed, 4 ignored. Merged into current main with `--no-commit`: 25 passed, 0 failed. - Fail-without-fix: I put main's `need` computation back into `Layout::walk` and kept the new test. `volume_depth_pitch_must_cover_the_last_active_row` fails at `texture.rs:1078` (`left: Ok(())`, `right: Err(TooSmall)`), so the pitch-0/5 case was accepted before. `git status` was clean afterwards. - `cargo clippy -p victory-formats --target x86_64-pc-windows-msvc`: 0 warnings, same as main. - `git merge --no-commit --no-ff` into main: merges cleanly. ### Review notes - The bound is right. With `depth_pitch >= slice_len = (height - 1) * row_pitch + bytes`, slice `z` ends at `z * dp + slice_len <= (z + 1) * dp`, which is where slice `z + 1` starts. Slices cannot overlap, in either copy direction, because `tile` and `detile` share `walk`. - `m.height as usize - 1` can't underflow, because mip heights go through `.max(1)` (`texture.rs:125/132`). - For the record: the condition is sufficient but not necessary. An interleaved layout such as `row_pitch = 4`, `bytes = 2`, `height = 2`, `depth_pitch = 2` puts slice 1's rows in slice 0's row padding without overlapping, and it is now refused as well. That seems fine to me, since no caller produces such a layout. I mention it only because the PR title says "overlapping". The doc comment (`texture.rs:601`, "must span the last active row") already states the exact rule. ### Not verified - Behaviour through `XGCreateTextureComputer` on Windows (the HLE path in `xg.rs`), and any title that passes its own depth pitch. Reviewed with Claude Code.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/21/head:github-bot/gh-21'
git switch 'github-bot/gh-21'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-21'
git switch 'github-bot/gh-21'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-21'
git switch 'github-bot/gh-21'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-21'
git switch 'main'
git merge --squash 'github-bot/gh-21'
git switch 'main'
git merge --ff-only 'github-bot/gh-21'
git switch 'main'
git merge 'github-bot/gh-21'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.