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

Open
github-bot wants to merge 1 commit from github-bot/gh-71 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:12 UTC · original
ubiquitarianism:old-pr/9794 → main · +306 −9 · 3 files · 1 commits · draft

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)
**@⁠Andretuta** on GitHub · 2026-11-24 02:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/71) `ubiquitarianism:old-pr/9794` → `main` · +306 −9 · 3 files · 1 commits · draft > 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:43:06 +00:00
This pull request has changes conflicting with the target branch.
  • runtime/CMakeLists.txt
  • runtime/src/vulkan_predicate.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/71/head:github-bot/gh-71'
git switch 'github-bot/gh-71'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-71'
git switch 'github-bot/gh-71'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-71'
git switch 'github-bot/gh-71'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-71'
git switch 'main'
git merge --squash 'github-bot/gh-71'
git switch 'main'
git merge --ff-only 'github-bot/gh-71'
git switch 'main'
git merge 'github-bot/gh-71'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.