[PR #1910] runtime: cache helper Vulkan device procs, fix uncounted BDA fault and BAR/cleanup guards (RT-VK-HELPER-PROC-CACHE-AND-GUARDS) #1919

Open
opened 2026-11-26 21:19:24 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1910
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/rt-vk-helper-proc-cache-and-guards


📝 Commits (1)

  • 8651979 runtime: cache helper Vulkan device procs, fix uncounted BDA fault and BAR/cleanup guards (RT-VK-HELPER-PROC-CACHE-AND-GUARDS)

📊 Changes

6 files changed (+714 additions, -155 deletions)

View changed files

📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/src/quad_index_expand.h (+48 -26)
📝 runtime/src/vulkan_indirect_dispatch_count.h (+91 -50)
📝 runtime/src/vulkan_predicate.h (+125 -48)
📝 runtime/src/vulkan_predicated_copy.h (+66 -31)
➕ runtime/test/vk_helper_proc_cache_test.cpp (+377 -0)

📄 Description

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):

  1. Fix uncounted count_offset GPU BDA fault + immediate failure cleanup (vulkan_indirect_dispatch_count.h):
    • Previously, when LEONIDA_INDIRECT_GROUP_BUDGET was active and count == VK_NULL_HANDLE with a non-zero count_offset, Batch::prepare() accepted the call and wrote out.count = count_va + count_offset = count_offset != 0; emit() then treated job.count != 0 as has_count = 1 and passed count_offset as a raw GPU device address.
    • Batch::prepare() now rejects !count && count_offset != 0, explicitly sets out.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 partial VkBuffer/VkDeviceMemory allocations immediately on failure instead of retaining dead handles until submission completion.
  2. BAR-aware memory selection, heap-size filtering, and OOM fallback (vulkan_predicate.h):
    • Replaces PredicateReducer::batch()'s first-DEVICE_LOCAL loop with memory_type_order() (with memoryHeapCount == 0 mock compatibility), prefers pure VRAM over the 256 MiB BAR window on non-ReBAR GPUs, retries all eligible memory types on VK_ERROR_OUT_OF_DEVICE_MEMORY, and clears failed handles on error.
  3. Immediate pool cleanup on descriptor allocation failure (vulkan_predicated_copy.h):
    • PredicatedBufferCopier::Batch::prepare() destroys the newly created VkDescriptorPool immediately if vkAllocateDescriptorSets fails instead of keeping an empty pool in pools until batch teardown.
  4. Eliminate per-command vkGetDeviceProcAddr string lookups (all four helpers):
    • Resolves and caches all required PFN_vk* function pointers once inside make_pipeline() rather than invoking vkGetDeviceProcAddr through the loader on every prepare(), capture(), emit(), and batch cleanup call.

Verification

  • AI-assisted: yes.
  • GPUs tested: none (macOS host, CPU-only portable Vulkan-Headers mock harness; no game files used).
  • New CTest target vk_helper_proc_cache (runtime/test/vk_helper_proc_cache_test.cpp, Clang 20, C++20, -Wall -Wextra -Werror):
    • ASan + UBSan (default and with LEONIDA_INDIRECT_GROUP_BUDGET=1024): PASS
    • TSan (LEONIDA_INDIRECT_GROUP_BUDGET=1024): PASS
    • -O2 × 3 (LEONIDA_INDIRECT_GROUP_BUDGET=1024): PASS
  • Existing regression suites under ASan + UBSan:
    • runtime/test/indirect_dispatch_count_alloc_test.cpp: PASS
    • runtime/test/replay_quad_list_test.cpp: PASS
  • Mutation test against main's headers with LEONIDA_INDIRECT_GROUP_BUDGET=1024: fails on main (prepare(args, 0, VK_NULL_HANDLE, 16, ...) returned true), passes on this branch.
  • Hygiene: python3 -I scripts/check_no_game_data.py on all 6 touched files and python3 -I tests/test_text_write_line_endings.py passed.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1910 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-vk-helper-proc-cache-and-guards` --- ### 📝 Commits (1) - [`8651979`](https://github.com/ubiquitarianism/leonida/commit/86519799babe8962efb5bed31a89915313b490a2) runtime: cache helper Vulkan device procs, fix uncounted BDA fault and BAR/cleanup guards (RT-VK-HELPER-PROC-CACHE-AND-GUARDS) ### 📊 Changes **6 files changed** (+714 additions, -155 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/src/quad_index_expand.h` (+48 -26) 📝 `runtime/src/vulkan_indirect_dispatch_count.h` (+91 -50) 📝 `runtime/src/vulkan_predicate.h` (+125 -48) 📝 `runtime/src/vulkan_predicated_copy.h` (+66 -31) ➕ `runtime/test/vk_helper_proc_cache_test.cpp` (+377 -0) </details> ### 📄 Description 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`): 1. **Fix uncounted `count_offset` GPU BDA fault + immediate failure cleanup (`vulkan_indirect_dispatch_count.h`)**: - Previously, when `LEONIDA_INDIRECT_GROUP_BUDGET` was active and `count == VK_NULL_HANDLE` with a non-zero `count_offset`, `Batch::prepare()` accepted the call and wrote `out.count = count_va + count_offset = count_offset != 0`; `emit()` then treated `job.count != 0` as `has_count = 1` and passed `count_offset` as a raw GPU device address. - `Batch::prepare()` now rejects `!count && count_offset != 0`, explicitly sets `out.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 partial `VkBuffer`/`VkDeviceMemory` allocations immediately on failure instead of retaining dead handles until submission completion. 2. **BAR-aware memory selection, heap-size filtering, and OOM fallback (`vulkan_predicate.h`)**: - Replaces `PredicateReducer::batch()`'s first-`DEVICE_LOCAL` loop with `memory_type_order()` (with `memoryHeapCount == 0` mock compatibility), prefers pure VRAM over the 256 MiB BAR window on non-ReBAR GPUs, retries all eligible memory types on `VK_ERROR_OUT_OF_DEVICE_MEMORY`, and clears failed handles on error. 3. **Immediate pool cleanup on descriptor allocation failure (`vulkan_predicated_copy.h`)**: - `PredicatedBufferCopier::Batch::prepare()` destroys the newly created `VkDescriptorPool` immediately if `vkAllocateDescriptorSets` fails instead of keeping an empty pool in `pools` until batch teardown. 4. **Eliminate per-command `vkGetDeviceProcAddr` string lookups (all four helpers)**: - Resolves and caches all required `PFN_vk*` function pointers once inside `make_pipeline()` rather than invoking `vkGetDeviceProcAddr` through the loader on every `prepare()`, `capture()`, `emit()`, and batch cleanup call. ### Verification - **AI-assisted**: yes. - **GPUs tested**: none (macOS host, CPU-only portable Vulkan-Headers mock harness; no game files used). - New CTest target `vk_helper_proc_cache` (`runtime/test/vk_helper_proc_cache_test.cpp`, Clang 20, C++20, `-Wall -Wextra -Werror`): - ASan + UBSan (default and with `LEONIDA_INDIRECT_GROUP_BUDGET=1024`): PASS - TSan (`LEONIDA_INDIRECT_GROUP_BUDGET=1024`): PASS - `-O2` × 3 (`LEONIDA_INDIRECT_GROUP_BUDGET=1024`): PASS - Existing regression suites under ASan + UBSan: - `runtime/test/indirect_dispatch_count_alloc_test.cpp`: PASS - `runtime/test/replay_quad_list_test.cpp`: PASS - Mutation test against `main`'s headers with `LEONIDA_INDIRECT_GROUP_BUDGET=1024`: fails on `main` (`prepare(args, 0, VK_NULL_HANDLE, 16, ...)` returned `true`), passes on this branch. - Hygiene: `python3 -I scripts/check_no_game_data.py` on all 6 touched files and `python3 -I tests/test_text_write_line_endings.py` passed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1919
No description provided.