[Mesa-dev] [PATCH 07/15] anv: refactor, remove else block in AllocateMemory

Lionel Landwerlin lionel.g.landwerlin at intel.com
Tue Dec 11 11:27:23 UTC 2018


On 27/11/2018 10:53, Tapani Pälli wrote:
> This makes it cleaner to introduce more cases where we import memory
> from different types of external memory buffers.
>
> Signed-off-by: Tapani Pälli <tapani.palli at intel.com>


Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>


> ---
>   src/intel/vulkan/anv_device.c | 64 +++++++++++++++++++----------------
>   1 file changed, 34 insertions(+), 30 deletions(-)
>
> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
> index 6b5ba25c6bc..0cbbaeca3b3 100644
> --- a/src/intel/vulkan/anv_device.c
> +++ b/src/intel/vulkan/anv_device.c
> @@ -2340,42 +2340,46 @@ VkResult anv_AllocateMemory(
>          * If the import fails, we leave the file descriptor open.
>          */
>         close(fd_info->fd);
> -   } else {
> -      const VkExportMemoryAllocateInfoKHR *fd_info =
> -         vk_find_struct_const(pAllocateInfo->pNext, EXPORT_MEMORY_ALLOCATE_INFO_KHR);
> -      if (fd_info && fd_info->handleTypes)
> -         bo_flags |= ANV_BO_EXTERNAL;
> -
> -      result = anv_bo_cache_alloc(device, &device->bo_cache,
> -                                  pAllocateInfo->allocationSize, bo_flags,
> -                                  &mem->bo);
> -      if (result != VK_SUCCESS)
> -         goto fail;
> +      goto success;
> +   }
>   
> -      const VkMemoryDedicatedAllocateInfoKHR *dedicated_info =
> -         vk_find_struct_const(pAllocateInfo->pNext, MEMORY_DEDICATED_ALLOCATE_INFO_KHR);
> -      if (dedicated_info && dedicated_info->image != VK_NULL_HANDLE) {
> -         ANV_FROM_HANDLE(anv_image, image, dedicated_info->image);
> +   /* Regular allocate (not importing memory). */
>   
> -         /* Some legacy (non-modifiers) consumers need the tiling to be set on
> -          * the BO.  In this case, we have a dedicated allocation.
> -          */
> -         if (image->needs_set_tiling) {
> -            const uint32_t i915_tiling =
> -               isl_tiling_to_i915_tiling(image->planes[0].surface.isl.tiling);
> -            int ret = anv_gem_set_tiling(device, mem->bo->gem_handle,
> -                                         image->planes[0].surface.isl.row_pitch_B,
> -                                         i915_tiling);
> -            if (ret) {
> -               anv_bo_cache_release(device, &device->bo_cache, mem->bo);
> -               return vk_errorf(device->instance, NULL,
> -                                VK_ERROR_OUT_OF_DEVICE_MEMORY,
> -                                "failed to set BO tiling: %m");
> -            }
> +   const VkExportMemoryAllocateInfoKHR *export_info =
> +      vk_find_struct_const(pAllocateInfo->pNext, EXPORT_MEMORY_ALLOCATE_INFO_KHR);
> +   if (export_info && export_info->handleTypes)
> +      bo_flags |= ANV_BO_EXTERNAL;
> +
> +   result = anv_bo_cache_alloc(device, &device->bo_cache,
> +                               pAllocateInfo->allocationSize, bo_flags,
> +                               &mem->bo);
> +   if (result != VK_SUCCESS)
> +      goto fail;
> +
> +   const VkMemoryDedicatedAllocateInfoKHR *dedicated_info =
> +      vk_find_struct_const(pAllocateInfo->pNext, MEMORY_DEDICATED_ALLOCATE_INFO_KHR);
> +   if (dedicated_info && dedicated_info->image != VK_NULL_HANDLE) {
> +      ANV_FROM_HANDLE(anv_image, image, dedicated_info->image);
> +
> +      /* Some legacy (non-modifiers) consumers need the tiling to be set on
> +       * the BO.  In this case, we have a dedicated allocation.
> +       */
> +      if (image->needs_set_tiling) {
> +         const uint32_t i915_tiling =
> +            isl_tiling_to_i915_tiling(image->planes[0].surface.isl.tiling);
> +         int ret = anv_gem_set_tiling(device, mem->bo->gem_handle,
> +                                      image->planes[0].surface.isl.row_pitch_B,
> +                                      i915_tiling);
> +         if (ret) {
> +            anv_bo_cache_release(device, &device->bo_cache, mem->bo);
> +            return vk_errorf(device->instance, NULL,
> +                             VK_ERROR_OUT_OF_DEVICE_MEMORY,
> +                             "failed to set BO tiling: %m");
>            }
>         }
>      }
>   
> + success:
>      *pMem = anv_device_memory_to_handle(mem);
>   
>      return VK_SUCCESS;




More information about the mesa-dev mailing list