GPU: texture to buffer copies (read back) #1952

Closed
RaghavVijayanand wants to merge 1 commit from upstream-pr/1954 into main
RaghavVijayanand commented 2026-11-25 01:45:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RaghavVijayanand on 2026-11-25T01:45:10Z.


CopyTextureRegion into a title buffer (a placed footprint) was dropped with a warning ("texture to buffer copies not implemented"), so anything a title read back from the GPU stayed stale.

  • The host texture is now copied into a host buffer laid out as the footprint at offset 0. The host requires 512-byte aligned footprints, and the title's may not be.
  • That buffer is filled from title memory at submission, so only the copied rows change and pitch padding keeps the title's bytes.
  • After the list has run, the buffer goes into title memory before the list's bottom-of-pipe writes signal completion. Guarded blocks are opened first, so the next refresh of the buffer's host copy picks up the new bytes.

Shortcut, documented in the code: later GPU work in the same submission that reads that buffer sees its old bytes. Titles read back for the CPU, after a fence.

Tests: resource::tests::texture_data_reaches_the_title_buffer copies a title buffer into a texture, then the texture into another title buffer at offset 64, through our list and queue.

  • It checks the rows, the padding between them and the bytes around the footprint.
  • It fails without the write into title memory.
  • 343 workspace tests pass, and clippy passes with -D warnings, with and without --all-features.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6595220633 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1954). Originally posted by [RaghavVijayanand](https://github.com/RaghavVijayanand) on 2026-11-25T01:45:10Z. --- `CopyTextureRegion` into a title buffer (a placed footprint) was dropped with a warning ("texture to buffer copies not implemented"), so anything a title read back from the GPU stayed stale. - The host texture is now copied into a host buffer laid out as the footprint at offset 0. The host requires 512-byte aligned footprints, and the title's may not be. - That buffer is filled from title memory at submission, so only the copied rows change and pitch padding keeps the title's bytes. - After the list has run, the buffer goes into title memory before the list's bottom-of-pipe writes signal completion. Guarded blocks are opened first, so the next refresh of the buffer's host copy picks up the new bytes. Shortcut, documented in the code: later GPU work in the same submission that reads that buffer sees its old bytes. Titles read back for the CPU, after a fence. **Tests:** `resource::tests::texture_data_reaches_the_title_buffer` copies a title buffer into a texture, then the texture into another title buffer at offset 64, through our list and queue. - It checks the rows, the padding between them and the bytes around the footprint. - It fails without the write into title memory. - 343 workspace tests pass, and clippy passes with `-D warnings`, with and without `--all-features`.
copilot-pull-request-reviewer[bot commented 2026-11-25 02:05:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T01:45:17Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Marvisak/VIctory:review:6050341750 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1954#pullrequestreview-6050341750). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-25T01:45:17Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
upipibi commented 2026-11-25 02:06:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T01:54:27Z.


Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 9e0a2d1. victory-shader: 120 passed, 0 failed. victory-gpu: 51 passed, 0 failed. Note that the branch is based on ffe310e, so these are that base's test sets, not current main's. A rebase would let it be checked against main's tests (and its NVIDIA heap-cap failures). Not run: a title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150097429 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1954#issuecomment-7150097429). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T01:54:27Z. --- Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `9e0a2d1`. `victory-shader`: 120 passed, 0 failed. `victory-gpu`: 51 passed, 0 failed. Note that the branch is based on `ffe310e`, so these are that base's test sets, not current `main`'s. A rebase would let it be checked against `main`'s tests (and its NVIDIA heap-cap failures). Not run: a title. AI-assisted (Claude Code).
catminou4 commented 2026-11-25 03:02:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T02:10:30Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Texture-to-buffer copies (read back…): copy path extension — pairs with #1816/#1869 copyback work.

<!-- greyfinch-sync:Marvisak/VIctory:review:6050613168 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1954#pullrequestreview-6050613168). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T02:10:30Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Texture-to-buffer copies (read back…): copy path extension — pairs with #1816/#1869 copyback work.
AlanQiang0418 commented 2026-11-25 03:03:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AlanQiang0418 on 2026-11-25T02:27:11Z.


Two disjoint readbacks into the same placed footprint can erase one another on 9e0a2d1. I used the existing 4×4 RGBA8 fixture, destination offset 64, row pitch 256, initialized to 0xEE. In one command list I copied the left two columns and then the right two into their corresponding positions. After completion, row 0 began EE EE EE EE EE EE EE EE 08 09 0A 0B 0C 0D 0E 0F; the expected bytes are 00..0F. RTX 5080 and WARP reproduced it. Each copy prefilled a separate staging footprint from the same original buffer and then wrote the entire footprint back, so the second one restored the left half's old bytes.

Follow-up commit with the fix and regression. It copies back only the row spans written by each command, in submission order; #137 also used row spans in its earlier partial-readback work. The fixture now checks all 2,048 destination bytes, covering the two writes, a whole-subresource copy at a second offset, padding and adjacent bytes. A separate arithmetic test covers BC1 blocks across two slices.

The victory-gpu diagnostics library suite passed on RTX 5080 and WARP (55 passed, 1 ignored on each). GPU all-targets/all-features Clippy also passed. The BC1 case checks the span calculation; the device readback uses RGBA8.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150740649 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1954#issuecomment-7150740649). Originally posted by [AlanQiang0418](https://github.com/AlanQiang0418) on 2026-11-25T02:27:11Z. --- Two disjoint readbacks into the same placed footprint can erase one another on `9e0a2d1`. I used the existing 4×4 RGBA8 fixture, destination offset 64, row pitch 256, initialized to `0xEE`. In one command list I copied the left two columns and then the right two into their corresponding positions. After completion, row 0 began `EE EE EE EE EE EE EE EE 08 09 0A 0B 0C 0D 0E 0F`; the expected bytes are `00..0F`. RTX 5080 and WARP reproduced it. Each copy prefilled a separate staging footprint from the same original buffer and then wrote the entire footprint back, so the second one restored the left half's old bytes. [Follow-up commit with the fix and regression](https://github.com/AlanQiang0418/VIctory/commit/f114ee74fc68d8fe400f17906ac9bd4fff592a51). It copies back only the row spans written by each command, in submission order; [#137](https://github.com/Marvisak/VIctory/pull/137) also used row spans in its earlier partial-readback work. The fixture now checks all 2,048 destination bytes, covering the two writes, a whole-subresource copy at a second offset, padding and adjacent bytes. A separate arithmetic test covers BC1 blocks across two slices. The `victory-gpu` diagnostics library suite passed on RTX 5080 and WARP (55 passed, 1 ignored on each). GPU all-targets/all-features Clippy also passed. The BC1 case checks the span calculation; the device readback uses RGBA8.
Marvisak commented 2026-11-25 09:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:21:18Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/host.rs, crates/victory-gpu/src/list.rs, crates/victory-gpu/src/resource.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs work) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156922075 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1954#issuecomment-7156922075). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:21:18Z. --- <!-- victory-triage v1 head=9e0a2d1c3126326fdb9e52256334540de2c2a16d verdict=needs-rebase at=2026-11-25T16:14:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/list.rs`, `crates/victory-gpu/src/resource.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-26 13:03:34 +00:00
RaghavVijayanand commented 2026-11-26 13:04:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RaghavVijayanand on 2026-11-26T12:24:51Z.


Closing as superseded by main. 5cb63d8 ("GPU: texture to buffer copies read back into the title's buffer") does the same through readback memory, and it writes back only the rows each copy touched (footprint.rows(at, size)). So the overwrite between disjoint copies that @AlanQiang0418 found, and fixed in f114ee7, cannot happen there. Thanks for the careful repro and fix.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7191969740 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1954#issuecomment-7191969740). Originally posted by [RaghavVijayanand](https://github.com/RaghavVijayanand) on 2026-11-26T12:24:51Z. --- Closing as superseded by `main`. 5cb63d8 ("GPU: texture to buffer copies read back into the title's buffer") does the same through readback memory, and it writes back only the rows each copy touched (`footprint.rows(at, size)`). So the overwrite between disjoint copies that @AlanQiang0418 found, and fixed in f114ee7, cannot happen there. Thanks for the careful repro and fix.

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