Residency classes for title memory: keep one copy of GPU-read data in RAM or VRAM, not both #1702
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Reference
No Branch/Tag specified
main
github-pr/3295
beta
docs/changelog-3483-3500
github-pr/3294
github-pr/2975
github-pr/2815
feat/gate-driver-start
feat/skip-pipelines-release
perf/lazy-compare
perf/mwaitx-wait
test/prio-ceiling-main
fix/ab-cpu-stdout
fix/gate-old-crashes
diag/ab-cpu
test/main-0312
github-pr/3291
diag/indirect-clamp-census
feat/barrier-enhanced
perf/texture-frame-ceiling
perf/dstorage-threads
fix/console-queue-dma-tables
fix/port-descriptors-record-parts
fix/frame-waits-fence
fix/console-sampler-words
fix/graphics-userdata-spill
fix/xg-reserved-layout-rotation
fix/barrier-console-flags
fix/switches-wait-test-child
test/list-value-waits
test/lot-gxdk-0412
fix/bvh-compacted-size
docs/i18n-quickstarts
feat/native-pipeline-slots
fix/clippy-leonida-gpu
fix/list-value-producers
fix/descriptor-page-straddle
fix/xmem-low-window
fix/ffx-jitter-never-zero
fix/run-stdout-closed
github-pr/2892
github-pr/2896
feat/warm-save-every
github-pr/2980
github-pr/2994
github-pr/3005
github-pr/3010
github-pr/3136
github-pr/3303
github-pr/3220
github-pr/3143
github-pr/3330
github-pr/3226
github-pr/3187
carry/3395
github-pr/2946
github-pr/2947
github-pr/2945
github-pr/2983
github-pr/3001
github-pr/3372
github-pr/3128
github-pr/3296
github-pr/2588
github-pr/3119
github-pr/3378
fix/crash-diagnostics
feat/dlss-mip-bias
fix/retired-out-of-order
fix/dxr-postbuild-barrier
fix/amd-relay-default
fix/removed-report-wait
feat/heap-twin
feat/vram-margin
github-pr/2472
github-pr/3123
github-pr/3088
assets/annonce-v1
github-pr/2794
github-pr/3300
github-pr/3304
github-pr/3308
github-pr/3367
github-pr/3369
fix/launcher-dlss-diagnostics
github-pr/3269
github-pr/2957
github-pr/3205
fix/crash-zero-guard
github-pr/3185
github-pr/3099
github-pr/3104
github-pr/3348
github-pr/3379
github-pr/3377
perf/darner-title-priority-ceiling
github-pr/3376
gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github-pr/3373
github-pr/3368
github-pr/3198
gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github-pr/3346
github-pr/3375
github-pr/2958
github-pr/3151
github-pr/3307
github-pr/3278
github-pr/3374
fix/runtime-test-conservative-fixtures
github-pr/3366
ci/shard-semantic-linux
github-pr/3354
docs/fg-limit-fps-switch
github-pr/3365
fix/read-file-hard-link
github-pr/3364
fix/book-slot-heap-never-read
github-pr/3361
github-pr/3263
github-pr/3360
github-pr/3353
github-pr/3331
fix/alias-later-queued-submissions
github-pr/3352
github-pr/3228
github-pr/3349
claude/gallant-sagan-aamatr
github-pr/3200
github-pr/3132
github-pr/3323
github-pr/3332
github-pr/3340
github-pr/3311
github-pr/3334
github-pr/3297
github-pr/3256
github-pr/2567
github-pr/2851
d3d12/agility-sdk-621
github-pr/3164
github-pr/3114
github-pr/3050
github-pr/3113
github-pr/3326
github-pr/3144
github-pr/2642
github-pr/3072
github-pr/2789
github-pr/2643
github-pr/3009
github-pr/3035
github-pr/3031
github-pr/2686
github-pr/2834
github-pr/3321
github-pr/3325
github-pr/3290
github-pr/3324
github-pr/3130
claude/fervent-curie-m19lnr
github-pr/3309
github-pr/3305
github-pr/3306
github-pr/3302
github-pr/3301
github-pr/3345
github-pr/3211
github-pr/3027
github-pr/3286
github-pr/3235
github-pr/3265
github-pr/3275
codex/skip-no-hit-ray-passes
github-pr/2823
github-pr/2911
github-pr/3262
github-pr/3125
github-pr/3206
github-pr/3250
github-pr/3238
github-pr/3188
github-pr/2952
github-pr/3217
github-pr/3168
t3/preserve-fsr-sdk-restart-path
t3/propagate-host-failure-hresult
github-pr/3209
t3/launcher-custom-parameters
github-pr/3207
github-pr/3183
github-pr/3160
github-pr/3201
ci/less-to-run
github-pr/2930
github-pr/2797
github-pr/2999
perf/native-compute-shader-forms
github-pr/3191
github-pr/3011
github-pr/3019
github-pr/2996
gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
claude/blissful-franklin-ukp7ag
github-pr/3141
github-pr/3156
github-pr/3150
github-pr/3153
github-pr/3163
github-pr/3142
github-pr/3139
github-pr/2841
github-pr/3069
github-pr/3098
github-pr/3107
github-pr/3071
github-pr/2774
github-pr/2889
github-pr/3075
github-pr/2661
github-pr/3064
github-pr/3054
github-pr/3049
github-pr/2855
github-pr/2943
github-pr/3016
github-pr/2887
github-pr/3006
github-pr/3003
github-pr/2993
notes/card-time-and-plant-flicker
github-pr/2989
feat/vulkan-rs
github-pr/2985
github-pr/2951
github-pr/2982
github-pr/752
github-pr/792
github-pr/2877
github-pr/2654
github-pr/2893
github-pr/2948
github-pr/2944
github-pr/2919
github-pr/2915
archive/ci/less-to-run/20261202T1121Z
github-pr/2800
github-pr/2822
github-pr/2833
github-pr/2840
github-pr/2831
github-pr/2832
github-pr/2801
github-pr/2890
github-pr/2891
github-pr/2664
github-pr/2807
rt-call-trace
github-pr/2755
perf/ahead-split
github-pr/2587
github-pr/2698
github-pr/2609
github-pr/3219
docs/readme-runtime-proposal
github-pr/2017
github-pr/1741
github-pr/1667
codex/coord-claim-check-20261124-7e48
v1.1.0
v1.0.1
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy#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?
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
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.@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).
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
@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
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.