From df2a013881532c9a29f6c9fd36b628ddc8565749 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Thu, 9 Jul 2015 19:49:19 -0700 Subject: [PATCH] vk/0.130: Implement vkGetPhysicalDeviceMemoryProperties() --- include/vulkan/vulkan.h | 26 ++++++++++++++++++++++++-- src/vulkan/device.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/include/vulkan/vulkan.h b/include/vulkan/vulkan.h index 26f5a235a84..72eef2ade08 100644 --- a/include/vulkan/vulkan.h +++ b/include/vulkan/vulkan.h @@ -910,6 +910,11 @@ typedef enum { } VkMemoryPropertyFlagBits; typedef VkFlags VkMemoryPropertyFlags; +typedef enum { + VK_MEMORY_HEAP_HOST_LOCAL = 0x00000001, +} VkMemoryHeapFlagBits; +typedef VkFlags VkMemoryHeapFlags; + typedef enum { VK_DEVICE_CREATE_VALIDATION_BIT = 0x00000001, } VkDeviceCreateFlagBits; @@ -1272,8 +1277,20 @@ typedef struct { } VkPhysicalDeviceQueueProperties; typedef struct { - bool32_t supportsMigration; - bool32_t supportsPinning; + VkMemoryPropertyFlags propertyFlags; + uint32_t heapIndex; +} VkMemoryType; + +typedef struct { + VkDeviceSize size; + VkMemoryHeapFlags flags; +} VkMemoryHeap; + +typedef struct { + uint32_t memoryTypeCount; + VkMemoryType memoryTypes[VK_MAX_MEMORY_TYPES]; + uint32_t memoryHeapCount; + VkMemoryHeap memoryHeaps[VK_MAX_MEMORY_HEAPS]; } VkPhysicalDeviceMemoryProperties; typedef void (VKAPI *PFN_vkVoidFunction)(void); @@ -1962,6 +1979,7 @@ typedef VkResult (VKAPI *PFN_vkGetPhysicalDeviceLimits)(VkPhysicalDevice physica typedef VkResult (VKAPI *PFN_vkGetPhysicalDeviceProperties)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties); typedef VkResult (VKAPI *PFN_vkGetPhysicalDeviceQueueCount)(VkPhysicalDevice physicalDevice, uint32_t* pCount); typedef VkResult (VKAPI *PFN_vkGetPhysicalDeviceQueueProperties)(VkPhysicalDevice physicalDevice, uint32_t count, VkPhysicalDeviceQueueProperties* pQueueProperties); +typedef VkResult (VKAPI *PFN_vkGetPhysicalDeviceMemoryProperties)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperies); typedef PFN_vkVoidFunction (VKAPI *PFN_vkGetInstanceProcAddr)(VkInstance instance, const char* pName); typedef PFN_vkVoidFunction (VKAPI *PFN_vkGetDeviceProcAddr)(VkDevice device, const char* pName); typedef VkResult (VKAPI *PFN_vkCreateDevice)(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice); @@ -2108,6 +2126,10 @@ VkResult VKAPI vkGetPhysicalDeviceQueueProperties( uint32_t count, VkPhysicalDeviceQueueProperties* pQueueProperties); +VkResult VKAPI vkGetPhysicalDeviceMemoryProperties( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceMemoryProperties* pMemoryProperies); + PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr( VkInstance instance, const char* pName); diff --git a/src/vulkan/device.c b/src/vulkan/device.c index c5079dfebd9..15cdc1dca83 100644 --- a/src/vulkan/device.c +++ b/src/vulkan/device.c @@ -422,6 +422,39 @@ VkResult anv_GetPhysicalDeviceQueueProperties( return VK_SUCCESS; } +VkResult anv_GetPhysicalDeviceMemoryProperties( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceMemoryProperties* pMemoryProperties) +{ + ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); + + size_t aperture_size; + size_t heap_size; + + if (anv_gem_get_aperture(physical_device, &aperture_size) == -1) + return vk_error(VK_ERROR_UNAVAILABLE); + + /* Reserve some wiggle room for the driver by exposing only 75% of the + * aperture to the heap. + */ + heap_size = 3 * aperture_size / 4; + + /* The property flags below are valid only for llc platforms. */ + pMemoryProperties->memoryTypeCount = 1; + pMemoryProperties->memoryTypes[0] = (VkMemoryType) { + .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, + .heapIndex = 1, + }; + + pMemoryProperties->memoryHeapCount = 1; + pMemoryProperties->memoryHeaps[0] = (VkMemoryHeap) { + .size = heap_size, + .flags = VK_MEMORY_HEAP_HOST_LOCAL, + }; + + return VK_SUCCESS; +} + PFN_vkVoidFunction anv_GetInstanceProcAddr( VkInstance instance, const char* pName) -- 2.30.2