Repository navigation
GPU: release unused depth-twin scratch buffers via Weak cache and keep 1 spare placement heap - #3454
Luislariosss wants to merge 1 commit into
Conversation
…p 1 spare placement heap
|
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? |
|
WARP test report (AI-assisted with Claude; synthetic tests only, no game files)
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 |
|
NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head Tested
Not tested
AI use
|
|
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 I checked this with a test written against this head; you're welcome to add it: /// A twin's scratch buffer, released with its last twin, stays alive
/// while a list that recorded a copy through it holds the depth texture,
/// and goes once that list is reset (after its last submission finished).
#[test]
fn scratch_outlives_the_lists_that_copy_through_it() {
let Some(host) = host() else {
return; // no host GPU here
};
let desc = D3D12_RESOURCE_DESC {
Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D,
Width: 64,
Height: 64,
DepthOrArraySize: 1,
MipLevels: 1,
Format: DXGI_FORMAT_R16_TYPELESS,
SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
Flags: D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL,
..Default::default()
};
let heap = D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() };
let mut texture: Option<ID3D12Resource> = None;
// SAFETY: plain creation; our out pointer.
unsafe { host.device.CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_DEPTH_WRITE, None, &mut texture) }.unwrap();
let depth = Arc::new(HostTexture::new(texture.unwrap(), DEPTH_WRITE, Vec::new()));
let list = host.new_list().unwrap();
let scratch = {
let twin = depth.twin.get_or_init(|| make(53, &depth.texture)).as_ref().unwrap();
// The twin written, then the depth texture read: a copy through
// the scratch buffer is recorded into the list.
assert!(route(&list, &depth, twin, UNORDERED_ACCESS));
const PIXEL_SHADER_RESOURCE: u32 = 0x80;
assert!(!route(&list, &depth, twin, PIXEL_SHADER_RESOURCE));
Arc::downgrade(&twin.scratch)
};
drop(depth);
assert!(scratch.upgrade().is_some(), "the list holds the twin, so its scratch");
list.close();
host.execute(&[&list]);
assert!(scratch.upgrade().is_some(), "held until the list is reset");
list.reset();
assert!(scratch.upgrade().is_none(), "released with the list's last hold");
}With it, WARP
What this validates, and what it doesn't: on WARP, the test shows the CPU-side ownership chain (list → This head merges cleanly with 11 open PRs on main Windows 11, Ryzen 7 7445HS, WARP, synthetic data only. AI-assisted (Claude Code). |
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.