mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:35:53 +01:00
[PR #1926] runtime: unlock TitleImagePool across allocate/bind, skip full pages lock-free, and guard bad types/procs (RT-TITLE-IMAGE-POOL-LOCK-AND-GUARDS) #1935
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#1935
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/1926
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-title-image-pool-lock-and-guards📝 Commits (1)
0d7871fruntime: unlock TitleImagePool across allocate/bind, skip full pages lock-free, and guard bad types/procs (RT-TITLE-IMAGE-POOL-LOCK-AND-GUARDS)📊 Changes
2 files changed (+258 additions, -15 deletions)
View changed files
📝
runtime/src/vulkan_title_image_pool.h(+42 -13)📝
runtime/test/vulkan_title_image_pool_test.cpp(+216 -2)📄 Description
Item ID:
RT-TITLE-IMAGE-POOL-LOCK-AND-GUARDS(claim: #1608, comment 7167409068)Problem
In
leonida::TitleImagePool(runtime/src/vulkan_title_image_pool.h, used to sub-allocate small optimal title textures):TitleImagePool::bind()heldmutex_across bothallocate(page_size, page->type)(device_.allocate()->vkAllocateMemory) andbind_image()(vkBindImageMemory), serializing concurrent texture creation on unrelated size classes and already-available pages behind slow page allocation and driver bind calls.classes_[stride]calledpage->take()(locking each page'sstd::mutex) even on pages that were already completely full.classes_[stride]beforevkBindImageMemorysucceeded, and empty expired size-class buckets stayed inclasses_.req.memoryTypeBits & (1u << page->type)has undefined behavior ifallocate()returns atype >= 32, and an incompatibletype(not inreq.memoryTypeBits) was neither rejected nor freed, allowing a mismatched page to enter the pool.req.alignmentcorrupted(needed + quantum - 1) & ~(quantum - 1)stride rounding.image,bind_image,destroy_image, orfree_memorywere not checked before allocating/destroying.Fix
runtime/src/vulkan_title_image_pool.h:!image, null Vulkan procs, non-power-of-tworeq.alignment, and zeroneeded/memoryTypeBitsup front before takingmutex_.free_slotsatomically (std::atomic<std::uint32_t>) onTitleImagePagesobind()skips full pages viahas_free()without acquiring each full page'sstd::mutex.TitleImagePool::mutex_before callingallocate()andbind_image().page->memory && page->type < 32u && (req.memoryTypeBits & (1u << page->type))immediately afterallocate()(letting~TitleImagePage()freepage->memorycleanly on failure so no VRAM leaks).classes_[stride]only afterbind_image()returnsVK_SUCCESS, pruning expiredweak_ptrs (and keeping the already-bound image intact if weak-pointer map insertion throwsstd::bad_alloc).~TitleImagePage()and~PooledTitleImage()against null function pointers/page pointers.runtime/test/vulkan_title_image_pool_test.cpp:type == 32) and incompatible memory types (verifyingfree_memoryis called and no bad page is published), failedbind_imageon fresh pages, two non-blocking concurrency proofs verifyingmutex_is released duringallocate()andbind_image(), and a 4-thread TSan stress test across 3 size classes and 2 memory types with intermittent bind failures.Verification
clang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer runtime/test/vulkan_title_image_pool_test.cpp-> PASSclang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=thread -fno-omit-frame-pointer runtime/test/vulkan_title_image_pool_test.cpp-> PASSclang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/vulkan_title_image_pool_test.cpp(x3) -> PASSruntime/src/vulkan_backend.h-> PASSmain:runtime/src/vulkan_title_image_pool.h-> FAILED as expected (exit 1)python3 -I scripts/check_no_game_data.py runtime/src/vulkan_title_image_pool.h runtime/test/vulkan_title_image_pool_test.cpp-> PASSpython3 -I tests/test_text_write_line_endings.py-> PASS (3/3)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.