| Jesse Hall | d02edcb | 2015-09-08 07:44:48 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright 2015 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
| Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 17 | #include <inttypes.h> | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 18 | #include <stdlib.h> | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 19 | #include <unistd.h> | 
 | 20 |  | 
 | 21 | #include <algorithm> | 
 | 22 | #include <array> | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 23 | #include <sstream> | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 24 | #include <vector> | 
 | 25 |  | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 26 | #include <vulkan/vulkan.h> | 
 | 27 |  | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 28 | namespace { | 
 | 29 |  | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 30 | struct Options { | 
 | 31 |     bool layer_description; | 
 | 32 |     bool layer_extensions; | 
| Jesse Hall | f63e445 | 2016-02-08 21:22:23 -0800 | [diff] [blame] | 33 |     bool unsupported_features; | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 34 |     bool validate; | 
 | 35 | }; | 
 | 36 |  | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 37 | struct GpuInfo { | 
 | 38 |     VkPhysicalDeviceProperties properties; | 
 | 39 |     VkPhysicalDeviceMemoryProperties memory; | 
| Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 40 |     VkPhysicalDeviceFeatures features; | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 41 |     std::vector<VkQueueFamilyProperties> queue_families; | 
| Jesse Hall | 6e4ab31 | 2016-01-07 22:26:20 -0800 | [diff] [blame] | 42 |     std::vector<VkExtensionProperties> extensions; | 
 | 43 |     std::vector<VkLayerProperties> layers; | 
 | 44 |     std::vector<std::vector<VkExtensionProperties>> layer_extensions; | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 45 | }; | 
 | 46 | struct VulkanInfo { | 
 | 47 |     std::vector<VkExtensionProperties> extensions; | 
 | 48 |     std::vector<VkLayerProperties> layers; | 
 | 49 |     std::vector<std::vector<VkExtensionProperties>> layer_extensions; | 
 | 50 |     std::vector<GpuInfo> gpus; | 
 | 51 | }; | 
 | 52 |  | 
 | 53 | // ---------------------------------------------------------------------------- | 
 | 54 |  | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 55 | [[noreturn]] void die(const char* proc, VkResult result) { | 
 | 56 |     const char* result_str; | 
 | 57 |     switch (result) { | 
 | 58 |         // clang-format off | 
 | 59 |         case VK_SUCCESS: result_str = "VK_SUCCESS"; break; | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 60 |         case VK_NOT_READY: result_str = "VK_NOT_READY"; break; | 
 | 61 |         case VK_TIMEOUT: result_str = "VK_TIMEOUT"; break; | 
 | 62 |         case VK_EVENT_SET: result_str = "VK_EVENT_SET"; break; | 
 | 63 |         case VK_EVENT_RESET: result_str = "VK_EVENT_RESET"; break; | 
 | 64 |         case VK_INCOMPLETE: result_str = "VK_INCOMPLETE"; break; | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 65 |         case VK_ERROR_OUT_OF_HOST_MEMORY: result_str = "VK_ERROR_OUT_OF_HOST_MEMORY"; break; | 
 | 66 |         case VK_ERROR_OUT_OF_DEVICE_MEMORY: result_str = "VK_ERROR_OUT_OF_DEVICE_MEMORY"; break; | 
| Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 67 |         case VK_ERROR_INITIALIZATION_FAILED: result_str = "VK_ERROR_INITIALIZATION_FAILED"; break; | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 68 |         case VK_ERROR_DEVICE_LOST: result_str = "VK_ERROR_DEVICE_LOST"; break; | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 69 |         case VK_ERROR_MEMORY_MAP_FAILED: result_str = "VK_ERROR_MEMORY_MAP_FAILED"; break; | 
| Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 70 |         case VK_ERROR_LAYER_NOT_PRESENT: result_str = "VK_ERROR_LAYER_NOT_PRESENT"; break; | 
 | 71 |         case VK_ERROR_EXTENSION_NOT_PRESENT: result_str = "VK_ERROR_EXTENSION_NOT_PRESENT"; break; | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 72 |         case VK_ERROR_INCOMPATIBLE_DRIVER: result_str = "VK_ERROR_INCOMPATIBLE_DRIVER"; break; | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 73 |         default: result_str = "<unknown VkResult>"; break; | 
 | 74 |             // clang-format on | 
 | 75 |     } | 
 | 76 |     fprintf(stderr, "%s failed: %s (%d)\n", proc, result_str, result); | 
 | 77 |     exit(1); | 
 | 78 | } | 
 | 79 |  | 
| Jesse Hall | 4da3bd6 | 2016-01-16 22:14:40 -0800 | [diff] [blame] | 80 | bool HasExtension(const std::vector<VkExtensionProperties>& extensions, | 
 | 81 |                   const char* name) { | 
 | 82 |     return std::find_if(extensions.cbegin(), extensions.cend(), | 
 | 83 |                         [=](const VkExtensionProperties& prop) { | 
 | 84 |                             return strcmp(prop.extensionName, name) == 0; | 
 | 85 |                         }) != extensions.end(); | 
 | 86 | } | 
 | 87 |  | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 88 | void EnumerateInstanceExtensions( | 
 | 89 |     const char* layer_name, | 
 | 90 |     std::vector<VkExtensionProperties>* extensions) { | 
 | 91 |     VkResult result; | 
 | 92 |     uint32_t count; | 
 | 93 |     result = | 
 | 94 |         vkEnumerateInstanceExtensionProperties(layer_name, &count, nullptr); | 
 | 95 |     if (result != VK_SUCCESS) | 
 | 96 |         die("vkEnumerateInstanceExtensionProperties (count)", result); | 
 | 97 |     do { | 
 | 98 |         extensions->resize(count); | 
 | 99 |         result = vkEnumerateInstanceExtensionProperties(layer_name, &count, | 
 | 100 |                                                         extensions->data()); | 
 | 101 |     } while (result == VK_INCOMPLETE); | 
 | 102 |     if (result != VK_SUCCESS) | 
 | 103 |         die("vkEnumerateInstanceExtensionProperties (data)", result); | 
 | 104 | } | 
 | 105 |  | 
| Jesse Hall | 6e4ab31 | 2016-01-07 22:26:20 -0800 | [diff] [blame] | 106 | void EnumerateDeviceExtensions(VkPhysicalDevice gpu, | 
 | 107 |                                const char* layer_name, | 
 | 108 |                                std::vector<VkExtensionProperties>* extensions) { | 
 | 109 |     VkResult result; | 
 | 110 |     uint32_t count; | 
 | 111 |     result = | 
 | 112 |         vkEnumerateDeviceExtensionProperties(gpu, layer_name, &count, nullptr); | 
 | 113 |     if (result != VK_SUCCESS) | 
 | 114 |         die("vkEnumerateDeviceExtensionProperties (count)", result); | 
 | 115 |     do { | 
 | 116 |         extensions->resize(count); | 
 | 117 |         result = vkEnumerateDeviceExtensionProperties(gpu, layer_name, &count, | 
 | 118 |                                                       extensions->data()); | 
 | 119 |     } while (result == VK_INCOMPLETE); | 
 | 120 |     if (result != VK_SUCCESS) | 
 | 121 |         die("vkEnumerateDeviceExtensionProperties (data)", result); | 
 | 122 | } | 
 | 123 |  | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 124 | void GatherGpuInfo(VkPhysicalDevice gpu, | 
 | 125 |                    const Options &options, | 
 | 126 |                    GpuInfo& info) { | 
| Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 127 |     VkResult result; | 
 | 128 |     uint32_t count; | 
 | 129 |  | 
 | 130 |     vkGetPhysicalDeviceProperties(gpu, &info.properties); | 
 | 131 |     vkGetPhysicalDeviceMemoryProperties(gpu, &info.memory); | 
 | 132 |     vkGetPhysicalDeviceFeatures(gpu, &info.features); | 
 | 133 |  | 
 | 134 |     vkGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr); | 
 | 135 |     info.queue_families.resize(count); | 
 | 136 |     vkGetPhysicalDeviceQueueFamilyProperties(gpu, &count, | 
 | 137 |                                              info.queue_families.data()); | 
 | 138 |  | 
 | 139 |     result = vkEnumerateDeviceLayerProperties(gpu, &count, nullptr); | 
 | 140 |     if (result != VK_SUCCESS) | 
 | 141 |         die("vkEnumerateDeviceLayerProperties (count)", result); | 
 | 142 |     do { | 
 | 143 |         info.layers.resize(count); | 
 | 144 |         result = | 
 | 145 |             vkEnumerateDeviceLayerProperties(gpu, &count, info.layers.data()); | 
 | 146 |     } while (result == VK_INCOMPLETE); | 
 | 147 |     if (result != VK_SUCCESS) | 
 | 148 |         die("vkEnumerateDeviceLayerProperties (data)", result); | 
 | 149 |     info.layer_extensions.resize(info.layers.size()); | 
 | 150 |  | 
 | 151 |     EnumerateDeviceExtensions(gpu, nullptr, &info.extensions); | 
 | 152 |     for (size_t i = 0; i < info.layers.size(); i++) { | 
 | 153 |         EnumerateDeviceExtensions(gpu, info.layers[i].layerName, | 
 | 154 |                                   &info.layer_extensions[i]); | 
 | 155 |     } | 
 | 156 |  | 
 | 157 |     const std::array<const char*, 1> kDesiredExtensions = { | 
 | 158 |         {VK_KHR_SWAPCHAIN_EXTENSION_NAME}, | 
 | 159 |     }; | 
 | 160 |     const char* extensions[kDesiredExtensions.size()]; | 
 | 161 |     uint32_t num_extensions = 0; | 
 | 162 |     for (const auto& desired_ext : kDesiredExtensions) { | 
 | 163 |         bool available = HasExtension(info.extensions, desired_ext); | 
| Chia-I Wu | 8955f3f | 2016-04-22 06:06:04 +0800 | [diff] [blame] | 164 |         if (options.validate) { | 
 | 165 |             for (size_t i = 0; !available && i < info.layer_extensions.size(); | 
 | 166 |                  i++) | 
 | 167 |                 available = HasExtension(info.layer_extensions[i], desired_ext); | 
 | 168 |         } | 
| Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 169 |         if (available) | 
 | 170 |             extensions[num_extensions++] = desired_ext; | 
 | 171 |     } | 
 | 172 |  | 
 | 173 |     VkDevice device; | 
| Courtney Goeltzenleuchter | ca472ab | 2016-02-01 20:09:00 -0700 | [diff] [blame] | 174 |     float queue_priorities[] = {0.0}; | 
| Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 175 |     const VkDeviceQueueCreateInfo queue_create_info = { | 
 | 176 |         .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, | 
 | 177 |         .queueFamilyIndex = 0, | 
 | 178 |         .queueCount = 1, | 
| Courtney Goeltzenleuchter | 0240059 | 2016-12-29 09:31:35 -0700 | [diff] [blame] | 179 |         .pQueuePriorities = queue_priorities | 
| Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 180 |     }; | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 181 |     // clang-format off | 
 | 182 |     const char *kValidationLayers[] = { | 
 | 183 |         "VK_LAYER_GOOGLE_threading", | 
| Chia-I Wu | dcad395 | 2016-04-22 06:26:37 +0800 | [diff] [blame] | 184 |         "VK_LAYER_LUNARG_parameter_validation", | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 185 |         "VK_LAYER_LUNARG_device_limits", | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 186 |         "VK_LAYER_LUNARG_object_tracker", | 
| Chia-I Wu | dcad395 | 2016-04-22 06:26:37 +0800 | [diff] [blame] | 187 |         "VK_LAYER_LUNARG_image", | 
 | 188 |         "VK_LAYER_LUNARG_core_validation", | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 189 |         "VK_LAYER_LUNARG_swapchain", | 
 | 190 |         "VK_LAYER_GOOGLE_unique_objects" | 
 | 191 |     }; | 
 | 192 |     // clang-format on | 
 | 193 |     uint32_t num_layers = sizeof(kValidationLayers) / sizeof(char*); | 
| Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 194 |     const VkDeviceCreateInfo create_info = { | 
 | 195 |         .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, | 
 | 196 |         .queueCreateInfoCount = 1, | 
 | 197 |         .pQueueCreateInfos = &queue_create_info, | 
 | 198 |         .enabledExtensionCount = num_extensions, | 
 | 199 |         .ppEnabledExtensionNames = extensions, | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 200 |         .enabledLayerCount = (options.validate) ? num_layers : 0, | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 201 |         .ppEnabledLayerNames = kValidationLayers, | 
| Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 202 |         .pEnabledFeatures = &info.features, | 
 | 203 |     }; | 
 | 204 |     result = vkCreateDevice(gpu, &create_info, nullptr, &device); | 
 | 205 |     if (result != VK_SUCCESS) | 
 | 206 |         die("vkCreateDevice", result); | 
 | 207 |     vkDestroyDevice(device, nullptr); | 
 | 208 | } | 
 | 209 |  | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 210 | void GatherInfo(VulkanInfo* info, const Options& options) { | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 211 |     VkResult result; | 
 | 212 |     uint32_t count; | 
 | 213 |  | 
 | 214 |     result = vkEnumerateInstanceLayerProperties(&count, nullptr); | 
 | 215 |     if (result != VK_SUCCESS) | 
 | 216 |         die("vkEnumerateInstanceLayerProperties (count)", result); | 
 | 217 |     do { | 
 | 218 |         info->layers.resize(count); | 
 | 219 |         result = | 
 | 220 |             vkEnumerateInstanceLayerProperties(&count, info->layers.data()); | 
 | 221 |     } while (result == VK_INCOMPLETE); | 
 | 222 |     if (result != VK_SUCCESS) | 
 | 223 |         die("vkEnumerateInstanceLayerProperties (data)", result); | 
 | 224 |     info->layer_extensions.resize(info->layers.size()); | 
 | 225 |  | 
 | 226 |     EnumerateInstanceExtensions(nullptr, &info->extensions); | 
 | 227 |     for (size_t i = 0; i < info->layers.size(); i++) { | 
 | 228 |         EnumerateInstanceExtensions(info->layers[i].layerName, | 
 | 229 |                                     &info->layer_extensions[i]); | 
 | 230 |     } | 
 | 231 |  | 
| Jesse Hall | ae3b70d | 2016-01-17 22:05:29 -0800 | [diff] [blame] | 232 |     const char* kDesiredExtensions[] = { | 
 | 233 |         VK_EXT_DEBUG_REPORT_EXTENSION_NAME, | 
| Jesse Hall | 4da3bd6 | 2016-01-16 22:14:40 -0800 | [diff] [blame] | 234 |     }; | 
| Jesse Hall | ae3b70d | 2016-01-17 22:05:29 -0800 | [diff] [blame] | 235 |     const char* | 
 | 236 |         extensions[sizeof(kDesiredExtensions) / sizeof(kDesiredExtensions[0])]; | 
| Jesse Hall | 4da3bd6 | 2016-01-16 22:14:40 -0800 | [diff] [blame] | 237 |     uint32_t num_extensions = 0; | 
 | 238 |     for (const auto& desired_ext : kDesiredExtensions) { | 
 | 239 |         bool available = HasExtension(info->extensions, desired_ext); | 
| Chia-I Wu | 8955f3f | 2016-04-22 06:06:04 +0800 | [diff] [blame] | 240 |         if (options.validate) { | 
 | 241 |             for (size_t i = 0; !available && i < info->layer_extensions.size(); | 
 | 242 |                  i++) | 
 | 243 |                 available = | 
 | 244 |                     HasExtension(info->layer_extensions[i], desired_ext); | 
 | 245 |         } | 
| Jesse Hall | 4da3bd6 | 2016-01-16 22:14:40 -0800 | [diff] [blame] | 246 |         if (available) | 
 | 247 |             extensions[num_extensions++] = desired_ext; | 
 | 248 |     } | 
 | 249 |  | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 250 |     // clang-format off | 
 | 251 |     const char *kValidationLayers[] = { | 
 | 252 |         "VK_LAYER_GOOGLE_threading", | 
| Chia-I Wu | dcad395 | 2016-04-22 06:26:37 +0800 | [diff] [blame] | 253 |         "VK_LAYER_LUNARG_parameter_validation", | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 254 |         "VK_LAYER_LUNARG_device_limits", | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 255 |         "VK_LAYER_LUNARG_object_tracker", | 
| Chia-I Wu | dcad395 | 2016-04-22 06:26:37 +0800 | [diff] [blame] | 256 |         "VK_LAYER_LUNARG_image", | 
 | 257 |         "VK_LAYER_LUNARG_core_validation", | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 258 |         "VK_LAYER_LUNARG_swapchain", | 
 | 259 |         "VK_LAYER_GOOGLE_unique_objects" | 
 | 260 |     }; | 
 | 261 |     // clang-format on | 
 | 262 |     uint32_t num_layers = sizeof(kValidationLayers) / sizeof(char*); | 
 | 263 |  | 
| Jesse Hall | dc7f6a6 | 2016-02-24 16:44:42 -0800 | [diff] [blame] | 264 |     const VkApplicationInfo application_info = { | 
 | 265 |         .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, | 
 | 266 |         .pApplicationName = "vkinfo", | 
 | 267 |         .applicationVersion = 0, | 
 | 268 |         .pEngineName = "vkinfo", | 
 | 269 |         .engineVersion = 0, | 
| Jesse Hall | 2676338 | 2016-05-20 07:13:52 -0700 | [diff] [blame] | 270 |         .apiVersion = VK_API_VERSION_1_0, | 
| Jesse Hall | dc7f6a6 | 2016-02-24 16:44:42 -0800 | [diff] [blame] | 271 |     }; | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 272 |     const VkInstanceCreateInfo create_info = { | 
 | 273 |         .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, | 
| Jesse Hall | dc7f6a6 | 2016-02-24 16:44:42 -0800 | [diff] [blame] | 274 |         .pApplicationInfo = &application_info, | 
| Jesse Hall | 4da3bd6 | 2016-01-16 22:14:40 -0800 | [diff] [blame] | 275 |         .enabledExtensionCount = num_extensions, | 
 | 276 |         .ppEnabledExtensionNames = extensions, | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 277 |         .enabledLayerCount = (options.validate) ? num_layers : 0, | 
| Courtney Goeltzenleuchter | b1e7d59 | 2016-02-08 20:31:25 -0700 | [diff] [blame] | 278 |         .ppEnabledLayerNames = kValidationLayers, | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 279 |     }; | 
| Jesse Hall | 4da3bd6 | 2016-01-16 22:14:40 -0800 | [diff] [blame] | 280 |     VkInstance instance; | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 281 |     result = vkCreateInstance(&create_info, nullptr, &instance); | 
 | 282 |     if (result != VK_SUCCESS) | 
 | 283 |         die("vkCreateInstance", result); | 
 | 284 |  | 
 | 285 |     uint32_t num_gpus; | 
 | 286 |     result = vkEnumeratePhysicalDevices(instance, &num_gpus, nullptr); | 
 | 287 |     if (result != VK_SUCCESS) | 
 | 288 |         die("vkEnumeratePhysicalDevices (count)", result); | 
 | 289 |     std::vector<VkPhysicalDevice> gpus(num_gpus, VK_NULL_HANDLE); | 
 | 290 |     do { | 
 | 291 |         gpus.resize(num_gpus, VK_NULL_HANDLE); | 
 | 292 |         result = vkEnumeratePhysicalDevices(instance, &num_gpus, gpus.data()); | 
 | 293 |     } while (result == VK_INCOMPLETE); | 
 | 294 |     if (result != VK_SUCCESS) | 
 | 295 |         die("vkEnumeratePhysicalDevices (data)", result); | 
 | 296 |  | 
 | 297 |     info->gpus.resize(num_gpus); | 
| Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 298 |     for (size_t i = 0; i < gpus.size(); i++) | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 299 |         GatherGpuInfo(gpus[i], options, info->gpus.at(i)); | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 300 |  | 
 | 301 |     vkDestroyInstance(instance, nullptr); | 
 | 302 | } | 
 | 303 |  | 
 | 304 | // ---------------------------------------------------------------------------- | 
 | 305 |  | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 306 | const size_t kMaxIndent = 8; | 
 | 307 | const size_t kIndentSize = 3; | 
 | 308 | std::array<char, kMaxIndent * kIndentSize + 1> kIndent; | 
 | 309 | const char* Indent(size_t n) { | 
 | 310 |     static bool initialized = false; | 
 | 311 |     if (!initialized) { | 
 | 312 |         kIndent.fill(' '); | 
 | 313 |         kIndent.back() = '\0'; | 
 | 314 |         initialized = true; | 
 | 315 |     } | 
 | 316 |     return kIndent.data() + | 
 | 317 |            (kIndent.size() - (kIndentSize * std::min(n, kMaxIndent) + 1)); | 
 | 318 | } | 
 | 319 |  | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 320 | const char* VkPhysicalDeviceTypeStr(VkPhysicalDeviceType type) { | 
 | 321 |     switch (type) { | 
 | 322 |         case VK_PHYSICAL_DEVICE_TYPE_OTHER: | 
 | 323 |             return "OTHER"; | 
 | 324 |         case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: | 
 | 325 |             return "INTEGRATED_GPU"; | 
 | 326 |         case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: | 
 | 327 |             return "DISCRETE_GPU"; | 
 | 328 |         case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: | 
 | 329 |             return "VIRTUAL_GPU"; | 
 | 330 |         case VK_PHYSICAL_DEVICE_TYPE_CPU: | 
 | 331 |             return "CPU"; | 
 | 332 |         default: | 
 | 333 |             return "<UNKNOWN>"; | 
 | 334 |     } | 
 | 335 | } | 
 | 336 |  | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 337 | void PrintExtensions(const std::vector<VkExtensionProperties>& extensions, | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 338 |                      const Options& /*options*/, | 
 | 339 |                      size_t indent) { | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 340 |     for (const auto& e : extensions) | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 341 |         printf("%s%s (v%u)\n", Indent(indent), e.extensionName, e.specVersion); | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 342 | } | 
| Jesse Hall | c1ab303 | 2016-01-04 07:26:53 -0800 | [diff] [blame] | 343 |  | 
| Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 344 | void PrintLayers( | 
 | 345 |     const std::vector<VkLayerProperties>& layers, | 
 | 346 |     const std::vector<std::vector<VkExtensionProperties>> extensions, | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 347 |     const Options& options, | 
 | 348 |     size_t indent) { | 
| Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 349 |     for (size_t i = 0; i < layers.size(); i++) { | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 350 |         printf("%s%s %u.%u.%u/%u\n", Indent(indent), layers[i].layerName, | 
| Jesse Hall | e2948d8 | 2016-02-25 04:19:32 -0800 | [diff] [blame] | 351 |                VK_VERSION_MAJOR(layers[i].specVersion), | 
 | 352 |                VK_VERSION_MINOR(layers[i].specVersion), | 
 | 353 |                VK_VERSION_PATCH(layers[i].specVersion), | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 354 |                layers[i].implementationVersion); | 
 | 355 |         if (options.layer_description) | 
 | 356 |             printf("%s%s\n", Indent(indent + 1), layers[i].description); | 
 | 357 |         if (options.layer_extensions && !extensions[i].empty()) { | 
 | 358 |             if (!extensions[i].empty()) { | 
 | 359 |                 printf("%sExtensions [%zu]:\n", Indent(indent + 1), | 
 | 360 |                        extensions[i].size()); | 
 | 361 |                 PrintExtensions(extensions[i], options, indent + 2); | 
 | 362 |             } | 
 | 363 |         } | 
| Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 364 |     } | 
 | 365 | } | 
 | 366 |  | 
| Jesse Hall | f63e445 | 2016-02-08 21:22:23 -0800 | [diff] [blame] | 367 | void PrintAllFeatures(const char* indent, | 
 | 368 |                       const VkPhysicalDeviceFeatures& features) { | 
 | 369 |     // clang-format off | 
 | 370 |     printf("%srobustBufferAccess: %s\n", indent, features.robustBufferAccess ? "YES" : "NO"); | 
 | 371 |     printf("%sfullDrawIndexUint32: %s\n", indent, features.fullDrawIndexUint32 ? "YES" : "NO"); | 
 | 372 |     printf("%simageCubeArray: %s\n", indent, features.imageCubeArray ? "YES" : "NO"); | 
 | 373 |     printf("%sindependentBlend: %s\n", indent, features.independentBlend ? "YES" : "NO"); | 
 | 374 |     printf("%sgeometryShader: %s\n", indent, features.geometryShader ? "YES" : "NO"); | 
 | 375 |     printf("%stessellationShader: %s\n", indent, features.tessellationShader ? "YES" : "NO"); | 
 | 376 |     printf("%ssampleRateShading: %s\n", indent, features.sampleRateShading ? "YES" : "NO"); | 
 | 377 |     printf("%sdualSrcBlend: %s\n", indent, features.dualSrcBlend ? "YES" : "NO"); | 
 | 378 |     printf("%slogicOp: %s\n", indent, features.logicOp ? "YES" : "NO"); | 
 | 379 |     printf("%smultiDrawIndirect: %s\n", indent, features.multiDrawIndirect ? "YES" : "NO"); | 
 | 380 |     printf("%sdrawIndirectFirstInstance: %s\n", indent, features.drawIndirectFirstInstance ? "YES" : "NO"); | 
 | 381 |     printf("%sdepthClamp: %s\n", indent, features.depthClamp ? "YES" : "NO"); | 
 | 382 |     printf("%sdepthBiasClamp: %s\n", indent, features.depthBiasClamp ? "YES" : "NO"); | 
 | 383 |     printf("%sfillModeNonSolid: %s\n", indent, features.fillModeNonSolid ? "YES" : "NO"); | 
 | 384 |     printf("%sdepthBounds: %s\n", indent, features.depthBounds ? "YES" : "NO"); | 
 | 385 |     printf("%swideLines: %s\n", indent, features.wideLines ? "YES" : "NO"); | 
 | 386 |     printf("%slargePoints: %s\n", indent, features.largePoints ? "YES" : "NO"); | 
 | 387 |     printf("%salphaToOne: %s\n", indent, features.alphaToOne ? "YES" : "NO"); | 
 | 388 |     printf("%smultiViewport: %s\n", indent, features.multiViewport ? "YES" : "NO"); | 
 | 389 |     printf("%ssamplerAnisotropy: %s\n", indent, features.samplerAnisotropy ? "YES" : "NO"); | 
 | 390 |     printf("%stextureCompressionETC2: %s\n", indent, features.textureCompressionETC2 ? "YES" : "NO"); | 
 | 391 |     printf("%stextureCompressionASTC_LDR: %s\n", indent, features.textureCompressionASTC_LDR ? "YES" : "NO"); | 
 | 392 |     printf("%stextureCompressionBC: %s\n", indent, features.textureCompressionBC ? "YES" : "NO"); | 
 | 393 |     printf("%socclusionQueryPrecise: %s\n", indent, features.occlusionQueryPrecise ? "YES" : "NO"); | 
 | 394 |     printf("%spipelineStatisticsQuery: %s\n", indent, features.pipelineStatisticsQuery ? "YES" : "NO"); | 
 | 395 |     printf("%svertexPipelineStoresAndAtomics: %s\n", indent, features.vertexPipelineStoresAndAtomics ? "YES" : "NO"); | 
 | 396 |     printf("%sfragmentStoresAndAtomics: %s\n", indent, features.fragmentStoresAndAtomics ? "YES" : "NO"); | 
 | 397 |     printf("%sshaderTessellationAndGeometryPointSize: %s\n", indent, features.shaderTessellationAndGeometryPointSize ? "YES" : "NO"); | 
 | 398 |     printf("%sshaderImageGatherExtended: %s\n", indent, features.shaderImageGatherExtended ? "YES" : "NO"); | 
 | 399 |     printf("%sshaderStorageImageExtendedFormats: %s\n", indent, features.shaderStorageImageExtendedFormats ? "YES" : "NO"); | 
 | 400 |     printf("%sshaderStorageImageMultisample: %s\n", indent, features.shaderStorageImageMultisample ? "YES" : "NO"); | 
 | 401 |     printf("%sshaderStorageImageReadWithoutFormat: %s\n", indent, features.shaderStorageImageReadWithoutFormat ? "YES" : "NO"); | 
 | 402 |     printf("%sshaderStorageImageWriteWithoutFormat: %s\n", indent, features.shaderStorageImageWriteWithoutFormat ? "YES" : "NO"); | 
 | 403 |     printf("%sshaderUniformBufferArrayDynamicIndexing: %s\n", indent, features.shaderUniformBufferArrayDynamicIndexing ? "YES" : "NO"); | 
 | 404 |     printf("%sshaderSampledImageArrayDynamicIndexing: %s\n", indent, features.shaderSampledImageArrayDynamicIndexing ? "YES" : "NO"); | 
 | 405 |     printf("%sshaderStorageBufferArrayDynamicIndexing: %s\n", indent, features.shaderStorageBufferArrayDynamicIndexing ? "YES" : "NO"); | 
 | 406 |     printf("%sshaderStorageImageArrayDynamicIndexing: %s\n", indent, features.shaderStorageImageArrayDynamicIndexing ? "YES" : "NO"); | 
 | 407 |     printf("%sshaderClipDistance: %s\n", indent, features.shaderClipDistance ? "YES" : "NO"); | 
 | 408 |     printf("%sshaderCullDistance: %s\n", indent, features.shaderCullDistance ? "YES" : "NO"); | 
 | 409 |     printf("%sshaderFloat64: %s\n", indent, features.shaderFloat64 ? "YES" : "NO"); | 
 | 410 |     printf("%sshaderInt64: %s\n", indent, features.shaderInt64 ? "YES" : "NO"); | 
 | 411 |     printf("%sshaderInt16: %s\n", indent, features.shaderInt16 ? "YES" : "NO"); | 
 | 412 |     printf("%sshaderResourceResidency: %s\n", indent, features.shaderResourceResidency ? "YES" : "NO"); | 
 | 413 |     printf("%sshaderResourceMinLod: %s\n", indent, features.shaderResourceMinLod ? "YES" : "NO"); | 
 | 414 |     printf("%ssparseBinding: %s\n", indent, features.sparseBinding ? "YES" : "NO"); | 
 | 415 |     printf("%ssparseResidencyBuffer: %s\n", indent, features.sparseResidencyBuffer ? "YES" : "NO"); | 
 | 416 |     printf("%ssparseResidencyImage2D: %s\n", indent, features.sparseResidencyImage2D ? "YES" : "NO"); | 
 | 417 |     printf("%ssparseResidencyImage3D: %s\n", indent, features.sparseResidencyImage3D ? "YES" : "NO"); | 
 | 418 |     printf("%ssparseResidency2Samples: %s\n", indent, features.sparseResidency2Samples ? "YES" : "NO"); | 
 | 419 |     printf("%ssparseResidency4Samples: %s\n", indent, features.sparseResidency4Samples ? "YES" : "NO"); | 
 | 420 |     printf("%ssparseResidency8Samples: %s\n", indent, features.sparseResidency8Samples ? "YES" : "NO"); | 
 | 421 |     printf("%ssparseResidency16Samples: %s\n", indent, features.sparseResidency16Samples ? "YES" : "NO"); | 
 | 422 |     printf("%ssparseResidencyAliased: %s\n", indent, features.sparseResidencyAliased ? "YES" : "NO"); | 
 | 423 |     printf("%svariableMultisampleRate: %s\n", indent, features.variableMultisampleRate ? "YES" : "NO"); | 
 | 424 |     printf("%sinheritedQueries: %s\n", indent, features.inheritedQueries ? "YES" : "NO"); | 
 | 425 |     // clang-format on | 
 | 426 | } | 
 | 427 |  | 
 | 428 | void PrintSupportedFeatures(const char* indent, | 
 | 429 |                             const VkPhysicalDeviceFeatures& features) { | 
 | 430 |     // clang-format off | 
 | 431 |     if (features.robustBufferAccess) printf("%srobustBufferAccess\n", indent); | 
 | 432 |     if (features.fullDrawIndexUint32) printf("%sfullDrawIndexUint32\n", indent); | 
 | 433 |     if (features.imageCubeArray) printf("%simageCubeArray\n", indent); | 
 | 434 |     if (features.independentBlend) printf("%sindependentBlend\n", indent); | 
 | 435 |     if (features.geometryShader) printf("%sgeometryShader\n", indent); | 
 | 436 |     if (features.tessellationShader) printf("%stessellationShader\n", indent); | 
 | 437 |     if (features.sampleRateShading) printf("%ssampleRateShading\n", indent); | 
 | 438 |     if (features.dualSrcBlend) printf("%sdualSrcBlend\n", indent); | 
 | 439 |     if (features.logicOp) printf("%slogicOp\n", indent); | 
 | 440 |     if (features.multiDrawIndirect) printf("%smultiDrawIndirect\n", indent); | 
 | 441 |     if (features.drawIndirectFirstInstance) printf("%sdrawIndirectFirstInstance\n", indent); | 
 | 442 |     if (features.depthClamp) printf("%sdepthClamp\n", indent); | 
 | 443 |     if (features.depthBiasClamp) printf("%sdepthBiasClamp\n", indent); | 
 | 444 |     if (features.fillModeNonSolid) printf("%sfillModeNonSolid\n", indent); | 
 | 445 |     if (features.depthBounds) printf("%sdepthBounds\n", indent); | 
 | 446 |     if (features.wideLines) printf("%swideLines\n", indent); | 
 | 447 |     if (features.largePoints) printf("%slargePoints\n", indent); | 
 | 448 |     if (features.alphaToOne) printf("%salphaToOne\n", indent); | 
 | 449 |     if (features.multiViewport) printf("%smultiViewport\n", indent); | 
 | 450 |     if (features.samplerAnisotropy) printf("%ssamplerAnisotropy\n", indent); | 
 | 451 |     if (features.textureCompressionETC2) printf("%stextureCompressionETC2\n", indent); | 
 | 452 |     if (features.textureCompressionASTC_LDR) printf("%stextureCompressionASTC_LDR\n", indent); | 
 | 453 |     if (features.textureCompressionBC) printf("%stextureCompressionBC\n", indent); | 
 | 454 |     if (features.occlusionQueryPrecise) printf("%socclusionQueryPrecise\n", indent); | 
 | 455 |     if (features.pipelineStatisticsQuery) printf("%spipelineStatisticsQuery\n", indent); | 
 | 456 |     if (features.vertexPipelineStoresAndAtomics) printf("%svertexPipelineStoresAndAtomics\n", indent); | 
 | 457 |     if (features.fragmentStoresAndAtomics) printf("%sfragmentStoresAndAtomics\n", indent); | 
 | 458 |     if (features.shaderTessellationAndGeometryPointSize) printf("%sshaderTessellationAndGeometryPointSize\n", indent); | 
 | 459 |     if (features.shaderImageGatherExtended) printf("%sshaderImageGatherExtended\n", indent); | 
 | 460 |     if (features.shaderStorageImageExtendedFormats) printf("%sshaderStorageImageExtendedFormats\n", indent); | 
 | 461 |     if (features.shaderStorageImageMultisample) printf("%sshaderStorageImageMultisample\n", indent); | 
 | 462 |     if (features.shaderStorageImageReadWithoutFormat) printf("%sshaderStorageImageReadWithoutFormat\n", indent); | 
 | 463 |     if (features.shaderStorageImageWriteWithoutFormat) printf("%sshaderStorageImageWriteWithoutFormat\n", indent); | 
 | 464 |     if (features.shaderUniformBufferArrayDynamicIndexing) printf("%sshaderUniformBufferArrayDynamicIndexing\n", indent); | 
 | 465 |     if (features.shaderSampledImageArrayDynamicIndexing) printf("%sshaderSampledImageArrayDynamicIndexing\n", indent); | 
 | 466 |     if (features.shaderStorageBufferArrayDynamicIndexing) printf("%sshaderStorageBufferArrayDynamicIndexing\n", indent); | 
 | 467 |     if (features.shaderStorageImageArrayDynamicIndexing) printf("%sshaderStorageImageArrayDynamicIndexing\n", indent); | 
 | 468 |     if (features.shaderClipDistance) printf("%sshaderClipDistance\n", indent); | 
 | 469 |     if (features.shaderCullDistance) printf("%sshaderCullDistance\n", indent); | 
 | 470 |     if (features.shaderFloat64) printf("%sshaderFloat64\n", indent); | 
 | 471 |     if (features.shaderInt64) printf("%sshaderInt64\n", indent); | 
 | 472 |     if (features.shaderInt16) printf("%sshaderInt16\n", indent); | 
 | 473 |     if (features.shaderResourceResidency) printf("%sshaderResourceResidency\n", indent); | 
 | 474 |     if (features.shaderResourceMinLod) printf("%sshaderResourceMinLod\n", indent); | 
 | 475 |     if (features.sparseBinding) printf("%ssparseBinding\n", indent); | 
 | 476 |     if (features.sparseResidencyBuffer) printf("%ssparseResidencyBuffer\n", indent); | 
 | 477 |     if (features.sparseResidencyImage2D) printf("%ssparseResidencyImage2D\n", indent); | 
 | 478 |     if (features.sparseResidencyImage3D) printf("%ssparseResidencyImage3D\n", indent); | 
 | 479 |     if (features.sparseResidency2Samples) printf("%ssparseResidency2Samples\n", indent); | 
 | 480 |     if (features.sparseResidency4Samples) printf("%ssparseResidency4Samples\n", indent); | 
 | 481 |     if (features.sparseResidency8Samples) printf("%ssparseResidency8Samples\n", indent); | 
 | 482 |     if (features.sparseResidency16Samples) printf("%ssparseResidency16Samples\n", indent); | 
 | 483 |     if (features.sparseResidencyAliased) printf("%ssparseResidencyAliased\n", indent); | 
 | 484 |     if (features.variableMultisampleRate) printf("%svariableMultisampleRate\n", indent); | 
 | 485 |     if (features.inheritedQueries) printf("%sinheritedQueries\n", indent); | 
 | 486 |     // clang-format on | 
 | 487 | } | 
 | 488 |  | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 489 | void PrintGpuInfo(const GpuInfo& info, const Options& options, size_t indent) { | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 490 |     VkResult result; | 
| Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 491 |     std::ostringstream strbuf; | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 492 |  | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 493 |     printf("%s\"%s\" (%s) %u.%u.%u/%#x [%04x:%04x]\n", Indent(indent), | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 494 |            info.properties.deviceName, | 
 | 495 |            VkPhysicalDeviceTypeStr(info.properties.deviceType), | 
| Jesse Hall | e2948d8 | 2016-02-25 04:19:32 -0800 | [diff] [blame] | 496 |            VK_VERSION_MAJOR(info.properties.apiVersion), | 
 | 497 |            VK_VERSION_MINOR(info.properties.apiVersion), | 
 | 498 |            VK_VERSION_PATCH(info.properties.apiVersion), | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 499 |            info.properties.driverVersion, info.properties.vendorID, | 
 | 500 |            info.properties.deviceID); | 
| Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 501 |  | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 502 |     for (uint32_t heap = 0; heap < info.memory.memoryHeapCount; heap++) { | 
 | 503 |         if ((info.memory.memoryHeaps[heap].flags & | 
| Jesse Hall | d1af812 | 2015-11-29 23:50:38 -0800 | [diff] [blame] | 504 |              VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) | 
 | 505 |             strbuf << "DEVICE_LOCAL"; | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 506 |         printf("%sHeap %u: %" PRIu64 " MiB (0x%" PRIx64 " B) %s\n", | 
 | 507 |                Indent(indent + 1), heap, | 
| Jesse Hall | 00f10fe | 2016-02-08 21:20:20 -0800 | [diff] [blame] | 508 |                info.memory.memoryHeaps[heap].size / 0x100000, | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 509 |                info.memory.memoryHeaps[heap].size, strbuf.str().c_str()); | 
| Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 510 |         strbuf.str(std::string()); | 
 | 511 |  | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 512 |         for (uint32_t type = 0; type < info.memory.memoryTypeCount; type++) { | 
 | 513 |             if (info.memory.memoryTypes[type].heapIndex != heap) | 
| Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 514 |                 continue; | 
 | 515 |             VkMemoryPropertyFlags flags = | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 516 |                 info.memory.memoryTypes[type].propertyFlags; | 
| Jesse Hall | d1af812 | 2015-11-29 23:50:38 -0800 | [diff] [blame] | 517 |             if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0) | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 518 |                 strbuf << " DEVICE_LOCAL"; | 
| Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 519 |             if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 520 |                 strbuf << " HOST_VISIBLE"; | 
| Jesse Hall | d1af812 | 2015-11-29 23:50:38 -0800 | [diff] [blame] | 521 |             if ((flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0) | 
 | 522 |                 strbuf << " COHERENT"; | 
 | 523 |             if ((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0) | 
 | 524 |                 strbuf << " CACHED"; | 
| Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 525 |             if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0) | 
 | 526 |                 strbuf << " LAZILY_ALLOCATED"; | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 527 |             printf("%sType %u:%s\n", Indent(indent + 2), type, | 
 | 528 |                    strbuf.str().c_str()); | 
| Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 529 |             strbuf.str(std::string()); | 
 | 530 |         } | 
 | 531 |     } | 
| Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 532 |  | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 533 |     for (uint32_t family = 0; family < info.queue_families.size(); family++) { | 
 | 534 |         const VkQueueFamilyProperties& qprops = info.queue_families[family]; | 
| Jesse Hall | 8966bf4 | 2016-01-16 17:26:48 -0800 | [diff] [blame] | 535 |         VkQueueFlags flags = qprops.queueFlags; | 
 | 536 |         char flags_str[5]; | 
 | 537 |         flags_str[0] = (flags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '_'; | 
 | 538 |         flags_str[1] = (flags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '_'; | 
 | 539 |         flags_str[2] = (flags & VK_QUEUE_TRANSFER_BIT) ? 'T' : '_'; | 
 | 540 |         flags_str[3] = (flags & VK_QUEUE_SPARSE_BINDING_BIT) ? 'S' : '_'; | 
 | 541 |         flags_str[4] = '\0'; | 
 | 542 |         printf( | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 543 |             "%sQueue Family %u: %ux %s\n" | 
 | 544 |             "%stimestampValidBits: %ub\n" | 
 | 545 |             "%sminImageTransferGranularity: (%u,%u,%u)\n", | 
 | 546 |             Indent(indent + 1), family, qprops.queueCount, flags_str, | 
 | 547 |             Indent(indent + 2), qprops.timestampValidBits, Indent(indent + 2), | 
| Jesse Hall | 8966bf4 | 2016-01-16 17:26:48 -0800 | [diff] [blame] | 548 |             qprops.minImageTransferGranularity.width, | 
 | 549 |             qprops.minImageTransferGranularity.height, | 
 | 550 |             qprops.minImageTransferGranularity.depth); | 
| Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 551 |     } | 
| Jesse Hall | 6e4ab31 | 2016-01-07 22:26:20 -0800 | [diff] [blame] | 552 |  | 
| Jesse Hall | c5cec28 | 2016-01-18 04:01:10 -0800 | [diff] [blame] | 553 |     printf("%sFeatures:\n", Indent(indent + 1)); | 
| Jesse Hall | f63e445 | 2016-02-08 21:22:23 -0800 | [diff] [blame] | 554 |     if (options.unsupported_features) { | 
 | 555 |         PrintAllFeatures(Indent(indent + 2), info.features); | 
 | 556 |     } else { | 
 | 557 |         PrintSupportedFeatures(Indent(indent + 2), info.features); | 
 | 558 |     } | 
| Jesse Hall | c5cec28 | 2016-01-18 04:01:10 -0800 | [diff] [blame] | 559 |  | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 560 |     printf("%sExtensions [%zu]:\n", Indent(indent + 1), info.extensions.size()); | 
 | 561 |     if (!info.extensions.empty()) | 
 | 562 |         PrintExtensions(info.extensions, options, indent + 2); | 
 | 563 |     printf("%sLayers [%zu]:\n", Indent(indent + 1), info.layers.size()); | 
 | 564 |     if (!info.layers.empty()) | 
 | 565 |         PrintLayers(info.layers, info.layer_extensions, options, indent + 2); | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 566 | } | 
 | 567 |  | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 568 | void PrintInfo(const VulkanInfo& info, const Options& options) { | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 569 |     std::ostringstream strbuf; | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 570 |     size_t indent = 0; | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 571 |  | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 572 |     printf("%sInstance Extensions [%zu]:\n", Indent(indent), | 
 | 573 |            info.extensions.size()); | 
 | 574 |     PrintExtensions(info.extensions, options, indent + 1); | 
 | 575 |     printf("%sInstance Layers [%zu]:\n", Indent(indent), info.layers.size()); | 
 | 576 |     if (!info.layers.empty()) | 
 | 577 |         PrintLayers(info.layers, info.layer_extensions, options, indent + 1); | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 578 |  | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 579 |     printf("%sPhysicalDevices [%zu]:\n", Indent(indent), info.gpus.size()); | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 580 |     for (const auto& gpu : info.gpus) | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 581 |         PrintGpuInfo(gpu, options, indent + 1); | 
| Jesse Hall | c1ab303 | 2016-01-04 07:26:53 -0800 | [diff] [blame] | 582 | } | 
 | 583 |  | 
| Jesse Hall | f63e445 | 2016-02-08 21:22:23 -0800 | [diff] [blame] | 584 | const char kUsageString[] = | 
 | 585 |     "usage: vkinfo [options]\n" | 
 | 586 |     "  -v                       enable all the following verbose options\n" | 
 | 587 |     "    -layer_description     print layer description strings\n" | 
 | 588 |     "    -layer_extensions      print extensions supported by each layer\n" | 
 | 589 |     "    -unsupported_features  print all physical device features\n" | 
 | 590 |     "  -validate                enable validation layers if present\n" | 
 | 591 |     "  -debug_pause             pause at start until resumed via debugger\n"; | 
 | 592 |  | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 593 | }  // namespace | 
 | 594 |  | 
| Jesse Hall | 09559b5 | 2016-01-07 21:50:19 -0800 | [diff] [blame] | 595 | // ---------------------------------------------------------------------------- | 
 | 596 |  | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 597 | int main(int argc, char const* argv[]) { | 
| Courtney Goeltzenleuchter | c2a7709 | 2016-02-08 20:31:46 -0700 | [diff] [blame] | 598 |     static volatile bool startup_pause = false; | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 599 |     Options options = { | 
 | 600 |         .layer_description = false, .layer_extensions = false, | 
| Jesse Hall | f63e445 | 2016-02-08 21:22:23 -0800 | [diff] [blame] | 601 |         .unsupported_features = false, | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 602 |         .validate = false, | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 603 |     }; | 
 | 604 |     for (int argi = 1; argi < argc; argi++) { | 
| Jesse Hall | f63e445 | 2016-02-08 21:22:23 -0800 | [diff] [blame] | 605 |         if (strcmp(argv[argi], "-h") == 0) { | 
 | 606 |             fputs(kUsageString, stdout); | 
 | 607 |             return 0; | 
 | 608 |         } | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 609 |         if (strcmp(argv[argi], "-v") == 0) { | 
 | 610 |             options.layer_description = true; | 
 | 611 |             options.layer_extensions = true; | 
| Jesse Hall | f63e445 | 2016-02-08 21:22:23 -0800 | [diff] [blame] | 612 |             options.unsupported_features = true; | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 613 |         } else if (strcmp(argv[argi], "-layer_description") == 0) { | 
 | 614 |             options.layer_description = true; | 
 | 615 |         } else if (strcmp(argv[argi], "-layer_extensions") == 0) { | 
 | 616 |             options.layer_extensions = true; | 
| Jesse Hall | f63e445 | 2016-02-08 21:22:23 -0800 | [diff] [blame] | 617 |         } else if (strcmp(argv[argi], "-unsupported_features") == 0) { | 
 | 618 |             options.unsupported_features = true; | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 619 |         } else if (strcmp(argv[argi], "-validate") == 0) { | 
 | 620 |             options.validate = true; | 
| Courtney Goeltzenleuchter | c2a7709 | 2016-02-08 20:31:46 -0700 | [diff] [blame] | 621 |         } else if (strcmp(argv[argi], "-debug_pause") == 0) { | 
 | 622 |             startup_pause = true; | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 623 |         } | 
 | 624 |     } | 
 | 625 |  | 
| Courtney Goeltzenleuchter | c2a7709 | 2016-02-08 20:31:46 -0700 | [diff] [blame] | 626 |     while (startup_pause) { | 
 | 627 |         sleep(0); | 
 | 628 |     } | 
 | 629 |  | 
| Jesse Hall | c1ab303 | 2016-01-04 07:26:53 -0800 | [diff] [blame] | 630 |     VulkanInfo info; | 
| Chia-I Wu | d0bba37 | 2016-02-22 11:41:27 +0800 | [diff] [blame] | 631 |     GatherInfo(&info, options); | 
| Jesse Hall | 38cb840 | 2016-01-18 03:41:35 -0800 | [diff] [blame] | 632 |     PrintInfo(info, options); | 
| Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 633 |     return 0; | 
 | 634 | } |