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 <[email protected]>
---

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

_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to