Skip to content

Memory: more than 4 memory windows once #680 lands, so title memory stops falling back to plain memory #697

Backlog

Description

@Daazd

Plan for comment before any code (CONTRIBUTING "Say what you are doing"). Stacked on #680.

The limit. Translated shaders reach 4 windows of 4 GiB (xcl_w = (hi) & 3u, emit.rs:1536); the title gets 11.5 GiB of sparse space. A retail title reserves more GPU-visible memory than that (kernelx.rs:322: a 24 GB reservation of 64 KiB pages, 2.2 GB of large pages), and the rest goes to plain memory outside every window. There its buffer views are empty V#s (real.rs:1751), vertex / index buffers are mirrored and copied every draw, up to 2 GiB of mirrors and stale after that (list_x.rs:1799-1866), and a raw pointer in a shader reads whichever window hi & 3 names.

Why now. With #680 a window is a descriptor index instead of a switch case, so a fifth or sixteenth window costs a shader nothing. What's left are constants: MAX_WINDOWS, the & 3u mask and the 4 heap slots.

Proposal. N windows (power of two, e.g. 16 → 64 GiB) in the heap form only: N · 4 GiB aligned to N · 4 GiB and below 2^40 (#585), windows 0..N-2 sparse and N-1 coherent as now, xcl_w = hi & (N-1) with N in Options and the cache key. The root-UAV switch form keeps 4.

Before any code: measurement. On the retail title (RTX 4070 Ti SUPER): bytes reserved and committed in plain GPU-visible memory, empty V#s, mirror MB and per-draw copy bytes. If little GPU traffic lands there, I'll report that and stop. Open risks: VRAM for pages that are plain today, write-watch and upload cost over more window memory, and whether out-of-range pointers should get an empty view instead of aliasing (a hi - base_hi index).

PR split (each stacked on #680, under ~400 lines): (1) window count as a value, no behaviour change; (2) N-window layout behind XCL_UMA_WINDOWS=n, with layout and GPU tests at window ≥ 4; (3) on by default, with smoke runs; (4) counters in report.json.

Does this fit where you want memory to go, or would you rather the windows stay at 4?

AI use: researched and drafted with Claude Code (Claude Opus 5.5); checked by me.

Activity

  1. maximecmb commented on Nov 24, 2026

    @maximecmb
    Contributor

    Data point for this plan: the retail title's empty buffer views all sit in its 24 GB GPU-view reservation, and wider windows alone don't reach it, because that reservation never goes to the windows

    Setup: RTX 5080 16 GB (driver 617.42, 32-lane waves), Ryzen 7 9800X3D, 64 GB, Windows 11 26300, Rust 1.100.0 MSVC, release builds, retail 1.0.2.1, XCL_NETWORK=0, XCL_ACTIVITY=1, hand-driven into the world load.

    1. Where the empty V#s are. #956 counts the views that get an empty V# and the resources unified memory had no room for. A local addition on top of it logs each empty buffer view's title address and size:

    • 125 buffer SRVs and 129 UAVs get an empty V#, all created at ~9–10 s in the menus. 4 + 8 more come during the world load. There are 0 no-room events.
    • Of the first 128, all 128 are in a graphics reservation outside the windows, and 0 are at any other title address. They include buffers of 50 MB, 26 MB, several of 5.9 MB, 2.7 MB and 1.8 MB.
    • That reservation is the 24 GB pair the kernelx::mirrors comment describes: kernelx: reservation 0x2eaa80c0000 (0x600000000 bytes, no CPU access) is the GPU view of 0x2e4a80c0000. With Memory: link xcl.exe without high-entropy ASLR so title memory stays under 2^40 #631 on main it now lands lower (the buffers are at ~0x43a6e0000), but it's still outside the windows.

    2. Why more windows don't change it. The pair is reserved as 64 KiB physical pages (MEM_LARGE_PAGES | MEM_PHYSICAL), not with MEM_GRAPHICS. So kernelx::VirtualAlloc never offers it to sparse_reserve / reserve: it goes straight to gpu_visible_fallback → reserve_watched, which is plain write-watched memory recorded in GRAPHICS_RESERVATIONS. That happens with any window count.

    I checked this with a local stack of main 6efdabc + #680 (its three current commits) + #822's two commits. I rebased them: in emit.rs I kept main's hi - xcl_uma_base window index with its range check, and in shaders.rs I took #822's window-count block. On top of that I added #956 and the address log, and ran with XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16:

    So for this title, the plan here only reaches those buffers if the 64 KiB-page pair is also placed in the windows, and the GPU view stays tied to the CPU view's pages the way mirrors::source ties them for textures.

    3. Why this looks worth it. A separate GTA VI–only project, which hands any title buffer to the host GPU by copying it on first use, keeps this title presenting the world for ~100 s on the same machine, at 1–3.5 fps with 1 100–2 770 draws per frame (its own missing shaders keep the picture dark). Under XCL the frames stop ~2 s into the world. That project has no equivalent of these empty views. That's a correlation, not proof: I haven't tested a build where the pair is reachable.

    Ruled out on this machine, each by a run:

    • unified memory running out (D3D12.X: count and report what console code cannot reach in unified memory #956: 0 no-room events)
    • shader writes into the sparse windows that the CPU never sees: a local opt-in that, after title submissions, merges every mapped sparse tile back into CPU memory (64-byte chunks the GPU changed and the CPU didn't) took 0 KB in every logged merge, and the stop was unchanged
    • more windows alone (above)

    Not tested: placing the 64 KiB-page pair in the windows; AMD; Linux.

    AI use: Claude Code (Claude Opus 5.5) wrote the local diagnostics and the experiment builds, read the logs and wrote this comment. I ran the title on the hardware above.

  2. Daazd commented on Nov 24, 2026

    @Daazd
    Author

    Thanks @maximecmb, this changes the plan.

    Window count: #822 already covers it (XCL_UMA_WINDOWS=8/16, stacked on #680), so I'm dropping my local window-count change and won't open a duplicate PR. What's left of this issue is the 24 GB GPU-view pair.

    One correction from reading main (b7aa9f3): kernelx::VirtualAlloc does try the windows for 64 KiB-page reservations. The MEM_64K_PAGES branch calls uma.sparse_reserve(size) before gpu_visible_fallback. The pair only falls back because sparse_reserve finds no 24 GB gap. So this is a space-and-pairing problem rather than a missing route.

    Proposed fix: put the CPU view in the windows, and point buffer views at it, instead of aliasing the GPU view.

    1. The CPU view goes in the windows, still paired. The 24 GB PAGE_READWRITE view, which is the one the title maps physical pages into, gets reserved in the sparse windows. That needs Memory/configurable uma windows #822's 16-window layout for the room. mirrors::reserved is then also called from the MEM_64K_PAGES sparse branch, not only after reserve_watched. Today, if the CPU view lands in the windows, it is never recorded, so its GPU view is never paired and title_textures loses the CPU view behind it (the Bink green screen would come back). The GPU view (PAGE_NOACCESS | PAGE_GRAPHICS_NOACCESS) stays where it is. It's never touched by the CPU, so it needs no window space.
    2. Buffer views in a GPU view are rebased to the CPU view. In dev_create_cbv_x and the SRV/UAV paths that currently write an empty V# (note_buffer_view), when va lies in a GPU view, the V# base becomes mirrors::source(va). That address is then in unified memory, so the shader reads the same pages the CPU writes. The check is the same as title_textures::mirror_source: if the title mapped a physical page at va itself (physical_page_at), va is kept. No second mapping and no syncing between the two views is needed, because the shader just reads the CPU view's address.
    3. Pass/fail: with D3D12.X: count and report what console code cannot reach in unified memory #956, the 125 SRV / 129 UAV empty buffer views drop to 0 (or the log names any that are left), the Bink video still plays, and we see whether Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505's stop moves.

    Limits of this approach:

    Questions:

    AI use: Claude Code (Claude Opus 5.5) read the code on main and the referenced PRs and drafted this reply. Nothing here is tested yet.

  3. CharlyRien commented on Nov 25, 2026

    @CharlyRien

    Data for the plan above, and an answer to "any reads of the GPU view that don't go through an empty V#?": yes, most of them. In a dump of the title's view heap taken when the world starts, 65 % of the buffer V#s are non-empty and carry a GPU-view address as their base. They come from the "view of memory at an address" device methods (#70 / #71), which write the title's address as it is, so the empty-V# count misses them, and step 2 as written would too.

    Setup

    1. The first 32 768 slots of the title's view heap in that frame

    what the slot holds slots
    image descriptor 15 680
    buffer V# whose base is in the GPU view of the 24 GB pair (high word 0x12: 10 764, 0x13: 23, 0xe: 43), outside every window 10 830
    buffer V# in a window 5 763
    all zero (an empty V# or never written; the two look the same) 476
    degenerate (base or size 0) 19

    So of 16 593 non-empty buffer V#s, 10 830 point into the GPU view. None point into the title's other 64 KiB-page reservations. On this tree dev_create_srv_at_x / dev_create_uav_at_x (device #70 / #71) write buffer_words_at(va, …) with the title's address unchanged, which is where these come from; note_buffer_view's empty V# is a different path.

    2. Root views (from a second pair of runs, same tree plus #1055's map, written up on #1031): 3 700 distinct compute root-view addresses in the GPU view in the first seconds of the world, 12 918 by 200 s. Rebasing those to the CPU view's same offset is right for all but one at 100 s and wrong for 119 at 200 s, so mirrors::source is a good first answer and #1055's per-page map is needed after that.

    3. Two readers that take a V# out of the view heap by index and end up with zeros (the heap address comes in the register after their root arguments, #1803):

    For both, the registers and the translation were checked. What I have not captured is the content of the exact slots the culling records name (they are past the part of the heap I dumped), so "those are GPU-view V#s" is inferred from the 65 %, not read; and for the mesh case the slot is a zero one, which could be an empty V# or a slot XCL never wrote.

    For the plan: placing the CPU view in the windows and rebasing would need to cover the by-address view methods and root views, not only the empty-V# path; and since two thirds of the title's buffer views are of this kind, I would expect it to change the picture, not just #505's stop. I can test a branch on this machine.

    Not tested: any fix; 16 windows; AMD; current main.

    AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 for the capture, the offline replay and the heap scan) did this and drafted the comment.

  4. CharlyRien commented on Nov 25, 2026

    @CharlyRien

    Follow-up to my comment above, with a test that goes against my own expectation: giving every one of these by-address views a readable copy does not restart the culling on this tree.

    Same tree and settings as above, plus #1055's map and a local experiment: when device #70 / #71 create a buffer view at a GPU-view address, the V# gets the address of a copy inside a sparse window, filled from the CPU view's same offset at creation and again at every present. One run, numbers at 106 – 123 s (about 20 s into the world).

    The views (counted in the title, not from a dump this time)

    The experiment

    • All 94 472 views got a copy (none over a cap, none refused); 81 387 copies were refreshed each frame (747 MB per frame), peak commit 41.8 GB.
    • Indirect draws of the captured frame: 263 of 286 still have an instance count of 0, 23 have work; 807 of 1 016 indirect dispatches have no groups. Without these copies, on the same tree last night: 262 of 267 (and 279 of 295 in a run that had copies for root views and empty views only), with about 800 of 1 000 dispatches without groups. An earlier run with copies for only the first 62 % of the views gave 262 of 270.
    • The main depth target of a later frame is still uniform (one value over the whole dump).

    So these views being unreadable is real and large, but it is not, on its own, what keeps the culling empty; my "I would expect it to change the picture" above was too optimistic. What I cannot exclude: the copies were filled from the same offset in the CPU view, and I did not compare their bytes with what the page map says the console would show (the map agreed with same offset on the samples logged). Root views and raw addresses into the GPU view were not covered by this experiment.

    Still not captured: the heap slots the culling records actually name. That is the next measurement here.

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

  5. CharlyRien commented on Nov 25, 2026

    @CharlyRien

    A correction to the conclusion of my last comment, and the measurement I said was missing. The exact heap slots the culling reads are now captured: all of them are GPU-view V#s. And with the copies in place the first culling program does write in the title; what stays empty is further down the chain.

    Same tree, settings and machine as my two comments above (the capture is from the tree without the copies; the in-title probe is from the tree with them).

    1. The slots, read from a capture (one frame, 4 dispatches of the first culling program, 81 groups)

    • Each group's record names a view-heap slot for its object list. 81 of 81 slots hold a well-formed buffer V# whose base is in the GPU view of the 24 GB pair; none is null, none is in a window.
    • The translated shader reads a count of 0 there. The CPU view at the same offset holds a count of 1 to 138 for every one of the 81.
    • Replayed offline from the capture (the real program, in the split-wave64 compute pass): as captured it fails its first guard in every lane and writes nothing, as in the title. With the out-of-window reads served from the CPU view's bytes it passes that guard, passes the next one for part of the lanes, and appends to its output list and counters in all 4 dispatches.

    2. In the title, with the by-address copies of my last comment and a probe on that program (one run)

    • In 4 of its 8 dispatches of the probed frame the program now changes its counter buffer (17, 4, 11 and 2 words, values from 1 to 157) and its output list. In every run probed without the copies it changed 0 words.
    • The frame's totals are unchanged all the same: 262 of 270 indirect draws with an instance count of 0, 819 of 996 indirect dispatches without groups.

    So "does not restart the culling" in my last comment was wrong as stated: the copies restart its first stage, and the indirect draws stay empty because of something downstream that I have not located yet (the other 4 dispatches, which use different buffers, still write nothing). The case for making the GPU view reachable is stronger than my last comment said, and same-offset rebasing is enough to get this first stage going.

    Not tested / limits: the capture keeps 64 bytes of each object list on the CPU side, so the offline replay is right for the first objects of a list only; one run each; nothing downstream of the first program.

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

  6. CharlyRien commented on Nov 25, 2026

    @CharlyRien

    With the GPU view of the 24 GB pair made readable for buffer views and root views (by copies, as an experiment), and the two-pass mesh path on top, the retail title rasterises world geometry here for the first time: the main depth target and the G-buffer hold a character and the scene around it. The presented frame is not right yet.

    Setup

    Measured, about 15 s into the world

    • Indirect mesh draws of one frame: 241, of which 115 now arrive with groups (562 groups), plus 12 direct DispatchMesh with groups. Before, the indirect ones had 0 groups, because the culling that fills their argument records wrote nothing.
    • Two-pass record headers read by those calls: 861 of 1 003 carry geometry, with real meshlet sizes such as (127 vertices, 116 primitives) and (128, 84). Before: every header was (1, 1) (see D3D12.X: execute two-pass mesh shaders on DispatchMesh and ExecuteIndirect #724).
    • Main depth target (2560×1440, D32S8), three consecutive frames: 91 %, 100 % and 100 % of the sampled texels differ from the clear value, with values spread up to 0.17, 1.0 and 0.54. Before, in every run dumped: one value over the whole target. The G-buffer colour targets are filled as well. Looking at the dumps, depth shows a character's head and shoulders and a wall edge, and one G-buffer target shows the same character and scene geometry.
    • The presented frame of the same moment is still close to uniform. I have not looked at what happens between the G-buffer and the present yet.

    What this does and does not show

    • It shows that the unreadable GPU view was what kept the world empty on this path: culling and mesh programs both take their data from it, through by-address views and root views.
    • It does not show which of the three kinds of copy are needed (all were on), nor that same-offset is right for all of them; about half of the indirect mesh draws still have 0 groups, which may be ordinary culling or inputs still missing.
    • The copies are an experiment, not a design: about 75 000 of them, 1.4 GB, with about 750 MB refilled from the CPU every frame, and writes through them do not go back to the title. Commit peaked at 43.6 GB; without the lower page budget the run does not fit in this machine's 64 GB of commit.

    For the plan above: rebasing GPU-view addresses to a CPU view placed in the windows (for the by-address views and root views too), or real aliasing, should give the same result without the copies. I can test such a branch here.

    Not tested: any of this without #541 / #724; AMD; current main; more than these two runs.

    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.

  7. ettehn commented on Nov 25, 2026

    @ettehn

    Synthetic mesh readback for GPU-view rebasing. I combined #2092 (47c7cc1), #1803 (cb00751, with its heap-base packing wired into the two-pass path), and #1055 (f532d33). The mesh compute pass reads a V# from the heap through s23. The test resolves backing addresses with #1055 and explicitly writes the descriptor between completed dispatches.

    • Remap: writing the V# once made it keep reading the old vertices after the GPU view moved to another physical page. Refreshing it from the updated mapping read the three new vertices.
    • Cross-page buffer: three 16-byte vertices started at offset 64 KiB - 16 in a view backed by pool pages 0 and 2. I filled pool page 1 with decoys. Rebasing to the first resolved address read one correct vertex and two decoys. Gathering the two mapped spans in view order into a contiguous read-only buffer read all three correctly.

    RTX 5070 Ti Laptop, driver 32.0.16.2124, Windows 11 25H2 (26200.9974), Ryzen 9 8945HX, Rust 1.97.1 MSVC, DXC 1.8.2502.11. With XCL_ADAPTER=nvidia XCL_HEAP_WINDOWS=1 XCL_DIRECT_DXIL=0, cargo test --locked --offline -j 2 -p xcl --lib gpu_mesh_mode -- --nocapture --test-threads=1 ran 2 passed, 0 failed, 0 skipped. This is a synthetic SRV readback. Retail frequency, in-flight mapping changes, UAV writes, and performance were outside the test.

    Test implementation and verification assisted by OpenAI Codex (GPT-6).

    Reserved-buffer alias follow-up. On the same RTX 5070 Ti Laptop, a 5-tile D3D12 reserved buffer exposed pool tiles 0, 2 as one logical range and 0, 1, 2 at separate offsets. The initial cross-boundary read returned 11, 22. A single-thread compute shader then wrote 33, 44 via a root UAV across the alias boundary. The original offsets read back 33, 99, 44, with the intervening decoy tile unchanged. After the first queue fence completed, I changed alias tile 1 to pool tile 1 with UpdateTileMappings. The next submission read back 33, 99 from the same alias range.

    cargo test --locked --offline -j 2 -p xcl --lib gpu_reserved_buffer_alias_spans_noncontiguous_tiles -- --nocapture --test-threads=1 with XCL_ADAPTER=nvidia ran 1 passed, 0 failed, 0 skipped. This checks D3D12 tile aliasing and ordered remap in isolation. XCL runtime integration, overlapping cross-queue use, and a retail title are still untested. Verification assisted by OpenAI Codex (GPT-6).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions