Mesa (master): anv: Add field anv_image::planes[]::bo_is_owned (v2)

Chad Versace chadversary at kemper.freedesktop.org
Tue Oct 17 18:26:54 UTC 2017


Module: Mesa
Branch: master
Commit: 076a279a1a0e3ffd537ff8c8e3d8541bd2d07830
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=076a279a1a0e3ffd537ff8c8e3d8541bd2d07830

Author: Chad Versace <chadversary at chromium.org>
Date:   Tue Aug 29 01:36:42 2017 -0700

anv: Add field anv_image::planes[]::bo_is_owned (v2)

If this flag is set, then the image and the 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 during the same
call, vkCreateImage.

v2: Rebase onto VK_KHR_bind_memory2.

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

---

 src/intel/vulkan/anv_image.c   | 9 +++++++++
 src/intel/vulkan/anv_private.h | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index c8ebdce0b4..b80011e222 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -565,6 +565,13 @@ anv_DestroyImage(VkDevice _device, VkImage _image,
    if (!image)
       return;
 
+   for (uint32_t p = 0; p < image->n_planes; ++p) {
+      if (image->planes[p].bo_is_owned) {
+         assert(image->planes[p].bo != NULL);
+         anv_bo_cache_release(device, &device->bo_cache, image->planes[p].bo);
+      }
+   }
+
    vk_free2(&device->alloc, pAllocator, image);
 }
 
@@ -574,6 +581,8 @@ static void anv_image_bind_memory_plane(struct anv_device *device,
                                         struct anv_device_memory *memory,
                                         uint32_t memory_offset)
 {
+   assert(!image->planes[plane].bo_is_owned);
+
    if (!memory) {
       image->planes[plane].bo = NULL;
       image->planes[plane].bo_offset = 0;
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index a80e851925..27d2c34203 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -2420,6 +2420,11 @@ struct anv_image {
        */
       struct anv_bo *bo;
       VkDeviceSize bo_offset;
+
+      /**
+       * When destroying the image, also free the bo.
+       * */
+      bool bo_is_owned;
    } planes[3];
 };
 




More information about the mesa-commit mailing list