Placed twins of another format family get their copy through a buffer… #3976

Closed
Koaio wants to merge 1 commit from upstream-pr/3976 into main
Koaio commented 2026-11-30 13:32:32 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Koaio on 2026-11-30T13:32:32Z.


…, not texture to texture (0x80070057 at list close)

The twins of a texture (resource::placed_twins) are matched by block size, so a BC3 texture's twin can be BC7. copy_texture_region copied into every twin with the title's own locations, and D3D12 refuses a texture to texture (or footprint to texture) copy across families when the list closes: "a host command list did not close (0x80070057)". #3901 named those twin copies as the refused commands (BC3_UNORM_SRGB levels into a BC7_UNORM_SRGB twin) and showed the same bytes land bit for bit through a buffer.

twin_copy now picks a route per twin:

  • same family: the title's copy, as before;
  • a buffer source: its footprint read in the twin's format;
  • a whole subresource of a texture: through a buffer, out in the source's format and in in the twin's (as texture::alias does), when both levels are laid out alike;
  • anything else across families: left out, counted, the first 16 logged.

Fixes #3923, #3928; refs #3901, #3880.

Fixes #

What it changes

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing):
  • Before:
  • After:
  • For shader changes, the wave sizes tested (32 and/or 64 lanes):
  • cargo test passed for the crates it touches: yes / no

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5566277925 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3976). Originally posted by [Koaio](https://github.com/Koaio) on 2026-11-30T13:32:32Z. --- …, not texture to texture (0x80070057 at list close) The twins of a texture (`resource::placed_twins`) are matched by block size, so a BC3 texture's twin can be BC7. `copy_texture_region` copied into every twin with the title's own locations, and D3D12 refuses a texture to texture (or footprint to texture) copy across families when the list closes: "a host command list did not close (0x80070057)". #3901 named those twin copies as the refused commands (BC3_UNORM_SRGB levels into a BC7_UNORM_SRGB twin) and showed the same bytes land bit for bit through a buffer. `twin_copy` now picks a route per twin: - same family: the title's copy, as before; - a buffer source: its footprint read in the twin's format; - a whole subresource of a texture: through a buffer, out in the source's format and in in the twin's (as `texture::alias` does), when both levels are laid out alike; - anything else across families: left out, counted, the first 16 logged. Fixes #3923, #3928; refs #3901, #3880. <!-- Thanks for the pull request. Please label it (pr-fix, pr-feature, pr-performance, pr-diagnostics, pr-refactor, pr-docs or pr-tests, plus the area labels), or put the label in the title, like [pr-fix]. --> Fixes # ## What it changes <!-- What was wrong, and what this does about it. --> ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): - Before: - After: - For shader changes, the wave sizes tested (32 and/or 64 lanes): - `cargo test` passed for the crates it touches: yes / no ## Checked for overlap - [ ] I searched the open pull requests for the same issue and for the files this touches. Related: #
tyr0nsur commented 2026-11-30 13:49:15 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T13:49:15Z.


I found a silent partial-copy case in the routing at 31f83baa. The primary copy can legally interpret a 4×4 R32G32B32A32_TYPELESS footprint as the 16 blocks of a 16×16 BC3 texture. When the twin is also BC3, the current branch changes the footprint to BC3 while leaving its dimensions at 4×4. D3D12 now reads one block instead of 16. Both commands close and execute successfully.

I initialized the destination to zero, filled the source with a 256-byte pattern across all four rows, and read back the BC3 blocks. The original footprint and a direct raw texture source reproduced all 256 bytes. The retagged footprint only copied the first 16 bytes. This reproduced on RTX 4060 and WARP for BC3 typeless, UNORM and sRGB.

The tested follow-up uses the primary destination family for the original-copy path, as #3979 does, and keeps the buffer route for compatible cross-family layouts such as BC3/BC7. A footprint can only be retagged when both element size and block dimensions match. It also delays the write bookkeeping until a route will actually record a copy. Previously a skipped region or failed scratch allocation could still mark the twin as host-written and suppress a later upload.

The route regression and related list, resource and alias-copy tests passed on Windows with 59 passed and 1 ignored in both the native and WARP configurations. Gameplay and the reported cutscene crashes remain unverified by this synthetic test.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7280409735 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3976#issuecomment-7280409735). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T13:49:15Z. --- I found a silent partial-copy case in the routing at 31f83baa. The primary copy can legally interpret a 4×4 `R32G32B32A32_TYPELESS` footprint as the 16 blocks of a 16×16 BC3 texture. When the twin is also BC3, the current branch changes the footprint to BC3 while leaving its dimensions at 4×4. D3D12 now reads one block instead of 16. Both commands close and execute successfully. I initialized the destination to zero, filled the source with a 256-byte pattern across all four rows, and read back the BC3 blocks. The original footprint and a direct raw texture source reproduced all 256 bytes. The retagged footprint only copied the first 16 bytes. This reproduced on RTX 4060 and WARP for BC3 typeless, UNORM and sRGB. The [tested follow-up](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/8ee5a30ca53b8846ba5599759e9e90e5875062fa) uses the primary destination family for the original-copy path, as #3979 does, and keeps the buffer route for compatible cross-family layouts such as BC3/BC7. A footprint can only be retagged when both element size and block dimensions match. It also delays the write bookkeeping until a route will actually record a copy. Previously a skipped region or failed scratch allocation could still mark the twin as host-written and suppress a later upload. The route regression and related list, resource and alias-copy tests passed on Windows with 59 passed and 1 ignored in both the native and WARP configurations. Gameplay and the reported cutscene crashes remain unverified by this synthetic test.
tillo88 commented 2026-11-30 17:58:55 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tillo88 on 2026-11-30T17:58:55Z.


I wanted to measure this against the 0x80070057 crash at the prison-to-plane cut (#2237), but it no longer merges: conflict with v2026.11.30.01 and with v2026.11.30.02 (GitHub shows it as conflicting with main too). I'll measure it if it is rebased.

Measured unattended on a replay bench (same save, recorded controller input via VICTORY_INPUT_REPLAY); numbers and text prepared with Claude.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7287136044 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3976#issuecomment-7287136044). Originally posted by [tillo88](https://github.com/tillo88) on 2026-11-30T17:58:55Z. --- I wanted to measure this against the 0x80070057 crash at the prison-to-plane cut (#2237), but it no longer merges: conflict with v2026.11.30.01 and with v2026.11.30.02 (GitHub shows it as conflicting with main too). I'll measure it if it is rebased. Measured unattended on a replay bench (same save, recorded controller input via VICTORY_INPUT_REPLAY); numbers and text prepared with Claude.
Lyrnc commented 2026-11-30 18:59:47 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T18:59:47Z.


Test report for this PR: the failure it targets is confirmed on WARP, and the PR routes every refused pair around it. The mission crash itself is not reproduced in game.

Setup: v2026.11.30.01 (c71899d9) and v2026.11.30.02 (84bd61e2); RTX 5080, Series X profile, 2560x1440, DLSS off, frame generation off, ray tracing off. To get it onto current main I re-applied 31f83baa on .01 and .02. Main now finds the twin's subresource with resource::host_target, so that lookup stays and twin_copy gets main's host_sub. No other change.

1. Mechanism, unit test on the software adapter (WARP). Each case records one copy into a fresh list, then calls Close.

Copy into a placed twin (title side to twin) Close without a check With this PR
BC3_UNORM_SRGB to BC7_UNORM_SRGB, texture to texture E_INVALIDARG whole level: through a buffer, closes; part of a level: left out
BC3_UNORM to BC7_UNORM E_INVALIDARG the same
BC7_UNORM to BC6H_UF16 E_INVALIDARG the same
BC1_UNORM to BC4_UNORM E_INVALIDARG the same
BC3 footprint (buffer) into a BC7 texture E_INVALIDARG read as a BC7 footprint, closes
same family: BC3_SRGB to BC3, BC7 to BC7_SRGB closes copied as before

The middle column comes from the WARP tests. The right column is twin_route checked on each pair, plus each pair's through-buffer copy recorded and closed on WARP, in a test on the port. Your own two tests pass there too. The tests ran on the .02 port, because .01's own test build stops at host test calls that .02 fixed. The mechanism tests are on a branch: https://github.com/Lyrnc/VIctory-NVIDIA/commits/test/twin-copy-close-warp (list::twin_close_tests). The per-PR check is below; it goes in the same module.

One review note, untested in game. Retyped swaps in the twin's format and keeps the footprint's texel width and height. For BC3 to BC7 that is exact, since both use 16-byte 4x4 blocks. But a raw footprint of 16-byte texels (R32G32B32A32, one texel per block) into a BC3 destination whose twin is BC7 also counts as "another family" here. Retyped as BC7, it would cover 1/16 of the region. D3D12 accepts that raw copy as it is: an R32G32B32A32 footprint into a BC7 texture closes on WARP. So it may be worth taking Retyped only when the source's block size matches the twin's, and letting the raw pairs D3D12 allows stay Direct. That only matters if the title makes such copies into twins, which I haven't seen.

Per-PR check (passes on the port)
    /// The pairs D3D12 refuses above (title destination or source, twin).
    const REFUSED: [(DXGI_FORMAT, DXGI_FORMAT); 4] = [
        (DXGI_FORMAT_BC3_UNORM_SRGB, DXGI_FORMAT_BC7_UNORM_SRGB),
        (DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC7_UNORM),
        (DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC6H_UF16),
        (DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC4_UNORM),
    ];
    /// #3976 never records a refused pair texture to texture: a whole level
    /// goes through a buffer, a part of a level is left out, a footprint is
    /// read in the twin's format. The through-buffer copy of every refused
    /// pair closes on the software adapter; so does the BC3 footprint read
    /// as BC7 (`a_footprint_copy_into_a_twin_of_another_family_fails_close`).
    #[test]
    fn pr3976_routes_every_refused_twin_copy_around_the_refusal() {
        use super::{twin_route, TwinRoute};
        for (from, twin) in REFUSED {
            let (f, t) = (from.0 as u32, twin.0 as u32);
            assert_eq!(twin_route(f, t, false, true), TwinRoute::Through);
            assert_eq!(twin_route(f, t, false, false), TwinRoute::LeftOut);
            assert_eq!(twin_route(f, t, true, true), TwinRoute::Retyped);
            assert_eq!(twin_route(f, t, true, false), TwinRoute::Retyped);
            let Some(gpu) = WarpHarness::new() else {
                eprintln!("no software adapter: not measured");
                return;
            };
            let (source, of_source) = texture(&gpu, from, D3D12_RESOURCE_STATE_COPY_SOURCE);
            let (to, of_twin) = texture(&gpu, twin, D3D12_RESOURCE_STATE_COPY_DEST);
            let mut rows = [D3D12_PLACED_SUBRESOURCE_FOOTPRINT::default(); 2];
            let mut bytes = [0u64; 2];
            // SAFETY: plain queries; the out pointers are ours.
            unsafe {
                gpu.device.GetCopyableFootprints(&of_source, 0, 1, 0, Some(&mut rows[0]), None, None, Some(&mut bytes[0]));
                gpu.device.GetCopyableFootprints(&of_twin, 0, 1, 0, Some(&mut rows[1]), None, None, Some(&mut bytes[1]));
            }
            assert_eq!(bytes[0], bytes[1]);
            let through = buffer_in(&gpu, bytes[0], D3D12_RESOURCE_STATE_COMMON);
            let placed = |row: &D3D12_PLACED_SUBRESOURCE_FOOTPRINT| D3D12_TEXTURE_COPY_LOCATION {
                // SAFETY: as in `at`.
                pResource: unsafe { std::mem::transmute_copy(&through) },
                Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
                Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { PlacedFootprint: *row },
            };
            // SAFETY: an open list; live resources in their copy states.
            let closed = unsafe {
                gpu.list.ResourceBarrier(&[crate::host::transition(&through, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_DEST)]);
                gpu.list.CopyTextureRegion(&placed(&rows[0]), 0, 0, 0, &at(&source, 0), None);
                gpu.list.ResourceBarrier(&[crate::host::transition(&through, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE)]);
                gpu.list.CopyTextureRegion(&at(&to, 0), 0, 0, 0, &placed(&rows[1]), None);
                gpu.list.Close()
            };
            eprintln!("#3976: {from:?} -> twin {twin:?} through a buffer: Close {:?}", closed.as_ref().map_err(|e| e.code()));
            assert!(closed.is_ok(), "{from:?} -> {twin:?}");
        }
    }
    // `buffer_in(gpu, bytes, state)`: a default-heap buffer made in `state`.

2. In game: the mission crash is not reproduced. The save attached to #3972 starts before the mission. Reaching the scene where it crashes means a long drive plus the first part of the mission, and #3890 says there is no save point after that part, so our scripted runs could not get there. I did about 25 min of free roam from that save on .01, outdoors and in a house interior. The build carried a local diagnostic log that names every copy D3D12 would refuse (title copies and placed-twin copies) and, when Close fails, what that list held. Result: no refused twin copy and no failed Close. The cross-family twin path simply did not come up there, so it gives no before/after for this PR.

Not covered by this PR (twins don't need it): a title copy whose own source and destination are of different families (#2914's BC7_TYPELESS -> BC6H). #3043 goes at that one.

Tested and written with Claude Code (AI).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7288681681 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3976#issuecomment-7288681681). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-30T18:59:47Z. --- **Test report for this PR: the failure it targets is confirmed on WARP, and the PR routes every refused pair around it. The mission crash itself is not reproduced in game.** Setup: v2026.11.30.01 (c71899d9) and v2026.11.30.02 (84bd61e2); RTX 5080, Series X profile, 2560x1440, DLSS off, frame generation off, ray tracing off. To get it onto current main I re-applied 31f83baa on .01 and .02. Main now finds the twin's subresource with `resource::host_target`, so that lookup stays and `twin_copy` gets main's `host_sub`. No other change. **1. Mechanism, unit test on the software adapter (WARP).** Each case records one copy into a fresh list, then calls `Close`. | Copy into a placed twin (title side to twin) | `Close` without a check | With this PR | |---|---|---| | BC3_UNORM_SRGB to BC7_UNORM_SRGB, texture to texture | E_INVALIDARG | whole level: through a buffer, closes; part of a level: left out | | BC3_UNORM to BC7_UNORM | E_INVALIDARG | the same | | BC7_UNORM to BC6H_UF16 | E_INVALIDARG | the same | | BC1_UNORM to BC4_UNORM | E_INVALIDARG | the same | | BC3 footprint (buffer) into a BC7 texture | E_INVALIDARG | read as a BC7 footprint, closes | | same family: BC3_SRGB to BC3, BC7 to BC7_SRGB | closes | copied as before | The middle column comes from the WARP tests. The right column is `twin_route` checked on each pair, plus each pair's through-buffer copy recorded and closed on WARP, in a test on the port. Your own two tests pass there too. The tests ran on the .02 port, because .01's own test build stops at host test calls that .02 fixed. The mechanism tests are on a branch: https://github.com/Lyrnc/VIctory-NVIDIA/commits/test/twin-copy-close-warp (`list::twin_close_tests`). The per-PR check is below; it goes in the same module. One review note, untested in game. `Retyped` swaps in the twin's format and keeps the footprint's texel width and height. For BC3 to BC7 that is exact, since both use 16-byte 4x4 blocks. But a raw footprint of 16-byte texels (R32G32B32A32, one texel per block) into a BC3 destination whose twin is BC7 also counts as "another family" here. Retyped as BC7, it would cover 1/16 of the region. D3D12 accepts that raw copy as it is: an R32G32B32A32 footprint into a BC7 texture closes on WARP. So it may be worth taking `Retyped` only when the source's block size matches the twin's, and letting the raw pairs D3D12 allows stay `Direct`. That only matters if the title makes such copies into twins, which I haven't seen. <details><summary>Per-PR check (passes on the port)</summary> ```rust /// The pairs D3D12 refuses above (title destination or source, twin). const REFUSED: [(DXGI_FORMAT, DXGI_FORMAT); 4] = [ (DXGI_FORMAT_BC3_UNORM_SRGB, DXGI_FORMAT_BC7_UNORM_SRGB), (DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC7_UNORM), (DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC6H_UF16), (DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC4_UNORM), ]; /// #3976 never records a refused pair texture to texture: a whole level /// goes through a buffer, a part of a level is left out, a footprint is /// read in the twin's format. The through-buffer copy of every refused /// pair closes on the software adapter; so does the BC3 footprint read /// as BC7 (`a_footprint_copy_into_a_twin_of_another_family_fails_close`). #[test] fn pr3976_routes_every_refused_twin_copy_around_the_refusal() { use super::{twin_route, TwinRoute}; for (from, twin) in REFUSED { let (f, t) = (from.0 as u32, twin.0 as u32); assert_eq!(twin_route(f, t, false, true), TwinRoute::Through); assert_eq!(twin_route(f, t, false, false), TwinRoute::LeftOut); assert_eq!(twin_route(f, t, true, true), TwinRoute::Retyped); assert_eq!(twin_route(f, t, true, false), TwinRoute::Retyped); let Some(gpu) = WarpHarness::new() else { eprintln!("no software adapter: not measured"); return; }; let (source, of_source) = texture(&gpu, from, D3D12_RESOURCE_STATE_COPY_SOURCE); let (to, of_twin) = texture(&gpu, twin, D3D12_RESOURCE_STATE_COPY_DEST); let mut rows = [D3D12_PLACED_SUBRESOURCE_FOOTPRINT::default(); 2]; let mut bytes = [0u64; 2]; // SAFETY: plain queries; the out pointers are ours. unsafe { gpu.device.GetCopyableFootprints(&of_source, 0, 1, 0, Some(&mut rows[0]), None, None, Some(&mut bytes[0])); gpu.device.GetCopyableFootprints(&of_twin, 0, 1, 0, Some(&mut rows[1]), None, None, Some(&mut bytes[1])); } assert_eq!(bytes[0], bytes[1]); let through = buffer_in(&gpu, bytes[0], D3D12_RESOURCE_STATE_COMMON); let placed = |row: &D3D12_PLACED_SUBRESOURCE_FOOTPRINT| D3D12_TEXTURE_COPY_LOCATION { // SAFETY: as in `at`. pResource: unsafe { std::mem::transmute_copy(&through) }, Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { PlacedFootprint: *row }, }; // SAFETY: an open list; live resources in their copy states. let closed = unsafe { gpu.list.ResourceBarrier(&[crate::host::transition(&through, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_DEST)]); gpu.list.CopyTextureRegion(&placed(&rows[0]), 0, 0, 0, &at(&source, 0), None); gpu.list.ResourceBarrier(&[crate::host::transition(&through, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE)]); gpu.list.CopyTextureRegion(&at(&to, 0), 0, 0, 0, &placed(&rows[1]), None); gpu.list.Close() }; eprintln!("#3976: {from:?} -> twin {twin:?} through a buffer: Close {:?}", closed.as_ref().map_err(|e| e.code())); assert!(closed.is_ok(), "{from:?} -> {twin:?}"); } } // `buffer_in(gpu, bytes, state)`: a default-heap buffer made in `state`. ``` </details> **2. In game: the mission crash is not reproduced.** The save attached to #3972 starts before the mission. Reaching the scene where it crashes means a long drive plus the first part of the mission, and #3890 says there is no save point after that part, so our scripted runs could not get there. I did about 25 min of free roam from that save on .01, outdoors and in a house interior. The build carried a local diagnostic log that names every copy D3D12 would refuse (title copies and placed-twin copies) and, when `Close` fails, what that list held. Result: no refused twin copy and no failed `Close`. The cross-family twin path simply did not come up there, so it gives no before/after for this PR. Not covered by this PR (twins don't need it): a title copy whose own source and destination are of different families (#2914's `BC7_TYPELESS -> BC6H`). #3043 goes at that one. Tested and written with Claude Code (AI).
trustno1-coder commented 2026-12-01 18:47:22 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:47:22Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321548036 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3976#issuecomment-7321548036). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:47:22Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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