runtime: remap XMem pool pages through copy queue slot 31 #2299
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2307"
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-25T11:29:30Z.
Refs #874 and #1914.
Copy queue slot 31 now applies ordered 64 KiB page ranges to XMem's section-backed virtual reservations. The provider supports consecutive, repeated, unmapped and preserved pages, resolves source pages from the pool at call entry, and skips identical mappings. Eligible consecutive section slots use a single view when shared views are enabled. Explicit mappings take precedence over the implicit mirror. The old section lease can remain live while a later submission binds the replacement.
The fixture forces a real placement failure with a private allocation inside the destination window. It checks that the earlier edit rolls back and that both the private allocation and the original alias retain their contents. The GPU comparison gates an old submission during remapping, then checks 4,096 bytes from each backing. It also exercises a late CPU write across a page boundary.
Windows 11 build 26200.9974, x64 MSVC Release. The lease tests used the D3D12 debug layer on RTX 4060 Laptop (32.0.16.1656) and WARP (10.0.26100.9818). The queue timing fixture used a WARP copy queue with the debug layer off. Across 128 pages in four regions, repeating the batch completed with zero map and unmap operations in both modes. Changing all pages used 128 maps and 128 unmaps with single-page views, or four of each with shared views. The benchmark reports median and p95 per batch over 51 paired samples. It measures host submission time; separate GPU resource copies have their own synchronization path.
Reproduction from the repository root in the x64 VS development shell:
Local result: 16 passed, 0 skipped. Inputs and controls are source-built.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:31:44Z.
Review: COMMENTED
Review of head
dd9cff6cf539e93a4f084585e44010a8e94cb9e9(comment only, not an approval).Scope: copy queue slot 31 ->
X2WMapPageBatchin XMem (src/xmem_mapped_pages.cpp,src/xmem_page_batch.h,src/startup_stubs/d3d12_xs_device.cpp), plus tests and CMake wiring.Commands executed locally (Linux, worktree of the PR head):
git diff --stat origin/main...HEAD-> 9 files, +794/-43python3 tests/docs_links_check.py-> self-test passed, 18 files, 444 links OKpython3 tests/bidi_controls_check.py-> 1591 files, no bidi controlsgit diff --check origin/main...HEAD-> cleangit merge-tree --write-tree origin/main HEAD-> merges cleanly into maingh pr checks 2307-> Windows build/test, Linux Python checks and gfx1013 fixtures still pending at review timeNot run: the C++ changes are Windows-only (MapViewOfFile3, placeholders, D3D12 WARP), so no Linux build or mutation run was possible here, and I did not queue the Windows VM. I am relying on the Windows result in the PR body plus the pending CI job. No source mutation was performed.
Read-through findings (file:line from the head):
CMakeLists.txtandsrc/xmem_mapped_pages.cpp.src/xmem_shim.defandtests/xmem_section_lease_check.cppalso change in both and need a check after the textual fix. #2280 is already merged and this PR builds on it (thex2w_xmem_lease_sectioncheck atsrc/xmem_mapped_pages.cpp:1365now accepts explicit mirror pages). Whichever of #2307/#2303 lands second must rebase and re-runxmem_section_lease_*. The lease check in #2303 relies on the CPU/GPU mirror equality that #2307 relaxes throughexplicit_mirror_pages, so the cached-mesh range binding should be re-tested against explicit mappings.explicit_mirror_pages,src/xmem_mapped_pages.cpp:51,1296,1329,1799): entries are added on success and cleared at line 1799 only. Please confirm that freeing or re-reserving a destination page inside the mirror window also drops its entry. If it does not, a later implicit mirror update would be skipped at line 939 for a page that is no longer explicit. A test that frees and reuses a destination after an explicit batch would settle it.owned_reservation(address)once per 64 KiB page (~:1285). Large batches could resolve it once per range.queue_page_mappings(d3d12_xs_device.cpp:3150) logs only the first two failures. That is fine, but a counter in the log line would help triage.Checked and looks right:
start/countagainst the pool, overflow ofaddress + bytes, the limit on total pages (earlier ranges count even if superseded), and unaligned or null destination all returnE_INVALIDARG. Faulting descriptors returnE_POINTERthrough the guarded reads.keepand identical mappings are counted as skipped and cause no OS calls.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:50:38Z.
Review: COMMENTED
Review of head
078581786f12711123805664963c43565c2c2bb4(Linux-side review; this PR is MSVC/Windows-only code).Scope read:
src/xmem_page_batch.h,X2WMapPageBatchentry validation insrc/xmem_mapped_pages.cpp(~L1268-1350), slot 31 hook insrc/startup_stubs/d3d12_xs_device.cpp,CMakeLists.txttest wiring, README/docs rows.Commands executed locally (worktree of the PR head):
git diff --stat origin/main...HEAD-> 9 files, +787/-43git diff --check origin/main...HEAD-> cleanpython3 tests/docs_links_check.py-> "Checked 18 Markdown files and 448 links." (self-test passed)python3 tests/bidi_controls_check.py-> "no bidirectional controls" (1606 files)x86_64-w64-mingw32-g++ -fsyntax-only src/xmem_mapped_pages.cpp-> fails inside an unrelated header (local_log.huses MSVC__except), so no compile check or logic mutation was possible on Linux. I did not run a mutation of the new logic, and I did not run Win2025.State: CI checks were still pending when I looked. Title and body are neutral,
Refs #874 and #1914is present. Earlier review by @tedin7 was ondd9cff6c; the new head only adds a merge of main (plus main's own changes), so the PR-specific diff is the same set of files.Findings
xmem_mapped_pages.cpp, entry validation): the input limit checkrange.count > limit - totalandaddress > UINT64_MAX - bytesread correctly and cover overflow. A short comment on whykind==3(keep) ranges still count towardlimitwould help; the header comment already says so, so this is only a pointer.d3d12_xs_device.cpp,queue_page_mappings): the slot 31 argument layout(count, batches, pool, pool_pages, flags)is defined by this PR, not checked against a public source. Please cite the public issue or in-repo doc that fixes this ABI so it stays traceable.CMakeLists.txt):startup_queue_page_batch_warphas noSKIP_RETURN_CODE 77while therunsvariant does. Fine if the first variant must never skip; just confirm it is intended.Behavior notes (no action needed): validation happens before the memory lock and before any edit; failures return before mutation or roll back via the plan, and
statsis zeroed on failure.GetModuleHandleExW(0,...)with a matchingFreeLibraryis balanced.Gate: the real behavior (placement failure rollback, in-flight GPU read, shared views) can only be proven by the Windows WARP/hardware run. Stage-2 should confirm the
startup_queue_page_batch*,xmem_page_batch_inflight_*andxmem_section_lease_*tests on the current head before Ready.AI-assisted; commands listed were executed locally.