[Mesa-dev] [PATCH v2 3/6] radv: Implement sparse image creation.

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Wed Mar 29 00:03:41 UTC 2017


Signed-off-by: Bas Nieuwenhuizen <basni at google.com>
---
 src/amd/vulkan/radv_image.c   | 23 +++++++++++++++++++++--
 src/amd/vulkan/radv_private.h |  1 +
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c
index dfd70a9eab8..3997e81acc1 100644
--- a/src/amd/vulkan/radv_image.c
+++ b/src/amd/vulkan/radv_image.c
@@ -636,6 +636,7 @@ radv_image_create(VkDevice _device,
 	image->samples = pCreateInfo->samples;
 	image->tiling = pCreateInfo->tiling;
 	image->usage = pCreateInfo->usage;
+	image->flags = pCreateInfo->flags;
 
 	image->exclusive = pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE;
 	if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
@@ -676,6 +677,20 @@ radv_image_create(VkDevice _device,
 		image->surface.level[0].pitch_bytes = create_info->stride;
 		image->surface.level[0].slice_size = create_info->stride * image->surface.level[0].nblk_y;
 	}
+
+	if (pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) {
+		image->alignment = MAX2(image->alignment, 4096);
+		image->size = align64(image->size, image->alignment);
+		image->offset = 0;
+
+		image->bo = device->ws->buffer_create(device->ws, image->size, image->alignment,
+		                                      0, RADEON_FLAG_VIRTUAL);
+		if (!image->bo) {
+			vk_free2(&device->alloc, alloc, image);
+			return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
+		}
+	}
+
 	*pImage = radv_image_to_handle(image);
 
 	return VK_SUCCESS;
@@ -872,11 +887,15 @@ radv_DestroyImage(VkDevice _device, VkImage _image,
 		  const VkAllocationCallbacks *pAllocator)
 {
 	RADV_FROM_HANDLE(radv_device, device, _device);
+	RADV_FROM_HANDLE(radv_image, image, _image);
 
-	if (!_image)
+	if (!image)
 		return;
 
-	vk_free2(&device->alloc, pAllocator, radv_image_from_handle(_image));
+	if (image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT)
+		device->ws->buffer_destroy(image->bo);
+
+	vk_free2(&device->alloc, pAllocator, image);
 }
 
 void radv_GetImageSubresourceLayout(
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index c5b00f29f1f..31e08287c9c 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -1070,6 +1070,7 @@ struct radv_image {
 	uint32_t samples; /**< VkImageCreateInfo::samples */
 	VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
 	VkImageTiling tiling; /** VkImageCreateInfo::tiling */
+	VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
 
 	VkDeviceSize size;
 	uint32_t alignment;
-- 
2.12.1



More information about the mesa-dev mailing list