Reject overlapping depth slices in volume texture copies #21
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!21
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-21"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 · openA 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-formatslibrary 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-bytecrates/victory-shader/src/emit/lower.rsagainst its 512 KiB limit.Windows XG interface verification
On Windows build 26200 I also exercised the HLE's exported
XGCreateTextureComputerand 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) returnedS_OKand modified the destination in all eight calls. At28b2879, all eight returnedE_INVALIDARGand 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.
@Ekabusto on GitHub · 2026-11-25 12:47 UTC · original
Checked locally:
cargo test -p victory-formats --libpasses (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/438passes 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).
@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 --libon28b2879: 25 passed, 0 failed, 4 ignored. Merged into current main with--no-commit: 25 passed, 0 failed.needcomputation back intoLayout::walkand kept the new test.volume_depth_pitch_must_cover_the_last_active_rowfails attexture.rs:1078(left: Ok(()),right: Err(TooSmall)), so the pitch-0/5 case was accepted before.git statuswas clean afterwards.cargo clippy -p victory-formats --target x86_64-pc-windows-msvc: 0 warnings, same as main.git merge --no-commit --no-ffinto main: merges cleanly.Review notes
depth_pitch >= slice_len = (height - 1) * row_pitch + bytes, slicezends atz * dp + slice_len <= (z + 1) * dp, which is where slicez + 1starts. Slices cannot overlap, in either copy direction, becausetileanddetilesharewalk.m.height as usize - 1can't underflow, because mip heights go through.max(1)(texture.rs:125/132).row_pitch = 4,bytes = 2,height = 2,depth_pitch = 2puts 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
XGCreateTextureComputeron Windows (the HLE path inxg.rs), and any title that passes its own depth pitch.Reviewed with Claude Code.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.