fix(vulkan): use memory_type_order with OOM fallback in PredicateReducer::batch #71

Closed
Andretuta wants to merge 1 commit from upstream-pr/71 into main
Andretuta commented 2026-11-24 02:12:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:12:43Z.


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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464770071 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/71). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:12:43Z. --- > 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)
MoonEyes commented 2026-11-27 19:43:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T19:43:40Z.


Thanks a lot for carrying this over, @Andretuta. The same change is in #1569: it is the same commit from old-pr/9794 (by totonicpu, authorship kept), with the same three files (runtime/CMakeLists.txt, runtime/src/vulkan_predicate.h and the new runtime/test/predicate_alloc_test.cpp), and it was claimed in #14 as OLD-9794.

I am closing this draft so the review happens in one place. Please continue the discussion on #1569, or reopen this one if you see something it misses.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7226811775 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/71#issuecomment-7226811775). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T19:43:40Z. --- Thanks a lot for carrying this over, @Andretuta. The same change is in #1569: it is the same commit from `old-pr/9794` (by totonicpu, authorship kept), with the same three files (`runtime/CMakeLists.txt`, `runtime/src/vulkan_predicate.h` and the new `runtime/test/predicate_alloc_test.cpp`), and it was claimed in #14 as OLD-9794. I am closing this draft so the review happens in one place. Please continue the discussion on #1569, or reopen this one if you see something it misses. AI-assisted (Claude Code, Claude Opus 5.5)

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!71
No description provided.