diff options
author | Bas Nieuwenhuizen <[email protected]> | 2019-07-10 14:21:11 +0200 |
---|---|---|
committer | Bas Nieuwenhuizen <[email protected]> | 2019-10-10 17:02:34 +0000 |
commit | 825ddfee59945e00845637262fba05975f7d16a4 (patch) | |
tree | 6725d5bc926d1d956c3f69bfd5606800e6a69862 /src/amd | |
parent | e1469c02cf424e38ab67a83fdffdad5b3ae830d0 (diff) |
radv: Handle device memory alloc failure with normal free.
Less duplication/complexity.
Reviewed-by: Samuel Pitoiset <[email protected]>
Diffstat (limited to 'src/amd')
-rw-r--r-- | src/amd/vulkan/radv_device.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 072b944169a..a5b3839394d 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -3419,6 +3419,23 @@ bool radv_get_memory_fd(struct radv_device *device, pFD); } + +static void radv_free_memory(struct radv_device *device, + const VkAllocationCallbacks* pAllocator, + struct radv_device_memory *mem) +{ + if (mem == NULL) + return; + + if (mem->bo) { + radv_bo_list_remove(device, mem->bo); + device->ws->buffer_destroy(mem->bo); + mem->bo = NULL; + } + + vk_free2(&device->alloc, pAllocator, mem); +} + static VkResult radv_alloc_memory(struct radv_device *device, const VkMemoryAllocateInfo* pAllocateInfo, const VkAllocationCallbacks* pAllocator, @@ -3450,7 +3467,7 @@ static VkResult radv_alloc_memory(struct radv_device *device, const struct wsi_memory_allocate_info *wsi_info = vk_find_struct_const(pAllocateInfo->pNext, WSI_MEMORY_ALLOCATE_INFO_MESA); - mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8, + mem = vk_zalloc2(&device->alloc, pAllocator, sizeof(*mem), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (mem == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -3477,6 +3494,7 @@ static VkResult radv_alloc_memory(struct radv_device *device, (int)(priority_float * RADV_BO_PRIORITY_APPLICATION_MAX)); mem->user_ptr = NULL; + mem->bo = NULL; if (import_info) { assert(import_info->handleType == @@ -3538,15 +3556,14 @@ static VkResult radv_alloc_memory(struct radv_device *device, result = radv_bo_list_add(device, mem->bo); if (result != VK_SUCCESS) - goto fail_bo; + goto fail; *pMem = radv_device_memory_to_handle(mem); return VK_SUCCESS; -fail_bo: - device->ws->buffer_destroy(mem->bo); fail: + radv_free_memory(device, pAllocator,mem); vk_free2(&device->alloc, pAllocator, mem); return result; @@ -3570,14 +3587,7 @@ void radv_FreeMemory( RADV_FROM_HANDLE(radv_device, device, _device); RADV_FROM_HANDLE(radv_device_memory, mem, _mem); - if (mem == NULL) - return; - - radv_bo_list_remove(device, mem->bo); - device->ws->buffer_destroy(mem->bo); - mem->bo = NULL; - - vk_free2(&device->alloc, pAllocator, mem); + radv_free_memory(device, pAllocator, mem); } VkResult radv_MapMemory( |