[Mesa-dev] [PATCH] radv: Add VK_KHR_bind_memory2 support.

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Sun Sep 17 11:59:21 UTC 2017


Nothing too exciting, just adding the possibility for a pNext pointer,
and batch binding. Our binding is pretty much trivial.

It also adds VK_IMAGE_CREATE_ALIAS_BIT_KHR, but since we store no
state in radv_image, I don't think we have to do anything there.
---
 src/amd/vulkan/radv_device.c           | 82 ++++++++++++++++++++++++----------
 src/amd/vulkan/radv_entrypoints_gen.py |  1 +
 2 files changed, 59 insertions(+), 24 deletions(-)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index e6d595dfbe5..7bfdddf0eea 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -174,6 +174,10 @@ static const VkExtensionProperties common_device_extensions[] = {
 		.extensionName = VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME,
 		.specVersion = 1,
 	},
+	{
+		.extensionName = VK_KHR_BIND_MEMORY_2_EXTENSION_NAME,
+		.specVersion = 1,
+	},
 };
 static const VkExtensionProperties ext_sema_device_extensions[] = {
 	{
@@ -2481,44 +2485,74 @@ void radv_GetDeviceMemoryCommitment(
 	*pCommittedMemoryInBytes = 0;
 }
 
+VkResult radv_BindBufferMemory2KHR(VkDevice device,
+                                   uint32_t bindInfoCount,
+                                   const VkBindBufferMemoryInfoKHR *pBindInfos)
+{
+	for (uint32_t i = 0; i < bindInfoCount; ++i) {
+		RADV_FROM_HANDLE(radv_device_memory, mem, pBindInfos[i].memory);
+		RADV_FROM_HANDLE(radv_buffer, buffer, pBindInfos[i].buffer);
+
+		if (mem) {
+			buffer->bo = mem->bo;
+			buffer->offset = pBindInfos[i].memoryOffset;
+		} else {
+			buffer->bo = NULL;
+		}
+	}
+	return VK_SUCCESS;
+}
+
 VkResult radv_BindBufferMemory(
 	VkDevice                                    device,
-	VkBuffer                                    _buffer,
-	VkDeviceMemory                              _memory,
+	VkBuffer                                    buffer,
+	VkDeviceMemory                              memory,
 	VkDeviceSize                                memoryOffset)
 {
-	RADV_FROM_HANDLE(radv_device_memory, mem, _memory);
-	RADV_FROM_HANDLE(radv_buffer, buffer, _buffer);
+	const VkBindBufferMemoryInfoKHR info = {
+		.sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR,
+		.buffer = buffer,
+		.memory = memory,
+		.memoryOffset = memoryOffset
+	};
 
-	if (mem) {
-		buffer->bo = mem->bo;
-		buffer->offset = memoryOffset;
-	} else {
-		buffer->bo = NULL;
-		buffer->offset = 0;
-	}
+	return radv_BindBufferMemory2KHR(device, 1, &info);
+}
 
+VkResult radv_BindImageMemory2KHR(VkDevice device,
+                                  uint32_t bindInfoCount,
+                                  const VkBindImageMemoryInfoKHR *pBindInfos)
+{
+	for (uint32_t i = 0; i < bindInfoCount; ++i) {
+		RADV_FROM_HANDLE(radv_device_memory, mem, pBindInfos[i].memory);
+		RADV_FROM_HANDLE(radv_image, image, pBindInfos[i].image);
+
+		if (mem) {
+			image->bo = mem->bo;
+			image->offset = pBindInfos[i].memoryOffset;
+		} else {
+			image->bo = NULL;
+			image->offset = 0;
+		}
+	}
 	return VK_SUCCESS;
 }
 
+
 VkResult radv_BindImageMemory(
 	VkDevice                                    device,
-	VkImage                                     _image,
-	VkDeviceMemory                              _memory,
+	VkImage                                     image,
+	VkDeviceMemory                              memory,
 	VkDeviceSize                                memoryOffset)
 {
-	RADV_FROM_HANDLE(radv_device_memory, mem, _memory);
-	RADV_FROM_HANDLE(radv_image, image, _image);
-
-	if (mem) {
-		image->bo = mem->bo;
-		image->offset = memoryOffset;
-	} else {
-		image->bo = NULL;
-		image->offset = 0;
-	}
+	const VkBindImageMemoryInfoKHR info = {
+		.sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR,
+		.image = image,
+		.memory = memory,
+		.memoryOffset = memoryOffset
+	};
 
-	return VK_SUCCESS;
+	return radv_BindImageMemory2KHR(device, 1, &info);
 }
 
 
diff --git a/src/amd/vulkan/radv_entrypoints_gen.py b/src/amd/vulkan/radv_entrypoints_gen.py
index 9634f76fcd6..21738f4da90 100644
--- a/src/amd/vulkan/radv_entrypoints_gen.py
+++ b/src/amd/vulkan/radv_entrypoints_gen.py
@@ -57,6 +57,7 @@ SUPPORTED_EXTENSIONS = [
     'VK_KHR_external_semaphore_capabilities',
     'VK_KHR_external_semaphore',
     'VK_KHR_external_semaphore_fd',
+    'VK_KHR_bind_memory2',
 ]
 
 # We generate a static hash table for entry point lookup
-- 
2.14.1



More information about the mesa-dev mailing list