D3D12.X: pre-reclaim completed upload jobs and keep one buffer per normal size class #3678
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3678"
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 iggyvilla on 2026-12-02T08:52:35Z.
t ≈ 20 s)85.9 ms(12misses /239 MB)29.9 ms(7misses /95 MB)takemisses (t = 21..102 s, 9 windows = 1,152 batches)158.0 ms(11misses /352 MB)0.0 ms(0misses)takemisses (t = 106..119 s, 384 batches)309.4 ms(31misses /554 MB, pre-reclaim only)70.2 ms(15misses /107 MB, 4.4× faster)XCL_UPLOAD_KEEP_MB, default64 MiB)64 MiB64 MiB(unchanged)What is in it
crates/xcl/src/hle/d3d12x/title_textures.rs: insubmit_on, non-blockingly reclaim already-completed upload jobs (reclaim(q, u64::MAX, 0)) intotexture_upload::FREEviareturn_for_reusebefore callingtexture_upload::submit->take(), instead of only reclaiming aftersubmit(which previously forcedtake()to allocate a new 32 MiB staging buffer while a completed 32 MiB buffer sat inq.in_flight, then immediately dropped the old one). An RAIITrimGuarddeclared before the queue lock guaranteestexture_upload::trim_free()always runs outside the queue lock even on early returns or errors.crates/xcl/src/hle/d3d12x/texture_upload.rs: splitgive_backintoreturn_for_reuse+trim_freeand refinetrim_freeeviction (pick_eviction_victim): (1) drop oversized one-off bursts (> 32 MiB, aboveBATCH_BYTES) largest-first, (2) drop duplicate size classes on the same device largest-duplicate-first so one buffer per normal power-of-two size class (32 + 16 + 8 + 4 + 2 + 1 = 63 MiB <= 64 MiB) stays resident simultaneously without repeatedly evicting the sole32 MiBbatch buffer, and (3) fall back to largest remaining whenXCL_UPLOAD_KEEP_MB < 64. Adds pure unit testfree_eviction_drops_oversized_bursts_and_duplicates_before_unique_normal_sizes.Tested
32.0.21045.29003), AMD Ryzen 7 5700X, Windows 11 x64,rustc 1.100.0 (0ef1bc386 2026-11-09), debug tests + release smoke.cargo test --lib -p xcl hle::d3d12x::texture_upload::tests:: -- --test-threads=4: 13 passed, 0 failed (includingfree_eviction_drops_oversized_bursts_and_duplicates_before_unique_normal_sizes).cargo test --workspace --no-fail-fast -- --test-threads=4: 2,959 passed, 13 pre-existing failed, 49 ignored (identical pre-existing failures to cleanorigin/amd-dev41aa60ce).T6-PROFsub-timers): eliminated all11load-phasetakemisses across 1,152 consecutive batches (158.0 ms -> 0.0 ms) and cut heavy in-worldtakemisses by 4.4× (309.4 ms -> 70.2 ms).Regression run
Base (
main, required bypr_check.py):Base (
origin/amd-devmerge base):PR head (
cfb59651):Not tested
AI use
texture_upload+submit_onon the retail workload, implemented pre-reclaim and duplicate-awareFREEtrimming with unit tests, ran the workspace GPU suite and 60 s smoke, and drafted this PR description.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T08:58:06Z.
Review (head
cfb59651, diff read, not a merge-check):submit_onhas no test. The only new test coverspick_eviction_victim(texture_upload.rs~1572). Nothing tests the newreclaim(q, u64::MAX, 0)+return_for_reusebeforetexture_upload::submit(title_textures.rs~3435): neither that a completed in-flight job's buffer is reused by the nextsubmit_on, nor that a job whose fence has not completed stays inin_flight. The existingsubmit_onGPU tests (~5180, ~5395) have the setup to check that a second upload after a completed one gets the samebuf.take()(~3432) and the newtrim_freeeviction order (texture_upload.rs~928-968) are independent and both always on; the description's own table measures them separately (its in-world "Before" is "pre-reclaim only", notamd-dev). The eviction order now drops many small duplicate buffers before a unique 32 MiB one, which changes what stays resident for every title; as its own PR each could be measured againstamd-devand reverted alone.Fine: the pre-reclaim uses the same fence check as the existing post-submit reclaim: with
cap = u64::MAXandwait_ms = 0,reclaimonly pops jobs whose fence has completed, so it never hands back a buffer the GPU still reads;TrimGuardis declared beforeslot, so trimming runs after the queue lock is released on every exit path; the idle cap is unchanged and the newFREElocking under the queue state does not invert any lock order.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-02T12:31:57Z.
merge-check
base:
41aa60ce84head:
cfb596517cmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2962 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev
41aa60cealone on this card, so none is from this PR)review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3678#issuecomment-7340176210 and its findings stand. Most serious: nothing tests the new default-path pre-reclaim in
submit_on(~3432), and two independent default-path changes share one PR.performance: 60 s smoke of a retail title, amd-dev
41aa60cevs this merge (cfb59651): 1671 -> 1635 frames shown (97 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 16795 MB, 0 device removals, 0 crashes.verdict: not yet: nothing tests the new default-path pre-reclaim in
submit_on(~3432), and two independent default-path changes share one PR (see the review)hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by grathepic on 2026-12-03T02:31:22Z.
merge-check claim
head:
cfb596517cImported from ivall/xcl. Originally posted by grathepic on 2026-12-03T03:08:03Z.
merge-check
base:
41aa60ce84head:
cfb596517cmerge: clean
build: cargo build --workspace -> ok (cargo +1.98.1-x86_64-pc-windows-msvc build --offline --locked --workspace; 46 pre-existing lib warnings, 0 new)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2960 passed, 10 unique failed (12 including 2 nested child-process summaries), 49 ignored; SKIPPED: 27 (19 no wave64, 3 per-lane form refused (#1426 semantics), 2 no heap windows, 1 no dxil.dll, 1 no GPU_UPLOAD heaps, 1 cannot disable the driver cache (Windows Developer Mode required)); failing:
gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu,gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk,gpu::recomp::tests::gpu_fract_f32_edges,hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping,hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels,hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held,hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads,hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload,hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones,two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs(gpu_two_pass_cache_e2e) — all 10 ran and failed identically on cleanorigin/amd-dev(41aa60ce) alone (0 new failures). All 13hle::d3d12x::texture_upload::tests::passed in 3.42 s (0 skips), includingfree_eviction_drops_oversized_bursts_and_duplicates_before_unique_normal_sizes.title run: none (no retail title folder on this machine; runtime change in
crates/xcl/srcoutside tests still needs an in-world run)review: Read full diff (
crates/xcl/src/hle/d3d12x/texture_upload.rs+71/-2,title_textures.rs+25/-4) and surrounding code.pick_eviction_victimis tested. Nothing testssubmit_on's pre-reclaim (reclaim(q, u64::MAX, 0)+return_for_reusebeforetexture_upload::submit), verifying that a completed in-flight job's buffer is reused before allocating a new one, that an incomplete job stays inin_flight, or thatTrimGuardtrims excess buffers on early return/error.take(), and changingtrim_free()from largest-first to duplicate-aware size-class eviction), which the PR's own measurement table evaluates separately.reclaim(q, u64::MAX, 0)breaks immediately on the first incomplete fence without sleeping and only pops completed jobs;TrimGuardis declared beforeslot, soslotis always dropped beforetrim_free()runs on every exit path, preserving lock order (slot->FREE->SPARE) and dropping D3D12 buffers outside locks;NORMAL_MAX(32 << 20) matchesBATCH_BYTESintitle_textures.rs. Minor non-blocking nit: intitle_textures.rs:3459-3463,return_for_reuse(retired)still locksFREEeven whenretiredis empty and onlytrim.0is true.#1607groups before and after testing; no duplicate found (#3050addsXCL_UPLOAD_KEEP_MB,#2912handles cross-queue reclaim andq_releasecleanup).performance: idle upload cap (
XCL_UPLOAD_KEEP_MB, default 64 MiB) is unchanged, so peak idle staging memory does not increase; pre-reclaim avoids an extra transient allocation when a completed buffer sits inin_flight;pick_eviction_victimis O(n^2) overFREEentries (tiny N under 64 MiB cap) and changes which size classes remain resident by default (unmeasured on a retail title here).verdict: not yet: missing test coverage for the new default-path pre-reclaim /
TrimGuardinsubmit_on, bundles two independent default-path changes in one PR, and no retail title run on this machinehardware / tool and model: NVIDIA GeForce RTX 3080 (driver 32.0.16.2140), AMD Ryzen 7 5800X3D, Windows 11 (10.0.26300.0), rustc 1.98.1 (48a229cea 2026-09-01, 1.98.1-x86_64-pc-windows-msvc), DXC 1.9.0.5512 (VulkanSDK, no dxil.dll) / Antigravity, Gemini 4 Neon
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.