D3D12.X: preserve live texture aliases during L0 promotion #3745
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3745"
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 jeroenhaentjens on 2026-12-02T23:57:15Z.
What & Why
Stacked on #3740 at
2ff33838. Only the top commit belongs to #3745. Preserve the contents and overlap of eligible live aliases when creating a render target that requires local backing. #3620 offers related promotion under XCL_L0_VRAM_MARGIN_MB. This PR builds on #3740's sampled TextureBudget policy and protects the tile move at native submission boundaries.What is in it
Tested
eced294121. Intel Core i7-9750H, NVIDIA Quadro RTX 3000 (driver 597.06 / 32.0.15.9706), Windows 11 25H2 build 26200.9974, Rust MSVC 1.100.0 and DXC 1.9.2609.5.Regression run
Baseline (main)
PR head
Not tested
AMD, Intel discrete GPUs, Linux and retail titles.
AI use
OpenAI Codex (GPT-6, specific revision unavailable) assisted with the implementation, tests and PR update. The author reviewed the diff and the recorded test results.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T00:05:10Z.
Review of
9bc13632(code reading only, not a merge-check; draft) · 2 high, 4 mediumIn short: Stacked on #3740; only the top commit
9bc13632belongs here, and it is reviewed alone. It adds a per-device admission gate on native queue submits. When a render target lands on sampled L0 tiles, it copies every live alias out, remaps the shared tiles to local memory and copies the data back. Everything is behindXCL_TEXTURE_BUDGET=1, so the default path is unchanged. Two things block it:KickoffXsubmits bypass the gate, and a busy gate now fails the title's resource creation where the base fell back.High
KickoffXsubmits bypass the promotion gate.kickoff_xsubmits the title's lists through the originalExecuteCommandListsinsidequeue_submit::with(list_x.rs~5515 for the earlier lists, ~5560 for the current one). Onlyq_execute_command_lists,native_queue_executeand the mapping copy go throughvram_promotion::submit(real.rs~1177, ~12052, ~12103).Gate::closecannot seeKickoffXwork in flight, because no mark fence is signalled for it, and it does not hold back aKickoffXsubmit while the backup, remap and restore run.KickoffXcan read or write the L0 tiles while they are copied and remapped.Fix: route both
KickoffXsubmits throughvram_promotion::submit(q_raw, ...), and check that no other title submit path calls the native slot directly.A busy gate now fails the title's resource creation.
BindFailure::Busycomes from:Gate::closemissing its 50 ms deadline (vram_promotion.rs~121 calls that the expected result on a busy device);promotingrange (vram.rs~3025);missing_receipt, which is set at ~114 and never cleared, so one failedCreateFenceorSignalmakes every later promotion fail.place_on_pagesturnsBusyintoSome(E_OUTOFMEMORY)(vram.rs~3324).place(~4183) returns it instead of trying the arena fallback, andCreatePlacedResourceXhands it to the title (device_x.rs~1284).Noneand fell back. Each failed attempt also stalls the creating thread for up to 50 ms.Fix: treat
BusylikeUnavailable, or retry, and resetmissing_receiptonce a submit records its mark.Medium
unmap_placedreturns at once whenevertexture_budget::enabled()(vram.rs~3357). That covers everyunmap_superseded/unmap_superseded_targetcaller invram.rsandtitle_textures.rs, not only aliases a promotion leased. A title that reuses an address without releasing the old texture keeps all its tiles until the release. Limit the change to the aliases that need it, or describe it and measure its memory cost.local_pinnedonly grows. Addresses are only ever added (vram.rs~2978), and nothing removes them when the pages are freed or recycled. After one promotion, every later sampled texture at that address is forced to local memory for the rest of the run, slowly undoing the L0 budget for addresses titles reuse. Drop the entries when the page goes away.texture_budget_native_alias_promotion_after_producer_completion(vram.rs~4504) callsbind_rangeandPages::mapand records its own copy lists. It never callsbind_eager,promote_tilesor the gate, so it tests the driver, not this PR, though the description presents it as confirming preserved data.vram_promotion.rsand the submit hooks, inert until used), then the promotion.XCL_L0_VRAM_MARGIN_MB: it promotes an L0 page to local in place when a target binds it, drains the queues first, and remaps every live alias. Both rewrite the same bind path invram.rs, so only one mechanism should land.Checked and fine
XCL_TEXTURE_BUDGETunset,vram_promotion::submitfalls through toqueue_submit::with, andnative_queue_executecalls the same native slot.lock_tracked_srv_lifetime,unmap_placedandforget_promotion_resourceare gated on the flag.bind_eagerwithout the budget does what the oldPages::binddid.ACTIVElist. Theepochre-check stops a submit from slipping in between the fence snapshot and closing the gate.native_mapping_copy_execute), with CPU fence waits and no GPU wait on a title queue.Unavailableand falls back. A failed backup or restore ends the title, after leaking the native objects the driver may still use.promotion_stateusestry_lockonTEXTURES, so it does not wait on a submitter blocked at admission.texture_budget_promotes_four_live_rt_aliases_with_readbackrunsbind_eagerthrough the gate, with four aliases and a submit blocked during the promotion. README updated.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-03T08:05:35Z.
@Foniass rebased on #3740 at
1a2bef6. Both KickoffX submits are gated, a new receipt from the same queue clears its block, and a busy promotion can fall back to an arena. Supersession waits only for leased aliases, and local pins disappear when the last page user releases them. The second native fixture now checks the actual timeout, arena and promotion paths. The description identifies the top commit and the overlap with #3620.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T08:12:12Z.
Follow-up review of
55057068, since9bc13632(code reading only, not a merge-check) · 2 high, 3 mediumIn short: Stacked on #3740 (now at
1a2bef64); only the top commit55057068belongs here. Since9bc13632:KickoffXpaths go through the promotion gate;local_pinnedentries go with the last page user;bind_eager, the gate timeout and the fallback.Two gate problems remain: XCL's own texture uploads still reach the title queue without passing it, and a deferred unmap can deadlock with a title
Signalwaiting for admission.High
Texture uploads still bypass the gate.
prepare_title_submissionruns before admission (real.rs~12091,list_x.rs~5497). Its uploads go throughtexture_upload::submit→sparse::pc_execute(texture_upload.rs~877,sparse.rs~5218-5225), which calls the nativeExecuteCommandListsinsidequeue_submit::with, notvram_promotion::submit.Gate::closedoes not wait for an upload in flight, and an upload prepared while the gate is closed is not held back.knownstill records the upload as sent, so the texture stays wrong until the next CPU write.Fix: route
pc_executethroughvram_promotion::submit(it re-enters correctly when nested in an admitted submit), or take admission beforeprepare_title_submission.A deferred unmap can deadlock with a title
Signal.Signalpath takes the queue turn first (real.rs~11741). Inside it,submit_prepared_downloadsreachesTextureDownloadPlan::submit→native_queue_execute(title_textures.rs~3819). With the budget on, that waits atGate::enterwith no limit (vram_promotion.rs~96).PromotionRange::drop(vram.rs~2864) runs the deferredunmap_placed. That signals each active title queue throughnative_queue_signal, which needs the same queue turn.Fix: run the deferred unmaps after
closedis dropped inbind_eager, or take admission before the queue turn in theSignalpath. Nothing tests the deferred-unmap path yet.Medium
remap_if_unmapped(vram.rs~3471) callsPages::binddirectly. With #3740's live-L0 refusal,bind_rangereturnsNonefor a render target over a live L0 page, and both callers ignore that (placements.rs~480,title_textures.rs~1043), so a superseded target taken back into use stays unmapped. Promotion runs only inbind_eager, fromplace_on_pages. The README line ("For supported live aliases, XCL waits ... remaps the aliases to local tiles") claims more than the code does. Cover this path, or say that only creation is covered.vram_promotion.rsand the submit hooks), then the promotion. The description now names #3620, but both rewrite the same bind path invram.rsfor the same case, and only one should land.hle::d3d12x::vram::testsandhle::d3d12x::vram_promotion::tests(91 passed, 1 ignored). This change hooks every native submit path underXCL_TEXTURE_BUDGET=1. Reportcargo test --workspace -- --test-threads=4.Checked and fine
KickoffXsubmits bypassed the gate. Both usevram_promotion::submitnow (list_x.rs~5515, ~5560).E_OUTOFMEMORY.place_on_pagesreturnsNoneon any failure (~3347), and the fixture checks the arena takes over after a gate timeout.missing_receiptwas never cleared. It is now kept per queue and generation, and a later receipt on the same queue clears it, with a test.unmap_placedskipped every unmap under the budget. Only aliases inleased_aliasesare deferred now, and they are replayed when the range is dropped (~3395).local_pinnedonly grew. An entry goes when a page's user count reaches zero inrelease_tiles(~2595), as the fixture checks.bind_eager, holds a producer throughGate::submit, checks the timeout counter and the arena fallback, then promotes and reads back.XCL_TEXTURE_BUDGETunset, the submit hooks fall through to the previous calls.bind_range.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-03T13:14:06Z.
@Foniass Texture upload submits through sparse::pc_execute now acquire promotion admission before the queue turn. Deferred unmaps are replayed after the gate opens. The native regression holds a queue turn during promotion and checks that the deferred unmap completes, the upload survives and the render target shares the promoted tiles. The README scopes promotion to creation, and the complete workspace result is in the PR.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T13:20:13Z.
Follow-up review of
100cac75, since55057068(code reading only, not a merge-check) · 1 high, 1 mediumIn short: Stacked on #3740 (now at
2ff33838); only the top commit100cac75belongs here. Since55057068:One new problem: a deferred unmap is replayed without checking whether the title used the texture again meanwhile, so a texture in use can lose its tiles. The size and the overlap with #3620 are still open.
High
A deferred unmap can unmap a texture the title is using again.
placements::unmap_if_superseded(placements.rs~541) checks under the registry lock that the target is still superseded before unmapping it, so the unmap and a lateruse_againstay in order.unmap_placedonly queues a leased alias inunmaps_after_promotion(vram.rs~3407-3410), and the target staysmapped.note_use(placements.rs~566-570) callsremap_if_unmapped. That returnstrueat once because the target is still mapped (vram.rs~3456-3458), anduse_againmarks it live. The same happens throughsettle→map_againwhen the newer placement is released.bind_eagerthen replays the queued unmap anyway (~3101). The texture loses its tiles while the registry counts it as mapped and no longer superseded, so nothing maps it again.Fix: let
remap_if_unmappedcancel a queued promotion unmap, as it already cancelsheld_unmaps(~3460), or replay through a check that the target is still superseded. Add a test where the alias is used again between the deferral and the replay.Medium
vram_promotion.rsand the submit hooks), then the promotion invram.rs. The description names #3620, which is still open; both rewrite the same bind path for the same case, so only one should land.Checked and fine
pc_executenow usesvram_promotion::submit(sparse.rs~5226), so each upload gets a mark and waits while the gate is closed. The fixture sends an upload throughpc_executeand checks the timeout and the arena fallback.Signal.PromotionRange::droponly moves the queued unmaps out, andbind_eagerdropsclosedbefore replaying them (~3100). The fixture holds the producer's queue turn while it waits for the gate to reopen.used, so it is never leased.XCL_TEXTURE_BUDGETunset,pc_executefalls through toqueue_submit::withas before.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-03T14:22:55Z.
@Foniass Reactivating a leased alias now cancels its pending unmap through the replay handoff. The regression checks the retained tile ownership and reads back the preserved contents. The timeout fixture holds a CPU admission slot while the explicit test budget exercises the deadline, so adapter-specific budget admission cannot bypass the assertion. The workspace results and smoke evidence are in the PR.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T14:25:20Z.
Follow-up review of
eced2941, since100cac75(code reading only, not a merge-check) · 2 mediumIn short: This push fixes the high finding from the last review. A deferred unmap that the title cancels by using the texture again is now dropped before it can run. The new fixture step covers that case, and the fallback-timeout part of the fixture now holds the admission slot itself. Still stacked on #3740 at
2ff33838. The size and the overlap with #3620 remain open, and the regression run uses the repository's test fixture, which does not reach this code.Medium
xcl-owned-test-fixture, which shows 1 frame (presents per 2 s: 0 0 0), with no setting given. The promotion and the gate only run withXCL_TEXTURE_BUDGETset, so they never run in this check. CONTRIBUTING.md asks for the regression run on a real title. Add a pair of runs on a title, made onmainand oneced2941, ideally with the opt-in on.vram_promotion.rsand the submit hooks), then the promotion invram.rs. #3620 is still open and rewrites the same bind path for the same case, so only one of the two should land.Checked and fine
Arcthat stays inunmaps_after_promotion.PromotionRange::droponly hands clones to the caller.remap_if_unmapped(vram.rs~3463) removes every queued request for the resource. It is the path bothnote_useandmap_againtake.bind_eagerpasses the request tounmap_placed, which returns unless it can still find thatArc(Arc::ptr_eq, ~3410).mapped = falseupdate all happen under onePAGESlock. So a use is ordered either before the replay (the replay is cancelled) or after it (the use remaps the texture).drop, becauseleased_aliasesis cleared there.remap_if_unmappedand then replays. It checks that the alias stays mapped with the sameusedtiles, and that the queue is empty.Gate::with_active_submit(test only) whilebind_eagerruns. It checks forBindFailure::Busyand one more timeout before the arena fallback, then sends the upload.auto. The existing skips (no Debug Layer, no sampled L0 tile heap) still apply there. Tested says the fixture passes on the Microsoft Basic Render Driver.eced2941(3017 passed, 0 failed, 52 ignored, 26 SKIPPED).Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Gevroska on 2026-12-03T17:45:36Z.
@jeroenhaentjens I tested queue replacement on
eced2941. The registered-queue control waited for the old fence as expected. I found two cases worth checking separately.I tried using the queue lease generation for the receipt and removing completed retired marks after validating the full prefix. The replacement then received its own mark at 1, the old fence stayed at 0 until its own completion, and the 16 retired marks dropped to zero. Same-queue signal recovery still passed.
These were controlled Windows tests with stand-in fences. The fixture explicitly drove queue creation and final release through the lease registry. I haven’t observed native D3D12 address reuse or measured GPU memory impact.
AI disclosure: OpenAI Codex GPT-6.2 Sol tested the PR and wrote the local correction. An independent Codex reviewer repeated the comparison. GPT-6.2 Astra drafted this comment.
I reviewed and approved this comment before posting.
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.