Skip to content

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

Open
Tortoche wants to merge 1 commit into
ProjectLeonida:mainfrom
Tortoche:old-9794
Open

Tortoche wants to merge 1 commit into
ProjectLeonida:mainfrom
Tortoche:old-9794

Conversation

@Tortoche

Copy link
Copy Markdown
Contributor

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 (comment)

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

Copy link
Copy Markdown

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants