a/vk: Tidy calls to vk_get_memory_type

This commit is contained in:
Jakob Bornecrantz 2022-04-24 14:23:14 +01:00
parent 045fc9c33f
commit 27e4577acb

View file

@ -241,10 +241,10 @@ vk_alloc_and_bind_image_memory(struct vk_bundle *vk,
uint32_t memory_type_index = UINT32_MAX; uint32_t memory_type_index = UINT32_MAX;
bool bret = vk_get_memory_type( // bool bret = vk_get_memory_type( //
vk, // vk, // vk_bundle
memory_requirements.memoryTypeBits, // memory_requirements.memoryTypeBits, // type_bits
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, // VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, // memory_props
&memory_type_index); // &memory_type_index); // out_type_id
if (!bret) { if (!bret) {
VK_ERROR(vk, "(%s) vk_get_memory_type: false\n\tFailed to find a matching memory type.", caller_name); VK_ERROR(vk, "(%s) vk_get_memory_type: false\n\tFailed to find a matching memory type.", caller_name);
return VK_ERROR_OUT_OF_DEVICE_MEMORY; return VK_ERROR_OUT_OF_DEVICE_MEMORY;
@ -377,21 +377,25 @@ vk_create_image_advanced(struct vk_bundle *vk,
image, // image image, // image
&memory_requirements); // pMemoryRequirements &memory_requirements); // pMemoryRequirements
VkMemoryAllocateInfo memory_allocate_info = { uint32_t memory_type_index = UINT32_MAX;
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, bool bret = vk_get_memory_type( //
.allocationSize = memory_requirements.size, vk, // vk_bundle
}; memory_requirements.memoryTypeBits, // type_bits
memory_property_flags, // memory_props
if (!vk_get_memory_type( // &memory_type_index); // out_type_id
vk, // if (!bret) {
memory_requirements.memoryTypeBits, // VK_ERROR(vk, "vk_get_memory_type: false\n\tFailed to find a matching memory type.");
memory_property_flags, //
&memory_allocate_info.memoryTypeIndex)) { //
VK_ERROR(vk, "vk_get_memory_type failed: 'false'\n\tFailed to find a matching memory type.");
ret = VK_ERROR_OUT_OF_DEVICE_MEMORY; ret = VK_ERROR_OUT_OF_DEVICE_MEMORY;
goto err_image; goto err_image;
} }
// vkAllocateMemory argument
VkMemoryAllocateInfo memory_allocate_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.allocationSize = memory_requirements.size,
.memoryTypeIndex = memory_type_index,
};
ret = vk->vkAllocateMemory( // ret = vk->vkAllocateMemory( //
vk->device, // device vk->device, // device
&memory_allocate_info, // pAllocateInfo &memory_allocate_info, // pAllocateInfo
@ -809,16 +813,24 @@ vk_buffer_init(struct vk_bundle *vk,
VkMemoryRequirements requirements; VkMemoryRequirements requirements;
vk->vkGetBufferMemoryRequirements(vk->device, *out_buffer, &requirements); vk->vkGetBufferMemoryRequirements(vk->device, *out_buffer, &requirements);
uint32_t memory_type_index = UINT32_MAX;
bool bret = vk_get_memory_type( //
vk, // vk_bundle
requirements.memoryTypeBits, // type_bits
properties, // memory_props
&memory_type_index); // out_type_id
if (!bret) {
VK_ERROR(vk, "vk_get_memory_type: false\n\tFailed to find a matching memory type.");
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
// vkAllocateMemory argument
VkMemoryAllocateInfo alloc_info = { VkMemoryAllocateInfo alloc_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.allocationSize = requirements.size, .allocationSize = requirements.size,
.memoryTypeIndex = memory_type_index,
}; };
if (!vk_get_memory_type(vk, requirements.memoryTypeBits, properties, &alloc_info.memoryTypeIndex)) {
VK_ERROR(vk, "Failed to find matching memoryTypeIndex for buffer");
return false;
}
res = vk->vkAllocateMemory(vk->device, &alloc_info, NULL, out_mem); res = vk->vkAllocateMemory(vk->device, &alloc_info, NULL, out_mem);
vk_check_error("vkAllocateMemory", res, false); vk_check_error("vkAllocateMemory", res, false);