Repository navigation
kernelx: with XCL_PAGE_ALIAS=1 the queue's page mappings show real pages - #2308
adiologydev wants to merge 7 commits into
Conversation
…addresses On the console a physical page mapped at several addresses is one page. XCL keeps a page at one address at a time and copies it when the title maps it elsewhere (`move_away`), so the other addresses go stale; a retail title maps its streamed pages into a pool, into the CPU view of a 24 GB reservation and into that reservation's GPU view (xcl-dev#1031). `kernelx::sections` is the base for real aliasing: a block of physical pages is one pagefile-backed SEC_RESERVE section, and a page is mapped as a view of its 64 KiB slice into a placeholder (MapViewOfFile3 with MEM_REPLACE_PLACEHOLDER). Every view of a slice is the same memory and a page takes commit once, when it is committed through any view. Unmapping leaves a placeholder for the next view. Ordinary reserved memory (write-watched if asked) can replace part of a placeholder and go back to one. Nothing calls it yet. Measured in a standalone program on Windows 11 26200 over 200 000 pages: map 2.2 us, unmap 2.75 us, commit 0.9 us a page. GetWriteWatch refuses a range that holds a view (error 87), and one call cannot span two neighbouring reservations either.
The upload of title memory to video memory (`d3d12x::sparse`) and the textures kept in step with title memory learn what the CPU wrote from the write watch, and a view of a section (`kernelx::sections`) cannot be write-watched: GetWriteWatch refuses any range that holds one. `kernelx::guards` keeps the views of a physical page read-only. The first write through any of them faults; a vectored handler makes that view writable, notes the page and lets the write go on. `take_dirty` hands over the pages of every view of each page written – a write through one view is a write to all of them – and guards those views again before their bytes are read, so a later write is caught again and an earlier one is in what is read. Kernel calls do not fault into the handler, they fail: `lazy::ensure`, which XCL already calls before a kernel call or its own code writes title memory, opens the guards there first and counts the write. A view committed by the lazy handler is writable and counts as written. Both take no lock until a view has been watched. Nothing watches a view yet.
… fault A guarded view of a physical page (`kernelx::guards`) is read-only until it is written. Code of XCL's own that writes there faults into the guard and goes on, but a kernel call does not fault: ReadFile into such a view fails. `lazy::ensure` opened the views first, yet the submit thread's `take_dirty` could guard them again before the write – between DirectStorage's check of its destination and the copy, or before the kernel wrote a ReadFile buffer. `guards::open` now returns `Opened`, which keeps its views writable until it is dropped; `take_dirty` uploads a pinned view but does not guard it again, and the end of the write counts as a write. `lazy::ensure` returns it and its callers hold it across their write: the routed ReadFile for a synchronous read, and the destination checks of DirectStorage and the CPU-side bottom-of-pipe writes. An overlapped ReadFile writes after the call returns: its views stay open until its OVERLAPPED is no longer STATUS_PENDING, which `take_dirty` reads without faulting (the title may free it once done). A retail title reads 271 MB that way into the CPU view of its 24 GB reservation 8.5 s after start. `guards::written` counts a page as written through all its views when XCL writes it by page number. Nothing watches a view yet, so nothing changes without views.
…s mapped at Without it XCL keeps a physical page at one address at a time and copies it when the title maps it elsewhere; the console shows the page at every address it is mapped at. A retail title maps its streamed pages into a pool, into the CPU view of a 24 GB reservation and into that reservation's GPU view (xcl-dev#1031). With `XCL_PAGE_ALIAS=1` (`kernelx::alias`): - a block of physical pages is a section (`kernelx::sections`) with a view of its own, through which XCL reads and writes pages by number (DirectStorage); the title never maps a page there; - the title's reservations of 64 KiB pages with no commit (its CPU view, GPU view and pool) are placeholders, and a page mapped there is a view of its slice, guarded (`kernelx::guards`) so that a write through one view is uploaded at all of them; `title_textures` adds those pages to what the write watch found; - a page mapped anywhere else (a placeholder region the title made in a sparse window) is moved there and back with its bytes, as before. Pages are committed on first use as before (`kernelx::lazy`); whether a page is committed is a bit per page: asking Windows walked the rest of a fresh block, and a title mapping 100 000 new pages one at a time took 20 s longer to its first frame. Measured in a traced run of a retail title: 3 blocks (11 360, 2 960 and 99 776 pages), 131 072 map calls in 150 s, nearly all single pages into its plain reservations, none at a page's home, no commit inside them.
…GPU-view page shows Queue method xcl-dev#31 (xcl-dev#29 of the older layout) maps pages of the title's memory into GPU views; it was a stub. Its batches are now decoded and checked against the batch count and the pool, and each 64 KiB page of a GPU view records the pool page it was given and the physical page the title had mapped there (kernelx::mirrors). A bad call records nothing; releasing a view drops its pages. XCL keeps a physical page's data where it was mapped last, and the title maps most streamed pages into the CPU view behind the GPU view too, so `mapped_source` answers where that page is now (`page_now`), else the pool page itself. Each title mapping is remembered per address (Away::title), written once the page is in place and forgotten when the reservation goes; a page freed while its allocation lives is no longer looked for (Away::freed). Nothing reads the record yet: textures are unchanged; the queue logs its counts. (xcl-dev#1031) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`mirrors::decode_batches` checks and decodes one call of the queue's CopyPageMappingsBatchX into (GPU-view page, pool page or unmapped) pairs; `apply_batches` records them as before. No change in behaviour: the next commit maps the decoded pages for real when physical pages alias.
The queue's CopyPageMappingsBatchX maps pool pages into GPU views; on the console a GPU-view page then shows the physical page mapped at its pool page at the time of the call. xcl-dev#1055 decodes the calls and keeps a record of them; with physical pages aliasing (`kernelx::alias`) the GPU view is a reservation of views, so the decoded mappings are made for real: each GPU-view page becomes a view of the physical page mapped at its pool page now, or is unmapped (kind 2, or nothing mapped at the pool page). Textures in the GPU view then read the page at their own address (`title_textures` prefers an address with a physical page mapped), and a write through any view of the page is uploaded at all of them. Without the switch nothing changes: the call is recorded as in xcl-dev#1055.
|
Wine/vkd3d-proton lane: this PR's own new test fails deterministically here, in both switch states, and with the switch on one pre-existing main test breaks on the branch too. Tested: heads Switch off (default):
Switch on (
The alias tests are in-process unit tests (finish in 0.03 s), and the failures are identical across reruns, so this does not look like timing flakiness; it looks like a real behavior gap for the physical-page-upload invariants on the Wine/vkd3d-proton lane. Whether the root is in the top two commits or in an unmerged ancestor layer I cannot separate from outside the stack; the queue-mapping test failure at least is in code this PR adds. Not tested: native Windows CI (upstream CI presumably sees these green, so the delta is lane-specific); NVIDIA lane (parked); retail titles (no title data on this lane, counts only). AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting. |
|
Native Windows check of exact head Tested
Not tested A mirror readback using an alias-aware fixture, Wine, retail smoke, and the full workspace suite. AI use OpenAI Codex (GPT-6.2 Sol) ran the checks, compared the two heads and wrote this report. |
…sing stack) Integrates upstream PR stack xcl-dev#2293 -> xcl-dev#2294 -> xcl-dev#2307 -> xcl-dev#2308 (opt-in real section-slice physical page aliasing across virtual views via XCL_PAGE_ALIAS=1).
|
Independent test and 60 s smoke report for head Tested
Regression run (
PR With Not tested: full workspace test suite on this head, NVIDIA/Intel GPUs, Linux/Wine, or world load past the 60 s smoke window. AI use: Antigravity (Gemini 4 Neon) ran the builds, tests, and smoke runs and drafted this report; the account owner reviewed and approved posting. |
|
Reviewed
AI use: Antigravity (Gemini 4 Carbon) assisted with tracing |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
The queue's CopyPageMappingsBatchX (xcl-dev#29 of the older layout, xcl-dev#31 in the newer one) maps pages of the title's pool into GPU views; it is a stub here. Its arguments are decoded apart from what is done with them, so the record that follows takes a checked list. mirrors::decode_batches turns one call into (GPU-view page, pool page or None for unmapped) in the call's order: batches of 24 bytes (first destination, number of ranges, pointer to them), ranges of three u32 (kind 0: consecutive pool pages, 1: one pool page repeated, 2: unmapped, 3: left as they are; start; count). The whole call is checked before anything is returned: an unreadable batch or range, a range leaving the pool, an unknown kind or more than 1 << 20 pages refuse it. No lock. Not called yet; mirrors::PAGE names the 64 KiB page. Tested: cargo check -p xcl --tests (no new warnings); cargo test --release -p xcl --lib hle::kernelx: 53 passed, 0 failed, 1 ignored, including the new the_page_mapping_batches_are_decoded_whole. Builds on xcl-dev#1055 by Xeltax (f532d33): the decoding, its checks, the Batch test helper and the cases of the test. Builds on xcl-dev#2308 by adiologydev (31fe59c): the decoding split from the record. The batch layout is a fact xcl-dev#1055 cites; no code from elsewhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The queue's CopyPageMappingsBatchX copies the mapping of a pool page into a page of a GPU view: from the call on, the view page shows the physical page the title had mapped at that pool address. XCL keeps a page's bytes in one place, often not the pool address (the title maps most streamed pages into the CPU view behind the GPU view too), so the record keeps, for each view page the method names, the physical page and where XCL keeps its bytes now. mirrors::apply_batches decodes a call (decode_batches), resolves each pool address through Away::title to its page and the page's place (the address it is mapped at away from home, else its home), and records it with AWAY held from the lookup to the record, so a page that moves in between cannot be recorded at the place it left. The record has a lock of its own (PAGES, an RwLock; STATE -> PAGES where both are held, readers take PAGES alone): what each page shows (physical page, place, whether a tile may show the place - unified memory, a graphics reservation or a home -, the call that last changed it, its log key), physical page -> view pages, place -> view pages, the 16 MiB blocks of the places and a log of the last change of each page. A pool page with no page mapped and an unmapped page show nothing; the same mapping named again changes nothing. mirrors::released drops the pages of the views that go. Readers: shows (NoView, Same, Page, Nothing), resolve (an address per 64 KiB page and four counts), touched, any_mapped, calls - each one atomic load while nothing is recorded. Still not called by the runtime: no behaviour change. Tested: cargo check -p xcl --tests (no new warnings); cargo test --release -p xcl --lib hle::kernelx: 54 passed, 0 failed, 1 ignored, including the new gpu_view_pages_record_the_physical_page_mapped_into_them (a call made after the page moved into the CPU view, the unchanged mapping named again, a remap, the tile flag of a page kept in plain memory, the release of the view). Builds on xcl-dev#1055 by Xeltax (f532d33): the recorded physical page, Mapped, the record step with its in-view check, the released hunk and the cases of its tests. Builds on xcl-dev#2308 by adiologydev (64ad64c): a pool page with nothing mapped shows nothing and is counted. Fork: the place kept eagerly (in place of page_now, which locks AWAY), the lock of its own, the tile flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One info line at the first recorded call of CopyPageMappingsBatchX, at powers of two and when 10 s have passed since the last one: the calls; the GPU-view pages mapped, unmapped, named with a pool page that had no page mapped there (must stay 0: above 0, Away::title misses a path by which the title maps pages) and elsewhere; the view pages that moved with their physical page; the textures read again for a mapping changed under them and the pages of their uploads by where they were read; the tiles shown anew and the tiles that followed their page. This is what a run needs to tell whether the page mappings reach the textures and tiles. Diagnostics only; the text comes from a pure function, and the counters are atomics read with the totals' lock dropped. Tested: the_page_mapping_line (new) checks the exact text. Module queue_tests: 4 passed, 0 failed, 0 ignored (release, software adapter); the run printed the line for the test's own call. Builds on xcl-dev#1055 by Xeltax (f532d33): the first half of the line. The count of pool pages with nothing mapped follows xcl-dev#2308 by adiologydev (64ad64c). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stacked on #2307 and on #1055; only the top two commits (
31fe59c,64ad64c) belong here.4f34c8dis #1055's commit (@Xeltax's, unchanged apart from one conflict with today'smaininVirtualFree: bothmirrors::released(a)andforget_title_mappings(a, n)kept). Fourth part of the plan on #1031.The queue's
CopyPageMappingsBatchXmaps pool pages into GPU views; on the console a GPU-view page then shows the physical page mapped at its pool page at the time of the call. #1055 decodes the calls and keeps a record of them. WithXCL_PAGE_ALIAS=1(#2307) the GPU view is a reservation of views, so the decoded mappings can be made for real.What is in it
31fe59ccrates/xcl/src/hle/kernelx.rs:mirrors::decode_batches– kernelx: queue CopyPageMappingsBatchX records the physical page each GPU-view page shows #1055's checked decoding, apart from its record (apply_batchesrecords as before). No change in behaviour.64ad64ckernelx/alias.rs,d3d12x/real.rs,kernelx.rs: with the switch, the queue method makes each GPU-view page a view of the physical page mapped at its pool page now, or unmaps it (kind 2, or nothing at the pool page), and bumps the GPU-view generation so textures there look again.title_texturesalready reads a texture at its own address when a physical page is mapped there. Without the switch the call is recorded as in kernelx: queue CopyPageMappingsBatchX records the physical page each GPU-view page shows #1055. Test: a page written through the CPU view reads back in the GPU view, one pool page at two GPU-view pages, a write in the GPU view uploads every view of the page, and a later change of the pool page leaves the GPU view on the page it was given.Tested
XCL_DXC_DIR), debug tests, release runs.cargo test --workspace -- --test-threads=4on64ad64c: 1118 passed, 4 failed, 26 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(CreateComputePipelineState→E_OUTOFMEMORYon this card, DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905);main568e7db fails the same 4 here (1094 passed, 4 failed, 26 ignored). SKIPPED (23, the same onmain): 20 need 64-lane waves ("no wave64"), 3 per-lane f16 refusals inlower_dxil::tests::{f16,f32}_programs_on_the_gpu.XCL_PAGE_ALIAS=1, 300 s into its world: 256 calls by 170 s, 31 196 GPU-view pages mapped to a physical page, 3 137 unmapped, none pointing at an empty pool page; no crash or device removal (before, every one of these mappings was dropped).Regression run (the switch off, as the PR checks run it)
scripts/smoke.ps1 -Game <retail title> -Seconds 60, no input,mainfirst, same machine (each run'sxcl.exebuilt from a clean checkout of its commit):Not tested
AI use
31fe59cand64ad64c, the test and this description, and made the runs above on this hardware.4f34c8dis @Xeltax's kernelx: queue CopyPageMappingsBatchX records the physical page each GPU-view page shows #1055. I read every line of the diff and checked it.