GPU: cache alias-copy footprint plans #1886
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1888"
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 Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-25T00:06:38Z.
Summary
AliasScratch/ALIAS_SCRATCHscratch buffer retention so zero GPU memory is retained between copies).D3D12_RESOURCE_DESCcopyable footprint plans in a bounded mutex-guardedAliasPlanCache(ALIAS_PLANS, cap256entries) keyed by(desc_key(da), desc_key(db)), storingOption<Arc<AliasPlan>>(crates/victory-gpu/src/texture.rs). Compatible and incompatible (n == 0/total == 0) pairs skip repeatedGetCopyableFootprintsCOM calls andVecallocations without holding the mutex across COM calls.alias_copy_inallocating a per-copyDEFAULT-heap buffer viahost.default_buffer(plan.total)and holding it inlist.keep(&buffer)as onmain.crates/victory-gpu/src/texture.rs:subresource_len_stays_inside_staging_total,committed_rejects_overflow_and_noaccess_pages,alias_plan_caches_compatible_and_incompatible_pairs,footprint_span_computes_exact_subresource_byte_extent, andalias_copy_caches_plans_and_copies_bytes(R32_UINT -> R8G8B8A8_UNORMandR32G32_UINT -> BC1_UNORMacross lists/submissions with plan cache reuse and D3D12 debug layer check).Verification
All checks ran after the final edit (
f6323bc):cargo run -p xtask --locked -- policy:asset policy: 191 files okcargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)cargo test -p victory-gpu --lib --locked texture::tests -- --test-threads=1(AMD Radeon RX 7600):5 passed; 0 failedVICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib --locked texture::tests -- --test-threads=1(AMD Radeon RX 7600 + D3D12 Debug):5 passed; 0 failedVICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib --locked texture::tests -- --test-threads=1(WARP + D3D12 Debug):5 passed; 0 failedAI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T00:32:45Z.
Review: COMMENTED
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Alias-copy footprint plans cached + temporary copy buffers pooled: allocation caching on the copy path.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:37:41Z.
Automated triage for the maintainers.
Merge candidate (recommend a look).
f6323bctakes the second option from the last triage: the plan cache alone, with no GPU memory kept between copies. Incrates/victory-gpu/src/texture.rs,alias_copyasksAliasPlanCache::get_or_computefor the pair's footprints. The cache holds up to 256(desc, desc)pairs, is cleared when full, caches incompatible pairs asNone, and does not hold its lock acrossGetCopyableFootprints. Each copy still makes its owndefault_bufferandlist.keeps it, as onmain.What I checked:
DescKeycovers everyD3D12_RESOURCE_DESCfield that affects footprints exceptAlignment, whichGetCopyableFootprintsdoes not use.compute_alias_planismain's, plus guards for theu64::MAX/u32::MAXfailure values.footprint_span), not toda's whole total. That is smaller or equal, and still covers both copies.For the maintainer: what this saves is two
GetCopyableFootprintscalls and theirVecs per alias copy, on the CPU. The in-world run in the thread found no measurable difference. It is correct and small in production code (about 200 lines, plus about 480 lines of tests), but the gain is unmeasured.CI: passing (
check).Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-25T03:06:18Z.
Rebased onto
origin/main(940d32f, new headc2f3417), resolving the merge conflict incrates/victory-gpu/src/texture.rs:#[cfg(test)] mod tests(subresource_len_stays_inside_staging_totalandcommitted_rejects_overflow_and_noaccess_pages) alongside #1888's alias-copy helpers and tests in a singlemod testsblock.Re-verified on
c2f3417(Windows MSVC):cargo run -p xtask -- policy --staged:asset policy: 1 files okcargo clippy --workspace --all-targets -- -D warnings&--all-features: cleancargo test -p victory-gpu --locked texture(default &--all-features): 12 passed, 0 failed, 1 ignoredcargo test --workspace --locked: 0 failures across all workspace crates (CIcheckalso green)Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-25T04:04:50Z.
Addressed the two triage items on
gpu/alias-copy-pool(rebased onorigin/main940d32f, new head2054d42):1. Byte-bounded pool + idle TTL (#1633 host memory)
crates/victory-gpu/src/texture.rswith a 16 MiB total retained byte cap (ALIAS_BUFFER_POOL_MAX_BYTES = 16 * 1024 * 1024) using LRU eviction (last_used) whenever returning a buffer would exceed the budget.main's immediate release once the list resets).ALIAS_BUFFER_IDLE_TTL) checked onacquire/releaseand swept onHost's 1 s frame tick viatrim_idle_alias_buffers()incrates/victory-gpu/src/host.rs, dropping expired COM resources outside the pool mutex so unused buffers return to D3D12 instead of lingering for the process lifetime.pooled_alias_buffer_enforces_byte_budget_lru_and_idle_ttlcovering total-byte LRU eviction, oversized-buffer bypass, and deterministic TTL expiration.2. Tightened diff + synthetic D3D12 benchmark
alias_copy_inback tomain's compact layout (non-test production diff acrosstexture.rsandhost.rsis ~300 lines; the remaining diff is unit/GPU tests and the benchmark).texture::tests::bench_alias_copy_uncached_vs_pooled(#[ignore]) comparingmain's uncached path (GetCopyableFootprints+Host::default_buffer+list.keepper copy) against cached plan + pooled buffer over 200 copies on this host's D3D12 device (cargo test --release -p victory-gpu --lib texture::tests::bench_alias_copy_uncached_vs_pooled -- --ignored --nocapture):64x64 R32_UINT->RGBA8: uncached150.37 ms(751.8 us/copy,footprints=400,default_buffer=200) vs pooled2.43 ms(12.2 us/copy,footprints=2,default_buffer=1) — 61.81x1024x1024 R32_UINT->RGBA8: uncached192.57 ms(962.9 us/copy,footprints=400,default_buffer=200) vs pooled2.45 ms(12.3 us/copy,footprints=2,default_buffer=1) — 78.52x512x512 R32G32_UINT->BC1: uncached156.62 ms(783.1 us/copy,footprints=400,default_buffer=200) vs pooled2.18 ms(10.9 us/copy,footprints=2,default_buffer=1) — 71.90xALIAS_COPIES/frame and frame-time measurement on a real title run remains open for someone with the title.Verification (
2054d42, Windows MSVC)cargo run -p xtask -- policy --staged: passed (2 files ok)cargo clippy --workspace --all-targets --locked -- -D warnings&--all-features: cleancargo test -p victory-gpu --locked texture(default &--all-features): 13 passed, 0 failed, 2 ignoredVICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked texture -- --test-threads=1: 13 passed, 0 failed, 2 ignoredcargo test --workspace --locked: all workspace crates passed (0 failures;victory-gpu: 148 passed, 0 failed, 3 ignored)Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T06:05:42Z.
Ran this in the game: Grand Theft Auto VI in the world, RTX 5080, Linux, proton-cachyos 11.0 with vkd3d-proton 3.2.0. I compared
mainplus a few NVIDIA/Wine fixes with and without this PR, back to back.Host::default_buffercalls fromtexture.rswith a diagnostics counter. In the world it was about 46–62 new buffers per second with the PR and about 44–84 without it. The ranges overlap and move with the scene, so I can't say how much the pool catches in this world. If it helps, I can rerun with a counter of pool hits and misses (cap reached vs size rule).Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-25T21:57:58Z.
Rebased onto
origin/main(61bfc77, new headbf6787e), resolving the merge conflicts incrates/victory-gpu/src/texture.rs:alias_copy_inandalias_copy_copies_bytes_and_reuses_pooled_buffer_across_submissions(andbench_alias_copy_uncached_vs_pooled) for upstream changes:host_writestracking (f68442f) and ownedID3D12Resourcereturned fromhost_resource(69d1e8e).@desplmfao Thank you for benchmarking this in-world on GTA VI / RTX 5080! If you happen to run another comparison, a breakdown of alias-copy pool hits vs. misses (empty pool / size-ratio mismatch / >16 MiB bypass / idle-TTL eviction) would be super helpful to see whether the pool sees hits or if most allocations in
texture.rscome from non-aliasHost::default_bufferpaths.Verification (
bf6787e)cargo run -p xtask -- policy->186 files okcargo clippy -p victory-gpu --all-targets --locked -- -D warnings&--all-features-> cleancargo test -p victory-gpu --lib --locked -- texture::tests --test-threads=1->7 passed; 0 failed; 1 ignoredVICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib --locked -- texture::tests --test-threads=1->7 passed; 0 failed; 1 ignored[PR #1888] GPU: cache alias-copy footprint plans and pool temporary copy buffersto [PR #1888] GPU: cache alias-copy footprint plansImported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-26T07:48:28Z.
Updated
f6323bcontomain(63bcca4) and reduced this PR toAliasPlanCachealone as suggested during triage:AliasScratch/ALIAS_SCRATCHso zero GPU scratch memory is retained between copies (alias_copy_inuses per-copyhost.default_buffer(plan.total)+list.keep(&buffer)as onmain).Re-verified after the final edit on Windows 11 / AMD Radeon RX 7600 and WARP:
cargo run -p xtask --locked -- policy:191 files okcargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): cleancargo test -p victory-gpu --lib --locked texture::tests -- --test-threads=1(RX 7600):5 passed; 0 failedVICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib --locked texture::tests -- --test-threads=1(RX 7600 + Debug):5 passed; 0 failedVICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib --locked texture::tests -- --test-threads=1(WARP + Debug):5 passed; 0 failedAI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T11:39:31Z.
Review: APPROVED
Reviewed
f6323bcc. Trimming the PR down toAliasPlanCachealone is clean and self-contained:DescKeycaptures everyD3D12_RESOURCE_DESCfield that affectsGetCopyableFootprints, the cache is bounded (256entries), caches both compatible plans and incompatible (None) pairs, and never holds its mutex across COM calls.compute_alias_planpreservesmain's subresource compatibility check while guardingu64::MAX/u32::MAXfailure sentinels, andfootprint_spancomputes the exact max byte extent across bothfaandfbfor thencopied subresources.alias_copy_inretainsmain's per-copyhost.default_buffer(plan.total)+list.keep(&buffer)lifetime (zero GPU memory retained between copies) and incrementsALIAS_COPIESonly when a copy is actually recorded.Verified locally on Windows 11 with RTX 5090 and WARP (
VICTORY_D3D12_WARP=1) underVICTORY_D3D12_DEBUG=1:cargo xtask policy(191 files ok) andcargo clippy -p victory-gpu --tests -- -D warnings(default and--all-features): clean.texture::tests5/5,draw::tests20/20 passed.VICTORY_D3D12_DEBUG=1(--features diagnostics):texture::tests5/5 passed with zero Debug Layer errors.VICTORY_D3D12_DEBUG=1(--features diagnostics):texture::tests5/5 passed with zero Debug Layer errors.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.