radv: Implement sparse image creation.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sat, 4 Feb 2017 14:56:20 +0000 (15:56 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Wed, 29 Mar 2017 06:50:37 +0000 (08:50 +0200)
Signed-off-by: Bas Nieuwenhuizen <basni@google.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_image.c
src/amd/vulkan/radv_private.h

index dfd70a9eab8c765d09953bc695c15890f049b512..3997e81acc1c3ebcaecd97c4f44b36647fb3068a 100644 (file)
@@ -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(
index c5b00f29f1f30ad5c5984c72223069aea2419ce7..31e08287c9cd1412840cd1222fe547bdecbf8b39 100644 (file)
@@ -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;