blob: e650a27d031fa5b76795d06714257fcec736d036 [file] [log] [blame]
Jesse Halld02edcb2015-09-08 07:44:48 -07001/*
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 Hall4da3bd62016-01-16 22:14:40 -080017#include <algorithm>
18#include <array>
Jesse Hall73ab0ac2015-08-25 15:09:15 +010019#include <inttypes.h>
Jesse Hall04f4f472015-08-16 19:51:04 -070020#include <stdlib.h>
Jesse Hall1f91d392015-12-11 16:28:44 -080021#include <sstream>
Jesse Hall04f4f472015-08-16 19:51:04 -070022#include <vector>
23
Jesse Hall04f4f472015-08-16 19:51:04 -070024#include <vulkan/vulkan.h>
Jesse Hall4da3bd62016-01-16 22:14:40 -080025#include <vulkan/vk_ext_debug_report.h>
Jesse Hall04f4f472015-08-16 19:51:04 -070026
27#define LOG_TAG "vkinfo"
28#include <log/log.h>
29
30namespace {
31
Chia-I Wud0bba372016-02-22 11:41:27 +080032struct Options {
33 bool layer_description;
34 bool layer_extensions;
Jesse Hallf63e4452016-02-08 21:22:23 -080035 bool unsupported_features;
Chia-I Wud0bba372016-02-22 11:41:27 +080036 bool validate;
37};
38
Jesse Hall09559b52016-01-07 21:50:19 -080039struct GpuInfo {
40 VkPhysicalDeviceProperties properties;
41 VkPhysicalDeviceMemoryProperties memory;
Jesse Hallb1471272016-01-17 21:36:58 -080042 VkPhysicalDeviceFeatures features;
Jesse Hall09559b52016-01-07 21:50:19 -080043 std::vector<VkQueueFamilyProperties> queue_families;
Jesse Hall6e4ab312016-01-07 22:26:20 -080044 std::vector<VkExtensionProperties> extensions;
45 std::vector<VkLayerProperties> layers;
46 std::vector<std::vector<VkExtensionProperties>> layer_extensions;
Jesse Hall09559b52016-01-07 21:50:19 -080047};
48struct VulkanInfo {
49 std::vector<VkExtensionProperties> extensions;
50 std::vector<VkLayerProperties> layers;
51 std::vector<std::vector<VkExtensionProperties>> layer_extensions;
52 std::vector<GpuInfo> gpus;
53};
54
55// ----------------------------------------------------------------------------
56
Jesse Hall04f4f472015-08-16 19:51:04 -070057[[noreturn]] void die(const char* proc, VkResult result) {
58 const char* result_str;
59 switch (result) {
60 // clang-format off
61 case VK_SUCCESS: result_str = "VK_SUCCESS"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070062 case VK_NOT_READY: result_str = "VK_NOT_READY"; break;
63 case VK_TIMEOUT: result_str = "VK_TIMEOUT"; break;
64 case VK_EVENT_SET: result_str = "VK_EVENT_SET"; break;
65 case VK_EVENT_RESET: result_str = "VK_EVENT_RESET"; break;
66 case VK_INCOMPLETE: result_str = "VK_INCOMPLETE"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070067 case VK_ERROR_OUT_OF_HOST_MEMORY: result_str = "VK_ERROR_OUT_OF_HOST_MEMORY"; break;
68 case VK_ERROR_OUT_OF_DEVICE_MEMORY: result_str = "VK_ERROR_OUT_OF_DEVICE_MEMORY"; break;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070069 case VK_ERROR_INITIALIZATION_FAILED: result_str = "VK_ERROR_INITIALIZATION_FAILED"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070070 case VK_ERROR_DEVICE_LOST: result_str = "VK_ERROR_DEVICE_LOST"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070071 case VK_ERROR_MEMORY_MAP_FAILED: result_str = "VK_ERROR_MEMORY_MAP_FAILED"; break;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070072 case VK_ERROR_LAYER_NOT_PRESENT: result_str = "VK_ERROR_LAYER_NOT_PRESENT"; break;
73 case VK_ERROR_EXTENSION_NOT_PRESENT: result_str = "VK_ERROR_EXTENSION_NOT_PRESENT"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070074 case VK_ERROR_INCOMPATIBLE_DRIVER: result_str = "VK_ERROR_INCOMPATIBLE_DRIVER"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070075 default: result_str = "<unknown VkResult>"; break;
76 // clang-format on
77 }
78 fprintf(stderr, "%s failed: %s (%d)\n", proc, result_str, result);
79 exit(1);
80}
81
Jesse Hall4da3bd62016-01-16 22:14:40 -080082bool HasExtension(const std::vector<VkExtensionProperties>& extensions,
83 const char* name) {
84 return std::find_if(extensions.cbegin(), extensions.cend(),
85 [=](const VkExtensionProperties& prop) {
86 return strcmp(prop.extensionName, name) == 0;
87 }) != extensions.end();
88}
89
Jesse Hall09559b52016-01-07 21:50:19 -080090void EnumerateInstanceExtensions(
91 const char* layer_name,
92 std::vector<VkExtensionProperties>* extensions) {
93 VkResult result;
94 uint32_t count;
95 result =
96 vkEnumerateInstanceExtensionProperties(layer_name, &count, nullptr);
97 if (result != VK_SUCCESS)
98 die("vkEnumerateInstanceExtensionProperties (count)", result);
99 do {
100 extensions->resize(count);
101 result = vkEnumerateInstanceExtensionProperties(layer_name, &count,
102 extensions->data());
103 } while (result == VK_INCOMPLETE);
104 if (result != VK_SUCCESS)
105 die("vkEnumerateInstanceExtensionProperties (data)", result);
106}
107
Jesse Hall6e4ab312016-01-07 22:26:20 -0800108void EnumerateDeviceExtensions(VkPhysicalDevice gpu,
109 const char* layer_name,
110 std::vector<VkExtensionProperties>* extensions) {
111 VkResult result;
112 uint32_t count;
113 result =
114 vkEnumerateDeviceExtensionProperties(gpu, layer_name, &count, nullptr);
115 if (result != VK_SUCCESS)
116 die("vkEnumerateDeviceExtensionProperties (count)", result);
117 do {
118 extensions->resize(count);
119 result = vkEnumerateDeviceExtensionProperties(gpu, layer_name, &count,
120 extensions->data());
121 } while (result == VK_INCOMPLETE);
122 if (result != VK_SUCCESS)
123 die("vkEnumerateDeviceExtensionProperties (data)", result);
124}
125
Chia-I Wud0bba372016-02-22 11:41:27 +0800126void GatherGpuInfo(VkPhysicalDevice gpu,
127 const Options &options,
128 GpuInfo& info) {
Jesse Hallb1471272016-01-17 21:36:58 -0800129 VkResult result;
130 uint32_t count;
131
132 vkGetPhysicalDeviceProperties(gpu, &info.properties);
133 vkGetPhysicalDeviceMemoryProperties(gpu, &info.memory);
134 vkGetPhysicalDeviceFeatures(gpu, &info.features);
135
136 vkGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr);
137 info.queue_families.resize(count);
138 vkGetPhysicalDeviceQueueFamilyProperties(gpu, &count,
139 info.queue_families.data());
140
141 result = vkEnumerateDeviceLayerProperties(gpu, &count, nullptr);
142 if (result != VK_SUCCESS)
143 die("vkEnumerateDeviceLayerProperties (count)", result);
144 do {
145 info.layers.resize(count);
146 result =
147 vkEnumerateDeviceLayerProperties(gpu, &count, info.layers.data());
148 } while (result == VK_INCOMPLETE);
149 if (result != VK_SUCCESS)
150 die("vkEnumerateDeviceLayerProperties (data)", result);
151 info.layer_extensions.resize(info.layers.size());
152
153 EnumerateDeviceExtensions(gpu, nullptr, &info.extensions);
154 for (size_t i = 0; i < info.layers.size(); i++) {
155 EnumerateDeviceExtensions(gpu, info.layers[i].layerName,
156 &info.layer_extensions[i]);
157 }
158
159 const std::array<const char*, 1> kDesiredExtensions = {
160 {VK_KHR_SWAPCHAIN_EXTENSION_NAME},
161 };
162 const char* extensions[kDesiredExtensions.size()];
163 uint32_t num_extensions = 0;
164 for (const auto& desired_ext : kDesiredExtensions) {
165 bool available = HasExtension(info.extensions, desired_ext);
166 for (size_t i = 0; !available && i < info.layer_extensions.size(); i++)
167 available = HasExtension(info.layer_extensions[i], desired_ext);
168 if (available)
169 extensions[num_extensions++] = desired_ext;
170 }
171
172 VkDevice device;
Courtney Goeltzenleuchterca472ab2016-02-01 20:09:00 -0700173 float queue_priorities[] = {0.0};
Jesse Hallb1471272016-01-17 21:36:58 -0800174 const VkDeviceQueueCreateInfo queue_create_info = {
175 .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
176 .queueFamilyIndex = 0,
177 .queueCount = 1,
Courtney Goeltzenleuchterca472ab2016-02-01 20:09:00 -0700178 queue_priorities
Jesse Hallb1471272016-01-17 21:36:58 -0800179 };
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700180 // clang-format off
181 const char *kValidationLayers[] = {
182 "VK_LAYER_GOOGLE_threading",
183 "VK_LAYER_LUNARG_device_limits",
184 "VK_LAYER_LUNARG_draw_state",
185 "VK_LAYER_LUNARG_image",
186 "VK_LAYER_LUNARG_mem_tracker",
187 "VK_LAYER_LUNARG_object_tracker",
188 "VK_LAYER_LUNARG_param_checker",
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 Hallb1471272016-01-17 21:36:58 -0800194 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 Wud0bba372016-02-22 11:41:27 +0800200 .enabledLayerCount = (options.validate) ? num_layers : 0,
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700201 .ppEnabledLayerNames = kValidationLayers,
Jesse Hallb1471272016-01-17 21:36:58 -0800202 .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 Wud0bba372016-02-22 11:41:27 +0800210void GatherInfo(VulkanInfo* info, const Options& options) {
Jesse Hall09559b52016-01-07 21:50:19 -0800211 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 Hallae3b70d2016-01-17 22:05:29 -0800232 const char* kDesiredExtensions[] = {
233 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Jesse Hall4da3bd62016-01-16 22:14:40 -0800234 };
Jesse Hallae3b70d2016-01-17 22:05:29 -0800235 const char*
236 extensions[sizeof(kDesiredExtensions) / sizeof(kDesiredExtensions[0])];
Jesse Hall4da3bd62016-01-16 22:14:40 -0800237 uint32_t num_extensions = 0;
238 for (const auto& desired_ext : kDesiredExtensions) {
239 bool available = HasExtension(info->extensions, desired_ext);
240 for (size_t i = 0; !available && i < info->layer_extensions.size(); i++)
241 available = HasExtension(info->layer_extensions[i], desired_ext);
242 if (available)
243 extensions[num_extensions++] = desired_ext;
244 }
245
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700246 // clang-format off
247 const char *kValidationLayers[] = {
248 "VK_LAYER_GOOGLE_threading",
249 "VK_LAYER_LUNARG_device_limits",
250 "VK_LAYER_LUNARG_draw_state",
251 "VK_LAYER_LUNARG_image",
252 "VK_LAYER_LUNARG_mem_tracker",
253 "VK_LAYER_LUNARG_object_tracker",
254 "VK_LAYER_LUNARG_param_checker",
255 "VK_LAYER_LUNARG_swapchain",
256 "VK_LAYER_GOOGLE_unique_objects"
257 };
258 // clang-format on
259 uint32_t num_layers = sizeof(kValidationLayers) / sizeof(char*);
260
Jesse Hall09559b52016-01-07 21:50:19 -0800261 const VkInstanceCreateInfo create_info = {
262 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
Jesse Hall4da3bd62016-01-16 22:14:40 -0800263 .enabledExtensionCount = num_extensions,
264 .ppEnabledExtensionNames = extensions,
Chia-I Wud0bba372016-02-22 11:41:27 +0800265 .enabledLayerCount = (options.validate) ? num_layers : 0,
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700266 .ppEnabledLayerNames = kValidationLayers,
Jesse Hall09559b52016-01-07 21:50:19 -0800267 };
Jesse Hall4da3bd62016-01-16 22:14:40 -0800268 VkInstance instance;
Jesse Hall09559b52016-01-07 21:50:19 -0800269 result = vkCreateInstance(&create_info, nullptr, &instance);
270 if (result != VK_SUCCESS)
271 die("vkCreateInstance", result);
272
273 uint32_t num_gpus;
274 result = vkEnumeratePhysicalDevices(instance, &num_gpus, nullptr);
275 if (result != VK_SUCCESS)
276 die("vkEnumeratePhysicalDevices (count)", result);
277 std::vector<VkPhysicalDevice> gpus(num_gpus, VK_NULL_HANDLE);
278 do {
279 gpus.resize(num_gpus, VK_NULL_HANDLE);
280 result = vkEnumeratePhysicalDevices(instance, &num_gpus, gpus.data());
281 } while (result == VK_INCOMPLETE);
282 if (result != VK_SUCCESS)
283 die("vkEnumeratePhysicalDevices (data)", result);
284
285 info->gpus.resize(num_gpus);
Jesse Hallb1471272016-01-17 21:36:58 -0800286 for (size_t i = 0; i < gpus.size(); i++)
Chia-I Wud0bba372016-02-22 11:41:27 +0800287 GatherGpuInfo(gpus[i], options, info->gpus.at(i));
Jesse Hall09559b52016-01-07 21:50:19 -0800288
289 vkDestroyInstance(instance, nullptr);
290}
291
292// ----------------------------------------------------------------------------
293
Jesse Hall38cb8402016-01-18 03:41:35 -0800294const size_t kMaxIndent = 8;
295const size_t kIndentSize = 3;
296std::array<char, kMaxIndent * kIndentSize + 1> kIndent;
297const char* Indent(size_t n) {
298 static bool initialized = false;
299 if (!initialized) {
300 kIndent.fill(' ');
301 kIndent.back() = '\0';
302 initialized = true;
303 }
304 return kIndent.data() +
305 (kIndent.size() - (kIndentSize * std::min(n, kMaxIndent) + 1));
306}
307
Jesse Hallc1ab3032016-01-04 07:26:53 -0800308uint32_t ExtractMajorVersion(uint32_t version) {
309 return (version >> 22) & 0x3FF;
310}
311uint32_t ExtractMinorVersion(uint32_t version) {
312 return (version >> 12) & 0x3FF;
313}
314uint32_t ExtractPatchVersion(uint32_t version) {
315 return (version >> 0) & 0xFFF;
316}
317
Jesse Hall04f4f472015-08-16 19:51:04 -0700318const char* VkPhysicalDeviceTypeStr(VkPhysicalDeviceType type) {
319 switch (type) {
320 case VK_PHYSICAL_DEVICE_TYPE_OTHER:
321 return "OTHER";
322 case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
323 return "INTEGRATED_GPU";
324 case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
325 return "DISCRETE_GPU";
326 case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
327 return "VIRTUAL_GPU";
328 case VK_PHYSICAL_DEVICE_TYPE_CPU:
329 return "CPU";
330 default:
331 return "<UNKNOWN>";
332 }
333}
334
Jesse Hall09559b52016-01-07 21:50:19 -0800335void PrintExtensions(const std::vector<VkExtensionProperties>& extensions,
Jesse Hall38cb8402016-01-18 03:41:35 -0800336 const Options& /*options*/,
337 size_t indent) {
Jesse Hall09559b52016-01-07 21:50:19 -0800338 for (const auto& e : extensions)
Jesse Hall38cb8402016-01-18 03:41:35 -0800339 printf("%s%s (v%u)\n", Indent(indent), e.extensionName, e.specVersion);
Jesse Hall09559b52016-01-07 21:50:19 -0800340}
Jesse Hallc1ab3032016-01-04 07:26:53 -0800341
Jesse Hallaa410942016-01-17 13:07:10 -0800342void PrintLayers(
343 const std::vector<VkLayerProperties>& layers,
344 const std::vector<std::vector<VkExtensionProperties>> extensions,
Jesse Hall38cb8402016-01-18 03:41:35 -0800345 const Options& options,
346 size_t indent) {
Jesse Hallaa410942016-01-17 13:07:10 -0800347 for (size_t i = 0; i < layers.size(); i++) {
Jesse Hall38cb8402016-01-18 03:41:35 -0800348 printf("%s%s %u.%u.%u/%u\n", Indent(indent), layers[i].layerName,
349 ExtractMajorVersion(layers[i].specVersion),
350 ExtractMinorVersion(layers[i].specVersion),
351 ExtractPatchVersion(layers[i].specVersion),
352 layers[i].implementationVersion);
353 if (options.layer_description)
354 printf("%s%s\n", Indent(indent + 1), layers[i].description);
355 if (options.layer_extensions && !extensions[i].empty()) {
356 if (!extensions[i].empty()) {
357 printf("%sExtensions [%zu]:\n", Indent(indent + 1),
358 extensions[i].size());
359 PrintExtensions(extensions[i], options, indent + 2);
360 }
361 }
Jesse Hallaa410942016-01-17 13:07:10 -0800362 }
363}
364
Jesse Hallf63e4452016-02-08 21:22:23 -0800365void PrintAllFeatures(const char* indent,
366 const VkPhysicalDeviceFeatures& features) {
367 // clang-format off
368 printf("%srobustBufferAccess: %s\n", indent, features.robustBufferAccess ? "YES" : "NO");
369 printf("%sfullDrawIndexUint32: %s\n", indent, features.fullDrawIndexUint32 ? "YES" : "NO");
370 printf("%simageCubeArray: %s\n", indent, features.imageCubeArray ? "YES" : "NO");
371 printf("%sindependentBlend: %s\n", indent, features.independentBlend ? "YES" : "NO");
372 printf("%sgeometryShader: %s\n", indent, features.geometryShader ? "YES" : "NO");
373 printf("%stessellationShader: %s\n", indent, features.tessellationShader ? "YES" : "NO");
374 printf("%ssampleRateShading: %s\n", indent, features.sampleRateShading ? "YES" : "NO");
375 printf("%sdualSrcBlend: %s\n", indent, features.dualSrcBlend ? "YES" : "NO");
376 printf("%slogicOp: %s\n", indent, features.logicOp ? "YES" : "NO");
377 printf("%smultiDrawIndirect: %s\n", indent, features.multiDrawIndirect ? "YES" : "NO");
378 printf("%sdrawIndirectFirstInstance: %s\n", indent, features.drawIndirectFirstInstance ? "YES" : "NO");
379 printf("%sdepthClamp: %s\n", indent, features.depthClamp ? "YES" : "NO");
380 printf("%sdepthBiasClamp: %s\n", indent, features.depthBiasClamp ? "YES" : "NO");
381 printf("%sfillModeNonSolid: %s\n", indent, features.fillModeNonSolid ? "YES" : "NO");
382 printf("%sdepthBounds: %s\n", indent, features.depthBounds ? "YES" : "NO");
383 printf("%swideLines: %s\n", indent, features.wideLines ? "YES" : "NO");
384 printf("%slargePoints: %s\n", indent, features.largePoints ? "YES" : "NO");
385 printf("%salphaToOne: %s\n", indent, features.alphaToOne ? "YES" : "NO");
386 printf("%smultiViewport: %s\n", indent, features.multiViewport ? "YES" : "NO");
387 printf("%ssamplerAnisotropy: %s\n", indent, features.samplerAnisotropy ? "YES" : "NO");
388 printf("%stextureCompressionETC2: %s\n", indent, features.textureCompressionETC2 ? "YES" : "NO");
389 printf("%stextureCompressionASTC_LDR: %s\n", indent, features.textureCompressionASTC_LDR ? "YES" : "NO");
390 printf("%stextureCompressionBC: %s\n", indent, features.textureCompressionBC ? "YES" : "NO");
391 printf("%socclusionQueryPrecise: %s\n", indent, features.occlusionQueryPrecise ? "YES" : "NO");
392 printf("%spipelineStatisticsQuery: %s\n", indent, features.pipelineStatisticsQuery ? "YES" : "NO");
393 printf("%svertexPipelineStoresAndAtomics: %s\n", indent, features.vertexPipelineStoresAndAtomics ? "YES" : "NO");
394 printf("%sfragmentStoresAndAtomics: %s\n", indent, features.fragmentStoresAndAtomics ? "YES" : "NO");
395 printf("%sshaderTessellationAndGeometryPointSize: %s\n", indent, features.shaderTessellationAndGeometryPointSize ? "YES" : "NO");
396 printf("%sshaderImageGatherExtended: %s\n", indent, features.shaderImageGatherExtended ? "YES" : "NO");
397 printf("%sshaderStorageImageExtendedFormats: %s\n", indent, features.shaderStorageImageExtendedFormats ? "YES" : "NO");
398 printf("%sshaderStorageImageMultisample: %s\n", indent, features.shaderStorageImageMultisample ? "YES" : "NO");
399 printf("%sshaderStorageImageReadWithoutFormat: %s\n", indent, features.shaderStorageImageReadWithoutFormat ? "YES" : "NO");
400 printf("%sshaderStorageImageWriteWithoutFormat: %s\n", indent, features.shaderStorageImageWriteWithoutFormat ? "YES" : "NO");
401 printf("%sshaderUniformBufferArrayDynamicIndexing: %s\n", indent, features.shaderUniformBufferArrayDynamicIndexing ? "YES" : "NO");
402 printf("%sshaderSampledImageArrayDynamicIndexing: %s\n", indent, features.shaderSampledImageArrayDynamicIndexing ? "YES" : "NO");
403 printf("%sshaderStorageBufferArrayDynamicIndexing: %s\n", indent, features.shaderStorageBufferArrayDynamicIndexing ? "YES" : "NO");
404 printf("%sshaderStorageImageArrayDynamicIndexing: %s\n", indent, features.shaderStorageImageArrayDynamicIndexing ? "YES" : "NO");
405 printf("%sshaderClipDistance: %s\n", indent, features.shaderClipDistance ? "YES" : "NO");
406 printf("%sshaderCullDistance: %s\n", indent, features.shaderCullDistance ? "YES" : "NO");
407 printf("%sshaderFloat64: %s\n", indent, features.shaderFloat64 ? "YES" : "NO");
408 printf("%sshaderInt64: %s\n", indent, features.shaderInt64 ? "YES" : "NO");
409 printf("%sshaderInt16: %s\n", indent, features.shaderInt16 ? "YES" : "NO");
410 printf("%sshaderResourceResidency: %s\n", indent, features.shaderResourceResidency ? "YES" : "NO");
411 printf("%sshaderResourceMinLod: %s\n", indent, features.shaderResourceMinLod ? "YES" : "NO");
412 printf("%ssparseBinding: %s\n", indent, features.sparseBinding ? "YES" : "NO");
413 printf("%ssparseResidencyBuffer: %s\n", indent, features.sparseResidencyBuffer ? "YES" : "NO");
414 printf("%ssparseResidencyImage2D: %s\n", indent, features.sparseResidencyImage2D ? "YES" : "NO");
415 printf("%ssparseResidencyImage3D: %s\n", indent, features.sparseResidencyImage3D ? "YES" : "NO");
416 printf("%ssparseResidency2Samples: %s\n", indent, features.sparseResidency2Samples ? "YES" : "NO");
417 printf("%ssparseResidency4Samples: %s\n", indent, features.sparseResidency4Samples ? "YES" : "NO");
418 printf("%ssparseResidency8Samples: %s\n", indent, features.sparseResidency8Samples ? "YES" : "NO");
419 printf("%ssparseResidency16Samples: %s\n", indent, features.sparseResidency16Samples ? "YES" : "NO");
420 printf("%ssparseResidencyAliased: %s\n", indent, features.sparseResidencyAliased ? "YES" : "NO");
421 printf("%svariableMultisampleRate: %s\n", indent, features.variableMultisampleRate ? "YES" : "NO");
422 printf("%sinheritedQueries: %s\n", indent, features.inheritedQueries ? "YES" : "NO");
423 // clang-format on
424}
425
426void PrintSupportedFeatures(const char* indent,
427 const VkPhysicalDeviceFeatures& features) {
428 // clang-format off
429 if (features.robustBufferAccess) printf("%srobustBufferAccess\n", indent);
430 if (features.fullDrawIndexUint32) printf("%sfullDrawIndexUint32\n", indent);
431 if (features.imageCubeArray) printf("%simageCubeArray\n", indent);
432 if (features.independentBlend) printf("%sindependentBlend\n", indent);
433 if (features.geometryShader) printf("%sgeometryShader\n", indent);
434 if (features.tessellationShader) printf("%stessellationShader\n", indent);
435 if (features.sampleRateShading) printf("%ssampleRateShading\n", indent);
436 if (features.dualSrcBlend) printf("%sdualSrcBlend\n", indent);
437 if (features.logicOp) printf("%slogicOp\n", indent);
438 if (features.multiDrawIndirect) printf("%smultiDrawIndirect\n", indent);
439 if (features.drawIndirectFirstInstance) printf("%sdrawIndirectFirstInstance\n", indent);
440 if (features.depthClamp) printf("%sdepthClamp\n", indent);
441 if (features.depthBiasClamp) printf("%sdepthBiasClamp\n", indent);
442 if (features.fillModeNonSolid) printf("%sfillModeNonSolid\n", indent);
443 if (features.depthBounds) printf("%sdepthBounds\n", indent);
444 if (features.wideLines) printf("%swideLines\n", indent);
445 if (features.largePoints) printf("%slargePoints\n", indent);
446 if (features.alphaToOne) printf("%salphaToOne\n", indent);
447 if (features.multiViewport) printf("%smultiViewport\n", indent);
448 if (features.samplerAnisotropy) printf("%ssamplerAnisotropy\n", indent);
449 if (features.textureCompressionETC2) printf("%stextureCompressionETC2\n", indent);
450 if (features.textureCompressionASTC_LDR) printf("%stextureCompressionASTC_LDR\n", indent);
451 if (features.textureCompressionBC) printf("%stextureCompressionBC\n", indent);
452 if (features.occlusionQueryPrecise) printf("%socclusionQueryPrecise\n", indent);
453 if (features.pipelineStatisticsQuery) printf("%spipelineStatisticsQuery\n", indent);
454 if (features.vertexPipelineStoresAndAtomics) printf("%svertexPipelineStoresAndAtomics\n", indent);
455 if (features.fragmentStoresAndAtomics) printf("%sfragmentStoresAndAtomics\n", indent);
456 if (features.shaderTessellationAndGeometryPointSize) printf("%sshaderTessellationAndGeometryPointSize\n", indent);
457 if (features.shaderImageGatherExtended) printf("%sshaderImageGatherExtended\n", indent);
458 if (features.shaderStorageImageExtendedFormats) printf("%sshaderStorageImageExtendedFormats\n", indent);
459 if (features.shaderStorageImageMultisample) printf("%sshaderStorageImageMultisample\n", indent);
460 if (features.shaderStorageImageReadWithoutFormat) printf("%sshaderStorageImageReadWithoutFormat\n", indent);
461 if (features.shaderStorageImageWriteWithoutFormat) printf("%sshaderStorageImageWriteWithoutFormat\n", indent);
462 if (features.shaderUniformBufferArrayDynamicIndexing) printf("%sshaderUniformBufferArrayDynamicIndexing\n", indent);
463 if (features.shaderSampledImageArrayDynamicIndexing) printf("%sshaderSampledImageArrayDynamicIndexing\n", indent);
464 if (features.shaderStorageBufferArrayDynamicIndexing) printf("%sshaderStorageBufferArrayDynamicIndexing\n", indent);
465 if (features.shaderStorageImageArrayDynamicIndexing) printf("%sshaderStorageImageArrayDynamicIndexing\n", indent);
466 if (features.shaderClipDistance) printf("%sshaderClipDistance\n", indent);
467 if (features.shaderCullDistance) printf("%sshaderCullDistance\n", indent);
468 if (features.shaderFloat64) printf("%sshaderFloat64\n", indent);
469 if (features.shaderInt64) printf("%sshaderInt64\n", indent);
470 if (features.shaderInt16) printf("%sshaderInt16\n", indent);
471 if (features.shaderResourceResidency) printf("%sshaderResourceResidency\n", indent);
472 if (features.shaderResourceMinLod) printf("%sshaderResourceMinLod\n", indent);
473 if (features.sparseBinding) printf("%ssparseBinding\n", indent);
474 if (features.sparseResidencyBuffer) printf("%ssparseResidencyBuffer\n", indent);
475 if (features.sparseResidencyImage2D) printf("%ssparseResidencyImage2D\n", indent);
476 if (features.sparseResidencyImage3D) printf("%ssparseResidencyImage3D\n", indent);
477 if (features.sparseResidency2Samples) printf("%ssparseResidency2Samples\n", indent);
478 if (features.sparseResidency4Samples) printf("%ssparseResidency4Samples\n", indent);
479 if (features.sparseResidency8Samples) printf("%ssparseResidency8Samples\n", indent);
480 if (features.sparseResidency16Samples) printf("%ssparseResidency16Samples\n", indent);
481 if (features.sparseResidencyAliased) printf("%ssparseResidencyAliased\n", indent);
482 if (features.variableMultisampleRate) printf("%svariableMultisampleRate\n", indent);
483 if (features.inheritedQueries) printf("%sinheritedQueries\n", indent);
484 // clang-format on
485}
486
Jesse Hall38cb8402016-01-18 03:41:35 -0800487void PrintGpuInfo(const GpuInfo& info, const Options& options, size_t indent) {
Jesse Hall04f4f472015-08-16 19:51:04 -0700488 VkResult result;
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100489 std::ostringstream strbuf;
Jesse Hall04f4f472015-08-16 19:51:04 -0700490
Jesse Hall38cb8402016-01-18 03:41:35 -0800491 printf("%s\"%s\" (%s) %u.%u.%u/%#x [%04x:%04x]\n", Indent(indent),
Jesse Hall09559b52016-01-07 21:50:19 -0800492 info.properties.deviceName,
493 VkPhysicalDeviceTypeStr(info.properties.deviceType),
494 ExtractMajorVersion(info.properties.apiVersion),
495 ExtractMinorVersion(info.properties.apiVersion),
496 ExtractPatchVersion(info.properties.apiVersion),
497 info.properties.driverVersion, info.properties.vendorID,
498 info.properties.deviceID);
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100499
Jesse Hall09559b52016-01-07 21:50:19 -0800500 for (uint32_t heap = 0; heap < info.memory.memoryHeapCount; heap++) {
501 if ((info.memory.memoryHeaps[heap].flags &
Jesse Halld1af8122015-11-29 23:50:38 -0800502 VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0)
503 strbuf << "DEVICE_LOCAL";
Jesse Hall38cb8402016-01-18 03:41:35 -0800504 printf("%sHeap %u: %" PRIu64 " MiB (0x%" PRIx64 " B) %s\n",
505 Indent(indent + 1), heap,
Jesse Hall00f10fe2016-02-08 21:20:20 -0800506 info.memory.memoryHeaps[heap].size / 0x100000,
Jesse Hall09559b52016-01-07 21:50:19 -0800507 info.memory.memoryHeaps[heap].size, strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100508 strbuf.str(std::string());
509
Jesse Hall09559b52016-01-07 21:50:19 -0800510 for (uint32_t type = 0; type < info.memory.memoryTypeCount; type++) {
511 if (info.memory.memoryTypes[type].heapIndex != heap)
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100512 continue;
513 VkMemoryPropertyFlags flags =
Jesse Hall09559b52016-01-07 21:50:19 -0800514 info.memory.memoryTypes[type].propertyFlags;
Jesse Halld1af8122015-11-29 23:50:38 -0800515 if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
Jesse Hall1f91d392015-12-11 16:28:44 -0800516 strbuf << " DEVICE_LOCAL";
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100517 if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
Jesse Hall1f91d392015-12-11 16:28:44 -0800518 strbuf << " HOST_VISIBLE";
Jesse Halld1af8122015-11-29 23:50:38 -0800519 if ((flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0)
520 strbuf << " COHERENT";
521 if ((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0)
522 strbuf << " CACHED";
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100523 if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
524 strbuf << " LAZILY_ALLOCATED";
Jesse Hall38cb8402016-01-18 03:41:35 -0800525 printf("%sType %u:%s\n", Indent(indent + 2), type,
526 strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100527 strbuf.str(std::string());
528 }
529 }
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700530
Jesse Hall09559b52016-01-07 21:50:19 -0800531 for (uint32_t family = 0; family < info.queue_families.size(); family++) {
532 const VkQueueFamilyProperties& qprops = info.queue_families[family];
Jesse Hall8966bf42016-01-16 17:26:48 -0800533 VkQueueFlags flags = qprops.queueFlags;
534 char flags_str[5];
535 flags_str[0] = (flags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '_';
536 flags_str[1] = (flags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '_';
537 flags_str[2] = (flags & VK_QUEUE_TRANSFER_BIT) ? 'T' : '_';
538 flags_str[3] = (flags & VK_QUEUE_SPARSE_BINDING_BIT) ? 'S' : '_';
539 flags_str[4] = '\0';
540 printf(
Jesse Hall38cb8402016-01-18 03:41:35 -0800541 "%sQueue Family %u: %ux %s\n"
542 "%stimestampValidBits: %ub\n"
543 "%sminImageTransferGranularity: (%u,%u,%u)\n",
544 Indent(indent + 1), family, qprops.queueCount, flags_str,
545 Indent(indent + 2), qprops.timestampValidBits, Indent(indent + 2),
Jesse Hall8966bf42016-01-16 17:26:48 -0800546 qprops.minImageTransferGranularity.width,
547 qprops.minImageTransferGranularity.height,
548 qprops.minImageTransferGranularity.depth);
Jesse Hallb1471272016-01-17 21:36:58 -0800549 }
Jesse Hall6e4ab312016-01-07 22:26:20 -0800550
Jesse Hallc5cec282016-01-18 04:01:10 -0800551 printf("%sFeatures:\n", Indent(indent + 1));
Jesse Hallf63e4452016-02-08 21:22:23 -0800552 if (options.unsupported_features) {
553 PrintAllFeatures(Indent(indent + 2), info.features);
554 } else {
555 PrintSupportedFeatures(Indent(indent + 2), info.features);
556 }
Jesse Hallc5cec282016-01-18 04:01:10 -0800557
Jesse Hall38cb8402016-01-18 03:41:35 -0800558 printf("%sExtensions [%zu]:\n", Indent(indent + 1), info.extensions.size());
559 if (!info.extensions.empty())
560 PrintExtensions(info.extensions, options, indent + 2);
561 printf("%sLayers [%zu]:\n", Indent(indent + 1), info.layers.size());
562 if (!info.layers.empty())
563 PrintLayers(info.layers, info.layer_extensions, options, indent + 2);
Jesse Hall04f4f472015-08-16 19:51:04 -0700564}
565
Jesse Hall38cb8402016-01-18 03:41:35 -0800566void PrintInfo(const VulkanInfo& info, const Options& options) {
Jesse Hall09559b52016-01-07 21:50:19 -0800567 std::ostringstream strbuf;
Jesse Hall38cb8402016-01-18 03:41:35 -0800568 size_t indent = 0;
Jesse Hall09559b52016-01-07 21:50:19 -0800569
Jesse Hall38cb8402016-01-18 03:41:35 -0800570 printf("%sInstance Extensions [%zu]:\n", Indent(indent),
571 info.extensions.size());
572 PrintExtensions(info.extensions, options, indent + 1);
573 printf("%sInstance Layers [%zu]:\n", Indent(indent), info.layers.size());
574 if (!info.layers.empty())
575 PrintLayers(info.layers, info.layer_extensions, options, indent + 1);
Jesse Hall09559b52016-01-07 21:50:19 -0800576
Jesse Hall38cb8402016-01-18 03:41:35 -0800577 printf("%sPhysicalDevices [%zu]:\n", Indent(indent), info.gpus.size());
Jesse Hall09559b52016-01-07 21:50:19 -0800578 for (const auto& gpu : info.gpus)
Jesse Hall38cb8402016-01-18 03:41:35 -0800579 PrintGpuInfo(gpu, options, indent + 1);
Jesse Hallc1ab3032016-01-04 07:26:53 -0800580}
581
Jesse Hallf63e4452016-02-08 21:22:23 -0800582const char kUsageString[] =
583 "usage: vkinfo [options]\n"
584 " -v enable all the following verbose options\n"
585 " -layer_description print layer description strings\n"
586 " -layer_extensions print extensions supported by each layer\n"
587 " -unsupported_features print all physical device features\n"
588 " -validate enable validation layers if present\n"
589 " -debug_pause pause at start until resumed via debugger\n";
590
Jesse Hall04f4f472015-08-16 19:51:04 -0700591} // namespace
592
Jesse Hall09559b52016-01-07 21:50:19 -0800593// ----------------------------------------------------------------------------
594
Jesse Hall38cb8402016-01-18 03:41:35 -0800595int main(int argc, char const* argv[]) {
Courtney Goeltzenleuchterc2a77092016-02-08 20:31:46 -0700596 static volatile bool startup_pause = false;
Jesse Hall38cb8402016-01-18 03:41:35 -0800597 Options options = {
598 .layer_description = false, .layer_extensions = false,
Jesse Hallf63e4452016-02-08 21:22:23 -0800599 .unsupported_features = false,
Chia-I Wud0bba372016-02-22 11:41:27 +0800600 .validate = false,
Jesse Hall38cb8402016-01-18 03:41:35 -0800601 };
602 for (int argi = 1; argi < argc; argi++) {
Jesse Hallf63e4452016-02-08 21:22:23 -0800603 if (strcmp(argv[argi], "-h") == 0) {
604 fputs(kUsageString, stdout);
605 return 0;
606 }
Jesse Hall38cb8402016-01-18 03:41:35 -0800607 if (strcmp(argv[argi], "-v") == 0) {
608 options.layer_description = true;
609 options.layer_extensions = true;
Jesse Hallf63e4452016-02-08 21:22:23 -0800610 options.unsupported_features = true;
Jesse Hall38cb8402016-01-18 03:41:35 -0800611 } else if (strcmp(argv[argi], "-layer_description") == 0) {
612 options.layer_description = true;
613 } else if (strcmp(argv[argi], "-layer_extensions") == 0) {
614 options.layer_extensions = true;
Jesse Hallf63e4452016-02-08 21:22:23 -0800615 } else if (strcmp(argv[argi], "-unsupported_features") == 0) {
616 options.unsupported_features = true;
Chia-I Wud0bba372016-02-22 11:41:27 +0800617 } else if (strcmp(argv[argi], "-validate") == 0) {
618 options.validate = true;
Courtney Goeltzenleuchterc2a77092016-02-08 20:31:46 -0700619 } else if (strcmp(argv[argi], "-debug_pause") == 0) {
620 startup_pause = true;
Jesse Hall38cb8402016-01-18 03:41:35 -0800621 }
622 }
623
Courtney Goeltzenleuchterc2a77092016-02-08 20:31:46 -0700624 while (startup_pause) {
625 sleep(0);
626 }
627
Jesse Hallc1ab3032016-01-04 07:26:53 -0800628 VulkanInfo info;
Chia-I Wud0bba372016-02-22 11:41:27 +0800629 GatherInfo(&info, options);
Jesse Hall38cb8402016-01-18 03:41:35 -0800630 PrintInfo(info, options);
Jesse Hall04f4f472015-08-16 19:51:04 -0700631 return 0;
632}