D3D12.X: spill overflow two-pass UAV buffers to L0 system memory #3614
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3614"
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 ivall/xcl. Originally posted by saintwolf on 2026-12-01T20:58:51Z.
When local-VRAM two-pass UAV buffers reach
XCL_TWO_PASS_MB(or the dynamic DXGI headroom floor), two-pass draws spin-wait up toFENCE_WAIT_LIMITand then shrink or skip draws once the local cap is saturated. On 12 GiB non-UMA cards during heavy mesh-shader world loads, this caused heavy draw skipping and multi-millisecond fence-wait stalls.This PR adds a bounded
D3D12_MEMORY_POOL_L0(system-memory) spillover pool for full-size overflow two-pass record and argument-scratch UAV buffers, tracked separately from the local VRAM cap (TWO_PASS_L0_ALIVEandFREE_L0_RES), while preserving the original localFENCE_WAIT_LIMITwait and shrink/refusal fallback whenever L0 spillover is disabled, full, or unsupported by the adapter.Complementary to #3165 (draft).
What is in it
crates/xcl/src/hle/d3d12x/bind.rs:XCL_TWO_PASS_L0_MB(default512MiB;0disables spillover) andTWO_PASS_L0_ALIVE/FREE_L0_REStracking (TwoPassBuf::is_l0).uav_buffer_in_poolcreatesD3D12_HEAP_TYPE_CUSTOM+D3D12_MEMORY_POOL_L0+D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLEbuffers for L0 spillover and caches non-OOM adapter refusals (L0_UNSUPPORTED).acquire_res_buf_or_l0andscratch_args: try full-size local (0 ms, no shrink), spill full-size to L0 on local-cap miss, and fall back to the original localFENCE_WAIT_LIMITwait + shrink/refusal path if L0 is full or unsupported.trim_idle_l0_free: trims idleFREE_L0_RESentries older thanFREE_RES_IDLEfromrelease_allocator_resandtake_freeas well asput_free_bufs.two_pass_l0_spillover_tracks_and_reuses_separately_from_localandtwo_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full(caps computed relative toTWO_PASS[TP_ALIVE]/TWO_PASS_L0_ALIVE).Tested
32.0.16.2140), AMD Ryzen 7 7800X3D, 31.1 GB RAM, Windows 11 build 26300,rustc 1.100.0, DXC1.8.2502.11.cargo test -p xcl --lib hle::d3d12x::bind::tests::two_pass_l0 -- --nocapture --test-threads=1on4179a5a5: 2 passed, 0 failed, 0 skipped.cargo test -p xcl --lib hle::d3d12x::bind::tests -- --test-threads=4: 117 passed, 0 failed.Regression run
Matched 60 s smoke runs with identical settings (
XCL_DIRECT_DXIL=1, defaultXCL_PSO_PRELOAD,smoke.ps1defaultXCL_PREPARE=0):main(f07e426d):this PR (
4179a5a5):Not tested
vkd3d-proton), and full workspace test suite locally (covered by CI).AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:10:09Z.
Review (head
19fc7dd3, diff read, not a merge-check):ensure_res_buffer_with_cap(bind.rs~3087) andscratch_args(~3297) now pass a zero wait wheneverXCL_TWO_PASS_L0_MBis non-zero, which is the default. Whentry_make_l0then returnsNone(the 512 MiB L0 cap is full, orCreateCommittedResourceon the L0 heap fails, ~285-301), the draw is refused at once instead of waiting up toFENCE_WAIT_LIMITas onmain, so under the heaviest load more draws can be skipped than before. A failed L0 creation is not remembered and is retried on every miss. "Fall back cleanly to the existing refusal path" does not hold, because that path used to wait.XCL_DIRECT_DXIL=1,XCL_PREPARE=0andXCL_PSO_PRELOAD=0, but no settings are given for themainrun, so 1045 → 1658 frames does not isolate this change; the retail numbers were measured together with other local L0 testing, and the full suite was not run.FREE_L0_RESis trimmed only when L0 buffers are put back (put_free_bufs, ~491);release_allocator_res(~737) andtake_freetrim onlyFREE_RES, andtry_make_l0only runs when the local cap is full. After a spill burst up to 256 MiB of system-memory buffers stay committed until the next spill instead of going afterFREE_RES_IDLE.two_pass_l0_spillover_tracks_and_reuses_separately_from_local(~10294) callstry_make_l0andput_free_bufsdirectly; nothing tests thatensure_res_buffer_with_caporscratch_argsfall back to L0 after a local refusal, the L0-full case, or the zero-wait change.Fine:
TWO_PASS_L0_ALIVEand theis_l0drop path keep L0 bytes out of the localTP_ALIVEcap, and thereservecalls are rolled back when L0 creation fails. Draft #3165 tackles the same skipped draws by letting buffers exceed the local cap; a maintainer may want only one of the two.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T21:38:29Z.
Thanks for the thorough review — addressed all four points in
1aa29c4d:elease_allocator_res\ and \ ake_free\ as well as \put_free_bufs, so idle L0 buffers are released after a spill burst ends.
1aa29c4d\ under identical settings (\XCL_DIRECT_DXIL=1, default \XCL_PSO_PRELOAD).AI use: Antigravity (Gemini 4 Neon) assisted with implementing the fixes, running the tests and matched smokes, and drafting this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:41:22Z.
Follow-up review (head
1aa29c4d, since19fc7dd3, diff read, not a merge-check):acquire_res_buf_or_l0(bind.rs~3105-3124) andscratch_args(~3345-3359) try local with no wait, then L0, then the oldFENCE_WAIT_LIMITwait when L0 returnsNone; adapter refusals other than out-of-memory are remembered inL0_UNSUPPORTED(~304-308).trim_idle_l0_free(~743) is also called fromrelease_allocator_res(~751) andtake_free(~771).two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full(~10392) goes throughacquire_res_buf_or_l0, but withmin_fit == need, so the shrink case below is not covered, and the L0 fallback inscratch_argsis not tested.New:
acquire_res_buf_or_l0first callsacquire_res_buf_with_capwith a zero wait (~3115), and that function still runs its shrink loop (~666-690), down to one record (min_fitisrecord_bytes, ~3579, ~3846). With the defaultXCL_TWO_PASS_L0_MB=512, a draw that hits the local cap gets a smaller local buffer at once and is sliced or has groups cut (record_groups, ~3580), wheremainfirst waits up toFENCE_WAIT_LIMITfor a full-size buffer. L0 is tried only when even the smallest size fails, so "spill to L0 on a local-cap miss" does not hold for record buffers.1aa29c4dfixes19fc7dd3, whose message still says overflow buffers spill "instead of spin-waiting and skipping draws".Fine: L0 bytes stay out of the local cap (
TWO_PASS_L0_ALIVE,is_l0on drop);reserveis rolled back when L0 creation fails;XCL_TWO_PASS_L0_MB=0gives back themainpath.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T21:48:35Z.
Thanks for catching the shrink-before-spill bug — fixed and squashed into a single clean commit (
344962b9) onmain(f07e426d):acquire_res_buf_or_l0now callsacquire_two_pass_buf_with_capfor the fullneedsize withDuration::ZERO(no shrink loop), then spills the full-size buffer to L0 viaTwoPassBuf::try_make_l0_with_cap, and only falls back toacquire_res_buf_with_cap(..., FENCE_WAIT_LIMIT)(wait + shrink) if L0 is disabled, full, or unsupported.two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_fullnow usesmin_fit < local_cap < needto assert all three transitions: full-size L0 spill without shrinking, local-shrink fallback when L0 is full, andOk(None)when both caps are full (2/2passed on RTX 4070 SUPER).344962b9) with an accurate commit message.AI use: Antigravity (Gemini 4 Neon) assisted with fixing the shrink-before-spill path, updating the unit test, squashing, and drafting this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:51:41Z.
Follow-up review (head
344962b9, since1aa29c4d, diff read, not a merge-check; checks red):acquire_res_buf_or_l0(bind.rs~3106-3123) now triesacquire_two_pass_buf_with_capat full size with no wait and no shrink loop, then L0, and only thenacquire_res_buf_with_capwithFENCE_WAIT_LIMIT.scratch_args(~3344-3358) is still untested.1aa29c4d, not the head344962b9, soPR descriptionfails; the description still says the 60 s run never fills the local cap, and the full suite was not run on a GPU.New:
budget_capas2 << 20and1, butTWO_PASS[TP_ALIVE]counts every live local two-pass buffer in the process, so if earlier tests still hold more than 1 MiB (fenced or awaiting an allocator reset) the shrink in step 2 cannot fit and the test fails depending on order. The other cap tests compute their cap fromTWO_PASS[TP_ALIVE].load(..)(~10001, ~10123, ~10330).Fine: the record path no longer shrinks before spilling;
XCL_TWO_PASS_L0_MB=0(or an adapter that refuses L0) keepsmain's wait-and-shrink path; L0 bytes stay out of the local cap;reserveis rolled back when L0 creation fails.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T22:00:31Z.
Follow-up review (head
4179a5a5, since344962b9, diff read, not a merge-check; checks red):two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full(bind.rs~10404-10431) now takes its local and L0 caps relative toTWO_PASS[TP_ALIVE]andTWO_PASS_L0_ALIVEat the start, like the other cap tests, so it no longer depends on what earlier tests still hold.scratch_argsis untested: still open (~3344-3358).1aa29c4d, not the head4179a5a5(the reasonPR descriptionis red), the spill path is not reached in the 60 s run, and the test counts are from1aa29c4d/19fc7dd3with no full-suite run on a GPU.New: none. Since
344962b9only the test changed.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T22:02:00Z.
@Foniass Let your bot take a breath bro. I haven't even had a chance to post the smoke results yet.
Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T22:02:55Z.
Fixed the relative local/L0 caps in
two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full(local_before + .../l0_before + ...), amended to4179a5a5, and updated the PR description with a fresh 60 s head smoke (1685frames,60 61 60,0removals/crashes).All substantive review points are now addressed and tested (
2/2L0 unit tests passed on hardware D3D12, single clean commit, matched head smoke). Leaving this ready for human maintainer review.AI use: Antigravity (Gemini 4 Neon) applied the relative-cap test fix, ran the head smoke, and drafted this reply.
Imported from ivall/xcl. Originally posted by jsalzy on 2026-12-01T22:43:48Z.
merge-check claim
head:
4179a5a59eImported from ivall/xcl. Originally posted by jsalzy on 2026-12-01T22:57:57Z.
merge-check
base:
1c8b551head:
4179a5amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64 on this GPU; 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: none
review: whole diff read (bind.rs, +270/-23). Both new GPU tests ran and passed on this NVIDIA card (not skipped: the driver made the CUSTOM / MEMORY_POOL_L0 / NOT_AVAILABLE UAV buffers): two_pass_l0_spillover_tracks_and_reuses_separately_from_local, two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full. L0 buffers are counted in TWO_PASS_L0_ALIVE and FREE_L0_RES only, and Drop subtracts from the right counter. Foniass's points look addressed at this head: with L0 full or unsupported, the original FENCE_WAIT_LIMIT wait and shrink path runs as before. Behaviour change to note: it is on by default (XCL_TWO_PASS_L0_MB=512), and while L0 has room a full local cap now spills at once instead of waiting up to 10 ms for in-flight buffers, so up to 512 MiB alive plus a 256 MiB free pool go to system commit, which matters on 32 GB machines near their commit limit. Minor: the adapter-refusal test in try_make_l0_with_cap matches the error text ("0x8007000E"); #3620 checks err.code() instead, which is sturdier. Overlaps draft #3165 in the same two-pass cap code (the author calls them complementary); not a duplicate.
performance: not measured.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.
Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T00:18:18Z.
merge-check claim
head:
4179a5a59eImported from ivall/xcl. Originally posted by vasanex on 2026-12-02T00:45:49Z.
merge-check
base:
1c8b551475head:
4179a5a59emerge: clean (merged tree f0185483,
git diff --checkclean)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same set as on the base; failing: none. Base alone, same machine: 2909 passed, 0 failed, 51 ignored. Both new tests pass and did not skip (
two_pass_l0_spillover_tracks_and_reuses_separately_from_local,two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full), so this card and driver accept a custom L0 UAV buffer without CPU access.review: whole diff read (bind.rs), in the merge result. No blocking finding; three points for whoever merges, most serious first. (1) It is on by default (512 MiB) and it changes what happens at a full local cap: main waits up to 10 ms on the oldest fences for local memory and then shrinks; with this the first try has no wait, the buffer goes to system memory at once, and the wait and shrink come only when L0 is full or refused. Draws are kept instead of cut, at the price of record and argument buffers the GPU writes and reads over PCIe. Neither side of that is measured: the description's smoke and mine do not reach the cap (no
two-pass buffers:line in either of my logs). (2)two_pass_capis derived from the adapter's local budget. On an adapter with one memory segment (integrated GPUs) an L0 heap is the same memory, so there the default raises the two-pass ceiling by up to 512 MiB instead of moving anything; nothing in the diff tells the two kinds apart. Reasoned from the code, not run on such an adapter. (3)L0_UNSUPPORTEDis set for good by any creation error whose text does not hold 0x8007000E, a lost device included; harmless (it only turns the spill off), but the log does not say so. Otherwise: L0 buffers are counted and freed apart from the local ones (TWO_PASS_L0_ALIVE,FREE_L0_RES,Drop), a buffer cannot change pools on reuse, idle L0 buffers are trimmed on the same paths as local ones, andXCL_TWO_PASS_L0_MB=0gives main's path exactly. The tests compute their caps from the live counters, as the file's other cap tests do. No README line forXCL_TWO_PASS_L0_MB. Duplicates: none; #3165 (draft, lets a draw's buffer go past the cap) and #3620 (same author, texture pools) are other changes.performance: 60 s smoke of the same title, release, default settings, same machine, one run each. Base
1c8b5514: 1608 frames shown, presents per 2 s (last 3) 60 60 61, 0 device removals, 0 crashes, peak commit 19911 MB. Merge result (local merge commit of the two commits above): 1616 frames shown, 61 60 60, 0 device removals, 0 crashes, peak commit 18794 MB. No difference outside the run-to-run spread, and the run does not saturate the cap, so this shows only that the default path is unharmed when the cap is not reached. By default it can add up to 512 MiB of system memory once the cap is full.verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0, debug suite and release smoke / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:03:42Z.
Code review location:
crates/xcl/src/hle/d3d12x/bind.rs; line 311Medium: L0_UNSUPPORTED is one process-wide flag, set for life on any error other than E_OUTOFMEMORY (device removed 0x887A0005, E_INVALIDARG, a null resource), with no log line, while E_OUTOFMEMORY is retried on every miss with no backoff. A device-removed or other transient error, or a refusal on one device (e.g. a WARP test device), turns spillover off silently and permanently for every device, including one recreated after a TDR. Meanwhile, with system memory exhausted, every two-pass draw that misses local calls CreateCommittedResource for a full-size L0 buffer, which fails each time before falling through to the local wait. Keeping the flag per device, logging it, and backing off on E_OUTOFMEMORY would avoid both.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:03:42Z.
Code review location:
crates/xcl/src/hle/d3d12x/bind.rs; line 3114Medium: Not certain about this one: nothing checks whether the adapter is UMA (D3D12_FEATURE_ARCHITECTURE). On UMA adapters MEMORY_POOL_L0 is the same physical memory as DEFAULT, so the spill just sidesteps the cap, and
two_pass_cap'snon_tp(~368) subtracts only TP_ALIVE, so L0 bytes count as non-two-pass usage and shrink the dynamic cap. On an iGPU/APU (or vkd3d-proton UMA), once the local cap is hit, up to another 512 MiB of two-pass buffers lands in the same memory. DXGIusedgrows,budget_two_pass_capreturns a smaller cap, and that causes more misses, more L0 spill and more refusals, a feedback loop past what XCL_TWO_PASS_MB was meant to bound. Disabling the spill on UMA adapters (and subtracting L0 bytes innon_tp) would avoid it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:03:42Z.
Review: COMMENTED
Review of
4179a5a5: 2 finding(s) (2 medium), most severe first.crates/xcl/src/hle/d3d12x/bind.rs:311: L0_UNSUPPORTED is one process-wide flag, set for life on any error other than E_OUTOFMEMORY (device removed 0x887A0005, E_INVALIDARG, a null resource), with no log line, while E_OUTOFMEMORY is retried on every miss with no backoff. (inline)crates/xcl/src/hle/d3d12x/bind.rs:3114: Not certain about this one: nothing checks whether the adapter is UMA (D3D12_FEATURE_ARCHITECTURE). (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:03:47Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
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.