runtime: remap XMem pool pages through copy queue slot 31 #2299

Merged
R0Y00 merged 2 commits from upstream-pr/2307 into main 2026-11-25 11:52:29 +00:00
R0Y00 commented 2026-11-25 11:29:30 +00:00 (Migrated from github.com)

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:

cmake --preset release -DCMAKE_TRY_COMPILE_CONFIGURATION=Release
cmake --build --preset release --target startup_queue_page_batch xmem_section_lease_check xmem_shim_test_controls xmem_shim_check xmem_page_runs_device_check vm_copy_queue_check
ctest --preset release --no-tests=error -R '^(startup_queue_page_batch.*|xmem_(page_batch_inflight_.*|section_lease_.*|shim_page_runs|shim_mapped_pages|page_runs_device_.*|shim_physical_pages|shim_exports|lazy_commit.*)|vm_copy_queue_(warp|hardware))$' -V

Local result: 16 passed, 0 skipped. Inputs and controls are source-built.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6603474845 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2307). Originally posted by [R0Y00](https://github.com/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: ```powershell cmake --preset release -DCMAKE_TRY_COMPILE_CONFIGURATION=Release cmake --build --preset release --target startup_queue_page_batch xmem_section_lease_check xmem_shim_test_controls xmem_shim_check xmem_page_runs_device_check vm_copy_queue_check ctest --preset release --no-tests=error -R '^(startup_queue_page_batch.*|xmem_(page_batch_inflight_.*|section_lease_.*|shim_page_runs|shim_mapped_pages|page_runs_device_.*|shim_physical_pages|shim_exports|lazy_commit.*)|vm_copy_queue_(warp|hardware))$' -V ``` Local result: 16 passed, 0 skipped. Inputs and controls are source-built.
tedin7 commented 2026-11-25 11:31:44 +00:00 (Migrated from github.com)

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 -> X2WMapPageBatch in 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/-43
  • python3 tests/docs_links_check.py -> self-test passed, 18 files, 444 links OK
  • python3 tests/bidi_controls_check.py -> 1591 files, no bidi controls
  • git diff --check origin/main...HEAD -> clean
  • git merge-tree --write-tree origin/main HEAD -> merges cleanly into main
  • gh pr checks 2307 -> Windows build/test, Linux Python checks and gfx1013 fixtures still pending at review time

Not 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):

  • P1: none found.
  • P2 (overlap/merge order): #2303 (open) touches the same regions. A trial merge of this head with #2303's head conflicts in CMakeLists.txt and src/xmem_mapped_pages.cpp. src/xmem_shim.def and tests/xmem_section_lease_check.cpp also change in both and need a check after the textual fix. #2280 is already merged and this PR builds on it (the x2w_xmem_lease_section check at src/xmem_mapped_pages.cpp:1365 now accepts explicit mirror pages). Whichever of #2307/#2303 lands second must rebase and re-run xmem_section_lease_*. The lease check in #2303 relies on the CPU/GPU mirror equality that #2307 relaxes through explicit_mirror_pages, so the cached-mesh range binding should be re-tested against explicit mappings.
  • P2 (lifetime of 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.
  • Nit: the per-page loop calls owned_reservation(address) once per 64 KiB page (~:1285). Large batches could resolve it once per range.
  • Nit: 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:

  • Input validation: the kind range, start/count against the pool, overflow of address + bytes, the limit on total pages (earlier ranges count even if superseded), and unaligned or null destination all return E_INVALIDARG. Faulting descriptors return E_POINTER through the guarded reads.
  • Transaction shape: a plan is built under the memory lock, with nodes reserved before any unmap, and it rolls back on failure. The fixture covers the forced placement failure.
  • keep and identical mappings are counted as skipped and cause no OS calls.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6056827380 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2307#pullrequestreview-6056827380). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:31:44Z. **Review:** COMMENTED --- Review of head `dd9cff6cf539e93a4f084585e44010a8e94cb9e9` (comment only, not an approval). Scope: copy queue slot 31 -> `X2WMapPageBatch` in 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/-43 - `python3 tests/docs_links_check.py` -> self-test passed, 18 files, 444 links OK - `python3 tests/bidi_controls_check.py` -> 1591 files, no bidi controls - `git diff --check origin/main...HEAD` -> clean - `git merge-tree --write-tree origin/main HEAD` -> merges cleanly into main - `gh pr checks 2307` -> Windows build/test, Linux Python checks and gfx1013 fixtures still pending at review time Not 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): - P1: none found. - P2 (overlap/merge order): #2303 (open) touches the same regions. A trial merge of this head with #2303's head conflicts in `CMakeLists.txt` and `src/xmem_mapped_pages.cpp`. `src/xmem_shim.def` and `tests/xmem_section_lease_check.cpp` also change in both and need a check after the textual fix. #2280 is already merged and this PR builds on it (the `x2w_xmem_lease_section` check at `src/xmem_mapped_pages.cpp:1365` now accepts explicit mirror pages). Whichever of #2307/#2303 lands second must rebase and re-run `xmem_section_lease_*`. The lease check in #2303 relies on the CPU/GPU mirror equality that #2307 relaxes through `explicit_mirror_pages`, so the cached-mesh range binding should be re-tested against explicit mappings. - P2 (lifetime of `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. - Nit: the per-page loop calls `owned_reservation(address)` once per 64 KiB page (`~:1285`). Large batches could resolve it once per range. - Nit: `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: - Input validation: the kind range, `start`/`count` against the pool, overflow of `address + bytes`, the limit on total pages (earlier ranges count even if superseded), and unaligned or null destination all return `E_INVALIDARG`. Faulting descriptors return `E_POINTER` through the guarded reads. - Transaction shape: a plan is built under the memory lock, with nodes reserved before any unmap, and it rolls back on failure. The fixture covers the forced placement failure. - `keep` and identical mappings are counted as skipped and cause no OS calls. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 11:50:38 +00:00 (Migrated from github.com)

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, X2WMapPageBatch entry validation in src/xmem_mapped_pages.cpp (~L1268-1350), slot 31 hook in src/startup_stubs/d3d12_xs_device.cpp, CMakeLists.txt test wiring, README/docs rows.

Commands executed locally (worktree of the PR head):

  • git diff --stat origin/main...HEAD -> 9 files, +787/-43
  • git diff --check origin/main...HEAD -> clean
  • python3 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.h uses 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 #1914 is present. Earlier review by @tedin7 was on dd9cff6c; 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

  • P1: none found.
  • P2: none found.
  • Nit 1 (xmem_mapped_pages.cpp, entry validation): the input limit check range.count > limit - total and address > UINT64_MAX - bytes read correctly and cover overflow. A short comment on why kind==3 (keep) ranges still count toward limit would help; the header comment already says so, so this is only a pointer.
  • Nit 2 (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.
  • Nit 3 (CMakeLists.txt): startup_queue_page_batch_warp has no SKIP_RETURN_CODE 77 while the runs variant 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 stats is zeroed on failure. GetModuleHandleExW(0,...) with a matching FreeLibrary is 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_* and xmem_section_lease_* tests on the current head before Ready.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057071493 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2307#pullrequestreview-6057071493). Originally posted by [tedin7](https://github.com/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`, `X2WMapPageBatch` entry validation in `src/xmem_mapped_pages.cpp` (~L1268-1350), slot 31 hook in `src/startup_stubs/d3d12_xs_device.cpp`, `CMakeLists.txt` test wiring, README/docs rows. **Commands executed locally (worktree of the PR head):** - `git diff --stat origin/main...HEAD` -> 9 files, +787/-43 - `git diff --check origin/main...HEAD` -> clean - `python3 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.h` uses 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 #1914` is present. Earlier review by @tedin7 was on `dd9cff6c`; 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** - P1: none found. - P2: none found. - Nit 1 (`xmem_mapped_pages.cpp`, entry validation): the input limit check `range.count > limit - total` and `address > UINT64_MAX - bytes` read correctly and cover overflow. A short comment on why `kind==3` (keep) ranges still count toward `limit` would help; the header comment already says so, so this is only a pointer. - Nit 2 (`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. - Nit 3 (`CMakeLists.txt`): `startup_queue_page_batch_warp` has no `SKIP_RETURN_CODE 77` while the `runs` variant 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 `stats` is zeroed on failure. `GetModuleHandleExW(0,...)` with a matching `FreeLibrary` is 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_*` and `xmem_section_lease_*` tests on the current head before Ready. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 12:01:46 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2299
No description provided.