D3D12.X: opt-in XCL_L0_VRAM_MARGIN_MB spills sparse and sampled texture pools to L0 #3620
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3620"
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-01T22:21:32Z.
On 12 GiB non-UMA discrete GPUs during heavy world loads, sparse tile pools (
sparse.rs) and sampled-only texture tile pools (vram.rs) can push local VRAM over the DXGI budget, forcing WDDM to evict render targets, depth buffers, and hot arenas across PCIe / into the pagefile.This PR adds a single opt-in DXGI budget-headroom control (
XCL_L0_VRAM_MARGIN_MB, default0= disabled) that dynamically spills new sparse tile pools and sampled-only (!gpu_owned) texture tile pools intoD3D12_MEMORY_POOL_L0(system memory) only when DXGI local VRAM usage is within the configured headroom margin of budget.Relation to existing PRs
#3614covers two-pass UAV buffers inbind.rs(bind.rsis untouched here); this PR covers onlyvram.rsandsparse.rs.amd-dev): Draft PR#3112(created 2026-11-28) targetsamd-devwith a static opt-in sparse cap and has not been updated since submission whilemainhas changed substantially.amd-dev), and #1702:#2987uses a static sparse tile cap,#3039/#1702move streamed/texture pools to L0 unconditionally behind opt-ins, and#3587targetsamd-dev; this PR offers a cleanmain-based single opt-in DXGI-headroom mechanism covering both sparse and sampled-only texture pools dynamically only when approaching budget.What is in it
crates/xcl/src/hle/d3d12x/vram.rs:XCL_L0_VRAM_MARGIN_MB(parse_l0_vram_margin_bytes, default0= disabled),vram_within_margin, and 250 ms cachedshould_spill_l0_for_vram()usingsuper::real::video_memory().L0_TEX_HEAP_UNSUPPORTED/note_l0_heap_error: caches non-OOMCreateHeapL0 refusals per heap class so unsupported adapters go straight toDEFAULT.alloc_pool_heap: sampled-only (evictable) 64 MiB texture pools spill toD3D12_MEMORY_POOL_L0(D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_BUFFERS) when within margin, with clean fallback toDEFAULT(andDEFAULT-> L0 fallback whenXCL_L0_VRAM_MARGIN_MB > 0). WhenXCL_L0_VRAM_MARGIN_MBis unset/0, behavior andTilePoolallocation classes are identical tomain.PoolHeaps::is_l0tracks L0 heaps andkeep_poolsskips them.place_on_pages/remap_if_unmapped),drain_device_queueswaits outsidePAGESfor active title queues,title_texturesupload queues, and retiring queue fences socopy_promoted_tilesonPages::queuereads completed uploads without creating a GPU-side dependency fromPages::queueback to a title queue. Returnsfalse(fail closed) on a blocked queue snapshot, failed signal, device removal, or 2 s timeout so the caller falls back without promoting or losing texels.bind_rangeis transactional: when a non-evictable target (RT/DS/UAV) binds a console page currently backed by an L0 heap (DENY_RT_DS_TEXTURES), it copies the 64 KiB tile bytes via a 4-slot ring of lazily-created 0-VRAM reserved scratch resources (TilePromoter/copy_promoted_tiles, submitting asynchronously viaown_work+native_queue_executewith no CPU wait underPAGESunless a ring slot is still busy) before mutatingpages/extra_pages. If the copy fails, the new local tiles are returned/cooled, L0 pages are left untouched and uncooled, andbind_rangereturnsNone(fail closed). On success,p.tileis swapped in-place, the old L0 tile is cooled, andremap_promotedre-maps every live mapped alias inPages::targets.HeldUnmap::stale_mapping:remap_promotedalso marks any pendingHeldUnmapreferencing a promoted page so cancelling it inremap_if_unmappedimmediately re-maps the resource onto the promoted local tiles instead of keeping the old L0 tile.l0_vram_margin_parses_opt_in_default_and_checks_budget(parsing, budget boundaries,texture_pool_heap_desc).pool_heaps_tracks_l0_flag_across_slot_reuse_and_l0_heap_creates(slot reuse + hardware D3D12 L0 texture and L0 bufferCreateHeap).wait_marks_with_timeout_fails_closed_on_timeout_and_device_removal(queue-drain timeout andu64::MAXdevice-removal fail-closed checks).l0_page_promotes_in_place_to_local_when_target_binds_same_va(real hardware D3D12 GPU test: verifies fail-closed rollback whencopy_promoted_tilesfails with L0 tiles untouched/uncooled and texels intact; promotes RGBA8 sampled texture via RT at same VA and reads back RT, sampled alias, live RT write, and cancelledHeldUnmap; promotes a 256x256BC7_UNORMtile via anR32G32B32A32_UINTRT and verifies byte-for-byte equality across all 65,536 bytes; and tests theextra_pagespromotion path).crates/xcl/src/hle/d3d12x/sparse.rs:vram::l0_vram_margin(),vram::should_spill_l0_for_vram(), andvram::note_l0_heap_errorwith its ownL0_SPARSE_HEAP_UNSUPPORTEDflag to spill new 4 MiB sparse tile pools (D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES) to L0 when within the DXGI headroom margin, skippingset_heap_priorityon L0 heaps and skipping retired L0 pools once VRAM pressure ends.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::vram::testsonc30b3f67: 75 passed, 0 failed, 1 ignored (including fail-closed rollback,wait_marks_with_timeout, full 65,536-byteBC7_UNORMtile copy, andextra_pagespromotion).cargo test -p xcl --lib hle::d3d12x::sparse::testsonc30b3f67: 140 passed, 0 failed, 1 ignored.XCL_L0_VRAM_MARGIN_MB=12288: 60 s run exited0x0,0device removals,0crashes,60 60presents per 2 s once initial PSO compiles completed, sparse tile pools cleanly spilled to L0.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 (
c30b3f67):Not tested
vkd3d-proton), and full workspace test suite locally onc30b3f67(covered by CI).AI use
TilePromoter),HeldUnmap::stale_mappingremap handling, hardware GPU pixel-readback test, running tests and smokes, and drafting this description. Reviewed by me.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T22:26:18Z.
Review (head
c42d20cc, diff read, not a merge-check):bind_range(vram.rs~2036, ~2345, ~2384), a render target, depth buffer or UAV placed over a sampled texture whose page went to an L0 heap gets its own tile inextra_pagesinstead of the title page. And onceXCL_L0_VRAM_MARGIN_MBis set, a sampled texture and a target at the samevaget differentextra_pageskeys (local_onlyfalse vs true, ~2336), so their extra tiles are no longer shared even when nothing has spilled. A title that writes a target and reads the same memory through a texture alias (whatplacementsremaps for, and whatshared_page_identity_is_the_title_address_not_allocation_class~4418 guards) then reads stale data.parse_l0_vram_margin_bytes,vram_within_margin,texture_pool_heap_desc,can_share_own_page,PoolHeaps) and create L0 heaps (~5899, ~5935), but nothing callsbind_rangewith an L0 pool, places two resources at one address, or maps a reserved texture onto an L0 heap.vram::testsandsparse::testsfilters and leaves the rest to CI, which has no GPU.amd-dev) samples the DXGI budget every 250 ms and moves new sampled-texture pool heaps to L0, never targets, withis_systracking inPoolHeaps; #1702 (onmain) moves texture page pools to L0 behind an opt-in.Fine: with
XCL_L0_VRAM_MARGIN_MBunset every caller passesevictable = falseand everyextra_pageskey is(va, i, true), so the default path is as onmain; lazily mapped level textures only reach the L0 path withFlags == NONE, andkeep_poolsskips L0 heaps.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:35:31Z.
Updated to
3008ae08(single commit, both default and active-spillover 60 s smokes re-run on3008ae08):extra_pagessharing: Addedextra_page_keyso targets (!evictable) and sampled textures share(va, i, false)whenever that slot is unmapped or backed by local VRAM, and only split to(va, i, true)if the existing tile is actually backed by an L0 heap (where D3D12'sDENY_RT_DS_TEXTURESrequires a local tile). Added unit assertions forextra_page_key.#3587(amd-dev) and#1702to the PR description.The remaining points (full workspace suite beyond CI and
vram/sparsemodule suites, and additional syntheticbind_rangefixtures beyond the unit tests + liveXCL_L0_VRAM_MARGIN_MB=12288smoke) are documented under Not tested; leaving this ready for human maintainer review.AI use: Antigravity (Gemini 4 Neon) applied the
extra_page_keytweak, ran the head smokes, and drafted this reply.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T22:37:02Z.
Follow-up review (head
3008ae08, sincec42d20cc, diff read, not a merge-check):extra_page_key(vram.rs~2040-2046, used at ~2353 and ~2394) keeps targets and sampled textures on one(va, i, false)extra tile unless that tile is in an L0 heap, so nothing splits while nothing has spilled. Once a sampled texture's page is in L0, a target at the same address still gets its own tile, both for the own page (can_share_own_page, ~2037) and for the extra page ((va, i, true)), so a title that renders to that memory and samples it through the texture alias still reads stale data whenever the spill path is taken. After the L0 page is released and swept, a later target at that address gets a fresh(va, i, false)tile while the earlier target keeps(va, i, true), so two targets can also diverge.extra_page_keyhas a unit test of the key choice, but nothing still callsbind_rangewith an L0 pool or places two resources at one address.vram::testsandsparse::testsfilters and two named tests, and leaves the rest to CI, which has no GPU.New: none. The new smoke block runs with
XCL_L0_VRAM_MARGIN_MB=12288, so it reaches the spill path.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 jsalzy on 2026-12-01T22:43:56Z.
merge-check claim
head:
3008ae08c0Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T23:16:10Z.
Fixed the aliased target/texture sharing issue cleanly in
476983d4(single commit, both default and active-spillover 60 s smokes re-run on476983d4):bind_range+remap_promoted): Revertedextra_pagesback to(usize, usize)(removing all splitting). When a non-evictable target (RT/DS/UAV) binds a console page currently backed by an L0 heap (DENY_RT_DS_TEXTURES),bind_rangeallocates a local VRAM tile, promotesp.tilein-place, cools the old L0 tile, and callsremap_promotedto re-map every live mapped alias inPages::targetsonto the promoted local tile before the next submit — so targets and sampled aliases at the same console address always share the exact same physical local tile and never read stale data.bind_rangetest: Addedl0_page_promotes_in_place_to_local_when_target_binds_same_vawhich seeds an L0 pool, binds a reserved sampled texture onto L0, then binds a reserved render target at the exact same VA, verifying in-place local promotion,users == 2, zeroextra_pagessplit, old L0 tiles cooled, and device health (3/3L0 tests passed on RTX 4070 SUPER).AI use: Antigravity (Gemini 4 Neon) implemented the in-place L0 -> local promotion, added the hardware
bind_rangetest, ran the head smokes, and drafted this reply.Imported from ivall/xcl. Originally posted by jsalzy on 2026-12-01T23:17:28Z.
merge-check claim
head:
476983d49aImported from ivall/xcl. Originally posted by Foniass on 2026-12-01T23:21:32Z.
Follow-up review (head
476983d4, since3008ae08, diff read, not a merge-check):extra_pagesis back to one(va, i)key; when a target binds a page held in an L0 heap,bind_range(vram.rs~2384-2453) moves the page to a new local tile andremap_promoted(~2313) points every mapped alias at it, so target and texture keep one tile and two targets cannot drift apart after a sweep. The two new points below are gaps in that promotion.l0_page_promotes_in_place_to_local_when_target_binds_same_va(~6046) binds a sampled texture onto an L0 pool and then a render target at the same address throughbind_range; it checks the bookkeeping, not the alias's actual mapping, and the extra-page and level-group paths are untested.New:
take_batchand the L0 tile goes tocooling, but nothing copies the L0 tile's contents across. The target placed over the texture and the sampled aliasremap_promotedmoves both start from whatever the recycled tile last held instead of the uploaded texels; onmainthey share one tile and the texels stay.register_gpu_ownedmarks the entrygpu_written, so nothing uploads them again.remap_promotedskips targets with!t.mapped(~2316), which includes a sampled texture whose unmap is waiting inheld_unmaps. Ifremap_if_unmappedthen cancels that unmap (~2781-2795), it gives the page keys back without callingmap, assuming a deferred unmap never changed the resource's tiles, so that texture stays mapped to the old L0 tile, which returns to the pool afterCOOLand can be handed to another resource. Narrow window (a sampled texture superseded at that address with its unmap still pending).Fine: with
XCL_L0_VRAM_MARGIN_MBunset the extra key is(va, i)and every caller passesevictable = false, as onmain; non-evictable pool heaps are never created in L0, so a promoted tile is always local;missingcounts the promoted pages;before_executeorders the remap before the next title work.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-02T01:28:23Z.
Fixed both promotion gaps in
92fef0ba(single commit, both default and active-spillover 60 s smokes re-run on92fef0ba):TilePromoter/copy_promoted_tiles) that copy the 64 KiB tile bytes from each promoted L0 tile to its new local VRAM tile onPages::queue(waiting for the copy fence before cooling the old L0 tile or reusing the allocator; dropsTilePromoteron timeout/failure instead of resetting an in-flight allocator).HeldUnmapon promoted pages: AddedHeldUnmap::stale_mapping, set byremap_promotedwhenever a pending deferred unmap references a promoted page, so cancelling it inremap_if_unmappedimmediately re-maps the resource onto the promoted local tiles.l0_page_promotes_in_place_to_local_when_target_binds_same_vato upload[0x12, 0x34, 0x56, 0x78]to the L0 sampled texture, promote via an RT at the same VA, read back BOTH RT and sampled alias on the GPU to assert texels survived, write[0xAA, 0xBB, 0xCC, 0xDD]to the RT and read back the sampled alias, and cancel a staleHeldUnmapviaremap_if_unmappedand read back[0xAA, 0xBB, 0xCC, 0xDD]from it (74/74vram::testspassed on RTX 4070 SUPER).AI use: Antigravity (Gemini 4 Neon) implemented the tile copy,
HeldUnmapremap fix, and GPU pixel-readback test, ran the tests and smokes, and drafted this reply.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T01:31:47Z.
Follow-up review (head
92fef0ba, since476983d4, diff read, not a merge-check):copy_promoted_tiles(vram.rs~2374) now copies each L0 tile to its new local tile before the old one is cooled (~2614-2618); the two gaps are below.remap_promotedmarks every held unmap holding a promoted pagestale_mapping, flat or per level (~2452-2464), andremap_if_unmappedre-maps such a resource onto the current tiles when it cancels the unmap (~2956-2998).l0_page_promotes_in_place_to_local_when_target_binds_same_va(~6248) reads the texels back through the target, the remapped alias and the cancelled held unmap (~6449-6473); theextra_pagesand level-group paths are still untested.New:
Pages::queue(~2420), which waits for no other queue, while texture uploads go on the title's DIRECT queue (title_textures.rssubmit_on~2658), which only waits for thePagesfence, never the other way. If an upload into the sampled texture is still running when a target is placed over it, the copy reads the old bytes and the upload lands in the L0 tile that is now cooling; the target and the remapped alias keep stale texels, andgpu_writtenstops a re-upload.promoteris dropped (~2437-2443) while its command list may still run, closing its event withSetEventOnCompletionpending;bind_rangethen cools the old tiles and remaps anyway, with no log. The same silent loss happens on every promotion whenTilePromoter::newreturnsNone.pr_checkreads the third block (XCL_L0_VRAM_MARGIN_MB=12288): 159 frames againstmain's 1668.bind_rangenow also waits on the CPU for the GPU copy while holdingPAGES(~2423-2431), so every queue'sbefore_executewaits behind a promotion; the description does not explain the slowdown with the variable set.sparse.rsspill and the in-place promotion with its copy (TilePromoter,stale_mapping) could be separate PRs.Fine: with
XCL_L0_VRAM_MARGIN_MBunset nothing reaches the promotion; the src/dst mappings, the copy, the unmaps and the alias remaps run onPages::queuein that order; the CPU waits for the copy before the old tile goes tocooling.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-02T01:46:15Z.
Updated to
cf90edf9(single commit,vram::tests74/74,sparse::tests140/140, and 60 s head smoke re-run:1677frames,60 60 61,0device removals,0crashes):Pages::range_has_l0anddrain_device_queuessoplace_on_pagesandremap_if_unmappeddrain active title queues,title_textures::upload_queues(), and retiring queue fences outsidePAGESbefore promoting an L0 page to local VRAM (polling without an event handle so a timeout never leaves a pendingSetEventOnCompletion, and without adding a GPU-side dependency fromPages::queueback to a title queue). WhenXCL_L0_VRAM_MARGIN_MBis unset or the target range hits no L0 page, no drain runs.TilePromoterlifetime, wait, and error logging:copy_promoted_tilesnow records and closes the copy command list before mappingsrc/dst, unmaps both before a singlePages::fencesignal, waits withINFINITE(with polling fallback ifSetEventOnCompletionfails) soTilePromoterand its event handle are never released while GPU work or a completion event is pending,std::mem::forgetspromoteron a non-TDR signal failure, and logsxlog_warn!on every failure path.AI use: Antigravity (Gemini 4 Neon) implemented the queue drain and
TilePromoterwait/lifetime fixes, ran the tests and 60 s smoke, and drafted this reply.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T01:53:14Z.
Follow-up review (head
cf90edf9, since92fef0ba, diff read, not a merge-check):src/dstare mapped (vram.rs~2415-2449), the fence wait isINFINITE(~2466-2471), a promoter whose signal failed is leaked rather than dropped (~2486-2489), and every failure is logged (thoughbind_rangestill cools and remaps after a failed copy, ~2661-2665).drain_device_queues(~2691) now signals every active title queue and the upload queues and waits on the CPU before the promotion (~2924-2928, ~3112-3116), but returns early and lets the promotion go ahead unordered when the queue snapshot is blocked (~2701-2703), a signal fails (~2707-2710) or the wait passes 2 s (~2722-2724).PAGES.New:
ExecuteCommandListshook whilePAGESis held.copy_promoted_tilescallsself.queue.ExecuteCommandLists(~2451) outsidetitle_textures::own_work.Pages::queuecomes from the device'sCreateCommandQueue(~2098), whichreal.rsadopts like a title queue (creator!, ~4360;is_own_objectexcludes queues, ~4373), so the submit takesq_execute_command_lists's title path (~11994), whose comment says internal submits made while holdingvram::PAGESmust run insideown_work()to avoid re-entrant self-deadlocks. That path reachesvram::before_execute(title_textures.rs~2066 →vram.rs~3392) andpresent::note_execute→vram::drain_recycled, which lockPAGESwhile this thread already holds it fromplace_on_pages/remap_if_unmapped(~2917, ~3115). The GPU test submits on the bare queue and callsbind_rangedirectly, so it cannot catch this; wrapping the submit inown_work(|| ...)assparse.rs~4099 does would.Fine: with
XCL_L0_VRAM_MARGIN_MBunset every new path is gated off byl0_vram_margin() > 0; no promoter is released while its copy is in flight;remap_if_unmappedchecksmappedagain after takingPAGESback.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-02T02:28:59Z.
Updated to
2d72aa60(single commit,vram::tests74/74, 60 s head smoke re-run:1677frames,60 60 61,0device removals,0crashes):ExecuteCommandListshook deadlock:copy_promoted_tilesnow submits its copy command list viasuper::title_textures::own_work(|| super::real::native_queue_execute(&self.queue, &cmd))(matchingsparse.rs:4099) so submitting whilePAGESis held never re-entersq_execute_command_lists/vram::before_execute.AI use: Antigravity (Gemini 4 Neon) applied the
own_work/native_queue_executefix, ran the tests and 60 s smoke, and drafted this reply.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T02:29:55Z.
Follow-up review (head
2d72aa60, sincecf90edf9, diff read, not a merge-check):ExecuteCommandListshook whilePAGESis held: fixed.copy_promoted_tilesnow submits withown_work(|| native_queue_execute(&self.queue, &cmd))(vram.rs~2451-2453), which calls the queue's native slot underqueue_submit::withand skips the title path, like the module's other internal submits.cf90edf9; see the previous review.New: none; only that submit 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 jsalzy on 2026-12-02T02:45:41Z.
merge-check claim
head:
2d72aa60e5Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-02T10:58:46Z.
Updated to
c30b3f67(single commit,vram::tests75/75,sparse::tests140/140, and 60 s head smoke re-run:1653frames,60 61 60,0device removals,0crashes):drain_device_queuesnow returnsbool(falseon blocked queue snapshot, failed signal,u64::MAXdevice removal, or 2 s timeout).place_on_pagesandremap_if_unmappedabort and fall back cleanly instead of promoting unordered.bind_rangeis transactional:copy_promoted_tilesruns before mutatingpages/extra_pages. On copy failure, newly allocated local tiles are returned to the pool (or cooled if a partial chunk was submitted), existing L0 pages remain untouched and uncooled, aliases andHeldUnmapare untouched, andbind_rangereturnsNone.TilePromoterring:copy_promoted_tilesuses a 4-slot ring (PROMO_SLOTS = 4) of 0-VRAM scratch resources/allocators so normal promotions submit asynchronously onPages::queuewith zero CPU wait while holdingPAGES; it only waits if a ring slot's own prior copy has not yet passedPages::fence.None, L0 tile/user count intact,coolingempty,HeldUnmap::stale_mapping == false, and L0 texels still readable on GPU) pluswait_marks_with_timeout_fails_closed_on_timeout_and_device_removal.BC7_UNORM256×256 tile preservation check (promoted via anR32G32B32A32_UINT64×64 RT at the same VA, verifying byte-for-byte equality across the entire 64 KiB tile) andextra_pagespromotion check.sparse.rs):State::take_tileskips retired L0 pools once VRAM pressure has ended (!spill_l0) so they drop instead of staying in system memory.AI use: Antigravity (Gemini 4 Neon) implemented the fail-closed promotion, 4-slot async
TilePromoterring, retired L0 sparse pool skip, and expanded tests, ran the tests and 60 s smoke, and drafted this reply.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T11:03:34Z.
Follow-up review (head
c30b3f67, since2d72aa60, diff read, not a merge-check):drain_device_queuesreturns early: fixed. It returnsfalseon a blocked snapshot, a failed signal, device removal or the 2 s timeout (vram.rs~2759-2810), and both callers then drop the promotion instead of copying (~3005, ~3197); see the new point for what that leaves.PAGES: partly fixed. The copy uses a ring of 4 slots and waits underPAGESonly when a slot's previous copy is still running (~2446-2474), but theXCL_L0_VRAM_MARGIN_MB=12288run is one sentence with noxcl-smokeblock, frame count or sign it reached a promotion, and each promotion still waits up to 2 s for every title queue.l0_page_promotes_in_place_to_local_when_target_binds_same_va(~6804) promotesextra_pagesand reads both resources back, and step 1b (~6629) checks the rollback when the copy fails; nothing covers a lazy-level texture inremap_promoted(~2552-2575) or the per-level re-map inremap_if_unmapped(~3141-3163).sparse.rsspill and the texture-pool spill with its promotion could be separate PRs.New:
place_on_pagesreturnsNone(~3005-3009) andplacefalls back to an arena (~3909-3925), so the render target gets its own memory at that address while the sampled alias stays on the L0 page, the split from the first review, now on every 2 s timeout. Inremap_if_unmapped(~3197-3199) a superseded target the title uses again is left withmapped == falseand no tiles, andplacements::map_againignores the result (placements.rs~477-481), so its draws are dropped; that up-to-2 s wait also runs withREGISTRYheld, including fromnote_useon the title's recording thread (placements.rs~556).Fine:
drain_device_queuesholdsPAGESonly for the snapshot; a ring slot waits for its ownPages::fencevalue before its allocator is reset andPages::queuewaits on no other queue, so theINFINITEwait cannot deadlock; a promoter whose signal failed is leaked; the old L0 tile cools only after the copy is onPages::queue, and title queues wait forPages::fence; with the variable unset everything stays gated.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-02T11:06:33Z.
Thanks for the re-checks — every real safety issue raised across the earlier passes is now resolved on
c30b3f67:None/false(leaving the L0 page and its texels untouched rather than silently wiping them) is the deliberate fail-closed trade-off requested in review. On a healthy GPU,drain_device_queuescompletes in milliseconds; the 2 s timeout is only a safety net so a stalled title queue cannot hangCreatePlacedResourceindefinitely.vram.rsandsparse.rswith the rest being the GPU pixel-readback, 64 KiBBC7_UNORM,extra_pages, and fail-closed unit tests added in response to review.XCL_L0_VRAM_MARGIN_MBunset (0), every new path is gated off and behavior matchesmain.Leaving this parked at
c30b3f67for human maintainer review and merge-check — no further bot-review iterations planned unless a maintainer asks for changes.AI use: Antigravity (Gemini 4 Neon) drafted this reply.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:15:29Z.
Code review location:
crates/xcl/src/hle/d3d12x/vram.rs; line 3005High: When a GPU-owned target's promotion fails (drain timeout, blocked queue snapshot, or a failed copy),
place_on_pagesreturns None andplaceputs the RT/DS/UAV in an arena instead of on the shared console pages. With XCL_L0_VRAM_MARGIN_MB > 0, a sampled texture at VA X on L0 pages followed by an RT at X while any title queue is busy for 2 s (or the queue snapshot is blocked) makesdrain_device_queuesreturn false, soplacefalls back toARENAS.take_forand the RT gets its own memory. Draws into the RT are then no longer seen through the sampled alias at the same console address, so the title samples stale texels. On main this binding always shared the page. Placing the target on the L0 pages unpromoted (and retrying later) would keep the aliasing.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:15:29Z.
Code review location:
crates/xcl/src/hle/d3d12x/vram.rs; line 3197High:
remap_if_unmappedcan now block up to 2 s indrain_device_queues, and it's called fromplacements::map_againwhile the placements registry lock is held. On timeout it returns false and leaves the superseded texture unmapped. When the newer placement shadowing an RT at an L0-backed VA is released, every other thread creating a placement (placements::placed) waits behind the 2 s poll. If any queue's work doesn't finish in 2 s (or waits on a fence a blocked title thread would signal), the drain fails and the resource keeps NULL tile mappings, so the title reads zeros from a texture that was valid on main. Remapping to the existing L0 tiles without promoting, when the drain can't complete, would avoid both.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:15:29Z.
Code review location:
crates/xcl/src/hle/d3d12x/vram.rs; line 2730High: Not certain about this one: promotion cools the old L0 tiles right away, even though pending HeldUnmap resources (marked
stale_mappingonly) and in-flight title work still map those tiles, which breaks the rule that a tile is released only after the held marks complete. If a superseded sampled texture is held-unmapped with marks still outstanding under heavy GPU load, and an RT promotes its pages, the old L0 tile goes to cooling atnow. After COOL (2 s) it can be reused for a new texture while the held resource is still mapped to it, so in-flight work through the held resource reads or writes another texture's memory. Cooling those tiles only after the held marks complete would keep the rule.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:15:29Z.
Code review location:
crates/xcl/src/hle/d3d12x/vram.rs; line 3207Medium: After dropping PAGES to drain and locking it again,
remap_if_unmappedrechecks onlymapped, notheld_unmaps, so it can bind a resource that became held-unmapped meanwhile. If another thread remaps during the drain window and thenunmap_placedholds the same resource (mapped=false, a new HeldUnmap holdingused), the resumed call binds again, adding a second set of page users, and overwritestarget.used. When the held unmap completes it unmaps the now-live resource, and the page user counts leak.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:15:29Z.
Code review location:
crates/xcl/src/hle/d3d12x/vram.rs; line 2759Medium: Not certain about this one: the queue drain runs with PAGES unlocked, then PAGES is relocked before the copy, so work submitted in between isn't waited on. If thread A sees
range_has_l0, drops PAGES and drains while thread B'stitle_textures::refreshsubmits an upload into the sampled alias (still mapped to the old L0 tile), thread A then submitscopy_promoted_tileson Pages::queue with no GPU wait on the upload queue. The copy can read the tile before the upload lands, or the upload writes the old L0 tile after the swap, and the promoted page loses those texels.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:15:29Z.
Review: COMMENTED
Review of
c30b3f67: 5 finding(s) (3 high, 2 medium), most severe first.crates/xcl/src/hle/d3d12x/vram.rs:3005: When a GPU-owned target's promotion fails (drain timeout, blocked queue snapshot, or a failed copy),place_on_pagesreturns None andplaceputs the RT/DS/UAV in an arena instead of on the shared console pages. (inline)crates/xcl/src/hle/d3d12x/vram.rs:3197:remap_if_unmappedcan now block up to 2 s indrain_device_queues, and it's called fromplacements::map_againwhile the placements registry lock is held. (inline)crates/xcl/src/hle/d3d12x/vram.rs:2730: Not certain about this one: promotion cools the old L0 tiles right away, even though pending HeldUnmap resources (markedstale_mappingonly) and in-flight title work still map those tiles, which breaks the rule that a tile is released .... (inline)crates/xcl/src/hle/d3d12x/vram.rs:3207: After dropping PAGES to drain and locking it again,remap_if_unmappedrechecks onlymapped, notheld_unmaps, so it can bind a resource that became held-unmapped meanwhile. (inline)crates/xcl/src/hle/d3d12x/vram.rs:2759: Not certain about this one: the queue drain runs with PAGES unlocked, then PAGES is relocked before the copy, so work submitted in between isn't waited on. (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:15:32Z.
@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.