vk: retire finalized pools without inheritance, remove 1.4 GB VMA prealloc, and trim stale render targets #2759
Open
github-sync
wants to merge 1 commit from
github/pr/2759 into main
pull from: github/pr/2759
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:github/pr/2876
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2859
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:perf/astc-opaque-bc1
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!2759
Loading…
Reference in a new issue
No description provided.
Delete branch "github/pr/2759"
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?
On 8 GB GPUs, Hyrule Field exceeds the Vulkan driver's VRAM budget (
7,112 MBused of6,614 MBallowed on RTX 4060 Ti 8 GB) while host memory imports and VMA system heap blocks accumulate across scene loads. This PR removes the eager 1,408 MB VMA pool pre-allocation at startup, immediately retires pools finalized vianvnMemoryPoolFinalizewithout inheriting stale textures into reused VA ranges, and reclaims idle render-target and finalized textures so 8 GB cards stay well below their VRAM budget (6,190–6,456 MBof6,954 MBallowed) and release-5.9 GBof pinned host pool imports.What changed
Retire
nvnMemoryPoolFinalized pools without texture inheritance (gpu/vk/vk_memory.cpp):memory_pool_finalize()only markedFinalizeEntry::dead = truewithout retiring the matchingPoolEntry, leaving finalized pools inpools[]until an overlapping pool was registered later and then callingretire_pool(..., inherit=true)to transfer dead textures into the new pool.retire_finalized_pools()(called at the start ofmemory_begin_submission()andmemory_pool_register()) which callsretire_pool(idx, false)(inherit = false) for every finalized pool. When the guest explicitly finalizes anNVNmemoryPool, itsTextureEntryobjects havepool_dead = trueset and its host memory import is queued forretired_poolscleanup as soon as in-flight GPU work completes, rather than surviving indefinitely via VA-overlap inheritance.Avoid 1.4 GB upfront VMA block pre-allocation (
gpu/vk/vk_vma.cpp):vma_init()was settingminBlockCount = 9(1,152 MB) onimage_poolandminBlockCount = 2(256 MB) ontarget_image_poolwheneversplit == true(!unified_memory), unconditionally pinning1,408 MBof VRAM at boot even before any textures were created.minBlockCountto0on both pools while keeping128 MBblock sizes so VMA allocates blocks on demand and frees empty blocks back to the driver.Promptly evict finalized-pool textures & idle render targets (
gpu/vk/vk_texture.cpp,gpu/vk/vk_texture.h):texture_TrimStale(), textures belonging to finalized pools (t->pool_dead) now release theirVkImageas soon as their last submission timeline completes (last_val <= completed), even when overall VRAM is below the trim threshold.is_target) that have been unused for>= 120completed submissions (~2 seconds) are also trimmed during pressure passes and sett->released = true, allowingtarget_image_poolblocks from prior scenes/passes to compact and return to VMA.Measured before / after (RTX 4060 Ti 8 GB, Driver 617.42, Windows 11 Pro 26200, Ryzen 7 3700X, 32 GB RAM)
Measured in-game across Title Screen, Kokiri Forest, and Hyrule Field (45,600 presents):
hookshot_log.txt)main)2,681 MB(image_pool: 9 blocks /1,152 MBfor350 MBused)1,677 MB(image_pool: 1 block /128 MBfor119 MBused)7,112 MBused of6,614 MBallowed (+498 MB over budget)6,456 MBpeak /6,190–6,286 MBsteady of6,954 MBallowedtarget_image_poolVMA blocks13 blocks 1,664 MB(653 MBused,1,011 MBslack)5 blocks 640 MB(446 MBused,194 MBslack)520 MB(285textures)21 MB(97textures)heap 1 (system)32 blocks 1,232 MB(42allocs1,062 MB)11 blocks 288 MB(38allocs224 MB)10,793 MBof15,571 MB3,252 MBof15,571 MBvk: imports:)257 live (8,720 MB),16 retired still imported (560 MB)74 live (2,816 MB),0 retired still imported (0 MB),24 given back (1,136 MB)33,860 MB30,590–30,901 MBacross 45,600 framesTesting
57.0 fpsat end of session,0device lost) and added row todocs/tested-configurations.md.tests/test_finalized_pools_and_vma_prealloc.pyand ranpython -I -B tests/run_all.py target_image_pool retired_give_back pool_span vram_pressure finalized_pools utf8_paths(all 6 passed).Tested on
RTX 5090(32 GB VRAM, Windows 11, 98 GB RAM, NVIDIA 621.14) againstmain(c544828f),main + RX_VK_IMAGE_PREALLOC=0(the zero-preallocation bound), and #2711.Setup & method:
origin/main(c544828f) built withRX_RELEASE=1(17,888 programs, 25,303 graphics and 799 compute pipelines precompiled at startup), 2048x1152 uncapped (RX_VK_FRAMEGEN=0,HOS_FPS_MAX=240), Kokiri Forest autosave (80 s run: 40 s settle + 30 s measurement window).RX_RELEASE=1, 25,303 pipelines)mainimage_pool/target/textureblocksp95/p99ms)maincontrol9,357 MB)544 MB)24 (3072 MB)/6 (768 MB)/18 (2304 MB)17.07/19.61)main+RX_VK_IMAGE_PREALLOC=0(bound)main2)6,477 MB)512 MB)1 (128 MB)/7 (896 MB)/18 (2304 MB)18.06/19.40)hckrman101)7,021 MB)544 MB)1 (128 MB)/5 (640 MB)/24 (3072 MB)16.79/20.25)Hinkiii)6,237 MB, -3,120 MB)352 MB, -192 MB)1 (128 MB)/6 (768 MB)/18 (2304 MB)17.38/19.98)What #2759 recovers on a 24+ GB card:
images_pool()pre-allocation (-2,944 MB/100%of the stranded blocks): SettingminBlockCount = 0whenRX_VK_COMPACTorRX_VK_TARGET_BLOCKSis active dropsimage_poolfrom24 blocks (3,072 MB)to1 block (128 MB, 8 images 33 MB)whiletextures_poolallocates only the18 blocks (2,304 MB)actually used in Kokiri Forest — recovering all 23 stranded blocks (2,944 MB/2.88 GB) (100%of theRX_VK_IMAGE_PREALLOC=0bound, compared to17 blocks = 2,176 MBwith #2711, which keepsminBlockCount = 24ontextures_pool).-192 MBVMA system heap,-176 MBextra VMA device blocks): Capping idle capture buffer spares (25 kept (200 MB), 9 spare buffers) drops VMA system heap (heap 1) from544 MBto352 MB(-192 MB) and Peak Working Set by-155 MB, with0frames over 50 ms during the first 30 s in the field.I merged this into current main. The related checks pass (39). The full run_all fails only test_lift_cache, which fails on main here too, plus a load timeout in test_recorder_sync. The memory numbers are useful, but:
fix(vk): ...).splitis true unless both are 0, so this drops the prealloc for everyone, which RX_VK_IMAGE_PREALLOC=0 already does. It also overlaps #2711's images_pool() change.!retired_pools.empty()runs mirrors_give_back every submission.github-sync referenced this pull request2026-11-12 16:54:31 +00:00
retire_pool(cur, true)would keep the foliage fix. The mirror waits for an overlapping new pool for at mostkIdleEpochssubmissions, and the import isn't given back whileinherit_pendingis set, so it stays bounded. Did you see a reason it has to befalse?The 128 MB class was prewarmed for the scene-load capture spikes on AMD (the comment above
cap_prewarm_on). Without it, the first 128/192 MB capture of a load makes its buffer on the submitting thread again. The log line incap_prewarm_onstill says 32, 64, 128 MB.This marks the textures released straight away, outside the hold the replay keeps for releases while a queue is stopped (
held_tex_releases). If finalized-pool textures can still be read by stopped work, they'd need the same hold. Minor:env_onis read on every call here; astatic constlike the caller's would do.Thanks for this, and for the numbers. Giving finalized pools' imports back is a real gap on main (they sit in
importeduntil something overlaps them), and the host-import and system-heap drops in your table are the most interesting part of the PR. I agree with all four of @Joey-Magnus's points and won't repeat them; a few more below, then how I'd like to land it.Scope: please split this. As maintainer, my position is:
RX_VK_IMAGE_PREALLOC=0on 8 GB setups (an RTX 3060 Ti 8 GB, and a 4070 SUPER under the 8 GB model). It also keeps what #2438 was for: the ~170 ms block allocations on AMD's Windows driver. Nobody has measured AMD on Windows either way since #2438, and that's the one case where removing the blocks outright could cost something. Brett-D's 5090 numbers show the price: #2711 holds about 1 GB more private memory than no preallocation on a 32 GB card, by design. If an AMD Windows run later shows no stalls without the blocks, we can drop them in a follow-up with that data. So please drop thevk_vma.cpphunk. With it go the test'simages_poolcheck and the prealloc part of the docs row.texture_TrimStaleisn't touched.Retiring without inheritance. The retire is keyed on the guest pool table, which follows the game's current state, not the replay's. Three cases worry me:
retire_pool's comment (Joey's point 4). Simply callingretire_pool(cur, true)here looks like it would keep that:inherit_pendingalready expires afterkIdleEpochs(600 submissions), andretired_imports_give_backskips the import until it does. So the cost is a mirror held for ≤600 submissions, not a leak. Could you try that and see whether your memory numbers hold?held_tex_releases, from PR 430), because releasing them early let a pass read what wasn't there yet.texture_pool_finalizedmarks the pool's GPU-written textures released straight away, outside that hold.retire_poolalso clears the range's page-table entries while that stopped work may still reach the pool when it runs. Can the game finalize a pool while work that uses it is still waiting in our replay? If it can, this needs the same hold.hos_gpu_track(host/nvdrv.c) that a pool made over another's memory can lose its entry in the GPU mappings to the old pool's finalize. Those mappings are whathos_gpu_poolsreads. On main the import just stays. With this PR, a live pool in that state is retired, its textures are marked released and itsgpu_ownedranges are dropped.Capture buffers. The prewarm set loses its 128 MB class (and 192 MB), and spares are capped at 128 MB. That prewarm is a stutter fix: per its comment, capture buffers made at scene loads cost 13-107 ms on AMD. Brett-D's 5090 run shows no spikes, but that's NVIDIA. The comments and the startup log (
32, 64, 128 MB spares) no longer match either. This needs an AMD load run, or keep the 128 MB class.Measurements (rule: before/after on the same scene, hardware named). The 4060 Ti numbers are useful, but:
Once the retire is its own PR, an alternated pair (main, then this, twice) on the same route, with a note that the foliage and the textures are right after loads, would be enough.
CI: the only failure is the Conventional Commit title check, which comes from this PR's title. Everything else passes.
I'm happy to see the finalized-pool retire land once it's split out and case 1 is handled (or shown not to happen).