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

Closed
Tortoche wants to merge 1 commit from upstream-pr/1569 into main
Tortoche commented 2026-11-25 04:47:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tortoche on 2026-11-25T04:47:06Z.


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://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7147781405

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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485351733 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1569). Originally posted by [Tortoche](https://github.com/Tortoche) on 2026-11-25T04:47:06Z. --- 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://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7147781405 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)
adrianmjim commented 2026-11-25 09:04:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-25T09:04:42Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7157844468 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1569#issuecomment-7157844468). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T09:04:42Z. --- 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.
MoonEyes commented 2026-11-28 02:59:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:59:42Z.


Hi @Tortoche, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/CMakeLists.txt, runtime/src/vulkan_predicate.h), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232724905 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1569#issuecomment-7232724905). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:59:42Z. --- Hi @Tortoche, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/CMakeLists.txt`, `runtime/src/vulkan_predicate.h`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:36:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:36:43Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317892996 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1569#issuecomment-7317892996). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:36:43Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

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!1569
No description provided.