Repository navigation
D3D12.X: reclaim two-pass buffers on submit fence completion - #2815
coolpersonnn wants to merge 1 commit into
Conversation
|
Independent Windows/NVIDIA check of #2815 head
The same six named tests failed in both runs: two I also ran the opt-in Not tested: paired retail-title smoke, sustained world load, AMD/Intel, or the full workspace suite with heap windows enabled. These results alone do not establish merge readiness. AI use: Codex (GPT-6.2 Sol) ran the builds and tests, compared the exact base and head results, and drafted this report. |
|
Source review of
Not tested: no build or run on our side. AI use: Gemini (Antigravity) flagged it in a review. Claude Code (Claude Opus 5.5) checked it against the source at |
|
Retail-title A/B on RTX 3090 Ti (24 GiB, driver 621.40), Windows 10 19045, Ryzen 9 5950X, 32 GiB RAM, Agility v620 and rustc 1.98.1 MSVC release. This adds a world-transition sample to the existing smoke and suite reports. Tested I replayed
All five tracked allocator fences on the base were caught up from 100.506 s through the last sample. The base still held 998 MiB for allocator resets at 115.199 s. On the patched arm, all tracked fences were caught up at 156.646 s and live two-pass widths fell from 636 to 243 MiB between 153.694 and 157.585 s while the released buffer count increased from 23 to 46. The sampled fence-wait bucket was 0 MiB throughout. The counters show lower retention and more reuse in this run. Per-recording release order is covered by the existing unit tests. The base showed loading artwork followed by a black capture and stopped gracefully at 116.4 s on the physical RAM floor. The patched arm captured two very dark world frames with sparse horizon and building lights at 149.869 and 165.276 s. It returned Coverage limits The arms progressed through different content for different durations. This measures observed buffer retention and records a concrete later hang. It leaves the cause of the hang, matched in-world memory use, steady-state FPS and playability unresolved. AMD and other drivers were outside this replay. AI use OpenAI Codex (GPT-6 family) verified the archived build and source identity, ran and analyzed the two replays, and prepared this report. Focused regression for out-of-order fence notifications I tested the ordering case described in the earlier source review. The fixture attaches q0 mark 15, q1 mark 2, then a delayed q0 mark 10 to one recording. After retiring the recording and completing q1, the original code makes the buffer reusable with q0 only at 13. A local change that retains the highest mark per queue keeps it out of the reuse pool until q0 reaches 15. On exact head On this Windows 10 19045 host (RTX 3090 Ti, driver 621.40, rustc 1.98.1 MSVC), the broader bind filter returned 37 passed / 1 failed on clean head and 38 passed / 1 failed with the fix and new test, zero ignored and five capability-skip notices in each. The same This test reproduces a lifetime error. Its connection to the retail indirect hang remains unresolved. OpenAI Codex (GPT-6 family) added and ran the test and checked the local change. Patch for @coolpersonnn on 71b1a93. This applies the per-queue maximum and adds the deterministic regression described above. The allocator pool assigns monotonically increasing values under its lock. Bind notifications occur after it releases that lock. The regression also completes the other queue independently. Minimal fence-order fix and regressiondiff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs
index 53d11d6a..f0318fd8 100644
--- a/crates/xcl/src/hle/d3d12x/bind.rs
+++ b/crates/xcl/src/hle/d3d12x/bind.rs
@@ -130,8 +130,11 @@ pub(super) unsafe fn two_pass_submitted(queue: *mut c_void, fence: Option<&ID3D1
match fence {
Some(f) => {
if let Some(m) = s.res_marks.iter_mut().find(|(k, ..)| *k == q) {
- m.1 = f.clone();
- m.2 = value;
+ // Notifications run outside the lock that orders a queue's signals.
+ if value > m.2 {
+ m.1 = f.clone();
+ m.2 = value;
+ }
} else {
s.res_marks.push((q, f.clone(), value));
}
@@ -4374,6 +4377,45 @@ void ms(uint3 g : SV_GroupID) { o.Store((v * 16u + g.x) * 4u, rec.Load(g.x * 4u)
assert_eq!(held, vec![rec_raw]);
}
+ #[test]
+ fn late_submit_notification_keeps_the_newest_mark_on_each_queue() {
+ let _warp_guard = lock_warp_tests();
+ let Some(dev) = warp_device_for_test() else { return };
+ let key = dev.as_raw() as usize;
+ let ids = Box::new([0u8; 4]);
+ let list = ids.as_ptr() as *mut c_void;
+ let (q1, q2) = (
+ (ids.as_ptr() as usize + 1) as *mut c_void,
+ (ids.as_ptr() as usize + 2) as *mut c_void,
+ );
+ let allocator = ids.as_ptr() as usize + 3;
+ reset(list, allocator, 0);
+ let rec = unsafe { TwoPassBuf::make(&dev, RECORD_MIN, "record buffer") }.unwrap();
+ let rec_raw = rec.res.as_raw() as usize;
+ with(list, |s| s.res_buf = Some(rec));
+ track_two_pass_list(list as usize);
+
+ let (f1, v1) = make_test_fence(13);
+ let (f2, v2) = make_test_fence(1);
+ unsafe {
+ two_pass_submitted(q1, Some(&f1), 15, &[list]);
+ two_pass_submitted(q2, Some(&f2), 2, &[list]);
+ // alloc_pool publishes its fence marks after releasing the submit bookkeeping lock.
+ two_pass_submitted(q1, Some(&f1), 10, &[list]);
+ }
+ reset(list, 0, 0);
+ let blocked_on_both = take_free(key, RECORD_MIN, u64::MAX).is_none();
+ v2.store(2, Ordering::Release);
+ let early = take_free(key, RECORD_MIN, u64::MAX);
+ v1.store(15, Ordering::Release);
+ let after = take_free(key, RECORD_MIN, u64::MAX);
+ forget(list);
+
+ assert!(blocked_on_both);
+ assert!(early.is_none(), "an older notification must not release a resubmitted recording");
+ assert_eq!(after.map(|b| b.res.as_raw() as usize), Some(rec_raw));
+ }
+
#[test]
fn resubmitted_list_waits_for_all_queue_fences() {
let _warp_guard = lock_warp_tests(); |
|
Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2815 at Setup
Targeted RTX 4060 release unit & GPU tests (
|
| Metric (60 s quiet default-flags run) | nvidia-dev base (af2cecc4) |
PR #2815 (71b1a932) |
|---|---|---|
Frames shown / PresentX |
1547 / 1547 |
1496 / 1496 |
| Presents per 2 s (last 3) | 60 60 60 |
61 60 60 |
| Peak process commit | 16342 MB |
15504 MB |
End process commit (xcl.log) |
15009 MB |
15308 MB |
| Peak / end local VRAM | 6245 MB / 6182 MB |
6182 MB / 6182 MB |
| End non-local VRAM | 4749 MB |
4730 MB |
| Translated draws / dispatches (last log line) | 18,382 draws / 1,024 dispatches (0 skipped) |
18,640 draws / 1,024 dispatches (0 skipped) |
- Note:
xcl.logrecorded0two-pass buffer/draw log lines during this 60 s no-input menu/intro smoke, so the lower single-run transient peak commit (15504 MBvs16342 MB, while steady-state end commit was15308 MBvs15009 MBand end local VRAM was6182 MBon both) should not be attributed to two-pass buffer reclamation.
Base origin/nvidia-dev (af2cecc4):
xcl-smoke v1
commit: af2cecc40886a8682ecf3267f5328c6dc4b66ad7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1547 (PresentX 1547)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16342 MB
PR #2815 head (71b1a932):
xcl-smoke v1
commit: 71b1a93201456a655a5b23fe45348257c0658018
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1496 (PresentX 1496)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15504 MB
Limits of coverage
- Full workspace test suite was not run on
71b1a932(only the 4 new tests individually, 3 parallel passes ofhle::d3d12x::alloc_pool::,hle::d3d12x::bind::, and the paired 60 s default-flags smokes);hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heapskipped without opt-inXCL_HEAP_WINDOWS=1. - The 60 s no-input menu/intro smoke did not exercise heavy in-world two-pass draw streams or multi-threaded
alloc_poolsubmit/signal races; two-pass fence reclamation was exercised by the targeted unit tests rather than live world-load telemetry on this host. - Single discrete NVIDIA 8 GB GPU (
RTX 4060) on native Windows 11; no AMD, Intel, or Wine/Linux run on this host.
AI use
Ran the targeted release tests, paired quiet 60 s smoke runs, and xcl.log comparisons with assistance from Google Antigravity (Gemini 4 Neon); all test counts, memory figures, and smoke blocks were extracted directly from cargo test, xcl.log, and scripts/smoke.ps1 outputs.
|
Ran the two-pass fence-reclamation tests at System
Results
What this adds Not tested AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used. |
71b1a93 to
839df6d
Compare
|
Independent data point for this series, from a 10 GB card (RTX 3080). I measured a local version of the same idea (fence reclaim of retired two-pass buffers) before I saw this PR, so it's not your exact code.
|
Reclaim retired and reset two-pass record, batch, and argument scratch buffers when their recording's submit queue fences pass, without waiting for the owning command allocator to reset. Guard fence polling against device removal (`u64::MAX` / `FenceState::Removed`) so in-flight buffers are never returned to the reuse pool on a lost device, keep closed command lists' buffers intact across idle trims for Reset-less replay, and track upstream `batch_buf` allocations through the same submit fences. Part of xcl-dev#2688 Assisted-by: T3 Code / Antigravity (Gemini Pro Orchestrator Neon) Assisted-by: Codex (GPT-6.2 Sol)
|
Checked at AI use: Claude Code (Claude Opus 5.5) checked the source and wrote this. |
|
Focused follow-up on current head In I added two local fake-fence/WARP regressions: one presents removal before retirement, and one after the buffer enters On the candidate, Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (driver 621.35), rustc 1.99.1 MSVC, DXC 1.8.2502.11. The regression uses a synthetic fence and a WARP resource; no game data. Not tested: retail smoke, sustained world load, AMD or Intel. This demonstrates incorrect buffer reuse after removal; it does not establish the cause of any reported retail hang. The diff is an uncommitted suggestion against this exact head; the author can share #2831's helper when integrating the branches. Candidate fix and two regressions against 839df6ddiff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs
index e4033d39..a956a4fd 100644
--- a/crates/xcl/src/hle/d3d12x/bind.rs
+++ b/crates/xcl/src/hle/d3d12x/bind.rs
@@ -312,13 +312,18 @@ fn put_free_bufs(bufs: Vec<TwoPassBuf>) {
drop(gone);
}
+fn submit_completed(fence: &ID3D12Fence, mark: u64) -> bool {
+ let value = unsafe { super::real::fence_completed(fence) };
+ value != u64::MAX && value >= mark
+}
+
fn retire_recording_res(allocator: usize, bufs: Vec<TwoPassBuf>, marks: Vec<(usize, ID3D12Fence, u64)>, untracked: bool) {
if bufs.is_empty() {
return;
}
if !untracked && !marks.is_empty() {
let marks: Vec<(ID3D12Fence, u64)> = marks.into_iter().map(|(_, f, v)| (f, v)).collect();
- if marks.iter().all(|(f, v)| unsafe { super::real::fence_completed(f) } >= *v) {
+ if marks.iter().all(|(f, v)| submit_completed(f, *v)) {
put_free_bufs(bufs);
return;
}
@@ -340,7 +345,7 @@ fn reclaim_fenced() -> u64 {
let mut fenced = FENCED_RES.lock().unwrap();
let mut i = 0;
while i < fenced.len() {
- let done = fenced[i].marks.iter().all(|(f, v)| unsafe { super::real::fence_completed(f) } >= *v);
+ let done = fenced[i].marks.iter().all(|(f, v)| submit_completed(f, *v));
if done {
let batch = fenced.remove(i).unwrap();
reclaimed += batch.bytes;
@@ -4327,6 +4332,46 @@ void ms(uint3 g : SV_GroupID) { o.Store((v * 16u + g.x) * 4u, rec.Load(g.x * 4u)
assert!(got.contains(&first_scratch_raw) && got.contains(&rec_raw), "fence completion reclaims both without allocator reset: got={got:?}");
}
+ #[test]
+ fn removed_device_does_not_reuse_fenced_two_pass_buffer() {
+ let _warp_guard = lock_warp_tests();
+ let Some(dev) = warp_device_for_test() else { return };
+ let key = dev.as_raw() as usize;
+ let rec = unsafe { TwoPassBuf::make(&dev, RECORD_MIN, "record buffer") }.unwrap();
+ let raw = rec.res.as_raw() as usize;
+ let (fence, value) = make_test_fence(4);
+ retire_recording_res(0, vec![rec], vec![(1, fence, 5)], false);
+ assert!(take_free(key, RECORD_MIN, u64::MAX).is_none());
+ value.store(u64::MAX, Ordering::Release); // D3D12's device-removal sentinel.
+ let early = take_free(key, RECORD_MIN, u64::MAX);
+ value.store(5, Ordering::Release);
+ let after = take_free(key, RECORD_MIN, u64::MAX);
+ let early_raw = early.as_ref().map(|b| b.res.as_raw() as usize);
+ let after_raw = after.as_ref().map(|b| b.res.as_raw() as usize);
+ drop((early, after));
+ assert_ne!(early_raw, Some(raw), "device removal must not make a live buffer reusable");
+ assert_eq!(after_raw, Some(raw), "normal fence completion reclaims the buffer");
+ }
+
+ #[test]
+ fn removed_device_does_not_immediately_retire_two_pass_buffer() {
+ let _warp_guard = lock_warp_tests();
+ let Some(dev) = warp_device_for_test() else { return };
+ let key = dev.as_raw() as usize;
+ let rec = unsafe { TwoPassBuf::make(&dev, RECORD_MIN, "record buffer") }.unwrap();
+ let raw = rec.res.as_raw() as usize;
+ let (fence, value) = make_test_fence(u64::MAX);
+ retire_recording_res(0, vec![rec], vec![(1, fence, 5)], false);
+ let early = take_free(key, RECORD_MIN, u64::MAX);
+ value.store(5, Ordering::Release);
+ let after = take_free(key, RECORD_MIN, u64::MAX);
+ let early_raw = early.as_ref().map(|b| b.res.as_raw() as usize);
+ let after_raw = after.as_ref().map(|b| b.res.as_raw() as usize);
+ drop((early, after));
+ assert_ne!(early_raw, Some(raw), "device removal must not immediately retire the buffer");
+ assert_eq!(after_raw, Some(raw), "normal fence completion reclaims the buffer");
+ }
+
#[test]
fn split_segment_without_allocator_reclaims_via_fence_instead_of_aging() {
let _warp_guard = lock_warp_tests();AI use: Codex (GPT-6.2 Sol) traced the fence paths, wrote and ran the local candidate and tests, and drafted this report. I checked each review point against the source and test output. |
839df6d to
4253226
Compare
|
Updated RTX 4060 (8 GB) / Windows 11 release verification of PR #2815 rebased head Setup
Targeted RTX 4060 release unit & GPU tests (
|
|
Independent Windows/NVIDIA verification and diff review of PR #2815 at head System
Tested
Code review findings (
Not tested
AI use
|
Reclaim retired two-pass mesh buffers on submit queue fence completion rather than waiting for the owning command allocator to reset, and rebase cleanly onto
nvidia-dev(eae01502).Part of #2688
What is in it
README.md: documentXCL_TWO_PASS_MBalongside two-pass mesh pool behavior.crates/xcl/src/hle/d3d12x/alloc_pool.rs: pollreclaim_fenced()before freeing idle two-pass buffers so completed recordings can be recycled immediately without holding allocator-lifetime memory, and trackFenceState::Removedso lost devices never recycle in-flight buffers.crates/xcl/src/hle/d3d12x/bind.rs: replace reset-only holding with fence-tracked batches (FencedBatch, monotonic per-queuerecord_queue_fence.max, explicitPending/Completed/Removedpolling withu64::MAXdevice-removal short-circuiting), preserve closed command lists' buffers acrossFREE_RES_IDLEtrims so Reset-less replays remain valid (in_flightlist tracking), track upstreambatch_bufallocations via submit fences, and add 7 unit/GPU tests covering fence reclamation, monotonic queue fence merging, closed-list replay preservation, and device removal.Tested
32.0.16.2101,32187 MiBVRAM, wave32 / split wave64), WARP (software renderer), AMD Ryzen 9 9950X3D, Windows 11 Pro (10.0.26300),rustc 1.100.0(0ef1bc386 2026-11-09), DXC1.8.2502.11.42532264:cargo test --offline --locked -p xcl --lib -- hle::d3d12x::bind hle::d3d12x::alloc_pool --test-threads=4(NVIDIA + WARP):68 passed; 0 failed(1opt-inSKIPPED:hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap: no heap windows (opt-in: XCL_HEAP_WINDOWS=1)).XCL_HEAP_WINDOWS=1:two_pass_binds_set_the_shared_view_heap1 passed; 0 failed.cargo build --offline --locked --release --workspace && cargo test --offline --locked --release --workspace --no-fail-fast -- --test-threads=4) on RTX 5090:42532264(this PR):total_passed=1819, total_failed=13, total_ignored=48, skips=27(xcllib:1692 passed; 7 failed; 28 ignored).nvidia-dev(eae01502):total_passed=1812, total_failed=13, total_ignored=48, skips=27(xcllib:1685 passed; 7 failed; 28 ignored).fuzz_validate_and_gpu_{0,1,2,3},gpu_compute_thread_limits_leave_the_lanes_past_them_out,texture_upload::{pieces_hold_the_texels_of_their_levels, gpu_parts_of_a_texture_go_up_and_the_rest_stays},console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly,async_compute_pso_registers_real_pso_and_not_standin,split_compute_prefers_the_offline_whole_pipelinex2,two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsx2).SKIPPEDGPU tests on RTX 5090:no wave64(20),wave32, per-lane form: refused(3),no heap windows(2),cannot disable the driver cache(1), plus opt-inXCL_HEAP_WINDOWS=1skip above (1).scripts/smoke.ps1,title: a93b40d7, RTX 5090,XCL_PREPARE=0):42532264produced1671frames (PresentX 1671),0device removals,0crashes,15915 MBpeak commit vsnvidia-deveae01502(1628frames,0removals,0crashes,15793 MBpeak commit) andmainb49be183(1654frames,16446 MBpeak commit).Regression run
Not tested
nvidia-dev(eae01502) and the top of the stack (D3D12.X: cap two-pass buffers by DXGI headroom with wait and shrink #2817), not separately on this intermediate commit (targetedbind+alloc_pooltests ran on both NVIDIA and WARP here).0two-pass draws); world loading was verified in 120 s runs on top of the stack (D3D12.X: cap two-pass buffers by DXGI headroom with wait and shrink #2817) using synthetic menu-advance inputs.AI use
gemini-pro-orchestrator-neon) and Codex (GPT-6.2 Sol) wrote and reviewed the fence-tracking fixes, tests, and PR description; all builds, tests, and smoke runs were executed directly on local hardware.