Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
17ee827
xmem: split slot 31 placeholders when the OS hides the placeholder bit
JohnConnorNPC Nov 26, 2026
364d3b4
tests: slot 31 split inside an XMem reservation, with a committed-tar…
JohnConnorNPC Nov 26, 2026
e44e3cd
docs: placeholder fallback for slot 31 splits under Wine
JohnConnorNPC Nov 26, 2026
f1f90ab
xmem: copy DirectStorage destinations under the mapping mutex
JohnConnorNPC Nov 25, 2026
b7b1552
startup: copy DirectStorage data through x2w_xmem_copy_to_destination
JohnConnorNPC Nov 25, 2026
4de5c09
tests: DirectStorage copy during an XMem run break
JohnConnorNPC Nov 25, 2026
06dfe20
xmem: split an owned placeholder before mapping a page into it
JohnConnorNPC Nov 26, 2026
be3f918
xmem: answer non-faulting readers outside run breaks
JohnConnorNPC Nov 26, 2026
e6e7d9b
xmem: answer the main module's VirtualQueryEx outside run breaks
JohnConnorNPC Nov 26, 2026
0ebef8a
xmem: retry a fault in the break after the one the handler saw end
JohnConnorNPC Nov 26, 2026
284f05e
xmem: run readers once without shared views, and write their answers …
JohnConnorNPC Nov 26, 2026
4408f03
xmem: join a page mapped on its own call to the view before it
JohnConnorNPC Nov 26, 2026
a4dc3f9
xmem: stop a joined run at 64 pages
JohnConnorNPC Nov 26, 2026
1bf82dd
xmem: retry a fault from any of the last 64 breaks, not only the last
JohnConnorNPC Nov 26, 2026
3985646
xmem: run title ReadFile/WriteFile again after a run break refused th…
JohnConnorNPC Nov 26, 2026
f415ffc
xmem: write back only what XMemVirtualQuery's query writes, and pass …
JohnConnorNPC Nov 26, 2026
4a43a17
xmem: say the run cap bounds joined runs only, and test the break rin…
JohnConnorNPC Nov 26, 2026
ad1980c
tests: map single-page XMem views from high to low
JohnConnorNPC Nov 26, 2026
238ed78
tests: preserve the XMem linear buffer view boundary
JohnConnorNPC Nov 26, 2026
14a9589
tests: move the XMem page-run registrations to tests/cmake/xmem_page_…
JohnConnorNPC Nov 26, 2026
e9e0b44
xmem: put the slab accounting comment back above x2w_xmem_slab_stats
JohnConnorNPC Nov 26, 2026
d4f1344
xmem: put joins across mapping calls behind X2W_XMEM_JOIN_CALLS
JohnConnorNPC Nov 26, 2026
cb8cc80
xmem: honour the two split test switches only in the test-controls build
JohnConnorNPC Nov 26, 2026
1615efc
xmem: check every region of a view the placeholder fallback accepts
JohnConnorNPC Nov 26, 2026
c839170
xmem: stamp each run with the break that mapped it instead of a 64-br…
JohnConnorNPC Nov 26, 2026
4f7d47d
xmem: run a failed ReadFile/WriteFile again only on a disk file
JohnConnorNPC Nov 26, 2026
f19890e
xmem: take the mapping mutex for a DirectStorage copy only when it to…
JohnConnorNPC Nov 26, 2026
302618b
dstorage: log the destination copy's outcome by its error code
JohnConnorNPC Nov 26, 2026
0cfdd60
docs, ci: move the page-run note to docs/experiments/ and add the fix…
JohnConnorNPC Nov 26, 2026
f9391cc
gh #2911 review round 1: state the placeholder fallback's limit for M…
JohnConnorNPC Nov 27, 2026
f4cc290
gh #2911 review round 1: say which half of the pipe retry reason is m…
JohnConnorNPC Nov 27, 2026
863c045
gh #2911 review round 1: describe the readers fixture's handler by it…
JohnConnorNPC Nov 27, 2026
bf9e448
gh #2911 review round 1: list no-join in the cross-call merge fixture…
JohnConnorNPC Nov 27, 2026
0c6be97
gh #2911 review round 1: put the page-run note link next to the row's…
JohnConnorNPC Nov 27, 2026
104617d
Merge main into memory/merged-page-runs
JohnConnorNPC Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
"d3d12_sdk_check", "era_heap_check", "xmem_shim", "offscreen_check",
"cpu_fuzz_lifted", "cpu_fuzz_lifted_o2", "pe_map", "intake_candidate",
"archive_gpu_reader", "archive_codec_gpu", "archive_texture_gpu_lifted", "startup_launch_probe",
"startup_indirect_dispatch", "startup_indirect_draw_indexed", "startup_present_readback_check"
"startup_indirect_dispatch", "startup_indirect_draw_indexed", "startup_present_readback_check",
"xmem_shim_test_controls", "startup_stub_xcrdapi", "startup_stub_xcrdapi_break_window_control",
"xmem_run_break_readers_check", "xmem_run_break_readers_control", "xmem_cross_call_merge_check",
"xmem_placeholder_split_check", "xmem_map_split_first_check", "startup_dstorage_break_window_check",
"xmem_page_runs_device_check", "linear_buffer_backing_check"
]
},
{ "name": "release", "configurePreset": "release" }
Expand All @@ -42,7 +46,7 @@
"displayName": "Windows pull request smoke tests",
"filter": {
"include": {
"name": "^(desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_shader_cache_key|startup_present_readback)$"
"name": "^(desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_shader_cache_key|startup_present_readback|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp)$"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ After the full [Windows build](#first-build), run one comparison from the reposi
| PE 32/64-bit base fixups against Windows | `ctest --preset dev --no-tests=error -R '^cpu_native_highlow$' -V` · [scope and controls](docs/experiments.md#highlow-and-mixed-width-base-relocations) |
| [CPU counted cache-line zero loops](docs/experiments.md#counted-cache-line-zero-loops) | `ctest --preset release --no-tests=error -R '^cpu_counted_clzero$' -V` |
| [Experimental startup stand-ins and debugger (trap-by-default DLLs)](docs/startup-runtime.md) | `ctest --preset release --no-tests=error -R '^startup_stubs$' -V` |
| [Remap XMem pool pages through queue slot 31](docs/experiments.md#queue-page-batches-on-xmem-sections) | `ctest --preset release --no-tests=error -R 'queue_page_batch|xmem_page_batch_inflight' -V` |
| [Remap XMem pool pages through queue slot 31](docs/experiments.md#queue-page-batches-on-xmem-sections) · [page runs](docs/experiments/xmem-page-runs.md) | `ctest --preset release --no-tests=error -R 'queue_page_batch|xmem_page_batch_inflight|xmem_placeholder_split' -V` |
| [Sample a texture by address in a translated draw](docs/startup-runtime.md#textures-published-by-address-device-slot-70) | `ctest --preset release --no-tests=error -R '^startup_address_console_' -V` |
| [Desktop audio render sink and its three-case fixture (WASAPI)](docs/experiments.md#desktop-audio-render-sink) | `ctest --preset release --no-tests=error -R '^startup_audio_output$' -V` |

Expand Down
63 changes: 63 additions & 0 deletions docs/experiments/xmem-page-runs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# XMem page runs: placeholder splits, joins and run breaks

Refs [#2911](https://github.com/R0Y00/Xbox2Windows/pull/2911). The fixtures below cover the shim's mapping of
physical pages into XMem reservations with shared views (`X2W_XMEM_SHARED_VIEWS=1`). The results quoted here were
measured under Wine (Proton Experimental, November 2026) on Linux x64, with a clang-cl cross build and each CTest
entry's command run through Wine in one prefix. They are not Windows results. The D3D12 fixtures at the end have no
result there.

## Placeholder split for queue slot 31

`xmem_placeholder_split` maps two pool pages into the middle of an XMem reservation through `X2WMapPageBatch`, which needs a placeholder split. Before splitting, xmem checks that the target is a placeholder, because on Windows `VirtualFree(MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)` can release a reservation that is not one. The check reads bit 0x100 of the `MemoryRegionInfo` flags. Wine (Proton Experimental, November 2026) leaves that bit 0 for placeholders but refuses the same release on a plain reservation with `ERROR_INVALID_ADDRESS` and keeps it whole. xmem measures both once. Where the bit is missing and the plain release is refused, it offers any reserved region to the split, and a plain one fails the split instead. Where the bit is reported, nothing changes. Without this, every slot 31 batch whose destination was not exactly one placeholder failed with `ERROR_INVALID_ADDRESS` under Wine. The fixture also maps onto a committed page in the same reservation, which must fail and keep its bytes (Windows returns `ERROR_INVALID_ADDRESS`, Wine `ERROR_INVALID_PARAMETER`). `xmem_placeholder_split_control` runs the same checks in the test-controls build (`xmem_shim_test_controls`) with `X2W_XMEM_TEST_NO_PLACEHOLDER_FALLBACK=1` and must fail. `xmem_placeholder_split_deployed` sets the same switch for the deployed `xmem_shim`, which ignores it, and must pass. `xmem_placeholder_split_partial` (test-controls build, shared views) maps a two-page view over a private allocation whose first page is reserved and whose second page is committed. The fallback checks every region the view covers, so it refuses the view and the committed page keeps its bytes. A check of the first region alone accepted the view, and Wine then released the allocation and the view replaced the committed page. Limit: the fallback cannot tell a reserved page of a private allocation made with `VirtualAlloc2(MEM_REPLACE_PLACEHOLDER)` from a placeholder, because Wine does not refuse the release for that kind of allocation. After the refused view, the batch retries each page on its own and releases the reserved first page, which cuts it out of the caller's allocation: under Wine the committed page's allocation then starts one page later. The fixture prints where that allocation starts and asserts only that the first page is still one reserved page at its own address. Where the OS reports the bit, the fallback is not used. The control, `xmem_placeholder_split_deployed` and `xmem_placeholder_split_partial` skip (77) where the OS reports the bit. Run `ctest --preset dev --no-tests=error -R '^xmem_placeholder_split' -V`.

## Split before map

`xmem_map_split_first` maps eight single pages with `XMemMapPhysicalPages`, each into the middle of the
reservation's placeholder. xmem splits first and maps once, so the eight pages take eight `MapViewOfFile3` attempts
and eight splits, and an exact placeholder left by an unmap is mapped without a split. `xmem_map_split_first_control`
runs the old map-first order in the test-controls build (`X2W_XMEM_TEST_MAP_FIRST=1`) and must measure 16 attempts.
`xmem_map_split_first_deployed` sets the same switch for the deployed `xmem_shim`, which ignores it, and must measure
8. Measured under Wine: 8, 16 and 8. Run `ctest --preset dev --no-tests=error -R '^xmem_map_split_first' -V`.

## Joins across mapping calls

With shared views, the pages of one call that are adjacent slots of one section share a view. A call joins the run
that ends at its address only with `X2W_XMEM_JOIN_CALLS=1`, which counts only with shared views on. It is off by
default; `tools/startup/run.sh` sets it, and `tools/startup/run.ps1 -LazyMemory` does not. `xmem_cross_call_merge`
checks the joined layout (32 single-page calls on consecutive slots give one view of 32 pages) and the cases around
it. `xmem_cross_call_merge_no_join` checks that the deployed shim with shared views and no join switch keeps a view
per call (32 views). `xmem_cross_call_merge_control` turns the merge off in the test-controls build
(`X2W_XMEM_TEST_NO_MERGE=1`) and must also show 32 views; `xmem_cross_call_merge_deployed` sets that switch for the
deployed shim, which ignores it and joins. All passed under Wine. Run
`ctest --preset dev --no-tests=error -R '^xmem_cross_call_merge' -V`.

## Run breaks and the fault handler

Unmapping a page of a shared view unmaps the whole view and maps its other pages again; a join and a slot 31 batch do
the same for the runs they change. `xmem_run_break_readers` holds that window open (the test-controls build's
`X2W_XMEM_TEST_HOLD_WINDOW`) and checks that each reader either waits for it or, for a pipe `ReadFile`, fails inside
it without being run again (under Wine with `ERROR_NOACCESS`, both queued messages kept). The access-violation
handler retries a fault on a page whose view was mapped inside a break, once per break and thread.
`xmem_run_break_readers_stamps` holds a fault's handler while 63, 64 and 200 later breaks run on another page; each
fault is retried (under Wine the later breaks took 3, 4 and 10 ms). In the same mode, a page made no-access faults
once on a run no break has mapped (passed on at once) and twice after a break mapped it (one retry), counted by a
first-chance handler of the test. Run `ctest --preset dev --no-tests=error -R '^xmem_run_break_readers' -V`.

## DirectStorage copies into runs

`startup_dstorage_break_window` submits a memory-source request into a page of a run while an unmap holds the run
apart: the request must not complete during the 1000 ms hold, then lands; its control, an XCRDAPI that judges the
destination with its own query, refuses inside the window. The copy takes xmem's mapping mutex only when the
destination or source overlaps a run: `startup_dstorage_break_window_plain` measures a `VirtualAlloc` destination
copied without it and a run destination with it, and `startup_dstorage_break_window_views_off` an XMem page
destination copied without it when shared views are off (`x2w_xmem_copy_counts`, test-controls build).
`startup_dstorage_break_window_outcomes` forces each copy error (`X2W_XMEM_TEST_COPY_ERROR`) and checks the outcome
XCRDAPI logs for it. All passed under Wine. Run
`ctest --preset dev --no-tests=error -R '^startup_dstorage_break_window' -V`.

## D3D12 fixtures (not run here)

`xmem_page_runs_device_warp`, `xmem_page_runs_device_join_warp` and `linear_buffer_backing_share_warp` check view
boundaries through D3D12 placed resources. They need D3D12 with WARP, which the Wine prefix above does not provide:
they fail there (`linear_buffer_backing_share_warp`: "WARP device not created"), so this note has no result for
them.
Loading
Loading