-
Notifications
You must be signed in to change notification settings - Fork 921
[ET-VK] VMA assertion crash on macOS/MoltenVK: test_host_cached_available() returns bool instead of VmaAllocationCreateFlags #18696
Copy link
Copy link
Open
Description
Bug
test_host_cached_available() in backends/vulkan/runtime/vk_api/memory/Allocator.cpp is declared as returning bool but returns VmaAllocationCreateFlags values, causing implicit truncation to 1 (true).
This results in allocation_strategy_device_to_host_ being set to 1 (VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) instead of the intended VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT (0x800) or VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT (0x400).
When a DEVICE_TO_HOST staging buffer is created, the invalid flag causes a VMA assertion failure:
Assertion failed: ((inoutCreateInfo.flags & (VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0 && "When using VMA_ALLOCATION_CREATE_MAPPED_BIT
and usage = VMA_MEMORY_USAGE_AUTO*, you must also specify VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT
or VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT."), function CalcAllocationParams, file vk_mem_alloc.h, line 14926.
Reproduction
- Platform: macOS (Apple Silicon) with MoltenVK
- Model: Any Vulkan model exported with
force_fp16=True - ExecuTorch version: 1.2.0
Works fine on 1.1.0 where this function didn't exist.
Root Cause
// Allocator.cpp, line 13
bool test_host_cached_available(VkPhysicalDevice physical_device) { // <- returns bool
// ...
if (host_visible && host_cached) {
return VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; // 0x800 -> truncated to true (1)
}
return VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT; // 0x400 -> truncated to true (1)
}Then at line 37-38:
allocation_strategy_device_to_host_{test_host_cached_available(physical_device_)}
// Gets value 1 instead of 0x800 or 0x400Used at line 181:
alloc_create_info.flags |= allocation_strategy_device_to_host_; // ORs in 1 instead of a host access flagFix
Change the return type from bool to VmaAllocationCreateFlags:
VmaAllocationCreateFlags test_host_cached_available(VkPhysicalDevice physical_device) {Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels