GPU: release unused depth-twin scratch buffers via Weak cache and keep 1 spare placement heap #3454
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3454"
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 Luislariosss on 2026-11-27T03:09:02Z.
Summary
Reclaims idle D3D12
DEFAULT-heap memory from depth-twin scratch buffers and spare texture-placement heaps:twin.rs):SCRATCHpreviously held strongID3D12Resourcereferences for every power-of-two size class ever created, keeping all scratch buffers alive for the lifetime of the process even after the twins using them were destroyed. StoringWeak<SharedScratch>inSCRATCHandArc<SharedScratch>onTwinpreserves full sharing among live twins of the same size class while automatically releasing theID3D12Resourceonce the lastTwinreferencing it drops. Buffer creation and any duplicate drop also run outsideSCRATCH.lock().placement.rs): lowerSPAREfrom2(128 MiB of idle 64 MiBDEFAULTheaps) to1(64 MiB), returning an extra 64 MiB once textures are evicted while keeping one warm heap to avoid churn at a heap boundary.Validation
cargo test -p victory-gpu --lib -- twin:: placement::: 5/5 passed (including newshared_scratch_reuses_live_buffer_and_releases_when_last_owner_drops).cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics): clean.cargo xtask policy: 191 files ok.Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-27T03:16:59Z.
Note: the only CI failure on run \45932472460\ (231/232 passed) is the unrelated timing-sensitive test \ictory-gpu::frame::tests::waits_end_on_ticks_and_count_frames\ (this PR only touches \placement.rs\ and \ win.rs). Could a maintainer re-run the failed job?
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T03:27:24Z.
WARP test report (AI-assisted with Claude; synthetic tests only, no game files)
e746a9e1986f82e907c5d9a6388affa4e1c0ea7a, base:origin/main@63bcca4(this PR's merge base)VICTORY_WARP=1,VICTORY_D3D12_WARP=1, adapter vendor 0x1414 / software flag), DXIL validatordxil.dllfrom the Windows SDK 10.0.26100VICTORY_D3D12_WARPis only honored with--features diagnostics(host.rscreate()); without itcargo test -p victory-gpu --libpicks the hardware GPU. I ran with--features diagnostics.cargo test -p victory-gpu --lib --locked --features diagnostics: 247 passed, 0 failed, 1 ignored (base: 246/0/1; +1 istwin::tests::shared_scratch_reuses_live_buffer_and_releases_when_last_owner_drops, which passes with a WARP device)waits_end_on_ticks_and_count_framespassed on base and on this head here, so it looks like the timing flake mentioned in the CI note (not caused by this change). I did not re-run clippy.Review: no failure found, one point to check. Before, the shared scratch buffer lived for the whole process, so no submission could lose it. Now the
ID3D12Resourceis released as soon as the lastTwindrops. If a recorded or running list still copies through it, that is a use-after-release unless the owningResourceis already dropped only after the GPU is done;host::retireexists for this. I did not verify the drop timing ofResource::twin, so please confirm or retire the buffer. The test returns early when there is no host device; it did run here.Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T08:47:48Z.
NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head
e746a9e(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.shared_scratch_reuses_live_buffer_and_releases_when_last_owner_drops.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by reallyvibe on 2026-11-29T01:47:21Z.
On oni-swr's open point (scratch release versus in-flight work): the list keeps the scratch alive until its reset, with a test
oni-swr asked whether the scratch buffer can now be released while a recorded or running list still copies through it. Reading this head
e746a9e1, the ownership chain prevents that. The two paths that record a copy throughscratcharetwin::routeand the submission prelude. Both start from the list's own twin use:routecallsHostList::twin_use, which stores theArc<HostTexture>intwins, and the prelude takes its copies from that sametwinsmap. TheTwinlives inside thatHostTexture, and theArc<SharedScratch>inside theTwin.twinsis cleared only inHostList::reset, which runs after the list's last submission finished. So the scratch has the same lifetime guarantee as the twin's planes, which already drop with theTwinon main.I checked this with a test written against this head; you're welcome to add it:
With it, WARP
twin::+placement::pass 6/6.cargo build -p victory-gpu --libandcargo clippy -p victory-gpu --all-targets -- -D warnings(default and--all-features) are clean. Run alone, the test fails if either side is undone:shared_scratch_reuses_live_buffer_and_releases_when_last_owner_dropstwin_usedoes not keep the list's useWhat this validates, and what it doesn't: on WARP, the test shows the CPU-side ownership chain (list →
HostTexture→Twin→Arc<SharedScratch>) keeps the buffer alive untilreset. That the GPU has finished with the buffer by then rests onHostList::reset's contract (it runs only after the list's last submission finished) and onhost.executewaiting for that. I didn't run this on a hardware GPU, and the test doesn't observe GPU completion itself.This head merges cleanly with 11 open PRs on main
63bcca43that touchtwin.rsorplacement.rs. Only four of their diffs mention scratch, all through the unchangedscratch_bufferor in comments (#3409's and #3064's tests, doc lines in #2973 and #2969), and #2955 only rewordsSPARE's doc. #3447, #3360, #3266, #2919 and #1964 conflict textually.Windows 11, Ryzen 7 7445HS, WARP, synthetic data only.
AI-assisted (Claude Code).
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.