GPU: copy into a placed twin of another format family through a buffer (#3901) #4080

Closed
github-bot wants to merge 1 commit from github-bot/gh-4080 into main AGit
Owner

@⁠ShalakZ on GitHub · 2026-11-30 15:41 UTC · original
ShalakZ:pr/twin-family-buffer → main · +526 −8 · 2 files · 1 commits · closed without merging

Fixes the a host command list did not close (0x80070057) crash named in #3901: the placed-twin CopyTextureRegion across format families (BC3_UNORM_SRGB levels into a BC7_UNORM_SRGB twin; placed_twins matches block size only).

What it changes

twin_plan / twin_record in list.rs choose the route for each twin, comparing host formats:

  • same family, another element size or block width (e.g. a raw R32G32B32A32 source of a BC texture, which D3D12 allows), or depth with stencil / 2x1-block formats (laid out per plane): the title's copy, as before;
  • a buffer source: its footprint tagged with the twin's format;
  • a texture source: through a pooled device-local buffer (HostList::copy_scratch, from uav_pool, returned once the list has run). The whole source subresource goes out in the source's format (GetCopyableFootprints); then the title's box of it goes into the twin, at the title's place, in the twin's format. A box that ends at the edge of a small BC level (right = 2 on a 2x2 level) is rounded to whole blocks on the footprint. The buffer is left COMMON;
  • across families with no buffer or no layout: left out (twin_copy_left_out), never recorded as it is.

Counted in TWIN_ACROSS; an info line at powers of two.

Compared with #3976 (same buffer route): this also covers boxed copies and copies placed elsewhere in a level, rather than leaving them out. It also keeps the title's copy whenever the block width differs, so a raw footprint is never retagged (the case found in review on #3976). #3979 skips all cross-family twins. This comparison comes from reading their diffs; I have not run them.

How it was tested

  • Unit tests (RTX 4080, driver 621.40), on this branch (main c71899d9 + this commit):
    • twin_copies_across_bc_families_close_and_land_bit_for_bit records through twin_plan/twin_record: every BC3 level into a BC7 twin down to 1x1, a 32x32 box placed at 128,64, a buffer source, and the 2x2 and 1x1 levels with boxes of their size. The list closes and the twins read back bit for bit equal to the source blocks. With twin_plan forced to the direct copy, or without the block rounding, Close fails with 0x80070057.
    • twin_plan_keeps_the_title_copy_where_d3d12_allows_it: a raw footprint into a BC twin, and planar pairs, stay direct.
    • a_copy_between_bc_families_fails_close keeps the rule itself.
  • cargo test -p victory-gpu on this branch: 1116 passed, 2 failed, 66 ignored.
    • The two failures are shader_cache::tests::every_switch_of_the_translator_is_in_the_key (VICTORY_ORACLE_RUNS no longer read) and list::thin::tests::bindings_record_no_work (47 vs 49). Both also fail on bare main c71899d9.
    • main's test target does not compile at c71899d9 (card_pass gained a 6th argument; two calls in host.rs tests pass 5). For these runs I added [0; 3] locally; that patch is not in this PR.
    • cargo clippy -p victory-gpu --lib (default and --all-features) and --tests: no warnings in the changed lines.
  • In game: on v2026.11.29.05 plus this change (before host_target; on current main only the unit tests ran). RTX 4080, 2560x1440, DLSS off, RT off.
    • Diagnostics + DRED, 420 s: cross-family twin copies went through a buffer at 69 s and 200 s, and the run survived.
    • Release, 360 s, with more switches on: they went through at 69 s, and the run survived.
    • Before the fix, the same scripted start failed Close at 199-206 s in 11 runs and at 69-72 s in 2.
  • GPU and profile: RTX 4080, Series X profile, 2560x1440, no DLSS, no frame generation, no RT.

Known limits

  • One scratch buffer per copy across families (pooled; not reused within a list).
  • The whole source subresource goes through the buffer, even for a small box.

Refs #3901, #3880.

**@⁠ShalakZ** on GitHub · 2026-11-30 15:41 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080) `ShalakZ:pr/twin-family-buffer` → `main` · +526 −8 · 2 files · 1 commits · closed without merging Fixes the `a host command list did not close (0x80070057)` crash named in #3901: the placed-twin `CopyTextureRegion` across format families (BC3_UNORM_SRGB levels into a BC7_UNORM_SRGB twin; `placed_twins` matches block size only). ## What it changes `twin_plan` / `twin_record` in `list.rs` choose the route for each twin, comparing host formats: - **same family**, **another element size or block width** (e.g. a raw R32G32B32A32 source of a BC texture, which D3D12 allows), or **depth with stencil / 2x1-block formats** (laid out per plane): the title's copy, as before; - **a buffer source**: its footprint tagged with the twin's format; - **a texture source**: through a pooled device-local buffer (`HostList::copy_scratch`, from `uav_pool`, returned once the list has run). The whole source subresource goes out in the source's format (`GetCopyableFootprints`); then the title's box of it goes into the twin, at the title's place, in the twin's format. A box that ends at the edge of a small BC level (`right = 2` on a 2x2 level) is rounded to whole blocks on the footprint. The buffer is left `COMMON`; - across families with no buffer or no layout: left out (`twin_copy_left_out`), never recorded as it is. Counted in `TWIN_ACROSS`; an info line at powers of two. Compared with #3976 (same buffer route): this also covers boxed copies and copies placed elsewhere in a level, rather than leaving them out. It also keeps the title's copy whenever the block width differs, so a raw footprint is never retagged (the case found in review on #3976). #3979 skips all cross-family twins. This comparison comes from reading their diffs; I have not run them. ## How it was tested - **Unit tests (RTX 4080, driver 621.40), on this branch (`main` c71899d9 + this commit):** - `twin_copies_across_bc_families_close_and_land_bit_for_bit` records through `twin_plan`/`twin_record`: every BC3 level into a BC7 twin down to 1x1, a 32x32 box placed at 128,64, a buffer source, and the 2x2 and 1x1 levels with boxes of their size. The list closes and the twins read back bit for bit equal to the source blocks. With `twin_plan` forced to the direct copy, or without the block rounding, `Close` fails with 0x80070057. - `twin_plan_keeps_the_title_copy_where_d3d12_allows_it`: a raw footprint into a BC twin, and planar pairs, stay direct. - `a_copy_between_bc_families_fails_close` keeps the rule itself. - **`cargo test -p victory-gpu`** on this branch: 1116 passed, 2 failed, 66 ignored. - The two failures are `shader_cache::tests::every_switch_of_the_translator_is_in_the_key` (`VICTORY_ORACLE_RUNS` no longer read) and `list::thin::tests::bindings_record_no_work` (47 vs 49). Both also fail on bare `main` c71899d9. - `main`'s test target does not compile at c71899d9 (`card_pass` gained a 6th argument; two calls in host.rs tests pass 5). For these runs I added `[0; 3]` locally; that patch is not in this PR. - `cargo clippy -p victory-gpu --lib` (default and `--all-features`) and `--tests`: no warnings in the changed lines. - **In game:** on v2026.11.29.05 plus this change (before `host_target`; on current `main` only the unit tests ran). RTX 4080, 2560x1440, DLSS off, RT off. - Diagnostics + DRED, 420 s: cross-family twin copies went through a buffer at 69 s and 200 s, and the run survived. - Release, 360 s, with more switches on: they went through at 69 s, and the run survived. - Before the fix, the same scripted start failed `Close` at 199-206 s in 11 runs and at 69-72 s in 2. - **GPU and profile:** RTX 4080, Series X profile, 2560x1440, no DLSS, no frame generation, no RT. ## Known limits - One scratch buffer per copy across families (pooled; not reused within a list). - The whole source subresource goes through the buffer, even for a small box. Refs #3901, #3880.
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 copy between
format families at Close (E_INVALIDARG, "a host command list did not
close"): #3901 named those copies (BC3_UNORM_SRGB levels into a
BC7_UNORM_SRGB twin).

twin_plan picks the route per twin, on host formats:
- same family, or elements of another size or block width (a raw
  R32G32B32A32 source of a BC texture, which D3D12 allows), or depth with
  stencil / 2x1-block formats (laid out per plane): the title's copy;
- a buffer source: its footprint tagged with the twin's format;
- a texture source: through a pooled buffer (HostList::copy_scratch): the
  whole source subresource out in the source's format (GetCopyableFootprints),
  then the title's box of it into the twin at the title's place, in the
  twin's format. A box ending at the edge of a small BC level (2 of 2x2) is
  rounded to whole blocks on the footprint (Close refuses it otherwise).
  The buffer is left common and goes back to the pool once the list ran;
- across families with no buffer or no layout: left out
  (twin_copy_left_out), never recorded as it is.
Counted in TWIN_ACROSS, logged at powers of two.

Tests (RTX 4080): twin_copies_across_bc_families_close_and_land_bit_for_bit
records through twin_plan/twin_record every BC3 level into a BC7 twin down
to 1x1, a 32x32 box placed at 128,64, a buffer source, and the 2x2 and 1x1
levels with boxes of their size; the list closes and the twins hold the
source's blocks bit for bit. With twin_plan forced to the direct copy, or
without the block rounding, Close fails (0x80070057).
a_copy_between_bc_families_fails_close keeps the rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01C98J7NWqaasuwGyScze2uo
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 15:47:23 +00:00
github-bot force-pushed github-bot/gh-4080 from 2f0522a777 to eb981a6dee 2026-11-30 18:10:28 +00:00 Compare
Author
Owner

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

In-game check on current main (c71899d9) with this change:

  • Tree: c71899d9 merged with this fix plus our local switches. The placed-twin loop is this PR's, line for line, apart from a diagnostics-only note.
  • Setup: RTX 4080, driver 621.40, 2560x1440, release build, DLSS off, RT off. Two runs of 360 s from the same scripted start.
  • Copies across format families, all through a buffer:
    • run 1 at 200 s: DXGI 78 -> 99, then 99 -> 83;
    • run 2 at 330 s: 78 -> 98 and 78 -> 99.
  • Result: no list failed to close; both runs survived. Before the fix, the same start failed Close at 199-206 s in 11 runs.

So the host_target level mapping and the family route work together on main, in game as well as in the unit tests.

**@⁠ShalakZ** on GitHub · 2026-11-30 17:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080#issuecomment-7286386028) In-game check on current `main` (c71899d9) with this change: - **Tree:** c71899d9 merged with this fix plus our local switches. The placed-twin loop is this PR's, line for line, apart from a diagnostics-only note. - **Setup:** RTX 4080, driver 621.40, 2560x1440, release build, DLSS off, RT off. Two runs of 360 s from the same scripted start. - **Copies across format families**, all through a buffer: - run 1 at 200 s: DXGI 78 -> 99, then 99 -> 83; - run 2 at 330 s: 78 -> 98 and 78 -> 99. - **Result:** no list failed to close; both runs survived. Before the fix, the same start failed `Close` at 199-206 s in 11 runs. So the `host_target` level mapping and the family route work together on main, in game as well as in the unit tests.
Author
Owner

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

Crash counts from a second machine (RTX 5070 Ti, i7-13700K, 32 GB RAM; RT on, DLSS Quality, frame generation off; scripts/bench.ps1, 30-210 s after the world starts, same save for every run).

Before a family check, runs that reached the world and ended with a host command list did not close (The parameter is incorrect. (0x80070057)):

build crashed
v2026.11.29.04 / .05 2 of 8
Broadside-RT rt-test-13 (based on 11.29) 3 of 11
v2026.11.28.03 (no placed_twins) 0 of 3
FoxHound v0.8.2 (no placed_twins) 0 of 3

With a family check equivalent to #3979 (destination family vs twin family in copy_texture_region, the twin left out) on v2026.11.30.01: 0 of 7, about 27-28 fps median and about 100 ms p99.

The run with logging (run 7; runs 1-6 had the same check without the log line) said 16 times, within 9 s, destination_family=Some(76) twin_family=Some(97): BC3_TYPELESS into BC7_TYPELESS, on 2 twin textures. That matches the case resource::placed_twins' doc describes (a BC3 texture copied into, a BC7 view over the same memory that is sampled). If that copy is what fills the sampled view, skipping it can leave that view stale, so a route that keeps the copy, like this PR's buffer bounce, looks preferable to leaving it out. I have not run this PR itself, and the skipping runs were not checked on screen for a stale texture.

**@⁠ozigalko** on GitHub · 2026-11-30 17:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080#issuecomment-7286421606) Crash counts from a second machine (RTX 5070 Ti, i7-13700K, 32 GB RAM; RT on, DLSS Quality, frame generation off; `scripts/bench.ps1`, 30-210 s after the world starts, same save for every run). **Before a family check**, runs that reached the world and ended with `a host command list did not close (The parameter is incorrect. (0x80070057))`: | build | crashed | |---|---| | v2026.11.29.04 / .05 | 2 of 8 | | Broadside-RT rt-test-13 (based on 11.29) | 3 of 11 | | v2026.11.28.03 (no `placed_twins`) | 0 of 3 | | FoxHound v0.8.2 (no `placed_twins`) | 0 of 3 | **With a family check equivalent to #3979** (destination family vs twin family in `copy_texture_region`, the twin left out) on v2026.11.30.01: **0 of 7**, about 27-28 fps median and about 100 ms p99. The run with logging (run 7; runs 1-6 had the same check without the log line) said 16 times, within 9 s, `destination_family=Some(76) twin_family=Some(97)`: BC3_TYPELESS into BC7_TYPELESS, on 2 twin textures. That matches the case `resource::placed_twins`' doc describes (a BC3 texture copied into, a BC7 view over the same memory that is sampled). If that copy is what fills the sampled view, skipping it can leave that view stale, so a route that keeps the copy, like this PR's buffer bounce, looks preferable to leaving it out. I have not run this PR itself, and the skipping runs were not checked on screen for a stale texture.
Author
Owner

@⁠IRennie74 on GitHub · 2026-11-30 18:22 UTC · original · edited 2026-11-30 18:44 UTC

One more rig with the same signature, in case it helps weigh this. Ryzen 5 5600X, RTX 3060 12 GB, Series S at 960x540, DLSS Performance, walking route through the cell after the opening cutscene: 3 of 18 walking runs ended with a host command list did not close (E_INVALIDARG), each with texture memory near full.

We had suspected two shader-visible view heaps in one SetDescriptorHeaps, because WARP gives that code for them, and added a per-type check in draw.rs's sound_heaps. In 6 walking runs after it there was no abort, but its warning never printed. So that was not the cause we saw, and 6 clean runs are within chance at the earlier 1-in-6 rate. A cross-family placed-twin copy fits the symptom better. This PR is the obvious candidate on our side too, but we have not run it yet.

On the diff: the copy_resource twin path already requires the same family (family(pc_format(a[8])) == family(pc_format(b[8])) before its CopyResource), so region copies are the only route left, and that is the one this covers. #4040 changes that whole-copy path and inherits the same family check, so the two should not step on each other.

**@⁠IRennie74** on GitHub · 2026-11-30 18:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080#issuecomment-7287767199) · edited 2026-11-30 18:44 UTC One more rig with the same signature, in case it helps weigh this. Ryzen 5 5600X, RTX 3060 12 GB, Series S at 960x540, DLSS Performance, walking route through the cell after the opening cutscene: 3 of 18 walking runs ended with `a host command list did not close` (`E_INVALIDARG`), each with texture memory near full. We had suspected two shader-visible view heaps in one `SetDescriptorHeaps`, because WARP gives that code for them, and added a per-type check in `draw.rs`'s `sound_heaps`. In 6 walking runs after it there was no abort, but its warning never printed. So that was not the cause we saw, and 6 clean runs are within chance at the earlier 1-in-6 rate. A cross-family placed-twin copy fits the symptom better. This PR is the obvious candidate on our side too, but we have not run it yet. On the diff: the `copy_resource` twin path already requires the same family (`family(pc_format(a[8])) == family(pc_format(b[8]))` before its `CopyResource`), so region copies are the only route left, and that is the one this covers. #4040 changes that whole-copy path and inherits the same family check, so the two should not step on each other.
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 19:29 UTC · original

Independent hardware check on another card: RTX 4060 8 GB, driver 621.14, Windows 11 26300. This PR's head merged cleanly into current main (e1251c31), then cargo test -p victory-gpu --lib twin_family_tests -- --test-threads=1:

BC3 -> BC7: Err(HRESULT(0x80070057)); BC3 -> BC3: Ok(())
test list::twin_family_tests::a_copy_between_bc_families_fails_close ... ok
test list::twin_family_tests::twin_copies_across_bc_families_close_and_land_bit_for_bit ... ok
test list::twin_family_tests::twin_plan_keeps_the_title_copy_where_d3d12_allows_it ... ok

So the RTX 4060 refuses the same cross-family copy at Close() with the same E_INVALIDARG, and the copy through a buffer lands bit for bit there too. That matches the open did not close (0x80070057) reports on RTX 4060 (#4246), RTX 5070 Ti (#4301) and #4319, and a 15-minute run of my own on an RTX 4060 that ended the same way. I've pointed those issues here.

AI-assisted with Claude Code.

**@⁠tyr0nsur** on GitHub · 2026-11-30 19:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080#issuecomment-7289482325) Independent hardware check on another card: **RTX 4060 8 GB**, driver 621.14, Windows 11 26300. This PR's head merged cleanly into current `main` (e1251c31), then `cargo test -p victory-gpu --lib twin_family_tests -- --test-threads=1`: ``` BC3 -> BC7: Err(HRESULT(0x80070057)); BC3 -> BC3: Ok(()) test list::twin_family_tests::a_copy_between_bc_families_fails_close ... ok test list::twin_family_tests::twin_copies_across_bc_families_close_and_land_bit_for_bit ... ok test list::twin_family_tests::twin_plan_keeps_the_title_copy_where_d3d12_allows_it ... ok ``` So the RTX 4060 refuses the same cross-family copy at `Close()` with the same `E_INVALIDARG`, and the copy through a buffer lands bit for bit there too. That matches the open `did not close (0x80070057)` reports on RTX 4060 (#4246), RTX 5070 Ti (#4301) and #4319, and a 15-minute run of my own on an RTX 4060 that ended the same way. I've pointed those issues here. AI-assisted with Claude Code.
Author
Owner

@⁠How-e on GitHub · 2026-12-01 02:11 UTC · original

I tested PR head eb981a6d applied to v2026.11.30.03 (e1251c31) on an NVIDIA GeForce RTX 4080 Laptop GPU, driver 617.14, running Windows 11 build 26300. The crash occurred at the end of the opening scene.

Gameplay results

  • Unpatched release build: Crashed 5m 14s after launch (4m 37s after the first presented frame) with 0x80070057 when closing the host command list.
  • Unpatched diagnostics build: Crashed 3m 29s after launch (3m 19s after the first presented frame). The D3D12 debug layer identified a CopyTextureRegion from BC3_TYPELESS to BC7_TYPELESS (id=874).
  • Patched diagnostics build: Got past the end of the opening scene. The log recorded at least four BC3_UNORM_SRGB → BC7_UNORM copies with through_a_buffer=true. The game continued for 5m 23s after the first logged buffered copy without the command-list error. I closed the window about 9 minutes after launch, and the process exited with code 0.

GPU regression tests

I ran the same BC3-to-BC7 copy cases on both builds. Before the patch, I adapted the PR’s fixture to use the original direct-copy path. The regression failed at Close() with 0x80070057, while the same-format BC3-to-BC3 control passed. With the patch applied, all three twin_family_tests passed on the laptop GPU. The buffered copy closed successfully, and GPU readback matched the source blocks bit for bit, including boxed copies, small mip levels, and a buffer source.

The patch resolved the opening-scene crash on my setup.

**@⁠How-e** on GitHub · 2026-12-01 02:11 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080#issuecomment-7298346488) I tested PR head `eb981a6d` applied to `v2026.11.30.03` (`e1251c31`) on an NVIDIA GeForce RTX 4080 Laptop GPU, driver 617.14, running Windows 11 build 26300. The crash occurred at the end of the opening scene. **Gameplay results** - **Unpatched release build:** Crashed **5m 14s after launch** (**4m 37s after the first presented frame**) with `0x80070057` when closing the host command list. - **Unpatched diagnostics build:** Crashed **3m 29s after launch** (**3m 19s after the first presented frame**). The D3D12 debug layer identified a `CopyTextureRegion` from `BC3_TYPELESS` to `BC7_TYPELESS` (`id=874`). - **Patched diagnostics build:** Got past the end of the opening scene. The log recorded at least four `BC3_UNORM_SRGB` → `BC7_UNORM` copies with `through_a_buffer=true`. The game continued for **5m 23s after the first logged buffered copy** without the command-list error. I closed the window about **9 minutes after launch**, and the process exited with code `0`. **GPU regression tests** I ran the same BC3-to-BC7 copy cases on both builds. Before the patch, I adapted the PR’s fixture to use the original direct-copy path. The regression failed at `Close()` with `0x80070057`, while the same-format BC3-to-BC3 control passed. With the patch applied, all three `twin_family_tests` passed on the laptop GPU. The buffered copy closed successfully, and GPU readback matched the source blocks bit for bit, including boxed copies, small mip levels, and a buffer source. The patch resolved the opening-scene crash on my setup.
Author
Owner

@⁠upipibi on GitHub · 2026-12-01 03:46 UTC · original

Review of #4080 (head eb981a6d) with an end-to-end test through the title's own copy: it closes the list, the D3D12 debug layer is quiet, and the code reads right to me. Synthetic only: no game files, no title run.

What the test does. It goes in where the title does, rather than calling twin_plan/twin_record. That makes it a check of the wiring this PR's tests don't reach: copy_texture_region, then resource::placed_twins, then host_list(list).close(). Two textures sit at one address: a 256x256 BC3_UNORM texture with nine levels and a BC7_UNORM view over it, both made with resource::texture_at. There is a BC3 source of the same shape elsewhere. The test copies each level of the source into the BC3 texture with the title's copy_texture_region, then closes the host list. The code is at the end.

RTX 3070, driver 621.40, Windows 11, debug test builds. Each tree is main 5fabb46e with that PR merged in (all three merge cleanly):

tree the test diagnostics build, VICTORY_D3D12_DEBUG=1 list::
main aborts: a host command list did not close (0x80070057) the debug layer names CopyTextureRegion: "The source format is BC3_TYPELESS and the destination format is BC7_TYPELESS"
main, VICTORY_PLACED_COPIED=0 closes
#4080 closes, all 9 twin copies made (0 left out) closes, no debug-layer message 30 passed, 0 failed
#3979 closes, 9 of 9 twin copies left out closes, no debug-layer message 28 passed, 0 failed
#3975 aborts: a host command list did not reset (0x80070057) the same aborts (this test is in list::)

The debug-layer line on main matches the in-game one in #3911 (and in the comments on #2914) word for word. So this one copy, made in a unit test, is the refused command from those reports.

Of the three mergeable PRs, #4080 is the one that fixes it.

  • #3979 avoids the crash by leaving the copy out. The BC7 view then keeps whatever it held before. That is the stale-texture risk ozigalko raised above.
  • #3975's recovery dies at its own self.reset(), as tyr0nsur, tillo88 and Lag0 reported on that PR. A list whose Close failed can't be Reset.

Code read.

  • The scratch buffer goes back to the pool by the same retired_uavs path as indirect_scratch, so no new lifetime is added.
  • Each half of the copy through the buffer names its own texture's format, and the buffer ends the list COMMON as copy_scratch requires.
  • Pairs that D3D12 already allows still take the direct copy: same family, a different element size or block width, and planar formats.

I didn't check the twin's bytes end to end. This PR's twin_copies_across_bc_families_close_and_land_bit_for_bit covers that, and two other cards have run it (RTX 4060, RTX 4080 Laptop).

If it's useful as a regression test for the title path, it goes in list.rs's mod tests:

/// A title copy into a BC3 texture that has a BC7 view placed over the same
/// memory (its placed twin) closes the host list.
#[cfg(windows)]
#[test]
fn a_copy_into_a_texture_with_a_bc7_twin_closes() {
    use windows_sys::Win32::System::Memory::{MEM_COMMIT, MEM_RESERVE, PAGE_READWRITE, VirtualAlloc};
    let null: This = std::ptr::null();
    if crate::host::host().is_none() {
        return;
    }
    // 256x256, nine levels; BC3_UNORM 77, BC7_UNORM 98.
    let desc = |format: u32| [3u32, 0, 0, 0, 256, 0, 256, 0x9_0001, format, 1, 0, 0x105, 0, 0];
    let (bc3, bc7) = (desc(77), desc(98));
    let bytes = crate::resource::placed_bytes(&bc3).expect("placed bytes");
    // SAFETY: memory of our own that stays.
    let alloc = || unsafe { VirtualAlloc(std::ptr::null(), bytes as usize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) } as u64;
    let (at, from_at) = (alloc(), alloc());
    assert!(at != 0 && from_at != 0);
    let dst = crate::resource::texture_at(at, &bc3).expect("BC3 texture");
    let _twin = crate::resource::texture_at(at, &bc7).expect("BC7 view over it");
    let src = crate::resource::texture_at(from_at, &bc3).expect("BC3 source");
    if crate::resource::placed_copied() {
        assert_eq!(crate::resource::placed_twins(dst).len(), 1, "the BC7 view is the BC3 texture's twin");
    }
    let mut allocator = null;
    assert_eq!(create_allocator(null, 0, &ALLOCATOR_IIDS[0], &mut allocator), S_OK);
    let mut list = null;
    assert_eq!(create_list(null, 0, 0, allocator, null, &LIST_IIDS[1], &mut list), S_OK);
    let at_sub = |resource: This, sub: u64| {
        // SAFETY: plain data.
        let mut l: CopyLocation = unsafe { std::mem::zeroed() };
        l.resource = resource;
        l.kind = 0;
        l.footprint.offset = sub;
        l
    };
    for level in 0..9u64 {
        copy_texture_region(list, &at_sub(dst, level), 0, 0, 0, &at_sub(src, level), std::ptr::null());
    }
    // Without the fix, `close` aborts the process through `host::fail`.
    host_list(list).expect("a host list").close();
}

(I ran it under another name and with a line that printed TWIN_COPIES_LEFT_OUT; otherwise it's the same.)

Tested with the help of Claude Code (Claude Opus 5.5).

**@⁠upipibi** on GitHub · 2026-12-01 03:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080#issuecomment-7300043416) Review of #4080 (head eb981a6d) with an end-to-end test through the title's own copy: **it closes the list, the D3D12 debug layer is quiet, and the code reads right to me.** Synthetic only: no game files, no title run. **What the test does.** It goes in where the title does, rather than calling `twin_plan`/`twin_record`. That makes it a check of the wiring this PR's tests don't reach: `copy_texture_region`, then `resource::placed_twins`, then `host_list(list).close()`. Two textures sit at one address: a 256x256 BC3_UNORM texture with nine levels and a BC7_UNORM view over it, both made with `resource::texture_at`. There is a BC3 source of the same shape elsewhere. The test copies each level of the source into the BC3 texture with the title's `copy_texture_region`, then closes the host list. The code is at the end. RTX 3070, driver 621.40, Windows 11, debug test builds. Each tree is `main` 5fabb46e with that PR merged in (all three merge cleanly): | tree | the test | diagnostics build, `VICTORY_D3D12_DEBUG=1` | `list::` | |---|---|---|---| | `main` | **aborts**: `a host command list did not close (0x80070057)` | the debug layer names `CopyTextureRegion`: "The source format is BC3_TYPELESS and the destination format is BC7_TYPELESS" | | | `main`, `VICTORY_PLACED_COPIED=0` | closes | | | | **#4080** | **closes**, all 9 twin copies made (0 left out) | closes, no debug-layer message | 30 passed, 0 failed | | #3979 | closes, **9 of 9 twin copies left out** | closes, no debug-layer message | 28 passed, 0 failed | | #3975 | **aborts**: `a host command list did not reset (0x80070057)` | the same | aborts (this test is in `list::`) | The debug-layer line on `main` matches the in-game one in #3911 (and in the comments on #2914) word for word. So this one copy, made in a unit test, is the refused command from those reports. **Of the three mergeable PRs, #4080 is the one that fixes it.** - #3979 avoids the crash by leaving the copy out. The BC7 view then keeps whatever it held before. That is the stale-texture risk ozigalko raised above. - #3975's recovery dies at its own `self.reset()`, as tyr0nsur, tillo88 and Lag0 reported on that PR. A list whose `Close` failed can't be `Reset`. **Code read.** - The scratch buffer goes back to the pool by the same `retired_uavs` path as `indirect_scratch`, so no new lifetime is added. - Each half of the copy through the buffer names its own texture's format, and the buffer ends the list `COMMON` as `copy_scratch` requires. - Pairs that D3D12 already allows still take the direct copy: same family, a different element size or block width, and planar formats. I didn't check the twin's bytes end to end. This PR's `twin_copies_across_bc_families_close_and_land_bit_for_bit` covers that, and two other cards have run it (RTX 4060, RTX 4080 Laptop). If it's useful as a regression test for the title path, it goes in `list.rs`'s `mod tests`: ```rust /// A title copy into a BC3 texture that has a BC7 view placed over the same /// memory (its placed twin) closes the host list. #[cfg(windows)] #[test] fn a_copy_into_a_texture_with_a_bc7_twin_closes() { use windows_sys::Win32::System::Memory::{MEM_COMMIT, MEM_RESERVE, PAGE_READWRITE, VirtualAlloc}; let null: This = std::ptr::null(); if crate::host::host().is_none() { return; } // 256x256, nine levels; BC3_UNORM 77, BC7_UNORM 98. let desc = |format: u32| [3u32, 0, 0, 0, 256, 0, 256, 0x9_0001, format, 1, 0, 0x105, 0, 0]; let (bc3, bc7) = (desc(77), desc(98)); let bytes = crate::resource::placed_bytes(&bc3).expect("placed bytes"); // SAFETY: memory of our own that stays. let alloc = || unsafe { VirtualAlloc(std::ptr::null(), bytes as usize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) } as u64; let (at, from_at) = (alloc(), alloc()); assert!(at != 0 && from_at != 0); let dst = crate::resource::texture_at(at, &bc3).expect("BC3 texture"); let _twin = crate::resource::texture_at(at, &bc7).expect("BC7 view over it"); let src = crate::resource::texture_at(from_at, &bc3).expect("BC3 source"); if crate::resource::placed_copied() { assert_eq!(crate::resource::placed_twins(dst).len(), 1, "the BC7 view is the BC3 texture's twin"); } let mut allocator = null; assert_eq!(create_allocator(null, 0, &ALLOCATOR_IIDS[0], &mut allocator), S_OK); let mut list = null; assert_eq!(create_list(null, 0, 0, allocator, null, &LIST_IIDS[1], &mut list), S_OK); let at_sub = |resource: This, sub: u64| { // SAFETY: plain data. let mut l: CopyLocation = unsafe { std::mem::zeroed() }; l.resource = resource; l.kind = 0; l.footprint.offset = sub; l }; for level in 0..9u64 { copy_texture_region(list, &at_sub(dst, level), 0, 0, 0, &at_sub(src, level), std::ptr::null()); } // Without the fix, `close` aborts the process through `host::fail`. host_list(list).expect("a host list").close(); } ``` (I ran it under another name and with a line that printed `TWIN_COPIES_LEFT_OUT`; otherwise it's the same.) *Tested with the help of Claude Code (Claude Opus 5.5).*
Author
Owner

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

Crash and speed check of #4080 (head eb981a6d) 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
+ #4080 9 0

Base errors were a host command list did not close (0x80070057) (2) and relay: the device was lost ... (0x887A0006) (3). With #4080 all 9 runs went past the cut and ran the whole ~6 min route. At the base rate (5 of 27), 0 of 9 by chance is about 16%, so on its own this is a good sign, not proof. Together with #4522, #3043 and #3979 (same kind of fix, same release), 0 of 30 runs stopped against 5 of 27 on the bare release, which would happen by chance about 2% of the time (Fisher's exact test).

The PR's own line shows up in 1 of the 9 runs: a copy into a placed twin of another format family (#452) copies=1 source=78 twin=98 through_a_buffer=true (then copies=2 with twin=99), 4 lines at +2:37. That is the second point where base runs fail, and that run went on to the end. In the other 8 runs the line never appears, so the cross-family twin copy did not happen in those runs.

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
+ #4080 7 32.13 (31.93–32.39) 20.23 6.31 46.9 59.9

+0.3% fps, inside the bench's ~2% run-to-run spread: no measurable difference in speed.

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/4080#issuecomment-7310671925) Crash and speed check of #4080 (head eb981a6d) 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 | | + #4080 | 9 | 0 | Base errors were `a host command list did not close (0x80070057)` (2) and `relay: the device was lost ... (0x887A0006)` (3). With #4080 all 9 runs went past the cut and ran the whole ~6 min route. At the base rate (5 of 27), 0 of 9 by chance is about 16%, so on its own this is a good sign, not proof. Together with #4522, #3043 and #3979 (same kind of fix, same release), 0 of 30 runs stopped against 5 of 27 on the bare release, which would happen by chance about 2% of the time (Fisher's exact test). The PR's own line shows up in 1 of the 9 runs: `a copy into a placed twin of another format family (#452) copies=1 source=78 twin=98 through_a_buffer=true` (then copies=2 with twin=99), 4 lines at +2:37. That is the second point where base runs fail, and that run went on to the end. In the other 8 runs the line never appears, so the cross-family twin copy did not happen in those runs. **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 | | + #4080 | 7 | 32.13 (31.93–32.39) | 20.23 | 6.31 | 46.9 | 59.9 | +0.3% fps, inside the bench's ~2% run-to-run spread: no measurable difference in speed. 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

@⁠ShalakZ on GitHub · 2026-12-01 15:14 UTC · original

Thanks everyone for testing this. That's way more coverage than I could get on one machine: the 4060, How-e's 4080 Laptop on .03, upipibi's end-to-end test on a 3070, and tillo88's 0/9 vs 5/27 on a 5070 Ti with no change in fps.

@⁠upipibi nice test. Going in through the title's own copy_texture_region is exactly the part my tests don't cover. I'd like to add it to this PR, credited to you. I'll do that once I've run it here (my machine is tied up with other tests right now).

**@⁠ShalakZ** on GitHub · 2026-12-01 15:14 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080#issuecomment-7315591950) Thanks everyone for testing this. That's way more coverage than I could get on one machine: the 4060, How-e's 4080 Laptop on .03, upipibi's end-to-end test on a 3070, and tillo88's 0/9 vs 5/27 on a 5070 Ti with no change in fps. @⁠upipibi nice test. Going in through the title's own `copy_texture_region` is exactly the part my tests don't cover. I'd like to add it to this PR, credited to you. I'll do that once I've run it here (my machine is tied up with other tests right now).
Author
Owner

@⁠hrk1337 on GitHub · 2026-12-01 16:43 UTC · original

Test Report for #4080 (eb981a6d)

  • Build: v2026.11.30.03 + eb981a6d (#4080) merged on top (release build with the D3D12 debug layer off)
  • Setup: NVIDIA GeForce RTX 5080 (driver 621.40), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11

Background (#4934)

On unpatched v2026.11.30.03, the game was reproducibly crashing with 0x80070057 (E_INVALIDARG at host command list Close()) at the exact same checkpoint during the Day Release mission. Running a diagnostics build with VICTORY_D3D12_DEBUG=1 pinpointed the cause right before the crash: an incompatible CopyTextureRegion call from BC3_TYPELESS to BC7_TYPELESS.

Result with #4080

After merging eb981a6d on top of v2026.11.30.03 and loading the exact same save, the game passed the problematic Day Release checkpoint without crashing

**@⁠hrk1337** on GitHub · 2026-12-01 16:43 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080#issuecomment-7318120086) ### Test Report for #4080 (`eb981a6d`) - **Build:** `v2026.11.30.03` + `eb981a6d` (#4080) merged on top (**release build with the D3D12 debug layer off**) - **Setup:** NVIDIA GeForce RTX 5080 (driver 621.40), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11 #### Background (#4934) On unpatched `v2026.11.30.03`, the game was reproducibly crashing with `0x80070057` (`E_INVALIDARG` at host command list `Close()`) at the exact same checkpoint during the **Day Release** mission. Running a diagnostics build with `VICTORY_D3D12_DEBUG=1` pinpointed the cause right before the crash: an incompatible `CopyTextureRegion` call from `BC3_TYPELESS` to `BC7_TYPELESS`. #### Result with #4080 After merging `eb981a6d` on top of `v2026.11.30.03` and loading the exact same save, **the game passed the problematic Day Release checkpoint without crashing**
github-bot closed this pull request 2026-12-01 18:50:44 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:46 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:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4080#issuecomment-7321525275) 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

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