[Mesa-dev] [PATCH 4/8] radv: Implement sparse buffer creation.

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Sun Feb 5 11:43:55 UTC 2017


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

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 3f9a452ddf3..1e92046d62c 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -1702,8 +1702,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(
@@ -2030,6 +2034,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);
 
@@ -2047,6 +2062,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);
 }
 
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index 69ff3578e34..72560f6a972 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -568,6 +568,7 @@ struct radv_buffer {
 	VkDeviceSize                                 size;
 
 	VkBufferUsageFlags                           usage;
+	VkBufferCreateFlags                          flags;
 
 	/* Set when bound */
 	struct radeon_winsys_bo *                      bo;
-- 
2.11.0



More information about the mesa-dev mailing list