Skip to content

kernelx: queue CopyPageMappingsBatchX records the physical page each GPU-view page shows - #1055

Open
Xeltax wants to merge 1 commit into
xcl-dev:mainfrom
Xeltax:queue-page-mappings
Open

Xeltax wants to merge 1 commit into
xcl-dev:mainfrom
Xeltax:queue-page-mappings

Conversation

@Xeltax

@Xeltax Xeltax commented Nov 24, 2026 •

Copy link
Copy Markdown

Queue method #31 of the newer layout (#29 of the older), CopyPageMappingsBatchX, maps pages of the title's memory into GPU views. It was a stub. This PR decodes its batches and records, for each 64 KiB page of a GPU view, the physical page it shows. It can then say where XCL keeps that page's data now. Nothing reads that record yet, so textures are unchanged. First of the PRs planned in #1031 (see the correction there).

What is in it

  • crates/xcl/src/hle/kernelx.rs, mirrors:
    • apply_batches(count, batches, pool, pool_pages) decodes one call:
      • a batch is 24 bytes: destination (u64), range count (u32), and a pointer to the ranges at +16;
      • a range is kind, start, count (u32 each). Kind 0 maps count pool pages from start; kind 1 maps pool page start at each of count pages; kind 2 unmaps; kind 3 keeps.
    • The whole call is checked before anything is recorded. Batches and ranges must be readable, pool ranges must stay inside pool_pages, the kind must be known, and the call may name at most 2^20 pages. A bad call records nothing.
    • Only pages inside a known GPU view are recorded. The retail title maps into nothing else; other pages are counted as "elsewhere".
    • Each recorded page keeps its pool page and the physical page the title had mapped there (Shown).
    • mapped_source(va) answers what the method put under va:
      • Some(Some(a)): a is where XCL keeps that physical page now (page_now), or the pool page itself when the title had mapped none there;
      • Some(None): the page is unmapped;
      • None: the method never touched the page.
    • released now also drops a released view's recorded pages.
  • crates/xcl/src/hle/kernelx.rs, physical pages:
    • Away::title remembers, per address, the page the title mapped there last.
    • On the console a page stays mapped at every address it was mapped at. XCL keeps its data in one place, the address it was mapped at last (move_away).
    • The retail title maps a streamed page into the pool, and most of them into the CPU view behind the GPU view too. So the pool address alone gives the wrong place for most pages; the physical page gives the right one.
    • page_now(page) gives where the page's data is: its address away from home, else its home. For a page the title freed while the rest of its allocation lives (Away::freed), it gives nothing.
    • An entry is written only once the page is in place, so a failed map leaves none. Releasing a graphics or sparse reservation forgets the entries in its range.
  • crates/xcl/src/hle/d3d12x/real.rs: queue Shader tools: keep DXC timings out of JSON output #29 (older numbering) calls apply_batches and returns S_OK as the stub did. It logs its totals at the first call and at powers of two, including how many mapped pages had a physical page, and warns once on a bad call.
  • Tests:
    • page_mappings_point_gpu_view_pages_at_pool_pages: synthetic batches covering:
      • all four kinds, a later call that remaps a page, and pages outside any GPU view;
      • bad calls: a range that leaves the pool after a good one, an unknown kind, unreadable ranges and unreadable batches;
      • release of the view.
    • a_gpu_view_page_shows_the_physical_page_where_it_is_kept: a real physical page is mapped into a pool and given to a GPU-view page. The page shows the pool. Once the page is also mapped at another address, the GPU-view page shows that address, with the same data.
    • a_freed_page_is_read_at_its_pool_page (from the review): one page of a two-page allocation is freed. The GPU-view page then reads the pool page, which keeps its bytes, and a later call records no physical page behind it.

On the retail title (the one in #505; main 67a3735 + this change, RTX 4080, A pressed through XCL_PRESS_AT; the run ends at +0x23cf683 as on main)

  • Every call decodes, and every page lands in the title's one GPU view (0xdffff0000, the view of 0x7ffff0000). Log line from the run of c8d5020:

    [   64.828] D3D12.X: queue CopyPageMappingsBatchX: 256 calls; GPU-view pages so far: 18635 mapped (18635 to a physical page the title mapped there), 2188 unmapped; 0 pages elsewhere ignored (pool 0x180090000, 99776 pages of 64 KiB)
    
  • Where XCL keeps the physical pages. A local tracker, not part of this PR, followed each page. This was a separate run, on 924b55c plus the tracker. After 256 calls (at 84 s), of 34,872 mapped GPU-view pages:

    • 19,808 have their physical page at the CPU view's same offset. There the identity mirror (mirrors::source), which title_textures reads today, is right.
    • 15,064 have it still at the pool address. The CPU view's same offset is not committed there, so those parts of textures are uploaded as zeros today.
  • How textures sit on the map (local count, another run, 111 s, 22,353 textures in the view):

    the texture's pages textures MB
    never touched by the method 0 0
    one run of consecutive pool pages 17,745 872
    all mapped, pool pages out of order 384 256
    some mapped, others unmapped or never mapped 2,306 4,219
    all unmapped 1,918 13
  • The next PR has title_textures read GPU-view textures page by page through mapped_source. It will re-check only the textures on pages that changed: the existing re-check of all GPU-view textures took 225 ms over 64k textures at 111 s, and there were 256 calls by 84 s.

Tested

  • NVIDIA GeForce RTX 4080 (driver 621.01), AMD Ryzen 9 9900X, Windows 11 Pro 26200, rustc 1.100.0, DXC 1.9.2609.5. Tests ran in debug, the title in release.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on f532d33: 738 passed, 0 failed, 41 ignored. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).

Regression run

main:

xcl-smoke v1
commit: 67a3735177f42cf8e5c886e67a974da7f87541b3
gpu: NVIDIA GeForce RTX 4080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1582 (PresentX 1583)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16549 MB

PR:

xcl-smoke v1
commit: f532d33d695a360bf5701650374dd87a4566c499
gpu: NVIDIA GeForce RTX 4080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1581)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16665 MB

Not tested

  • AMD and Intel GPUs. The change does not touch the GPU path, but no run was made there.
  • Other titles.

Reference
The batch and range layout comes from VIctory's description of this method (crates/victory-gpu/src/queue.rs). I read it as a reference only; no code was taken. The decode matches what the retail title passes (#1031).

AI use

  • Claude Code (Claude Opus 5.5) wrote the code, the tests and this description, ran the title and the tests, and read the logs.

🤖 Generated with Claude Code

@Xeltax
Xeltax marked this pull request as draft November 24, 2026 11:09
@Xeltax Xeltax changed the title kernelx: queue CopyPageMappingsBatchX records the pool pages a GPU view's pages show kernelx: queue CopyPageMappingsBatchX records the physical page each GPU-view page shows Nov 24, 2026
@Xeltax
Xeltax marked this pull request as ready for review November 24, 2026 11:17
@thehollowedone

Copy link
Copy Markdown

Independent Windows 11 check at c8d5020. The offline workspace build and both stock page-mapping tests passed.

I extended the physical-page fixture to reuse the vacated pool address for a second page with different bytes. The original GPU view still resolved to the first page at its new address, and a new mapping resolved to the second page. A keep range preserved both mappings, including the address at the last byte of the first view page. Releasing the view removed both records.

These checks exercise the mapping functions directly. AI-assisted. Codex (GPT-6) extended and ran the synthetic fixture.

@pvfreis pvfreis left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of c8d5020 against its merge base 67a3735, by reading the code; nothing was built or run here. I found no defect that changes what a title does today: nothing reads mapped_source yet, and the decode is checked before anything is recorded. The one real point is that the new address-to-page record (Away::title) is not kept in step with frees and failed maps, and the description's statement about freed pages does not match the code. That matters for #1102, which reads this record.

  1. CONFIRMED: a freed page is answered at its home, not at the pool address as the description says (crates/xcl/src/hle/kernelx.rs:949-952, :989-994, :1307-1314). Not tested says: "page_now then finds no page, and the pool address is answered." That holds only when the page's whole allocation is gone. page_home asks whether the block has any live page (live > 0, :993), not whether this page is live, and FreeTitlePhysicalPages removes the block only when its last page is freed (:1323-1326). Scenario: the title allocates its streaming pages in one call (the comment at :916-918 describes a retail game doing so), maps page P at a pool page, gives that pool page to a GPU-view page, and later frees P alone. The free drops away.page[P] and leaves the bytes at the pool address (:1306, "that address keeps whatever it holds"). mapped_source then returns P's home: page_now finds nothing in away.page and page_home(P) is still Some. That home was given back when the page moved away (move_home_away / give_back_homes), so it is not committed, or in the coherent window it holds old bytes. The pool address, which still holds the data, is not answered. Fix: either drop the freed pages from the record in FreeTitlePhysicalPages (see 2), or correct the sentence in Not tested; a test that frees one page of a two-page allocation would pin it down.

  2. CONFIRMED (minor): Away::title keeps entries for mappings that are gone or never happened (kernelx.rs:1398-1402, :1374-1376). Three cases:

    • FreeTitlePhysicalPages (:1307-1314) clears away.page / away.at but not title, so a later apply_batches on that pool page still records page: Some(P) and counts it under "to a physical page the title mapped there" in the log.
    • In map_pages the entry is written before the mapping is made. When move_away fails (:1419-1422) or the commit fails (:1436-1439) the call returns null, but title[at] already names the page, after unmap_away removed whatever was there.
    • Releasing a reservation with pages mapped in it (VirtualFree, :571-575) leaves its entries; a later reservation at the same address inherits them. (away.at has the same gap on main, so this one is not new in kind.)
      None of these is read by anything in this PR. Fix: remove the freed pages' entries in FreeTitlePhysicalPages, and write the entry in map_pages after the page is in place.

Checked and found in order:

  • Decode and bounds (kernelx.rs:255-297): batch and range arrays go through readable before they are read, the pool bound is checked per range with checked_add, the page total is capped before any extend, an unknown kind or a range leaving the pool returns before anything is recorded.
  • Locks: apply_batches releases AWAY before taking STATE then PAGES (:299-307); released takes the same order (:204-210); mapped_source drops PAGES before page_now takes AWAY (:241-242); map_pages holds AWAY and reaches STATE through note_mapping_at. I see no inversion.
  • Slot: with the newer layout queue_dispatch subtracts 2, so #31 arrives as 29 (crates/xcl/src/hle/d3d12x/real.rs:4961, :5010); four arguments are enough for count, batches, pool, pool_pages, and the method still returns S_OK as the stub did. Like 23 and 30, the arm is not gated on the layout being known; a newer-layout title calling its #29 before its first fence at #16 / #17 would have that call decoded as batches, where the readable and kind checks are the only guard.
  • Tests: both tests assert what the description lists. The second goes through MapTitlePhysicalPages, so it covers the move from the pool address to another address. Neither covers a freed page (finding 1) or the page limit.
  • CONTRIBUTING: Tested, Regression run (main block at the merge base, PR block at the head commit, frames and peak commit within the limits), Not tested and AI use are there; 286 changed lines. The CI workflow shows action_required for this head (it has not run), so only PR checks is green so far.

Questions for the author, not defects:

  • The log line in the description shows 18,635 mapped GPU-view pages after 256 calls (at 64.8 s); the tracker table says 34,872 mapped after 256 calls, and the last bullet says 256 calls by 84 s. Are these from different runs? The share of pages read wrong (15,064 of 34,872) rests on the tracker's count.
  • The first commit records pool pages and the second replaces that model with physical pages, as the correction in #1031 explains. Both land in main; squashing them would keep the superseded model out of the history.

Overlap: #1102 (draft) is stacked on this PR and reads mapped_source. #979 touches only crates/xcl/src/hle/dstorage.rs and resolves GPU-view addresses through mirrors::source and physical_page_at; there is no textual conflict, but once pages recorded here are honoured, a DirectStorage destination in a GPU-view page that this method pointed at a pool page should follow mapped_source too, otherwise it writes the CPU view while textures read the pool page. No other open PR implements this queue method.

Verdict: no blocking defect; fine as a logging-only first step once CI has run. Finding 1 should be settled (code or description) before #1102 relies on it.

Review by Claude Code (written by Claude Fable 5.2, checked with Claude Opus 5.5); each point checked by a person before posting.

…GPU-view page shows

Queue method ivall#31 (ivall#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. (ivall#1031)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Xeltax

Xeltax commented Nov 24, 2026

Copy link
Copy Markdown
Author

Thanks @pvfreis, both findings were right. I pushed f532d33, one commit as you suggested.

1. A page freed alone. page_now now answers nothing for such a page: Away::freed holds the pages freed while their allocation lives, and page_home is no longer asked about them. Page numbers are never handed out again, and the entries go when the whole block goes. mapped_source then answers the pool page, which keeps the bytes.

  • The new test a_freed_page_is_read_at_its_pool_page does your scenario: it frees one page of a two-page allocation and checks that the GPU-view page reads the pool page with its bytes.
  • I removed the wrong sentence from Not tested.

2. Away::title.

  • map_pages now writes the entry only once the page is in place (the moved, lazy and committed paths), after clearing whatever was mapped at the address. A failed map leaves nothing behind.
  • A freed page is no longer recorded by apply_batches (Away::title_page), so it is not counted as "to a physical page".
  • Releasing a graphics reservation or a sparse reservation forgets the entries in its range.

Your questions.

Tested so far on f532d33: cargo test -p xcl --lib -- kernelx title_textures: 49 passed, 0 failed. The full suite and a new regression run on this head come next. I'll put both in the description, with the counts per run labelled, and say so here.

#1102 is rebased onto f532d33 (c387de2). A freed page now also counts as a change there, so the textures on it are read again.

AI use: Claude Code (Claude Opus 5.5) made the changes, ran the tests and the title, and wrote this reply.

@Xeltax

Xeltax commented Nov 24, 2026

Copy link
Copy Markdown
Author

The full suite and a regression run on f532d33 are in the description now:

  • cargo test --workspace --no-fail-fast -- --test-threads=4: 738 passed, 0 failed, 41 ignored.
  • Smoke, 60 s: 1,581 frames against 1,582 on main 67a3735; peak commit 16,665 MB against 16,549 MB.

Each figure in the description now names the run it comes from, and I removed the wrong sentence about freed pages.

@pvfreis

pvfreis commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Thanks, both are fixed at f532d33 as far as I can see by reading it (nothing built or run here):

  1. A page freed alone: page_now returns None for a page in Away::freed (kernelx.rs:972-981), so mapped_source falls back to the pool page, and a_freed_page_is_read_at_its_pool_page checks exactly that, including that a later batch records no physical page. FreeTitlePhysicalPages drops the freed entries when the whole block goes (:1376-1378).
  2. Away::title: map_pages removes the entry for each address first and writes it only on the three paths where the page is in place (:1443, :1456, :1476, :1496), so a failed map leaves nothing; title_page ignores freed pages; releasing a graphics or sparse reservation forgets its range (forget_title_mappings, :559, :578).

Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.

Revens2 added a commit to Revens2/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PRs ivall#1055 and ivall#1102 (issue ivall#1031) and ivall#1070 (issue ivall#1040).

Assisted-by: xcl-ops (deepseek-v4.1-flash)
Trace-Issue: ivall#1031
@raylitebull

Copy link
Copy Markdown
Member

Code review on f532d33:

  • queue_dispatch arm 29 (#31 in the newer layout via slot - 2) cleanly dispatches q_copy_page_mappings -> mirrors::apply_batches.
  • apply_batches validates count, batches, ranges_n, ranges, pool bounds (checked_add), MOST (1 << 20) page cap, at.checked_add, and kind (0..=3) before mutating PAGES. Lock acquisition order (AWAY dropped before STATE -> PAGES, and PAGES dropped before page_now takes AWAY) has no inversion.
  • Both @pvfreis findings are resolved in f532d33 (Away::freed + block cleanup in FreeTitlePhysicalPages, post-placement away.title.insert in map_pages, forget_title_mappings on VirtualFree, and a_freed_page_is_read_at_its_pool_page).
  • PR description is green and the PR is cleanly MERGEABLE against main.

What is still needed before merge:

  1. Build and test (Windows, no GPU) needs to run on f532d33 (currently unrun / awaiting workflow approval or a rebase onto current main).
  2. An isolated AMD verification on #1055 (the RX 7900 XT test so far ran #1055 + #1102 together).

@raylitebull

Copy link
Copy Markdown
Member

Update: \Build and test (Windows, no GPU)\ is now green on \ 532d33\ (\CLEAN). Isolated AMD verification on \ 532d33\ is the only remaining item before merge.

@CharlyRien

Copy link
Copy Markdown

A reader for this record beyond textures (#1102): the title's buffer views and root views in the GPU view. Making them readable is what gets the world's geometry rasterised here. Result: #697 (comment) ; the per-page census with this PR's map is on #1031 (#1031 (comment)).

Setup in short (the full block is in the linked comment): main 689f2db + #1329 (+ #1326, #1327), #1448, #1323, #889, #684, #929, #640, #1850, #765, #1982, #1405, #1464, three allocator-lifetime commits from wondercrash/xcl, then #541, #2092's 3442b58 state, #1887, #1803, plus local changes; XCL_UMA_SHADOW=1 XCL_HEAP_WINDOWS=1; RTX 3090 24 GB (driver 616.56), Windows 11 22631; one clean run and one partial run. The census runs were on an older tree with this PR's decode-and-record part ported by hand.

  • The title's GPU-driven culling and its mesh programs read object lists, meshlet data and vertex streams through buffer views created by address (device recomp: run wave64 compute programs as two wave32 halves on 32-lane GPUs #70) and through root views whose addresses are in the GPU view. 65 % of the buffer V#s in the part of its view heap I dumped (the first 32 768 slots) are of that kind.
  • For those views, same offset in the CPU view is right at first (3 699 of 3 700 compute root views at 100 s) and drifts (119 of 12 918 wrong at 200 s), so the V# writers and the root-view setters would want mapped_source rather than mirrors::source once they rebase GPU-view addresses.
  • My experiment used copies filled from the same offset, without this map, and that was enough for geometry in the first 30 s of the world.

AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 for the ports and the runs) did this and drafted the comment.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main (crates/xcl/src/hle/kernelx.rs) — needs a rebase before it can be tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants