D3D12.X: defer GPU-owned target pages until first use #3395
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3395"
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 lnqigr on 2026-11-29T13:06:45Z.
Stacked on #3443; only the top commit (
bdf38bf4) belongs here.Adds opt-in
XCL_LAZY_TARGETS=1. GPU-owned placed targets bind their 64 KiB video-memory tiles at first use, so a title can create render targets without allocating tiles it may never use. Related to #3211 and #1773.What is in it
vram.rs. Bind the tiles before command-list or upload use.for_each_declared_table_slotinbind.rs), not only in the first 64 slots of each table. Test:lazy_targets_are_mapped_in_every_declared_table_range.README.md.Tested
6a4c17fd, the four-thread workspace run aborted in the PSO library tests on the test fixture address0x4332. The two-pass cache integration test failed once and passed on the repeat. The full library target passed on the main baseline. The parallel failure on the candidate remains unresolved.cargo test --offline --locked --workspace --no-fail-fast -j 4 -- --test-threads=1 --show-outputcompleted with 2,621 passed, 0 failed, 49 ignored, and 30 SKIPPED reports.SKIPPED). The command-list refusal test passed in both four-thread attempts.bdf38bf4(this commit on #3443's7afecf84):.\scripts\test.ps1(cargo test --workspace -- --test-threads=4) completed with 2,743 passed, 0 failed, 49 ignored, and 31 SKIPPED reports. The new table-range test fails when the old 64-slot walk is put back (it finds the view at slot 10, not the one at slot 100).cargo build --offline --locked --release -p xcl -j 4and 60 s ofscripts/smoke.ps1on titledc7b94e1for each configuration. On6a4c17fd, enabling the flag reduced local VRAM from 6,057 to 3,048 MB (−3,009 MB, −49.7%) and target-pool capacity from 3,584 to 576 MB at the final activity sample. The PR blocks below are frombdf38bf4, without input; on that run the flag lowered peak commit from 16,363 to 13,323 MB.Regression run
Main baseline
PR head with the flag off
PR head with the flag on
Not tested
AI use
Antigravity (Gemini 4 Neon) wrote the original implementation and GPU tests, and ran the initial benchmarks. Codex (GPT-6) reviewed it, implemented the allocation-failure handling and its regression test, ran the final tests and smoke checks, and edited this description. Claude Code (Claude Opus 5.5) moved the commit onto #3443, made the lazy-target scan walk the declared table ranges, added its test, reran the suite and the two PR smoke runs, and updated this description.
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T13:37:37Z.
Ran the lazy-target deferral tests at
6a4c17fdon an NVIDIA Blackwell desktop part.System
Results
XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu_lazy_target_defers_vram_until_first_use_and_renders_correctly -- --test-threads=1: 1 passed, 0 failed, 0 ignored. The GPU test ran here, with no SKIPPED line.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib target_view_copy_pieces_and_table_follow_handles -- --test-threads=1: 1 passed, 0 failed, 0 ignored.What this adds
Both tests pass: VRAM for a GPU-owned placed target is deferred until first use and the render still reads correctly, and copied RTV/DSV handles follow the target views. The thread has no comments yet, so this is the first datapoint in it and the first from an RTX 5070 Ti. Synthetic GPU tests only; no title run.
Not tested
A retail title, a paired smoke run, the full workspace suite here, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.
Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-29T22:40:07Z.
A note from reading
6a4c17fd(code reading, not a run):ensure_table_lazy_targetsinhle/d3d12x/bind.rs(around lines 1567-1601, called frombind.rs~5256 andconsole_list.rs~1056) checksreadable(base, 64 * 32)and then loopsfor k in 0..64usize, so it only looks at the first 64 slots of eachParam::Table. A lazy GPU-owned target bound past slot 64 (a bindless SRV/UAV range or an explicit offset) would never reachvram::ensure_target_mapped, so withXCL_LAZY_TARGETS=1its tiles stay unmapped: writes dropped, reads zero.#3443 (Lakanya, open) handles the same kind of fixed slot cap in the superseded-target scan: it records each table's declared SRV/UAV ranges (
Layout::table_ranges), caps unbounded ranges withconsole_heap::view_heap_remaining_slots, and scans in 256-slot chunks (scan_superseded_in_tables_with). Walking the declared ranges the same way here (skipping CBV and sampler ranges) would close the gap without touching the rest of the deferral.AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 3.8 Flash; I checked the lines above against the pinned commit.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:01:54Z.
Review (head
bdf38bf4, diff read, not a merge-check; draft, off by default (XCL_LAZY_TARGETS=1turns it on),PR descriptionred):bind.rs~5362), and targets the title never uses never get tiles. The scan is #3443's: unbounded ranges are read to the end of the view heap, the globalHEAPSlock is taken per table, and there are twoLAZY_UNMAPPEDlookups per view. For a heap of 1M descriptors that is 32 MB read per bind. The smoke runs are capped at 60 fps, so this is unmeasured.list_x.rs~6454) are the only other net.real.rs~4125 / ~4131 now read the poison flag afterflush_two_passandbefore_close, and a poisoned list skipsnote_list_closed. It isn't in the description and has no test.PAGESlock, possibly creating a 64 MiB pool heap mid-frame. Before, that happened when the target was made. The ordering is sound: mappings go on the dedicated queue, andbefore_executemakes the submitting queue wait.ensure_target_view_mappeddirectly. No test goes through the hooked set-targets, barrier, copy or clear paths.vram.rs~5893 raisesLAZY_UNMAPPED_COUNTfor the whole process, which turns the lazy paths on for tests running beside it. ~5929 sets the test flag before the skip check. Either may explain the four-thread abort the description mentions (unverified).6a4c17fd, not this head.vram.rstracking, not yet called, with its tests;cl_closepoison change, with a test;page_ownersstats.Fine: off by default, with one relaxed atomic load per hook. Two threads mapping one target are serialised under
PAGES. A failed allocation poisons the list and KickoffX refuses it. Copies of RTV / DSV handles are tracked, and release bookkeeping is right. The two red CI runs arestandin::tests::concurrent_shell_miss_..., which main fixed in54544682(not in this PR's base).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-01T09:53:43Z.
Triage (#1607) – head
bdf38bfStacked on #3443: the lines shared with it are #3443's commit (
7afecf84), and onlybdf38bf4belongs here, so it is not a duplicate. Read the top commit.XCL_LAZY_TARGETSis opt-in, but two default-path changes come with it, both inreal.rs.cl_closenow reads the poison state afterflush_two_pass/before_closeand skipsnote_list_closedfor a poisoned list. The KickoffX/Close warnings no longer name the cause.ensure_target_mappedbinds tiles while a list is recording. The diff does not show how the tile mapping is ordered before that list runs on the GPU, asvram::before_executedoes for level pages.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T15:18:28Z.
Queued an in-world A/B of this on an RTX 4080 16 GB: current
main+ this headbdf38bf4, same build withXCL_LAZY_TARGETSunset vs=1, 900 s each withXCL_RESIDENCY_PRIORITY=1andXCL_GPU_PROFILE=1. Our runs are ~3.3 GB over the video-memory budget with render targets the largest part (~6.4 GB), so this is the case it targets; numbers here when done.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T16:37:34Z.
In-world result, RTX 4080 16 GB (621.40), current
main6bfb5c51+ this headbdf38bf4(plus our local input-timing patch), same build, 900 s each,XCL_RESIDENCY_PRIORITY=1, default two-pass reserve, no draws skipped in either run:XCL_LAZY_TARGETSSo it saves about 1.1 GB of video memory (render-target pages 6.6 → 5.4 GB at the end of a run) but costs ~16 % presents/s here, where the card stays over budget either way. No device removal or crash. (An earlier pair at
XCL_TWO_PASS_MB=512is not comparable: that limit made XCL skip 41 % of draws in the run without the switch and 1.4 % with it.)AI use: Claude Code (Claude Opus 5.5).
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.