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

index dcef1da7e3cedf73dcc2c4b9f762e61080877b74..adcc63a81727d367c60c3d1f34244f01aabea4ad 100644 (file)
@@ -1881,8 +1881,12 @@ void radv_GetBufferMemoryRequirements(
 
        pMemoryRequirements->memoryTypeBits = (1u << RADV_MEM_TYPE_COUNT) - 1;
 
-       pMemoryRequirements->size = buffer->size;
-       pMemoryRequirements->alignment = 16;
+       if (buffer->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT)
+               pMemoryRequirements->alignment = 4096;
+       else
+               pMemoryRequirements->alignment = 16;
+
+       pMemoryRequirements->size = align64(buffer->size, pMemoryRequirements->alignment);
 }
 
 void radv_GetImageMemoryRequirements(
@@ -2208,6 +2212,17 @@ VkResult radv_CreateBuffer(
        buffer->usage = pCreateInfo->usage;
        buffer->bo = NULL;
        buffer->offset = 0;
+       buffer->flags = pCreateInfo->flags;
+
+       if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) {
+               buffer->bo = device->ws->buffer_create(device->ws,
+                                                      align64(buffer->size, 4096),
+                                                      4096, 0, RADEON_FLAG_VIRTUAL);
+               if (!buffer->bo) {
+                       vk_free2(&device->alloc, pAllocator, buffer);
+                       return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
+               }
+       }
 
        *pBuffer = radv_buffer_to_handle(buffer);
 
@@ -2225,6 +2240,9 @@ void radv_DestroyBuffer(
        if (!buffer)
                return;
 
+       if (buffer->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT)
+               device->ws->buffer_destroy(buffer->bo);
+
        vk_free2(&device->alloc, pAllocator, buffer);
 }
 
index f587ee3ffd84cf935511dc89aa4845b0cb108d41..c5b00f29f1f30ad5c5984c72223069aea2419ce7 100644 (file)
@@ -557,6 +557,7 @@ struct radv_buffer {
        VkDeviceSize                                 size;
 
        VkBufferUsageFlags                           usage;
+       VkBufferCreateFlags                          flags;
 
        /* Set when bound */
        struct radeon_winsys_bo *                      bo;