vk/0.130: Implement vkGetPhysicalDeviceMemoryProperties()
authorChad Versace <chad.versace@intel.com>
Fri, 10 Jul 2015 02:49:19 +0000 (19:49 -0700)
committerChad Versace <chad.versace@intel.com>
Sat, 11 Jul 2015 00:35:52 +0000 (17:35 -0700)
include/vulkan/vulkan.h
src/vulkan/device.c

index 26f5a235a8499a5ec72899a9d59ae2a0b09b5bde..72eef2ade08835e73c5e48b3e11943e95f855e30 100644 (file)
@@ -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);
index c5079dfebd9ec3d1b3a5c379746fc243ffdcf8bc..15cdc1dca832bc3ae892d0b0dcb6e83100a927fa 100644 (file)
@@ -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)