Repository navigation
runtime: unlock TitleImagePool across allocate/bind, skip full pages lock-free, and guard bad types/procs (RT-TITLE-IMAGE-POOL-LOCK-AND-GUARDS) - #1926
Conversation
…lock-free, and guard bad types/procs (RT-TITLE-IMAGE-POOL-LOCK-AND-GUARDS)
|
Native Windows/Intel verification of #1926 (0d7871f) together with #1920, on main b0f3d39 plus local integration fixes:
Combined integration, not an isolated A/B of this PR. No successful retail load or performance improvement claimed. The full existing_heap fixture still has a pre-existing first-render-target device-loss failure on this Intel setup, reproduced before these changes; the focused cases above were run separately. No game data included. AI-assisted with OpenAI Codex. |
|
#1926 | head 0d7871f (merged cleanly with main c7753ed) | |
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)