List: title copies name a held host copy's levels, and are fitted to the host's textures #3062

Open
Adriwin06 wants to merge 2 commits from upstream-pr/3062 into main
Adriwin06 commented 2026-11-29 19:52:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Adriwin06 on 2026-11-29T19:52:39Z.


What it changes

A host copy made of only the levels a placed texture's views show
(resource::held_only, on by default on cards over 8 GB) begins at the
title's level base, but copy_texture_region, its read backs and
copy_resource handed the title's subresource index to the host as it
was, so a copy from the title's level 0 read the host copy's first
level, which is a smaller one, with the title's box.

held_sub maps the title's index to the host copy's. A copy naming a
level the host copy lacks first asks for one with every level
(want_level, as the placed twins' copies do), and is left out with a
warning only if the host copy is kept (one the host wrote). Whole copies
ask the same of both sides and are left out if they still begin at
other levels. The placed twins and bakes still read the title's indices.

Every region copy (and read back, and copy into a placed twin) is also
fitted to the host's subresources before it is recorded (fit_copy: the
source box cut to the source, the copy to the destination's room from
its corner, blocks counted for block-compressed formats). A copy that is
cut or left out is logged with both textures as the title and the host
have them, instead of recording a CopyTextureRegion the debug layer
calls invalid (which leaves the list unclosable with E_INVALIDARG).
Whole copies between host textures of two shapes are left out the
same way.

Tests: resource::a_copy_names_the_levels_a_held_copy_has, list::fit_tests.

How it was tested

  • GPU and profile: RTX 4070 SUPER, Ryzen 7 5800X. Not measured in the title on these commits by themselves: they come from a fork of mine that carries them with the rest of this set, and the title ran there. What is below is the unit tests on this branch.
  • Before: n/a (no in-title measurement on this branch)
  • After: n/a
  • cargo test passed for the crates it touches:
    • this change: yes, cargo test -p victory-gpu --lib -- list:: resource::: 67 passed
  • cargo clippy --workspace --all-targets --locked: no finding that main does not already have (main has 34 of its own, which is why the Clippy step of CI is red on main itself).
  • cargo xtask policy: no new finding (main fails it on crates/victory-loader/src/heap_sites/frame_users.rs).
  • With all eleven of my pull requests merged together: cargo clippy also with --all-features adds no finding, and cargo test --workspace --locked fails only tests main also fails on this machine: the five shader tests that fail on main here too (WARP's SM 6.2 and the validator) (barycentric_tests::first_half_values_render_on_hardware_and_warp, hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, intersect_tests::flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves, rect::tests::rectangles_are_drawn_whole, rect::tests::the_rectangle_stage_is_a_geometry_shader) and xtask's repository_passes_policy (frame_users.rs). 2208 passed, including five that fail on main (three BCPack oracle tests, the menu save race, the shader key test).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related:
    None found for held copies or copy fitting (searched "held", "CopyTextureRegion", "fit_copy").

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5554483612 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062). Originally posted by [Adriwin06](https://github.com/Adriwin06) on 2026-11-29T19:52:39Z. --- ## What it changes A host copy made of only the levels a placed texture's views show (resource::held_only, on by default on cards over 8 GB) begins at the title's level `base`, but copy_texture_region, its read backs and copy_resource handed the title's subresource index to the host as it was, so a copy from the title's level 0 read the host copy's first level, which is a smaller one, with the title's box. held_sub maps the title's index to the host copy's. A copy naming a level the host copy lacks first asks for one with every level (want_level, as the placed twins' copies do), and is left out with a warning only if the host copy is kept (one the host wrote). Whole copies ask the same of both sides and are left out if they still begin at other levels. The placed twins and bakes still read the title's indices. Every region copy (and read back, and copy into a placed twin) is also fitted to the host's subresources before it is recorded (fit_copy: the source box cut to the source, the copy to the destination's room from its corner, blocks counted for block-compressed formats). A copy that is cut or left out is logged with both textures as the title and the host have them, instead of recording a CopyTextureRegion the debug layer calls invalid (which leaves the list unclosable with E_INVALIDARG). Whole copies between host textures of two shapes are left out the same way. Tests: resource::a_copy_names_the_levels_a_held_copy_has, list::fit_tests. ## How it was tested - GPU and profile: RTX 4070 SUPER, Ryzen 7 5800X. Not measured in the title on these commits by themselves: they come from a fork of mine that carries them with the rest of this set, and the title ran there. What is below is the unit tests on this branch. - Before: n/a (no in-title measurement on this branch) - After: n/a - `cargo test` passed for the crates it touches: - this change: yes, `cargo test -p victory-gpu --lib -- list:: resource::`: 67 passed - `cargo clippy --workspace --all-targets --locked`: no finding that main does not already have (main has 34 of its own, which is why the Clippy step of CI is red on main itself). - `cargo xtask policy`: no new finding (main fails it on crates/victory-loader/src/heap_sites/frame_users.rs). - With all eleven of my pull requests merged together: `cargo clippy` also with `--all-features` adds no finding, and `cargo test --workspace --locked` fails only tests main also fails on this machine: the five shader tests that fail on main here too (WARP's SM 6.2 and the validator) (barycentric_tests::first_half_values_render_on_hardware_and_warp, hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, intersect_tests::flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves, rect::tests::rectangles_are_drawn_whole, rect::tests::the_rectangle_stage_is_a_geometry_shader) and xtask's repository_passes_policy (frame_users.rs). 2208 passed, including five that fail on main (three BCPack oracle tests, the menu save race, the shader key test). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: None found for held copies or copy fitting (searched "held", "CopyTextureRegion", "fit_copy"). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Copilot commented 2026-11-29 19:58:34 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Copilot on 2026-11-29T19:58:34Z.

Code review location: crates/victory-gpu/src/list.rs; line 1445

@@ -1408,6 +1421,29 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) {
                 });
                 return;
             }
+            // A whole copy only between host textures of one shape: the host
+            // refuses any other, and the list would not close ([`fit_copy`]
+            // is the same for region copies).
+            // SAFETY: live textures.
+            let (a, b) = unsafe { (to.GetDesc(), from.GetDesc()) };
+            if (a.Dimension, a.Width, a.Height, a.DepthOrArraySize, a.MipLevels)
+                != (b.Dimension, b.Width, b.Height, b.DepthOrArraySize, b.MipLevels)
+            {
+                static TOLD: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
+                let n = TOLD.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
+                if n <= 8 || n.is_power_of_two() {
+                    let title = |r: This| crate::resource::texture_memory(r).map(|(_, d)| format!("{d:?}"));
+                    tracing::warn!(
+                        times = n,
+                        host_dst = ?(a.Width, a.Height, a.DepthOrArraySize, a.MipLevels, a.Format.0),
+                        host_src = ?(b.Width, b.Height, b.DepthOrArraySize, b.MipLevels, b.Format.0),
+                        title_dst = ?title(dst),
+                        title_src = ?title(src),
+                        "a whole texture copy between host textures of two shapes: left out"
+                    );
+                }
+                return;

A rejected whole copy still calls host_written and host_write_listed before returning, so an unwritten destination can lose subsequent title-memory uploads and held-copy growth without receiving the copy. The same issue occurs for Fit::Nothing in crates/victory-gpu/src/list.rs:1883. Validate shape compatibility and nonempty regions before destination initialization, tile-write preparation, and write bookkeeping, so omitted copies leave content ownership unchanged.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4732930714 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4732930714). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T19:58:34Z. **Code review location:** `crates/victory-gpu/src/list.rs`; line 1445 ~~~~diff @@ -1408,6 +1421,29 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) { }); return; } + // A whole copy only between host textures of one shape: the host + // refuses any other, and the list would not close ([`fit_copy`] + // is the same for region copies). + // SAFETY: live textures. + let (a, b) = unsafe { (to.GetDesc(), from.GetDesc()) }; + if (a.Dimension, a.Width, a.Height, a.DepthOrArraySize, a.MipLevels) + != (b.Dimension, b.Width, b.Height, b.DepthOrArraySize, b.MipLevels) + { + static TOLD: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); + let n = TOLD.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1; + if n <= 8 || n.is_power_of_two() { + let title = |r: This| crate::resource::texture_memory(r).map(|(_, d)| format!("{d:?}")); + tracing::warn!( + times = n, + host_dst = ?(a.Width, a.Height, a.DepthOrArraySize, a.MipLevels, a.Format.0), + host_src = ?(b.Width, b.Height, b.DepthOrArraySize, b.MipLevels, b.Format.0), + title_dst = ?title(dst), + title_src = ?title(src), + "a whole texture copy between host textures of two shapes: left out" + ); + } + return; ~~~~ --- A rejected whole copy still calls `host_written` and `host_write_listed` before returning, so an unwritten destination can lose subsequent title-memory uploads and held-copy growth without receiving the copy. The same issue occurs for `Fit::Nothing` in `crates/victory-gpu/src/list.rs:1883`. Validate shape compatibility and nonempty regions before destination initialization, tile-write preparation, and write bookkeeping, so omitted copies leave content ownership unchanged.
Copilot commented 2026-11-29 19:58:35 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Copilot on 2026-11-29T19:58:35Z.

Code review location: crates/victory-gpu/src/list.rs; line 1688

@@ -1491,6 +1676,21 @@ extern "system" fn copy_texture_region(
         else {
             return;
         };
+        // The host copies' subresources ([`held_sub`]); `dst` and `src` keep
+        // the title's, which the placed twins and the bakes below read.
+        let host_at = |l: &CopyLocation| {
+            if l.kind == FOOTPRINT {
+                Some(l.footprint.offset)
+            } else {
+                held_sub(l.resource, l.footprint.offset as u32).map(u64::from)
+            }
+        };
+        let (Some(src_at), Some(dst_at)) = (host_at(&src), host_at(&dst)) else {

For a copy within one unwritten texture held from mip 2, source mip 2 maps to host mip 0 before destination mip 0 grows the texture to a full host copy. Both recorded indices then become 0 instead of copying mip 2 to mip 0, and the title-index self-copy check misses this. Finish growth on both sides before calculating either host index.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4732930738 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4732930738). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T19:58:35Z. **Code review location:** `crates/victory-gpu/src/list.rs`; line 1688 ~~~~diff @@ -1491,6 +1676,21 @@ extern "system" fn copy_texture_region( else { return; }; + // The host copies' subresources ([`held_sub`]); `dst` and `src` keep + // the title's, which the placed twins and the bakes below read. + let host_at = |l: &CopyLocation| { + if l.kind == FOOTPRINT { + Some(l.footprint.offset) + } else { + held_sub(l.resource, l.footprint.offset as u32).map(u64::from) + } + }; + let (Some(src_at), Some(dst_at)) = (host_at(&src), host_at(&dst)) else { ~~~~ --- For a copy within one unwritten texture held from mip 2, source mip 2 maps to host mip 0 before destination mip 0 grows the texture to a full host copy. Both recorded indices then become 0 instead of copying mip 2 to mip 0, and the title-index self-copy check misses this. Finish growth on both sides before calculating either host index.
Copilot commented 2026-11-29 19:58:35 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Copilot on 2026-11-29T19:58:35Z.

Code review location: crates/victory-gpu/src/list.rs; line 2052

@@ -1777,6 +2035,24 @@ fn read_back(
     to.resource = buffer.resource().as_raw().cast_const().cast();
     to.footprint = footprint;
     let host_box = (!source_box.is_null()).then(|| source_box.cast::<D3D12_BOX>());
+    // The region against the host texture and our buffer ([`fit_copy`]).
+    // SAFETY: the title's box, when there is one, is six words; a live texture.
+    let asked = (!source_box.is_null()).then(|| unsafe { source_box.read_unaligned() });
+    let src_extent = sub_extent(&unsafe { texture.GetDesc() }, src.footprint.offset as u32);
+    let dst_extent = footprint_extent(&footprint);
+    let fitted = match (src_extent, dst_extent) {
+        (Some(s), Some(d)) => fit_copy(s, d, [0, 0, 0], asked),
+        _ => Fit::AsAsked,
+    };
+    if fitted != Fit::AsAsked {
+        copy_did_not_fit("a read back", fitted, dst.resource, 0, src.resource, src.footprint.offset, [src_extent, dst_extent], asked, [0, 0, 0]);
+    }
+    let cut_box = match fitted {
+        Fit::AsAsked => None,
+        Fit::Cut(b) => Some(D3D12_BOX { left: b[0], top: b[1], front: b[2], right: b[3], bottom: b[4], back: b[5] }),

When a read-back is clipped, the GPU writes only the fitted region, but defer_read_back still passes the original footprint's row width and row count to host::read_backs. The CPU copy then overwrites title memory with unwritten bytes from the pooled buffer. Carry the fitted byte width and row/depth counts through deferred read-back handling while preserving the original host row/slice strides and title destination pitch.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4732930754 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4732930754). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T19:58:35Z. **Code review location:** `crates/victory-gpu/src/list.rs`; line 2052 ~~~~diff @@ -1777,6 +2035,24 @@ fn read_back( to.resource = buffer.resource().as_raw().cast_const().cast(); to.footprint = footprint; let host_box = (!source_box.is_null()).then(|| source_box.cast::<D3D12_BOX>()); + // The region against the host texture and our buffer ([`fit_copy`]). + // SAFETY: the title's box, when there is one, is six words; a live texture. + let asked = (!source_box.is_null()).then(|| unsafe { source_box.read_unaligned() }); + let src_extent = sub_extent(&unsafe { texture.GetDesc() }, src.footprint.offset as u32); + let dst_extent = footprint_extent(&footprint); + let fitted = match (src_extent, dst_extent) { + (Some(s), Some(d)) => fit_copy(s, d, [0, 0, 0], asked), + _ => Fit::AsAsked, + }; + if fitted != Fit::AsAsked { + copy_did_not_fit("a read back", fitted, dst.resource, 0, src.resource, src.footprint.offset, [src_extent, dst_extent], asked, [0, 0, 0]); + } + let cut_box = match fitted { + Fit::AsAsked => None, + Fit::Cut(b) => Some(D3D12_BOX { left: b[0], top: b[1], front: b[2], right: b[3], bottom: b[4], back: b[5] }), ~~~~ --- When a read-back is clipped, the GPU writes only the fitted region, but `defer_read_back` still passes the original footprint's row width and row count to `host::read_backs`. The CPU copy then overwrites title memory with unwritten bytes from the pooled buffer. Carry the fitted byte width and row/depth counts through deferred read-back handling while preserving the original host row/slice strides and title destination pitch.
Copilot commented 2026-11-29 19:58:35 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Copilot on 2026-11-29T19:58:35Z.

Code review location: crates/victory-gpu/src/list.rs; line 1430

@@ -1408,6 +1421,29 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) {
                 });
                 return;
             }
+            // A whole copy only between host textures of one shape: the host
+            // refuses any other, and the list would not close ([`fit_copy`]
+            // is the same for region copies).
+            // SAFETY: live textures.
+            let (a, b) = unsafe { (to.GetDesc(), from.GetDesc()) };
+            if (a.Dimension, a.Width, a.Height, a.DepthOrArraySize, a.MipLevels)
+                != (b.Dimension, b.Width, b.Height, b.DepthOrArraySize, b.MipLevels)

Comparing raw width and height rejects valid block-compressed reinterpret copies, such as a 256×256 R32G32B32A32_UINT texture copied to a 1024×1024 BC5_UNORM texture. D3D12 CopyResource supports this, with one uncompressed texel representing one compressed block. Validate dimensions using the supported reinterpret-format pairs and their block sizes rather than requiring raw dimensions to match.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4732930765 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4732930765). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T19:58:35Z. **Code review location:** `crates/victory-gpu/src/list.rs`; line 1430 ~~~~diff @@ -1408,6 +1421,29 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) { }); return; } + // A whole copy only between host textures of one shape: the host + // refuses any other, and the list would not close ([`fit_copy`] + // is the same for region copies). + // SAFETY: live textures. + let (a, b) = unsafe { (to.GetDesc(), from.GetDesc()) }; + if (a.Dimension, a.Width, a.Height, a.DepthOrArraySize, a.MipLevels) + != (b.Dimension, b.Width, b.Height, b.DepthOrArraySize, b.MipLevels) ~~~~ --- Comparing raw width and height rejects valid block-compressed reinterpret copies, such as a 256×256 `R32G32B32A32_UINT` texture copied to a 1024×1024 `BC5_UNORM` texture. [D3D12 CopyResource supports this](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist-copyresource#reinterpret-copy), with one uncompressed texel representing one compressed block. Validate dimensions using the supported reinterpret-format pairs and their block sizes rather than requiring raw dimensions to match.
copilot-pull-request-reviewer[bot] commented 2026-11-29 19:58:36 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-29T19:58:36Z.

Review: COMMENTED


Critical copy and read-back defects can select the wrong mip, overwrite title memory with unwritten bytes, and incorrectly change destination ownership when copies are omitted.

4 open issues
What changed in this PR

This PR updates the GPU command-list copy paths to account for host textures that retain only selected mip levels, aiming to prevent invalid D3D12 copies from leaving command lists unclosable.

Changes:

  • Maps title subresource indices to retained host levels and requests missing levels when possible.
  • Fits region copies, read-backs, and placed-twin copies to host extents, with warnings for clipped or omitted transfers.
  • Adds tests for held-level mapping and copy-region fitting.
File Description
crates/​victory-gpu/​src/​resource.rs Adds footprint extent access and a held-level mapping regression test.
crates/​victory-gpu/​src/​list.rs Adds subresource remapping, copy fitting, shape checks, diagnostics, and fitting tests.

Review effort: Balanced

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6104541095 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#pullrequestreview-6104541095). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T19:58:36Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟡 Changes recommended Critical copy and read-back defects can select the wrong mip, overwrite title memory with unwritten bytes, and incorrectly change destination ownership when copies are omitted. <details open> <summary><strong>4 open issues</strong></summary> - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Validate copies before initializing or marking the destination written](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4732930714) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Grow both textures before calculating held-copy mip indices](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4732930738) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Use the fitted region size for deferred read-back copies](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4732930754) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Allow valid block-compressed reinterpret copies](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4732930765) · New </details> <details> <summary><strong>What changed in this PR</strong></summary> This PR updates the GPU command-list copy paths to account for host textures that retain only selected mip levels, aiming to prevent invalid D3D12 copies from leaving command lists unclosable. **Changes:** - Maps title subresource indices to retained host levels and requests missing levels when possible. - Fits region copies, read-backs, and placed-twin copies to host extents, with warnings for clipped or omitted transfers. - Adds tests for held-level mapping and copy-region fitting. | File | Description | | ---- | ----------- | | `crates/​victory-gpu/​src/​resource.rs` | Adds footprint extent access and a held-level mapping regression test. | | `crates/​victory-gpu/​src/​list.rs` | Adds subresource remapping, copy fitting, shape checks, diagnostics, and fitting tests. | </details> <sub>Review effort: Balanced</sub>
dyshay commented 2026-11-29 20:46:56 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-29T20:46:56Z.


Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262353272 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#issuecomment-7262353272). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-29T20:46:56Z. --- Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.
Adriwin06 commented 2026-11-30 01:10:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Adriwin06 on 2026-11-30T01:10:23Z.

Code review location: crates/victory-gpu/src/list.rs; line 1445

@@ -1408,6 +1421,29 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) {
                 });
                 return;
             }
+            // A whole copy only between host textures of one shape: the host
+            // refuses any other, and the list would not close ([`fit_copy`]
+            // is the same for region copies).
+            // SAFETY: live textures.
+            let (a, b) = unsafe { (to.GetDesc(), from.GetDesc()) };
+            if (a.Dimension, a.Width, a.Height, a.DepthOrArraySize, a.MipLevels)
+                != (b.Dimension, b.Width, b.Height, b.DepthOrArraySize, b.MipLevels)
+            {
+                static TOLD: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
+                let n = TOLD.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
+                if n <= 8 || n.is_power_of_two() {
+                    let title = |r: This| crate::resource::texture_memory(r).map(|(_, d)| format!("{d:?}"));
+                    tracing::warn!(
+                        times = n,
+                        host_dst = ?(a.Width, a.Height, a.DepthOrArraySize, a.MipLevels, a.Format.0),
+                        host_src = ?(b.Width, b.Height, b.DepthOrArraySize, b.MipLevels, b.Format.0),
+                        title_dst = ?title(dst),
+                        title_src = ?title(src),
+                        "a whole texture copy between host textures of two shapes: left out"
+                    );
+                }
+                return;

Fixed in 1e02966d: the whole copy's shape check now runs before the source upload, the twins, card_writes, host_written and host_write_listed. For region copies, the fit (Fit::Nothing) is decided before the destination is uploaded into or marked, so a copy left out leaves ownership unchanged.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4734087759 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4734087759). Originally posted by [Adriwin06](https://github.com/Adriwin06) on 2026-11-30T01:10:23Z. **Code review location:** `crates/victory-gpu/src/list.rs`; line 1445 ~~~~diff @@ -1408,6 +1421,29 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) { }); return; } + // A whole copy only between host textures of one shape: the host + // refuses any other, and the list would not close ([`fit_copy`] + // is the same for region copies). + // SAFETY: live textures. + let (a, b) = unsafe { (to.GetDesc(), from.GetDesc()) }; + if (a.Dimension, a.Width, a.Height, a.DepthOrArraySize, a.MipLevels) + != (b.Dimension, b.Width, b.Height, b.DepthOrArraySize, b.MipLevels) + { + static TOLD: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); + let n = TOLD.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1; + if n <= 8 || n.is_power_of_two() { + let title = |r: This| crate::resource::texture_memory(r).map(|(_, d)| format!("{d:?}")); + tracing::warn!( + times = n, + host_dst = ?(a.Width, a.Height, a.DepthOrArraySize, a.MipLevels, a.Format.0), + host_src = ?(b.Width, b.Height, b.DepthOrArraySize, b.MipLevels, b.Format.0), + title_dst = ?title(dst), + title_src = ?title(src), + "a whole texture copy between host textures of two shapes: left out" + ); + } + return; ~~~~ --- Fixed in 1e02966d: the whole copy's shape check now runs before the source upload, the twins, `card_writes`, `host_written` and `host_write_listed`. For region copies, the fit (`Fit::Nothing`) is decided before the destination is uploaded into or marked, so a copy left out leaves ownership unchanged.
Adriwin06 commented 2026-11-30 01:10:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Adriwin06 on 2026-11-30T01:10:26Z.

Code review location: crates/victory-gpu/src/list.rs; line 1688

@@ -1491,6 +1676,21 @@ extern "system" fn copy_texture_region(
         else {
             return;
         };
+        // The host copies' subresources ([`held_sub`]); `dst` and `src` keep
+        // the title's, which the placed twins and the bakes below read.
+        let host_at = |l: &CopyLocation| {
+            if l.kind == FOOTPRINT {
+                Some(l.footprint.offset)
+            } else {
+                held_sub(l.resource, l.footprint.offset as u32).map(u64::from)
+            }
+        };
+        let (Some(src_at), Some(dst_at)) = (host_at(&src), host_at(&dst)) else {

Fixed in 1e02966d: both locations grow before either host index is taken. Any side naming a level below its held base calls want_level(.., 0) first, so a copy of mip 2 into mip 0 within one held texture is recorded as 2 into 0.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4734087867 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4734087867). Originally posted by [Adriwin06](https://github.com/Adriwin06) on 2026-11-30T01:10:26Z. **Code review location:** `crates/victory-gpu/src/list.rs`; line 1688 ~~~~diff @@ -1491,6 +1676,21 @@ extern "system" fn copy_texture_region( else { return; }; + // The host copies' subresources ([`held_sub`]); `dst` and `src` keep + // the title's, which the placed twins and the bakes below read. + let host_at = |l: &CopyLocation| { + if l.kind == FOOTPRINT { + Some(l.footprint.offset) + } else { + held_sub(l.resource, l.footprint.offset as u32).map(u64::from) + } + }; + let (Some(src_at), Some(dst_at)) = (host_at(&src), host_at(&dst)) else { ~~~~ --- Fixed in 1e02966d: both locations grow before either host index is taken. Any side naming a level below its held base calls `want_level(.., 0)` first, so a copy of mip 2 into mip 0 within one held texture is recorded as 2 into 0.
Adriwin06 commented 2026-11-30 01:10:27 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Adriwin06 on 2026-11-30T01:10:27Z.

Code review location: crates/victory-gpu/src/list.rs; line 2052

@@ -1777,6 +2035,24 @@ fn read_back(
     to.resource = buffer.resource().as_raw().cast_const().cast();
     to.footprint = footprint;
     let host_box = (!source_box.is_null()).then(|| source_box.cast::<D3D12_BOX>());
+    // The region against the host texture and our buffer ([`fit_copy`]).
+    // SAFETY: the title's box, when there is one, is six words; a live texture.
+    let asked = (!source_box.is_null()).then(|| unsafe { source_box.read_unaligned() });
+    let src_extent = sub_extent(&unsafe { texture.GetDesc() }, src.footprint.offset as u32);
+    let dst_extent = footprint_extent(&footprint);
+    let fitted = match (src_extent, dst_extent) {
+        (Some(s), Some(d)) => fit_copy(s, d, [0, 0, 0], asked),
+        _ => Fit::AsAsked,
+    };
+    if fitted != Fit::AsAsked {
+        copy_did_not_fit("a read back", fitted, dst.resource, 0, src.resource, src.footprint.offset, [src_extent, dst_extent], asked, [0, 0, 0]);
+    }
+    let cut_box = match fitted {
+        Fit::AsAsked => None,
+        Fit::Cut(b) => Some(D3D12_BOX { left: b[0], top: b[1], front: b[2], right: b[3], bottom: b[4], back: b[5] }),

Fixed in 1e02966d: the deferred read back now gets the rows and bytes of the region actually written, at the buffer's start. That is the fitted cut, or the title's own box when there is one (read_back_rows). Host row pitch and title pitch are unchanged. A volume cut within each slice's height is refused before recording. Regression test: fit_tests::a_cut_read_back_returns_only_what_the_copy_wrote.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4734088007 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4734088007). Originally posted by [Adriwin06](https://github.com/Adriwin06) on 2026-11-30T01:10:27Z. **Code review location:** `crates/victory-gpu/src/list.rs`; line 2052 ~~~~diff @@ -1777,6 +2035,24 @@ fn read_back( to.resource = buffer.resource().as_raw().cast_const().cast(); to.footprint = footprint; let host_box = (!source_box.is_null()).then(|| source_box.cast::<D3D12_BOX>()); + // The region against the host texture and our buffer ([`fit_copy`]). + // SAFETY: the title's box, when there is one, is six words; a live texture. + let asked = (!source_box.is_null()).then(|| unsafe { source_box.read_unaligned() }); + let src_extent = sub_extent(&unsafe { texture.GetDesc() }, src.footprint.offset as u32); + let dst_extent = footprint_extent(&footprint); + let fitted = match (src_extent, dst_extent) { + (Some(s), Some(d)) => fit_copy(s, d, [0, 0, 0], asked), + _ => Fit::AsAsked, + }; + if fitted != Fit::AsAsked { + copy_did_not_fit("a read back", fitted, dst.resource, 0, src.resource, src.footprint.offset, [src_extent, dst_extent], asked, [0, 0, 0]); + } + let cut_box = match fitted { + Fit::AsAsked => None, + Fit::Cut(b) => Some(D3D12_BOX { left: b[0], top: b[1], front: b[2], right: b[3], bottom: b[4], back: b[5] }), ~~~~ --- Fixed in 1e02966d: the deferred read back now gets the rows and bytes of the region actually written, at the buffer's start. That is the fitted cut, or the title's own box when there is one (`read_back_rows`). Host row pitch and title pitch are unchanged. A volume cut within each slice's height is refused before recording. Regression test: `fit_tests::a_cut_read_back_returns_only_what_the_copy_wrote`.
Adriwin06 commented 2026-11-30 01:10:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Adriwin06 on 2026-11-30T01:10:29Z.

Code review location: crates/victory-gpu/src/list.rs; line 1430

@@ -1408,6 +1421,29 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) {
                 });
                 return;
             }
+            // A whole copy only between host textures of one shape: the host
+            // refuses any other, and the list would not close ([`fit_copy`]
+            // is the same for region copies).
+            // SAFETY: live textures.
+            let (a, b) = unsafe { (to.GetDesc(), from.GetDesc()) };
+            if (a.Dimension, a.Width, a.Height, a.DepthOrArraySize, a.MipLevels)
+                != (b.Dimension, b.Width, b.Height, b.DepthOrArraySize, b.MipLevels)

Fixed in 1e02966d: whole_copy_fits compares dimension, slices and levels, then the size in blocks of the same bytes, so 256x256 R32G32B32A32_UINT and 1024x1024 BC5_UNORM match. Formats whose blocks are unknown fall back to raw sizes. Regression test: fit_tests::a_whole_copy_compares_sizes_in_blocks.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4734088148 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#discussion_r4734088148). Originally posted by [Adriwin06](https://github.com/Adriwin06) on 2026-11-30T01:10:29Z. **Code review location:** `crates/victory-gpu/src/list.rs`; line 1430 ~~~~diff @@ -1408,6 +1421,29 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) { }); return; } + // A whole copy only between host textures of one shape: the host + // refuses any other, and the list would not close ([`fit_copy`] + // is the same for region copies). + // SAFETY: live textures. + let (a, b) = unsafe { (to.GetDesc(), from.GetDesc()) }; + if (a.Dimension, a.Width, a.Height, a.DepthOrArraySize, a.MipLevels) + != (b.Dimension, b.Width, b.Height, b.DepthOrArraySize, b.MipLevels) ~~~~ --- Fixed in 1e02966d: `whole_copy_fits` compares dimension, slices and levels, then the size in blocks of the same bytes, so 256x256 `R32G32B32A32_UINT` and 1024x1024 `BC5_UNORM` match. Formats whose blocks are unknown fall back to raw sizes. Regression test: `fit_tests::a_whole_copy_compares_sizes_in_blocks`.
tyr0nsur commented 2026-11-30 09:03:51 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T09:03:51Z.


I tested the read-back follow-up at 1e02966 on an RTX 4060 and found two cases that still fail. The test uploads distinct rows to a 256×256 R32_FLOAT texture and reads it back into a wider and taller footprint with a 1,280-byte GPU pitch and a 1,536-byte title pitch.

  • A null source box copies the whole source. Since it fits, Fit::AsAsked leaves the effective region unset and the CPU copies the unwritten tail of the wider destination footprint into title memory.
  • With an explicit 192×3 region, the GPU writes 768 bytes per row. The deferred CPU copy uses that width to recalculate the GPU pitch as 768 instead of 1,280. The first row lands correctly and subsequent rows come from the wrong offsets.

Follow-up commit cb3f59d carries the actual GPU pitch and uses the source extent when there is no box. The regression verifies each copied row and the sentinel bytes outside the region. Both cases fail on the PR head with only the test added and pass with the patch.

The targeted Windows suite passed 74 tests (one ignored). With the existing diagnostics build repair from 41adb551 applied locally, 95 passed (two ignored), and the new regression also passed on WARP. The staged asset-policy check passed. Review assisted by Claude Opus 5.5.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7273692176 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3062#issuecomment-7273692176). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T09:03:51Z. --- I tested the read-back follow-up at 1e02966 on an RTX 4060 and found two cases that still fail. The test uploads distinct rows to a 256×256 R32_FLOAT texture and reads it back into a wider and taller footprint with a 1,280-byte GPU pitch and a 1,536-byte title pitch. - A null source box copies the whole source. Since it fits, `Fit::AsAsked` leaves the effective region unset and the CPU copies the unwritten tail of the wider destination footprint into title memory. - With an explicit 192×3 region, the GPU writes 768 bytes per row. The deferred CPU copy uses that width to recalculate the GPU pitch as 768 instead of 1,280. The first row lands correctly and subsequent rows come from the wrong offsets. [Follow-up commit `cb3f59d`](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/cb3f59df00f4733cfe8e884e08d73e1775fb32a4) carries the actual GPU pitch and uses the source extent when there is no box. The regression verifies each copied row and the sentinel bytes outside the region. Both cases fail on the PR head with only the test added and pass with the patch. The targeted Windows suite passed 74 tests (one ignored). With the existing diagnostics build repair from `41adb551` applied locally, 95 passed (two ignored), and the new regression also passed on WARP. The staged asset-policy check passed. Review assisted by Claude Opus 5.5.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3062:upstream-pr/3062'
git switch 'upstream-pr/3062'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3062'
git switch 'upstream-pr/3062'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3062'
git switch 'upstream-pr/3062'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3062'
git switch 'main'
git merge --squash 'upstream-pr/3062'
git switch 'main'
git merge --ff-only 'upstream-pr/3062'
git switch 'main'
git merge 'upstream-pr/3062'
git push origin 'main'
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
trustno1-coder/VIctory-NVIDIA!3062
No description provided.