Repository navigation
GPU: implement CopyTextureRegion texture-to-buffer readbacks - #67
alessiodeia wants to merge 10 commits into
Conversation
Implements the previously stubbed texture-to-buffer path in CopyTextureRegion: - Add mapped D3D12_HEAP_TYPE_READBACK staging allocation (Host::readback_buffer, HostList::readback) and post-submission copy-back (HostList::defer_readback) that writes completed GPU readbacks into title memory via watch::writing + write_mapped before bottom-of-pipe completion writes. - Align staging RowPitch to 256 bytes (D3D12_TEXTURE_DATA_PITCH_ALIGNMENT) and copy row by row when a title footprint uses an unaligned row pitch; translate console formats with pc_format and check footprint arithmetic against overflow. - Upload CPU-written source textures (texture::upload) and transition to COPY_SOURCE before recording CopyTextureRegion. - Add an end-to-end GPU test in victory-gpu covering 256-aligned readback at a non-zero offset, unaligned packed row_pitch (16 bytes), and partial 2x2 source_box cropping. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com>
|
Reviewing |
| let mut to_location = dst; | ||
| to_location.resource = buffer.as_raw().cast_const().cast(); | ||
| to_location.footprint.offset = 0; | ||
| to_location.footprint.format = crate::resource::pc_format(dst.footprint.format); |
There was a problem hiding this comment.
Okay, verify this but I believe title formats 118–120 use 3 bytes per texel. Our PC GPUs will store them as 4 bytes per texel so check this one out.
Addresses review feedback on Marvisak#67: console formats 118..=120 (3-byte D16_UNORM_S8_UINT and its typeless views) map to 4-byte PC substitutes (45..=47). Check element(pc_format(format)) == element(format) before staging a texture-to-buffer readback so mismatched formats are skipped with a warning rather than mis-sizing the staging buffer or writing the wrong texel layout, and cover format 118 in the readback test. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com>
|
@raffclar Good catch — verified in Fixed in
Re-tested with |
|
Approved |
|
I checked One additional valid partial copy loses neighboring pixels. I prefilled a 4×4 destination with The deferred host readback copies the width and line count of the destination footprint even when the GPU wrote a smaller rectangle into staging. The correction is in upstream draft #137, which depends on this PR. At |
Copy only the rows, columns and depth slices written into the staging footprint. Preserve surrounding texels for boxed and whole-subresource copies into larger destinations. Refs: Marvisak#67
|
Tested
No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent). |
|
@jeremygold02 @martingouv @DaviTostes Thanks all for the thorough testing!
|
|
We ran the Wine retest suggested above on main We also ran #137’s partial-copy control on the same setup. With #67 alone, untouched destination pixel (2,0) changed from |
Applied as the net diff of upstream PR Marvisak#67 (head b5c38fa), 2 commits: b5c38fa,1ac256cf.
Apply the existing texture ownership check before staging title memory. Exercise a GPU-cleared linear render target and a CPU-populated linear texture through the guest copy path. Refs: Marvisak#67
…sak#67; docs and results
Conflicts: list.rs kept the base's prepare_footprint_upload (packed 16-bit widening) and the buffer-to-texture path that uses it, with Marvisak#67's readback branch ahead of it; the readback now uploads the source from title memory only when title_written, like the texture-to-texture path, so a render target is not overwritten by stale staging. resource.rs kept both tests (unordered_writes_reach_a_depth_target and the readback test).
…sak#67; docs and results
…PipelineStateX (console caches): E_NOTIMPL, cleared out, named
|
@alessiodeia this was fine on its own at Checked on main Those calls, as checked: VIctory/crates/victory-gpu/src/list.rs Lines 567 to 568 in b5c38fa
Borrowing both arguments is enough for the type check on that merged tree. It cannot land on this PR while Compile only ( AI-assisted; Windows workspace check of that two-PR merge, run on this machine. |
…acks main's watch::writing now returns a Writing guard that must live while the write happens. Keep it across each readback write. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Updated for today's What Verified on Windows 11 with an RTX 2070 SUPER (driver 621.40):
@CaravelaLabs, thanks for re-checking against #32. I tried the borrow here, but on current |
|
@alessiodeia thanks, you're right. I only type-checked the borrow. While AI-assisted. |
Addresses review feedback on Marvisak#67: console formats 118..=120 (3-byte D16_UNORM_S8_UINT and its typeless views) map to 4-byte PC substitutes (45..=47). Check element(pc_format(format)) == element(format) before staging a texture-to-buffer readback so mismatched formats are skipped with a warning rather than mis-sizing the staging buffer or writing the wrong texel layout, and cover format 118 in the readback test. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com>
Conflicts: list.rs kept the base's prepare_footprint_upload (packed 16-bit widening) and the buffer-to-texture path that uses it, with Marvisak#67's readback branch ahead of it; the readback now uploads the source from title memory only when title_written, like the texture-to-texture path, so a render target is not overwritten by stale staging. resource.rs kept both tests (unordered_writes_reach_a_depth_target and the readback test).
…sak#67; docs and results
|
Automated triage for the maintainers. Needs work. This implements texture-to-buffer Blocking: the deferred copy writes the full destination footprint (every line at full CI: the Generated by Claude Code |
# Conflicts: # crates/victory-gpu/src/host.rs
…ytes around it The readback test now also writes the crop box at a non-zero x into a 4x4 footprint and checks that every byte outside the box keeps the 0xa5 sentinel, the partial-copy case requested in review. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. Addressed in
Verified on Windows 11 with an RTX 2070 SUPER (driver 621.40):
The |
What
Implements the previously stubbed texture-to-buffer path in
CopyTextureRegion(texture to buffer copies not implemented):crates/victory-gpu/src/host.rs): addsHost::readback_buffer(mappedD3D12_HEAP_TYPE_READBACK),HostList::readback, andHostList::defer_readback. After the GPU submission fence completes (and before bottom-of-pipe completion writes), completed readbacks are written into title memory viawatch::writing+write_mapped.crates/victory-gpu/src/resource.rs,crates/victory-gpu/src/list.rs): adds checkedPlacedFootprint::layout(), translates console formats withpc_format, aligns the stagingRowPitchto 256 bytes (D3D12_TEXTURE_DATA_PITCH_ALIGNMENT), and copies row-by-row when a title footprint uses an unaligned row pitch. Uploads CPU-written source textures (texture::upload) and transitions them toCOPY_SOURCEbefore recordingCopyTextureRegion.crates/victory-gpu/src/resource.rs): uploads a 4×4R8G8B8A8_UNORMpattern to a host texture and verifies three texture-to-buffer readbacks throughExecuteCommandLists: 256-aligned at a non-zero offset (256), unaligned packedrow_pitch = 16at offset 32, and a 2×2source_boxcrop(1, 1)..(3, 3).Tested
Windows 11 x64 (26300), Rust
1.98.1(--locked), NVIDIA GeForce RTX 2070 SUPER (driver617.42):cargo test -p victory-gpu --locked --offline: 37 passed, 0 failed (includingcopy_texture_region_reads_back_into_title_bufferon hardware GPU).cargo test --workspace --locked --offline(skipping sandboxed socket testonly_loopback_is_reachable): all passed.cargo clippy -p victory-gpu --all-targets --locked --offline -- -D warnings(both default and--features diagnostics): 0 warnings.cargo --offline xtask policy:asset policy: 148 files ok.AI-assisted; no game assets were used.