GPU: implement CopyTextureRegion texture-to-buffer readbacks #67

Closed
github-bot wants to merge 10 commits from gh-pr/67/head into gh-pr/67/base
Owner

@⁠alessiodeia on GitHub · 2026-11-24 00:07 UTC · original
alessiodeia:feat/texture-to-buffer-copy → main · +790 −18 · 3 files · 10 commits · closed without merging

What

Implements the previously stubbed texture-to-buffer path in CopyTextureRegion (texture to buffer copies not implemented):

  • Readback staging (crates/victory-gpu/src/host.rs): adds Host::readback_buffer (mapped D3D12_HEAP_TYPE_READBACK), HostList::readback, and HostList::defer_readback. After the GPU submission fence completes (and before bottom-of-pipe completion writes), completed readbacks are written into title memory via watch::writing + write_mapped.
  • Footprint layout & row-pitch alignment (crates/victory-gpu/src/resource.rs, crates/victory-gpu/src/list.rs): adds checked PlacedFootprint::layout(), translates console formats with pc_format, aligns the staging RowPitch to 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 to COPY_SOURCE before recording CopyTextureRegion.
  • End-to-end GPU test (crates/victory-gpu/src/resource.rs): uploads a 4×4 R8G8B8A8_UNORM pattern to a host texture and verifies three texture-to-buffer readbacks through ExecuteCommandLists: 256-aligned at a non-zero offset (256), unaligned packed row_pitch = 16 at offset 32, and a 2×2 source_box crop (1, 1)..(3, 3).

Tested

Windows 11 x64 (26300), Rust 1.98.1 (--locked), NVIDIA GeForce RTX 2070 SUPER (driver 617.42):

  • cargo test -p victory-gpu --locked --offline: 37 passed, 0 failed (including copy_texture_region_reads_back_into_title_buffer on hardware GPU).
  • cargo test --workspace --locked --offline (skipping sandboxed socket test only_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.

**@⁠alessiodeia** on GitHub · 2026-11-24 00:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/67) `alessiodeia:feat/texture-to-buffer-copy` → `main` · +790 −18 · 3 files · 10 commits · closed without merging ## What Implements the previously stubbed texture-to-buffer path in `CopyTextureRegion` (`texture to buffer copies not implemented`): - **Readback staging (`crates/victory-gpu/src/host.rs`):** adds `Host::readback_buffer` (mapped `D3D12_HEAP_TYPE_READBACK`), `HostList::readback`, and `HostList::defer_readback`. After the GPU submission fence completes (and before bottom-of-pipe completion writes), completed readbacks are written into title memory via `watch::writing` + `write_mapped`. - **Footprint layout & row-pitch alignment (`crates/victory-gpu/src/resource.rs`, `crates/victory-gpu/src/list.rs`):** adds checked `PlacedFootprint::layout()`, translates console formats with `pc_format`, aligns the staging `RowPitch` to 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 to `COPY_SOURCE` before recording `CopyTextureRegion`. - **End-to-end GPU test (`crates/victory-gpu/src/resource.rs`):** uploads a 4×4 `R8G8B8A8_UNORM` pattern to a host texture and verifies three texture-to-buffer readbacks through `ExecuteCommandLists`: 256-aligned at a non-zero offset (256), unaligned packed `row_pitch = 16` at offset 32, and a 2×2 `source_box` crop `(1, 1)..(3, 3)`. ## Tested Windows 11 x64 (26300), Rust `1.98.1` (`--locked`), NVIDIA GeForce RTX 2070 SUPER (driver `617.42`): - `cargo test -p victory-gpu --locked --offline`: 37 passed, 0 failed (including `copy_texture_region_reads_back_into_title_buffer` on hardware GPU). - `cargo test --workspace --locked --offline` (skipping sandboxed socket test `only_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.
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 <[email protected]>
Addresses review feedback on #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 <[email protected]>
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/VIctory#67
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: #67
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 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	crates/victory-gpu/src/host.rs
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 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:03 +00:00
github-bot closed this pull request 2026-11-26 03:49:03 +00:00
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 00:11 UTC · original

Reviewing

**@⁠raffclar** on GitHub · 2026-11-24 00:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7117796076) Reviewing
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-24 00:23 UTC · original

@⁠raffclar Good catch — verified in resource.rs (element(118..=120) == (3, 1) while pc_format(118..=120) == 45..=47 has element == (4, 1)), so raw readback into a 3-byte footprint would both under-size the staging buffer and copy the wrong texel layout.

Fixed in b5c38fa:

  • Guarded copy_texture_region readbacks with element(host_format) != element(dst.footprint.format), skipping mismatched substitute formats cleanly with a one-time tracing::warn! instead of mis-sizing staging memory or failing Close().
  • Added a regression case for format 118 in copy_texture_region_reads_back_into_title_buffer verifying the command list closes/executes cleanly and leaves the destination buffer untouched.

Re-tested with cargo test -p victory-gpu --locked --offline (37 passed on RTX 2070 SUPER), cargo clippy -p victory-gpu --all-targets -- -D warnings (default + --features diagnostics, 0 warnings), and cargo xtask policy (148 files ok).

**@⁠alessiodeia** on GitHub · 2026-11-24 00:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7118015354) @⁠raffclar Good catch — verified in `resource.rs` (`element(118..=120) == (3, 1)` while `pc_format(118..=120) == 45..=47` has `element == (4, 1)`), so raw readback into a 3-byte footprint would both under-size the staging buffer and copy the wrong texel layout. Fixed in `b5c38fa`: - Guarded `copy_texture_region` readbacks with `element(host_format) != element(dst.footprint.format)`, skipping mismatched substitute formats cleanly with a one-time `tracing::warn!` instead of mis-sizing staging memory or failing `Close()`. - Added a regression case for format `118` in `copy_texture_region_reads_back_into_title_buffer` verifying the command list closes/executes cleanly and leaves the destination buffer untouched. Re-tested with `cargo test -p victory-gpu --locked --offline` (37 passed on RTX 2070 SUPER), `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default + `--features diagnostics`, 0 warnings), and `cargo xtask policy` (`148 files ok`).
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 00:24 UTC · original

Approved

**@⁠raffclar** on GitHub · 2026-11-24 00:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7118036198) Approved
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 00:38 UTC · original · edited 2026-11-24 00:51 UTC

I checked b5c38fa on a physical RTX 5070, driver 621.01, with a synthetic 4×4 RGBA8 texture. The aligned, packed, cropped and format-skip assertions all passed.

One additional valid partial copy loses neighboring pixels. I prefilled a 4×4 destination with 0xA5, then copied a 2×2 source box into its top-left corner. All 4 requested pixels matched the source. All 12 pixels outside the box lost their prefilled values. The device remained healthy. The comparison counts only actual texels, excluding row padding.

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 219e3ce, 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. All 37 GPU library tests and diagnostics Clippy passed. These tests used synthetic textures.

**@⁠jeremygold02** on GitHub · 2026-11-24 00:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7118286557) · edited 2026-11-24 00:51 UTC I checked `b5c38fa` on a physical RTX 5070, driver 621.01, with a synthetic 4×4 RGBA8 texture. The aligned, packed, cropped and format-skip assertions all passed. One additional valid partial copy loses neighboring pixels. I prefilled a 4×4 destination with `0xA5`, then copied a 2×2 source box into its top-left corner. All 4 requested pixels matched the source. All 12 pixels outside the box lost their prefilled values. The device remained healthy. The comparison counts only actual texels, excluding row padding. 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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/137), which depends on this PR. At `219e3ce`, 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. All 37 GPU library tests and diagnostics Clippy passed. These tests used synthetic textures.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:55 UTC · original

Tested b5c38fa under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with cargo xwin ... --target x86_64-pc-windows-msvc: the PR's own test fails here, but only because of #128.

  • victory_gpu: 34 passed, 3 failed:
    • resource::tests::copy_texture_region_reads_back_into_title_buffer — the new test, all readback rows zero;
    • the two environment-only ones (argument_clamp_builds, buffer_data_reaches_the_host_texture).
  • Cause is the same #128: the test first uploads the source rows into the texture through the deferred staging copy, which copy_mapped's VirtualQuery guard skips under vkd3d-proton, so the texture is zero before any readback happens. With the per-step guard bypassed locally (title_dst = false), this test passes.
  • So the aligned rows, packed 16-byte rows, 2×2 sub-box crop and the 3-byte-format skip all behave correctly on vkd3d-proton; nothing here points at the readback code. Re-running after #128 is fixed would confirm that without the local patch.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7118576881) Tested `b5c38fa` under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with `cargo xwin ... --target x86_64-pc-windows-msvc`: **the PR's own test fails here, but only because of #128**. - `victory_gpu`: 34 passed, 3 failed: - `resource::tests::copy_texture_region_reads_back_into_title_buffer` — the new test, all readback rows zero; - the two environment-only ones (`argument_clamp_builds`, `buffer_data_reaches_the_host_texture`). - **Cause is the same #128**: the test first uploads the source rows into the texture through the deferred staging copy, which `copy_mapped`'s `VirtualQuery` guard skips under vkd3d-proton, so the texture is zero before any readback happens. With the per-step guard bypassed locally (`title_dst = false`), this test **passes**. - So the aligned rows, packed 16-byte rows, 2×2 sub-box crop and the 3-byte-format skip all behave correctly on vkd3d-proton; nothing here points at the readback code. Re-running after #128 is fixed would confirm that without the local patch. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-24 01:02 UTC · original

@⁠jeremygold02 @⁠martingouv @⁠DaviTostes Thanks all for the thorough testing!

  • Leaving this PR at b5c38fa so it can merge cleanly first without conflicting with @⁠jeremygold02's follow-up #137 (219e3ce), which cleanly addresses the partial-region / non-zero (x, y, z) sentinel case both @⁠jeremygold02 and @⁠martingouv flagged.
  • Independently verified #137 (219e3ce) on Windows 11 + RTX 2070 SUPER (driver 617.42): cargo test -p victory-gpu 37 passed, 0 failed, cargo clippy -p victory-gpu --all-targets -- -D warnings clean, cargo xtask policy ok.
  • Thanks @⁠DaviTostes for confirming the readback path also passes under Wine + vkd3d-proton on AMD RX 9060 XT once #128 is bypassed.
**@⁠alessiodeia** on GitHub · 2026-11-24 01:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7118697964) @⁠jeremygold02 @⁠martingouv @⁠DaviTostes Thanks all for the thorough testing! - Leaving this PR at `b5c38fa` so it can merge cleanly first without conflicting with @⁠jeremygold02's follow-up #137 (`219e3ce`), which cleanly addresses the partial-region / non-zero `(x, y, z)` sentinel case both @⁠jeremygold02 and @⁠martingouv flagged. - Independently verified #137 (`219e3ce`) on Windows 11 + RTX 2070 SUPER (driver `617.42`): `cargo test -p victory-gpu` **37 passed, 0 failed**, `cargo clippy -p victory-gpu --all-targets -- -D warnings` clean, `cargo xtask policy` ok. - Thanks @⁠DaviTostes for confirming the readback path also passes under Wine + vkd3d-proton on AMD RX 9060 XT once #128 is bypassed.
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 10:43 UTC · original

We ran the Wine retest suggested above on main ffe310e, keeping main’s deferred staging upload intact. On an RTX 4090 with Wine/vkd3d-proton, #67 read all 16 aligned pixels, all 16 packed pixels and all four pixels in the 2×2 crop correctly. This run needed no local guard bypass.

We also ran #137’s partial-copy control on the same setup. With #67 alone, untouched destination pixel (2,0) changed from [0xa5; 4] to zero. Adding #137 preserved the neighbors and passed all 52 destination-pixel checks across the two layouts. That confirms the fix for partial copies on this Wine/NVIDIA setup. The original Wine report used AMD.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 10:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7129150207) We ran the Wine retest suggested above on main `ffe310e`, keeping main’s deferred staging upload intact. On an RTX 4090 with Wine/vkd3d-proton, #67 read all 16 aligned pixels, all 16 packed pixels and all four pixels in the 2×2 crop correctly. This run needed no local guard bypass. We also ran #137’s partial-copy control on the same setup. With #67 alone, untouched destination pixel (2,0) changed from `[0xa5; 4]` to zero. Adding #137 preserved the neighbors and passed all 52 destination-pixel checks across the two layouts. That confirms the fix for partial copies on this Wine/NVIDIA setup. The original Wine report used AMD.
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 00:14 UTC · original · edited 2026-11-24 00:15 UTC
On crates/victory-gpu/src/list.rs line 555 (outdated):

@@ -503,9 +503,98 @@ extern "system" fn copy_texture_region(
         else {
             return;
         };
+        const _: () =
+            assert!(size_of::<CopyLocation>() == size_of::<D3D12_TEXTURE_COPY_LOCATION>());
+        let host_box = (!source_box.is_null()).then(|| source_box.cast::<D3D12_BOX>());
+        if dst.kind == FOOTPRINT {
+            if src.kind == FOOTPRINT {
+                return;
+            }
+            let (Some(host), Some(from_tex)) = (
+                crate::host::host(),
+                crate::resource::host_resource(src.resource),
+            ) else {
+                return;
+            };
+            let Some((lines, row_bytes, total)) = dst.footprint.layout() else {
+                return;
+            };
+            if total == 0 || lines == 0 || row_bytes == 0 {
+                return;
+            }
+            let dst_pitch = u64::from(dst.footprint.row_pitch);
+            if lines > 1 && dst_pitch < row_bytes {
+                return;
+            }
+            let Some(target) = buffer_range(dst.resource, dst.footprint.offset, total) else {
+                return;
+            };
+            let Ok(row_bytes_u32) = u32::try_from(row_bytes) else {
+                return;
+            };
+            // D3D12 requires placed footprints' row pitch to be 256-byte aligned.
+            let host_pitch = dst
+                .footprint
+                .row_pitch
+                .max(row_bytes_u32)
+                .next_multiple_of(256);
+            let Some(staging_bytes) = u64::from(host_pitch)
+                .checked_mul(lines - 1)
+                .and_then(|n| n.checked_add(row_bytes))
+            else {
+                return;
+            };
+            let Some((buffer, staging)) = list.readback(host, staging_bytes) else {
+                return;
+            };
+            crate::texture::upload(list, src.resource, from_tex);
+            ensure_state(list, src.resource, COPY_SOURCE);
+            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);

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.

**@⁠raffclar** on GitHub · 2026-11-24 00:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#discussion_r4673789453) · edited 2026-11-24 00:15 UTC On `crates/victory-gpu/src/list.rs` line 555 (outdated): ```diff @@ -503,9 +503,98 @@ extern "system" fn copy_texture_region( else { return; }; + const _: () = + assert!(size_of::<CopyLocation>() == size_of::<D3D12_TEXTURE_COPY_LOCATION>()); + let host_box = (!source_box.is_null()).then(|| source_box.cast::<D3D12_BOX>()); + if dst.kind == FOOTPRINT { + if src.kind == FOOTPRINT { + return; + } + let (Some(host), Some(from_tex)) = ( + crate::host::host(), + crate::resource::host_resource(src.resource), + ) else { + return; + }; + let Some((lines, row_bytes, total)) = dst.footprint.layout() else { + return; + }; + if total == 0 || lines == 0 || row_bytes == 0 { + return; + } + let dst_pitch = u64::from(dst.footprint.row_pitch); + if lines > 1 && dst_pitch < row_bytes { + return; + } + let Some(target) = buffer_range(dst.resource, dst.footprint.offset, total) else { + return; + }; + let Ok(row_bytes_u32) = u32::try_from(row_bytes) else { + return; + }; + // D3D12 requires placed footprints' row pitch to be 256-byte aligned. + let host_pitch = dst + .footprint + .row_pitch + .max(row_bytes_u32) + .next_multiple_of(256); + let Some(staging_bytes) = u64::from(host_pitch) + .checked_mul(lines - 1) + .and_then(|n| n.checked_add(row_bytes)) + else { + return; + }; + let Some((buffer, staging)) = list.readback(host, staging_bytes) else { + return; + }; + crate::texture::upload(list, src.resource, from_tex); + ensure_state(list, src.resource, COPY_SOURCE); + 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); ``` 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.
Author
Owner

@⁠CaravelaLabs on GitHub · 2026-11-24 21:04 UTC · original · edited 2026-11-24 22:36 UTC

@⁠alessiodeia this was fine on its own at b5c38fa, and #32 at 9c5328d. Those two did not compile together. This PR is now 9ea5068 on main 70564ae; I have not re-compiled that pair. On 9ea5068, host_list still returns a reference, and the two readback calls still pass list (now lines 570-571), so the clippy note below still applies.

Checked on main ffe310e, b5c38fa and 9c5328d. Each passed a Windows workspace check on its own. Merged, the texture-to-buffer readback did:

crate::texture::upload(list, src.resource, from_tex);
ensure_state(list, src.resource, COPY_SOURCE);

Those calls, as checked: github.com/Marvisak/VIctory@b5c38fa9c2/crates/victory-gpu/src/list.rs (L567-L568)

list there is what host_list returned. On #32 that is an Arc<HostList>. upload and ensure_state take &HostList, so the check stops with E0308: expected &HostList, found Arc<HostList>. @⁠AndyLatimer already passes &list at the other copy sites for that reason.

Borrowing both arguments is enough for the type check on that merged tree. It cannot land on this PR while host_list still returns a reference: &list is a needless borrow, and cargo clippy -D warnings rejects it. Whichever of these two lands second has to add the &. Thanks @⁠alessiodeia for catching that.

Compile only (cargo xwin check --workspace --all-targets --all-features --locked, Windows target), on ffe310e / b5c38fa / 9c5328d. No tests run.

AI-assisted; Windows workspace check of that two-PR merge, run on this machine.

**@⁠CaravelaLabs** on GitHub · 2026-11-24 21:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7144446393) · edited 2026-11-24 22:36 UTC @⁠alessiodeia this was fine on its own at `b5c38fa`, and #32 at `9c5328d`. Those two did not compile together. This PR is now `9ea5068` on main `70564ae`; I have not re-compiled that pair. On `9ea5068`, `host_list` still returns a reference, and the two readback calls still pass `list` (now lines 570-571), so the clippy note below still applies. Checked on main `ffe310e`, `b5c38fa` and `9c5328d`. Each passed a Windows workspace check on its own. Merged, the texture-to-buffer readback did: ``` crate::texture::upload(list, src.resource, from_tex); ensure_state(list, src.resource, COPY_SOURCE); ``` Those calls, as checked: https://github.com/Marvisak/VIctory/blob/b5c38fa9c25cfdbfbc656d2f1e8371a450743315/crates/victory-gpu/src/list.rs#L567-L568 `list` there is what `host_list` returned. On #32 that is an `Arc<HostList>`. `upload` and `ensure_state` take `&HostList`, so the check stops with E0308: expected `&HostList`, found `Arc<HostList>`. @⁠AndyLatimer already passes `&list` at the other copy sites for that reason. Borrowing both arguments is enough for the type check on that merged tree. It cannot land on this PR while `host_list` still returns a reference: `&list` is a needless borrow, and `cargo clippy -D warnings` rejects it. Whichever of these two lands second has to add the `&`. Thanks @⁠alessiodeia for catching that. Compile only (`cargo xwin check --workspace --all-targets --all-features --locked`, Windows target), on `ffe310e` / `b5c38fa` / `9c5328d`. No tests run. AI-assisted; Windows workspace check of that two-PR merge, run on this machine.
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-24 21:47 UTC · original

Updated for today's main (70564ae). The head is now 9ea5068: a merge of main plus one small commit. b5c38fa is still an ancestor, so #137 still stacks on it.

What main broke: watch::writing() now returns a #[must_use] Writing guard that has to live while the write happens. The two readback writes in host.rs called it as a statement, so the merge no longer compiled under -D warnings. 9ea5068 holds the guard across each write with let _writing = crate::watch::writing(..), the same pattern shadow.rs and copy_mapped use on main.

Verified on Windows 11 with an RTX 2070 SUPER (driver 621.40):

  • workspace clippy -D warnings, with and without --all-features: clean
  • cargo xtask policy: ok
  • cargo test -p victory-gpu: copy_texture_region_reads_back_into_title_buffer passes. Two other tests fail here, descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views. They fail the same way on clean 70564ae on this card (NumDescriptors >= HEAP_VIEWS / past the dynamic slots, the view heap is capped on NVIDIA), so they're unrelated to this PR.

@⁠CaravelaLabs, thanks for re-checking against #32. I tried the borrow here, but on current main host_list still returns &HostList. upload(&list, ..) / ensure_state(&list, ..) then fail cargo clippy -D warnings with needless_borrow, so this PR can't carry it without failing CI. Whichever lands second has to adapt. If #32 merges first I'll add the & here right away. If this lands first, #32 needs the same &list at these two call sites that it already uses at the other copy sites.

**@⁠alessiodeia** on GitHub · 2026-11-24 21:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7145396328) Updated for today's `main` (`70564ae`). The head is now `9ea5068`: a merge of `main` plus one small commit. `b5c38fa` is still an ancestor, so #137 still stacks on it. **What `main` broke:** `watch::writing()` now returns a `#[must_use]` `Writing` guard that has to live while the write happens. The two readback writes in `host.rs` called it as a statement, so the merge no longer compiled under `-D warnings`. `9ea5068` holds the guard across each write with `let _writing = crate::watch::writing(..)`, the same pattern `shadow.rs` and `copy_mapped` use on `main`. Verified on Windows 11 with an RTX 2070 SUPER (driver 621.40): - workspace clippy `-D warnings`, with and without `--all-features`: clean - `cargo xtask policy`: ok - `cargo test -p victory-gpu`: `copy_texture_region_reads_back_into_title_buffer` passes. Two other tests fail here, `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`. They fail the same way on clean `70564ae` on this card (`NumDescriptors >= HEAP_VIEWS` / `past the dynamic slots`, the view heap is capped on NVIDIA), so they're unrelated to this PR. @⁠CaravelaLabs, thanks for re-checking against #32. I tried the borrow here, but on current `main` `host_list` still returns `&HostList`. `upload(&list, ..)` / `ensure_state(&list, ..)` then fail `cargo clippy -D warnings` with `needless_borrow`, so this PR can't carry it without failing CI. Whichever lands second has to adapt. If #32 merges first I'll add the `&` here right away. If this lands first, #32 needs the same `&list` at these two call sites that it already uses at the other copy sites.
Author
Owner

@⁠CaravelaLabs on GitHub · 2026-11-24 22:04 UTC · original

@⁠alessiodeia thanks, you're right.

I only type-checked the borrow. While host_list still returns a reference, &list fails cargo clippy -D warnings as a needless borrow, so this PR can't carry it without failing CI. I've corrected the note. Whichever of these two lands second adds the & at those two calls.

AI-assisted.

**@⁠CaravelaLabs** on GitHub · 2026-11-24 22:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7145760646) @⁠alessiodeia thanks, you're right. I only type-checked the borrow. While `host_list` still returns a reference, `&list` fails `cargo clippy -D warnings` as a needless borrow, so this PR can't carry it without failing CI. I've corrected the note. Whichever of these two lands second adds the `&` at those two calls. AI-assisted.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:23 UTC · original · edited 2026-11-25 15:54 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 (merge-candidate) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7148467242) · edited 2026-11-25 15:54 UTC <!-- victory-triage v1 head=1e59257104251e4c90b58e140a6a990921f3ae76 verdict=needs-rebase at=2026-11-25T15:54:40Z --> 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 (merge-candidate) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-25 00:41 UTC · original

Thanks for the review. Addressed in 1e59257:

  • #137 folded in. @⁠jeremygold02's two commits (219e3ce, 31979ad) are merged into this branch with their authorship kept. The deferred readback now writes only the rows y..y+height and the bytes x*element..(x+width)*element the copy covers, so title bytes outside the box are untouched, as D3D12 leaves them.
  • Sentinel test for a partial box. copy_texture_region_reads_back_into_title_buffer now has three partial cases, each prefilled with 0xa5. A 2×2 box at the origin and a 4×4 copy at (1, 1) of a 6×6 footprint come from #137. I added the case you asked for: the same 2×2 box at x = 1 in a 4×4 footprint. Every byte outside each box must keep the sentinel.
  • Negative control: with this test on the pre-#137 code (9ea5068), it fails at pixel (2, 0) in the 4×4 footprint (the sentinel is overwritten). With the fix it passes.
  • The watch::writing guard is held across both write paths (whole-block and per-row), as before.
  • Merged with current main (4118f33) with no conflicts. The only conflict was between #137 and main's Writing guard in host.rs: #137's per-box logic is kept, with let _writing = … around the write.

Verified on Windows 11 with an RTX 2070 SUPER (driver 621.40):

  • workspace clippy -D warnings, default and --all-features: clean
  • cargo xtask policy: ok
  • copy_texture_region_reads_back_into_title_buffer: passes on hardware
  • cargo test -p victory-gpu: 140 passed, 2 failed. Both failures (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views) also fail on clean main on this card (NVIDIA's capped view heap), so they're unrelated to this PR.
  • rustfmt --check on resource.rs shows the same 15 differences as main and none in this PR's code.

The &list change for #32 still waits for whichever of the two lands second.

**@⁠alessiodeia** on GitHub · 2026-11-25 00:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7148771998) Thanks for the review. Addressed in `1e59257`: - **#137 folded in.** @⁠jeremygold02's two commits (`219e3ce`, `31979ad`) are merged into this branch with their authorship kept. The deferred readback now writes only the rows `y..y+height` and the bytes `x*element..(x+width)*element` the copy covers, so title bytes outside the box are untouched, as D3D12 leaves them. - **Sentinel test for a partial box.** `copy_texture_region_reads_back_into_title_buffer` now has three partial cases, each prefilled with `0xa5`. A 2×2 box at the origin and a 4×4 copy at (1, 1) of a 6×6 footprint come from #137. I added the case you asked for: **the same 2×2 box at `x = 1` in a 4×4 footprint**. Every byte outside each box must keep the sentinel. - **Negative control:** with this test on the pre-#137 code (`9ea5068`), it fails at `pixel (2, 0)` in the 4×4 footprint (the sentinel is overwritten). With the fix it passes. - **The `watch::writing` guard** is held across both write paths (whole-block and per-row), as before. - **Merged with current `main` (`4118f33`)** with no conflicts. The only conflict was between #137 and main's `Writing` guard in `host.rs`: #137's per-box logic is kept, with `let _writing = …` around the write. Verified on Windows 11 with an RTX 2070 SUPER (driver 621.40): - workspace clippy `-D warnings`, default and `--all-features`: clean - `cargo xtask policy`: ok - `copy_texture_region_reads_back_into_title_buffer`: passes on hardware - `cargo test -p victory-gpu`: 140 passed, 2 failed. Both failures (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`) also fail on clean `main` on this card (NVIDIA's capped view heap), so they're unrelated to this PR. - `rustfmt --check` on `resource.rs` shows the same 15 differences as `main` and none in this PR's code. The `&list` change for #32 still waits for whichever of the two lands second.
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-25 21:34 UTC · original

Closing as superseded by main. 5cb63d8 ("GPU: texture to buffer copies read back into the title's buffer") implements texture-to-buffer CopyTextureRegion the same way: readback memory laid out as the title's footprint, copied into the title's buffer after the list runs, inside watch::writing. It also covers the blocking point from the triage. PlacedFootprint::rows(at, size) writes only each row's x * element .. (x + w) * element bytes of the region, so bytes outside a partial box are left alone, as in @⁠jeremygold02's fix. Merging this branch now would duplicate that code in another form.

If the sentinel cases from this PR are wanted as extra coverage (a 2×2 box at the origin, the same box at x = 1 in a 4×4 footprint, and a whole copy at (1, 1) of a 6×6, each prefilled with 0xa5), I can port them as a test-only PR on top of read_back. Ask here and I will.

Thanks @⁠raffclar for the review, and @⁠jeremygold02, @⁠martingouv, @⁠DaviTostes, @⁠MichaelSmithAI and @⁠CaravelaLabs for testing.

**@⁠alessiodeia** on GitHub · 2026-11-25 21:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/67#issuecomment-7175250080) Closing as superseded by `main`. `5cb63d8` ("GPU: texture to buffer copies read back into the title's buffer") implements texture-to-buffer `CopyTextureRegion` the same way: readback memory laid out as the title's footprint, copied into the title's buffer after the list runs, inside `watch::writing`. It also covers the blocking point from the triage. `PlacedFootprint::rows(at, size)` writes only each row's `x * element .. (x + w) * element` bytes of the region, so bytes outside a partial box are left alone, as in @⁠jeremygold02's fix. Merging this branch now would duplicate that code in another form. If the sentinel cases from this PR are wanted as extra coverage (a 2×2 box at the origin, the same box at `x = 1` in a 4×4 footprint, and a whole copy at (1, 1) of a 6×6, each prefilled with `0xa5`), I can port them as a test-only PR on top of `read_back`. Ask here and I will. Thanks @⁠raffclar for the review, and @⁠jeremygold02, @⁠martingouv, @⁠DaviTostes, @⁠MichaelSmithAI and @⁠CaravelaLabs for testing.

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