fix(gpu): preserve source and destination pixels in texture readbacks #137

Closed
jeremygold02 wants to merge 4 commits from upstream-pr/137 into main
jeremygold02 commented 2026-11-24 00:51:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T00:51:06Z.


Depends on #67. Please merge #67 first. This branch adds two commits on top of #67 at b5c38fa. The first preserves pixels outside the destination region. The second preserves the GPU-written source during readback. GitHub’s full diff also includes the two commits from #67.

A texture-to-buffer copy may write only part of its destination. The GPU writes the requested rectangle into staging. The host then copies the entire destination footprint back into title memory, replacing pixels outside the rectangle. This follow-up copies only the affected row spans in each depth slice, using the source box or the selected subresource’s extent and the destination coordinates.

On a physical RTX 5070 (driver 621.01), I prefilled a 4×4 RGBA8 destination and copied a 2×2 source box into its top-left corner. At the dependency head all 4 requested pixels matched and 0 of the 12 neighboring pixels retained their values. With this change all 4 requested pixels matched and all 12 neighbors retained their values. A whole 4×4 source copied to (1,1) in a packed 6×6 destination also matched all 36 expected pixels. Both cases are included in the synthetic test.

All 37 victory-gpu library tests passed on Windows at the follow-up head. Diagnostics Clippy with warnings denied and git diff --check passed. The original hardware verification on #67 records the comparison.

Integration with main at d2a4bae. The locally tested Git tree is identical to the clean merge of this branch with d2a4bae, including the merged test-module fix from #129. The GPU library suites passed with 44 default and 46 diagnostics tests, including the readback regression in both. Each configuration ignored one benchmark. Both library configurations also passed cargo check on the earlier GitHub merge preview. AI-assisted.

RTX 5070 mission-loading verification. Two interactive runs using the combined tree above reached a guest texture-to-buffer readback. In each run, a local probe queried the D3D12 queue fence and observed the requested submission value complete before copying two row spans (96 bytes total) into guest memory. The first run stopped at that checkpoint. The second continued for 20 more CPU present calls before manual closure. The synthetic sentinel test above remains the evidence that neighboring pixels are preserved. The live runs exercised #67 and this follow-up together. Later rendering and frame time remain unresolved.

GPU-written source regression at 31979ad2. On a physical RTX 5070 (driver 621.01), clearing a linear-layout 4×4 RGBA8 render target to magenta and immediately copying it through the guest texture-to-buffer path returned 00 00 00 00 at pixel (0,0) on 219e3ce. The readback path uploaded stale title memory over the GPU clear. Applying the existing texture::title_written check before the upload preserves all 16 magenta pixels. A separate CPU-populated linear texture returned all 16 expected pixels. The regression uses synthetic inputs. All 37 default GPU library tests, diagnostics Clippy with warnings denied, and git diff --check passed on Windows. The earlier mission trace lacks source layout and last-writer information for its two readback spans, so it cannot establish whether the mission exercised this case.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572061496 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/137). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T00:51:06Z. --- **Depends on #67. Please merge #67 first.** This branch adds two commits on top of #67 at `b5c38fa`. The [first](https://github.com/jeremygold02/VIctory/commit/219e3cefc1b234fe6f8c93252a6ceae735a6897f) preserves pixels outside the destination region. The [second](https://github.com/jeremygold02/VIctory/commit/31979ad2a749e147ad6cd8e3219b0894c8002d71) preserves the GPU-written source during readback. GitHub’s full diff also includes the two commits from #67. A texture-to-buffer copy may write only part of its destination. The GPU writes the requested rectangle into staging. The host then copies the entire destination footprint back into title memory, replacing pixels outside the rectangle. This follow-up copies only the affected row spans in each depth slice, using the source box or the selected subresource’s extent and the destination coordinates. On a physical RTX 5070 (driver 621.01), I prefilled a 4×4 RGBA8 destination and copied a 2×2 source box into its top-left corner. At the dependency head all 4 requested pixels matched and 0 of the 12 neighboring pixels retained their values. With this change all 4 requested pixels matched and all 12 neighbors retained their values. A whole 4×4 source copied to (1,1) in a packed 6×6 destination also matched all 36 expected pixels. Both cases are included in the synthetic test. All 37 `victory-gpu` library tests passed on Windows at the follow-up head. Diagnostics Clippy with warnings denied and `git diff --check` passed. The [original hardware verification on #67](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7118286557) records the comparison. **Integration with main at `d2a4bae`.** The locally tested Git tree is identical to the clean merge of this branch with `d2a4bae`, including the merged test-module fix from #129. The GPU library suites passed with 44 default and 46 diagnostics tests, including the readback regression in both. Each configuration ignored one benchmark. Both library configurations also passed `cargo check` on the earlier GitHub merge preview. AI-assisted. **RTX 5070 mission-loading verification.** Two interactive runs using the combined tree above reached a guest texture-to-buffer readback. In each run, a local probe queried the D3D12 queue fence and observed the requested submission value complete before copying two row spans (96 bytes total) into guest memory. The first run stopped at that checkpoint. The second continued for 20 more CPU present calls before manual closure. The synthetic sentinel test above remains the evidence that neighboring pixels are preserved. The live runs exercised #67 and this follow-up together. Later rendering and frame time remain unresolved. **GPU-written source regression at `31979ad2`.** On a physical RTX 5070 (driver 621.01), clearing a linear-layout 4×4 RGBA8 render target to magenta and immediately copying it through the guest texture-to-buffer path returned `00 00 00 00` at pixel (0,0) on `219e3ce`. The readback path uploaded stale title memory over the GPU clear. Applying the existing `texture::title_written` check before the upload preserves all 16 magenta pixels. A separate CPU-populated linear texture returned all 16 expected pixels. The regression uses synthetic inputs. All 37 default GPU library tests, diagnostics Clippy with warnings denied, and `git diff --check` passed on Windows. The earlier mission trace lacks source layout and last-writer information for its two readback spans, so it cannot establish whether the mission exercised this case.
nullmarsh commented 2026-11-24 06:54:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by nullmarsh on 2026-11-24T01:12:36Z.


AMD run: head 219e3ce. cargo test --workspace on main 9aef3d9 + #129 (main's victory-gpu tests don't compile without it) + this PR, AMD Radeon RX 9060 XT (RDNA4), Windows 11 Pro 26200, Rust 1.98.1, debug: copy_texture_region_reads_back_into_title_buffer and the rest of victory-gpu pass.

One run of the suite died with 0xC0000005 in victory_shader's tests. That's not from this PR (it doesn't touch that crate): it's the intermittent parallel-GPU-test crash on main, now #181.

AI use

  • Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs; I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7118870054 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/137#issuecomment-7118870054). Originally posted by [nullmarsh](https://github.com/nullmarsh) on 2026-11-24T01:12:36Z. --- AMD run: head `219e3ce`. `cargo test --workspace` on `main` `9aef3d9` + #129 (main's `victory-gpu` tests don't compile without it) + this PR, AMD Radeon RX 9060 XT (RDNA4), Windows 11 Pro 26200, Rust 1.98.1, debug: `copy_texture_region_reads_back_into_title_buffer` and the rest of `victory-gpu` pass. One run of the suite died with `0xC0000005` in `victory_shader`'s tests. That's not from this PR (it doesn't touch that crate): it's the intermittent parallel-GPU-test crash on `main`, now #181. **AI use** - Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs; I checked it before posting.
miniongk commented 2026-11-24 06:55:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by miniongk on 2026-11-24T05:11:52Z.


Tested 219e3ce (including #67) combined with #413, #320, #483 and #89 on an RTX 5080, driver 621.24, Windows 11 26300, local Xbox Series 1.0.2.1.

  • resource::tests::copy_texture_region_reads_back_into_title_buffer passed on hardware in 0.23 s.
  • cargo test --workspace on the integrated tree: 291 passed, 0 failed, 4 ignored.
  • On the real title path, the previous texture to buffer copies not implemented warning is gone.
  • The run still reaches the same explicit null-write fatal path in title code as without this patch. So the readback path is exercised, but it is not sufficient to resolve that later failure.

Only aggregate counts and error classes shared; no game data or raw game logs. AI-assisted (Kimi Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122716365 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/137#issuecomment-7122716365). Originally posted by [miniongk](https://github.com/miniongk) on 2026-11-24T05:11:52Z. --- Tested `219e3ce` (including #67) combined with #413, #320, #483 and #89 on an RTX 5080, driver 621.24, Windows 11 26300, local Xbox Series 1.0.2.1. - `resource::tests::copy_texture_region_reads_back_into_title_buffer` passed on hardware in 0.23 s. - `cargo test --workspace` on the integrated tree: 291 passed, 0 failed, 4 ignored. - On the real title path, the previous `texture to buffer copies not implemented` warning is gone. - The run still reaches the same explicit null-write fatal path in title code as without this patch. So the readback path is exercised, but it is not sufficient to resolve that later failure. Only aggregate counts and error classes shared; no game data or raw game logs. AI-assisted (Kimi Code).
upstream-sync changed title from [PR #137] fix(gpu): preserve pixels outside texture readback regions to [PR #137] fix(gpu): preserve source and destination pixels in texture readbacks 2026-11-24 17:02:20 +00:00
alessiodeia commented 2026-11-25 01:08:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alessiodeia on 2026-11-25T00:41:17Z.


@jeremygold02, the maintainer's triage on #67 asked to fold this fix into #67, so I've merged your two commits (219e3ce, 31979ad) into its branch with your authorship intact (#67 head 1e59257). I also added the requested sentinel case (a 2×2 box at x = 1 in a 4×4 footprint) next to your two partial cases, and merged current main. The only conflict was main's new watch::writing guard in host.rs. I kept your per-box logic and held the guard across the write. Thanks for the fix. If #67 lands, this draft should have nothing left to add, but I'll leave closing it to you.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148772218 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/137#issuecomment-7148772218). Originally posted by [alessiodeia](https://github.com/alessiodeia) on 2026-11-25T00:41:17Z. --- @jeremygold02, the maintainer's triage on #67 asked to fold this fix into #67, so I've merged your two commits (`219e3ce`, `31979ad`) into its branch with your authorship intact (#67 head `1e59257`). I also added the requested sentinel case (a 2×2 box at `x = 1` in a 4×4 footprint) next to your two partial cases, and merged current `main`. The only conflict was main's new `watch::writing` guard in `host.rs`. I kept your per-box logic and held the guard across the write. Thanks for the fix. If #67 lands, this draft should have nothing left to add, but I'll leave closing it to you.
upstream-sync closed this pull request 2026-11-25 03:01:34 +00:00
jeremygold02 commented 2026-11-25 03:03:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T02:52:44Z.


@alessiodeia Thanks for folding both fixes into #67 and adding the offset sentinel case. I verified that both of my commits, 219e3ce and 31979ad, are in #67 at 1e59257. I've closed this draft so review can continue in #67.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151304701 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/137#issuecomment-7151304701). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T02:52:44Z. --- @alessiodeia Thanks for folding both fixes into #67 and adding the offset sentinel case. I verified that both of my commits, `219e3ce` and `31979ad`, are in #67 at `1e59257`. I've closed this draft so review can continue in #67.

Pull request closed

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!137
No description provided.