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

Open
github-bot wants to merge 4 commits from github-bot/gh-311 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 02:15 UTC · original
mauroalvare:codex/victory-readback-region → main · +297 −53 · 4 files · 4 commits · open

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).

**@⁠mauroalvare** on GitHub · 2026-11-26 02:15 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/311) `mauroalvare:codex/victory-readback-region` → `main` · +297 −53 · 4 files · 4 commits · open ## 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).
Carry the copied rectangle into the deferred readback and use the
original footprint pitches for both buffers. This preserves data outside
the region, including when the copy starts at a nonzero destination
coordinate or the destination footprint is larger than the source mip.

Source: Marvisak/VIctory 5cb63d8b28b950a2f4d25bef1c341de133771c24
Co-authored-by: Marvis <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:41 +00:00
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/311/head:github-bot/gh-311'
git switch 'github-bot/gh-311'

Merge

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