fix(victory-gpu): preserve bytes outside texture readback regions #311

Open
mauroalvare wants to merge 5 commits from upstream-pr/311 into main
mauroalvare commented 2026-11-26 02:15:49 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-26T02:15:49Z.


Change

In Neptune's D3D12 CopyTextureRegion texture-to-buffer path, the GPU copied the requested box into staging. The deferred CPU copy then wrote every row of the destination footprint, including bytes outside the box. A 2×2 box read back into a 4×4 footprint overwrote adjacent title data even though the GPU copied the four requested texels correctly.

Carry the region, row pitches and slice stride through the deferred copy. The title buffer receives only the rows and bytes written by the GPU, including when the destination has a nonzero origin. An omitted box uses the selected source mip's dimensions. This path is in victory-gpu, which tools/lancer_victory.ps1 builds and launches.

The region handling adapts Marvisak/VIctory 5cb63d8 to Neptune's deferred readback and separate host and title pitches. The commit and THIRD_PARTY.md retain attribution. Microsoft's CopyTextureRegion contract

Verification

Base c4c93bdc413191a9dc909998d2d53080a3f0c880. Fix 3f11d6cd59be6f7ccb5b2caa966cff338e05e764. Windows x64, Rust 1.98.1 MSVC, RTX 5070 Ti with driver 621.40 and Microsoft WARP.

The minimal synthetic case uploads a 4×4 RGBA8 texture through the emulated command-list slot, then copies a 2×2 box to a title buffer filled with 0xcd. At the same 64-byte title pitch and 256-byte host pitch, base changed byte 520 from 0xcd to 0x00 on both adapters. The same minimal case passed with the fix. The committed test also covers a nonzero destination origin and a whole source copied into a larger footprint. It compares all 4,096 bytes and passed on both adapters with 96 bytes copied and 4,000 unchanged. Neither focused run skipped.

Command from third_party/victory Result
cargo test --locked --offline -p victory-gpu --lib --features diagnostics resource::tests::a_partial_texture_readback_preserves_unwritten_bytes -- --exact --nocapture --test-threads=1 1 passed on NVIDIA, 1 passed with VICTORY_D3D12_WARP=1
cargo test --locked --offline -p victory-gpu --lib --features diagnostics resource::tests::readback_layout_counts_block_rows_and_volume_slices -- --exact 1 passed, checking BC1 block rows and 3D slice strides
cargo test --locked --offline -p victory-gpu --lib --features diagnostics -- --test-threads=1 198 passed, 3 failed, 3 ignored. Base had the same 3 failures and ignores
cargo test --locked --offline -p victory-loader --test load_probe 2 passed
cargo build --locked --offline --release -p victory Passed
cargo xtask policy 199 files OK

The three base failures are spans_say_the_next_start_and_the_lowest_level_viewed, warp_card_fetch_copies_flagged_pieces_to_their_slots, and warp_card_patch_writes_the_masked_bytes_and_no_others.

From the repository root, python -m pytest -rs passed 1,342 tests and skipped 323 that require built runtime or GPU artifacts absent from this checkout. python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools passed.

Oracle and test data

The test computes the expected pixels and all untouched bytes from the original synthetic upload and the destination sentinel. The fixture uses small committed resources and holds them through submission and readback. All inputs are generated by the test.

Prepared with AI assistance (OpenAI Codex).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5502766784 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/311). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-26T02:15:49Z. --- ## Change In Neptune's D3D12 `CopyTextureRegion` texture-to-buffer path, the GPU copied the requested box into staging. The deferred CPU copy then wrote every row of the destination footprint, including bytes outside the box. A 2×2 box read back into a 4×4 footprint overwrote adjacent title data even though the GPU copied the four requested texels correctly. Carry the region, row pitches and slice stride through the deferred copy. The title buffer receives only the rows and bytes written by the GPU, including when the destination has a nonzero origin. An omitted box uses the selected source mip's dimensions. This path is in `victory-gpu`, which `tools/lancer_victory.ps1` builds and launches. The region handling adapts [Marvisak/VIctory `5cb63d8`](https://github.com/Marvisak/VIctory/commit/5cb63d8b28b950a2f4d25bef1c341de133771c24) to Neptune's deferred readback and separate host and title pitches. The commit and `THIRD_PARTY.md` retain attribution. [Microsoft's `CopyTextureRegion` contract](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist-copytextureregion) ## Verification Base `c4c93bdc413191a9dc909998d2d53080a3f0c880`. Fix `3f11d6cd59be6f7ccb5b2caa966cff338e05e764`. Windows x64, Rust 1.98.1 MSVC, RTX 5070 Ti with driver 621.40 and Microsoft WARP. The minimal synthetic case uploads a 4×4 RGBA8 texture through the emulated command-list slot, then copies a 2×2 box to a title buffer filled with `0xcd`. At the same 64-byte title pitch and 256-byte host pitch, base changed byte 520 from `0xcd` to `0x00` on both adapters. The same minimal case passed with the fix. The committed test also covers a nonzero destination origin and a whole source copied into a larger footprint. It compares all 4,096 bytes and passed on both adapters with 96 bytes copied and 4,000 unchanged. Neither focused run skipped. | Command from `third_party/victory` | Result | | --- | --- | | `cargo test --locked --offline -p victory-gpu --lib --features diagnostics resource::tests::a_partial_texture_readback_preserves_unwritten_bytes -- --exact --nocapture --test-threads=1` | 1 passed on NVIDIA, 1 passed with `VICTORY_D3D12_WARP=1` | | `cargo test --locked --offline -p victory-gpu --lib --features diagnostics resource::tests::readback_layout_counts_block_rows_and_volume_slices -- --exact` | 1 passed, checking BC1 block rows and 3D slice strides | | `cargo test --locked --offline -p victory-gpu --lib --features diagnostics -- --test-threads=1` | 198 passed, 3 failed, 3 ignored. Base had the same 3 failures and ignores | | `cargo test --locked --offline -p victory-loader --test load_probe` | 2 passed | | `cargo build --locked --offline --release -p victory` | Passed | | `cargo xtask policy` | 199 files OK | The three base failures are `spans_say_the_next_start_and_the_lowest_level_viewed`, `warp_card_fetch_copies_flagged_pieces_to_their_slots`, and `warp_card_patch_writes_the_masked_bytes_and_no_others`. From the repository root, `python -m pytest -rs` passed 1,342 tests and skipped 323 that require built runtime or GPU artifacts absent from this checkout. `python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools` passed. ## Oracle and test data The test computes the expected pixels and all untouched bytes from the original synthetic upload and the destination sentinel. The fixture uses small committed resources and holds them through submission and readback. All inputs are generated by the test. Prepared with AI assistance (OpenAI Codex).
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/311:upstream-pr/311'
git switch 'upstream-pr/311'

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