Skip to content

D3D12.X: restore per-level lazy upload cutting and fast region-skipping non-zero scan - #3679

Open
iggyvilla wants to merge 1 commit into
xcl-dev:amd-devfrom
iggyvilla:amd-level-upload-fast-scan
Open

iggyvilla wants to merge 1 commit into
xcl-dev:amd-devfrom
iggyvilla:amd-level-upload-fast-scan

Conversation

@iggyvilla

Copy link
Copy Markdown
Collaborator
Metric (retail world load, 128-batch windows) Before After
World-load peak 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)
Late-load 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)
Video/menu 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)
World-load 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

  • Restores per-level lazy upload cutting accidentally dropped during #3444's main merge onto amd-dev: brings back level_upload, levels_with_texels_where, level_ranges, split_ranges (crates/xcl/src/hle/d3d12x/title_textures.rs) and texture_upload::unknown_parts (crates/xcl/src/hle/d3d12x/texture_upload.rs). Because 8ea8524f re-enabled vram::level_pages by default right after #3444, amd-dev (41aa60ce) was falling back to map_levels_with_texels_in on every lazy-level upload — reading and scanning the full multi-MB texture on every partial update, forcing changed = None whole-texture re-uploads whenever any level mapped, and inflating batch_fits byte estimates with unmapped top mips. Restoring level_upload before batch_fits skips empty textures, cuts uploads to mapped levels, tracks per-range unknown hashes (unknown_parts), and packs batches by actual mapped-level bytes.
  • Fast region-skipping non-zero scan (range_any_nonzero_with_skip + PageMap::any_nonzero_with_skip):
    • range_any_nonzero_with_skip uses a zero-copy all_zero fast path when in_committed_window || sparse::known_readable, probes 4 KiB first (then 64 KiB chunks) on ReadProcessMemory so populated mip levels short-circuit after 4 KiB, and on any uncommitted/no-access/guard page jumps across the entire unreadable VirtualQuery region in one call while caching (reg_lo, reg_hi) across mip levels of the same texture.
    • PageMap::any_nonzero_with_skip coalesces contiguous unmapped-mirror fallback runs (p & 1 != 0) into a single range_any_nonzero_with_skip call instead of calling copy_readable + VirtualQuery once per 64 KiB page (which accounted for 92% of level_scan time on streamed textures in GPU mirror views), and probes 4 KiB first on mapped physical pages (p & 1 == 0).
    • map_levels_with_texels_in delegates 2D single-slice textures to levels_with_texels_where so the non-by_level fallback benefits from the same fast scan.
  • Adds 4 unit tests: 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, and split_ranges_partitions_inside_and_outside_cleanly.

Tested

  • Hardware: AMD Radeon RX 6650 XT 8 GB (RDNA2, driver 32.0.21045.29003), AMD Ryzen 7 5700X, Windows 11 x64, rustc 1.100.0 (0ef1bc386 2026-11-09), debug tests + release smoke.
  • Targeted tests (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 clean origin/amd-dev 41aa60ce).
  • Matched 160 s retail world-load profiling (T6-PROF sub-timers): level_scan dropped 6.6×–8.3× (701.0 ms -> 134.9 ms, 404.4 ms -> 43.8 ms), cutting average world-load submit cost from 6.57 ms to 4.97 ms (-24.4%) and textures from 4.07 ms to 2.69 ms (-33.9%).

Regression run
Base (main, required by pr_check.py):

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15479 MB

Base (origin/amd-dev merge base):

xcl-smoke v1
commit: 41aa60ce842060a597b7e8724896f7bf6a031af5
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15902 MB

PR head (b9deb01d):

xcl-smoke v1
commit: b9deb01dc52e720893e694cc1cf65da59eb19c78
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1655 (PresentX 1655)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16173 MB

Not tested

  • NVIDIA and Intel GPUs, and Wine.

AI use

  • Antigravity (Gemini 4 Neon High) identified the #3444 merge drop of level_upload, profiled PageMap::any_nonzero and range_any_nonzero on 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.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Review (head b9deb01, diff read, not a merge-check):

  • The restored upload cutting has no test. level_upload (title_textures.rs ~3907) and levels_with_texels_where (~3819) are on the default path (level pages are on by default), but nothing tests the cut to levels with pages, the look filter that skips unwritten levels without pages, the mip-tail block or the unknown_parts bookkeeping. a68f609, 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 cover unknown_parts, split_ranges and the two scan helpers.
  • Two changes in one PR, over the size target. It restores a68f609's per-level cutting (dropped in the main merge 4fedcbc, Merge main into amd-dev #3444) and adds a new scan (range_any_nonzero_with_skip, PageMap::any_nonzero_with_skip) that map_levels_with_texels_in (~3984) now uses instead of Chain::level_has_nonzero for 2D single-slice textures; 429 lines that would review and bisect better as the restore with its original tests, then the scan.
  • The "Before" column is not amd-dev. The level_scan timer, copy_readable and PageMap::any_nonzero the description profiles exist neither on amd-dev (41aa60ce) nor in this PR; they are a68f609'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_skip reads directly only inside the committed window or sparse::known_readable ranges and otherwise uses ReadProcessMemory, then VirtualQuery with the same readable test as read_committed_into, so it does not touch uncommitted or guard pages; its level and tail ranges match Chain::level_bytes, so it cannot miss a non-zero texel; the PageMap fallback keeps runs contiguous; 3D and array textures behave as on amd-dev.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 41aa60c
head: b9deb01
merge: 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 41aa60c alone on this card, so none is from this PR)
review: read by one reviewer at this same head; the review is at #3679 (comment) and its findings stand. Most serious: level_upload / levels_with_texels_where (default path) come back without a68f609's tests, and the restore and the new scan share one 429-line PR.
performance: 60 s smoke of a retail title, amd-dev 41aa60c vs this merge (b9deb01): 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 a68f609'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.

Decodere added a commit to Decodere/xcl that referenced this pull request Dec 3, 2026
Port the fast region-skipping non-zero scan from xcl-dev#3679 (iggyvilla) to main's map_levels_with_texels_in path:

- Add range_any_nonzero_with_skip (title_textures.rs) and PageMap::any_nonzero_with_skip (texture_upload.rs), probing 4 KiB first so populated mips short-circuit immediately, scanning remaining committed spans in 64 KiB TLS chunks without multi-MB per-slice copies or Vec allocations, skipping unmapped PageMap pages and uncommitted/guard VirtualQuery regions in one step, and caching the last unreadable region across mips/slices.
- Wire 2D and 2D-array lazy-level textures through levels_with_texels_2d in map_levels_with_texels_in (confirming non-full-block/odd levels and packed mip tails via Chain::level_has_nonzero so padding-only bytes match exact texel presence).

Credit: ported from xcl-dev#3679 by iggyvilla.
AI-assisted: Antigravity (Gemini 4 Neon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants