[Mesa-dev] [PATCH 18/23] anv: Add field anv_image::mem_is_owned

Jason Ekstrand jason at jlekstrand.net
Sat Sep 2 17:17:39 UTC 2017


On Sat, Sep 2, 2017 at 1:17 AM, Chad Versace <chadversary at chromium.org>
wrote:

> If this flag is set, then the image and it's device memory have the same
> lifetime.  vkDestroyImage will free its anv_device_memory.
>
> We need this for VK_ANDROID_native_buffer, because that extension
> creates the VkImage and imports its memory in the same call,
> vkCreateImage.
>

So, this got me thinking... VK_ANDROID_native_buffer doesn't actually
return the VkDeviceMemory object to the client.  Why does anv_image need to
own an anv_device_memory?  It's just a wrapper around a pointer and a map
anyway.  Why not just have it own a reference to the BO?  We still need the
logic here to release said BO but that sounds like it would shrink the
reach of VK_ANDROID_native_buffer down a bit.


> ---
>  src/intel/vulkan/anv_image.c   | 8 ++++++++
>  src/intel/vulkan/anv_private.h | 3 +++
>  2 files changed, 11 insertions(+)
>
> diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
> index 1fe8ab8ee43..1cc3adae5ee 100644
> --- a/src/intel/vulkan/anv_image.c
> +++ b/src/intel/vulkan/anv_image.c
> @@ -450,6 +450,9 @@ anv_image_create(VkDevice _device,
>     return VK_SUCCESS;
>
>  fail:
> +   if (image && image->mem_is_owned)
> +      anv_FreeMemory(_device, anv_device_memory_to_handle(image->mem),
> alloc);
> +
>     if (image)
>        vk_free2(&device->alloc, alloc, image);
>
> @@ -480,6 +483,11 @@ anv_DestroyImage(VkDevice _device, VkImage _image,
>     if (!image)
>        return;
>
> +   if (image->mem_is_owned) {
> +      anv_FreeMemory(_device, anv_device_memory_to_handle(image->mem),
> +                     pAllocator);
> +   }
> +
>     vk_free2(&device->alloc, pAllocator, image);
>  }
>
> diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_
> private.h
> index 98bdaa90a50..d1c3d743061 100644
> --- a/src/intel/vulkan/anv_private.h
> +++ b/src/intel/vulkan/anv_private.h
> @@ -2089,6 +2089,9 @@ struct anv_image {
>     struct anv_device_memory *mem;
>     VkDeviceSize mem_offset;
>
> +   /** When destroying the image, also free its device memory. */
> +   bool mem_is_owned;
> +
>     /**
>      * Image subsurfaces
>      *
> --
> 2.13.5
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170902/a7766e41/attachment.html>


More information about the mesa-dev mailing list