runtime: BAR-aware memory fallback and bounded KHR/XDXR stage/query pools (RT-VK-MEMORY-FALLBACK-AND-STAGE-POOL-CAPS) #1874
Closed
leonida/mandy
quietfold wants to merge 0 commits from
fix/vk-memory-fallback-and-stage-pool-caps into main
pull from: fix/vk-memory-fallback-and-stage-pool-caps
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
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
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!1874
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/vk-memory-fallback-and-stage-pool-caps"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Item:
RT-VK-MEMORY-FALLBACK-AND-STAGE-POOL-CAPSClaim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164142288
Summary
Fixes three ad-hoc single-type
vkAllocateMemoryhelpers and unbounded per-queue acceleration-structure staging/query pools on the multi-frame world rendering path:BAR-aware memory fallback and heap-size validation (
runtime/src/vulkan_backend.h,runtime/src/vulkan_present_compose.h):detail::device_memory_orderanddetail::host_stage_memory_orderoverleonida::memory_type_order+resizable_bar()(with a fallback for synthetic zero-heap mocks such asreplay_query_edges_test.cppwherememoryHeapCount == 0).PresentComposer::ensure_target: guards zero width/height beforevkCreateImage(VUID-VkImageCreateInfo-extent-00944), avoids placing never-mapped RGBA16F compose targets in a 256 MiB non-ReBAR window when pure VRAM is available, skips undersized heaps (VUID-vkAllocateMemory-pAllocateInfo-01713), and retries remaining compatible types (including system RAM and host-only devices) onvkAllocateMemoryfailure while clearing failed handles before retry.OcclusionResolve::initialize: applies the same BAR-aware ordering, heap-size filtering, OOM retry loop, and cleanup onvkBindBufferMemoryfailure.VulkanQueue::acquire_stage(KHR TLASARRAY_OF_POINTERSand XDXR BLAS-address table staging): prefersDEVICE_LOCALon Resizable BAR GPUs and system RAM (!DEVICE_LOCAL) on non-ReBAR GPUs so per-frame staging does not exhaust the 256 MiB BAR window, skips undersized heaps, and retries remaining host-visible coherent types on OOM.Bounded pools, pre-prepare reclamation, and best-fit reuse (
runtime/src/vulkan_backend.h):VulkanQueue::recycle_completed_khr_pools()soacquire_stage()andallocate_khr_as_queries()reclaim KHR/XDXR stages and postbuildVkQueryPools from already-completed command slots beforeprepare()allocates fresh ones (previouslyrecycle_finished()ran inacquire()afterprepare(), causing steady frame-to-frame traffic to double-allocate).acquire_stage()andallocate_khr_as_queries()to best-fit selection (smallest sufficient pooled entry).khr_stage_pool_andkhr_as_query_pool_at 8 entries (kMaxPooledKhrStages/kMaxPooledKhrAsQueries), keeping the largest stages/pools and destroying evicted allocations immediately so monotonically growingtitle_va_aliasestables or TLAS bursts do not accumulate leakedVkDeviceMemory/VkQueryPoolhandles over sustained streaming.Regression test (
runtime/test/vk_memory_fallback_and_pools_test.cpp,runtime/CMakeLists.txt):Verification
Vulkan-Headers6802bb4733b63ed5efd3adb308a6c885ef180ea1)vk_memory_fallback_and_pools_test.cpp:clang++ -std=c++20 -Wall -Wextra -Werror ... -fsanitize=address,undefined->vk_memory_fallback_and_pools: okclang++ -std=c++20 -Wall -Wextra -Werror ... -fsanitize=thread->vk_memory_fallback_and_pools: okclang++ -std=c++20 -Wall -Wextra -Werror ... -O2(3 runs) ->vk_memory_fallback_and_pools: okvk_host_at_aliasing_test.cpp->vk_host_at_aliasing: okreplay_query_edges_test.cpp-> passedreplay_khr_as_copy_postbuild_test.cpp-> passedmainvulkan_backend.handvulkan_present_compose.h): 25 failures reproduced cleanly, exit code 1.python3 -I scripts/check_no_game_data.py runtime/src/vulkan_backend.h runtime/src/vulkan_present_compose.h runtime/test/vk_memory_fallback_and_pools_test.cpp runtime/CMakeLists.txt-> OKpython3 -I tests/test_text_write_line_endings.py-> 3 tests OKIndependent verification — Turing and Blackwell
5e95fa2f46d5df1a8397d5ee871add369031d8b66fbb6552efae6f8c091777899318d72e111ddceeEnvironment
NVIDIA 621.14, Vulkan SDK 1.4.363.0,
MSVC 19.44.35230, Ninja RelWithDebInfo.
Three repetitions per GPU, revision and validation mode.
The new mock-Vulkan test was run once per system on HEAD.
Results
vk_presenter_capture_colourvk_binary_occlusionvk_overlapping_occlusionvk_xdxr_postbuild_readbackreplay_query_edgesreplay_khr_as_copy_postbuildvk_memory_fallback_and_pools146 executions: 146 passed, 0 failed, 0 skipped.
Findings
passes under Windows/MSVC on both systems.
offsets and sentinels exact.
expected=320, compute_to_host_barriers=1.
Validation-layer feature-adjustment warnings were present.
No regressions observed on either architecture.
Allocation fallback and pool limits were covered by the
new mock test; physical BAR exhaustion and long-running
world-rendering workloads were not exercised.
Synthetic tests only. No game files used.
AI-assisted: yes.
Independent Hardware Verification & Cross-PR Interaction Note (RTX 3090, Windows 11)
origin/main(04f484006e) + PR#1874(6fbb6552ef) — clean 3-way merge (0conflicts).RelWithDebInfo), Vulkan SDK +VK_LAYER_KHRONOS_validation1.4.363.1(LEONIDA_VK_VALIDATION=1).Red -> Green Results
vk_memory_fallback_and_poolsagainstorigin/main'svulkan_backend.handvulkan_present_compose.h):rc=8,vk_memory_fallback_and_pools: 25 failure(s)across zero-extent guard, BAR-aware ordering/OOM retries, undersized-heap filtering, best-fit reuse, and stage/query pool caps).origin/main04f484006e+#18746fbb6552ef,LEONIDA_VK_VALIDATION=1):1.70 stotal,0Vulkan validation errors):vk_presenter_capture_colour: Passed (0.06 s)vk_overlapping_occlusion: Passed (0.37 s,261 segments summed; alternating binary results 1/1; resolve inside an active query 4)vk_binary_occlusion: Passed (0.40 s,1026 visible, 3 zero, 3 repeated)replay_khr_as_copy_postbuild: Passed (0.06 s)replay_query_edges: Passed (0.11 s)vk_xdxr_postbuild_readback: Passed (0.37 s,compute_to_host_barriers=1, reported_size=320, expected=320)vk_memory_fallback_and_pools: Passed (0.10 s)python -m unittest tests/test_ctest_registration.py tests/test_text_write_line_endings.py:10/10passed.python -I scripts/check_no_game_data.pyacross all 4 touched files: passed (0issues). No game files used.Heads-Up: Zero-Conflict CI Interaction with Open PR
#1681#1874(6fbb6552ef) +#1681(86eb22f7e8) ontoorigin/main(04f484006e) succeeds with zero Git conflicts (git merge-tree/git mergerc=0), butvk_memory_fallback_and_poolsfails 2 assertions (rc=8):FAIL: PresentComposer tries VRAM (1) -> BAR (0) -> RAM (2) in orderFAIL: OcclusionResolve tries VRAM (1) -> BAR (0) -> RAM (2)#1681updatesleonida::memory_type_order(memory, type_bits, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, size)inruntime/src/vulkan_memory.hso thatbar_window_type(DEVICE_LOCAL | HOST_VISIBLEin a<= 256 MiBheap) is placed last after system RAM ({1, 2, 0}onmake_non_rebar_props()), reserving the BAR window for the arena. In#1874,detail::device_memory_ordercallsmemory_type_order(..., 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, size)and appliesstd::stable_partitionfordevice_local && !small_bar, which leaves{1, 2, 0}(VRAM -> RAM -> BAR) unchanged once#1681is present; whendrv.fail_memory_types = {1, 0}is injected,type 2succeeds on attempt 2 ({1, 2}) instead of{1, 0, 2}.#1681and leave the 256 MiB BAR window to the arena (VRAM -> RAM -> BAR), update those two OOM order checks invk_memory_fallback_and_pools_test.cpp(fail{1, 2}and expect{1, 2, 0}).VRAM -> BAR -> RAMbefore host RAM,detail::device_memory_orderneeds a second partition pass placingdevice_local && small_barahead of!device_local.AI-assisted: yes
Verified by OreoFR — READY
vk_memory_fallback_and_poolsfails on main, for examplezero width rejected before vkCreateImage,PresentComposer picks pure VRAM (type 1) before 256 MiB BAR (type 0)andPresentComposer falls back to host RAM when VRAM and BAR OOM. The test's CMake registration was kept for the red run.vk_memory_fallback_and_poolspasses; ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p2 = main + #1874 + #1894 + #1713 (no shared files): 495 tests, new failures vs main: none (main alone: 494 tests, 5 failures: loader, xs_proxy_mock, xmem_no_write_watch, api_ref_state timeout, xbox_present; xbox_present fails in every package as on main)LEONIDA_CARGO=OFF,LEONIDA_XMA2_DECODER_LIBempty), main + this PR alone; imports unchanged vs main (25 DLLs, 655 functions, no WS2_32)AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
Independent verification on this machine (Windows 11, MSVC 19.44.35226): this pull request applies and builds, and its own new test then fails - and the reason is how far
mainhas moved under it, not the hardware.1. It applies.
merge-treeclean;6fbb6552echerry-picks ontomaindcba958e5without a conflict. Four files:runtime/CMakeLists.txt,runtime/src/vulkan_backend.h,runtime/src/vulkan_present_compose.hand the newruntime/test/vk_memory_fallback_and_pools_test.cpp.2. It builds, and the test is not hardware-dependent - its own header says so:
3. The test fails, on two assertions:
which come from:
4. Why a clean merge is not a working tree here:
The pull request carries both the implementation and the test, and the file it implements against has been rewritten in
mainthree times since its base. A textual cherry-pick puts the branch's version besidemain's newer code and produces a hybrid that neither side expects - and the test, being mock-based, reports it honestly.What that means for the author: a rebase will not fix this by itself. The fallback order the test demands has to be reconciled with what
vulkan_present_compose.hnow does - the patch is 2611 commits old in a file that moved, which is themain-drift case rather than an ordinary conflict.How it was found: a sweep of open pull requests that replay onto
main, building what each test'scommand[0]says to build and running it throughctest -R. 17 of the 25 in this batch built and passed; this is one of two that did not (the other, #1898, does not compile at all).Written with an AI assistant.
I reproduced the two mock failures on Linux and isolated the change in policy. Stock
vk_memory_fallback_and_poolspasses at6fbb6552on its original history. With6fbb6552merged ontomain171af5d93, both failing cases try types1, 2(pure VRAM, then system RAM) and succeed on type 2. They never reach the BAR window in those cases.The shared
memory_type_order()inruntime/src/vulkan_memory.hnow appends small BAR-window types for requests that don't ask for bothDEVICE_LOCALandHOST_VISIBLE. That rule came from commit798077b7cin #1681. As a control I restored just the older implementation ofmemory_type_order()in the merged tree. The original fixture passed with that one substitution.I also tested updating the fixture to the current policy while keeping the merged runtime unchanged. For both PresentComposer and OcclusionResolve, simulated OOM on VRAM now asserts
1 → 2with no BAR attempt. Simulated OOM on VRAM and RAM asserts1 → 2 → 0, so the last-resort BAR allocation is still covered. The complete fixture passed with ASan and UBSan. The comment abovedetail::device_memory_order()still describes the old BAR-before-RAM order and should match the revised expectation.Native Vulkan A/B: CachyOS, clang++ 23.1.5, RTX 4070 SUPER (620.73.04) and Radeon 610M/Raphael (RADV 26.3.1), Khronos validation 1.4.363. The same five CTest entries passed on each GPU with each tree, 20/20 overall. These were
vk_presenter_capture_colour,vk_binary_occlusion, bothvk_overlapping_occlusionvariants andvk_xdxr_postbuild_readback. The four device tests reported validation enabled and emitted zero VUIDs in these runs. The forced OOM paths were exercised only in the mock fixture.AI-assisted: yes (OpenAI Codex).
Closing this PR 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 contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.