Residency classes for title memory: keep one copy of GPU-read data in RAM or VRAM, not both #1702
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-25T08:46:14Z.
Problem
On the console the title's assets live once, in 16 GB of memory the CPU and GPU share. On a PC the runtime keeps most GPU-read title data twice:
Nothing ever releases the first copy after the second exists.
Measured on the retail boot (main
c7e82e26e, RTX 5070 Ti 16 GB, 64 GB RAM, Windows 11 26300,LEONIDA_MEM_PROBE=10), at t=258 s, a few seconds before the int3 at+0x2474606and the access violation:In the same log, title-memory imports that land below the arena fall back to an arena shadow (
an import of title memory at ... landed below the arena ...: a shadow in the arena is used instead), so even data that could have been shared ends up copied.Each run from #1537 onwards dies with commit and RAM exhausted. Raising
LEONIDA_TITLE_WINDOWS_MBandLEONIDA_ARENA_MB(as in #1537) moves the point of failure, but the duplication stays.Proposal: a residency class for every title range
Decide, per 64 KiB granule of title memory, where its one authoritative copy lives, and treat the other copy as a cache that can be dropped. This adds no new copy path; it only adds a rule for which existing copy may be released.
Signals the runtime already has
runtime/shims/xmem.cpp:PAGE_GRAPHICS_*bits (kPageGraphicsMask): the GPU reads the range;PAGE_NOACCESS: a GPU-only view (title_gpu_views);PAGE_WRITECOMBINE: the CPU streams writes the GPU reads;MEM_GRAPHICSonVirtualAlloc;XMemAlloc/XMemVirtualAllocattributes, for example the 0x183, 0x283, 0x23 and 0x27 values the retail title passes for its large blocks.title_write_watch/ShadowPages): whether the granule is rewritten every frame, was written once and then left alone, or is never written after its upload.Classes and what each keeps
PAGE_GRAPHICS_*VirtualUnlockon a range that is not locked removes it from the working set (documented in the Win32VirtualUnlockremarks). The OS writes it to the pagefile and pages it back in transparently if the CPU touches it, so no fault handler and no GPU readback are needed. A new CPU write sends the granule back to GPU-dynamic.VK_EXT_external_memory_host, already used for slot 133) so the GPU reads them in place over PCIe, instead of refreshing an arena shadow before every submissionChanges, in order (each one measurable on its own)
heap_base, as the arena already allows for imports above it, wherever the 32-bit table-pointer rule permits. Otherwise reserve the arena low enough for imports to land above it. Either way, a GPU-dynamic buffer keeps one copy.VirtualUnlockafter K clean submissions, behindLEONIDA_TITLE_RESIDENCY(off by default until it has been measured). This frees RAM only, not commit; commit is helped by steps 2 and 3.What this does not do
How to check it
Open question: what value of K separates a streamed asset from a per-frame buffer without trimming something that is about to be rewritten. Step 1's write-watch histogram should answer it.
Related: #1537 (title-window cap), section 3.3 of
docs/d3d12_vulkan.md(arena, imports, write watch),runtime/shims/xmem.cpp(kPageGraphicsMask,title_gpu_views).AI-assisted: yes (Claude Code, Claude Opus 5.5). The figures come from one retail boot on the hardware above, and the class rules are a proposal that has not been measured.
🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-25T10:11:16Z.
Progress on the steps above: step 1 (accounting) is #1734, step 2 (the arena out of ReBAR memory) is #1732. The cause of step 2 turned out to be the buffer's
memoryTypeBits: NVIDIA leaves the ReBAR type out above about 4,091 MiB, soLEONIDA_ARENA_MB=4096landed in system memory. Step 3 (imports below the arena): only 8 imports of up to 64 KiB fell back to shadows in that boot, so it is not worth doing for now.Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-26T12:40:28Z.
@kawaii-shakal is the residency-class step itself (the class table: per-granule classes and releasing the non-authoritative copy) free for someone to take? On a 12 GB card the world runs over the VRAM budget: on an RTX 4070 SUPER (NVIDIA 621.01, Windows 11, 64 GB RAM), the title's own device-local allocations come to about 9.3 GB plus our arena, 12-14.1 GB in use against a 10.6 GB budget at world entry, with the Series S device type already set. Shrinking
LEONIDA_ARENA_MB/LEONIDA_TITLE_WINDOWS_MBdoesn't get it under budget. The world then draws 1-7 frames a minute.If it's free, I'd start with the VRAM half: GPU-dynamic granules (written in most submissions) keep the title pages as the authoritative copy and get no device-local copy, behind an env switch, measured with #1734's accounting on that card. Happy to leave the RAM half (trimming GPU-static title pages) to you or to do it after, whichever you prefer. Counts only.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-30T17:13:27Z.
Notes from reading AnyPS5 (https://github.com/boykopovar/AnyPS5, commit 2af8e79,
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp,GuestBufferMemory.cpp,docs/user/USAGE.md"Texture cache budget"). It is a PS5 port layer on Vulkan, not an Xbox one: the console and the title differ, so only the shape of its answers to the same problem carries over — one console memory split into the PC's RAM and VRAM — not its numbers or thresholds, which would have to be measured on our title (the Series consoles also split their memory into a faster and a slower pool, which a PS5 title does not see). It is GPL-2.0-only, so these are ideas, not code to copy. All of them need a GPU run to judge; they apply to the Vulkan runtime (runtime/) — the d3d12/ runtime sits on native D3D12, where the system moves memory itself.allocate()(d3d12_vulkan_device.cpp) walksmemory_type_orderand goes to the next (host) type as soon as a device-local one fails, logged once. AnyPS5 first releases unused pooled buffers, then asks its texture caches to free reclaimable entries for the request plus what the heap is over itsVK_EXT_memory_budgetbudget, re-reads the budget, and only then places the allocation in host memory, logging count and MiB on the first five and every power of two. Their measurement of the cost, on a PS5 title (PPSA16064) and an RTX 4060 8 GB: ~870 MiB pushed to host memory took its first-level walk from 6.1-6.5 to 4.5-4.8 FPS. How much it costs GTA VI is not known; that is the measurement to make. Candidates on our side would be idle pooled memory (scratch spares #1898, KHR stage/query pools #1874, idle upload-ring slots #2463). Needs an 8 GB card that fills, before/after spill bytes and FPS. Overlaps #443 (proactive steering with a reserve): the question is which order wins on such a card.heapBudget, re-read every second, the sampled one shrinking first, each with a floor (their constants — budget/8 headroom, 512 MiB and 2 GiB floors — are tuned for PS5 titles). We already place page-mirror homes byusage + unit + max(1.5 GiB, budget/8) <= budget, one way: nothing is evicted. Whether our textures should evict rather than go to host memory is a GPU question.heapBudgetminus its other use minus budget/8, in 64 MiB steps, with MoltenVK's usage corrected (it counts imports in heap usage). We have a comment about an RTX 3070 Ti refusing imports after about 64 MiB; a budget read from the driver might replace per-driver guesses. Needs runs on NVIDIA and AMD.VK_EXT_memory_priority/ pageable device-local memory (#443 has these).To measure 1 and 2, the breakdown line now says per consumer how much is in host memory (RT-MEM-PROBE-HOST-SHARE, #2767). Anyone with an 8 GB card who wants to take one of these: say so here.
Generated by Claude Code
Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-30T17:15:30Z.
@Tyrannys sorry for the slow answer: yes, the residency-class step is free, and you can take both halves. I can't run the game on a GPU for about a week, and your 4070 SUPER is the case that shows the problem. I'm keeping the accounting side: #1734 (title memory behind filled images in RAM) and #2767 (per consumer, how much of the breakdown is in host memory), which should give you the before/after figures. If you want the RAM half (trimming GPU-static title pages) left for later, say so and I'll pick it up once I can test again.
Generated by Claude Code
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:06:23Z.
Closing this issue because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the report/contribution! If you believe this issue was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.