[Mesa-dev] [PATCH 18/23] anv: Add field anv_image::mem_is_owned
Chad Versace
chadversary at chromium.org
Sat Sep 2 08:17:41 UTC 2017
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.
---
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
More information about the mesa-dev
mailing list