render/vulkan: add error handling for vulkan_find_mem_type()

The function returns -1 if it doesn't find a suitable memory type.
This commit is contained in:
Simon Ser 2022-09-19 11:45:10 +02:00 committed by Simon Zeni
parent 5206cea566
commit 8d6d2101bc
1 changed files with 9 additions and 3 deletions

View File

@ -271,12 +271,18 @@ struct wlr_vk_buffer_span vulkan_get_stage_span(struct wlr_vk_renderer *r,
VkMemoryRequirements mem_reqs;
vkGetBufferMemoryRequirements(r->dev->dev, buf->buffer, &mem_reqs);
int mem_type_index = vulkan_find_mem_type(r->dev,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, mem_reqs.memoryTypeBits);
if (mem_type_index < 0) {
wlr_log(WLR_ERROR, "Failed to find memory type");
goto error;
}
VkMemoryAllocateInfo mem_info = {0};
mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
mem_info.allocationSize = mem_reqs.size;
mem_info.memoryTypeIndex = vulkan_find_mem_type(r->dev,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, mem_reqs.memoryTypeBits);
mem_info.memoryTypeIndex = (uint32_t)mem_type_index;
res = vkAllocateMemory(r->dev->dev, &mem_info, NULL, &buf->memory);
if (res != VK_SUCCESS) {
wlr_vk_error("vkAllocatorMemory", res);