mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:25:53 +01:00
[GH-ISSUE #1702] Residency classes for title memory: keep one copy of GPU-read data in RAM or VRAM, not both #47
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#47
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?
Originally created by @kawaii-shakal on GitHub (Nov 25, 2026).
Original GitHub issue: https://github.com/ubiquitarianism/leonida/issues/1702
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
@kawaii-shakal commented on GitHub (Nov 25, 2026):
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.@Tyrannys commented on GitHub (Nov 26, 2026):
@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).