runtime: unlock ImageMemoryPool across driver allocations/frees and fix BlockRanges alignment overflow #1975
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1975"
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?
Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T17:12:58Z.
Claim:
RT-IMAGE-MEMORY-UNLOCK-ALLOC-AND-OVERFLOW(claim comment#7169137144on #1608).Fixes (
runtime/src/image_memory.h)mutex_acrossallocate_()and failure-pathfree_()inImageMemoryPool::allocate():allocate()heldmutex_acrossallocate_(type, block_bytes)(a 100+ µsvkAllocateMemorykernel call) and across failure-pathfree_(memory)— stalling every concurrent texture allocation,stats()query, andDeferredDeletionQueuerange release, and risking AB-BA lock-order inversion with driver/device locks (release()already unlockedmutex_before callingfree_()).allocate_()andfree_()callbacks run outsidemutex_, with exception-safe cleanup ifstd::make_unique<Block>throws.uint64_twraparound inBlockRanges::allocate()alignment calculation:(piece + alignment - 1) / alignment * alignmentcould wrapuint64_tfor largealignmenton a non-zeropiece.rem = piece % alignment; lead = rem ? alignment - rem : 0).BlockRanges::release():by_offset_.lower_bound(offset)and iterator-based erasure instead of two separate tree lookups, and guards zero-size releases.Verification
CMakeLists.txtchanges).runtime/test/image_memory_test.cppwithallocate_runs_unlocked()(blocks insideallocate_()while verifying another thread completes an existing-block allocation,stats(), andrelease()without deadlocking) plusBlockRangesalignment-overflow (UINT64_MAX,(1<<63)+1,0) and zero-size release tests.image_memory_testcleanly under:clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror -pthreadclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror -pthreadclang++ -std=c++20 -O2 -Wall -Wextra -Werror -pthreadpython3 -I scripts/check_no_game_data.pyon both files andpython3 -I tests/test_text_write_line_endings.py: all passed.Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T17:13:10Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:38:45Z.
Verified on Windows 11 (
10.0.26200.9974) with MSVC19.44.35228(x64,/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) againstmaind48a957bb+1f1248b95d(claim#2570#issuecomment-7239309422):runtime/src/image_memory.h,runtime/test/image_memory_test.cpp); avoids(piece + alignment - 1)uint64_twraparound viapiece % alignment, guards zero size/alignment, reuses thelower_bounditerator inBlockRanges::release, and unlocksmutex_across driverallocate_()/free_().check_no_game_data.pyclean.d48a957bb+ PR test):image_memory_test.exedeadlocks (TIMEOUT after 12s) inallocate_runs_unlocked()becausemainholdsmutex_acrossallocate_().d48a957bb+1f1248b95dmerge): Auto-merges cleanly (rc=0), compiles with0warnings under/W4 /permissive-, and passes (image memory: textures share blocks, and released ranges are used again,rc=0).#1698: Confirmedgit merge-treeconflicts with sibling PR#1698onimage_memory.h/image_memory_test.cpp; when reconciling the two, keep#1698's pre-allocatedRange+pool.blocks.reserve(...)sopush_back/new Rangeafterlock.lock()cannot leakmemoryorranges_understd::bad_alloc.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:56:09Z.
Red/green: On main image_memory_test hangs until the 300 s timeout (the pool stays locked across driver allocations), and with the PR ctest -R "^image_memory$" passes in 0.4 s.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main
c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:57:23Z.
Verified by OreoFR
c1ecf04ed+ PR head1f1248b95; green run in a merge package of 16 PRs, no new ctest failure vs mainctest -R ^image_memory$AI-assisted (Claude Code, Claude Opus 5.5).