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