runtime: cache helper Vulkan device procs, fix uncounted BDA fault and BAR/cleanup guards (RT-VK-HELPER-PROC-CACHE-AND-GUARDS) #1910
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1910"
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-25T15:35:34Z.
Item ID:
RT-VK-HELPER-PROC-CACHE-AND-GUARDS(claimed in #1608).Summary
Hardens and speeds up the four Vulkan replay compute helpers (
runtime/src/vulkan_indirect_dispatch_count.h,runtime/src/vulkan_predicate.h,runtime/src/vulkan_predicated_copy.h,runtime/src/quad_index_expand.h):count_offsetGPU BDA fault + immediate failure cleanup (vulkan_indirect_dispatch_count.h):LEONIDA_INDIRECT_GROUP_BUDGETwas active andcount == VK_NULL_HANDLEwith a non-zerocount_offset,Batch::prepare()accepted the call and wroteout.count = count_va + count_offset = count_offset != 0;emit()then treatedjob.count != 0ashas_count = 1and passedcount_offsetas a raw GPU device address.Batch::prepare()now rejects!count && count_offset != 0, explicitly setsout.count = count ? count_va + count_offset : 0, prefers pure VRAM ahead of the 256 MiB BAR window on non-ReBAR GPUs (!resizable_bar()), and destroys partialVkBuffer/VkDeviceMemoryallocations immediately on failure instead of retaining dead handles until submission completion.vulkan_predicate.h):PredicateReducer::batch()'s first-DEVICE_LOCALloop withmemory_type_order()(withmemoryHeapCount == 0mock compatibility), prefers pure VRAM over the 256 MiB BAR window on non-ReBAR GPUs, retries all eligible memory types onVK_ERROR_OUT_OF_DEVICE_MEMORY, and clears failed handles on error.vulkan_predicated_copy.h):PredicatedBufferCopier::Batch::prepare()destroys the newly createdVkDescriptorPoolimmediately ifvkAllocateDescriptorSetsfails instead of keeping an empty pool inpoolsuntil batch teardown.vkGetDeviceProcAddrstring lookups (all four helpers):PFN_vk*function pointers once insidemake_pipeline()rather than invokingvkGetDeviceProcAddrthrough the loader on everyprepare(),capture(),emit(), and batch cleanup call.Verification
vk_helper_proc_cache(runtime/test/vk_helper_proc_cache_test.cpp, Clang 20, C++20,-Wall -Wextra -Werror):LEONIDA_INDIRECT_GROUP_BUDGET=1024): PASSLEONIDA_INDIRECT_GROUP_BUDGET=1024): PASS-O2× 3 (LEONIDA_INDIRECT_GROUP_BUDGET=1024): PASSruntime/test/indirect_dispatch_count_alloc_test.cpp: PASSruntime/test/replay_quad_list_test.cpp: PASSmain's headers withLEONIDA_INDIRECT_GROUP_BUDGET=1024: fails onmain(prepare(args, 0, VK_NULL_HANDLE, 16, ...)returnedtrue), passes on this branch.python3 -I scripts/check_no_game_data.pyon all 6 touched files andpython3 -I tests/test_text_write_line_endings.pypassed.Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T15:35:51Z.
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:17:41Z.
#1910 | head
86519799ba(merged cleanly with maind48a957bb9) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vk_helper_proc_cache|indirect_dispatch_count_alloc|replay_quad_list|d3d12_indirect_dispatch_count|d3d12_indirect_group_budget|d3d12_predicated_copy)$" --output-on-failure(LEONIDA_VK_VALIDATION=1, plusLEONIDA_INDIRECT_GROUP_BUDGET=1024) | red on main:vk_helper_proc_cachefails (exit 8 at!batch->prepare(args, 0, VK_NULL_HANDLE, 16, 12, 4, out)withLEONIDA_INDIRECT_GROUP_BUDGET=1024) | green on PR+main: 6/6 CTests pass (vk_helper_proc_cacheboth default andLEONIDA_INDIRECT_GROUP_BUDGET=1024,indirect_dispatch_count_alloc,replay_quad_list,d3d12_indirect_dispatch_count,d3d12_indirect_group_budget, andd3d12_predicated_copy) on RTX 3090 with0Khronos validation errors;check_no_game_data.py0violations (coordination note:#2491also touches!count && count_offset != 0invulkan_indirect_dispatch_count.h, choosing to ignorecount_offsetwhen!countper D3D12ExecuteIndirectsemantics rather than refusingprepare()) | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yesImported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T12:03:31Z.
Run of this pull request on a second machine.
Heads: PR head
86519799b, main8fb974878. Merged: git merge --no-ff of the PR into main, no conflicts.Commands (RelWithDebInfo, Ninja, -DLEONIDA_REQUIRE_VULKAN=ON):
Green: 9/9 pass. vk_helper_proc_cache is a mock-device test (no GPU). The other eight are existing tests that exercise the four touched headers (the GPU ones, d3d12_predicated_copy, d3d12_indirect_dispatch_count and d3d12_quad_index, ran on the RTX 3090).
Red (behavioural: the test compiles against the old headers): the four changed headers (quad_index_expand.h, vulkan_indirect_dispatch_count.h, vulkan_predicate.h, vulkan_predicated_copy.h) restored to main, test and CMake entry kept. vk_helper_proc_cache then fails at vk_helper_proc_cache_test.cpp:229, the immediate-cleanup check after a failed bind (create_buffer_calls == 1 && destroy_buffer_calls == 1 && free_memory_calls == 1). The test stops at its first failing check, so later cases were not enumerated.
One observation: the first case of the test (an uncounted call with a non-zero count_offset must be rejected) passes on main too. The test does not set LEONIDA_INDIRECT_GROUP_BUDGET, and main already rejects an uncounted call when no budget is set, so the budget-active path described in the PR (the one that passed count_offset as a device address) is not exercised by the test.
Link: gta6rt.exe of the merged build vs gta6rt.exe of main
8fb974878(dumpbin /imports, DLL!symbol, sorted, 694 entries): no new imports vs main.Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44, Vulkan SDK 1.4.363.1.