OLD-9794: fix(vulkan): use memory_type_order with OOM fallback in PredicateReducer::batch #1569

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

@⁠Tortoche on GitHub · 2026-11-25 04:47 UTC · original
Tortoche:old-9794 → main · +306 −9 · 3 files · 1 commits · open

Item ID: OLD-9794
Carries forward Draft #71 (old-pr/9794 by totonii / totonicpu, preserving original commit authorship at dd8625af6), rebased cleanly onto main (364ab4eab).
Claimed in #14: #14

AI-assisted: yes

Summary

  • runtime/src/vulkan_predicate.h (PredicateReducer::batch):
    • Replace the single-choice memory-type scan with leonida::memory_type_order(memory_, requirements.memoryTypeBits, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, requirements.size) (runtime/src/vulkan_memory.h), filtering out heaps smaller than requirements.size (VUID-vkAllocateMemory-pAllocateInfo-01713).
    • Iterate over all ordered 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 safely.
  • runtime/test/predicate_alloc_test.cpp & runtime/CMakeLists.txt:
    • Add CPU-only mock Vulkan dispatch test predicate_alloc_test (registered as predicate_alloc under if(TARGET Vulkan::Headers)), covering undersized-heap skip, OOM fallback, all-heaps-undersized failure, and all-types-OOM cleanup.

Tests Executed (Linux x86_64, no retail game files / no Windows build)

  • ctest --test-dir runtime/build -C RelWithDebInfo: 71 Passed / 2 Skipped (shader_library_corpus, vk_sync_validation) / 0 Failed out of 73
    • ctest --test-dir runtime/build -C RelWithDebInfo -E "^xdxr_build_check$" --output-on-failure: 70 Passed / 2 Skipped / 0 Failed out of 72 (including predicate_alloc 1/1 and vk_predicate_capture 1/1)
    • Isolated ctest --test-dir runtime/build -C RelWithDebInfo -R "^xdxr_build_check$" --output-on-failure: 2/2 Passed (xdxr_build, xdxr_build_check)
  • ./runtime/build/predicate_alloc_test: OK (predicate_alloc_test: all checks passed)
  • python3 -I tests/test_ci_registration.py: 16/16 passed
  • python3 -I tests/test_ctest_registration.py: 5/5 passed
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed
  • python3 -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/src/vulkan_predicate.h runtime/test/predicate_alloc_test.cpp: OK (exit 0, zero game data)
**@⁠Tortoche** on GitHub · 2026-11-25 04:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1569) `Tortoche:old-9794` → `main` · +306 −9 · 3 files · 1 commits · open Item ID: `OLD-9794` Carries forward Draft `#71` (`old-pr/9794` by `totonii` / `totonicpu`, preserving original commit authorship at `dd8625af6`), rebased cleanly onto `main` (`364ab4eab`). Claimed in `#14`: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 AI-assisted: yes ### Summary - `runtime/src/vulkan_predicate.h` (`PredicateReducer::batch`): - Replace the single-choice memory-type scan with `leonida::memory_type_order(memory_, requirements.memoryTypeBits, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, requirements.size)` (`runtime/src/vulkan_memory.h`), filtering out heaps smaller than `requirements.size` (`VUID-vkAllocateMemory-pAllocateInfo-01713`). - Iterate over all ordered 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 safely. - `runtime/test/predicate_alloc_test.cpp` & `runtime/CMakeLists.txt`: - Add CPU-only mock Vulkan dispatch test `predicate_alloc_test` (registered as `predicate_alloc` under `if(TARGET Vulkan::Headers)`), covering undersized-heap skip, OOM fallback, all-heaps-undersized failure, and all-types-OOM cleanup. ### Tests Executed (Linux x86_64, no retail game files / no Windows build) - `ctest --test-dir runtime/build -C RelWithDebInfo`: **71 Passed / 2 Skipped** (`shader_library_corpus`, `vk_sync_validation`) **/ 0 Failed out of 73** - `ctest --test-dir runtime/build -C RelWithDebInfo -E "^xdxr_build_check$" --output-on-failure`: **70 Passed / 2 Skipped / 0 Failed out of 72** (including `predicate_alloc` **1/1** and `vk_predicate_capture` **1/1**) - Isolated `ctest --test-dir runtime/build -C RelWithDebInfo -R "^xdxr_build_check$" --output-on-failure`: **2/2 Passed** (`xdxr_build`, `xdxr_build_check`) - `./runtime/build/predicate_alloc_test`: **OK** (`predicate_alloc_test: all checks passed`) - `python3 -I tests/test_ci_registration.py`: **16/16 passed** - `python3 -I tests/test_ctest_registration.py`: **5/5 passed** - `python3 -I tests/test_text_write_line_endings.py`: **3/3 passed** - `python3 -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/src/vulkan_predicate.h runtime/test/predicate_alloc_test.cpp`: **OK** (exit 0, zero game data)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:54 +00:00
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 09:04 UTC · original

Tested dd8625af6 applied onto main 42537e7b6 on Windows with an AMD Radeon RX 7900 XT (RDNA3), AMD driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 (MSVC 19.44), RelWithDebInfo. This is the first Windows run, and the first on a discrete GPU reported here. No game files.

  • The new test builds under MSVC and predicate_alloc passes.
  • The related tests pass, 13 of 13, plain and with LEONIDA_VK_VALIDATION=1 (validation on, no messages).
    • Seven of them run on the card and reach PredicateReducer::batch with its real memory layout: vk_command_replay, vk_predicated_copy, vk_predicate_capture, vk_overlapping_occlusion, vk_overlapping_occlusion_no_statistics, vk_binary_occlusion and d3d12_predicated_copy.
    • The other six are CPU-only or mocked: predicated_copy, replay_write_immediate_predication, d3d12_state_map, indirect_dispatch_count_alloc, predicate_alloc and replay_query_predication.
  • Whole ctest -j 6: 400 of 403 without failures (387 passed, 13 skipped). The three failures are the same on main (399 of 402): d3d12_texture_tiles (#964), d3d12_clear and d3d12_geometry_views (#1678). No regression.

One small thing in the test. On OOM the mock vkAllocateMemory already writes VK_NULL_HANDLE to *out, so no check depends on the new b->memory = VK_NULL_HANDLE reset: the tests would pass without it. If the mock wrote a poison handle such as 0xdead on failure, test 4 would catch a missing reset: batch would come back non-null, because the poison handle passes the !b->memory check and the mock bind succeeds.

**@⁠adrianmjim** on GitHub · 2026-11-25 09:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1569#issuecomment-7157844468) Tested `dd8625af6` applied onto `main` `42537e7b6` on Windows with an AMD Radeon RX 7900 XT (RDNA3), AMD driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 (MSVC 19.44), RelWithDebInfo. This is the first Windows run, and the first on a discrete GPU reported here. No game files. - **The new test builds under MSVC** and `predicate_alloc` passes. - **The related tests** pass, 13 of 13, plain and with `LEONIDA_VK_VALIDATION=1` (validation on, no messages). - Seven of them run on the card and reach `PredicateReducer::batch` with its real memory layout: `vk_command_replay`, `vk_predicated_copy`, `vk_predicate_capture`, `vk_overlapping_occlusion`, `vk_overlapping_occlusion_no_statistics`, `vk_binary_occlusion` and `d3d12_predicated_copy`. - The other six are CPU-only or mocked: `predicated_copy`, `replay_write_immediate_predication`, `d3d12_state_map`, `indirect_dispatch_count_alloc`, `predicate_alloc` and `replay_query_predication`. - **Whole `ctest -j 6`:** 400 of 403 without failures (387 passed, 13 skipped). The three failures are the same on `main` (399 of 402): `d3d12_texture_tiles` (#964), `d3d12_clear` and `d3d12_geometry_views` (#1678). No regression. One small thing in the test. On OOM the mock `vkAllocateMemory` already writes `VK_NULL_HANDLE` to `*out`, so no check depends on the new `b->memory = VK_NULL_HANDLE` reset: the tests would pass without it. If the mock wrote a poison handle such as `0xdead` on failure, test 4 would catch a missing reset: `batch` would come back non-null, because the poison handle passes the `!b->memory` check and the mock bind succeeds.
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/1569/head:github-bot/gh-1569'
git switch 'github-bot/gh-1569'

Merge

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