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

Closed
github-bot wants to merge 1 commit from github-bot/gh-1954 into main AGit
Owner

@⁠RaghavVijayanand on GitHub · 2026-11-25 01:45 UTC · original
RaghavVijayanand:gpu/texture-readback → main · +228 −4 · 3 files · 1 commits · closed without merging

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.
**@⁠RaghavVijayanand** on GitHub · 2026-11-25 01:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/1954) `RaghavVijayanand:gpu/texture-readback` → `main` · +228 −4 · 3 files · 1 commits · closed without merging `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`.
CopyTextureRegion into a title buffer (a placed footprint) was dropped
with a warning, so whatever a title read back from the GPU stayed as it
was. The host texture is now copied into a host buffer laid out as the
footprint at offset 0, since the host wants 512-byte aligned footprints
and the title's may not be. That buffer is filled from title memory at
submission, so the copy changes only its rows and pitch padding keeps
the title's bytes. Once the list has run, it goes into title memory
before the list's bottom-of-pipe writes tell the title the GPU is done,
with guarded blocks opened first so the next refresh of the buffer's
host copy takes the new bytes.

Later work of the same submission that reads the buffer on the GPU still
sees its bytes from before the copy; titles read back for the CPU, after
a fence.

resource::tests::texture_data_reaches_the_title_buffer copies a title
buffer into a texture and the texture into another title buffer at
offset 64 through our list and queue, and checks the rows, the padding
between them and the bytes around the footprint. It fails without the
copy into title memory.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:57 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 01:54 UTC · original

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

**@⁠upipibi** on GitHub · 2026-11-25 01:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1954#issuecomment-7150097429) 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).
Author
Owner

@⁠AlanQiang0418 on GitHub · 2026-11-25 02:27 UTC · original

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.

**@⁠AlanQiang0418** on GitHub · 2026-11-25 02:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1954#issuecomment-7150740649) 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://git.gtahub.st/github/Marvisak--VIctory/pulls/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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:21 UTC · original · edited 2026-11-25 16:02 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 08:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1954#issuecomment-7156922075) · edited 2026-11-25 16:02 UTC <!-- 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)_
github-bot closed this pull request 2026-11-26 12:25:29 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 01:45 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 01:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/1954#pullrequestreview-6050341750) · **reviewed** 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.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 02:10 UTC · original · reviewed

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.

**@⁠catminou4** on GitHub · 2026-11-25 02:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1954#pullrequestreview-6050613168) · **reviewed** 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.
Author
Owner

@⁠RaghavVijayanand on GitHub · 2026-11-26 12:24 UTC · original

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.

**@⁠RaghavVijayanand** on GitHub · 2026-11-26 12:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1954#issuecomment-7191969740) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1954
No description provided.