fix(list): legalise cross-family CopyTextureRegion and guard bounds/self-copy #4521
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4521"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Andreww2009 on 2026-11-30T21:50:29Z.
Why
copy_texture_region(crates/victory-gpu/src/list.rs) currently forwardsCopyTextureRegiondirectly to D3D12 for both the primary destination and everyplaced_twinsentry without validating format compatibility, twin self-copies, empty boxes, block alignment, or subresource/mip bounds. On PC D3D12 (unlike Xbox D3D12.X), recording an invalidCopyTextureRegionsilently poisons the open command list and aborts the session atHostList::close()withE_INVALIDARG (0x80070057).Concrete failure cases addressed:
BC3_TYPELESSinto aBC7_TYPELESSplaced twin —placed_twinsmatches by 16-byte block size only, #3901): forbidden directly by D3D12CopyTextureRegion.from.footprint.formatholdsdst's format (BC3), not the twin's format (BC7).source_boxcoordinates (e.g.2x2or1x1box on small BC mips) not rounded up to 4x4 block multiples.other == srcandhost_sub == src_sub), empty source boxes, unaligned BC destination offsets, or out-of-bounds subresource/region coordinates.Change
crates/victory-gpu/src/host.rs(HostList::copy_texture_via_bounce): records a legal 2-step GPU bounce through a pooledD3D12_HEAP_TYPE_DEFAULTscratch buffer fromuav_pool::take_uav(COMMON -> COPY_DEST -> COPY_SOURCE), sized to the exact copy region (not the whole subresource) and pushed ontobetween_uavssoHostList::close()transitions it back toCOMMONforUAV_SPAREreuse.crates/victory-gpu/src/list.rs(record_texture_copy,direct_texture_copy_compatible,scale_copy_extent,subresource_extent,typed_copy_format):CopyTextureRegionfor same-typeless-family pairs and D3D12's native 64/128-bit uncompressed <-> BC alias copies (R32G32B32A32_*<->BC2/3/5/6H/7,R32G32_*/R16G16B16A16_*<->BC1/4) with exact4xblock-to-texel bounds scaling (both texture and raw footprint sources).PlacedFootprint.formattodst's concrete typed format when copying a buffer footprint across equal-block-size families (BC3footprint ->BC7twin).BC3 -> BC7) throughHostList::copy_texture_via_bounce.source_box.right/bottomup to 4x4 multiples on sub-block BC mips (2x2,1x1), skips empty boxes and twin self-copies, and cleanly rejects out-of-bounds/incompatible copies with rate-limited diagnostics rather than failingClose()with0x80070057.crates/victory-gpu/src/resource.rs: exposesPlacedFootprintfields aspub(crate).list::copy_texture_region_tests): 4 unit + RTX 5080 hardware tests coveringBC3_UNORMfootprint ->BC7_TYPELESS,BC3_TYPELESS -> BC7_TYPELESSbounce (both full mip 0 and boxed2x2mip 3), directR32G32B32A32_UINT (4x4) -> BC7_TYPELESS (16x16), and invalid offset/subresource rejection — verified byte-for-byte with 0 D3D12 debug layer errors.Relation to #4080
#4080 solves the cross-BC-family
placed_twinscase (#3901) by bouncing the entire source subresource through a scratch buffer for twins only. This PR differs in three ways:UAV_SPAREbounce buffer to the exactsource_boxregion rather than copying the full subresource for small boxed copies.placed_twins.host_resourcelookup untouched (no overlap with #4126).Verification
Rust 1.98.1, pinned).VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked copy_texture_region_tests: 4 passed, 0 failed, 0 D3D12 debug layer errors, 0 warnings in modified files.cargo xtask policy --stagedclean (3 files ok),git diff --checkclean.v2026.11.30.03(base,VICTORY_SUBMIT_SPLIT=1, and 146 s DLSS FG 2x): 0 skipped copies, 00x80070057failures, 0 crashes (where the same scripted route previously hit0x80070057at +104.6 s without this fix).Original contribution under GPL-3.0-or-later.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by IRennie74 on 2026-11-30T22:39:08Z.
Some data on how often this abort happens on a low-end PC (Ryzen 5 5600X, RTX 3060 12 GB, Series S, walking route).
a host command list did not close(E_INVALIDARG) ended 3 of 18 walking runs on a base without #4080, each with texture memory near full. It did not appear in 11 runs of main + #4080 (+ #4040, #4226, #4199, #4255, #4027). That fits #4080 already covering the case that hits there. A guard on the primary copy, as here, is still worth having.Points on the diff:
placed_twinsloop ofcopy_texture_regionwith their own scratch-buffer bounce (#4080 throughtwin_planandcopy_scratch, or the title's buffer retagged; this one the box throughcopy_texture_via_bounce), so they will conflict. Building this on top of #4080, so that there is one bounce helper, would make it much easier to take both.record_texture_copyturns an invalid copy into a skipped one (awarn!for the first 16, then every 1024th). That is much better than losing the list, but a skipped copy leaves stale texels, which shows up as ghosting rather than a crash. A counter on the existing card-copies line (next totwin_copy_left_out's) would make those visible in normal logs, not only the first 16.returnnow comes before theplaced_twinsloop and thetwin_use/host_writtenbookkeeping. An empty box is a no-op for the twins too, so that is fine, but it also skips the diagnosticsnote_optext for that call.ClearUnorderedAccessViewhandler changes…to…(list.rs, hunk@@ -2235,7 +2596,7). It looks like the file went through a Latin-1 round trip, so it may be worth checking the rest of the file for the same thing.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Andreww2009 on 2026-12-01T09:46:30Z.
Thanks for the careful review and RTX 3060 testing, @IRennie74! Rebased onto latest
main(5fabb46e) and addressed all three points in the updated commit:crates/victory-gpu/src/list.rs(0 mojibake occurrences verified).self.note_op(...)ahead of the empty-box early return inCopyTextureRegion.COPIES_SKIPPEDalongsideTWIN_COPIES_LEFT_OUTandSELF_COPIESin the periodic host frame summary (texture copies left out: {} primary, {} twin, {} self).Re-tested on RTX 5080 Laptop (
2560x1440, Series X, DLSS Quality):cargo test -p victory-gpu --lib copy_texture_region(4/4underVICTORY_D3D12_DEBUG=1, 0 debug errors), 14 live runs including two 15-minute soaks (No-RT25,881frames and DXR 1.117,011frames) with00x80070057aborts and0 primarycopies left out.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tillo88 on 2026-12-01T12:10:05Z.
Crash and speed check of #4521 (head
987401cc) merged on top of v2026.11.30.03 (it applied there without conflicts), against the bare release on the same bench and route.Crashes (warm-up runs included for the count):
Base errors were
a host command list did not close (0x80070057)(2) andrelay: the device was lost ... (0x887A0006)(3). With #4521 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 this is not conclusive on its own. Together with #4080, #3043 and #3979 (same kind of fix, same release), 0 of 30 runs stopped against 5 of 27 on the bare release, about 2% by chance (Fisher's exact test).The PR logs nothing when it bounces a copy, and none of its skip/reject warnings appeared in any run, so the logs cannot show how often the bounce path ran or whether any copy was dropped.
Speed (measured runs only, warm-up excluded):
Same mean fps as the base: no measurable difference. One run was at 31.29 fps (below the slowest base run) and one had p95 54.2 ms; the other five had p95 46.6–47.4 ms, so the higher mean p95 comes from that single run.
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.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Andreww2009 on 2026-12-01T14:29:39Z.
Thanks for the RTX 5070 Ti replay verification, @tillo88 —
0/7vs5/27aborts with identical32.02fps is great confirmation!One quick note on logging: your test ran the earlier commit
987401cc. The latest rebased head (0745fad9, addressing @IRennie74's review) now exposesCOPIES_SKIPPEDon the periodic host frame summary line (texture copies left out: {} primary, {} twin, {} self) so any skipped primary copy is visible in normal release logs.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:38:51Z.
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