From 43e21702f65a5a22e5d38c3e459153290d321050 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Tue, 9 Aug 2022 10:26:54 -0700 Subject: [PATCH] anv: Integrate gem vm bind and unbind kmd backend functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_allocator.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index d451ee3..e1f0931 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -1372,11 +1372,8 @@ anv_bo_alloc_flags_to_bo_flags(struct anv_device *device, } static void -anv_bo_finish(struct anv_device *device, struct anv_bo *bo) +anv_bo_unmap_close(struct anv_device *device, struct anv_bo *bo) { - if (bo->offset != 0 && !bo->has_fixed_address) - anv_vma_free(device, bo->offset, bo->size + bo->_ccs_size); - if (bo->map && !bo->from_host_ptr) anv_device_unmap_bo(device, bo, bo->map, bo->size); @@ -1384,6 +1381,22 @@ anv_bo_finish(struct anv_device *device, struct anv_bo *bo) device->kmd_backend->gem_close(device, bo->gem_handle); } +static void anv_bo_vma_free(struct anv_device *device, struct anv_bo *bo) +{ + if (bo->offset != 0 && !bo->has_fixed_address) + anv_vma_free(device, bo->offset, bo->size + bo->_ccs_size); +} + +static void +anv_bo_finish(struct anv_device *device, struct anv_bo *bo) +{ + /* Not releasing vma in case unbind fails */ + if (device->kmd_backend->gem_vm_unbind(device, bo) == 0) + anv_bo_vma_free(device, bo); + + anv_bo_unmap_close(device, bo); +} + static VkResult anv_bo_vma_alloc_or_close(struct anv_device *device, struct anv_bo *bo, @@ -1411,7 +1424,7 @@ anv_bo_vma_alloc_or_close(struct anv_device *device, bo->offset = anv_vma_alloc(device, bo->size + bo->_ccs_size, align, alloc_flags, explicit_address); if (bo->offset == 0) { - anv_bo_finish(device, bo); + anv_bo_unmap_close(device, bo); return vk_errorf(device, VK_ERROR_OUT_OF_DEVICE_MEMORY, "failed to allocate virtual address for BO"); } @@ -1538,6 +1551,12 @@ anv_device_alloc_bo(struct anv_device *device, if (result != VK_SUCCESS) return result; + if (device->kmd_backend->gem_vm_bind(device, &new_bo)) { + anv_bo_vma_free(device, &new_bo); + anv_bo_unmap_close(device, &new_bo); + return vk_errorf(device, VK_ERROR_UNKNOWN, "vm bind failed"); + } + if (new_bo._ccs_size > 0) { assert(device->info->has_aux_map); intel_aux_map_add_mapping(device->aux_map_ctx, @@ -1793,6 +1812,12 @@ anv_device_import_bo(struct anv_device *device, return result; } + if (device->kmd_backend->gem_vm_bind(device, &new_bo)) { + anv_bo_vma_free(device, &new_bo); + pthread_mutex_unlock(&cache->mutex); + return vk_errorf(device, VK_ERROR_UNKNOWN, "vm bind failed"); + } + *bo = new_bo; } -- 2.7.4