Give explicit names to the various memory heaps, 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 heaps. Signed-off-by: Eric Engestrom <[email protected]> --- I'm sure there are better names than these, but this patch is here to suggest using names. Feel free to use better names :) --- src/amd/vulkan/radv_device.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 0defc0f..ed71bb6 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -575,40 +575,49 @@ void radv_GetPhysicalDeviceMemoryProperties( { RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice); + enum memoryHeaps { + heapVramNonVisible, + heapVramVisible, + heapGart, + _heapCount, + }; + + STATIC_ASSERT(_heapCount <= VK_MAX_MEMORY_HEAPS); + pMemoryProperties->memoryTypeCount = 4; pMemoryProperties->memoryTypes[0] = (VkMemoryType) { .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, - .heapIndex = 0, + .heapIndex = heapVramNonVisible, }; pMemoryProperties->memoryTypes[1] = (VkMemoryType) { .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - .heapIndex = 2, + .heapIndex = heapGart, }; pMemoryProperties->memoryTypes[2] = (VkMemoryType) { .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - .heapIndex = 1, + .heapIndex = heapVramVisible, }; pMemoryProperties->memoryTypes[3] = (VkMemoryType) { .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, - .heapIndex = 2, + .heapIndex = heapGart, }; - pMemoryProperties->memoryHeapCount = 3; + pMemoryProperties->memoryHeapCount = _heapCount; - pMemoryProperties->memoryHeaps[0] = (VkMemoryHeap) { + pMemoryProperties->memoryHeaps[heapVramNonVisible] = (VkMemoryHeap) { .size = physical_device->rad_info.vram_size - physical_device->rad_info.visible_vram_size, .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, }; - pMemoryProperties->memoryHeaps[1] = (VkMemoryHeap) { + pMemoryProperties->memoryHeaps[heapVramVisible] = (VkMemoryHeap) { .size = physical_device->rad_info.visible_vram_size, .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, }; - pMemoryProperties->memoryHeaps[2] = (VkMemoryHeap) { + pMemoryProperties->memoryHeaps[heapGart] = (VkMemoryHeap) { .size = physical_device->rad_info.gart_size, .flags = 0, }; -- Cheers, Eric _______________________________________________ mesa-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-dev
