mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:50:52 +01:00
[PR #1874] runtime: BAR-aware memory fallback and bounded KHR/XDXR stage/query pools (RT-VK-MEMORY-FALLBACK-AND-STAGE-POOL-CAPS) #1888
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#1888
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1874
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/vk-memory-fallback-and-stage-pool-caps📝 Commits (1)
6fbb655runtime: BAR-aware memory fallback and bounded KHR/XDXR stage/query pools📊 Changes
4 files changed (+1151 additions, -56 deletions)
View changed files
📝
runtime/CMakeLists.txt(+12 -0)📝
runtime/src/vulkan_backend.h(+171 -46)📝
runtime/src/vulkan_present_compose.h(+9 -10)➕
runtime/test/vk_memory_fallback_and_pools_test.cpp(+959 -0)📄 Description
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 OK🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.