Repository navigation
fix(gpu): preserve source and destination pixels in texture readbacks - #137
jeremygold02 wants to merge 4 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>
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>
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
|
AMD run: head One run of the suite died with AI use
|
|
Tested
Only aggregate counts and error classes shared; no game data or raw game logs. AI-assisted (Kimi Code). |
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
|
@jeremygold02, the maintainer's triage on #67 asked to fold this fix into #67, so I've merged your two commits ( |
|
@alessiodeia Thanks for folding both fixes into #67 and adding the offset sentinel case. I verified that both of my commits, |
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-gpulibrary tests passed on Windows at the follow-up head. Diagnostics Clippy with warnings denied andgit diff --checkpassed. 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 withd2a4bae, 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 passedcargo checkon 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 returned00 00 00 00at pixel (0,0) on219e3ce. The readback path uploaded stale title memory over the GPU clear. Applying the existingtexture::title_writtencheck 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, andgit diff --checkpassed 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.