GPU: check destination format family for CopyTextureRegion placed twins #3979

Manually merged
github merged 494 commits from github-bot/gh-3979 into main 2026-11-30 16:52:20 +00:00 AGit
Owner

@⁠bemfavivaEC807E52 on GitHub · 2026-11-30 13:33 UTC · original
bemfavivaEC807E52:pr/twin-copy-format-family → main · +38 −3 · 2 files · 1 commits · closed without merging

Summary

Fixes a 0x80070057 (a host command list did not close) crash in copy_texture_region's placed_twins loop when a placed twin has the same block/element size as the destination texture but belongs to a different DXGI format family (for example BC3 vs BC7, #3901).

Root cause

  • resource::placed_twins pairs overlapping texture views by block/element size only (so 16-byte-block BC3 and BC7 views can be paired).
  • While copy_resource already checks format-family compatibility before recording twin copies, copy_texture_region recorded CopyTextureRegion into every twin returned by placed_twins without a format-family check.
  • D3D12 rejects cross-family CopyTextureRegion copies with E_INVALIDARG (0x80070057) at ID3D12GraphicsCommandList::Close().

What this PR changes (crates/victory-gpu/src/list.rs)

  • Compares the primary destination's host format family (to.GetDesc().Format) against the twin's host format family (other.GetDesc().Format) via resource::family().
    • Comparing against the destination format (rather than the copy source format) intentionally preserves valid D3D12 raw-block bake copies such as R32G32B32A32_TYPELESS -> BC3_TYPELESS for same-family twins, while cleanly skipping cross-family twins (BC3 vs BC7, BC7 vs BC6H, R8G8B8A8 vs R16G16).
  • Skips mismatched twins before calling host_written, host_write_listed, or ensure_state, and logs the first 16 occurrences (then every 1024th) at INFO.
  • Adds unit test placed_twins_require_a_matching_destination_format_family.

Relation to #3792 and #3043

  • Complements #3792 (which fixes held-mip-level / extent mismatches in placed_twins): on live RTX 4090 / Series X runs tested alongside #3792, the same area that previously crashed twice in a row with 0x80070057 triggered 16 cross-family twin skips at base=0 (other format family), which held-level mapping alone does not catch, and ran with 0 errors / 0 crashes.
  • Note: raw-sourced copies into cross-family twins are skipped here rather than bounced through an intermediate buffer (for full cross-format bouncing, see #3043).

Verification

  • cargo test -p victory-gpu --locked placed_twins_require_a_matching_destination_format_family: passed (0 failures).
  • Live RTX 4090 / 4K / Series X test: intercepted 16 cross-family twin copies at base=0 with 0 0x80070057 crashes.
**@⁠bemfavivaEC807E52** on GitHub · 2026-11-30 13:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3979) `bemfavivaEC807E52:pr/twin-copy-format-family` → `main` · +38 −3 · 2 files · 1 commits · closed without merging ## Summary Fixes a `0x80070057` (`a host command list did not close`) crash in `copy_texture_region`'s `placed_twins` loop when a placed twin has the same block/element size as the destination texture but belongs to a different DXGI format family (for example BC3 vs BC7, #3901). ### Root cause - `resource::placed_twins` pairs overlapping texture views by block/element size only (so 16-byte-block BC3 and BC7 views can be paired). - While `copy_resource` already checks format-family compatibility before recording twin copies, `copy_texture_region` recorded `CopyTextureRegion` into every twin returned by `placed_twins` without a format-family check. - D3D12 rejects cross-family `CopyTextureRegion` copies with `E_INVALIDARG` (`0x80070057`) at `ID3D12GraphicsCommandList::Close()`. ### What this PR changes (`crates/victory-gpu/src/list.rs`) - Compares the **primary destination's host format family** (`to.GetDesc().Format`) against the **twin's host format family** (`other.GetDesc().Format`) via `resource::family()`. - Comparing against the destination format (rather than the copy source format) intentionally preserves valid D3D12 raw-block bake copies such as `R32G32B32A32_TYPELESS -> BC3_TYPELESS` for same-family twins, while cleanly skipping cross-family twins (BC3 vs BC7, BC7 vs BC6H, R8G8B8A8 vs R16G16). - Skips mismatched twins **before** calling `host_written`, `host_write_listed`, or `ensure_state`, and logs the first 16 occurrences (then every 1024th) at `INFO`. - Adds unit test `placed_twins_require_a_matching_destination_format_family`. ### Relation to #3792 and #3043 - Complements #3792 (which fixes held-mip-level / extent mismatches in `placed_twins`): on live RTX 4090 / Series X runs tested alongside #3792, the same area that previously crashed twice in a row with `0x80070057` triggered **16 cross-family twin skips at `base=0`** (`other format family`), which held-level mapping alone does not catch, and ran with **0 errors / 0 crashes**. - Note: raw-sourced copies into cross-family twins are skipped here rather than bounced through an intermediate buffer (for full cross-format bouncing, see #3043). ### Verification - `cargo test -p victory-gpu --locked placed_twins_require_a_matching_destination_format_family`: passed (0 failures). - Live RTX 4090 / 4K / Series X test: intercepted 16 cross-family twin copies at `base=0` with 0 `0x80070057` crashes.
placed_twins pairs overlapping texture views by block/element size only, so a BC3 texture and a BC7 twin (both 16-byte blocks) can be paired. While CopyResource already checks format family compatibility, CopyTextureRegion's placed_twins loop recorded copies into cross-family twins without checking, causing D3D12 ID3D12GraphicsCommandList::Close() to fail with E_INVALIDARG (0x80070057) (#3901).

Compare the primary destination's host format family against the twin's host format family (rather than the copy source format, so valid raw-source bakes like R32G32B32A32_TYPELESS -> BC3_TYPELESS still reach same-family twins). Skip mismatched twins before marking host_written / ensure_state and log the first 16 occurrences.

Verified live on RTX 4090 / Series X alongside #3792: intercepted 16 cross-family twin copies (base=0) in the same sequence that previously crashed twice in a row with 0x80070057, eliminating the crash.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 13:34:57 +00:00
github-bot force-pushed github-bot/gh-3979 from c383067a7d to c71899d9e8 2026-11-30 16:52:17 +00:00 Compare
github manually merged commit e0f3e08131 into main 2026-11-30 16:52:20 +00:00
Author
Owner

@⁠ozigalko on GitHub · 2026-11-30 17:30 UTC · original

Independent confirmation on RTX 5070 Ti / i7-13700K / 32 GB: with an equivalent family check on v2026.11.30.01, 0 of 7 runs crashed with 0x80070057 (before: 2 of 8 on 11.29.04/.05, 3 of 11 on Broadside-RT rt-test-13). The skipped copies were BC3 (family 76) into BC7 (family 97), on 2 twin textures, which looks like the copy placed_twins exists for; #4080 keeps that copy through a buffer instead of skipping it. Details and table in #4080.

**@⁠ozigalko** on GitHub · 2026-11-30 17:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3979#issuecomment-7286422413) Independent confirmation on RTX 5070 Ti / i7-13700K / 32 GB: with an equivalent family check on v2026.11.30.01, 0 of 7 runs crashed with 0x80070057 (before: 2 of 8 on 11.29.04/.05, 3 of 11 on Broadside-RT rt-test-13). The skipped copies were BC3 (family 76) into BC7 (family 97), on 2 twin textures, which looks like the copy `placed_twins` exists for; #4080 keeps that copy through a buffer instead of skipping it. Details and table in #4080.
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-30 18:59 UTC · original

Test report for this PR: the failure it targets is confirmed on WARP, and the PR leaves out every refused pair. 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 c383067a on .01 and .02. Main now finds the twin's subresource with resource::host_target, so that lookup stays and the family check comes right after it. 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 left out
BC3_UNORM to BC7_UNORM E_INVALIDARG left out
BC7_UNORM to BC6H_UF16 E_INVALIDARG left out
BC1_UNORM to BC4_UNORM E_INVALIDARG left out
BC3 footprint (buffer) into a BC7 texture E_INVALIDARG left out (the title destination is BC3)
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_copy_same_family checked on each pair, in a test on the port. Your own placed_twins_require_a_matching_destination_format_family passes 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. Anyone can take them into this PR.

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),
    ];
    /// #3979 leaves out a twin copy whenever the title destination's family
    /// is not the twin's, whatever the source (texture or footprint): every
    /// refused pair above, and the BC3 footprint into a BC7 twin (its title
    /// destination is BC3). Same-family twins keep their copy.
    #[test]
    fn pr3979_leaves_out_every_refused_twin_copy() {
        for (to, twin) in REFUSED {
            assert!(!super::twin_copy_same_family(to.0 as u32, twin.0 as u32), "{to:?} -> {twin:?}");
            eprintln!("#3979: title destination {to:?}, twin {twin:?}: left out");
        }
        assert!(super::twin_copy_same_family(DXGI_FORMAT_BC3_UNORM.0 as u32, DXGI_FORMAT_BC3_UNORM_SRGB.0 as u32));
    }

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, the BC7_TYPELESS -> BC6H that #2914's debug layer named. #3043 goes at that one. The naming log saw none in free roam.

Tested and written with Claude Code (AI).

**@⁠Lyrnc** on GitHub · 2026-11-30 18:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3979#issuecomment-7288680916) **Test report for this PR: the failure it targets is confirmed on WARP, and the PR leaves out every refused pair. 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 c383067a on .01 and .02. Main now finds the twin's subresource with `resource::host_target`, so that lookup stays and the family check comes right after it. 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 | left out | | BC3_UNORM to BC7_UNORM | E_INVALIDARG | left out | | BC7_UNORM to BC6H_UF16 | E_INVALIDARG | left out | | BC1_UNORM to BC4_UNORM | E_INVALIDARG | left out | | BC3 footprint (buffer) into a BC7 texture | E_INVALIDARG | left out (the title destination is BC3) | | 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_copy_same_family` checked on each pair, in a test on the port. Your own `placed_twins_require_a_matching_destination_format_family` passes 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. Anyone can take them into this PR. <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), ]; /// #3979 leaves out a twin copy whenever the title destination's family /// is not the twin's, whatever the source (texture or footprint): every /// refused pair above, and the BC3 footprint into a BC7 twin (its title /// destination is BC3). Same-family twins keep their copy. #[test] fn pr3979_leaves_out_every_refused_twin_copy() { for (to, twin) in REFUSED { assert!(!super::twin_copy_same_family(to.0 as u32, twin.0 as u32), "{to:?} -> {twin:?}"); eprintln!("#3979: title destination {to:?}, twin {twin:?}: left out"); } assert!(super::twin_copy_same_family(DXGI_FORMAT_BC3_UNORM.0 as u32, DXGI_FORMAT_BC3_UNORM_SRGB.0 as u32)); } ``` </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, the `BC7_TYPELESS -> BC6H` that #2914's debug layer named. #3043 goes at that one. The naming log saw none in free roam. Tested and written with Claude Code (AI).
Author
Owner

@⁠tillo88 on GitHub · 2026-12-01 12:06 UTC · original

Crash and speed check of #3979 (head 0bd8a5f8) merged on top of v2026.11.30.03, against the bare release on the same bench and route.

Crashes (warm-up runs included for the count):

build runs list-close / device-lost failures
v2026.11.30.03 27 5: 3 at the prison → plane cutscene cut (+2:15 to +2:18), 1 at +2:40, 1 at +2:49
+ #3979 7 0

Base errors were a host command list did not close (0x80070057) (2) and relay: the device was lost ... (0x887A0006) (3). With #3979 all 7 runs went past the cut and ran the whole ~6 min route. At the base rate (5 of 27), 0 of 7 by chance is about 24%, so on its own this is not conclusive.

The PR's line a copy into a view placed over a texture the host copied into is left out ... why="other format family" appears in every run, 12 to 16 times, in two bursts between +0:41 and +1:53 (before the cut). The PR logs only the first 16, and 3 runs reached 16, so any later skips, at the cut included, would not show in those runs. The masked twin was made at +2:14/+2:15 in all 7 runs, as in the base.

Speed (measured runs only, warm-up excluded):

build runs fps (range) submitting thread ms refresh ms p95 ms p99 ms
v2026.11.30.03 15 32.02 (31.72–32.46) 20.51 6.42 47.7 62.7
+ #3979 6 32.12 (31.90–32.46) 20.47 6.34 48.5 63.4

+0.3% fps: no measurable difference. The higher mean p95 comes from one run (53.7 ms); the other five had 47.3–47.7 ms.

Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing off. Route: same save from the start of the game, prison cutscene, plane cutscene, first boat section, about 6 minutes per run.

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

**@⁠tillo88** on GitHub · 2026-12-01 12:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3979#issuecomment-7310671402) Crash and speed check of #3979 (head 0bd8a5f8) merged on top of v2026.11.30.03, against the bare release on the same bench and route. **Crashes** (warm-up runs included for the count): | build | runs | list-close / device-lost failures | |---|---|---| | v2026.11.30.03 | 27 | 5: 3 at the prison → plane cutscene cut (+2:15 to +2:18), 1 at +2:40, 1 at +2:49 | | + #3979 | 7 | 0 | Base errors were `a host command list did not close (0x80070057)` (2) and `relay: the device was lost ... (0x887A0006)` (3). With #3979 all 7 runs went past the cut and ran the whole ~6 min route. At the base rate (5 of 27), 0 of 7 by chance is about 24%, so on its own this is not conclusive. The PR's line `a copy into a view placed over a texture the host copied into is left out ... why="other format family"` appears in **every** run, 12 to 16 times, in two bursts between +0:41 and +1:53 (before the cut). The PR logs only the first 16, and 3 runs reached 16, so any later skips, at the cut included, would not show in those runs. The masked twin was made at +2:14/+2:15 in all 7 runs, as in the base. **Speed** (measured runs only, warm-up excluded): | build | runs | fps (range) | submitting thread ms | refresh ms | p95 ms | p99 ms | |---|---|---|---|---|---|---| | v2026.11.30.03 | 15 | 32.02 (31.72–32.46) | 20.51 | 6.42 | 47.7 | 62.7 | | + #3979 | 6 | 32.12 (31.90–32.46) | 20.47 | 6.34 | 48.5 | 63.4 | +0.3% fps: no measurable difference. The higher mean p95 comes from one run (53.7 ms); the other five had 47.3–47.7 ms. Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing off. Route: same save from the start of the game, prison cutscene, plane cutscene, first boat section, about 6 minutes per run. Measured unattended on a replay bench (same save, recorded controller input via VICTORY_INPUT_REPLAY); numbers and text prepared with Claude.
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:47 UTC · original

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.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:47 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3979#issuecomment-7321547386) 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.
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/trustno1-coder--VIctory-NVIDIA!3979
No description provided.