blob: 066563adde64be7d13affc1b07f769a00480ba78 [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>
25
26#define LOG_TAG "vkinfo"
27#include <log/log.h>
28
29namespace {
30
Chia-I Wud0bba372016-02-22 11:41:27 +080031struct Options {
32 bool layer_description;
33 bool layer_extensions;
Jesse Hallf63e4452016-02-08 21:22:23 -080034 bool unsupported_features;
Chia-I Wud0bba372016-02-22 11:41:27 +080035 bool validate;
36};
37
Jesse Hall09559b52016-01-07 21:50:19 -080038struct GpuInfo {
39 VkPhysicalDeviceProperties properties;
40 VkPhysicalDeviceMemoryProperties memory;
Jesse Hallb1471272016-01-17 21:36:58 -080041 VkPhysicalDeviceFeatures features;
Jesse Hall09559b52016-01-07 21:50:19 -080042 std::vector<VkQueueFamilyProperties> queue_families;
Jesse Hall6e4ab312016-01-07 22:26:20 -080043 std::vector<VkExtensionProperties> extensions;
44 std::vector<VkLayerProperties> layers;
45 std::vector<std::vector<VkExtensionProperties>> layer_extensions;
Jesse Hall09559b52016-01-07 21:50:19 -080046};
47struct 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 Hall04f4f472015-08-16 19:51:04 -070056[[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 Hall04f4f472015-08-16 19:51:04 -070061 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 Hall04f4f472015-08-16 19:51:04 -070066 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 Hall5ae3abb2015-10-08 14:00:22 -070068 case VK_ERROR_INITIALIZATION_FAILED: result_str = "VK_ERROR_INITIALIZATION_FAILED"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070069 case VK_ERROR_DEVICE_LOST: result_str = "VK_ERROR_DEVICE_LOST"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070070 case VK_ERROR_MEMORY_MAP_FAILED: result_str = "VK_ERROR_MEMORY_MAP_FAILED"; break;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070071 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 Hall04f4f472015-08-16 19:51:04 -070073 case VK_ERROR_INCOMPATIBLE_DRIVER: result_str = "VK_ERROR_INCOMPATIBLE_DRIVER"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070074 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 Hall4da3bd62016-01-16 22:14:40 -080081bool 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 Hall09559b52016-01-07 21:50:19 -080089void 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 Hall6e4ab312016-01-07 22:26:20 -0800107void 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 Wud0bba372016-02-22 11:41:27 +0800125void GatherGpuInfo(VkPhysicalDevice gpu,
126 const Options &options,
127 GpuInfo& info) {
Jesse Hallb1471272016-01-17 21:36:58 -0800128 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);
Chia-I Wu8955f3f2016-04-22 06:06:04 +0800165 if (options.validate) {
166 for (size_t i = 0; !available && i < info.layer_extensions.size();
167 i++)
168 available = HasExtension(info.layer_extensions[i], desired_ext);
169 }
Jesse Hallb1471272016-01-17 21:36:58 -0800170 if (available)
171 extensions[num_extensions++] = desired_ext;
172 }
173
174 VkDevice device;
Courtney Goeltzenleuchterca472ab2016-02-01 20:09:00 -0700175 float queue_priorities[] = {0.0};
Jesse Hallb1471272016-01-17 21:36:58 -0800176 const VkDeviceQueueCreateInfo queue_create_info = {
177 .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
178 .queueFamilyIndex = 0,
179 .queueCount = 1,
Courtney Goeltzenleuchterca472ab2016-02-01 20:09:00 -0700180 queue_priorities
Jesse Hallb1471272016-01-17 21:36:58 -0800181 };
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700182 // clang-format off
183 const char *kValidationLayers[] = {
184 "VK_LAYER_GOOGLE_threading",
185 "VK_LAYER_LUNARG_device_limits",
186 "VK_LAYER_LUNARG_draw_state",
187 "VK_LAYER_LUNARG_image",
188 "VK_LAYER_LUNARG_mem_tracker",
189 "VK_LAYER_LUNARG_object_tracker",
190 "VK_LAYER_LUNARG_param_checker",
191 "VK_LAYER_LUNARG_swapchain",
192 "VK_LAYER_GOOGLE_unique_objects"
193 };
194 // clang-format on
195 uint32_t num_layers = sizeof(kValidationLayers) / sizeof(char*);
Jesse Hallb1471272016-01-17 21:36:58 -0800196 const VkDeviceCreateInfo create_info = {
197 .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
198 .queueCreateInfoCount = 1,
199 .pQueueCreateInfos = &queue_create_info,
200 .enabledExtensionCount = num_extensions,
201 .ppEnabledExtensionNames = extensions,
Chia-I Wud0bba372016-02-22 11:41:27 +0800202 .enabledLayerCount = (options.validate) ? num_layers : 0,
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700203 .ppEnabledLayerNames = kValidationLayers,
Jesse Hallb1471272016-01-17 21:36:58 -0800204 .pEnabledFeatures = &info.features,
205 };
206 result = vkCreateDevice(gpu, &create_info, nullptr, &device);
207 if (result != VK_SUCCESS)
208 die("vkCreateDevice", result);
209 vkDestroyDevice(device, nullptr);
210}
211
Chia-I Wud0bba372016-02-22 11:41:27 +0800212void GatherInfo(VulkanInfo* info, const Options& options) {
Jesse Hall09559b52016-01-07 21:50:19 -0800213 VkResult result;
214 uint32_t count;
215
216 result = vkEnumerateInstanceLayerProperties(&count, nullptr);
217 if (result != VK_SUCCESS)
218 die("vkEnumerateInstanceLayerProperties (count)", result);
219 do {
220 info->layers.resize(count);
221 result =
222 vkEnumerateInstanceLayerProperties(&count, info->layers.data());
223 } while (result == VK_INCOMPLETE);
224 if (result != VK_SUCCESS)
225 die("vkEnumerateInstanceLayerProperties (data)", result);
226 info->layer_extensions.resize(info->layers.size());
227
228 EnumerateInstanceExtensions(nullptr, &info->extensions);
229 for (size_t i = 0; i < info->layers.size(); i++) {
230 EnumerateInstanceExtensions(info->layers[i].layerName,
231 &info->layer_extensions[i]);
232 }
233
Jesse Hallae3b70d2016-01-17 22:05:29 -0800234 const char* kDesiredExtensions[] = {
235 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Jesse Hall4da3bd62016-01-16 22:14:40 -0800236 };
Jesse Hallae3b70d2016-01-17 22:05:29 -0800237 const char*
238 extensions[sizeof(kDesiredExtensions) / sizeof(kDesiredExtensions[0])];
Jesse Hall4da3bd62016-01-16 22:14:40 -0800239 uint32_t num_extensions = 0;
240 for (const auto& desired_ext : kDesiredExtensions) {
241 bool available = HasExtension(info->extensions, desired_ext);
Chia-I Wu8955f3f2016-04-22 06:06:04 +0800242 if (options.validate) {
243 for (size_t i = 0; !available && i < info->layer_extensions.size();
244 i++)
245 available =
246 HasExtension(info->layer_extensions[i], desired_ext);
247 }
Jesse Hall4da3bd62016-01-16 22:14:40 -0800248 if (available)
249 extensions[num_extensions++] = desired_ext;
250 }
251
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700252 // clang-format off
253 const char *kValidationLayers[] = {
254 "VK_LAYER_GOOGLE_threading",
255 "VK_LAYER_LUNARG_device_limits",
256 "VK_LAYER_LUNARG_draw_state",
257 "VK_LAYER_LUNARG_image",
258 "VK_LAYER_LUNARG_mem_tracker",
259 "VK_LAYER_LUNARG_object_tracker",
260 "VK_LAYER_LUNARG_param_checker",
261 "VK_LAYER_LUNARG_swapchain",
262 "VK_LAYER_GOOGLE_unique_objects"
263 };
264 // clang-format on
265 uint32_t num_layers = sizeof(kValidationLayers) / sizeof(char*);
266
Jesse Halldc7f6a62016-02-24 16:44:42 -0800267 const VkApplicationInfo application_info = {
268 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
269 .pApplicationName = "vkinfo",
270 .applicationVersion = 0,
271 .pEngineName = "vkinfo",
272 .engineVersion = 0,
273 .apiVersion = VK_API_VERSION,
274 };
Jesse Hall09559b52016-01-07 21:50:19 -0800275 const VkInstanceCreateInfo create_info = {
276 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
Jesse Halldc7f6a62016-02-24 16:44:42 -0800277 .pApplicationInfo = &application_info,
Jesse Hall4da3bd62016-01-16 22:14:40 -0800278 .enabledExtensionCount = num_extensions,
279 .ppEnabledExtensionNames = extensions,
Chia-I Wud0bba372016-02-22 11:41:27 +0800280 .enabledLayerCount = (options.validate) ? num_layers : 0,
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700281 .ppEnabledLayerNames = kValidationLayers,
Jesse Hall09559b52016-01-07 21:50:19 -0800282 };
Jesse Hall4da3bd62016-01-16 22:14:40 -0800283 VkInstance instance;
Jesse Hall09559b52016-01-07 21:50:19 -0800284 result = vkCreateInstance(&create_info, nullptr, &instance);
285 if (result != VK_SUCCESS)
286 die("vkCreateInstance", result);
287
288 uint32_t num_gpus;
289 result = vkEnumeratePhysicalDevices(instance, &num_gpus, nullptr);
290 if (result != VK_SUCCESS)
291 die("vkEnumeratePhysicalDevices (count)", result);
292 std::vector<VkPhysicalDevice> gpus(num_gpus, VK_NULL_HANDLE);
293 do {
294 gpus.resize(num_gpus, VK_NULL_HANDLE);
295 result = vkEnumeratePhysicalDevices(instance, &num_gpus, gpus.data());
296 } while (result == VK_INCOMPLETE);
297 if (result != VK_SUCCESS)
298 die("vkEnumeratePhysicalDevices (data)", result);
299
300 info->gpus.resize(num_gpus);
Jesse Hallb1471272016-01-17 21:36:58 -0800301 for (size_t i = 0; i < gpus.size(); i++)
Chia-I Wud0bba372016-02-22 11:41:27 +0800302 GatherGpuInfo(gpus[i], options, info->gpus.at(i));
Jesse Hall09559b52016-01-07 21:50:19 -0800303
304 vkDestroyInstance(instance, nullptr);
305}
306
307// ----------------------------------------------------------------------------
308
Jesse Hall38cb8402016-01-18 03:41:35 -0800309const size_t kMaxIndent = 8;
310const size_t kIndentSize = 3;
311std::array<char, kMaxIndent * kIndentSize + 1> kIndent;
312const char* Indent(size_t n) {
313 static bool initialized = false;
314 if (!initialized) {
315 kIndent.fill(' ');
316 kIndent.back() = '\0';
317 initialized = true;
318 }
319 return kIndent.data() +
320 (kIndent.size() - (kIndentSize * std::min(n, kMaxIndent) + 1));
321}
322
Jesse Hall04f4f472015-08-16 19:51:04 -0700323const char* VkPhysicalDeviceTypeStr(VkPhysicalDeviceType type) {
324 switch (type) {
325 case VK_PHYSICAL_DEVICE_TYPE_OTHER:
326 return "OTHER";
327 case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
328 return "INTEGRATED_GPU";
329 case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
330 return "DISCRETE_GPU";
331 case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
332 return "VIRTUAL_GPU";
333 case VK_PHYSICAL_DEVICE_TYPE_CPU:
334 return "CPU";
335 default:
336 return "<UNKNOWN>";
337 }
338}
339
Jesse Hall09559b52016-01-07 21:50:19 -0800340void PrintExtensions(const std::vector<VkExtensionProperties>& extensions,
Jesse Hall38cb8402016-01-18 03:41:35 -0800341 const Options& /*options*/,
342 size_t indent) {
Jesse Hall09559b52016-01-07 21:50:19 -0800343 for (const auto& e : extensions)
Jesse Hall38cb8402016-01-18 03:41:35 -0800344 printf("%s%s (v%u)\n", Indent(indent), e.extensionName, e.specVersion);
Jesse Hall09559b52016-01-07 21:50:19 -0800345}
Jesse Hallc1ab3032016-01-04 07:26:53 -0800346
Jesse Hallaa410942016-01-17 13:07:10 -0800347void PrintLayers(
348 const std::vector<VkLayerProperties>& layers,
349 const std::vector<std::vector<VkExtensionProperties>> extensions,
Jesse Hall38cb8402016-01-18 03:41:35 -0800350 const Options& options,
351 size_t indent) {
Jesse Hallaa410942016-01-17 13:07:10 -0800352 for (size_t i = 0; i < layers.size(); i++) {
Jesse Hall38cb8402016-01-18 03:41:35 -0800353 printf("%s%s %u.%u.%u/%u\n", Indent(indent), layers[i].layerName,
Jesse Halle2948d82016-02-25 04:19:32 -0800354 VK_VERSION_MAJOR(layers[i].specVersion),
355 VK_VERSION_MINOR(layers[i].specVersion),
356 VK_VERSION_PATCH(layers[i].specVersion),
Jesse Hall38cb8402016-01-18 03:41:35 -0800357 layers[i].implementationVersion);
358 if (options.layer_description)
359 printf("%s%s\n", Indent(indent + 1), layers[i].description);
360 if (options.layer_extensions && !extensions[i].empty()) {
361 if (!extensions[i].empty()) {
362 printf("%sExtensions [%zu]:\n", Indent(indent + 1),
363 extensions[i].size());
364 PrintExtensions(extensions[i], options, indent + 2);
365 }
366 }
Jesse Hallaa410942016-01-17 13:07:10 -0800367 }
368}
369
Jesse Hallf63e4452016-02-08 21:22:23 -0800370void PrintAllFeatures(const char* indent,
371 const VkPhysicalDeviceFeatures& features) {
372 // clang-format off
373 printf("%srobustBufferAccess: %s\n", indent, features.robustBufferAccess ? "YES" : "NO");
374 printf("%sfullDrawIndexUint32: %s\n", indent, features.fullDrawIndexUint32 ? "YES" : "NO");
375 printf("%simageCubeArray: %s\n", indent, features.imageCubeArray ? "YES" : "NO");
376 printf("%sindependentBlend: %s\n", indent, features.independentBlend ? "YES" : "NO");
377 printf("%sgeometryShader: %s\n", indent, features.geometryShader ? "YES" : "NO");
378 printf("%stessellationShader: %s\n", indent, features.tessellationShader ? "YES" : "NO");
379 printf("%ssampleRateShading: %s\n", indent, features.sampleRateShading ? "YES" : "NO");
380 printf("%sdualSrcBlend: %s\n", indent, features.dualSrcBlend ? "YES" : "NO");
381 printf("%slogicOp: %s\n", indent, features.logicOp ? "YES" : "NO");
382 printf("%smultiDrawIndirect: %s\n", indent, features.multiDrawIndirect ? "YES" : "NO");
383 printf("%sdrawIndirectFirstInstance: %s\n", indent, features.drawIndirectFirstInstance ? "YES" : "NO");
384 printf("%sdepthClamp: %s\n", indent, features.depthClamp ? "YES" : "NO");
385 printf("%sdepthBiasClamp: %s\n", indent, features.depthBiasClamp ? "YES" : "NO");
386 printf("%sfillModeNonSolid: %s\n", indent, features.fillModeNonSolid ? "YES" : "NO");
387 printf("%sdepthBounds: %s\n", indent, features.depthBounds ? "YES" : "NO");
388 printf("%swideLines: %s\n", indent, features.wideLines ? "YES" : "NO");
389 printf("%slargePoints: %s\n", indent, features.largePoints ? "YES" : "NO");
390 printf("%salphaToOne: %s\n", indent, features.alphaToOne ? "YES" : "NO");
391 printf("%smultiViewport: %s\n", indent, features.multiViewport ? "YES" : "NO");
392 printf("%ssamplerAnisotropy: %s\n", indent, features.samplerAnisotropy ? "YES" : "NO");
393 printf("%stextureCompressionETC2: %s\n", indent, features.textureCompressionETC2 ? "YES" : "NO");
394 printf("%stextureCompressionASTC_LDR: %s\n", indent, features.textureCompressionASTC_LDR ? "YES" : "NO");
395 printf("%stextureCompressionBC: %s\n", indent, features.textureCompressionBC ? "YES" : "NO");
396 printf("%socclusionQueryPrecise: %s\n", indent, features.occlusionQueryPrecise ? "YES" : "NO");
397 printf("%spipelineStatisticsQuery: %s\n", indent, features.pipelineStatisticsQuery ? "YES" : "NO");
398 printf("%svertexPipelineStoresAndAtomics: %s\n", indent, features.vertexPipelineStoresAndAtomics ? "YES" : "NO");
399 printf("%sfragmentStoresAndAtomics: %s\n", indent, features.fragmentStoresAndAtomics ? "YES" : "NO");
400 printf("%sshaderTessellationAndGeometryPointSize: %s\n", indent, features.shaderTessellationAndGeometryPointSize ? "YES" : "NO");
401 printf("%sshaderImageGatherExtended: %s\n", indent, features.shaderImageGatherExtended ? "YES" : "NO");
402 printf("%sshaderStorageImageExtendedFormats: %s\n", indent, features.shaderStorageImageExtendedFormats ? "YES" : "NO");
403 printf("%sshaderStorageImageMultisample: %s\n", indent, features.shaderStorageImageMultisample ? "YES" : "NO");
404 printf("%sshaderStorageImageReadWithoutFormat: %s\n", indent, features.shaderStorageImageReadWithoutFormat ? "YES" : "NO");
405 printf("%sshaderStorageImageWriteWithoutFormat: %s\n", indent, features.shaderStorageImageWriteWithoutFormat ? "YES" : "NO");
406 printf("%sshaderUniformBufferArrayDynamicIndexing: %s\n", indent, features.shaderUniformBufferArrayDynamicIndexing ? "YES" : "NO");
407 printf("%sshaderSampledImageArrayDynamicIndexing: %s\n", indent, features.shaderSampledImageArrayDynamicIndexing ? "YES" : "NO");
408 printf("%sshaderStorageBufferArrayDynamicIndexing: %s\n", indent, features.shaderStorageBufferArrayDynamicIndexing ? "YES" : "NO");
409 printf("%sshaderStorageImageArrayDynamicIndexing: %s\n", indent, features.shaderStorageImageArrayDynamicIndexing ? "YES" : "NO");
410 printf("%sshaderClipDistance: %s\n", indent, features.shaderClipDistance ? "YES" : "NO");
411 printf("%sshaderCullDistance: %s\n", indent, features.shaderCullDistance ? "YES" : "NO");
412 printf("%sshaderFloat64: %s\n", indent, features.shaderFloat64 ? "YES" : "NO");
413 printf("%sshaderInt64: %s\n", indent, features.shaderInt64 ? "YES" : "NO");
414 printf("%sshaderInt16: %s\n", indent, features.shaderInt16 ? "YES" : "NO");
415 printf("%sshaderResourceResidency: %s\n", indent, features.shaderResourceResidency ? "YES" : "NO");
416 printf("%sshaderResourceMinLod: %s\n", indent, features.shaderResourceMinLod ? "YES" : "NO");
417 printf("%ssparseBinding: %s\n", indent, features.sparseBinding ? "YES" : "NO");
418 printf("%ssparseResidencyBuffer: %s\n", indent, features.sparseResidencyBuffer ? "YES" : "NO");
419 printf("%ssparseResidencyImage2D: %s\n", indent, features.sparseResidencyImage2D ? "YES" : "NO");
420 printf("%ssparseResidencyImage3D: %s\n", indent, features.sparseResidencyImage3D ? "YES" : "NO");
421 printf("%ssparseResidency2Samples: %s\n", indent, features.sparseResidency2Samples ? "YES" : "NO");
422 printf("%ssparseResidency4Samples: %s\n", indent, features.sparseResidency4Samples ? "YES" : "NO");
423 printf("%ssparseResidency8Samples: %s\n", indent, features.sparseResidency8Samples ? "YES" : "NO");
424 printf("%ssparseResidency16Samples: %s\n", indent, features.sparseResidency16Samples ? "YES" : "NO");
425 printf("%ssparseResidencyAliased: %s\n", indent, features.sparseResidencyAliased ? "YES" : "NO");
426 printf("%svariableMultisampleRate: %s\n", indent, features.variableMultisampleRate ? "YES" : "NO");
427 printf("%sinheritedQueries: %s\n", indent, features.inheritedQueries ? "YES" : "NO");
428 // clang-format on
429}
430
431void PrintSupportedFeatures(const char* indent,
432 const VkPhysicalDeviceFeatures& features) {
433 // clang-format off
434 if (features.robustBufferAccess) printf("%srobustBufferAccess\n", indent);
435 if (features.fullDrawIndexUint32) printf("%sfullDrawIndexUint32\n", indent);
436 if (features.imageCubeArray) printf("%simageCubeArray\n", indent);
437 if (features.independentBlend) printf("%sindependentBlend\n", indent);
438 if (features.geometryShader) printf("%sgeometryShader\n", indent);
439 if (features.tessellationShader) printf("%stessellationShader\n", indent);
440 if (features.sampleRateShading) printf("%ssampleRateShading\n", indent);
441 if (features.dualSrcBlend) printf("%sdualSrcBlend\n", indent);
442 if (features.logicOp) printf("%slogicOp\n", indent);
443 if (features.multiDrawIndirect) printf("%smultiDrawIndirect\n", indent);
444 if (features.drawIndirectFirstInstance) printf("%sdrawIndirectFirstInstance\n", indent);
445 if (features.depthClamp) printf("%sdepthClamp\n", indent);
446 if (features.depthBiasClamp) printf("%sdepthBiasClamp\n", indent);
447 if (features.fillModeNonSolid) printf("%sfillModeNonSolid\n", indent);
448 if (features.depthBounds) printf("%sdepthBounds\n", indent);
449 if (features.wideLines) printf("%swideLines\n", indent);
450 if (features.largePoints) printf("%slargePoints\n", indent);
451 if (features.alphaToOne) printf("%salphaToOne\n", indent);
452 if (features.multiViewport) printf("%smultiViewport\n", indent);
453 if (features.samplerAnisotropy) printf("%ssamplerAnisotropy\n", indent);
454 if (features.textureCompressionETC2) printf("%stextureCompressionETC2\n", indent);
455 if (features.textureCompressionASTC_LDR) printf("%stextureCompressionASTC_LDR\n", indent);
456 if (features.textureCompressionBC) printf("%stextureCompressionBC\n", indent);
457 if (features.occlusionQueryPrecise) printf("%socclusionQueryPrecise\n", indent);
458 if (features.pipelineStatisticsQuery) printf("%spipelineStatisticsQuery\n", indent);
459 if (features.vertexPipelineStoresAndAtomics) printf("%svertexPipelineStoresAndAtomics\n", indent);
460 if (features.fragmentStoresAndAtomics) printf("%sfragmentStoresAndAtomics\n", indent);
461 if (features.shaderTessellationAndGeometryPointSize) printf("%sshaderTessellationAndGeometryPointSize\n", indent);
462 if (features.shaderImageGatherExtended) printf("%sshaderImageGatherExtended\n", indent);
463 if (features.shaderStorageImageExtendedFormats) printf("%sshaderStorageImageExtendedFormats\n", indent);
464 if (features.shaderStorageImageMultisample) printf("%sshaderStorageImageMultisample\n", indent);
465 if (features.shaderStorageImageReadWithoutFormat) printf("%sshaderStorageImageReadWithoutFormat\n", indent);
466 if (features.shaderStorageImageWriteWithoutFormat) printf("%sshaderStorageImageWriteWithoutFormat\n", indent);
467 if (features.shaderUniformBufferArrayDynamicIndexing) printf("%sshaderUniformBufferArrayDynamicIndexing\n", indent);
468 if (features.shaderSampledImageArrayDynamicIndexing) printf("%sshaderSampledImageArrayDynamicIndexing\n", indent);
469 if (features.shaderStorageBufferArrayDynamicIndexing) printf("%sshaderStorageBufferArrayDynamicIndexing\n", indent);
470 if (features.shaderStorageImageArrayDynamicIndexing) printf("%sshaderStorageImageArrayDynamicIndexing\n", indent);
471 if (features.shaderClipDistance) printf("%sshaderClipDistance\n", indent);
472 if (features.shaderCullDistance) printf("%sshaderCullDistance\n", indent);
473 if (features.shaderFloat64) printf("%sshaderFloat64\n", indent);
474 if (features.shaderInt64) printf("%sshaderInt64\n", indent);
475 if (features.shaderInt16) printf("%sshaderInt16\n", indent);
476 if (features.shaderResourceResidency) printf("%sshaderResourceResidency\n", indent);
477 if (features.shaderResourceMinLod) printf("%sshaderResourceMinLod\n", indent);
478 if (features.sparseBinding) printf("%ssparseBinding\n", indent);
479 if (features.sparseResidencyBuffer) printf("%ssparseResidencyBuffer\n", indent);
480 if (features.sparseResidencyImage2D) printf("%ssparseResidencyImage2D\n", indent);
481 if (features.sparseResidencyImage3D) printf("%ssparseResidencyImage3D\n", indent);
482 if (features.sparseResidency2Samples) printf("%ssparseResidency2Samples\n", indent);
483 if (features.sparseResidency4Samples) printf("%ssparseResidency4Samples\n", indent);
484 if (features.sparseResidency8Samples) printf("%ssparseResidency8Samples\n", indent);
485 if (features.sparseResidency16Samples) printf("%ssparseResidency16Samples\n", indent);
486 if (features.sparseResidencyAliased) printf("%ssparseResidencyAliased\n", indent);
487 if (features.variableMultisampleRate) printf("%svariableMultisampleRate\n", indent);
488 if (features.inheritedQueries) printf("%sinheritedQueries\n", indent);
489 // clang-format on
490}
491
Jesse Hall38cb8402016-01-18 03:41:35 -0800492void PrintGpuInfo(const GpuInfo& info, const Options& options, size_t indent) {
Jesse Hall04f4f472015-08-16 19:51:04 -0700493 VkResult result;
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100494 std::ostringstream strbuf;
Jesse Hall04f4f472015-08-16 19:51:04 -0700495
Jesse Hall38cb8402016-01-18 03:41:35 -0800496 printf("%s\"%s\" (%s) %u.%u.%u/%#x [%04x:%04x]\n", Indent(indent),
Jesse Hall09559b52016-01-07 21:50:19 -0800497 info.properties.deviceName,
498 VkPhysicalDeviceTypeStr(info.properties.deviceType),
Jesse Halle2948d82016-02-25 04:19:32 -0800499 VK_VERSION_MAJOR(info.properties.apiVersion),
500 VK_VERSION_MINOR(info.properties.apiVersion),
501 VK_VERSION_PATCH(info.properties.apiVersion),
Jesse Hall09559b52016-01-07 21:50:19 -0800502 info.properties.driverVersion, info.properties.vendorID,
503 info.properties.deviceID);
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100504
Jesse Hall09559b52016-01-07 21:50:19 -0800505 for (uint32_t heap = 0; heap < info.memory.memoryHeapCount; heap++) {
506 if ((info.memory.memoryHeaps[heap].flags &
Jesse Halld1af8122015-11-29 23:50:38 -0800507 VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0)
508 strbuf << "DEVICE_LOCAL";
Jesse Hall38cb8402016-01-18 03:41:35 -0800509 printf("%sHeap %u: %" PRIu64 " MiB (0x%" PRIx64 " B) %s\n",
510 Indent(indent + 1), heap,
Jesse Hall00f10fe2016-02-08 21:20:20 -0800511 info.memory.memoryHeaps[heap].size / 0x100000,
Jesse Hall09559b52016-01-07 21:50:19 -0800512 info.memory.memoryHeaps[heap].size, strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100513 strbuf.str(std::string());
514
Jesse Hall09559b52016-01-07 21:50:19 -0800515 for (uint32_t type = 0; type < info.memory.memoryTypeCount; type++) {
516 if (info.memory.memoryTypes[type].heapIndex != heap)
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100517 continue;
518 VkMemoryPropertyFlags flags =
Jesse Hall09559b52016-01-07 21:50:19 -0800519 info.memory.memoryTypes[type].propertyFlags;
Jesse Halld1af8122015-11-29 23:50:38 -0800520 if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
Jesse Hall1f91d392015-12-11 16:28:44 -0800521 strbuf << " DEVICE_LOCAL";
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100522 if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
Jesse Hall1f91d392015-12-11 16:28:44 -0800523 strbuf << " HOST_VISIBLE";
Jesse Halld1af8122015-11-29 23:50:38 -0800524 if ((flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0)
525 strbuf << " COHERENT";
526 if ((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0)
527 strbuf << " CACHED";
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100528 if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
529 strbuf << " LAZILY_ALLOCATED";
Jesse Hall38cb8402016-01-18 03:41:35 -0800530 printf("%sType %u:%s\n", Indent(indent + 2), type,
531 strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100532 strbuf.str(std::string());
533 }
534 }
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700535
Jesse Hall09559b52016-01-07 21:50:19 -0800536 for (uint32_t family = 0; family < info.queue_families.size(); family++) {
537 const VkQueueFamilyProperties& qprops = info.queue_families[family];
Jesse Hall8966bf42016-01-16 17:26:48 -0800538 VkQueueFlags flags = qprops.queueFlags;
539 char flags_str[5];
540 flags_str[0] = (flags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '_';
541 flags_str[1] = (flags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '_';
542 flags_str[2] = (flags & VK_QUEUE_TRANSFER_BIT) ? 'T' : '_';
543 flags_str[3] = (flags & VK_QUEUE_SPARSE_BINDING_BIT) ? 'S' : '_';
544 flags_str[4] = '\0';
545 printf(
Jesse Hall38cb8402016-01-18 03:41:35 -0800546 "%sQueue Family %u: %ux %s\n"
547 "%stimestampValidBits: %ub\n"
548 "%sminImageTransferGranularity: (%u,%u,%u)\n",
549 Indent(indent + 1), family, qprops.queueCount, flags_str,
550 Indent(indent + 2), qprops.timestampValidBits, Indent(indent + 2),
Jesse Hall8966bf42016-01-16 17:26:48 -0800551 qprops.minImageTransferGranularity.width,
552 qprops.minImageTransferGranularity.height,
553 qprops.minImageTransferGranularity.depth);
Jesse Hallb1471272016-01-17 21:36:58 -0800554 }
Jesse Hall6e4ab312016-01-07 22:26:20 -0800555
Jesse Hallc5cec282016-01-18 04:01:10 -0800556 printf("%sFeatures:\n", Indent(indent + 1));
Jesse Hallf63e4452016-02-08 21:22:23 -0800557 if (options.unsupported_features) {
558 PrintAllFeatures(Indent(indent + 2), info.features);
559 } else {
560 PrintSupportedFeatures(Indent(indent + 2), info.features);
561 }
Jesse Hallc5cec282016-01-18 04:01:10 -0800562
Jesse Hall38cb8402016-01-18 03:41:35 -0800563 printf("%sExtensions [%zu]:\n", Indent(indent + 1), info.extensions.size());
564 if (!info.extensions.empty())
565 PrintExtensions(info.extensions, options, indent + 2);
566 printf("%sLayers [%zu]:\n", Indent(indent + 1), info.layers.size());
567 if (!info.layers.empty())
568 PrintLayers(info.layers, info.layer_extensions, options, indent + 2);
Jesse Hall04f4f472015-08-16 19:51:04 -0700569}
570
Jesse Hall38cb8402016-01-18 03:41:35 -0800571void PrintInfo(const VulkanInfo& info, const Options& options) {
Jesse Hall09559b52016-01-07 21:50:19 -0800572 std::ostringstream strbuf;
Jesse Hall38cb8402016-01-18 03:41:35 -0800573 size_t indent = 0;
Jesse Hall09559b52016-01-07 21:50:19 -0800574
Jesse Hall38cb8402016-01-18 03:41:35 -0800575 printf("%sInstance Extensions [%zu]:\n", Indent(indent),
576 info.extensions.size());
577 PrintExtensions(info.extensions, options, indent + 1);
578 printf("%sInstance Layers [%zu]:\n", Indent(indent), info.layers.size());
579 if (!info.layers.empty())
580 PrintLayers(info.layers, info.layer_extensions, options, indent + 1);
Jesse Hall09559b52016-01-07 21:50:19 -0800581
Jesse Hall38cb8402016-01-18 03:41:35 -0800582 printf("%sPhysicalDevices [%zu]:\n", Indent(indent), info.gpus.size());
Jesse Hall09559b52016-01-07 21:50:19 -0800583 for (const auto& gpu : info.gpus)
Jesse Hall38cb8402016-01-18 03:41:35 -0800584 PrintGpuInfo(gpu, options, indent + 1);
Jesse Hallc1ab3032016-01-04 07:26:53 -0800585}
586
Jesse Hallf63e4452016-02-08 21:22:23 -0800587const char kUsageString[] =
588 "usage: vkinfo [options]\n"
589 " -v enable all the following verbose options\n"
590 " -layer_description print layer description strings\n"
591 " -layer_extensions print extensions supported by each layer\n"
592 " -unsupported_features print all physical device features\n"
593 " -validate enable validation layers if present\n"
594 " -debug_pause pause at start until resumed via debugger\n";
595
Jesse Hall04f4f472015-08-16 19:51:04 -0700596} // namespace
597
Jesse Hall09559b52016-01-07 21:50:19 -0800598// ----------------------------------------------------------------------------
599
Jesse Hall38cb8402016-01-18 03:41:35 -0800600int main(int argc, char const* argv[]) {
Courtney Goeltzenleuchterc2a77092016-02-08 20:31:46 -0700601 static volatile bool startup_pause = false;
Jesse Hall38cb8402016-01-18 03:41:35 -0800602 Options options = {
603 .layer_description = false, .layer_extensions = false,
Jesse Hallf63e4452016-02-08 21:22:23 -0800604 .unsupported_features = false,
Chia-I Wud0bba372016-02-22 11:41:27 +0800605 .validate = false,
Jesse Hall38cb8402016-01-18 03:41:35 -0800606 };
607 for (int argi = 1; argi < argc; argi++) {
Jesse Hallf63e4452016-02-08 21:22:23 -0800608 if (strcmp(argv[argi], "-h") == 0) {
609 fputs(kUsageString, stdout);
610 return 0;
611 }
Jesse Hall38cb8402016-01-18 03:41:35 -0800612 if (strcmp(argv[argi], "-v") == 0) {
613 options.layer_description = true;
614 options.layer_extensions = true;
Jesse Hallf63e4452016-02-08 21:22:23 -0800615 options.unsupported_features = true;
Jesse Hall38cb8402016-01-18 03:41:35 -0800616 } else if (strcmp(argv[argi], "-layer_description") == 0) {
617 options.layer_description = true;
618 } else if (strcmp(argv[argi], "-layer_extensions") == 0) {
619 options.layer_extensions = true;
Jesse Hallf63e4452016-02-08 21:22:23 -0800620 } else if (strcmp(argv[argi], "-unsupported_features") == 0) {
621 options.unsupported_features = true;
Chia-I Wud0bba372016-02-22 11:41:27 +0800622 } else if (strcmp(argv[argi], "-validate") == 0) {
623 options.validate = true;
Courtney Goeltzenleuchterc2a77092016-02-08 20:31:46 -0700624 } else if (strcmp(argv[argi], "-debug_pause") == 0) {
625 startup_pause = true;
Jesse Hall38cb8402016-01-18 03:41:35 -0800626 }
627 }
628
Courtney Goeltzenleuchterc2a77092016-02-08 20:31:46 -0700629 while (startup_pause) {
630 sleep(0);
631 }
632
Jesse Hallc1ab3032016-01-04 07:26:53 -0800633 VulkanInfo info;
Chia-I Wud0bba372016-02-22 11:41:27 +0800634 GatherInfo(&info, options);
Jesse Hall38cb8402016-01-18 03:41:35 -0800635 PrintInfo(info, options);
Jesse Hall04f4f472015-08-16 19:51:04 -0700636 return 0;
637}