Lease committed XMem section pages for GPU access #2272
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2280"
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 R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T09:29:52Z.
Refs #1914.
Add a versioned in-process XMem section lease for a bounded span of committed mirrored pages. The lease requires matching CPU and mirrored page identities and consecutive physical slots in one section. Callers can map just those slots as one view and open it as a desktop D3D12 heap. Unmapping and freeing the original grant leaves the slots pinned until the caller releases the lease after GPU completion. Existing export names and ordinals 1–18 are preserved.
The fixture uses the XMem shim’s own section pool. WARP and the RTX 4060 Laptop GPU (driver 616.56, Windows 11 build 26200.9974, D3D12 debug layer) read and write the same 4,096 bytes across two 64 KiB pages. It checks late CPU writes, a remap before GPU submission, fence-delayed reuse and zeroing, and refusal of holes, reversed slots, a wrong address space, a wrong ABI version, a wrong structure size, and repeated release.
Six tests passed with zero skips.
dumpbin /exportschecked the existing export names and ordinals against the base definition.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:32:58Z.
Review: COMMENTED
Review of head
5d20b85875ec6304ff23bfe52a74134a47f95da4(comment only, no approval).Scope:
src/xmem_mapped_pages.cpp, newsrc/xmem_section_lease.h,xmem_shim.def(+2 exports), newtests/xmem_section_lease_check.cpp, CMake,docs/experiments.md. Mergeable; title is neutral; no clean-room concerns seen.Commands executed locally (Linux worktree of the PR head)
git diff --stat origin/main...HEAD: 6 files, +289/-1.python3 tests/docs_links_check.py: passed (18 files, 435 links).python3 tests/bidi_controls_check.py: passed (1568 files).git diff --check origin/main...HEAD: clean.gh pr checks 2280: "Run platform-independent Python checks on Linux" is red. The log showsTypeError: 'NoneType' object is not an iteratorattools/mesh_entry_aot.py:882(next(steps)), hit bytests/mesh_dynamic_geometry_check.pyandtests/mesh_dynamic_aot_check.py. This PR touches none of those files, so it looks like a failure that is not caused by this change. The branch is also 2 commits behind main, so a rebase and a re-run are worth doing. The Windows jobs were still pending when I looked.Logic read (P1/P2)
free_pagesmarks a pinned slot retired and does not release it.unpin_slotreleases it on the last reference. Lease rollback afterbad_allocunpins exactly thepinnedcount and closes the duplicate handle. I could not trigger a leak or a double release by reading it.Nits
src/xmem_mapped_pages.cppx2w_xmem_lease_section:first = address & ~(page_bytes - 1)aligns the absolute GPU address. This is only right ifmirror_gpuis 64 KiB aligned. Aligningoffsetinstead (mirror_gpu + (offset & ~(page_bytes-1))) would not depend on that. The test's reservation is aligned, so this passes today.unpin_slotdereferencespins.find(slot)without anend()check. It holds today because every lease slot was pinned under the same lock. A debug assert would document that.x2w_xmem_slab_statswould make leaks visible.Not run
xmem_section_lease_{warp,hardware}) is Windows-only, so I did not run it. I did not run a Win2025 job: the code is C++ runtime with no shader lowering, and the Windows CI jobs cover the build.free_pages. Make it release the slot even when it is pinned, then check that the fixture's "late CPU update after free" assertion fails.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:42:13Z.
Review: COMMENTED
Re-review of head
4e4c2777b7c397f896770994feb92512b30b78fc(comment only, no approval). My earlier review was on5d20b85.What changed since the last review
CMakeLists.txt,docs/experiments.md,src/xmem_mapped_pages.cpp,src/xmem_section_lease.h,src/xmem_shim.def,tests/xmem_section_lease_check.cpp) are byte-identical to5d20b85:git diff 5d20b85 HEAD -- <those files>is empty.README.md,docs/startup-runtime.md,src/startup_stubs/gameinput.cpp,tests/startup_gameinput_contracts_check.cpp,tools/mesh_entry_aot.py) come from main, not from this PR. The PR diff against main is still 6 files, +289/-1.Commands executed locally (Linux worktree of this head)
git diff --stat origin/main...HEAD: 6 files, +289/-1.git diff --check origin/main...HEAD: clean.python3 tests/docs_links_check.py: passed (18 files, 435 links).python3 tests/bidi_controls_check.py: passed (1568 files).gh pr checks 2280: "Run platform-independent Python checks on Linux" now passes. Themesh_entry_aot.pyfailure I reported before was fixed on main and is gone after the merge. "Build and test on Windows" and "Assemble and translate gfx1013 fixtures" also pass. The /O2 job and the chart job are skipped.free_pagesretire logic: unchanged, and my earlier conclusions still hold.Findings
offsetrather than the absolute address inx2w_xmem_lease_section. (2) Add a debug assert forpins.find()inunpin_slot. (3) Report open leases in the slab stats.Not run
xmem_section_lease_{warp,hardware}is Windows-only. I read it but did not run it. The Windows CI build passes.src/startup_stubs/local_log.hon__except, which is unrelated to this PR. I ran no mutation. I still suggest mutating the retire path infree_pages(always release) to confirm the fixture catches it.AI-assisted; commands listed were executed locally.