[PR #71] fix(vulkan): use memory_type_order with OOM fallback in PredicateReducer::batch #123

Open
opened 2026-11-26 20:16:52 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/71
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9794


📝 Commits (1)

  • 028df8b fix(vulkan): use memory_type_order with OOM fallback in PredicateReducer::batch

📊 Changes

3 files changed (+306 additions, -9 deletions)

View changed files

📝 runtime/CMakeLists.txt (+6 -0)
📝 runtime/src/vulkan_predicate.h (+11 -9)
➕ runtime/test/predicate_alloc_test.cpp (+289 -0)

📄 Description

Carried over from old PR 9794 by totonicpu in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9794, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
totonicpu: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Summary

Fixes VUID-vkAllocateMemory-pAllocateInfo-01713 and missing OOM memory-type fallback in leonida::PredicateReducer::batch() (runtime/src/vulkan_predicate.h:70-81), matching the memory_type_order() policy used in d3d12_vulkan_device.cpp and vulkan_indirect_dispatch_count.h (#8978):

  • Replaces the hand-rolled single-choice memory-type loop with leonida::memory_type_order() (runtime/src/vulkan_memory.h), skipping any memory type whose heap is smaller than requirements.size (and bounding memoryTypeCount / heapIndex).
  • Iterates through all compatible memory types when vkAllocateMemory() fails (e.g., VK_ERROR_OUT_OF_DEVICE_MEMORY), resetting b->memory = VK_NULL_HANDLE on each failed attempt so ~Batch() cleans up cleanly.

Testing

  • Fail-first proof: Added CPU-only mock test runtime/test/predicate_alloc_test.cpp (registered as predicate_alloc under Vulkan::Headers, no GPU required). Before the fix it failed at line 220: state.alloc_attempts[0].first == 1u (attempting to allocate 2048 B from a 1024 B heap).
  • Build (Debug & RelWithDebInfo, MSVC): 0 new warnings across predicate_alloc_test, d3d12_state_map_test, vk_predicate_capture_test, and vk_command_replay_test.
  • CTest (Debug & RelWithDebInfo) + RTX 4070 Ti with LEONIDA_VK_VALIDATION=1:
    • predicate_alloc: Passed (Debug & RelWithDebInfo)
    • d3d12_state_map: Passed (Debug & RelWithDebInfo)
    • vk_predicate_capture: Passed on NVIDIA GeForce RTX 4070 Ti with Vulkan validation enabled (32 gated + 32 reused submissions, 192 snapshots, 0 validation errors)
    • vk_command_replay: Passed on NVIDIA GeForce RTX 4070 Ti with Vulkan validation enabled (0 validation errors)

🔄 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/71 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9794` --- ### 📝 Commits (1) - [`028df8b`](https://github.com/ubiquitarianism/leonida/commit/028df8b53feb0294ccfb3a8e15c428d22e1fe4e0) fix(vulkan): use memory_type_order with OOM fallback in PredicateReducer::batch ### 📊 Changes **3 files changed** (+306 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+6 -0) 📝 `runtime/src/vulkan_predicate.h` (+11 -9) ➕ `runtime/test/predicate_alloc_test.cpp` (+289 -0) </details> ### 📄 Description > Carried over from **old PR 9794** by `totonicpu` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9794`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `totonicpu`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): ## Summary Fixes `VUID-vkAllocateMemory-pAllocateInfo-01713` and missing OOM memory-type fallback in `leonida::PredicateReducer::batch()` (`runtime/src/vulkan_predicate.h:70-81`), matching the `memory_type_order()` policy used in `d3d12_vulkan_device.cpp` and `vulkan_indirect_dispatch_count.h` (`#8978`): - Replaces the hand-rolled single-choice memory-type loop with `leonida::memory_type_order()` (`runtime/src/vulkan_memory.h`), skipping any memory type whose heap is smaller than `requirements.size` (and bounding `memoryTypeCount` / `heapIndex`). - Iterates through all compatible memory types when `vkAllocateMemory()` fails (e.g., `VK_ERROR_OUT_OF_DEVICE_MEMORY`), resetting `b->memory = VK_NULL_HANDLE` on each failed attempt so `~Batch()` cleans up cleanly. ## Testing - **Fail-first proof:** Added CPU-only mock test `runtime/test/predicate_alloc_test.cpp` (registered as `predicate_alloc` under `Vulkan::Headers`, no GPU required). Before the fix it failed at `line 220: state.alloc_attempts[0].first == 1u` (attempting to allocate 2048 B from a 1024 B heap). - **Build (`Debug` & `RelWithDebInfo`, MSVC):** 0 new warnings across `predicate_alloc_test`, `d3d12_state_map_test`, `vk_predicate_capture_test`, and `vk_command_replay_test`. - **CTest (`Debug` & `RelWithDebInfo`) + RTX 4070 Ti with `LEONIDA_VK_VALIDATION=1`:** - `predicate_alloc`: Passed (Debug & RelWithDebInfo) - `d3d12_state_map`: Passed (Debug & RelWithDebInfo) - `vk_predicate_capture`: Passed on NVIDIA GeForce RTX 4070 Ti with Vulkan validation enabled (`32 gated + 32 reused submissions, 192 snapshots`, 0 validation errors) - `vk_command_replay`: Passed on NVIDIA GeForce RTX 4070 Ti with Vulkan validation enabled (0 validation errors) --- <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#123
No description provided.