[Mesa-dev] [PATCH 09/14] anv: Add field anv_image::bo_is_owned

Chad Versace chad at kiwitree.net
Thu Sep 28 00:11:55 UTC 2017


If this flag is set, then the image and it's bo have the same
lifetime. vkDestroyImage will release the bo.

We need this for VK_ANDROID_native_buffer, because that extension
creates the VkImage and imports its memory in the same call,
vkCreateImage.
---
 src/intel/vulkan/anv_image.c   | 9 ++++++++-
 src/intel/vulkan/anv_private.h | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index f2553970b31..36ba0ca15ce 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -527,8 +527,12 @@ anv_image_create(VkDevice _device,
    return VK_SUCCESS;
 
 fail:
-   if (image)
+   if (image) {
+      if (image->bo_is_owned && image->bo)
+         anv_bo_cache_release(device, &device->bo_cache, image->bo);
+
       vk_free2(&device->alloc, alloc, image);
+   }
 
    return r;
 }
@@ -557,6 +561,9 @@ anv_DestroyImage(VkDevice _device, VkImage _image,
    if (!image)
       return;
 
+   if (image->bo_is_owned && image->bo)
+      anv_bo_cache_release(device, &device->bo_cache, image->bo);
+
    vk_free2(&device->alloc, pAllocator, image);
 }
 
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 0b215c4f738..cd1295d078b 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -2241,6 +2241,7 @@ struct anv_image {
    /* Set when bound */
    struct anv_bo *bo;
    VkDeviceSize offset;
+   bool bo_is_owned; /**< When destroying the image, also free its bo. */
 
    /**
     * Image subsurfaces
-- 
2.13.5



More information about the mesa-dev mailing list