Sparse windows: commits before the device are merged page ranges, not a list scanned per page #204
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!204
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/204/head"
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?
@Kalmarv on GitHub · 2026-11-23 20:47 UTC · original
Kalmarv:fix/sparse-early-ranges→main· +177 −7 · 1 files · 1 commits · closed without mergingBefore the D3D12 device exists,
sparse::committedappended one(addr, len)per call toEARLY, andsparse::decommittedranEARLY.retain(..)over the whole list each time. Moving N pages away therefore cost O(N²). This was found in the #187 review: #187 and #203 put more of the retail title's memory in sparse ranges, which sends it down this path.Complementary to #203. #203 fixes the same pattern after the device exists:
decommit_tilesprunedto_zeroat every decommit, and #203 prunes it once. This PR is the pre-device path only and does not touchdecommit_tiles. gw1337x's watchdog stack on #187 (unmap_away → sparse::decommitted → Vec::retain) fits either retain, and #203 ties the same watchdog to the post-device one.Change
EARLYis now aBTreeMapof disjoint page ranges (start → end), merged with their neighbours. A commit or decommit before the device is O(log n).initcommits the ranges once the windows exist, as before.A range counts every page it touches, as
committed/decommittedalready do once the state exists. A decommit takes out only its own pages.One behaviour change. The old list dropped every entry a decommit overlapped. So after
commit_homescommitted several pages in one call andmove_home_awaygave one of them back,initleft the pages that were still committed as holes. They are now kept.Timing
Release build, Ryzen 9 9950X, CPU only (no device, so the early path), one run each.
early_commit_timing(new, ignored) commits 64 KiB pages one at a time, then decommits them one at a time in reverse:mainXMemMapPhysicalPagesScatterin reverse, then unmap, throughkernelx. The sparse and plain targets differ only incommitted/decommitted. The probe is the one from the #187 review and is not in this PR.mainmainWith this PR the sparse cost matches the plain one.
This does not remove the whole stall, and probably isn't its main cause. In a release build the old early path would cost only about 1 s even at 100,000 pages, so the debug-build numbers in the #187 review overstated it, and the after-device retain that #203 fixes is the likelier culprit. The scatter itself costs about 0.27 ms per page on plain memory too, linear in the page count (about 27 s at 100,000 pages if that holds). I have not found where that goes. Hoisting
page_homeout ofunmap_away'saway.gone.retainsaved only about 7%, so it is not in this PR.Tests
early_commits_are_the_pages_a_page_set_holds: 8 seeds × 4,000 random commits and decommits, unaligned ones included. After each step, the pages match a page-set model, and the ranges are page-aligned, disjoint and merged.early_commits_match_the_old_list_for_page_entries: 20,000 random steps against the old list, for what it handled exactly (single-page commits, page-aligned decommits of any length). The resulting pages are the same.early_decommit_of_one_page_keeps_the_rest: the case the old list got wrong.early_removefails the first two tests.cargo test --release -p xcl --lib -- --test-threads=4on Windows 11 with an RTX 5070 Ti (NVIDIA 610.74):83f9c91on956a476)main, the control (plus 3 ignored local probes)8c0346d), clean merge7cbd008), clean mergeThe 3 extra passes on this branch are its new tests. The extra ignored test is
early_commit_timing.Not tested:
AI-assisted (Claude Code); synthetic memory only, no game files.
🤖 Generated with Claude Code
@Kalmarv on GitHub · 2026-11-23 20:56 UTC · original
Rebased on main
2abc562(68a6640). The only conflict was next to the newpool_bytesinsparse.rs; this change is otherwise unchanged.cargo test --release -p xcl --lib sparse::: 9 passed, 1 ignored (the timing probe).@Kalmarv on GitHub · 2026-11-23 21:04 UTC · original
Rebased again, now on main
eaa36b6(8f662ea, no conflicts).cargo test --release -p xcl --lib sparse::: 9 passed, 1 ignored (the timing probe).Overlaps: #187 also reworks the code around the homes in
kernelx.rsandsparse.rs. This PR changes only the pre-deviceEARLYlist and its two callers, so the two stay separable. Main's38b05b7(lazy homes, pool release) didn't touchEARLY.@ivall on GitHub · 2026-11-23 21:10 UTC · original
Merged into main (
6da33fa) as68a66402, the head before your last rebase - the same patch (identical patch-id), so GitHub does not show it as merged; closing it by hand. Checked on an RX 9070 (RDNA4) with the 22 PRs merged together: 582 unit tests passed, 0 failed, the integration and e2e tests passed, and the retail game still reaches its first menu (646 frames in 30 s, no device removal). Thanks!Pull request closed