D3D12.X: restore per-level lazy upload cutting and fast region-skipping non-zero scan #3679
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3679"
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:38Z.
level_scan(t ≈ 90..94 s, ~3,000 calls)701.0 ms(254.5 µs/call)134.9 ms(38.8 µs/call, 6.6× faster)level_scan(t ≈ 96..98 s, ~1,700 calls)404.4 ms(217.1 µs/call)43.8 ms(26.1 µs/call, 8.3× faster)level_scan(t ≈ 21..33 s, ~384 calls)2.3–3.3 ms(~7.8 µs/call)0.6–0.8 ms(~1.8 µs/call, 4.3× faster)submit cost(textures, 1024-submit avg)6.57 ms(textures 4.07 ms)4.97 ms(-24.4%,textures 2.69 ms-33.9%)What is in it
#3444'smainmerge ontoamd-dev: brings backlevel_upload,levels_with_texels_where,level_ranges,split_ranges(crates/xcl/src/hle/d3d12x/title_textures.rs) andtexture_upload::unknown_parts(crates/xcl/src/hle/d3d12x/texture_upload.rs). Because8ea8524fre-enabledvram::level_pagesby default right after#3444,amd-dev(41aa60ce) was falling back tomap_levels_with_texels_inon every lazy-level upload — reading and scanning the full multi-MB texture on every partial update, forcingchanged = Nonewhole-texture re-uploads whenever any level mapped, and inflatingbatch_fitsbyte estimates with unmapped top mips. Restoringlevel_uploadbeforebatch_fitsskips empty textures, cuts uploads to mapped levels, tracks per-range unknown hashes (unknown_parts), and packs batches by actual mapped-level bytes.range_any_nonzero_with_skip+PageMap::any_nonzero_with_skip):range_any_nonzero_with_skipuses a zero-copyall_zerofast path whenin_committed_window || sparse::known_readable, probes4 KiBfirst (then64 KiBchunks) onReadProcessMemoryso populated mip levels short-circuit after 4 KiB, and on any uncommitted/no-access/guard page jumps across the entire unreadableVirtualQueryregion in one call while caching(reg_lo, reg_hi)across mip levels of the same texture.PageMap::any_nonzero_with_skipcoalesces contiguous unmapped-mirror fallback runs (p & 1 != 0) into a singlerange_any_nonzero_with_skipcall instead of callingcopy_readable+VirtualQueryonce per 64 KiB page (which accounted for 92% oflevel_scantime on streamed textures in GPU mirror views), and probes4 KiBfirst on mapped physical pages (p & 1 == 0).map_levels_with_texels_indelegates 2D single-slice textures tolevels_with_texels_whereso the non-by_levelfallback benefits from the same fast scan.unknown_parts_clears_only_requested_pages,page_map_any_nonzero_coalesces_fallback_runs_and_skips_uncommitted,range_any_nonzero_skips_uncommitted_reserve_and_guard_pages, andsplit_ranges_partitions_inside_and_outside_cleanly.Tested
32.0.21045.29003), AMD Ryzen 7 5700X, Windows 11 x64,rustc 1.100.0 (0ef1bc386 2026-11-09), debug tests + release smoke.texture_upload::tests::,range_any_nonzero_skips,split_ranges_partitions): 16 passed, 0 failed.cargo test --workspace --no-fail-fast -- --test-threads=4: 2,962 passed, 13 pre-existing failed, 49 ignored (identical pre-existing failures to cleanorigin/amd-dev41aa60ce).T6-PROFsub-timers):level_scandropped 6.6×–8.3× (701.0 ms -> 134.9 ms,404.4 ms -> 43.8 ms), cutting average world-loadsubmit costfrom6.57 msto4.97 ms(-24.4%) andtexturesfrom4.07 msto2.69 ms(-33.9%).Regression run
Base (
main, required bypr_check.py):Base (
origin/amd-devmerge base):PR head (
b9deb01d):Not tested
AI use
#3444merge drop oflevel_upload, profiledPageMap::any_nonzeroandrange_any_nonzeroon the retail workload, implemented the coalesced region-skipping non-zero scan and 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:23Z.
Review (head
b9deb01d, diff read, not a merge-check):level_upload(title_textures.rs~3907) andlevels_with_texels_where(~3819) are on the default path (level pages are on by default), but nothing tests the cut to levels with pages, thelookfilter that skips unwritten levels without pages, the mip-tail block or theunknown_partsbookkeeping.a68f609f5, the commit these come from, had tests for exactly this (levels_are_looked_at_one_by_one_and_their_bytes_are_ranges,levels_with_texels_in_matches_detiled_subresources, and lazy-level assertions that only level 1's bytes go up and that a write changing nothing sends nothing); none were brought back. The four new tests coverunknown_parts,split_rangesand the two scan helpers.4fedcbc8c, #3444) and adds a new scan (range_any_nonzero_with_skip,PageMap::any_nonzero_with_skip) thatmap_levels_with_texels_in(~3984) now uses instead ofChain::level_has_nonzerofor 2D single-slice textures; 429 lines that would review and bisect better as the restore with its original tests, then the scan.amd-dev. Thelevel_scantimer,copy_readableandPageMap::any_nonzerothe description profiles exist neither onamd-dev(41aa60ce) nor in this PR; they are a68f609f5's helpers in a local build, so the table compares the new scan with an intermediate restore. Against the base the only numbers are the smoke run (1654 → 1655 frames, peak commit 15902 → 16173 MB).Fine:
range_any_nonzero_with_skipreads directly only inside the committed window orsparse::known_readableranges and otherwise usesReadProcessMemory, thenVirtualQuerywith the same readable test asread_committed_into, so it does not touch uncommitted or guard pages; its level and tail ranges matchChain::level_bytes, so it cannot miss a non-zero texel; thePageMapfallback keeps runs contiguous; 3D and array textures behave as onamd-dev.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:53:31Z.
merge-check
base:
41aa60ce84head:
b9deb01dc5merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2965 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/3679#issuecomment-7340182405 and its findings stand. Most serious:
level_upload/levels_with_texels_where(default path) come back without a68f609f5's tests, and the restore and the new scan share one 429-line PR.performance: 60 s smoke of a retail title, amd-dev
41aa60cevs this merge (b9deb01d): 1671 -> 1687 frames shown (100 %; last presents per 2 s: 60 61 60), peak commit 16722 -> 16728 MB, 0 device removals, 0 crashes.verdict: not yet:
level_upload/levels_with_texels_where(default path) come back without a68f609f5's tests, and the restore and the new scan share one 429-line 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.
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.