[Mesa-dev] [PATCH mesa 2/2] radv: name memory types

Eric Engestrom eric at engestrom.ch
Thu Dec 8 00:18:34 UTC 2016


Following the previous patch, give explicit names to the various memory types,
reducing the risk of bugs when adding or modifying them.

While at it, use a static_assert to make sure we don't have too many
memory types.

Signed-off-by: Eric Engestrom <eric at engestrom.ch>
---

This one isn't really useful yet, but I thought I'd suggest it anyway :)

---
 src/amd/vulkan/radv_device.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index ed71bb6..0c8b39f 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -575,6 +575,16 @@ void radv_GetPhysicalDeviceMemoryProperties(
 {
 	RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
 
+	enum memoryTypes {
+		typeDeviceLocal,
+		typeHostVisibleCoherent,
+		typeDeviceLocalHostVisibleCoherent,
+		typeHostVisibleCoherentCached,
+		_typeCount,
+	};
+
+	STATIC_ASSERT(_typeCount <= VK_MAX_MEMORY_TYPES);
+
 	enum memoryHeaps {
 		heapVramNonVisible,
 		heapVramVisible,
@@ -582,22 +593,22 @@ void radv_GetPhysicalDeviceMemoryProperties(
 	STATIC_ASSERT(_heapCount <= VK_MAX_MEMORY_HEAPS);
 
-	pMemoryProperties->memoryTypeCount = 4;
+	pMemoryProperties->memoryTypeCount = _typeCount;
-	pMemoryProperties->memoryTypes[0] = (VkMemoryType) {
+	pMemoryProperties->memoryTypes[typeDeviceLocal] = (VkMemoryType) {
 		.propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
 		.heapIndex = heapVramNonVisible,
 	};
-	pMemoryProperties->memoryTypes[1] = (VkMemoryType) {
+	pMemoryProperties->memoryTypes[typeHostVisibleCoherent] = (VkMemoryType) {
 		.propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
 		VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
 		.heapIndex = heapGart,
 	};
-	pMemoryProperties->memoryTypes[2] = (VkMemoryType) {
+	pMemoryProperties->memoryTypes[typeDeviceLocalHostVisibleCoherent] = (VkMemoryType) {
 		.propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
 		VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
 		VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
 		.heapIndex = heapVramVisible,
 	};
-	pMemoryProperties->memoryTypes[3] = (VkMemoryType) {
+	pMemoryProperties->memoryTypes[typeHostVisibleCoherentCached] = (VkMemoryType) {
 		.propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
 		VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
 		VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
-- 
Cheers,
  Eric



More information about the mesa-dev mailing list